akhauriyash/Code-Regression huggingface dataset:
public class Main {
    public static void main(String[] args) {

        java.util.Scanner sc = new java.util.Scanner(System.in);

        while (true) {
            int n = sc.nextInt();
            if (n == 0) { break; }

            int[] s = new int[n];
            double m = 0;
            for (int i = 0; i < n; i ++) {
                s[i] = sc.nextInt();
                m += s[i];
            }
            m /= n;

            double a = 0;
            for (int i = 0; i < n; i ++) { a += (s[i] - m) * (s[i] - m); }
            a = Math.sqrt(a / n);
            System.out.println(String.format("%10.8f", a));
        }
    }
}

Measured memory_bytes: 31256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int main () {
    
    int a,b,c,d; cin >>a>>b>>c>>d;

    if (a+b > c+d ) {
        cout << "Left" << endl;
    } else if (a+b == c+d) {
        cout << "Balanced" << endl;
    } else {
        cout << "Right" << endl;
    } 
    
    return 0;
}





Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	string s,t,m;
	int n;
	cin>>n;
	cin>>s>>t;
	for(int i=0;i<n;i++){
		m.push_back(s[i]);
		m.push_back(t[i]);
	}
	cout<<m<<endl;
	
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>

using namespace std;
typedef long long ll;

#define MAX_N 10000
int a[MAX_N];

int main() {

  // -----------------------------
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  // input
  int H, W, N;
  cin >> H;
  cin >> W;
  cin >> N;
  
  // -----------------------------

  int max_num;
  int inc;
  
  if (H >= W) {
    max_num = W;
    inc = H;
  }
  else{
    max_num = H;
    inc = W;
  }

  int count = 0;
  
  while (count < max_num) {
    count++;
    if (count * inc >= N) break;
  }

  cout << count << endl;
  
  return 0;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n, 0);
  rep(i, n) cin >> a.at(i);

  int m = 1e6 + 1;
  vector<int> cnt(m, 0);
  for (int x : a) {
    if (cnt.at(x) != 0) {
      cnt.at(x) = 2;
      continue;
    }
    for (int j = x; j < m; j += x) {
      cnt.at(j)++;
    }
  }

  int ans = 0;
  for (int x : a) {
    if (cnt.at(x) == 1) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 8020
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

struct mint {
    lint v;
    lint _mod;
    mint() : v(0) {}
    mint(signed v, lint _mod = mod) : v(v), _mod(_mod) {}
    mint(lint t, lint _mod = mod) : _mod(_mod) {
        v = t % _mod;
        if (v < 0)
            v += _mod;
    }

    mint pow(lint k) {
        mint res(1), tmp(v);
        while (k) {
            if (k & 1)
                res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    static mint add_identity() { return mint(0); }
    static mint mul_identity() { return mint(1); }
    mint inv() { return pow(_mod - 2); }

    mint &operator+=(mint a) {
        v += a.v;
        if (v >= _mod)
            v -= _mod;
        return *this;
    }
    mint &operator-=(mint a) {
        v += _mod - a.v;
        if (v >= _mod)
            v -= _mod;
        return *this;
    }
    mint &operator*=(mint a) {
        v = v * a.v % _mod;
        return *this;
    }
    mint &operator/=(mint a) { return (*this) *= a.inv(); }

    mint operator+(mint a) const { return mint(v) += a; };
    mint operator-(mint a) const { return mint(v) -= a; };
    mint operator*(mint a) const { return mint(v) *= a; };
    mint operator/(mint a) const { return mint(v) /= a; };

    mint operator-() const { return v ? mint(_mod - v) : mint(v); }

    bool operator==(const mint a) const { return v == a.v; }
    bool operator!=(const mint a) const { return v != a.v; }
    bool operator<(const mint a) const { return v < a.v; }
};
ostream &operator<<(ostream &os, mint m) { return os << m.v; }

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n, k;
    cin >> n >> k;
    vector<vector<vector<mint>>> dp(n + 1, vector<vector<mint>>(n + 1, vector<mint>(k + 1, 0)));
    dp[0][0][0] = 1;
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= n; ++j) {
            for (int l = 0; l <= k; ++l) {
                if (l >= 2 * j) {
                    if (j != 0)
                        dp[i][j][l] += dp[i - 1][j - 1][l - 2 * j];
                    dp[i][j][l] += mint(1 + 2 * j) * dp[i - 1][j][l - 2 * j];
                    if (j != n)
                        dp[i][j][l] += mint(j + 1).pow(2) * dp[i - 1][j + 1][l - 2 * j];
                }
            }
        }
    }
    cout << dp[n][0][k] << "\n";
    return 0;
}

Measured memory_bytes: 104064
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<climits>
#include<set>
#include<map>
#define ll long long
using namespace std;

int main() {
	vector<string>c(3);
	for (ll i = 0; i < 3; i++) {
		cin >> c[i];
	
	}
	ll j = 0;
	for (ll i = 0; i < 3; i++) {
		cout << c[i][j];
		j++;
	}
	cout << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
int N;
  int K;
  cin >>N>>K;
  if(N%K==0) {
cout << 0<< endl;
  }
else {
  cout << 1<< endl;
}
}

Measured memory_bytes: 256
import fractions

n, x = map(int, input().split())
x_arr = [int(_) for _ in input().split()]

x_arr.append(x)
x_arr = sorted(x_arr)
distance = [x_arr[i+1] - x_arr[i] for i in range(0, n)]

if len(distance) == 1:
    print(distance[0])
    exit()

ans = 1000000000
for i in range(len(distance)-1):
    ans = min(ans, fractions.gcd(distance[i], distance[i+1]))

print(ans)

Measured memory_bytes: 16276
A, B = map(int, input().split())

# S * 0.08 = A + a, S * 0.10 = B + b
#  A < B
# A <= S * 0.08 < A+1 B <= S * 0.10 < B+1

def getS(A, B):
    if A / 0.08 <= B / 0.10:
        start = int(A / 0.08)
        end = int((B + 1) // 0.10 + 1)
        for S in range(start, end):
            if int(S * 0.08) == A and int(S * 0.10) == B:
                return S
        return -1
    elif B / 0.10 < A / 0.08:
        start = int(B / 0.10)
        end = int((A + 1) // 0.08 + 1)
        for S in range(start, end):
            if int(S * 0.08) == A and int(S * 0.10) == B:
                return S
        return -1
    
print(getS(A, B))

Measured memory_bytes: 38384
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int n,k,l,last,ans[210000],num[210000],u,v;
struct node{
	int fa1,fa2,id;
}a[210000];
bool cmp(node a,node b)
{
	return a.fa1<b.fa1;
}
int get2(int x) 
{
	return a[x].fa2==x?x:a[x].fa2=get2(a[x].fa2);
}
void un2(int x,int y)
{
	int X=get2(x); int Y=get2(y);
	if(X!=Y) a[X].fa2=Y;
}
int get1(int x) 
{
	return a[x].fa1==x?x:a[x].fa1=get1(a[x].fa1);
}
void un1(int x,int y)
{
	int X=get1(x); int Y=get1(y);
	if(X!=Y) a[X].fa1=Y;
}
int main()
{
	scanf("%d%d%d",&n,&k,&l);
	for(int i=1;i<=n;++i) 
	{
		a[i].fa1=i;
		a[i].fa2=i;
		a[i].id=i;
	}
	for(int i=1;i<=k;++i)
	{
		scanf("%d%d",&u,&v);
		un1(u,v);
	}
	for(int i=1;i<=l;++i)
	{
		scanf("%d%d",&u,&v);
		un2(u,v);
	}
	for(int i=1;i<=n;++i) 
	{
		a[i].fa1=get1(i);
		a[i].fa2=get2(i);
	}
	sort(a+1,a+n+1,cmp);
	last=1;
	for(int i=1;i<=n;++i)
	{
		if(a[i].fa1!=a[i+1].fa1)
		{
			for(int j=last;j<=i;++j)
			{
				num[a[j].fa2]++;
			}
			for(int j=last;j<=i;++j)
			{
				ans[a[j].id]=num[a[j].fa2];
			}
			for(int j=last;j<=i;++j)
			{
				num[a[j].fa2]=0;
			}
			last=i+1;
		}
	}
	for(int i=1;i<n;++i) printf("%d ",ans[i]); printf("%d",ans[n]);
	return 0;
}

Measured memory_bytes: 4608
ans = 0
n = gets.to_i
ss = readlines.map(&:chomp).map(&:chars).map(&:sort).map(&:join)
hash = {}
for s in ss do
	hash[s] = hash.fetch(s, 0) + 1
end
hash.each_value do |v|
	ans += v * (v - 1) / 2
end
print(ans)
#print(hash)


Measured memory_bytes: 101212
#include<iostream>
#include<utility>
#include<cstdlib>
#include<string>
using namespace std;

void insert(int A[],int key);
void heapIncreaseKey(int A[],int i,int key);
int heapExtractMax(int A[]);
void maxHeapify(int A[],int i);

int Sentinel = -2000000000;
int H;
int A[2000000];

int main(){
	string command;
	cin>>command;
	int key;

	while(command!="end"){
		if(command=="insert"){
			cin>>key;
			insert(A,key);
		}else if(command=="extract"){
			cout<<heapExtractMax(A)<<endl;
		}
		cin>>command;
	}
}
	
void insert(int A[],int key){
	H++;
	A[H] = Sentinel;
	heapIncreaseKey(A,H,key);
}

void heapIncreaseKey(int A[],int i,int key){
	if(key<A[i]) exit(0);
	A[i] = key;
	int parent = i/2;
	while(i>1 && A[parent]<A[i]){
		swap(A[i],A[parent]);
		i = parent;
		parent = i/2;
	}
}

int heapExtractMax(int A[]){
	if(H<1) exit(0);
	int max = A[1];
	A[1] = A[H];
	H--;
	maxHeapify(A,1);
	return max;
}

void maxHeapify(int A[],int i){
	int left = i*2, right = left+1, largest;
	if(left<=H && A[left]>A[i])
		largest = left;
	else
		largest = i;
	if(right<=H && A[largest]<A[right])
		largest = right;

	if(largest != i){
		swap(A[i],A[largest]);
		maxHeapify(A,largest);
	}
}

Measured memory_bytes: 7004
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)

ll H, W, INF=1e9+7;
ll dx[4] = {0,0,1,-1};
ll dy[4] = {1,-1, 0, 0};

vector<string> S;

ll BFS(ll X, ll Y)
{
    queue<pair<ll, ll> > Q;
    vector<vector<ll> > Dist(H, vector<ll>(W, INF));
    Q.push({X,Y});
    Dist[X][Y] = 0;
    while(!Q.empty())
    {
        pair<ll, ll> P = Q.front();
        Q.pop();
        rep(i,4)
        {
            ll NX = P.first + dx[i];
            ll NY = P.second + dy[i];
            if (NX < 0 || H <= NX || NY < 0 || W <= NY || S[NX][NY]!='.' || Dist[NX][NY] != INF) continue;
            {
                Dist[NX][NY] = Dist[P.first][P.second] + 1;
                Q.push({NX, NY});
            }
        }
    }
    ll MAX = 0;
    rep(i,H) rep(j,W) if (Dist[i][j] != INF) MAX = max(MAX, Dist[i][j]);
    return MAX;
}

int main()
{
    cin >> H >> W;
    S.resize(H);
    rep(i,H) cin >> S[i];
    ll ANS = 0;
    rep(i,H) rep(j,W) if (S[i][j] == '.') ANS = max(ANS, BFS(i,j));
    cout << ANS << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define mm (1e16)

ll Mod=(1e9+7);

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int m,d,ans=0; cin>>m>>d;
    for(int i=22;i<=d;i++){
        int x=(i%10)*(i/10);
        if(x>=1 && x<=m && (i%10)>=2) {
            ans++;
            // cout<<i<<" ";
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))

int main() {
    string S; cin >> S;
    vector<int> a;
    int turn=(S[0]=='W' ? 0 : 1);
    a.push_back(0);
    rep(i,S.size()) {
        if (turn && S[i]=='W') {
            turn=0;
            a.push_back(0);
        }
        else if (!turn && S[i]=='B') {
            turn=1;
            a.push_back(0);
        }
    }
    cout << a.size()-1 << endl;
    return 0;
}


Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;

signed main () {
    int n;
    cin >> n;
    if (n == 0) {
        cout << 0 << '\n';
        return 0;
    }
    string ans;
    while (n) {
        if (n % (-2) == 0)
            ans += '0';
        else 
            --n, ans += '1';
        n /= -2;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << '\n';
}


Measured memory_bytes: 256
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define ull       unsigned long long
#define sd(x)     scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)
#define MAX       100005
#define maxn 	  200005
#define pb 		  push_back
#define mk 		  make_pair
#define endl	  "\n"
#define INF 	  1000000000
#define MOD		  1000000007
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int mod = 2019;

int main()
{
	ll l,r;
	cin >> l >> r;
	int ans = INF;
	for (int i=l ; i<=min(r,l+2040) ; i++)
	{
		for (int j=i+1 ; j<=min(r,l+2040) ; j++)
		{
			ans=min(ans,((i%mod)*(j%mod))%mod);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <iostream>
#include <chrono>
#include <time.h>
using namespace std;
#define ll 				long long 
#define rep(i,n) 			for(int i=0;i<n;i++)
#define vi 				vector<int>
#define vvi 			vector<vector<int>>
#define str				string
#define pb(x)           push_back(x)
#define fast_io 		ios_sync(false).sync_with_stdio.cin(false)
#define loop()			int t; cin>>t; while(t--)

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
 
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
//i donno what is above
int dp[3002][3002];
vector<char> v;
void lcs(string s, string t,int n,int m){
    for(int i=0;i<=n;i++)
        for(int j=0;j<=m;j++){
            if(i==0 || j==0)
                dp[i][j]=0;
            else if(s[i-1]==t[j-1]){
                dp[i][j]=1+dp[i-1][j-1];
            }
            else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }


}

int main(){
	


	#ifndef ONLINE_JUDGE 
	freopen ("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
   
    string s,t;
    cin>>s>>t;
    memset(dp,-1,sizeof(dp));
    lcs(s,t,s.size(),t.size());
    
    // rep(i,s.size()+1){
    // rep(j,t.size()+1) 
    // cout<<dp[i][j]<<"  "; 
    // cout<<endl;
    // }
    int i=s.size(),j=t.size();
       while(i>0 && j>0){ 
            if(s[i-1]==t[j-1] && i>0 && j>0){
                v.push_back(s[i-1]);
                // cout<<s[i-1];
                i--;j--;
            }
            else {
                if(dp[i][j-1]>dp[i-1][j] && i>0 && j>0) {
                    j--;
                }
                else if(i>0 && j>0) i--;
           }

}
    for(int d=v.size()-1;d>=0;d--)
    cout<<v[d];

	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}


Measured memory_bytes: 38860
#include<bits/stdc++.h>
using namespace std;
int a[10],ch,k,p[10],bi,ans;


int  main(){
   cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4];
   for(int i=0;i<5;i++){
        if(a[i]%10==0){
            ans+=a[i];
        }else{

            if(bi<10-(a[i]%10))bi=10-(a[i]%10);
            ans+=a[i]+10-(a[i]%10);
        }
   }
   cout<<ans-bi<<endl;




}




Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <tuple>
using namespace std;
 
#define INF 1e+16
#define MAX_V 10000
 
struct edge {
    int to;
    int cost;
};
 
// <最短距離, 頂点の番号>
using P = pair<int, int>;
 
int V;
vector<edge> G[MAX_V];
long long int d[MAX_V];
 　　
void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+V, INF);
    d[s] = 0;
    que.push(P(0, s));
 
    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
 
        for (int i=0; i<G[v].size(); ++i){
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}
 
int main() {
	cin >> V;
  	long long int ans = 0;
  	long long int adj[V][V];
  	for(int i=0;i<V;i++) for(int j=0; j<V;j++) cin >> adj[i][j];
  	priority_queue<
      	tuple<int,int,int>,
  		vector<tuple<int,int,int>>,
  		greater<tuple<int,int,int>>
    > q;
  	for(int i=0;i<V;i++) for(int j=i+1; j<V;j++) q.push(make_tuple(adj[i][j],i,j));
    while(!q.empty()){
        int c = get<0>(q.top()), b = get<1>(q.top()),  a = get<2>(q.top());
      	q.pop();
      	dijkstra(b);
      	if(d[a] < c){cout << -1 << endl; return 0;}
      	else if(d[a] > c){
        	ans = ans + c;
          	edge e1 = {a,c}, e2 = {b,c};
        	G[a].push_back(e2);
          	G[b].push_back(e1);
        }
    }

   	cout << ans << endl;
  	return 0;
}

Measured memory_bytes: 2044
#include <iostream>
using namespace std;

int main()

{
   int num, reverse = 0, remainder, temp;
   
   cin >> num;

   temp = num; 

   while( temp != 0)
   {
      remainder = temp % 10;
      reverse = reverse * 10 + remainder;
      temp = temp / 10;
   }

  

   if (num == reverse) 
      cout <<  "Yes" << endl;
   else
      cout << "No"<<endl;
   return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
x = list(map(int, input().split()))
a = 0
b = 0
ans = 0
mae = 0
b = [0] * 40
for i in range(40):
    for k in x:
        b[i] += (k & (1 << i)) >> i
c = [0] * 40
for i in range(39):
    if b[i] > n - b[i]:
        c[i+1] = c[i] + (b[i] << i)
    else:
        c[i+1] = c[i] + (n - b[i] << i)
for i in range(39, -1, -1):
    if m & (1 << i):
        ansb = mae
        ansb += b[i] << i
        ansb += c[i]
        if ans < ansb:
            ans = ansb
        mae += n-b[i] << i
    else:
        mae += b[i] << i
ans = max(ans, mae)
print(ans)


Measured memory_bytes: 63504
N = int(input())

# 約数列挙(1,N)も含まれる
prime, i = set(), 1
while i * i <= N:
    if N % i == 0:
        prime.add(i)
        prime.add(N//i)
    i += 1

#print(prime)
ans = []
for i in prime:
    if i == 1:
        continue
    i -= 1
    if N // i == N % i:
        ans.append(i)

print(sum(ans))


Measured memory_bytes: 3828
#include <bits/stdc++.h>

using namespace std;
int main(){
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << x2 + y1 - y2  << ' ' << y2 + x2 - x1 << ' ' << x1 + y1 - y2 << ' ' << y1 + x2 - x1 << endl;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	const int INF = 1010101010;
	int n, sum = 0, mn = INF;
	cin >> n;
	for(int i = 0; i < n; ++i){
		int a;
		cin >> a;
		sum += a;
		if(a % 10){ chmin(mn, a); }
	}
	
	int ans = 0;
	if(sum % 10){ ans = sum; }
	else if(mn != INF){ ans = sum - mn; }
	cout << ans << endl;
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back
 
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

int main(){
  int n,m;
  if(scanf("%d %d",&n,&m)<2){
    exit(1);
  }

  char A[51][51];
  char B[51][51];
  char s[51];
  rep(i,n){
    scanf("%s",s);
    rep(j,n)
      A[i][j] = s[j];
  }

  rep(i,m){
    scanf("%s",s);
    rep(j,m)
      B[i][j] = s[j];
  }


  int flag=0;
  rep(i,n-m+1){
    rep(j,n-m+1){

      rep(k,m){

        rep(l,m){
          if(A[i+k][j+l]!=B[k][l]) {flag=-1;break;}
          if(k==m-1&&l==m-1) flag=1;
        }

        if(flag==-1) {flag=0;break;}
        if(flag==1) break;
      }
      if(flag==1) break;
    }
    if(flag==1) break;
  }

  if(flag==1)
    printf("Yes\n");
  else
    printf("No\n");

return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>

#include<cmath>
#include<map>
#include<string>
#include<vector>
#include<algorithm> 

using namespace std;

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) std::cout << (j ? s1 : s2) << endl;
# define YES(j) std::cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define rep(n,i) for(i = 0 ; i < n ; i++)

int main()
{
    int n,k;cin >> n >> k;

    int l[51];

    for(int i=0;i<n;i++){
        cin >> l[i];
    }

    for(int i=0;i<n;i++){
        for(int j=n-1;j>i;j--){
            if(l[j]>l[j-1]){
                int tmp = l[j];
                l[j] = l[j-1];
                l[j-1] = tmp;
            }
        }
    }

    int res=0;
    for(int i=0;i<k;i++){
        res += l[i];
    }
    p(res)
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,maxi,a[1000010],cnt[1000010];
vector<int> v;
int main()
{
    for(int i=2;i<=1000;i++)
    {
        bool flag=true;
        for(int j=2;j*j<=i;j++)
        {
            if(i%j==0)
            {
                flag=false;
            }
        }
        if(flag)
        {
            v.push_back(i);
        }
    }
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",a+i);
        for(int j=0;j<v.size();j++)
        {
            if(a[i]%v[j]==0)
            {
                cnt[v[j]]++;
            }
            while(a[i]%v[j]==0)
            {
                a[i]/=v[j];
            }
        }
        if(a[i]!=1)
        {
            cnt[a[i]]++;
        }
    }
    for(int i=2;i<=1000000;i++)
    {
        maxi=max(maxi,cnt[i]);
    }
    if(maxi==n)
    {
        printf("not coprime");
    }
    else if(maxi<=1)
    {
        printf("pairwise coprime");
    }
    else
    {
        printf("setwise coprime");
    }
}


Measured memory_bytes: 11512
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,m,a[N],c[N],b[N],hs[N],tot,head[N],nex[N<<1],to[N<<1],wi[N<<1];
void add(int u,int v,int w){to[++tot]=v;nex[tot]=head[u];head[u]=tot;wi[tot]=w;}
bool vis[N],use[N];
int lowb(int x)
{
    return lower_bound(hs+1,hs+1+n,x)-hs;
}
int uppb(int x)
{
    return upper_bound(hs+1,hs+1+n,x)-hs;
}
bool dfs(int u)
{
    vis[u]=true;
    int x=c[u];
    for(int i=head[u];i;i=nex[i])
    {
        int v=to[i];
        if(!vis[v]&&dfs(v))
        {
            x^=1;use[wi[i]]=true;
        }
    }
    return x;
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%d%d",&a[i],&b[i]),hs[i]=a[i];
    sort(hs+1,hs+1+n);
    for(int i=1;i<=n;i++)
        a[i]=lowb(a[i]),c[a[i]]=b[i];
    for(int i=n+1;i>=1;i--)
        c[i]^=c[i-1];
    for(int i=1;i<=m;i++)
    {
        int l,r;scanf("%d%d",&l,&r);
        l=lowb(l);
        r=uppb(r)-1;
        if(l<=r)
        {
            //     cout<<l<<" "<<r+1<<endl;
            add(l,r+1,i),add(r+1,l,i);
        }
    }
    for(int i=1;i<=n+1;i++)
        if(!vis[i]&&dfs(i))
        {
            printf("-1\n");return 0;
        }
    int ans=0;
    for(int i=1;i<=m;i++)
        if(use[i]) ans++;
    printf("%d\n",ans);
    for(int i=1;i<=m;i++)
        if(use[i])
            printf("%d ",i);
}

Measured memory_bytes: 10880
#include <bits/stdc++.h>
using namespace std;
 
int main() {

    int n; 
    cin >> n;
    vector<int> a(n), b(n), c(n-1);
    int ans = 0;

    for(int i = 0; i < n; ++i){
        cin >> a.at(i);
    }
    for(int i = 0; i < n; ++i){
        cin >> b.at(i);
    }
    for(int i = 0; i < n-1; ++i){
        cin >> c.at(i);
    }

    for(int i = 0; i < n; ++i){
        ans += b.at(i);
    }

     for(int i = 0; i < n-1;++i){
         if(a.at(i+1) == a.at(i)+1){
             ans += c.at(a.at(i)-1);
         }
     }

    cout << ans << endl;

}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
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; }



int main(){ 
    int n, a, b; string s; cin >> n >> a >> b >> s;
    int len = s.size(), cnt = 0, b_ = 0;
    vector<string> ans(len);
    rep(i, len){
        char c = s[i];
        if(c=='c')ans[i] = "No";
        else if(c=='a'){
            if(cnt < a+b){ans[i] = "Yes"; cnt++;}
            else ans[i] = "No";
        }else{
            b_++;
            if(cnt < a+b && b_ <= b){ans[i] = "Yes"; cnt++;}
            else ans[i] = "No";
        }
    }
    rep(i, len)cout << ans[i] << ln;
}



Measured memory_bytes: 6664
#include<bits/stdc++.h>
using namespace std;
long long ans;
bool fins(string s,string t){
	int i,j;
	for(i=0,j=0;i<s.size()&&j<t.size();i++)
		if(s[i]==t[j])
			j++;
	return (j==3);
}
string aco(int x){
	string s="";
	s+=char(x/100+'0');
	s+=char(x/10%10+'0');
	s+=char(x%10+'0');
	return s;
}
int main(){
	int n;
	string s;
	cin>>n>>s; 
	for(int i=0;i<1000;i++)
		ans+=fins(s,aco(i));
	cout<<ans;
}
//d

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x, a, b;
  cin >> x >> a >> b;

  if (b <= a){
    cout << "delicious" << endl;
  }
  else if (b <= a + x){
    cout << "safe" << endl;
  }
  else {
    cout << "dangerous" << endl;
  }
}

Measured memory_bytes: 256
n,m= map(int,input().split())

s=[]
for i in range(n):
	s.append(list(map(int,input().split())))
c=[]
for i in range(m):
	c.append(list(map(int,input().split())))

for i in range(n):
	p = (abs(s[i][0]-c[0][0])+abs(s[i][1]-c[0][1]))
	q = 0
	for j in range(m-1):
		p = min(p,abs(s[i][0]-c[j][0])+abs(s[i][1]-c[j][1]))
		if abs(s[i][0]-c[j+1][0])+abs(s[i][1]-c[j+1][1])<p:
			q = j+1
	print(q+1)
		




Measured memory_bytes: 3064
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val n = readInteger()
    var baCount = 0
    var aCount = 0
    var bCount = 0
    var ans = 0L
    repeat(n) {
        val s = br.readLine()!!
        when {
            s.first() == 'B' && s.last() == 'A' -> baCount++
            s.last() == 'A' -> aCount++
            s.first() == 'B' -> bCount++
        }

        for (i in 0 until s.lastIndex) {
            if (s[i] == 'A' && s[i + 1] == 'B') ans++
        }
    }

    if (aCount > 0) {
        aCount--

        if (baCount > 0) {
            repeat(baCount) { ans++ }
        }

        if (bCount > 0) {
            ans++
            bCount--

            ans += min(aCount, bCount)
        }
    } else {
        if (baCount > 0) {
            repeat(baCount - 1) { ans++ }
            if (bCount > 0) ans++
        }
    }
    out.println(ans)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 39436
#include <stdio.h>
#define MAX 101

void serch(int);
int n, M[MAX][MAX], c[MAX], d[MAX], f[MAX], time;

int main() {
  int i, j, m, r, p;
  time = 0;
  scanf("%d",&n);
  for(i = 1; i <= n; i++) {
    for(j = 1; j <= n; j++) {
      M[i][j] = 0;
    }
  }
  for(i = 1; i <= n; i++) {
    c[i] = 0;
  }
  for(i = 1; i <= n; i++) {
    scanf("%d%d",&m,&r);
    for(j = 1; j <= r; j++) {
      scanf("%d",&p);
      M[i][p] = 1;
    }
  }

  for(i = 1; i <= n; i++) {
    if(c[i] == 0) serch(i); //???????¨?????????????????????¨????????????serch
  }
  for(i = 1; i <= n; i++) {
    printf("%d %d %d\n",i,d[i],f[i]);
  }
  return 0;
}

//????????¢?´¢
void serch(int a) {
  int i;
  c[a] = 1; //???????????£?????¨?????????????????¨???????????¨??§??¨????????????
  ++time;
  d[a] = time; //??????????¨????????????¨???
  for(i = 1; i <= n; i++) {
    if(M[a][i] == 0) continue;
    if(c[i] == 0) { //???????????£???????????£??£??????serch
      serch(i);
    }
  }
  c[a] = 2; //???????????£???????????¨???????????¨??¨????????????
  time++;
  f[a] = time;
  return;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int n,d;
  cin >> n >> d;
  int c=0;
  d=d*d;
  while(n--)
  {
    long long int x,y;
    cin >> x >> y;
    if(x*x + y*y <= d)
      c++;
  }
  cout << c;
}

Measured memory_bytes: 3632
#!/usr/bin/env python3
import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8

input = sys.stdin.buffer.readline
mod = 998244353


def I():
    return int(input())


def MI():
    return map(int, input().split())


@njit((i8, i8[:]), cache=True)
def main(N, LR):
    L, R = LR[::2], LR[1::2]
    K = len(L)

    dp = np.zeros(N + 1, np.int64)
    dpsum = np.zeros(N + 1, np.int64)
    dp[1] = 1
    dpsum[1] = 1

    for i in range(2, N + 1):
        for k in range(K):
            li = i - R[k]
            ri = i - L[k]
            if ri < 0:
                continue
            li = max(li, 1)
            dp[i] += dpsum[ri] - dpsum[li - 1]
            dp[i] %= mod
        dpsum[i] = dpsum[i - 1] + dp[i]
        dpsum[i] %= mod

    return dp[N]


N, K = MI()
LR = np.array(sys.stdin.buffer.read().split(), np.int64)

print(main(N, LR))


Measured memory_bytes: 109232
#include <stdio.h>
int main(void){
	int a, b, c, tmp;
	scanf("%d %d %d", &a, &b, &c);
	if(a>b){
		tmp = a; a = b; b =tmp; 
		if(b>c){
			tmp = b; b = c; c =tmp;
			if(a>b){
				tmp = a; a = b; b = tmp;
			}
		}
	}
	else if(a<b){
		if(b>c){
			tmp = b; b = c; c = tmp;
			if(a>b){
				tmp = a; a = b; b = tmp;
			}
		}
	}
	printf("%d %d %d\n", a, b, c);
	return 0;
}


Measured memory_bytes: 2132
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;


public class Main{

	static int[][] grid;
	static char[][] trace;
	static String s;
	static String t;
	static PrintWriter pw= new PrintWriter(System.out);
	public static void trace(int i, int j)
	{
		if(i==0 || j==0)
		{
			return;
		}
		if(trace[i][j]=='D')
		{
			trace(i-1,j-1);
			pw.print(s.charAt(i-1));
		}
		else if(trace[i][j]=='U')
		{
			trace(i-1,j);
		}
		else if(trace[i][j]=='L')
		{
			trace(i,j-1);
		}
	}
	public static void main(String[] args) throws IOException {
		BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
		s= br.readLine();
		t=br.readLine();
		grid= new int[s.length()+1][t.length()+1];
		trace=new char[s.length()+1][t.length()+1];
		for (int i = 1; i < grid.length; i++) {
			for (int j = 1; j < grid[i].length; j++) {
				if(s.charAt(i-1)==t.charAt(j-1))
				{
					grid[i][j]=grid[i-1][j-1]+1;
					trace[i][j]='D';
				}
				else if(grid[i-1][j]>=grid[i][j-1])
				{
					grid[i][j]=grid[i-1][j];
					trace[i][j]='U';
				}
				else
				{
					grid[i][j]=grid[i][j-1];
					trace[i][j]='L';
				}
			}
		}
		
		trace(s.length(),t.length());
		
		pw.close();
	}
}


Measured memory_bytes: 88788
#include<cstdio>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

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

int n,m,s,g;

const int N = 41;
const int T = (N+5)*2*6;

typedef pair<int,string> E;

vector<E> edge[N];

string dp[T][N];

void init(){
	rep(i,N)edge[i].clear();
	rep(i,T)rep(j,N)dp[i][j]="~";
}

string solve(){
	init();
	
	rep(i,m){
		int a,b;
		string c;
		cin>>a>>b>>c;
		edge[a].push_back(E(b,c));
	}
	
	dp[0][s] = "";
	
	string mini = "~";
	int maxlen = (n+3)*2*6;
	rep(i,maxlen){
		rep(j,n){
			rep(k,edge[j].size()){
				E e = edge[j][k];
				string str = dp[i][j]+e.second;
				if(dp[i+e.second.size()][e.first]>str){
					dp[i+e.second.size()][e.first]=str;
				}
				mini = min(str,mini);
			}
		}
	}
	
	string answer = "~";
	rep(i,maxlen){
		answer = min(answer, dp[i][g]);
	}
	
	//if(answer!=mini)answer="NO";
	
	if(answer=="~")answer = "NO";
	if(answer.size()>=n*6)answer = "NO";
	return answer;
}

int main(){
	
	while(1){
		cin>>n>>m>>s>>g;
		if(n==0)break;
		string str = solve();
		cout<<str<<endl;
		//break;
	}
}

Measured memory_bytes: 11304
import sys; input = sys.stdin.buffer.readline
from collections import defaultdict
import math
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

def ccw(ax, ay, bx, by, cx, cy):
	x1 = bx - ax; y1 = by - ay
	x2 = cx - ax; y2 = cy - ay
	cross = x1 * y2 - x2 * y1 
	if cross > 0:
		return 1
	elif cross < 0:
		return - 1
	else:
		return 0

class triangle(object):
	def __init__(self, Ax, Ay, Bx, By, Cx, Cy):
		self.a = ((Cx - Bx) ** 2 + (Cy - By) ** 2) ** 0.5
		self.b = ((Ax - Cx) ** 2 + (Ay - Cy) ** 2) ** 0.5
		self.c = ((Bx - Ax) ** 2 + (By - Ay) ** 2) ** 0.5
		self.alpha = math.acos((self.b ** 2 + self.c ** 2 - self.a ** 2) / (2 * self.b * self.c))
		self.preA = (self.a ** 2) * (self.b ** 2 + self.c ** 2 - self.a ** 2)
		self.preB = (self.b ** 2) * (self.c ** 2 + self.a ** 2 - self.b ** 2)
		self.preC = (self.c ** 2) * (self.a ** 2 + self.b ** 2 - self.c ** 2)
		self.Rx = (self.preA * Ax + self.preB * Bx + self.preC * Cx) / (self.preA + self.preB + self.preC)
		self.Ry = (self.preA * Ay + self.preB * By + self.preC * Cy) / (self.preA + self.preB + self.preC)
		self.R = self.a / (2 * math.sin(self.alpha))

def dist(Ax, Ay, Bx, By):
	return (((Ax - Bx) ** 2 + (Ay - By) ** 2) ** 0.5)

def judge(N, node, R, Rx, Ry):
	jud = "Yes"
	for i in range(N):
		x = node[i][0]; y = node[i][1]
		if dist(Rx, Ry, x, y) > R + 0.00001:
			jud = "No"

	if jud == "Yes":
		return R
	else:
		return INF

#処理内容
def main():
	N = int(input())
	node = []
	for i in range(N):
		x, y = getlist()
		node.append([x, y])

	if N == 2:
		R = dist(node[0][0], node[0][1], node[1][0], node[1][1]) / 2
		print(R)
		return

	ans = INF
	#2点を直径とする円
	for i in range(N):
		for j in range(i + 1, N):
			Rx = (node[i][0] + node[j][0]) / 2
			Ry = (node[i][1] + node[j][1]) / 2
			R = dist(node[i][0], node[i][1], node[j][0], node[j][1]) / 2
			ans = min(ans, judge(N, node, R, Rx, Ry))

	#3点を通る外接円
	for i in range(N):
		for j in range(i + 1, N):
			for k in range(j + 1, N):
				x1 = node[i][0]; y1 = node[i][1]
				x2 = node[j][0]; y2 = node[j][1]
				x3 = node[k][0]; y3 = node[k][1]
				if ccw(x1, y1, x2, y2, x3, y3) == 0:
					continue
				T = triangle(x1, y1, x2, y2, x3, y3)
				Rx = T.Rx; Ry = T.Ry; R = T.R
				ans = min(ans, judge(N, node, R, Rx, Ry))

	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 57708
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, sum = 0 ; 
  cin >> N ;
  
  for ( int i = 0 ; i < N ; i++ ){
  	int L,R ;
    cin >> L >> R ;
    sum += (R-L+1) ; 
  }
  cout << sum  << endl ; 
}




Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;

int main(){
	int z[101];
	int i, mode;
	
	for(int j = 0; j < 101; j++) z[j] = 0;
	
	while((scanf("%d", &i)) != EOF) z[i]++;
	
	mode = 0;
	for(int j = 1; j < 101; j++) mode = max(mode, z[j]);
	
	for(int j = 1; j < 101; j++){
		if(z[j] == mode) printf("%d\n", j);
	}
	
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int m,n,ans;char f[5050],a[5050],b[5050];
void init()
{
	cin>>m>>n;
	int a,b,c,d;
	for(int i=m;i<=n;i++){
	d=i%10;
	c=i/10%10;
	b=i/1000%10;
	a=i/10000%10;
	if(a==d&&b==c)ans++;
	}
	cout<<ans<<endl;
}
int main()
{
	init();
	return 0;
}

Measured memory_bytes: 256
n =int(input())
d,x = map(int,input().split())
a = [int(input()) for _ in range(n)]
ans = x + n
for i in range(n):
  for j in range(2,d+1):
    for k in range(d+1):
      if j == 1 + (k-1)*a[i]:
        ans += 1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define In_The_Name_Of_Allah_The_Merciful ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define Alhamdulillah return 0;
#define loop(i,k,n) for (ll i = k ; i < n ; ++i)
#define all(v) v.begin(),v.end()
#define debug(n) cerr << "[" << #n << " = " << n << "]" << endl
/*
#define T int

T Merge (const T &lf , const T &rt){
    return max (lf,rt);
}

const int N = 1e5 + 5 , M = (1 << (int) ceil(log2(N)) + 1) + 5;

T seg[M] , lazy[M];
T arr[N];
int n;
T BaseCase = -1e9;

void build (int idx = 1 , int L = 1 , int R = n){

    if (L == R){
        seg[idx] = arr[L];
        return;
    }

    int mid = L + (R-L) / 2;
    build(2*idx,L,mid);
    build(2*idx+1,mid+1,R);

    seg[idx] = Merge( seg[2*idx] , seg[2*idx+1] );

}

T query (int st , int en , int idx = 1 , int L  = 1,  int R = n){

    if (L >= st && R <= en)
        return seg[idx];

    if (L > en || R < st)
        return BaseCase;

    int mid = L + (R-L) / 2;
    return Merge (query(st,en,2*idx,L,mid),query(st,en,2*idx+1,mid+1,R));

}

void update (int goal , T val , int idx = 1, int L = 1 , int R = n){

    if (L == R){
        arr[L] = val;
        seg[idx] = arr[L];
        return;
    }

    int mid = L + (R-L) / 2;
    if (goal <= mid)
        update(goal,val,2*idx,L,mid);
    else
        update(goal,val,2*idx+1,mid+1,R);

    seg[idx] = Merge( seg[2*idx] , seg[2*idx+1] );

}
*/
void Suhaib_Sawalha (){

    int n;
    cin >> n;
    int a[n];
    for (int i = 0 ; i < n ; ++i)
        cin >> a[i];
    sort(a,a+n,greater<int>());

    vector <int> v;
    ll ans = 0;
    for (int i = 0 ; i < n ; ++i){
        v.push_back(a[i]);
        if (i)
            v.push_back(a[i]);
    }

    for (int i = 0 ; i < n-1 ; ++i)
        ans += v[i];
    cout << ans;

}

int main(){
                                In_The_Name_Of_Allah_The_Merciful   /* بسم الله الرحمن الرحيم  */
#ifndef ONLINE_JUDGE
    freopen("SuhaibSawalha1.txt","r",stdin);
#endif
//int _;for(cin>>_;_;--_,cout<<'\n')
        Suhaib_Sawalha();
                                         Alhamdulillah                    /* الحمد لله */
}


Measured memory_bytes: 6088
#include <bits/stdc++.h>
using namespace std;

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll r;
  cin >> r;

  if(r < 1200)
    cout << "ABC";
  else if(r < 2800)
    cout << "ARC";
  else
    cout << "AGC";

  cout << endl;
  
  
}


Measured memory_bytes: 256
N, A, B, C, D = map(int, input().split())
S = str(input())
ng = False

if '##' in S[A:C-1] or '##' in S[B:D-1]:
  ng=True
if (not ng) and (B<C and D<C):
  if '...' in S[B-1:D+1]: pass
  elif S[B-2:B+1]=='...' and A<=B-1: pass
  else: ng = True

if ng: print('No')
else: print('Yes')

Measured memory_bytes: 3636
import bisect
import collections
import itertools


def getint(): return int(input())
def getints(): return list(map(int, input().split()))
def getint2d(rows): return [getints() for _ in range(rows)]
def getgrid(rows): return [input() for _ in range(rows)]
def array1d(n, value): return [value for _ in range(n)]
def array2d(n, m, value): return [array1d(m, value) for _ in range(n)]

a,b,c=getints()
move = min(a-b,c)
print(c-move)

Measured memory_bytes: 38256
/*
	  Ashraful Islam Paran
	  22-August-2020
	  19:36:48
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(n) for (int i = 0; i < n; i++)
#define fo(i, x, n) for (int i = x; i < n; i++)
#define fb(i, x, n) for (int i = n - 1; i <= 0; i--)
#define w(t) int t; cin >> t; while (t--)



typedef unsigned long long ull;
typedef vector<long long> vi;
#define ull unsigned long long
#define msi map<string, long long>
#define mii map<long long, long long>
const int MX = 2e5 + 5;
const int INF = 1e18;
#define pb push_back
#define endl "\n"
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define all(x) x.begin(), x.end()
#define ff first
#define ss second


int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	// online submission
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	double d,e,f,m,n,p,x,y,z,t,i,j,k;
    cin>>n>>x>>t;
    d=ceil(n/x);
    int c=d*t;
    cout<<c<<endl;
	
	
	
	cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
	return 0;
}

Measured memory_bytes: 3772
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <tuple>
#include <utility>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <map>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};

int main()
{
    int q;
    cin>>q;
    vector<int> v;
    while(q--){
        int a;
        cin>>a;
        if(a==0){
            int x;
            cin>>x;
            v.push_back(x);
        }
        else if(a==1){
            int x;
            cin>>x;
            cout << v[x]<<endl;
        }
        else{
            v.pop_back();
        }

    }
    return 0;
}



Measured memory_bytes: 3928
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
  
using namespace std;

typedef long long ll;

class Point {
public:
  ll x, y;
  
  Point () {}
  Point ( ll x = 0, ll y = 0 ) : x(x), y(y) {}
  
  Point operator - ( const Point &p ) const { return Point(x - p.x, y - p.y); }
};
  
typedef Point Vector;
  
typedef vector<Point> Polygon;
  
ll dot( Vector a, Vector b ) { return a.x*b.x + a.y*b.y; }
ll cross( Vector a, Vector b ) { return a.x*b.y - a.y*b.x; }

/*
  contain: 2
  on segment: 1
  the other case: 0
*/
int
pointInPolygon(Polygon G, Point p) {
  
  int n = G.size();
  bool x = false;
  
  for(int i=0; i<n; i++) {
    Vector V1 = G[i] - p, V2 = G[(i+1)%n] - p;
    
    if( V1.y > V2.y ) swap(V1, V2);
    if( V1.y <= 0 && 0 < V2.y && cross(V1, V2) > 0 ) x = !x;
    if( llabs(cross(V1, V2)) == 0 && dot(V1, V2) <= 0 ) return 1;
  }
  return (x?2:0);
}
  
int
main() {
  int n, q;
  ll x, y;
    
  Polygon G;
  cin >> n;
    
  for(int i=0; i<n; i++) {
    cin >> x >> y;
    G.push_back(Point(x, y));
  }
    
  cin >> q;
  for(int i=0; i<q; i++) {
    cin >> x >> y;
    cout << pointInPolygon(G, Point(x, y)) << endl;
  }
  return 0;
}

Measured memory_bytes: 1212
#include<stdio.h>
#include<stdlib.h>

int compare(const void *a,const void *b){
	return *(int*)a - *(int*)b;
}

int main(){
  int n = 0;
  int s[100] = {};
  int i = 0;
  int sum = 0;
  int flag = 1;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&s[i]);
  }
  qsort(s,n,sizeof(int),compare);
  for(i=0;i<n;i++){
    sum += s[i];
  }
  if(sum % 10 != 0){
    sum = sum;
  }else{
    for(i = 0;i < n;i++){
      if(s[i] % 10 != 0){
        flag = 0;
        sum = sum - s[i];
        break;
      }
    }
    if(flag){
      sum = 0;
    }
  }
  printf("%d",sum);  
  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#define N 200005

int n;
int a[N], cnt[N];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", a + i);
        ++cnt[a[i]];
    }
    long long ans = 0;
    for (int i = 1; i <= n; ++i) ans += (long long)cnt[i] * (cnt[i] - 1) >> 1;
    for (int i = 1; i <= n; ++i) printf("%lld\n", ans - cnt[a[i]] + 1);
    return 0;
}

Measured memory_bytes: 3584
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    string s; cin>>s;
    int a=0,b=0,c=0;
    for (int i=0;i<sz(s);i++){
    	if (s[i]=='a') a++;
    	if (s[i]=='b') b++;
    	if (s[i]=='c') c++;
    } 
    if (max({a,b,c})-min({a,b,c})>1) cout << "NO" << endl;
    else cout << "YES" << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3752