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

#include <string.h>

#define MAXN 100005

using namespace std;



int n, ps[MAXN];

string s;

bool valid(int k){

	memset(ps, 0, sizeof ps);

	int tmp = 0;

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

		tmp += ps[i];

		int now = (s[i]	- '0') ^ (tmp % 2);

//		cout << i << " # " << tmp << " \n";

		if(!now) continue;

		ps[i+1]++;

		ps[min(i+k, n)]--;

	}

	int r = n - k;

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

		tmp += ps[i];

		int now = (s[i]	- '0') ^ (tmp % 2);

		if(now) break;

		r = i;

	}

//	cout << k << " -> " << r << "\n";

	return r + 1 >= k;

}

int main(){

	ios_base::sync_with_stdio(0);

	cin.tie();

	

	cin >> s;

	n = s.length();

	int l = 1;

	int r = s.length();

	int k = (l + r + 1) / 2;

	while(l < r){

		if(valid(k)) l = k;

		else r = k - 1;

		k = (l + r + 1) / 2;

	}

	cout << l << "\n";

	return 0;

}

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

#include<stdio.h>

#include<string>

#include<string.h>

#include<algorithm>

#define INF 0x3f3f3f3f

const int N = 100000+5;

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

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

using namespace std;

int a[N];

int main()

{

    string str;

   cin>>str;

    int len=str.length();

    int cnt=0;

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

    {

        if(str[i]!=str[i-1])

            a[++cnt]=max(i,len-i);

    }

    int res;

    res=len;

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

    {

        res=min(res,a[i]);

    }

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

    return 0;

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

#include <string.h>

#define MAXN 100005

using namespace std;



int n, ps[MAXN];

string s;

bool valid(int k){

	memset(ps, 0, sizeof ps);

	int tmp = 0;

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

		tmp += ps[i];

		int now = (s[i]	- '0') ^ (tmp % 2);

//		cout << i << " # " << tmp << " \n";

		if(!now) continue;

		ps[i+1]++;

		ps[min(i+k, n)]--;

	}

	int r = n - k;

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

		tmp += ps[i];

		int now = (s[i]	- '0') ^ (tmp % 2);

		if(now) break;

		r = i;

	}

//	cout << k << " -> " << r << "\n";

	return r + 1 >= k;

}

int main(){

	ios_base::sync_with_stdio(0);

	cin.tie();

	

	cin >> s;

	n = s.length();

	int l = 1;

	int r = s.length();

	int k = (l + r + 1) / 2;

	while(l < r){

		if(valid(k)) l = k;

		else r = k - 1;

		k = (l + r + 1) / 2;

	}

	cout << l << "\n";

	return 0;

}

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

using namespace std;

#define filein freopen ("in.txt", "r", stdin)

#define fileout freopen ("out.txt", "w", stdout)

typedef long long ll;

int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    //cout << "time consumed : " << clock() * 1.0 / CLOCKS_PER_SEC << endl;

    //filein;

    //fileout;



    string str;

    cin >> str;

    int len=str.size();

    int ans=len;

    int temp;

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

    {

		if(str[i]!=str[i+1])

		{



			temp=max(len-i-1,i+1);

		    ans=min(temp,ans);



		}

    }

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











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

#include <string.h>

#define MAXN 100005

using namespace std;



int n, ps[MAXN];

string s;

bool valid(int k){

	memset(ps, 0, sizeof ps);

	int tmp = 0;

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

		tmp += ps[i];

		int now = (s[i]	- '0') ^ (tmp % 2);

//		cout << i << " # " << tmp << " \n";

		if(!now) continue;

		ps[i+1]++;

		ps[min(i+k, n)]--;

	}

	int r = n - k;

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

		tmp += ps[i];

		int now = (s[i]	- '0') ^ (tmp % 2);

		if(now) break;

		r = i;

	}

//	cout << k << " -> " << r << "\n";

	return r + 1 >= k;

}

int main(){

	ios_base::sync_with_stdio(0);

	cin.tie();

	

	cin >> s;

	n = s.length();

	int l = 1;

	int r = s.length();

	int k = (l + r + 1) / 2;

	while(l < r){

		if(valid(k)) l = k;

		else r = k - 1;

		k = (l + r + 1) / 2;

	}

	cout << l << "\n";

	return 0;

}

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

#include <cstdio>

#include <cstring>

#include <algorithm>

#define LL long long

using namespace std;

int n;

string S;

int check(int x){

    string s = S;

    int len = 0;

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

        if(len){

            len--;

            if(s[i] == '1') s[i] = '0';

            else s[i] = '1';

        }

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

            if(i - 1 < x){

                if(n - i < x){

                    len = x - 1;

                }

            }

        }

    }

    if(len) return 0;

    return 1;

}

int main(){

    ios::sync_with_stdio(false);

    cin>>S; S = " " + S;

    n = S.size() - 1;

    int l = 1, r = n;

    while(l < r){

        int mid = (l + r + 1)>>1;

        if(check(mid)) l = mid;

        else r = mid - 1;

    }

    cout<<l;

    return 0;

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

#include <string.h>

#define MAXN 100005

using namespace std;



int n, ps[MAXN];

string s;

bool valid(int k){

	memset(ps, 0, sizeof ps);

	int tmp = 0;

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

		tmp += ps[i];

		int now = (s[i]	- '0') ^ (tmp % 2);

//		cout << i << " # " << tmp << " \n";

		if(!now) continue;

		ps[i+1]++;

		ps[min(i+k, n)]--;

	}

	int r = n - k;

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

		tmp += ps[i];

		int now = (s[i]	- '0') ^ (tmp % 2);

		if(now) break;

		r = i;

	}

//	cout << k << " -> " << r << "\n";

	return r + 1 >= k;

}

int main(){

	ios_base::sync_with_stdio(0);

	cin.tie();

	

	cin >> s;

	n = s.length();

	int l = 1;

	int r = s.length();

	int k = (l + r + 1) / 2;

	while(l < r){

		if(valid(k)) l = k;

		else r = k - 1;

		k = (l + r + 1) / 2;

	}

	cout << l << "\n";

	return 0;

}

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

#include<cstdio>

#include<cstring>

using namespace std;

char s[100010];

int main(){

	scanf("%s",s);

	int n=strlen(s),ans=n;

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

		if(s[i]!=s[i-1])

			ans=min(ans,max(i,n-i));

	cout<<ans;

	return 0;

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

#include <string.h>

#define MAXN 100005

using namespace std;



int n, ps[MAXN];

string s;

bool valid(int k){

	memset(ps, 0, sizeof ps);

	int tmp = 0;

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

		tmp += ps[i];

		int now = (s[i]	- '0') ^ (tmp % 2);

//		cout << i << " # " << tmp << " \n";

		if(!now) continue;

		ps[i+1]++;

		ps[min(i+k, n)]--;

	}

	int r = n - k;

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

		tmp += ps[i];

		int now = (s[i]	- '0') ^ (tmp % 2);

		if(now) break;

		r = i;

	}

//	cout << k << " -> " << r << "\n";

	return r + 1 >= k;

}

int main(){

	ios_base::sync_with_stdio(0);

	cin.tie();

	

	cin >> s;

	n = s.length();

	int l = 1;

	int r = s.length();

	int k = (l + r + 1) / 2;

	while(l < r){

		if(valid(k)) l = k;

		else r = k - 1;

		k = (l + r + 1) / 2;

	}

	cout << l << "\n";

	return 0;

}

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

#include<cstdlib>

#include<cstdio>

#include<algorithm>

#include<cmath>

#include<cstring>

#include<stack>

#define LL long long

using namespace std;

string f;

int a[100011];

int n;

int ans;

int read()

{

	int _=0,__=1;char ch=getchar();

	while(ch<'0'||ch>'9') {if(ch=='-')__=-1;ch=getchar();}

	while(ch>='0'&&ch<='9'){_=_*10+ch-'0';ch=getchar();}

	return _*__;

}

int main()

{

	cin>>f;

	n=f.size();

	ans=f.size();

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

	a[i]=f[i]-'0';

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

	if(a[i]!=a[i-1])

	ans=min(ans,max(i,n-i));

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

	return 0;

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

#include <string.h>

#define MAXN 100005

using namespace std;



int n, ps[MAXN];

string s;

bool valid(int k){

	memset(ps, 0, sizeof ps);

	int tmp = 0;

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

		tmp += ps[i];

		int now = (s[i]	- '0') ^ (tmp % 2);

//		cout << i << " # " << tmp << " \n";

		if(!now) continue;

		ps[i+1]++;

		ps[min(i+k, n)]--;

	}

	int r = n - k;

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

		tmp += ps[i];

		int now = (s[i]	- '0') ^ (tmp % 2);

		if(now) break;

		r = i;

	}

//	cout << k << " -> " << r << "\n";

	return r + 1 >= k;

}

int main(){

	ios_base::sync_with_stdio(0);

	cin.tie();

	

	cin >> s;

	n = s.length();

	int l = 1;

	int r = s.length();

	int k = (l + r + 1) / 2;

	while(l < r){

		if(valid(k)) l = k;

		else r = k - 1;

		k = (l + r + 1) / 2;

	}

	cout << l << "\n";

	return 0;

}

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

#include<iostream>

#include<cstring>

#include<cstdio>

#include<cmath>

#include<vector>

using namespace std;

vector<int>G;

int main()

{

    

	 char ss[100005];

     scanf("%s",ss);

     int ll = strlen(ss);

	 int ans=strlen(ss);

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

     {

     	if(ss[i]!=ss[i-1]) ans=min(ans,max(i,ll-i));

     	

	 }

	 cout<<ans;

	return 0;

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

#include <string.h>

#define MAXN 100005

using namespace std;



int n, ps[MAXN];

string s;

bool valid(int k){

	memset(ps, 0, sizeof ps);

	int tmp = 0;

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

		tmp += ps[i];

		int now = (s[i]	- '0') ^ (tmp % 2);

//		cout << i << " # " << tmp << " \n";

		if(!now) continue;

		ps[i+1]++;

		ps[min(i+k, n)]--;

	}

	int r = n - k;

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

		tmp += ps[i];

		int now = (s[i]	- '0') ^ (tmp % 2);

		if(now) break;

		r = i;

	}

//	cout << k << " -> " << r << "\n";

	return r + 1 >= k;

}

int main(){

	ios_base::sync_with_stdio(0);

	cin.tie();

	

	cin >> s;

	n = s.length();

	int l = 1;

	int r = s.length();

	int k = (l + r + 1) / 2;

	while(l < r){

		if(valid(k)) l = k;

		else r = k - 1;

		k = (l + r + 1) / 2;

	}

	cout << l << "\n";

	return 0;

}

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

using namespace std;



using ll = long long;

using ii = pair<int,int>;



const int N = 1e5+10;



int n;

char s[N];



int main() { 

  scanf("%s", s);

  n = strlen(s);

  int j = (n - 1) / 2;

  while(j + 1 < n && s[j + 1] == s[(n - 1) / 2]) j++;

  int ans = j + 1;

  j = (n - 1) / 2;

  while(j - 1 >= 0 && s[j - 1] == s[(n - 1) / 2]) j--;

  ans = min(ans, n - j);

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

  return 0;

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

#include <cstdio>

#include <cstring>

#include <algorithm>

using namespace std;





int a[200010], b[200010];

int n, bs;





int mn[800010], tag[800010];

void build(int p, int l, int r) {

	if(l == r) {

		mn[p] = b[l]; tag[p] = 0;

		return ;

	}

	int mid = (l + r)>>1;

	build(p<<1, l, mid); build(p<<1|1, mid + 1, r);

	mn[p] = min(mn[p<<1], mn[p<<1|1]);

}

inline void pd(int p) {

	tag[p<<1]+= tag[p]; mn[p<<1]+= tag[p];

	tag[p<<1|1]+= tag[p]; mn[p<<1|1]+= tag[p];

	tag[p] = 0;

}

void add(int p, int l, int r, int x, int y) {

	if(x > y) return ;

	if(x <= l && r <= y) {

		++tag[p];

		++mn[p];

		return ;

	}

	int mid = (l + r)>>1;

	pd(p); 

	if(x <= mid) add(p<<1, l, mid, x, y);

	if(mid + 1 <= y) add(p<<1|1, mid + 1, r, x, y);

	mn[p] = min(mn[p<<1], mn[p<<1|1]);

}

int query(int p, int l, int r, int x, int y) {

	if(x <= l && r <= y) return mn[p];

	int mid = (l + r)>>1;

	int s1 = 0x7fffffff, s2 = 0x7fffffff;

	pd(p);

	if(x <= mid) s1 = query(p<<1, l, mid, x, y);

	if(mid + 1 <= y) s2 = query(p<<1|1, mid + 1, r, x, y);

	return min(s1, s2);

}

int main() {

	cin >> n;

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

	memcpy(b, a, sizeof(b)); sort(b+1, b+n+1); bs = unique(b+1, b+n+1) - b - 1;

	build(1, 1, bs);

	long long ans = 0;

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

		int p = lower_bound(b+1, b+bs+1, a[i]) - b;

		ans+= query(1, 1, bs, p, bs) - a[i];

		add(1, 1, bs, 1, p - 1);

	}

	cout << ans << endl;

	return 0;

}

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

#include <cstring>

#include <algorithm>

using namespace std;

int a[200010], b[200010];

int n, bs;

int mn[800010], tag[800010];

void build(int p, int l, int r) {

	if(l == r) {

		mn[p] = b[l]; tag[p] = 0;

		return ;

	}

	int mid = (l + r)>>1;

	build(p<<1, l, mid); build(p<<1|1, mid + 1, r);

	mn[p] = min(mn[p<<1], mn[p<<1|1]);

}

inline void pd(int p) {

	tag[p<<1]+= tag[p]; mn[p<<1]+= tag[p];

	tag[p<<1|1]+= tag[p]; mn[p<<1|1]+= tag[p];

	tag[p] = 0;

}

void add(int p, int l, int r, int x, int y) {

	if(x > y) return ;

	if(x <= l && r <= y) {

		++tag[p];

		++mn[p];

		return ;

	}

	int mid = (l + r)>>1;

	pd(p); 

	if(x <= mid) add(p<<1, l, mid, x, y);

	if(mid + 1 <= y) add(p<<1|1, mid + 1, r, x, y);

	mn[p] = min(mn[p<<1], mn[p<<1|1]);

}

int query(int p, int l, int r, int x, int y) {

	if(x <= l && r <= y) return mn[p];

	int mid = (l + r)>>1;

	int s1 = 0x7fffffff, s2 = 0x7fffffff;

	pd(p);

	if(x <= mid) s1 = query(p<<1, l, mid, x, y);

	if(mid + 1 <= y) s2 = query(p<<1|1, mid + 1, r, x, y);

	return min(s1, s2);

}

int main() {

	scanf("%d", &n);

	for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);

	memcpy(b, a, sizeof(b)); sort(b+1, b+n+1); bs = unique(b+1, b+n+1) - b - 1;

	build(1, 1, bs);

	long long ans = 0;

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

		int p = lower_bound(b+1, b+bs+1, a[i]) - b;

		ans+= query(1, 1, bs, p, bs) - a[i];

		add(1, 1, bs, 1, p - 1);

	}

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

	return 0;

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

#include <cstdio>

#include <cstring>

#include <stdlib.h>

#include <algorithm>

#include <math.h>

#include <vector>

#include <list>

#include <map>

#include <queue>

#include <set>

using namespace std;



int p[10][10];

int n,m;



int main(){

	while(cin>>n>>m){

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

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

				cin>>p[a][b];

			}

		}

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

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

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

					p[i][j]=min(p[i][j],p[i][k]+p[k][j]);

				}

			}

		}

		int sum=0;

		for(int a=0;a<n*m;a++){

			int key;

			cin>>key;

			if(!(key==1||key==-1)) sum+=p[key][1];

		}

		cout<<sum<<endl;

	}

}

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

int h,w;

int c[10][10],a[200+5][200+5];

int mp[10];



void solve(int &ini,int cur,int &sum){

	if(sum>=mp[ini])return;

	int s[10];

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

		if(i==cur)continue;

		s[i]=(c[cur][i]+sum);

		if(i!=1)solve(ini,i,s[i]);

		else{

			if(s[1]<mp[ini])mp[ini]=s[1];

		}

	}

}



int main(){

	scanf("%d%d",&h,&w);

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

		for(int j=0;j<10;j++)scanf("%d",&c[i][j]);

	}

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

		for(int j=0;j<w;j++)scanf("%d",&a[i][j]); 

	}

	for(int i=0;i<10;i++)mp[i]=c[i][1];

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

		if(i==1)continue;

		int sum=0;

		solve(i,i,sum);

	}

	int count=0;

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

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

			if(a[i][j]==-1||a[i][j]==1)continue;

			count+=mp[a[i][j]];

		}

	}

	printf("%d",count);

	return 0;

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

#include <cstdio>

#include <cstring>

#include <stdlib.h>

#include <algorithm>

#include <math.h>

#include <vector>

#include <list>

#include <map>

#include <queue>

#include <set>

using namespace std;



int p[10][10];

int n,m;



int main(){

	while(cin>>n>>m){

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

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

				cin>>p[a][b];

			}

		}

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

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

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

					p[i][j]=min(p[i][j],p[i][k]+p[k][j]);

				}

			}

		}

		int sum=0;

		for(int a=0;a<n*m;a++){

			int key;

			cin>>key;

			if(!(key==1||key==-1)) sum+=p[key][1];

		}

		cout<<sum<<endl;

	}

}

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

#include <algorithm>



using namespace std;



int C[10][10];

int h, w;



int main() {

    scanf("%d%d", &h, &w);

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

        for (int j = 0; j < 10; j++) scanf("%d", &C[i][j]);

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

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

            for (int j = 0; j < 10; j++) C[i][j] = min(C[i][j], C[i][k] + C[k][j]);

    int ans = 0;

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

        for (int j = 0; j < w; j++) scanf("%d", &x), ans += (x==-1)?0:C[x][1];

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

    return 0;

}
// Slower C++ solution:
// 



#include <vector>

#include <iostream>

#include <queue>

#include <climits>

using namespace std;



#define INF 2000

#define F first

#define S second

typedef pair< int, int > ii;



const int N = 10;



int n, start, finish;

int cost[N][N]; // adjacency matrix

int freq[10]; // number of each digit on the wall



priority_queue< ii, vector< ii >, greater< ii > > pq;



int dist[N];

bool visit[N];



int row, col;



void input ()

{

	cin >> row >> col;

	

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

	for (int j = 0; j < 10; ++j) cin >> cost[j][i]; // reversed

	

	int digit;

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

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

		cin >> digit;

		if (digit != -1) ++freq[digit];

	}

}



void init ()

{

	for (int i = 0; i < 10; ++i) dist[i] = INF;

	dist[1] = 0;

	pq.emplace(0, 1);

}



void dijkstra ()

{

	input();

	init();

	

	int proc;

	while (!pq.empty())

	{

		proc = pq.top().second;

		pq.pop();

		

		if (visit[proc]) continue;

		visit[proc] = true;

		

		int temp;

		int adj;

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

			

			adj = i;

			temp = cost[proc][i] + dist[proc];

			

			if (temp < dist[adj]) {

				dist[adj] = temp;

				pq.emplace(temp, adj);

			}

		}

	}

	

	long long ans = 0;

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

		ans += (long long) dist[i]*freq[i];

	}

	

	cout << ans << "\n";

	

	return;

}



int main ()

{

	dijkstra();

	return 0;

}

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

#include <algorithm>



using namespace std;



int C[10][10];

int h, w;



int main() {

    scanf("%d%d", &h, &w);

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

        for (int j = 0; j < 10; j++) scanf("%d", &C[i][j]);

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

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

            for (int j = 0; j < 10; j++) C[i][j] = min(C[i][j], C[i][k] + C[k][j]);

    int ans = 0;

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

        for (int j = 0; j < w; j++) scanf("%d", &x), ans += (x==-1)?0:C[x][1];

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

    return 0;

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

using namespace std;

typedef long long LL;



LL cost[15][15];



int main(){

	ios_base::sync_with_stdio(0);

	

	int h, w;

	LL ans=0;

	cin >> h >> w;

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

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

			cin >> cost[i][j];

	}

	

	//floyd warshall

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

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

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

				cost[j][k]=min(cost[j][k], cost[j][i]+cost[i][k]);

			}

		}

	}

	

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

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

			int in;

			cin >> in;

			if(in > -1)

				ans+=cost[in][1];

		}

	}

	

	cout << ans << "\n";

	

	return 0;

}

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

#include <algorithm>



using namespace std;



int C[10][10];

int h, w;



int main() {

    scanf("%d%d", &h, &w);

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

        for (int j = 0; j < 10; j++) scanf("%d", &C[i][j]);

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

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

            for (int j = 0; j < 10; j++) C[i][j] = min(C[i][j], C[i][k] + C[k][j]);

    int ans = 0;

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

        for (int j = 0; j < w; j++) scanf("%d", &x), ans += (x==-1)?0:C[x][1];

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

    return 0;

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



using namespace std;



typedef long long ll;



int r,c,tujuan,x;

ll temp;



int main(){

		cin>>r>>c;

		int dist[10];

		int w[10][10];

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

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

		{

			dist[i] = INT_MAX;

		}

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

		{

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

				cin>>w[i][j];

			}

		}

		priority_queue<pair<ll,ll>> pq;

		dist[1] = 0;

		pq.push(make_pair(-dist[1],1));

		while(!pq.empty()){

			x = pq.top().second;

			pq.pop();

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

                if (dist[i]>w[i][x] + dist[x]){

                    dist[i] = w[i][x]+dist[x];

                    pq.push(make_pair(-dist[i],i));

                }

            }

		}

		ll res = 0;

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

		{

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

				cin>>tujuan;

				if (tujuan!=-1){

					if (tujuan != 1) res+=dist[tujuan];

				}

			}

		}

		cout<<res<<endl;







	return 0;



}


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

#include <algorithm>



using namespace std;



int C[10][10];

int h, w;



int main() {

    scanf("%d%d", &h, &w);

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

        for (int j = 0; j < 10; j++) scanf("%d", &C[i][j]);

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

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

            for (int j = 0; j < 10; j++) C[i][j] = min(C[i][j], C[i][k] + C[k][j]);

    int ans = 0;

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

        for (int j = 0; j < w; j++) scanf("%d", &x), ans += (x==-1)?0:C[x][1];

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

    return 0;

}