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

#include <queue>

#include <tuple>

#include <vector>

#include <iostream>

#include <algorithm>

using namespace std;

int n, m, c, a, b;

int main() {

	ios::sync_with_stdio(false);

	while (cin >> n >> m, n | m) {

		vector<vector<pair<int, int> > > v(n);

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

			cin >> c;

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

				cin >> a >> b;

				v[i].push_back(make_pair(a, b));

			}

		}

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

		for (int i = 0; i < n; i++) d[i] = vector<vector<int> >(v[i].size(), vector<int>(m + 1, 999999999));

		priority_queue<tuple<int, int, int, int> > que; // (dist, y, x, z)

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

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

				d[i][j][i] = 0;

				que.push(make_tuple(0, i, j, i));

			}

		}

		while (!que.empty()) {

			tuple<int, int, int, int> t1 = que.top(); que.pop();

			int a1 = -get<0>(t1), b1 = get<1>(t1), c1 = get<2>(t1), d1 = get<3>(t1);

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

				if (i == 2 && d1 == m) continue;

				for (int j = 0; j < v[b1 + i].size(); j++) {

					int s = abs(v[b1][c1].first - v[b1 + i][j].first) * (v[b1][c1].second + v[b1 + i][j].second);

					if (d[b1 + i][j][d1 + i - 1] > a1 + s) {

						d[b1 + i][j][d1 + i - 1] = a1 + s;

						que.push(make_tuple(-d[b1 + i][j][d1 + i - 1], b1 + i, j, d1 + i - 1));

					}

				}

			}

		}

		int ret = 999999999;

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

			for (int j = 0; j < v[n - i - 1].size(); j++) {

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

					ret = min(ret, d[n - i - 1][j][k]);

				}

			}

		}

		cout << ret << endl;

	}

}

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

#include <cstdio>

#include <algorithm>

#pragma warning(disable : 4996)

using namespace std;

int n, m, c[155], p[155][15], v[155][15], dp[155][15][79];

int main() {

	while (scanf("%d%d", &n, &m), n) {

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

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

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

		}

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

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

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

					dp[i][j][k] = 999999999;

					for (int l = 0; l < c[i - 1]; l++) {

						dp[i][j][k] = min(dp[i][j][k], dp[i - 1][l][k] + abs(p[i][j] - p[i - 1][l]) * (v[i][j] + v[i - 1][l]));

					}

					if (k == 0) continue;

					if (i == 1) {

						dp[i][j][k] = 0;

						continue;

					}

					for (int l = 0; l < c[i - 2]; l++) {

						dp[i][j][k] = min(dp[i][j][k], dp[i - 2][l][k - 1] + abs(p[i][j] - p[i - 2][l]) * (v[i][j] + v[i - 2][l]));

					}

				}

			}

		}

		int ret = 999999999;

		for (int i = 0; i < c[n - 1]; i++) ret = min(ret, dp[n - 1][i][m]);

		if (m >= 1) for (int i = 0; i < c[n - 2]; i++) ret = min(ret, dp[n - 2][i][m - 1]);

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

	}

	return 0;

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

#include <string.h>

#include <math.h>

#include <iostream>

#include <algorithm>

#include <string>

#include <vector>

#include <set>

#include <queue>

#include <map>

#include <unordered_map>

using namespace std;



typedef long long ll;

typedef pair<int, int> pii;



const int maxn = 1e5 + 10;

const int INF = 0x3f3f3f3f;

const ll LL_INF = 0x3f3f3f3f3f3f3f3f;



#define dbg(x1) cout<<#x1<<" = "<<(x1)<<endl

#define dbg2(x1,x2) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<endl

#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<" "<<#x3<<" = "<<(x3)<<endl

int dp[200][20000];

int a[maxn];

int main() {

    //freopen(".in", "r", stdin);

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

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

    dp[0][0]=1;

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

    {

        for(int j=0;j<=10000;j++) dp[i][j]=dp[i-1][j];

        for(int j=a[i];j<=10000;j++)

        {

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

        }

    }

    int ans=0;

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

    {

        if(dp[n][i]&&(i%10!=0)) ans=i;

    }

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

    return 0;

}




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

using namespace std;

#define ll long long

int main()

{

    ll t,n,i,j,k,x,sum=0;

    cin>>n;

    vector<ll> vi;

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

        cin>>x;

        vi.push_back(x);

        sum+=x;

    }

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

    ll flag =0;

    if(sum%10 == 0){

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

    {

        ll x= vi[i];

        if(x%10 !=0)

        {

            sum-=x;

            flag = 1;

            break;

        }

    }

    if(flag == 1)

    cout<<sum<<endl;

    else

        cout<<0<<endl;

    }

    else

        cout<<sum<<endl;

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

#include <string.h>

#include <math.h>

#include <iostream>

#include <algorithm>

#include <string>

#include <vector>

#include <set>

#include <queue>

#include <map>

#include <unordered_map>

using namespace std;



typedef long long ll;

typedef pair<int, int> pii;



const int maxn = 1e5 + 10;

const int INF = 0x3f3f3f3f;

const ll LL_INF = 0x3f3f3f3f3f3f3f3f;



#define dbg(x1) cout<<#x1<<" = "<<(x1)<<endl

#define dbg2(x1,x2) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<endl

#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<" "<<#x3<<" = "<<(x3)<<endl

int dp[200][20000];

int a[maxn];

int main() {

    //freopen(".in", "r", stdin);

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

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

    dp[0][0]=1;

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

    {

        for(int j=0;j<=10000;j++) dp[i][j]=dp[i-1][j];

        for(int j=a[i];j<=10000;j++)

        {

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

        }

    }

    int ans=0;

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

    {

        if(dp[n][i]&&(i%10!=0)) ans=i;

    }

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

    return 0;

}




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

using namespace std;

int a[105];

int main()

{

    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int i,n,m,s=0;

    cin>>n;

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

    {

        cin>>a[i];

        s+=a[i];

    }

    sort(a,a+n);

    if((s%10)==0)

    {

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

        {

            if((a[i]%10)!=0)

            {

                cout<<(s-a[i])<<"\n";

                return 0;

            }

        }

        cout<<"0\n";

    }

    else

    {

        cout<<s<<"\n";

    }

    return 0;

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

#include <string.h>

#include <math.h>

#include <iostream>

#include <algorithm>

#include <string>

#include <vector>

#include <set>

#include <queue>

#include <map>

#include <unordered_map>

using namespace std;



typedef long long ll;

typedef pair<int, int> pii;



const int maxn = 1e5 + 10;

const int INF = 0x3f3f3f3f;

const ll LL_INF = 0x3f3f3f3f3f3f3f3f;



#define dbg(x1) cout<<#x1<<" = "<<(x1)<<endl

#define dbg2(x1,x2) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<endl

#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<" "<<#x3<<" = "<<(x3)<<endl

int dp[200][20000];

int a[maxn];

int main() {

    //freopen(".in", "r", stdin);

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

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

    dp[0][0]=1;

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

    {

        for(int j=0;j<=10000;j++) dp[i][j]=dp[i-1][j];

        for(int j=a[i];j<=10000;j++)

        {

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

        }

    }

    int ans=0;

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

    {

        if(dp[n][i]&&(i%10!=0)) ans=i;

    }

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

    return 0;

}




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

using namespace std;



typedef long long ll;

typedef pair<int, int> pii;

typedef pair<int, pii> pipii;

typedef pair<pii, pii> piipii;



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

#define sz(a) (int)(a).size()

#define eb emplace_back



int dp[105][10], a[105];

int main(){

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

    int n;

    scanf("%d", &n);

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

    dp[0][0] = 0;

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

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

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

            int nt = (j+a[i])%10;

            dp[i][nt] = max(dp[i][nt], dp[i-1][j] + a[i]);

            dp[i][j] = max(dp[i][j], dp[i-1][j]);

        }

    }

    int ans = 0;

    for(int j=1;j<10;j++) ans = max(ans, dp[n][j]);

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

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

#include <string.h>

#include <math.h>

#include <iostream>

#include <algorithm>

#include <string>

#include <vector>

#include <set>

#include <queue>

#include <map>

#include <unordered_map>

using namespace std;



typedef long long ll;

typedef pair<int, int> pii;



const int maxn = 1e5 + 10;

const int INF = 0x3f3f3f3f;

const ll LL_INF = 0x3f3f3f3f3f3f3f3f;



#define dbg(x1) cout<<#x1<<" = "<<(x1)<<endl

#define dbg2(x1,x2) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<endl

#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<" "<<#x3<<" = "<<(x3)<<endl

int dp[200][20000];

int a[maxn];

int main() {

    //freopen(".in", "r", stdin);

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

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

    dp[0][0]=1;

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

    {

        for(int j=0;j<=10000;j++) dp[i][j]=dp[i-1][j];

        for(int j=a[i];j<=10000;j++)

        {

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

        }

    }

    int ans=0;

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

    {

        if(dp[n][i]&&(i%10!=0)) ans=i;

    }

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

    return 0;

}




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

	#include <algorithm>

	#include <vector>

	using namespace std;



	int main() {

		int N;

		cin >> N;

		vector<int>p;

		vector < int>t;

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

			int a;

			cin >> a;

			p.push_back(a);

			if (a % 10 != 0) {

				t.push_back(a);

			}

		}

		int suma = 0;

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

		{

			suma += p[i];

		}

		int minElement = *std::min_element(t.begin(), t.end());



		

		if (suma % 10 == 0 && !t.empty()) {

			suma -= minElement;

			cout << suma << endl;



		}

		else if (t.empty()) {

			cout << 0 << endl;

	

		}

		else cout << suma << endl;

		

		return 0;

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

#include <string.h>

#include <math.h>

#include <iostream>

#include <algorithm>

#include <string>

#include <vector>

#include <set>

#include <queue>

#include <map>

#include <unordered_map>

using namespace std;



typedef long long ll;

typedef pair<int, int> pii;



const int maxn = 1e5 + 10;

const int INF = 0x3f3f3f3f;

const ll LL_INF = 0x3f3f3f3f3f3f3f3f;



#define dbg(x1) cout<<#x1<<" = "<<(x1)<<endl

#define dbg2(x1,x2) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<endl

#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<" "<<#x3<<" = "<<(x3)<<endl

int dp[200][20000];

int a[maxn];

int main() {

    //freopen(".in", "r", stdin);

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

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

    dp[0][0]=1;

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

    {

        for(int j=0;j<=10000;j++) dp[i][j]=dp[i-1][j];

        for(int j=a[i];j<=10000;j++)

        {

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

        }

    }

    int ans=0;

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

    {

        if(dp[n][i]&&(i%10!=0)) ans=i;

    }

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

    return 0;

}




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

	#include <algorithm>

	#include <vector>

	using namespace std;



	int main() {

		int N;

		cin >> N;

		vector < int>t;

		int suma = 0;

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

			int a;

			cin >> a;

			suma += a;

			if (a % 10 != 0) {

				t.push_back(a);

			}

		}

		int minElement = *std::min_element(t.begin(), t.end());



		

		if (suma % 10 == 0 && !t.empty()) {

			suma -= minElement;

			cout << suma << endl;



		}

		else if (t.empty()) {

			cout << 0 << endl;

		}

		else cout << suma << endl;

		

		return 0;

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

#include <string.h>

#include <math.h>

#include <iostream>

#include <algorithm>

#include <string>

#include <vector>

#include <set>

#include <queue>

#include <map>

#include <unordered_map>

using namespace std;



typedef long long ll;

typedef pair<int, int> pii;



const int maxn = 1e5 + 10;

const int INF = 0x3f3f3f3f;

const ll LL_INF = 0x3f3f3f3f3f3f3f3f;



#define dbg(x1) cout<<#x1<<" = "<<(x1)<<endl

#define dbg2(x1,x2) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<endl

#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<" "<<#x3<<" = "<<(x3)<<endl

int dp[200][20000];

int a[maxn];

int main() {

    //freopen(".in", "r", stdin);

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

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

    dp[0][0]=1;

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

    {

        for(int j=0;j<=10000;j++) dp[i][j]=dp[i-1][j];

        for(int j=a[i];j<=10000;j++)

        {

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

        }

    }

    int ans=0;

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

    {

        if(dp[n][i]&&(i%10!=0)) ans=i;

    }

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

    return 0;

}




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

using namespace std;

typedef long long ll;

int a[101];

void solve() {

	int n;

	cin >> n;

	int s = 0;

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

		cin >> a[i];

		s += a[i];

	}

	if (s % 10 == 0) {

		int mn = s;

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

			if (a[i] % 10 != 0) {

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

			}

		}

		s -= mn;

	}

	cout << s;

}



int main() {

	ios::sync_with_stdio(false);

	cin.tie(0);

	int t = 1;

	//cin >> t;

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

		solve();

	}

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

#include <algorithm>

#include <vector>

#include <queue>

#include <set>

#include <map>

#include <functional>

#define fs first

#define se second



using namespace std;

typedef long long llong;

typedef long double ld;

typedef pair<int, int> pii;

typedef pair<llong, llong> pll;

typedef pair<ld, ld> pdd;



bool dp[101][10001];

int main() {

    ios_base::sync_with_stdio(0); cin.tie(0);

    dp[0][0] = 1;

    int n, x;

    cin >> n;

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

        cin >> x;

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

            if (dp[i - 1][j]) {

                dp[i][j] = 1;

                if (j + x <= 10000) dp[i][j + x] = 1;

            }

        }

    }

    int ans = 0;

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

        if (i % 10 && dp[n][i]) {

            ans = i;

        }

    }

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

    return 0;

}

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

#include<cstdio>

#include<cstdlib>

#include<string>

#include<cstring>

#include<cmath>

#include<ctime>

#include<algorithm>

#include<utility>

#include<stack>

#include<queue>

#include<vector>

#define INF 0x3f3f3f3f

#define LL long long

const int MOD = 1E9+7;

const int N = 1000000+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 main() {

    int n;

    scanf("%d",&n);

    int sum=0;

    int minn=INF;

    bool flag=false;

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

        int x;

        scanf("%d",&x);

        sum+=x;

        if(x%10!=0){

            flag=true;

            minn=min(minn,x);

        }

    }

 

    if(!flag)

        printf("0\n");

    else{

        if(sum%10!=0)

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

        else

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

    }

 

    return 0;

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

#include <string.h>

#include <math.h>

#include <iostream>

#include <algorithm>

#include <string>

#include <vector>

#include <set>

#include <queue>

#include <map>

#include <unordered_map>

using namespace std;



typedef long long ll;

typedef pair<int, int> pii;



const int maxn = 1e5 + 10;

const int INF = 0x3f3f3f3f;

const ll LL_INF = 0x3f3f3f3f3f3f3f3f;



#define dbg(x1) cout<<#x1<<" = "<<(x1)<<endl

#define dbg2(x1,x2) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<endl

#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<" "<<#x3<<" = "<<(x3)<<endl

int dp[200][20000];

int a[maxn];

int main() {

    //freopen(".in", "r", stdin);

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

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

    dp[0][0]=1;

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

    {

        for(int j=0;j<=10000;j++) dp[i][j]=dp[i-1][j];

        for(int j=a[i];j<=10000;j++)

        {

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

        }

    }

    int ans=0;

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

    {

        if(dp[n][i]&&(i%10!=0)) ans=i;

    }

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

    return 0;

}




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

#include<cstdio>

#include<cstdlib>

#include<string>

#include<cstring>

#include<cmath>

#include<ctime>

#include<algorithm>

#include<utility>

#include<stack>

#include<queue>

#include<vector>

#define INF 0x3f3f3f3f

#define LL long long

const int MOD = 1E9+7;

const int N = 1000000+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 main() {

    int n;

    scanf("%d",&n);

    int sum=0;

    int minn=INF;

    bool flag=false;

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

        int x;

        scanf("%d",&x);

        sum+=x;

        if(x%10!=0){

            flag=true;

            minn=min(minn,x);

        }

    }

 

    if(!flag)

        printf("0\n");

    else{

        if(sum%10!=0)

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

        else

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

    }

 

    return 0;

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



using namespace std;

inline void read(long long &x) {

    char ch;

    bool flag = false;

    for (ch = getchar(); !isdigit(ch); ch = getchar())if (ch == '-') flag = true;

    for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());

    x = flag ? -x : x;

}

inline void write(long long x) {

    static const long long maxlen = 100;

    static char s[maxlen];

    if (x < 0) {   putchar('-'); x = -x;}

    if (!x) { putchar('0'); return; }

    long long len = 0; for (; x; x /= 10) s[len++] = x % 10 + '0';

    for (long long i = len - 1; i >= 0; --i) putchar(s[i]);

}



inline void read(int &x){

    char ch;

    bool flag = false;

    for (ch = getchar(); !isdigit(ch); ch = getchar())if (ch == '-') flag = true;

    for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());

    x = flag ? -x : x;

}



const int MAXN =101000;



int n;

int a[ MAXN ];

bool f[ MAXN ];



int main(){

    read(n);

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

        read(a[i]);

    f[0]=1;

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

        for (int j=MAXN-1;j>=a[i];j--)

            f[j]=f[j]||f[j-a[i]];

    for (int i=MAXN-1;i>=0;i--)

        if ( (f[i]) && ( i%10!=0) )

            {

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

                return 0;

            }

    puts("0");

    return 0;

}


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

#define LL long long

#define MEM(x,y) memset(x,y,sizeof(x))

#define MOD(x) ((x)%mod)

#define mod 1000000007

#define pb push_back

#define STREAM_FAST ios::sync_with_stdio(false)



using namespace std;

int a[107];

int main()

{

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

    int sum=0;

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

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

    a[0]=0;

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

    {

        if ((sum-a[i])%10!=0)

        {

            sum-=a[i];

            break;

        }

    }

    if (sum%10==0) sum=0;

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

    return 0;

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



using namespace std;

inline void read(long long &x) {

    char ch;

    bool flag = false;

    for (ch = getchar(); !isdigit(ch); ch = getchar())if (ch == '-') flag = true;

    for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());

    x = flag ? -x : x;

}

inline void write(long long x) {

    static const long long maxlen = 100;

    static char s[maxlen];

    if (x < 0) {   putchar('-'); x = -x;}

    if (!x) { putchar('0'); return; }

    long long len = 0; for (; x; x /= 10) s[len++] = x % 10 + '0';

    for (long long i = len - 1; i >= 0; --i) putchar(s[i]);

}



inline void read(int &x){

    char ch;

    bool flag = false;

    for (ch = getchar(); !isdigit(ch); ch = getchar())if (ch == '-') flag = true;

    for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());

    x = flag ? -x : x;

}



const int MAXN =101000;



int n;

int a[ MAXN ];

bool f[ MAXN ];



int main(){

    read(n);

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

        read(a[i]);

    f[0]=1;

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

        for (int j=MAXN-1;j>=a[i];j--)

            f[j]=f[j]||f[j-a[i]];

    for (int i=MAXN-1;i>=0;i--)

        if ( (f[i]) && ( i%10!=0) )

            {

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

                return 0;

            }

    puts("0");

    return 0;

}


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

using namespace std;



int n;

int a[205];

bool dp[105][10005];



int main()

{

    scanf("%d",&n);

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

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

    dp[0][0]=1;

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

    {

        dp[i][0]=1;

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

        {

            dp[i][j]|=dp[i-1][j];

            if(j-a[i]>=0)

                dp[i][j]|=dp[i-1][j-a[i]];

        }

    }



    for(int j=10000;j>=0;j--)

    {

        if(j==0)

        {

            printf("0\n");

            return 0;

        }

        if(j%10==0)continue;

        if(dp[n][j])

        {

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

            return 0;

        }

    }



    return 0;

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



using namespace std;

inline void read(long long &x) {

    char ch;

    bool flag = false;

    for (ch = getchar(); !isdigit(ch); ch = getchar())if (ch == '-') flag = true;

    for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());

    x = flag ? -x : x;

}

inline void write(long long x) {

    static const long long maxlen = 100;

    static char s[maxlen];

    if (x < 0) {   putchar('-'); x = -x;}

    if (!x) { putchar('0'); return; }

    long long len = 0; for (; x; x /= 10) s[len++] = x % 10 + '0';

    for (long long i = len - 1; i >= 0; --i) putchar(s[i]);

}



inline void read(int &x){

    char ch;

    bool flag = false;

    for (ch = getchar(); !isdigit(ch); ch = getchar())if (ch == '-') flag = true;

    for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());

    x = flag ? -x : x;

}



const int MAXN =101000;



int n;

int a[ MAXN ];

bool f[ MAXN ];



int main(){

    read(n);

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

        read(a[i]);

    f[0]=1;

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

        for (int j=MAXN-1;j>=a[i];j--)

            f[j]=f[j]||f[j-a[i]];

    for (int i=MAXN-1;i>=0;i--)

        if ( (f[i]) && ( i%10!=0) )

            {

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

                return 0;

            }

    puts("0");

    return 0;

}


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

#include <algorithm>

using namespace std;



const int N = 110;



int q[N];



int main()

{

    int n;

    cin >> n;



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

        cin >> q[i];



    int sum = 0;



    sort(q,q+n);



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

        sum += q[i];



        if(sum % 10 == 0)

        {

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

            {

                if(q[j] % 10 != 0)

                    {

                        sum -= q[j];

                        cout << sum << endl;

                        return 0;

                    }

            }

        }

        else  cout << sum << endl;

        if(sum % 10 == 0) cout << "0" << endl;

    return 0;

}