stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int main()



{

    int n,a,b;

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

    int i,j,x,y,s=0,hp;

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

    {

        x=0;

        y=i;

        for(j=0;;j++)

        {

            if(pow(10,j)>y)

            {

                hp=j-1;

                break;

            }

        }

        for(j=hp;j>=0;j--)

        {

            int power=pow(10,j);

            x=x+y/power;

            y=y%power;

        }







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

        {

            s=s+i;

        }

    }

    printf("%d",s);

    return 0;

}


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







int main(){

    int N, A, B;

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



    int sum = 0;

    // i == 123

    // 123 % 10 == 3; 123 / 12

    // 12 % 10 == 2; 12 / 10 == 1

    // 1 % 10 == 1; 1/ 10 = 0

    // 3 + 2 + 1 = 6

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

        int digitSum = 0;

        int temp = i;  

        while (temp != 0){

            // berhenti selama tidak 0

            digitSum = digitSum + temp % 10;

            temp /= 10;

        } 

        if(digitSum >= A && digitSum <= B){

            //printf("%d ", i);

            sum += i;

        }

    }

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



    return 0;

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

using namespace std;



int main ()



{

    int a,c,N,A,B,i,x,y,z,k,j;

    j=0;

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

    c=N;

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

        N=i;

        x=N/10000.0;

        N=N-10000*x;

        y=N/1000.0;

        N=N-1000*y;

        z=N/100.0;

        N=N-z*100;

        a=N/10.0;

        N=N-a*10;



        k=a+z+x+y+N;

        if(k>=A && k<=B){

            j=i+j;

        }





    }

    printf("%d",j);

}


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







int main(){

    int N, A, B;

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



    int sum = 0;

    // i == 123

    // 123 % 10 == 3; 123 / 12

    // 12 % 10 == 2; 12 / 10 == 1

    // 1 % 10 == 1; 1/ 10 = 0

    // 3 + 2 + 1 = 6

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

        int digitSum = 0;

        int temp = i;  

        while (temp != 0){

            // berhenti selama tidak 0

            digitSum = digitSum + temp % 10;

            temp /= 10;

        } 

        if(digitSum >= A && digitSum <= B){

            //printf("%d ", i);

            sum += i;

        }

    }

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



    return 0;

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

int main()

{

    int i,j,k,l,m,n,o,a,b,sum;

    scanf("%d",&n);

    scanf("%d",&a);

    scanf("%d",&b);

    sum=0;

    for(o=0;o<=9;o++)

    {

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

        {

            for(j=0;j<=9;j++)

            {

                for(k=0;k<=9;k++)

                {

                    for(l=0;l<=9;l++)

                    {

                        for(m=a;m<=b&&10000*o+1000*i+100*j+10*k+l<=n;m++)

                        {

                            if(m==o+i+j+k+l)

                            {

                                sum=sum+10000*o+1000*i+100*j+10*k+l;

                                break;

                            }

                        }

                    }

                }

            }

        }

    }

    printf("%d",sum);

    return 0;

}


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







int main(){

    int N, A, B;

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



    int sum = 0;

    // i == 123

    // 123 % 10 == 3; 123 / 12

    // 12 % 10 == 2; 12 / 10 == 1

    // 1 % 10 == 1; 1/ 10 = 0

    // 3 + 2 + 1 = 6

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

        int digitSum = 0;

        int temp = i;  

        while (temp != 0){

            // berhenti selama tidak 0

            digitSum = digitSum + temp % 10;

            temp /= 10;

        } 

        if(digitSum >= A && digitSum <= B){

            //printf("%d ", i);

            sum += i;

        }

    }

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



    return 0;

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

using namespace std;

#define pb push_back

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

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

#define mp make_pair

#define F first

#define S second

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

typedef long long ll;

vector<int> g[100005];

ll q,n;



int main()

{

    //IOS;

    while(cin>>n)

    {

        ll sum=0;

        ll A,B;

        cin>>A>>B;

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

        {

            ll a=i/10000,b=(i%10000)/1000,c=(i%1000)/100,d=(i%100)/10,e=i%10;

            if(a+b+c+d+e<=B&&a+b+c+d+e>=A) sum+=i;

        }

        cout<<sum<<"\n";

    }



    return 0;

}




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







int main(){

    int N, A, B;

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



    int sum = 0;

    // i == 123

    // 123 % 10 == 3; 123 / 12

    // 12 % 10 == 2; 12 / 10 == 1

    // 1 % 10 == 1; 1/ 10 = 0

    // 3 + 2 + 1 = 6

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

        int digitSum = 0;

        int temp = i;  

        while (temp != 0){

            // berhenti selama tidak 0

            digitSum = digitSum + temp % 10;

            temp /= 10;

        } 

        if(digitSum >= A && digitSum <= B){

            //printf("%d ", i);

            sum += i;

        }

    }

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



    return 0;

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



using namespace std;



int main(){

    int n,a,b,ans=0,d,p=0;

    cin >> n >> a >> b;

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

        d=t,p=0;

        while(d>=1){

            p+=d%10;

            d/=10;

        }

        if(p>=a && p<=b){

            ans+=t;

        }

    }

    cout << ans << '\n';

}

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







int main(){

    int N, A, B;

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



    int sum = 0;

    // i == 123

    // 123 % 10 == 3; 123 / 12

    // 12 % 10 == 2; 12 / 10 == 1

    // 1 % 10 == 1; 1/ 10 = 0

    // 3 + 2 + 1 = 6

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

        int digitSum = 0;

        int temp = i;  

        while (temp != 0){

            // berhenti selama tidak 0

            digitSum = digitSum + temp % 10;

            temp /= 10;

        } 

        if(digitSum >= A && digitSum <= B){

            //printf("%d ", i);

            sum += i;

        }

    }

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



    return 0;

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

using namespace std;

int main()



{

    int n,a,b;

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

    int i,j,x,y,s=0,hp;

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

    {

        x=0;

        y=i;

        for(j=0;;j++)

        {

            if(pow(10,j)>y)

            {

                hp=j-1;

                break;

            }

        }

        for(j=hp;j>=0;j--)

        {

            int power=pow(10,j);

            x=x+y/power;

            y=y%power;

        }







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

        {

            s=s+i;

        }

    }

    printf("%d",s);

    return 0;

}


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



int main() {

  int N, A, B;

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

  int sum = 0;



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

    int digitSum = 0;

    int temp = i;

    while(temp != 0) {

      digitSum = digitSum + temp % 10;

      temp /= 10;

    }

    if(digitSum >= A && digitSum <= B) {

      sum += i;

    }

  }

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

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

using namespace std;



int main ()



{

    int a,c,N,A,B,i,x,y,z,k,j;

    j=0;

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

    c=N;

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

        N=i;

        x=N/10000.0;

        N=N-10000*x;

        y=N/1000.0;

        N=N-1000*y;

        z=N/100.0;

        N=N-z*100;

        a=N/10.0;

        N=N-a*10;



        k=a+z+x+y+N;

        if(k>=A && k<=B){

            j=i+j;

        }





    }

    printf("%d",j);

}


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



int main() {

  int N, A, B;

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

  int sum = 0;



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

    int digitSum = 0;

    int temp = i;

    while(temp != 0) {

      digitSum = digitSum + temp % 10;

      temp /= 10;

    }

    if(digitSum >= A && digitSum <= B) {

      sum += i;

    }

  }

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

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

int main()

{

    int i,j,k,l,m,n,o,a,b,sum;

    scanf("%d",&n);

    scanf("%d",&a);

    scanf("%d",&b);

    sum=0;

    for(o=0;o<=9;o++)

    {

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

        {

            for(j=0;j<=9;j++)

            {

                for(k=0;k<=9;k++)

                {

                    for(l=0;l<=9;l++)

                    {

                        for(m=a;m<=b&&10000*o+1000*i+100*j+10*k+l<=n;m++)

                        {

                            if(m==o+i+j+k+l)

                            {

                                sum=sum+10000*o+1000*i+100*j+10*k+l;

                                break;

                            }

                        }

                    }

                }

            }

        }

    }

    printf("%d",sum);

    return 0;

}


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



int main() {

  int N, A, B;

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

  int sum = 0;



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

    int digitSum = 0;

    int temp = i;

    while(temp != 0) {

      digitSum = digitSum + temp % 10;

      temp /= 10;

    }

    if(digitSum >= A && digitSum <= B) {

      sum += i;

    }

  }

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

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

using namespace std;

#define pb push_back

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

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

#define mp make_pair

#define F first

#define S second

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

typedef long long ll;

vector<int> g[100005];

ll q,n;



int main()

{

    //IOS;

    while(cin>>n)

    {

        ll sum=0;

        ll A,B;

        cin>>A>>B;

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

        {

            ll a=i/10000,b=(i%10000)/1000,c=(i%1000)/100,d=(i%100)/10,e=i%10;

            if(a+b+c+d+e<=B&&a+b+c+d+e>=A) sum+=i;

        }

        cout<<sum<<"\n";

    }



    return 0;

}




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



int main() {

  int N, A, B;

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

  int sum = 0;



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

    int digitSum = 0;

    int temp = i;

    while(temp != 0) {

      digitSum = digitSum + temp % 10;

      temp /= 10;

    }

    if(digitSum >= A && digitSum <= B) {

      sum += i;

    }

  }

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

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



using namespace std;



int main(){

    int n,a,b,ans=0,d,p=0;

    cin >> n >> a >> b;

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

        d=t,p=0;

        while(d>=1){

            p+=d%10;

            d/=10;

        }

        if(p>=a && p<=b){

            ans+=t;

        }

    }

    cout << ans << '\n';

}

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



int main() {

  int N, A, B;

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

  int sum = 0;



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

    int digitSum = 0;

    int temp = i;

    while(temp != 0) {

      digitSum = digitSum + temp % 10;

      temp /= 10;

    }

    if(digitSum >= A && digitSum <= B) {

      sum += i;

    }

  }

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

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

using namespace std;

int main()



{

    int n,a,b;

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

    int i,j,x,y,s=0,hp;

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

    {

        x=0;

        y=i;

        for(j=0;;j++)

        {

            if(pow(10,j)>y)

            {

                hp=j-1;

                break;

            }

        }

        for(j=hp;j>=0;j--)

        {

            int power=pow(10,j);

            x=x+y/power;

            y=y%power;

        }







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

        {

            s=s+i;

        }

    }

    printf("%d",s);

    return 0;

}


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



int main(){

	int m,l,r,sum=0;

	scanf("%d %d %d", &m,&l,&r);

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

		int dSum = 0;

		int temp = i;

		while (temp != 0){

			dSum = dSum + temp % 10;

			temp /= 10;

		}

		if(dSum >= l && dSum <=r){

			sum+=i;

		}

	}

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

	

	return 0;

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

using namespace std;



int main ()



{

    int a,c,N,A,B,i,x,y,z,k,j;

    j=0;

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

    c=N;

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

        N=i;

        x=N/10000.0;

        N=N-10000*x;

        y=N/1000.0;

        N=N-1000*y;

        z=N/100.0;

        N=N-z*100;

        a=N/10.0;

        N=N-a*10;



        k=a+z+x+y+N;

        if(k>=A && k<=B){

            j=i+j;

        }





    }

    printf("%d",j);

}


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



int main(){

	int m,l,r,sum=0;

	scanf("%d %d %d", &m,&l,&r);

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

		int dSum = 0;

		int temp = i;

		while (temp != 0){

			dSum = dSum + temp % 10;

			temp /= 10;

		}

		if(dSum >= l && dSum <=r){

			sum+=i;

		}

	}

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

	

	return 0;

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

int main()

{

    int i,j,k,l,m,n,o,a,b,sum;

    scanf("%d",&n);

    scanf("%d",&a);

    scanf("%d",&b);

    sum=0;

    for(o=0;o<=9;o++)

    {

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

        {

            for(j=0;j<=9;j++)

            {

                for(k=0;k<=9;k++)

                {

                    for(l=0;l<=9;l++)

                    {

                        for(m=a;m<=b&&10000*o+1000*i+100*j+10*k+l<=n;m++)

                        {

                            if(m==o+i+j+k+l)

                            {

                                sum=sum+10000*o+1000*i+100*j+10*k+l;

                                break;

                            }

                        }

                    }

                }

            }

        }

    }

    printf("%d",sum);

    return 0;

}


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



int main(){

	int m,l,r,sum=0;

	scanf("%d %d %d", &m,&l,&r);

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

		int dSum = 0;

		int temp = i;

		while (temp != 0){

			dSum = dSum + temp % 10;

			temp /= 10;

		}

		if(dSum >= l && dSum <=r){

			sum+=i;

		}

	}

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

	

	return 0;

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

using namespace std;

#define pb push_back

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

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

#define mp make_pair

#define F first

#define S second

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

typedef long long ll;

vector<int> g[100005];

ll q,n;



int main()

{

    //IOS;

    while(cin>>n)

    {

        ll sum=0;

        ll A,B;

        cin>>A>>B;

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

        {

            ll a=i/10000,b=(i%10000)/1000,c=(i%1000)/100,d=(i%100)/10,e=i%10;

            if(a+b+c+d+e<=B&&a+b+c+d+e>=A) sum+=i;

        }

        cout<<sum<<"\n";

    }



    return 0;

}




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



int main(){

	int m,l,r,sum=0;

	scanf("%d %d %d", &m,&l,&r);

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

		int dSum = 0;

		int temp = i;

		while (temp != 0){

			dSum = dSum + temp % 10;

			temp /= 10;

		}

		if(dSum >= l && dSum <=r){

			sum+=i;

		}

	}

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

	

	return 0;

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



using namespace std;



int main(){

    int n,a,b,ans=0,d,p=0;

    cin >> n >> a >> b;

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

        d=t,p=0;

        while(d>=1){

            p+=d%10;

            d/=10;

        }

        if(p>=a && p<=b){

            ans+=t;

        }

    }

    cout << ans << '\n';

}

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



int main(){

	int m,l,r,sum=0;

	scanf("%d %d %d", &m,&l,&r);

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

		int dSum = 0;

		int temp = i;

		while (temp != 0){

			dSum = dSum + temp % 10;

			temp /= 10;

		}

		if(dSum >= l && dSum <=r){

			sum+=i;

		}

	}

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

	

	return 0;

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



using namespace std;

int n, m;

char op[1005][1005];

bool vis[1005][1005];

int dp[1005][1005];

const int X[] = {-1, 0, 1, 0}, Y[] = {0, 1, 0, -1};



struct Node {

    int x, y;



    Node(int a, int b) : x(a), y(b) {}

};



queue<Node> que;



int main() {

    ios::sync_with_stdio(false), memset(dp, 127, sizeof(dp));

    cin >> n >> m;

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

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

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

            if (op[i][j] == '#') {

                for (int p = 0; p < 4; p++) {

                    int xx = i + X[p], yy = j + Y[p];

                    if (op[xx][yy] == '.' && !vis[xx][yy])vis[xx][yy] = true, dp[xx][yy] = 1, que.push(Node(xx, yy));

                }

            }

        }

    }

    while (!que.empty()) {

        Node s = que.front();

        que.pop(), vis[s.x][s.y] = false;

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

            int xx = s.x + X[i], yy = s.y + Y[i];

            if (xx < 1 || xx > n || yy < 1 || yy > m)continue;

            if (op[xx][yy] == '.' && dp[xx][yy] > dp[s.x][s.y] + 1) {

                dp[xx][yy] = dp[s.x][s.y] + 1;

                if (!vis[xx][yy])que.push(Node(xx, yy)), vis[xx][yy] = true;

            }

        }

    }

    int ans = 0;

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

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

            if (op[i][j] == '.')ans = max(ans, dp[i][j]);

        }

    }

    cout << ans;

    return 0;

}

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

#include<algorithm>

#include<cstring>

#include<queue>

#define SIZE 1010

#define MOD 998244353



using namespace std;



int n,m;

int ans;

char map[SIZE][SIZE];

int step[SIZE][SIZE];

bool vis[SIZE][SIZE];

struct point

{

    int x,y;

    int steps;

}tmp;

int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};

bool legal(int x,int y)

{

    if(x==0 || y==0)

        return false;

    if(x>n || y>m)

        return false;

    return !vis[x][y];

}

void bfs()

{

    int i,j;

    queue<point> que;

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

    {

        for(j=1;j<=m;j++)

        {

            if(map[i][j]=='#')

            {

                que.push({i,j,0});

                vis[i][j]=true;

            }

        }

    }

    while(!que.empty())

    {

        tmp=que.front();

        que.pop();

        ans=max(ans,tmp.steps);

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

        {

            int tmpx=tmp.x+dir[i][0];

            int tmpy=tmp.y+dir[i][1];

            if(legal(tmpx,tmpy))

            {

                vis[tmpx][tmpy]=true;

                que.push({tmpx,tmpy,tmp.steps+1});

            }

        }

    }

    return ;

}

int main()

{

    int i,j;

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

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

        scanf("%s",map[i]+1);

    bfs();

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

    return 0;

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



using namespace std;

int n, m;

char op[1005][1005];

bool vis[1005][1005];

int dp[1005][1005];

const int X[] = {-1, 0, 1, 0}, Y[] = {0, 1, 0, -1};



struct Node {

    int x, y;



    Node(int a, int b) : x(a), y(b) {}

};



queue<Node> que;



int main() {

    ios::sync_with_stdio(false), memset(dp, 127, sizeof(dp));

    cin >> n >> m;

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

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

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

            if (op[i][j] == '#') {

                for (int p = 0; p < 4; p++) {

                    int xx = i + X[p], yy = j + Y[p];

                    if (op[xx][yy] == '.' && !vis[xx][yy])vis[xx][yy] = true, dp[xx][yy] = 1, que.push(Node(xx, yy));

                }

            }

        }

    }

    while (!que.empty()) {

        Node s = que.front();

        que.pop(), vis[s.x][s.y] = false;

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

            int xx = s.x + X[i], yy = s.y + Y[i];

            if (xx < 1 || xx > n || yy < 1 || yy > m)continue;

            if (op[xx][yy] == '.' && dp[xx][yy] > dp[s.x][s.y] + 1) {

                dp[xx][yy] = dp[s.x][s.y] + 1;

                if (!vis[xx][yy])que.push(Node(xx, yy)), vis[xx][yy] = true;

            }

        }

    }

    int ans = 0;

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

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

            if (op[i][j] == '.')ans = max(ans, dp[i][j]);

        }

    }

    cout << ans;

    return 0;

}

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

using namespace std;

char mp[1005][1005];

int h,w;

struct node{

	int x,y,step;

};

int vis[1005][1005];

queue<node>q;

int tox[]={1,0,0,-1};

int toy[]={0,1,-1,0};

int main()

{

	cin >> h >> w;

	int cnt=0;

	node s;

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

	{

		scanf("%s",mp[i]);

	}

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

	{

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

		{

			if(mp[i][j]=='#')

			{

				vis[i][j]=1;

				s.x=i;

				s.y=j;

				s.step=0;

				q.push(s);

			}

		}

	}

	node t;

	int op=0;

	while(!q.empty())

	{

		s=q.front();

		q.pop();

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

		{

			int x=s.x+tox[i];

			int y=s.y+toy[i];

			if(x<h&&x>=0&&y>=0&&y<w)

			{

				if(mp[x][y]=='.'&&!vis[x][y])

				{

					mp[x][y]='#';

					vis[x][y]=1;

					t.x=x;

					t.y=y;

					t.step=s.step+1;

					q.push(t);

					op=max(op,t.step);

				}

			}

		}

	}

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

    return 0;

}