akhauriyash/Code-Regression huggingface dataset:
import bisect
import sys
input = sys.stdin.readline
N = int(input())
list = list(map(int, input().split()))
list.sort()

score = 0

for i in range (N-2):
    for j in range (i+1, N-1):
        index = bisect.bisect_left(list, list[i] + list[j]) - j - 1
        score += index

print (score)


Measured memory_bytes: 3188
# encoding: utf-8
c = [list(map(int, input().split())) for i in range(3)]

# a1 - a2
ans = "Yes"

for i in range(2):
    if c[0][i + 1] - c[0][i] == c[1][i + 1] - c[1][i] == c[2][i + 1] - c[2][i]: ans = ans
    else: ans = "No"

for i in range(2):
    if c[i + 1][0] - c[i][0] == c[i + 1][1] - c[i][1] == c[i + 1][2] - c[i][2]: ans = ans
    else: ans = "No"

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-10;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

vs teams;
unordered_map<string, int> mp;
set<string> usedt, usedm;
vector<vs> v;

void solve(string s)
{
	int n = mp[s];
	REP(i, v[n].size())
	{
		string tmp = v[n][i];
		if (mp.find(tmp) == mp.end()) usedm.insert(tmp);
		else if (usedt.find(tmp) == usedt.end())
		{
			usedt.insert(tmp);
			solve(tmp);
		}
	}
}

int main()
{
	int n;
	while (cin >> n, n)
	{
		v.clear();
		v.resize(n);
		teams.clear();
		usedt.clear();
		usedm.clear();
		mp.clear();
		REP(i, n)
		{
			string s;
			cin >> s;
			int p = s.find(':');
			string team = s.substr(0, p);
			teams.push_back(team);
			mp[team] = i;
			s = s.substr(p+1);
			while (s.find(',') != string::npos)
			{
				p = s.find(',');
				v[i].push_back(s.substr(0, p));
				s = s.substr(p+1);
			}
			p = s.find('.');
			v[i].push_back(s.substr(0, p));
		}
		solve(teams[0]);
		cout << usedm.size() << endl;
	}
	return 0;
}

Measured memory_bytes: 3160
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<deque>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<tuple>
#include<utility>
#include<vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<vector<int>> vvi;

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define REP(i, n)  for(int i=0; i<(int)(n); i++)
#define REPS(i, n)  for(int i=1; i<=(int)(n); i++)
#define PER(i, n) for(int i=(int)(n)-1; i>= 0; i--)
#define PERS(i, n)  for(int i=(int)(n); i>0; i--)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
#define RFOR(i, c)  for(__typeof((c).rbegin()) i=(c).rbegin(); i!=(c).end(); i++)
#define ALL(container)  (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) (container).size()
#define FILL0(n)  setfill('0') << right << setw(n)
#define mp(a, b)  make_pair(a, b)
#define toLower(c)  c+0x20
#define toUpper(c)  c-0x20
#define pb  push_back
#define eb  emplace_back

const int INF = 1e9;
const long long LLINF = 1e18;
const int MOD = 1000000007;
const int MSIZE = 100000;
const double Pi = 3.14159265358979323146;

int main(){
  int n;  cin >> n;
  map<int, int> mp;
  REP(i, n){
    int a;  cin >> a;
    mp[a]++;
  }
  int sum=0;
  for(auto it=mp.begin(); it!=mp.end(); it++){
    sum += it->second-1;
  }
  if(sum%2) cout << mp.size()-1 << endl;
  else cout << mp.size() << endl;
}


Measured memory_bytes: 4992
using System;

namespace ABC166C
{
    class Program
    {
        static void Main(string[] args)
        {
            var mo = Console.ReadLine().Split(" ");
            ulong n = ulong.Parse(mo[0]);
            ulong m = ulong.Parse(mo[1]);
            ulong[] h = new ulong[n + 1];
            ulong[] z = new ulong[n + 1];
            ulong[] a = new ulong[m + 1];
            ulong[] b = new ulong[m + 1];
            ulong[] d = new ulong[n + 2];
            ulong y = 0;
            var mm = Console.ReadLine().Split(" ");
            for (ulong i = 1; i <= n; i++)
                h[i] = ulong.Parse(mm[i - 1]);
            ulong x = 0;
            for (ulong i = 1; i <= m; i++)
            {
                var aa = Console.ReadLine().Split(" ");
                a[i] = ulong.Parse(aa[0]);
                b[i] = ulong.Parse(aa[1]);
               
            }



            for (ulong i = 1; i <= m; i++)
            {
                if (h[a[i]] < h[b[i]])
                { 
                    z[a[i]] = 1;
                }
                if (h[b[i]] < h[a[i]])
                {
                    z[b[i]] = 1;
                }
                if(h[a[i]]==h[b[i]])
                {
                    z[a[i]] = 1;
                    z[b[i]] = 1;
                }

                //d[a[i]] = 1;
                //d[b[i]] = 1;
            }
            //for (ulong i = 1; i <= n; i++)
            //{
            //    y += d[i];
            //    Console.Write(d[i]);
            //}
            //y = n - y;
            //Console.WriteLine();

            for (ulong i = 1; i <= n; i++)
            {
                //Console.Write(z[i]);
                if (z[i] == 1)
                    x += 1;
            }
            //Console.WriteLine();
            //Console.WriteLine(y);
            Console.WriteLine(n-  x );



        }
    }
}

Measured memory_bytes: 35516
#include <utility>
#include <vector>
#include <iostream>
#include <cstdlib>
#include <bits/stdc++.h>
#include <limits>
#include <set>
#include <map>
#include <string>
#include <sstream>
#include <stdio.h>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef unsigned long long ull;
ull gcd(ull a, ull b){return b? gcd(b, a%b):a;}
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
	ll H, W;
	cin >> H >> W;

	ll half = 0;
	if(H%2==0){
		half = H/2;
	}else{
		half = H/2 + 1;
	}

	ll ans = 0;
	if(H==1 || W==1){
		ans = 1;
	}else if(W%2 == 0){
		ans = H * (W/2);
	}else{
		ans = H * (W/2) + half;
	}

	cout << ans << endl;

	return 0;
}


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

#define int long long

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	int h, w, k, res = 0;
	cin >> h >> w >> k;

	vector<string> a(h);
	for (int i = 0; i < h; ++i)
		cin >> a[i];

	for (int i = 0; i < (1 << h); ++i) {
		for (int j = 0; j < (1 << w); ++j) {
			vector<string> temp = a;
			int curr = 0;

			for (int x = 0; x < h; ++x)
				if ((1 << x) & i)
					for (int y = 0; y < w; ++y)
						temp[x][y] = '0';
			for (int y = 0; y < w; ++y)
				if ((1 << y) & j)
					for (int x = 0; x < h; ++x)
						temp[x][y] = '0';

			// for (int x = 0; x < h; ++x)
			// 	cout << temp[x] << '\n';
			// cout << '\n';

			for (int x = 0; x < h; ++x)
				for (int y = 0; y < w; ++y)
					if (temp[x][y] == '#')
						++curr;

			if (curr == k)
				++res;
		}
	}

	cout << res;

	return 0;
}

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

using P = pair<int, int>;

int main() {
  int N;
  cin >> N;
  map<int, int> m;
  for (int i{}; i < N; ++i) {
    int a; cin >> a;
    ++m[a];
  }

  vector<P> v;
  for (const auto& p : m)
    v.push_back(p);
  sort(v.begin(), v.end(), [](P l, P r) { return l.second < r.second; });

  int ans{};
  switch (v.size()) {
    case 1:
      if (v[0].first == 0)
        ans = true;
      break;
    case 2:
      if (v[0].second*2 == v[1].second &&
          (v[0].first ^ v[1].first) == v[1].first &&
          (v[1].first ^ v[1].first) == v[0].first)
        ans = true;
      break;
    case 3:
      if (v[0].second == v[1].second && v[1].second == v[2].second &&
          (v[0].first ^ v[1].first) == v[2].first &&
          (v[1].first ^ v[2].first) == v[0].first &&
          (v[2].first ^ v[0].first) == v[1].first)
        ans = true;
      break;
    default:
      break;
  }

  cout << (ans ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 4988
# 素数リスト生成
def sieve(x):
    if x < 2: return []
    primes = [i for i in range(x)]
    primes[1] = 0
    for p in primes:
        if p > x ** (1/2): break
        if p == 0: continue
        for np in range(2 * p, x, p): primes[np] = 0
    return [p for p in primes if p != 0]

PS = sieve(10**6)

# 素因数分解
def factorint(x):
  d = {}
  for k in PS:
    if(x % k== 0):
      m = 1
      while(x % (k**m) == 0):
        m += 1
      d[k] = m - 1
      x = x / (k ** (m - 1))
      if x == 1:
        break
  return d

n, m = map(int, input().split())
f = factorint(m)
idx = [i for i in f.values()]
# 10^6より大きい素因数があったときの処理
re = 1
for k, v in f.items():
  re *= k**v
if m // re != 1:
  idx.append(1)


def fact(n):
  ret = 1
  for i in range(1, n + 1):
    ret *= i
  return ret
def com(n, r):
  if n - r < r: r = n - r
  ret = 1
  for i in range(n-r+1, n+1):
    ret *= i
  for j in range(1, r+1):
    ret //= j
  return ret

ans = 1
for i in range(len(idx)):
  ans *= com(idx[i] + n - 1, n - 1) % (10 ** 9 + 7)

  
print(ans % (10 ** 9 + 7))

Measured memory_bytes: 114032
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int x,y;
int n;
int a[100001];
string s;
int main(){
  cin >> x >> y;
  int c=0;
  if(x<=y)cout << x << endl;
  else cout << x-1 << endl;
  
  return 0;
}


Measured memory_bytes: 256
import sys,math

n=m=int(input())
c=0
def factorint(N):
    i=2
    fct=[]
    while i**2<=N:
        if N%i!=0:
            i+=1
        else:
            N//=i
            fct.append(i)
    if N>1:
        fct.append(N)
    return fct
l1=factorint(n)
l2=list(set(l1))
#print(l1)
#print(l2)

if len(l1)==len(l2):
    ans=1
    for item in l2:
        ans*=(item-1)
else:
    l3=[]
    x=1
    for i in range(len(l2)):
        for j in range(i,len(l2)):
            if i!=j:
                l3.append(l2[i]*l2[j])
        x*=l2[i]
    l4=[n//item for item in l2]
    l5=[n//item for item in l3]
    if len(l2)>2:
        y=n//x
    else:
        y=0
    ans=(n-(sum(l4)-sum(l5)+y))
#    print(x)
#    print(l3)
#    print(l4)
#    print(l5)

print(ans)


Measured memory_bytes: 5672
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    string S;
    cin >> S;

    int i = 1;

    if (S == "RRR")
    {
        i = 3;
    }

    if (S == "RRS" || S == "SRR")
    {
        i = 2;
    }

    if (S == "SSS")
    {
        i = 0;
    }

    cout << i << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
static const int INF (1<<30);

int main() {
  string S;
  cin >> S;

  if (S[0] != 'A') {
    cout << "WA" << endl;
    return 0;
  }

  int cnt_C = 0;
  for (int i = 2; i < S.length()-1; i++) {
    if (S[i] == 'C') cnt_C++;
  }

  if (cnt_C != 1) {
    cout << "WA" << endl;
    return 0;
  }

  int cnt = 0;
  rep(i, S.length()) {
    if (S[i] >= 'a' && S[i] <= 'z') cnt++;
  }

  if (cnt == S.length()-2) cout << "AC" << endl;
  else cout << "WA" << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

int main() {
  while (true) {
    int x, y;
    cin >> x >> y;
    if (x == 0 && y == 0) break;
    int c[20][20];
    rep (i, y) rep (j, x) cin >> c[i][j];
    long long dp[20][20][3] = {};
    rep (i, x) if (c[0][i] == 0) dp[0][i][1] = 1;
    rep (i, y - 1) rep (j, x) {
      if (c[i][j] == 0) {
	long long sum = dp[i][j][0] + dp[i][j][1] + dp[i][j][2];
	if (j > 0 && c[i + 1][j - 1] != 2) dp[i + 1][j - 1][0] += sum;
	dp[i + 1][j][1] += sum;
	if (c[i + 1][j + 1] != 2) dp[i + 1][j + 1][2] += sum;
      } else if (c[i][j] == 2) {
	dp[i + 2][j][1] += dp[i][j][1];
      }
    }
    long long res = 0;
    rep (i, x) if (c[y - 1][i] != 1) rep (k, 3) res += dp[y - 1][i][k];
    rep (i, x) res += dp[y][i][1];
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1172
/**
 *    author:  Daredevil666
 *    institution: IIT Patna
**/
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define nl cout<<"\n";
#define ll long long int
#define IOS  ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
ll mod=1e9+7;
int main()
{
IOS
string s,t;
cin>>s>>t;
int cnt=0;
for(int i=0;i<s.length();i++)
{
    if(s[i]!=t[i])
        cnt++;
}
cout<<cnt;
return 0;
}


Measured memory_bytes: 3728
#include<algorithm>
#include<stack>
#include<iostream>
#include<vector>
using namespace std;
int main(){
    stack<int>S1;
    stack<pair<int,int> >S2;
    char ch;
    int sum=0,a;
    for(int i=1;cin>>ch;i++)
    {
        if(ch=='\\')S1.push(i);
        else if(ch=='/'&&S1.size()>0)
        {
            int j=S1.top();S1.pop();
            sum+=i-j;
            a=i-j;
            while(S2.size()>0&&S2.top().first>j)
            {
                a+=S2.top().second;S2.pop();
            }
            S2.push(make_pair(j,a));
        }
    }
    vector<int>ans;
    while(S2.size()>0){ans.push_back(S2.top().second);S2.pop();}
      reverse(ans.begin(),ans.end());
      cout<<sum<<endl;
      cout<<ans.size();
      for(int i=0;i<ans.size();i++)
      {
          cout<<" "<<ans[i];
      }
      cout<<endl;
      return 0;
}

Measured memory_bytes: 3228
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int maxn=-1;
	int a[15];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}	
	sort(a,a+n);
	int sum=0;
	for(int i=0;i<n-1;i++){
		sum+=a[i];
	}
	cout<<sum+a[n-1]/2<<endl;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define forr(i,p,n) for(ll i=p;i<n;i++)
#define tam 310010
#define offset 30010
using namespace std;
typedef long long  ll;
typedef pair<ll,ll> ii;
typedef pair<ll,ii> iii;
const ll MOD=1e9+7;

int main()
{
   ios::sync_with_stdio(false);cin.tie(0);
   int n;
   cin>>n;
   ll ant1,ant2,val1,val2;
   ant1=ant2=0;
   forr(i,0,n)
   {
        cin>>val1>>val2;
        ll maxx=max((ant1)/val1+(ant1%val1!=0),(ant2)/val2+(ant2%val2!=0));maxx=max(maxx,1LL);
        ant1=maxx*val1;
        ant2=maxx*val2;
   }
    cout<<ant1+ant2<<endl;   
}   


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Your code here!
    int i,j,n;
    int ans=0,sum=0;
    scanf("%d",&n);
    int a[n];
    
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    
    for(j=0;j<n;j++){
        ans = (ans+(long)a[j]*sum)%1000000007;
        sum = (sum+a[j])%1000000007;
    }
    
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 2476
N,M = map(int,input().split())
order = {}
if N==1 and M==0:
  print(0)
else:
  for i in range(M):
    s,c = map(int,input().split())
    if order.get(s,57)==57:
        order[s]=c
    elif order.get(s,57)!=57 and order[s]!=c:
        print(-1)
        break
  else:
    moji = [1]+[0]*(N-1)
    for k in order.keys():
        moji[k-1]=str(order[k])
    if N!=1 and moji[0]=='0':
      print(-1)
    else:
      ans = [str(a) for a in moji]
      print(''.join(ans))

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int a,b;
    cin >> a >> b;
    if(a>=13)
        cout << b << endl;
    else if(6<=a && a<=12)
        cout << b / 2 << endl;
    else
        cout << 0 << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int main(){
  int n;
  while(cin >> n , n){
    vector< bool > hoge(2*n,false);
    priority_queue< int, vector<int>, greater<int> > taha[2];
    for(int i = 0 ; i < n ; i++ ){
      int tmp;
      cin >> tmp;
      taha[0].push(tmp);
      hoge[tmp-1] = true;
    }
    for(int i = 0 ; i < 2 * n ; i++ ){
      if(!hoge[i]) taha[1].push(i + 1);
    }
    int ba = 0; bool ban = 0;
    while(!taha[0].empty() && !taha[1].empty()){
      vector<int> tmp;
      while(!taha[ban].empty() && ba >= taha[ban].top()){
        tmp.push_back(taha[ban].top());
        taha[ban].pop();
      }
      if(!taha[ban].empty() && taha[ban].top() > ba){ //パスじゃないじゃん
        ba = taha[ban].top();
        taha[ban].pop();
      }else{ //パスじゃん
        ba = 0;
      }
      for(int i = 0 ; i < tmp.size() ; i++ ) taha[ban].push(tmp[i]);
      ban = !ban;
    }
    cout << taha[1].size() << endl << taha[0].size() << endl;
  }
}

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

int main(void) {
  int N, M;
  cin >> N >> M;
  int L, R;
  int maxL = 0, minR = N + 1;
  for (int i = 0; i < M; i++) {
    cin >> L >> R;
    maxL = max(L, maxL);
    minR = min(R, minR);
  }
  if (minR - maxL >= 0)
    cout << minR - maxL + 1 << endl;
  else
    cout << 0 << endl;

  return 0;
}

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

bool is_prime(ll x){
    if(x<=1) return false;
    for(ll i = 2; i*i <= x; i++){
        if(x % i == 0) return false;
    }
    return true;
}

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

vector<long long> divisor(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}

int main(){
  ll a, b;
  cin >> a >> b;
  ll c = gcd(a,b);
  vector<ll> d = divisor(c);
  int ans = 1;
  rep(i, d.size()) if (is_prime(d[i])) ans++;
  cout << ans << endl;
}


Measured memory_bytes: 384
using System;


    public static class Program
    {
    static void Main()
    {
        var i = 1;
        
        var data = 1;
        while(true)
        {
            data = int.Parse(Console.ReadLine());
            if (data == 0) break;
            Console.WriteLine("Case {0}: {1}", i,data);
            i++;
            
        }
   
        
       
    }
    }




Measured memory_bytes: 17940
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <limits>

using namespace std;

template <typename T>
struct RMQ {
	T RMQ_MAX = numeric_limits<T>::max();
	vector<T> v;
	int tsize;
	RMQ(int size){
		tsize = 1;
		while (tsize < size) tsize *= 2;
		v.resize(2*tsize);
		for(auto&& x : v) x = RMQ_MAX;
	}
  void print(){
    for(auto&& x : v) cout<<x<<" ";
    cout<<endl;
  }
	void update(int i, int x) {
		i += (tsize - 1);
		v[i] = x;
		while (i > 0) {
			i = (i-1)/2;
			v[i] = min(v[i*2+1],v[i*2+2]);
		}
		return;
	}
	T sub_query(int r, int l, int rseg, int lseg, int node){
		if(l < rseg || lseg <= r) return RMQ_MAX;
		if(r <= rseg && lseg-1 <= l) return v[node];

		T rr = sub_query(r,l,rseg,(rseg+lseg)/2,node*2+1);
		T ll = sub_query(r,l,(rseg+lseg)/2,lseg,node*2+2);
		return min(rr,ll);
	}
	T query(int r, int l) {
		return sub_query(r,l,0,tsize,0);
	}
};

struct point{
	double t;
	int i;
	int x;
	int cat;
};

bool operator < (point a, point b){
	return a.t < b.t;
}

point v[600001];
int ans[200001];

int n,q;

int main(){
	cin>>n>>q;
	RMQ<int> rmq(n);
	for(int i=0;i<n;i++){
		double s,t,x;
		cin>>s>>t>>x;
		v[i*2].t = s-x-0.5;
		v[i*2].cat = 0;
		v[i*2].x = x;
		v[i*2].i = i;
		v[i*2+1].t = t-x-0.5;
		v[i*2+1].cat = 1;
		v[i*2+1].x = x;
		v[i*2+1].i = i;
	}
	for(int i=0;i<q;i++){
		double d;cin>>d;
		v[2*n+i].t = d;
		v[2*n+i].cat = 2;
		v[2*n+i].x = i;
		v[2*n+i].i = i;
	}
	sort(v,v+2*n+q);
	for(int i=0;i<2*n+q;i++){
		//cout<<v[i].t<<" "<<v[i].cat<<" "<<v[i].x<<" "<<v[i].i<<endl;
		if(v[i].cat == 0){
			rmq.update(v[i].i, v[i].x);
			//rmq.print();
		} else if(v[i].cat == 1){
			rmq.update(v[i].i, rmq.RMQ_MAX);
			//rmq.print();
		} else {
			int tmp = rmq.query(0,n-1);
			if(tmp == rmq.RMQ_MAX){
				ans[v[i].x] = -1;
			} else {
				ans[v[i].x] = tmp;
			}
		}
	}
	for(int i=0;i<q;i++){
		cout<<ans[i]<<endl;
	}
	return 0;

}

Measured memory_bytes: 18816
#include <bits/stdc++.h>
using namespace std;
#define ri register int
typedef long long ll;
#define rll register ll
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// input a letter
	template <class I>
	inline void get (I &x) {
		for (c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		x = c;
	}
	// input a string
	inline void read (char *s){
		for(c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		for(; c >= 'A' && c <= 'Z'; c = gc()) *++s = c;
		*++s = '\0';
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: gi;
using io :: get;
using io :: read;
using io :: putc;
using io :: print;
const int N=3e5+5;
int x0[N],t[N],del[N],fl[N],fr[N];
int main(){
	ri n,l,i,ans,cnt,last,pos;
	gi(n);gi(l);
	ans=n+1;
	for(i=1;i<=n;++i) gi(x0[i]);
	for(i=1;i<=n;++i)
		gi(t[i]),
		ans+=t[i]/(l<<1),
		t[i]%=l<<1;
	for(i=1;i<=n;++i){
		if(!t[i]){ // 只需要经过即可，不与别人相消也可减少1个来回 
			--ans;
			del[i]=1;
			continue;
		}
		fl[i]=2*(l-x0[i])>=t[i];
		fr[i]=2*x0[i]>=t[i];
		if(!fl[i]&&!fr[i]) // 无论如何都需要2个来回 
			del[i]=1;
	}
	ans-=fl[n]; // 不与别人相消也可减少1个来回 
	pos=n;
	cnt=0;
	for(i=1;i<n;++i){
		if(del[i]) continue;
		if(!fl[i]){
			pos=i;
			break;
			/*
			fl = 1 fr = 0 的与 fl = 0 fr = 1 的需要相消的反向不同，要分开做
			当从左向右出现第一个 fl = 0 fr = 1 的时候就不可能再出现 fl = 1 fr = 0 的了
			列式可发现 fl = 1 fr = 0 的满足 x <= l/2 而 fl = 0 fr = 1 的满足 x >= l/2
			*/
		}
		if(fr[i]) // 加入 fl = fr = 1 的待消 
			++cnt;
		else if(cnt) // fl = fr = 1 的与 fl = 1 fr = 0 的相消 
			--cnt,--ans; 
	}
	last=cnt;
	cnt=0;
	for(i=n-1;i>=pos;--i){
		if(del[i]) continue;
	//	if(!fr[i]) break;
		if(fl[i])
			++cnt;
		else if(cnt)
			--cnt,--ans;
	}
	ans-=last+cnt>>1;
	printf("%lld\n",2ll*l*ans);
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
int gcd(int a, int b){ return (a%b ? gcd(b,a%b) : b); }

int main(){
    int n,q;
    cin >> n >> q;
    string s;
    cin >> s;
    int A[n];
    A[0] = 0;
    int count=0;
    for(int i=1;i<n;i++){
        if(s.at(i-1) == 'A' && s.at(i) == 'C')count++;
        A[i] = count;
    }

    rep(i,q){
        int l,r;
        cin >> l >> r;
        cout << A[r-1] - A[l-1] << endl;
    }

    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = INT64_MAX;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;
using Vi = vector<long long int>;
typedef pair<int, int> P; typedef pair<ll, ll> PLL;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i=0;i<N;i++)
auto max(auto x,auto y){if(x>y){return x;}else{return y;}}
auto min(auto x,auto y){if(x>y){return y;}else{return x;}}
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
typedef vector<vector<ll> > matrix;
void princ(auto x){cout<<x<<" ";}; void print(auto x){cout<<x<<"\n";};
///////////////////////////////////////////////////////////////////////////////////

ll n,m;
Vi a;
bool ck[100001];
ll dp[100001];
ll calc(ll x){
    if(dp[x]!=-1)return dp[x];
    if(ck[x] || x<0)return dp[x]=0;
    if(x==0)return dp[x]=1;
    dp[x]=0;
    dp[x] += calc(x-1);
    dp[x] %= Mod;
    dp[x] += calc(x-2);
    dp[x] %= Mod;
    return dp[x];
}


int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>n>>m;
    a.resize(m);
    rep(i,n+1)ck[i]=false;
    rep(i,n+1)dp[i] = -1;
    rep(i,m){
        cin>>a[i];
        ck[a[i]] = true;
    }
    print(calc(n));
    return 0;
}

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

int main() {
	int abc[3];
	for (int i = 0; i < 3; i++) {
		cin >> abc[i];
	}
	sort(abc, abc + 3);
	int ans = abc[2] - abc[1];
	abc[0] += ans;
	if ((abc[0] - abc[2]) % 2 == 0) {
		ans += (abc[2] - abc[0]) / 2;
	}
	else {
		ans += (abc[2] - abc[0] - 1) / 2 + 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int count=0;
  char a[3];
  for(int i=0;i<3;i++)
  {
    cin>>a[i];
  }
  if(a[0]=='R' && a[1]=='R' && a[2]=='R')
      count=3;
      else
      {
    if((a[0]=='R' && a[1]=='R') || (a[1]=='R' && a[2]=='R') )
    count=2;
    else  if(a[0]=='S' && a[1]=='S' && a[2]=='S')
      count=0;
    
      else
    count=1;
      }
  cout<<count;
  return 0;
}

Measured memory_bytes: 3592
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits.h>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>

using namespace std;

#define EPS 1e-9
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert(B <= A && A <= C)
#define INF (int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))
#define MOD 1000000007
#define MP make_pair
#define PB push_back
#define PI 3.1415926535897932384626433832795
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()

typedef pair<int, int> PII;
typedef vector<int> VI;

const double pi = acos(-1.0);
typedef long int int32;
typedef long long int int64;
typedef map<int, int> MPII;
typedef multiset<int> MSETI;
typedef set<int> SETI;
typedef set<string> SETS;
typedef unsigned long int uint32;
typedef unsigned long long int uint64;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef vector<string> VS;

#define watch(x) cerr << (#x) << " is " << (x) << endl
#define printvii(v)                                    \
  cerr << (#v) << "=";                                 \
  for_each(v.begin(), v.end(), [](PII i) -> void {     \
    cerr << "(" << i.first << "," << i.second << "),"; \
  });                                                  \
  cerr << endl;
#define printvi(v)                                                       \
  cerr << (#v) << "=";                                                   \
  for_each(v.begin(), v.end(), [](int i) -> void { cerr << i << ","; }); \
  cerr << endl;

int main(int argc, char const *argv[]) {
  //freopen("boredom.in", "r", stdin);    
  //freopen("boredom.out", "w", stdout); 

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

  
  int x, a;

  cin >> x >> a;

  if(x < a) cout << 0;
  else cout << 10;

  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from collections import defaultdict
n = int(input())
d = defaultdict(int)

for _ in range(n):
    s = input()
    d[s] += 1

l = []
for k in d:
    l.append((d[k],k))
l.sort(key=lambda x:(-x[0],x[1]))
m = l[0][0]
i = 0
while i<len(l) and l[i][0]==m:
    print(l[i][1])
    i += 1

Measured memory_bytes: 59612
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#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 SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'
#define endl '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

void dfs(const int v, const int col, const vector< vector< P > >& g, vector<int>& ans){
    int nc = (col == 1 ? 2 : 1);

    for(auto e : g[v]){
        if(ans[e.second] > 0){
            continue;
        }
        ans[e.second] = nc++;
        if(nc == col){
            ++nc;
        }
        dfs(e.first, ans[e.second], g, ans);
    }

    return;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int n;
    cin >> n;

    vector< vector< P > > g(n);
    rep(i, n - 1){
        int a, b;
        cin >> a >> b;
        g[--a].emplace_back(--b, i);
        g[b].emplace_back(a, i);
    }

    vector<int> ans(n - 1);

    dfs(0, -1, g, ans);

    int k = 0;
    rep(i, n - 1){
        chmax(k, ans[i]);
    }

    cout << k << endl;
    rep(i, n - 1){
        cout << ans[i] << endl;
    }

    cout << flush;

    return 0;
}

Measured memory_bytes: 7424
<?php
while (fscanf(STDIN, "%d", $e) && $e) {
  $m = 1000000000;
  for ($z = 0; $z * $z * $z <= $e; $z++) {
    $tmp = $e - $z * $z * $z;
    $y = (int)(sqrt($tmp));
    $x = $tmp - $y * $y;
    $m = min($m, $x + $y + $z);
    /* for ($y = 0; $y * $y + $Z <= $e; $y++) { */
    /*   $Y = $y * $y; */
    /*   $x = $e - $Z - $Y; */
    /*   $sum = $x + $y + $z; */
    /*   if ($m > $sum) $m = $sum; */
    /* } */
  }
  print $m . "\n";
}

Measured memory_bytes: 6576
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stdio.h>
#include <math.h>

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef vector<vector<int>> vii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<ll> vll;

typedef pair<int, int> pii;

typedef queue<int> qi;
typedef queue<string> qs;


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

const ll MOD = pow(10, 9) + 7;


int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;

    int ans = 0;
    repp(i, 1, n-1){
        string s1 = s.substr(0, i);
        string s2 = s.substr(i, n-i);

        int cnt = 0;

        for(char c = 'a'; c <= 'z'; c++){
            if(s1.find(c)<s1.length() && s2.find(c)<s2.length()) cnt++;
        }

        ans = max(ans, cnt);
    }


    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

#define N 9
#define INF 1000000

int DFS(int X,int Y,int Z,int n);
int MIN(int a,int b);
int ABS(int x);

int l[N],A,B,C,n;

int main(void){
	int i;
	
	scanf("%d",&n);
	scanf("%d%d%d",&A,&B,&C);
	for(i=0;i<n;i++){scanf("%d",&l[i]);}
	
	printf("%d\n",DFS(0,0,0,0));
	
	return 0;
}

int DFS(int X,int Y,int Z,int depth){
	int NO_USE_POWER,SYNTHESIS_1,SYNTHESIS_2,SYNTHESIS_3;
	
	if(depth==n){
		if(X==0||Y==0||Z==0){return INF;}
		else{return (ABS(X-A)+ABS(Y-B)+ABS(Z-C)-30);}
	}
	
	NO_USE_POWER=DFS(X,Y,Z,depth+1);
	SYNTHESIS_1=DFS(X+l[depth],Y,Z,depth+1)+10;
	SYNTHESIS_2=DFS(X,Y+l[depth],Z,depth+1)+10;
	SYNTHESIS_3=DFS(X,Y,Z+l[depth],depth+1)+10;
	
	return (MIN(MIN(NO_USE_POWER,SYNTHESIS_1),MIN(SYNTHESIS_2,SYNTHESIS_3)));
}

int MIN(int a,int b){
	if(a<b){return a;}
	else{return b;}
}

int ABS(int x){
	if(x<0){return (-1*x);}
	else{return x;}
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define LL long long
#define LB long double
using namespace std;
template<typename T>void read(T &x){
	x=0;int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if (c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-48;
	x*=f;
}
int sz[200010],fa[200010];
int ans[200010];
vector<int>pe[200010];
vector<int>e[200010];
int m[200010];
void dfs(int x){
	int si=pe[x].size();
	sz[x]=1;
	for(int i=0;i<si;++i){
		int u=pe[x][i];
		if(u!=fa[x]){
			e[x].push_back(u);
			fa[u]=x;
			m[u]=max(m[x],x);
			dfs(u);
			sz[x]+=sz[u];
		}
	}
}
map<int,int>mp[200010];
int qy(int x,int mx){
	if(mp[x][mx]) return mp[x][mx];
	int rt=1;
	int si=e[x].size();
	for(int i=0;i<si;++i)
		if(e[x][i]<mx) rt+=qy(e[x][i],mx);
	mp[x][mx]=rt;
	return rt; 
}
void gtans(int x){
	int si=e[x].size();
	for(int i=0;i<si;++i){
		int u=e[x][i];
		ans[u]=ans[x];
		if(u>m[x]) ans[u]+=qy(u,m[u]);
			else ans[u]+=qy(u,m[u])-qy(u,m[x]);
		gtans(u);
	}
}
int n;
int main(){
	read(n);
	for(int i=1;i<n;++i){
		int x,y;
		read(x);read(y);
		pe[x].push_back(y);
		pe[y].push_back(x);
	}
	dfs(1);
	gtans(1);
	for(int i=2;i<=n;++i)
		printf("%d ",ans[i]);
	return 0;
}


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


int main()
{
    string s;
    cin>>s;
    int *a =  new int[26]();
    for(int i=0;i<s.length();i++)
    {
        if( a[s[i] -'a' ] != 0)
        {
            cout<<"no";
            return 0;
        }
        a[s[i]-'a']++;
    }
    cout<<"yes";
}


Measured memory_bytes: 3616
#include <iostream>
int main() {
	int H[100], W[100];
	int i= 0, j, k, l;
	
	while (1) {
		std::cin >> H[i] >> W[i];
		if (H[i] == 0 && W[i] == 0) break;
		if (H[i] < 3 && H[i] > 300 && W[i] < 3 && W[i] > 300) break;
		i++;
	}

	for (l = 0; l < i; l++) {
		for (k = 0; k < H[l]; k++) {
			for (j = 0; j < W[l]; j++) {
				if(j == 0 || j == W[l] - 1 || k == 0 || k == H[l] - 1) std::cout << "#";
				else std::cout << ".";
			}
			std::cout << std::endl;
		}
		std::cout << std::endl;
	}

	return 0;
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef bool boolean;

#define ll long long

int Mod;

typedef class Zi {
	public:
		int v;

		Zi() : v(0) {	}
		Zi(int v) : v(v) {	}
		Zi(ll x) : v(x % Mod) {	}

		friend Zi operator + (Zi a, Zi b) {
			return ((a.v += b.v) >= Mod) ? (a.v - Mod) : a; 
		}
		friend Zi operator - (Zi a, Zi b) {
			return ((a.v -= b.v) < 0) ? (a.v + Mod) : a; 
		}
		friend Zi operator * (Zi a, Zi b) {
			return 1ll * a.v * b.v;
		}
} Zi;

const int N = 5e3 + 5;

int n;
Zi f[N][N], g[N][N];

void work(Zi (*f)[N], int lim) {
	f[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < i; j++)
			f[i][j] = f[i - 1][j];
		for (int j = i; j <= n; j++) {
			f[i][j] = f[i - 1][j] + f[i][j - i];
		}
	}
	for (int i = n; i; i--) {
		Zi sum = 0;
		for (int j = lim + 1; j <= n; j++) {
			sum = sum + f[i - 1][j - lim - 1];
			f[i][j] = f[i][j] - sum;
		}
	}
}

int main() {
	scanf("%d%d", &n, &Mod);
	int hn = (n + 1) >> 1;
	Zi ans = 0;
	if (n & 1) {
		work(f, hn - 1);
		work(g, hn - 1);
	} else {
		work(f, hn);
		work(g, hn - 1);
	}
	for (int i = 0; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			g[i][j] = g[i][j] + g[i][j - 1];
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < i; j++) {
			ans = ans + f[i - 1][j] * g[n - i][i - j - 1];
		}
	}
	printf("%d\n", ans.v);
	return 0;
}


Measured memory_bytes: 196096
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
AA=[]
AA.append(A[0])
for i in range(1,N):
    AA.append(A[i])
    AA.append(A[i])
ans=0
for j in range(N-1):
    ans+=AA[j]
print(ans)

Measured memory_bytes: 31408
#include<stdio.h>

#define MAX 100

int F[MAX];

int fibonacci(int n){

  if(n == 0 || n == 1)
    return F[n] = 1;

  if(F[n])
    return F[n];

  else return F[n] = fibonacci(n - 2) + fibonacci(n - 1);
}

int main(){

  int n;

  scanf("%d", &n);

  fibonacci(n);

  printf("%d\n", F[n]);

  return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define INF 1e15
#define MOD 1000000007
int a, b, c;
signed main() {
	cin >> a >> b >> c;
	if (a == b && b == c)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static long gcd(long a, long b) {
		return b == 0 ? a: gcd(b, a % b);
	}
	
	public static long lcm(long a, long b) {
		return a / gcd(a, b) * b;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextInt();
		long D = sc.nextInt();
		System.out.println((B-A+1)-B/C+(A-1)/C-B/D+(A-1)/D+B/lcm(C,D)-(A-1)/lcm(C,D)); 
	}

}


Measured memory_bytes: 21972
N = int(input())
S = input()
A = [[],[],[]]

for i in range(N):
    if S[i] == 'R':
        A[0].append(i)
    elif S[i] == 'G':
        A[1].append(i)
    else:
        A[2].append(i)
ans = len(A[0])*len(A[1])*len(A[2])
p = 0
for i in range(N):
  for j in range(N):
    if i+j+j <= N-1:
      if S[i] != S[i+j] and S[i] != S[i+j+j] and S[i+j] != S[i+j+j]:
        p += 1

print(ans-p)

Measured memory_bytes: 73816
//recurive code hai 0/1 knapsack ka
#include<bits/stdc++.h>
#include <cstdlib>

using namespace std;
#define int long long
#define fastIO  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ip(a,n) for(int i=0;i<n;i++) cin>>a[i];
#define op(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";
#define MAX 100002

int dp[MAX][1002];

int knapsack(int wt[],int val[],int capacity,int n){
    if(n == 0 || capacity == 0) return 0;

    if(wt[n-1] <= capacity){
        return max(val[n-1] + knapsack(wt,val,capacity-wt[n-1],n-1) , knapsack(wt,val,capacity,n-1));
    }

    else return knapsack(wt,val,capacity,n-1);
}

int memoization(int wt[],int val[],int capacity,int n){
    if(n == 0 || capacity == 0) return 0;

    if(dp[capacity][n-1] != -1) return dp[capacity][n-1];

    if(wt[n-1] <= capacity){
        dp[capacity][n-1] = max( (val[n-1] + memoization(wt,val,capacity-wt[n-1],n-1) ) , memoization(wt,val,capacity,n-1));
        return dp[capacity][n-1];
    }

    else{
        dp[capacity][n-1] = memoization(wt,val,capacity,n-1);
        return dp[capacity][n-1];
    }
} 


int32_t main(){

fastIO 
int n,capacity;
cin>>n>>capacity;

int wt[n],val[n];

for(int i=0;i<n;i++){
    cin>>wt[i];
    cin>>val[i];
}
memset(dp,-1,sizeof(dp));
// cout<<knapsack(wt,val,capacity,n)<<endl;
cout<<memoization(wt,val,capacity,n)<<endl;


}

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

// clang-format off
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define endl '\n'
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

i64 binomial(i64 N, i64 K) {
  if(K < 0 || N < K) return 0;
  i64 ret = 1;
  for(i64 i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}

void solver() {
    string N;
    cin >> N;
    
    int K = input();
    int n = N.size();

    i64 ans = 0;
    range(i, 0, n) {
        int m = N[i] - '0';
        if (m == 0) continue;

        ans += (m - 1) * binomial(n - i - 1, K - 1) * pow(9, K - 1);
        ans += binomial(n - i - 1, K) * pow(9, K);
        K--;
        if (K == 0) break;
    }

    if (!K) ans++;

    cout << ans << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf -1000000000000
struct edge {long long from, to, cost;};
edge es[2005];
long long d[1100];
int over[1252];
int n,m;
int main()
{
  scanf("%d%d",&n,&m);
  for(int i=0;i<m;i++)
  {
    long long a,b,c;
    scanf("%lld%lld%lld", &a,&b,&c);
    es[i].from = a-1;
    es[i].to = b-1;
    es[i].cost =  c;
  }
  for(int i = 0; i < n; i++)
  d[i] = inf;
  d[0] = 0;
  for(int k=0;k<=n+1;k++)
  {
    for(int i=0;i<m;i++)
    {
      if(d[es[i].from] != inf && d[es[i].to] < d[es[i].from] + es[i].cost)
      {
        d[es[i].to] = d[es[i].from] + es[i].cost;
        if(k == 1+n)
        {
          over[es[i].to] = 1;
        }
      }
    }
  }
  if(over[n-1])
  printf("inf\n");
  else
  printf("%lld\n", d[n-1]);
}


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

int main(){
    int N, C, K;
    cin >> N >> C >> K;
    vector<int> T(N, 0);
    for (int i = 0; i < N; i++) {
        cin >> T.at(i);
    }
    sort(T.begin(), T.end());
    int passanger = 0;
    int clock;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (passanger == 0) {
            clock = T.at(i) + K;
            passanger++;
        } else if (clock < T.at(i)) {
            ans++;
            passanger = 1;
            clock = T.at(i) + K;
        } else {
            passanger++;
        }

        if (passanger == C) {
            ans++;
            passanger = 0;
        }
    }
    if (passanger) {
        ans++;
    }
    cout << ans << endl;
    return 0;
}


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

template<class T> void fzt(vector<T>& a) {
  int n = a.size();
  assert(__builtin_popcount(n) == 1);
  for (int i = 0; 1 << i < n; ++i) {
    for (int S = 0; S < n; ++S) if (~S & 1 << i) {
      a[S | 1 << i] += a[S];
    }
  }
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (auto&& e : a) {
    cin >> e;
  }
  vector<int> f(1 << n);
  for (int s = 0; s < 1 << n; ++s) {
    int sum = 0;
    for (int i = 0; i < n; ++i) {
      if (s >> i & 1) {
        sum += a[i];
      }
    }
    f[s] = sum == k;
  }
  fzt(f);
  int res = 0;
  for (int s = 0; s < 1 << n; ++s) {
    if (f[s] == 0) {
      res = max(res, __builtin_popcount(s));
    }
  }
  cout << n - res << '\n';
}



Measured memory_bytes: 7024
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];
    sort(h.begin(), h.end());
    ll ans = 0;
    for(int i=0; i<n-k; i++){
        ans += h[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792