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

using namespace std;

typedef long long ll;

#define P pair<ll,ll>

#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)

#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)

#define TO(x,t,f) ((x)?(t):(f))

#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9

#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted

#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted

#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted

#define REV(x) (reverse(x.begin(),x.end())) //reverse

ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}

ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu

#define NEXTP(x) next_permutation(x.begin(),x.end())

const ll INF=1e18+7;

const ll MOD=1e9+7;



int main(){

	ll N,A,B,C;

	cin >> N >> A >> B >> C;

	vector<ll> L(N);

	FOR(i,0,N)cin>>L[i];

	ll ans = INF;

	ll K = 1;

	FOR(i,0,N)K*=3;

	FOR(i,0,K){

		ll p = i;

		vector<ll> a,b,c;

		FOR(j,0,N){

			if(p%3==0)a.push_back(L[j]);

			if(p%3==1)b.push_back(L[j]);

			if(p%3==2)c.push_back(L[j]);

			p /= 3;

		}

		vector<P> dpa,dpb,dpc;

		for(auto x:a){

			vector<P> d;

			d.push_back({x,0});

			for(auto y:dpa){

				d.push_back(y);

				d.push_back({y.first+x,y.second+10});

			}

			dpa = d;

		}

		for(auto x:b){

			vector<P> d;

			d.push_back({x,0});

			for(auto y:dpb){

				d.push_back(y);

				d.push_back({y.first+x,y.second+10});

			}

			dpb = d;

		}

		for(auto x:c){

			vector<P> d;

			d.push_back({x,0});

			for(auto y:dpc){

				d.push_back(y);

				d.push_back({y.first+x,y.second+10});

			}

			dpc = d;

		}

		ll mina=INF,minb=INF,minc=INF;

		for(auto x:dpa)mina = min(mina,x.second+abs(x.first-A));

		for(auto x:dpb)minb = min(minb,x.second+abs(x.first-B));

		for(auto x:dpc)minc = min(minc,x.second+abs(x.first-C));

		ans = min(ans,minc+minb+mina);

	}

	cout << ans << endl;

}

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

using namespace std;

typedef long long ll;

#define P pair<ll,ll>

#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)

const ll INF=1e16+7;

int main(){

	ll N,A[3],ans=INF,K=1;

	cin >> N >> A[0] >> A[1] >> A[2];

	vector<ll> L(N);

	FOR(i,0,N)cin>>L[i];

	FOR(i,0,N)K*=4;

	FOR(t,0,K){

		vector<P> a={{0,0},{0,0},{0,0}};

		ll p = t;

		FOR(i,0,N){

			if(p%4!=3){

				a[p%4].first+=L[i];

				a[p%4].second++;

			}

			p /= 4;

		}

		FOR(i,0,3)p+=abs(a[i].first-A[i]);

		FOR(i,0,3)p+=(a[i].second-1)*10;

		FOR(i,0,3)if(a[i].second==0)p=INF;

		ans = min(ans,p);

	}

	cout << ans << endl;

}

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

using namespace std;

typedef long long ll;

#define P pair<ll,ll>

#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)

const ll INF=1e18+7;

int main(){

	ll N;

	vector<ll> A(3);

	cin >> N >> A[0] >> A[1] >> A[2];

	vector<ll> L(N);

	FOR(i,0,N)cin>>L[i];

	ll ans = INF;

	ll K = 1;

	FOR(i,0,N)K*=3;

	FOR(i,0,K){

		ll p = i;

		vector<ll> a[3];

		FOR(j,0,N)a[p%3].push_back(L[j]),p/=3;

		vector<P> dp[3];

		FOR(j,0,3){

			for(auto x:a[j]){

				vector<P> dpp;

				dpp.push_back({x,0});

				for(auto y:dp[j]){

					dpp.push_back(y);

					dpp.push_back({y.first+x,y.second+10});

				}

				dp[j] = dpp;

			}

		}

		vector<ll> mina(3,INF);

		FOR(j,0,3)

			for(auto x:dp[j])

				mina[j] = min(mina[j],x.second+abs(x.first-A[j]));

		ans = min(ans,mina[0]+mina[1]+mina[2]);

	}

	cout << ans << endl;

}

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

using namespace std;

typedef long long ll;

#define P pair<ll,ll>

#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)

const ll INF=1e16+7;

int main(){

	ll N,A[3],ans=INF,K=1;

	cin >> N >> A[0] >> A[1] >> A[2];

	vector<ll> L(N);

	FOR(i,0,N)cin>>L[i];

	FOR(i,0,N)K*=4;

	FOR(t,0,K){

		vector<P> a={{0,0},{0,0},{0,0}};

		ll p = t;

		FOR(i,0,N){

			if(p%4!=3){

				a[p%4].first+=L[i];

				a[p%4].second++;

			}

			p /= 4;

		}

		FOR(i,0,3)p+=abs(a[i].first-A[i]);

		FOR(i,0,3)p+=(a[i].second-1)*10;

		FOR(i,0,3)if(a[i].second==0)p=INF;

		ans = min(ans,p);

	}

	cout << ans << endl;

}

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

using namespace std;



const long long INF = 1LL << 60;



template <class T> bool chmin(T& a, T b)

{

  if (a > b) {

    a = b; return true;

  } else return false;

}



template <class T> bool chmax(T& a, T b)

{

  if (a < b) {

    a = b; return true;

  } else return false;

}





int main()

{

  int N, A, B, C;

  cin >> N >> A >> B >> C;

  vector<int> l(N);

  for (int i = 0; i < N; i++) cin >> l.at(i);

  

  long long ans = INF;

  

  for (int i = 0; i < pow(4, N); i++)

  {

    long long at = 0, bt = 0, ct = 0;

    long long al = 0, bl = 0, cl = 0;

    

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

    {

      int p = pow(4, j);

      int Z = (i / p) % 4;

      if (Z == 1) {at++; al += l.at(j);}

      else if (Z == 2) {bt++; bl += l.at(j);}

      else if (Z == 3) {ct++; cl += l.at(j);}

    }

    

    if (at > 0 && bt > 0 && ct > 0)

    {

      long long MP = (at + bt + ct - 3) * 10 

                    + abs(A - al) + abs(B - bl) + abs(C - cl);

      chmin(ans, MP);

    }

  }

  

  cout << ans << endl;

}

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

using namespace std;



const long long INF = 1LL << 60;



template <class T> bool chmin(T& a, T b)

{

  if (a > b) {

    a = b; return true;

  } else return false;

}



template <class T> bool chmax(T& a, T b)

{

  if (a < b) {

    a = b; return true;

  } else return false;

}





int main()

{

  int N, A, B, C;

  cin >> N >> A >> B >> C;

  vector<int> l(N);

  for (int i = 0; i < N; i++) cin >> l.at(i);

  

  long long ans = INF;

  

  for (int i = 0; i < pow(4, N); i++)

  {

    long long at = 0, bt = 0, ct = 0;

    long long al = 0, bl = 0, cl = 0;

    

    for (int j = 0, p = 1; j < N; j++)

    {

      int Z = (i / p) % 4;

      if (Z == 1) {at++; al += l.at(j);}

      else if (Z == 2) {bt++; bl += l.at(j);}

      else if (Z == 3) {ct++; cl += l.at(j);}

      p *= 4;

    }

    

    if (at > 0 && bt > 0 && ct > 0)

    {

      long long MP = (at + bt + ct - 3) * 10 

                    + abs(A - al) + abs(B - bl) + abs(C - cl);

      chmin(ans, MP);

    }

  }

  

  cout << ans << endl;

}

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

using namespace std;

using ll = long long;

int main(){

    int N,A,B,C;

    cin >> N >> A >> B >> C;

    int l[8] = {};

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

    int d[8];

    int ans = 100000000;

    

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

        d[0] = i;

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

            d[1] = j;

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

                d[2] = k;

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

                    d[3] = m;

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

                        d[4] = n;

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

                            d[5] = o;

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

                                d[6] = p;

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

                                    d[7] = q;

                                    int a = 0,b = 0,c = 0,interim = 0;

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

                                        if(d[z] == 0){

                                            a += l[z];

                                            interim += 10;

                                        }

                                        else if(d[z] == 1){

                                            b += l[z];

                                            interim += 10;

                                        }

                                        else if(d[z] == 3){

                                            c += l[z];

                                            interim += 10;

                                        }

                                    }

                                    if(a == 0 || b == 0 || c == 0) continue;

                                    interim += (abs(A-a) + abs(B-b) + abs(C-c) - 30);

                                    if(ans > interim)

                                        ans = interim;

                                }

                            }

                        }

                    }

                }

            }

        }

    }

    cout << ans << "\n";

    return 0;

}




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

using namespace std;

using ll = long long;

int N,A,B,C;

int l[8];

int ans = 100000000;

void dfs(int depth,int a,int b,int c,int cost){

    if(depth == N){

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

            ans = min(ans,cost + (abs(A-a) + abs(B-b) + abs(C-c) - 30));

    return ;

    }

    dfs(depth+1,a+l[depth],b,c,cost+10);

    dfs(depth+1,a,b+l[depth],c,cost+10);

    dfs(depth+1,a,b,c+l[depth],cost+10);

    dfs(depth+1,a,b,c,cost);

}

int main(){

    cin >> N >> A >> B >> C;

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

    dfs(0,0,0,0,0);

    cout << ans << "\n";

    return 0;

}




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

#include <vector>

#include <string>

#include <cmath>

#include <algorithm>

#include <tuple>

#include <map>

using namespace std;

typedef long long ll;

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

#define repd(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)

#define repdm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)



int N, A, B, C;

int seq[4] = {0, 1, 2, 3};

int ANS = 100000;



int calcMP(map<int, int> m)

{

  if (m[1] == 0 || m[2] == 0 || m[3] == 0)

    return 10000;

  return abs(A - m[1]) + abs(B - m[2]) + abs(C - m[3]);

}



int dfs(int depth, int l[], map<int, int> m, int mp)

{

  if (depth == 0)

  {

    mp += calcMP(m);

    return mp;

  }



  for (auto s : seq)

  {

    int tmp = mp;

    map<int, int> mm = m;

    if (mm[s] == 0)

    {

      mm[s] = l[depth - 1];

    }

    else

    {

      mm[s] += l[depth - 1];

      if (s != 0)

        tmp += 10;

    }

    tmp = dfs(depth - 1, l, mm, tmp);

    ANS = min(ANS, tmp);

  }



  return ANS;

}



int main()

{

  cin >> N >> A >> B >> C;

  int l[N];

  rep(i, N) cin >> l[i];

  int mp = 0;



  map<int, int> m{

      {0, 0}, {1, 0}, {2, 0}, {3, 0}};



  dfs(N, l, m, mp);



  cout << ANS;

}

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

#include <vector>

#include <string>

#include <cmath>

#include <algorithm>

#include <tuple>

#include <map>

using namespace std;

typedef long long ll;

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

#define repd(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)

#define repdm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)



int N, A, B, C;

int seq[4] = {0, 1, 2, 3};

int ANS = 100000;

int l[8];



int calcMP(vector<int> m)

{

  if (m[1] == 0 || m[2] == 0 || m[3] == 0)

    return 10000;

  return abs(A - m[1]) + abs(B - m[2]) + abs(C - m[3]);

}



int dfs(int depth, vector<int> m, int mp)

{

  if (depth == 0)

  {

    mp += calcMP(m);

    return mp;

  }



  for (auto s : seq)

  {

    int tmp = mp;

    vector<int> mm = m;

    if (s != 0)

    {

      if (mm[s] == 0)

      {

        mm[s] = l[depth - 1];

      }

      else

      {

        tmp += 10;

        mm[s] += l[depth - 1];

      }

    }

    tmp = dfs(depth - 1, mm, tmp);

    ANS = min(ANS, tmp);

  }



  return ANS;

}



int main()

{

  cin >> N >> A >> B >> C;

  rep(i, N) cin >> l[i];

  int mp = 0;



  vector<int> m(4, 0);



  dfs(N, m, mp);



  cout << ANS;

}

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

using namespace std;

#define ll long long int

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

#define rrep(i,n) for( int i = n; i >= 0; i-- )

#define REP(i,s,t) for( int i = s; i <= t; i++ )

#define RREP(i,s,t) for( int i = s; i >= t; i-- )

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define INF 2000000000

#define mod 1000000007

#define INF2 1000000000000000000





int main(void)

{

    cin.tie(0);

    ios::sync_with_stdio(false);

    int N, A[3];

    cin >> N >> A[0] >> A[1] >> A[2];

    int l[8];

    rep(i, N) cin >> l[i];

    int ans = INF;

    int pattern = 1;

    rep(i, N) pattern *= 4;

    rep(bit, pattern) {

        int tmp = bit;

        vector<int> v[3];

        int sum[3] = {};

        rep(i, N) {

            if(tmp % 4 != 3) {

                v[tmp % 4].push_back(l[i]);

                sum[tmp % 4] += l[i];

            }

            tmp /= 4;

        }

        bool ok = true;

        rep(i, 3) if(v[i].size() == 0) ok = false;

        if(!ok) continue;

        int cost = 0;

        rep(i, 3) {

            cost += abs(sum[i] - A[i]);

            cost += (v[i].size() - 1) * 10;

        }

        ans = min(ans, cost);

    }

    cout << ans << endl;





    return 0;

}


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

#include <fstream>

#include <set>

#include <map>

#include <string>

#include <vector>

#include <queue>

#include <deque>

#include <stack>

#include <functional>

#include <algorithm>

#include <climits>

#include <cmath>

#include <iomanip>

using namespace std;

#define ll long long int

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

#define rrep(i,n) for( int i = n; i >= 0; i-- )

#define REP(i,s,t) for( int i = s; i <= t; i++ )

#define RREP(i,s,t) for( int i = s; i >= t; i-- )

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define INF 2000000000

#define mod 1000000007

#define INF2 1000000000000000000





int main(void)

{

    cin.tie(0);

    ios::sync_with_stdio(false);

    int N, A[3];

    cin >> N >> A[0] >> A[1] >> A[2];

    int l[8];

    rep(i, N) cin >> l[i];

    int ans = INF;

    int pattern = (1 << (N * 2));

    rep(k, pattern) {

        int cnt[3] = {};

        int bit = k;

        int sum[3] = {};

        rep(i, N) {

            int c = bit % 4;

            bit /= 4;

            if(c == 3) continue;

            cnt[c]++;

            sum[c] += l[i];

            

        }

        bool ok = true;

        int tmp = 0;

        rep(i, 3) {

            if(cnt[i] == 0) ok = false;

            tmp += (cnt[i] - 1) * 10;

            tmp += abs(A[i] - sum[i]);

        }

        if(!ok) continue;

        ans = min(ans, tmp);

    }

    cout << ans << endl;



    return 0;

}


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

 

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

#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)

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



using namespace std;

using ll  = long long;

using pll = pair<ll, ll>;



const ll MOD  = 1e9 + 7;

const ll LINF = 1LL << 62;

const int INF = 1e9 + 7;



ll n, a, b, c;

vector<ll> l(10);



//long to binary

string ternary(ll n){

    if(n == 2)return "2";

    else if(n == 1)return "1";

    else if(n == 0)return "0";



    return ternary(n/3)  + ternary(n%3);

}



ll dfs(ll n_i, string ter, vector<ll> cost, vector<ll> len){

    if(n_i >= n){

        //無から竹は作れない

        if(len[0]*len[1]*len[2] == 0){

            return INF;

        }

        //合成魔法は使う本数−１*10のコストがかかる

        rep(i, 3)cost[i] = 10 * max((ll)0, cost[i]-1);

        ll res = cost[0] + cost[1] + cost[2];



        //合成した後の誤差は延長，短縮魔法を使う

        res += abs(a - len[0]) + abs(b - len[1]) + abs(c - len[2]);

        return res;

    }



    string ter_bit = "012"; 

    ll res = INF;

    //使わない場合

    res = min(res, dfs(n_i+1, ter, cost, len));

    rep(i, 3){

        if(ter[n_i] == ter_bit[i]){

            //合成する場合

            cost[i]++;

            len[i] += l[n_i];

            res = min(res, dfs(n_i+1, ter, cost, len));

        }

    }



    return res;

}



int main(){

    cin >> n >> a >> b >> c;

    

    rep(i, n)cin >> l[i];



    ll ans = INF;

    vector<ll> cost(3, 0), len(3, 0);

    rep(i, pow(3, n)){

        //3進数，０〜２が竹A~Cに対応

        string ter = ternary(i);

        while(ter.size() != n)ter = '0' + ter;

        ans = min(ans, dfs(0, ter, cost, len));

    }



    cout << ans << endl;

}

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

 

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

#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)

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



using namespace std;

using ll  = long long;

using pll = pair<ll, ll>;



const ll MOD  = 1e9 + 7;

const ll LINF = 1LL << 62;

const int INF = 1e9 + 7;



ll n, a, b, c;

vector<ll> l(10);



ll dfs(ll n_i, ll l_a, ll l_b, ll l_c){

    if(n_i >= n){

        //無から竹は作れない

        if(l_a*l_b*l_c == 0){

            return INF;

        }

        //合成魔法は使う本数−１*10のコストがかかる

        //合成した後の誤差は延長，短縮魔法を使う

        ll res = abs(a - l_a) + abs(b - l_b) + abs(c - l_c) - 30;

        return res;

    }



    ll res = INF;

    //使わない場合

    res = min(res, dfs(n_i+1, l_a, l_b, l_c));

    //A~Bいずれかに使う場合

    res = min(res, dfs(n_i+1, l_a+l[n_i], l_b, l_c) + 10);

    res = min(res, dfs(n_i+1, l_a, l_b+l[n_i], l_c) + 10);

    res = min(res, dfs(n_i+1, l_a, l_b, l_c+l[n_i]) + 10);



    return res;

}



int main(){

    cin >> n >> a >> b >> c;

    

    rep(i, n)cin >> l[i];



    cout << dfs(0, 0, 0, 0) << endl;

}

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

using namespace std;



int main() {

	int a[3][3];

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

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

			cin >> a[i][j];

		}

	}

	int b[3]{};

	for (b[0] = 0; b[0] <= 100; b[0]++) {

		for (b[1] = 0; b[1] <= 100; b[1]++) {

			for (b[2] = 0; b[2] <= 100; b[2]++) {

				int c[3] = {a[0][0] - b[0], a[0][1] - b[0], a[0][2] - b[0]};

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

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

						if (a[i][j] != b[i] + c[j]) {

							goto next;

						}

					}

				}

				cout << "Yes" << endl;

				return 0;

				next:;

			}

		}

	}

	cout << "No" << endl;

	return 0;

}

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

using namespace std;



int main() {

	int a[3][3];

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

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

			cin >> a[i][j];

		}

	}

	int x[3]{}, y[3];

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

		y[i] = a[0][i];

	}

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

		x[i] = a[i][0] - y[0];

	}

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

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

			if (a[i][j] != x[i] + y[j]) {

				cout << "No" << endl;

				return 0;

			}

		}

	}

	cout << "Yes" << endl;

	return 0;

}

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

using namespace std;



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

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

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

#define allg(a) (a).begin(), (a).end(), greater<int>()



using vi = vector<int>;

using vvi = vector<vi>;

using vs = vector<string>;



const int INF = 1001001001;

const int MOD = 1000000007;

const long long INFL = (1LL << 60);

const double EPS = 1e-9;



int main() {

  int c[3][3];

  rep(i, 3) rep(j, 3) cin >> c[i][j];



  string res = "No";

  rep(k, 101) rep(m, 101) rep(n, 101) {

    int a[3], b[3];

    a[0] = k, a[1] = m, a[2] = n;

    b[0] = c[0][0] - a[0], b[1] = c[1][1] - a[1], b[2] = c[2][2] - a[2];

    bool skip = false;

    rep(i, 3) if (b[i] < 0) skip = true;

    if (skip) continue;

    int cnt = 0;

    rep(i, 3) rep(j, 3) {

      if (c[i][j] != a[i] + b[j]) continue;

      cnt++;

    }

    if (cnt == 9) {

      res = "Yes";

      goto RES;

    }

  }



RES:

  cout << res << endl;

}

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

using namespace std;



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

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

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

#define allg(a) (a).begin(), (a).end(), greater<int>()



using vi = vector<int>;

using vvi = vector<vi>;

using vs = vector<string>;



const int INF = 1001001001;

const int MOD = 1000000007;

const long long INFL = (1LL << 60);

const double EPS = 1e-9;



int main() {

  int c[3][3];

  rep(i, 3) rep(j, 3) cin >> c[i][j];



  string res = "No";

  rep(k, 101) rep(m, 101) rep(n, 101) {

    int a[3], b[3];

    a[0] = k, a[1] = m, a[2] = n;

    b[0] = c[0][0] - a[0], b[1] = c[1][1] - a[1], b[2] = c[2][2] - a[2];

    int cnt = 0;

    rep(i, 3) rep(j, 3) {

      if (c[i][j] != a[i] + b[j]) continue;

      cnt++;

    }

    if (cnt == 9) {

      res = "Yes";

      goto RES;

    }

  }



RES:

  cout << res << endl;

}

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

using namespace std;



int main(void){

    int c[3][3];

    int tr[3][3]={};

    int a[3]={};

    bool ans=false;

    int con=0;

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

        cin >> c[i][0]>>c[i][1]>>c[i][2];

    }

    for(a[0]=0;a[0]<=100;a[0]++){

        for (a[1] = 0; a[1] <= 100; a[1]++){

            for (a[2] = 0; a[2] <= 100; a[2]++){

                con=0;

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

                    

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

                        tr[i][j]=c[i][j]-a[j];

                    }

                    if(tr[i][0]==tr[i][1] and tr[i][1]==tr[i][2]){

                        con++;

                    }

                }

                

                if(con==3){

                    ans=true;

                    goto fin;

                }

                

            }

        }

    }

    fin:

    if(ans){

        cout <<"Yes"<<endl;

    }else{

        cout <<"No"<<endl;

    }

}

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

using ll = long long;

using namespace std;

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

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

#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)

#define rreps(i,n) for(int i=((int)(n));i>0;i--)

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

#define F first

#define S second

#define mp make_pair

#define pb push_back

#define solve(a) ((a)?"Yes":"No")

typedef vector<long long> V;

typedef vector<V> VV;

typedef pair<long long , long long> P;

typedef vector<P> VP;

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

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

const long long INFLL = 1LL<<62;

const int INF = 1<<30;

const double PI=acos(-1);

int main(){

	VV c(3,V(3));

	V isum(3,0);

	V jsum(3,0);

	int ans=1;

	rep(i,3){

		rep(j,3){

			cin>>c[i][j];

			isum[i]+=c[i][j];

			jsum[j]+=c[i][j];

		}

	}

	ll mi=min(isum[0],min(isum[1],isum[2]));

	ll mj = min(jsum[0],min( jsum[1], jsum[2]));

	rep(i,3){

		isum[i]-=mi;

		jsum[i]-=mj;

		if(isum[i]%3!=0 or jsum[i]%3!=0){

			ans=0;

		}

	}

	cout<<solve(ans)<<endl;

}

// Fastest known solution for this problem: