akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.buffer.readline
from collections import defaultdict
import heapq

def main():
    N,M = map(int,input().split())
    a = list(map(int,input().split()))
    d = defaultdict(list)
        
    I = [i for i in range(N)]
    rank = [1 for _ in range(N)]
    def root(a):
        if I[a] == a:
            return a
        else:
            I[a] = root(I[a])
            return I[a]
            
    def unite(a,b):
        pa,pb = root(a),root(b)
        ra,rb = rank[a],rank[b]
        if ra > rb:
            I[pb] = pa
        else:
            I[pa] = pb
            if ra == rb:
                rank[pb] += 1
    
    for _ in range(M):
        x,y = map(int,input().split())
        unite(x,y)
        parent = root(x)
    
    for i,num in enumerate(I):
        parent = root(num)
        heapq.heappush(d[parent],a[i])
        
    if M == N-1:
        print(0)
        exit()
    elif N < 2*(N-M-1):
        print("Impossible")
        exit()

    l = len(d.keys())
    ans = 0
    rest = []
    for use in d.values():
        ans += heapq.heappop(use)
        rest.extend(use)

    remain = 2*(N-M-1)-l
    rest.sort()
    ans += sum(rest[:remain])
    
    print(ans)
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 30892
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,int> PI;
typedef pair<P,P> PP;
#define rep(i,a,n) for(int i = a;i < n;i++)
#define LINF (ll)1e17
#define INF 1e9
#define MOD 1e9+7
#define sMOD 1e5
#define fs first
#define sc second

signed main(){
	ll n,k,cnt = 0,memo = 0,memo2 = 0;
	cin >> n >> k;
	
	if(k % 2){
		rep(i,1,n+1){
			if(i % k == 0) cnt++;
		}
		
		cout << (ll)pow(cnt,3) << endl;
	}
	else{
		rep(i,1,n+1){
			if(i % k == 0) memo++;
			else if(i % k == (k/2)) memo2++;
		}
		
		cout << (ll)pow(memo,3)+(ll)pow(memo2,3) << endl;
	}
	
	
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a, b;
    scanf("%d %d",&a,&b);
    if(a==1){
        a = a + 13;
    }
    if(b==1){
        b = b + 13;
    }
    if(a>b){
        printf("Alice\n");
    } else if(a<b){
        printf("Bob\n");
    } else {
        printf("Draw\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<math.h>
int main(void){
  int A[10000];
  int N,i,j,C,x;
  C=0;

  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
    x=0;
    for(j=2;j<=sqrt(A[i]);j++){
      if(A[i]%j==0)x++;
    }
    if(x==0)C++;
  }
  printf("%d\n",C);
  return 0;
}

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

int main () {
  int N;
  cin >> N;
  
  vector<int>C(N-1);
  vector<int>S(N-1);
  vector<int>F(N-1);
  for (int i = 0; i < N-1; i++) {
    cin >> C.at(i) >> S.at(i) >> F.at(i);
  }
  
  vector<int>time(N-1,0);
  for (int i = 0; i < N-1; i++) {
    for (int j = i; j < N-1; j++) {
      if (time.at(i) < S.at(j)){
        time.at(i) = C.at(j) + S.at(j);
      }
      else {
        if ((time.at(i)-S.at(j)) % F.at(j) == 0){
          time.at(i) += C.at(j);
        }
        else {
          time.at(i) += F.at(j)- ((time.at(i)-S.at(j)) % F.at(j)) + C.at(j);
        }
      }
    }
    cout << time.at(i) << endl;
  }
  
  cout << 0 << endl;
}
      
  

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


#define LOCAL
#define sim template <class c
#define ris return *this
#define dor > deb &operator<<
#define eni(x)                                                                  \
    sim > typename enable_if<sizeof dud<c>(0) x 1, deb &>::type operator<<(c i) \
    {
sim > struct rge
{
    c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct deb
{
#ifdef LOCAL
    ~deb()
    {
        cerr << endl;
    }
    eni(!=) cerr << boolalpha << i;
    ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
    sim dor(const c &)
    {
        ris;
    }
#endif
}
;
#define what(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
// -DLOCAL


using lint = long long int ;


int main() {
    //code
    // int t;cin>>t;
    int t = 1;
    while(t--)
    {
        lint n; cin>>n;
        lint p = 26;
        string ans="";
        while(1)
        {
            lint val = n - p;
            if(val<=0)
            {
                p/=26;
               lint d = (n+p-1)/p;

                // deb() << what(n) what(p) what(d);
               lint r = n%p;
            //    if(p>1 && r==0)
            //    {
            //        r = 26;
            //    }

               if(d == 0) d = 26;

               ans+=(char)('a' + d-1);
               
               n = r;
               break;
            }
            else{
                n-=p;
                p*=26;
            }
        }

        // cout<<n<<" "<<p<<endl;

        while(p>1)
        {
           p/=26;
           lint d = (n+p-1)/p;
           lint r = n%p;

        //   deb() << what(n) << what(p) << what(d);
        //    if(p>1 && r==0)
        //    {
        //        r = 26;
        //    }

           if(d == 0) d = 26; // possibly the only case;;;

           ans+=(char)('a' + d-1);
           n = r;
        }


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

Measured memory_bytes: 3560
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

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

const ll mod = 1e9 + 7;
const ll inf = 1e18;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input
    ll N;
    cin >> N;

    ll odd = 0;
    ll even = 0;
    FOR(i, 0, N){
        ll a;
        cin >> a;
        if(a%2==0){
            even++;
        }else{
            odd++;
        }
    }

    if(odd%2==0){
        p_yes();
    }else{
        p_no();
    }
    
    return 0;
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
int n;
int dp[maxn];

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cin>>n;
  memset(dp, inf, sizeof dp);
  dp[0]=0;


  for (int i=0; i<n; i++) {
    for (int j=1; j<=6; j++) {
      dp[i+j] = min(dp[i+j], j+dp[i]);
    }
    for (int x=6; i+x<=n; x*=6) {
      dp[i+x] = min(dp[i+x], 1+dp[i]);
    }
    for (int x=9; i+x<=n; x*=9) {
      dp[i+x] = min(dp[i+x], 1+dp[i]);
    }
  }

  cout<<dp[n]<<endl;
  

  return 0;
}


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

int n, k, x, a[10];

bool f(int n) {
	while (n > 0) {
		if (a[n % 10]) return true;
		n /= 10;
	}
	return false;
}

int main() {
	cin >> n >> k;
	while (k--) {
		cin >> x;
		a[x] = true;
	}
	while (f(n)) {n++;}
	cout << n << endl;
}


Measured memory_bytes: 256
H, W = gets.split.map(&:to_i)
grid = H.times.map { gets.chomp.split }

grid.each_with_index do |row, y|
  row.each_with_index do |str, x|
    next if str != 'snuke'

    puts "%c%d" % [(65 + x).chr, y + 1]

    exit
  end
end


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

int main () {
  char c;
  cin >> c;
  
  if ((c == 'a') || (c == 'i') || (c == 'u') || (c == 'e') || (c == 'o'))
    cout << "vowel" << endl;
  
  else {
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	int a,b,c;
	a=n/100;b=n%100/10;c=n%10;
//	cout<<a<<b<<c<<endl;
	if(a==1) a=9;
	else a=1;
	if(b==1) b=9;
	else b=1;
	if(c==1) c=9;
	else c=1;
	cout<<a*100+b*10+c<<endl; 
	return 0;
} 

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define endl '\n'

int main(int argc, char const *argv[])
{
	ios_base :: sync_with_stdio (false);
	cin.tie(0);

	int n;
	string s;
	cin >> s;
	n = s.size();
	s = "&" + s;

	if(s[1] == '0' || s[n] == '1') {
		cout << -1 << endl;
		exit(0);
 	}
 	for(int i = 1; i < n; i++) {
 		if(s[i] != s[n - i]) {
 			cout << -1 << endl;
 			exit(0);
 		}
 	}
 	int last = 1;
	for(int i = 2; i < n; i++) {
		if((n - i) < i) break;		
		if(s[i] == '1') {
			cout << i << " " << last << endl;			
			for(int j = last + 1; j < i; j++) {
				cout << i << " " << j << endl;
			}
			last = i;
		}
	} 
	cout << last + 1 << " " << last << endl;
	++last;
	for(int i = last + 1; i <= n; i++) {
		cout << last << " " << i << endl;
	}
	return 0;
}

Measured memory_bytes: 1664
import java.awt.Point;
import java.util.ArrayDeque;
import java.util.Scanner;
import java.util.*;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Set;
import java.util.HashSet;
import java.util.Collection;


 
public class Main{
	
        static final Scanner sc=new Scanner(System.in);
        static String S=sc.next();
        static int w=sc.nextInt();
        
        
        
        
        
        public static void main(String[]args){
                boolean ok=true;
                int o=0;
                while(ok){
                        if(o>S.length()-1){
                                System.out.println();
                                break;
                        }
                        System.out.print(S.charAt(o));
                        o=o+w;



                }
                
                

        }
        
        
        

		
	
}


Measured memory_bytes: 21844
S = list(input())
count = 0

for i in range(len(S)-1):
    if S[i] == S[i+1] and S[i+1] == '1':
        S[i+1] = '0'
        count += 1
    elif S[i] == S[i+1] and S[i+1] == '0':
        S[i+1] = '1'
        count += 1

print(count)


Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=300030,mod=1000000007,to[9][2]={{1,3},{2,0},{1,1},{4,6},{5,3},{4,4},{7,6},{8,6},{7,7}};
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
int n,f[maxn][9],ans;
char s[maxn];
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	f[0][0]=1;
	FOR(i,0,n-1) FOR(j,0,8){
		if(s[i+1]!='1') f[i+1][to[j][0]]=(f[i+1][to[j][0]]+f[i][j])%mod;
		if(s[i+1]!='0') f[i+1][to[j][1]]=(f[i+1][to[j][1]]+f[i][j])%mod;
	}
	FOR(i,3,8) if(i!=5) ans=(ans+f[n][i])%mod;
	printf("%d\n",ans);
}

Measured memory_bytes: 11136
#include <algorithm>
#include <iostream>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

const ll INF = LONG_LONG_MAX / 2;

vector<ll> A;

bool check(const ll v, const ll N, const ll K) {
    ll acc = 0;

    for (int i = 0; i < N; i++) {
        ll left = -1, right = N;
        ll mid;
        if (A[i] >= 0) {
            while (right - left > 1) {
                mid = left + (right - left) / 2;
                if (A[i] * A[mid] < v) {
                    left = mid;
                } else {
                    right = mid;
                }
            }
            acc += (left + 1);
            if (A[i] * A[i] < v) {
                acc--;
            }
        } else {
            while (right - left > 1) {
                mid = left + (right - left) / 2;
                if (A[i] * A[mid] < v) {
                    right = mid;
                } else {
                    left = mid;
                }
            }
            acc += N - right;
            if (A[i] * A[i] < v) {
                acc--;
            }
        }

        // printf("A[%d]: %lld, left: %lld, right: %lld, %lld\n", i, A[i], left, right, acc);
    }

    acc /= 2;

    // printf("v: %lld, acc: %lld\n", v, acc);
    return acc < K;
}

int main(void) {
    ll N, K;
    cin >> N >> K;

    A.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());

    ll left = -INF, right = INF, mid;
    while (right - left > 1) {
        mid = left + (right - left) / 2;
        if (check(mid, N, K)) left = mid;
        else right = mid;
    }

    cout << left << endl;

    return 0;
}


Measured memory_bytes: 1792
#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;

    int odd_count = 0;
    for(int i=1;i<=N;i++){
        if(i%2 == 1){
            ++odd_count;
        }
    }

    cout << (double)odd_count/N << endl;
    

    return 0;
}

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

const int pri=1000000007;


template<int mod>
struct ModInt{
	int x;

	ModInt() : x(0){}
	ModInt(long long y) : x(y>=0 ? y%mod : (mod-(-y)%mod)){}

	ModInt &operator+=(const ModInt &p){
		if((x+=p.x)>=mod)x-=mod;
		return *this;
	}
	ModInt &operator-=(const ModInt &p){
		if((x+=mod-p.x)>=mod)x-=mod;
		return *this;
	}
	ModInt &operator*=(const ModInt &p){
		x=(int)(1LL*x*p.x%mod);
		return *this;
	}
	ModInt &operator/=(const ModInt &p){
		*this*=p.inverse();
		return *this;
	}

	ModInt operator-() const{return ModInt(-x);}
	ModInt operator+(const ModInt &p) const{return ModInt (*this)+=p;}
	ModInt operator-(const ModInt &p) const{return ModInt (*this)-=p;}
	ModInt operator*(const ModInt &p) const{return ModInt (*this)*=p;}
	ModInt operator/(const ModInt &p) const{return ModInt (*this)/=p;}
	bool operator==(const ModInt &p) const{return x==p.x;}
	bool operator!=(const ModInt &p) const{return x!=p.x;}
	friend ostream &operator<<(ostream &os, const ModInt &p){return os<<p.x;}
	friend istream &operator>>(istream &is,ModInt &a){
		int t;
		is>>t;
		a=ModInt<mod>(t);
		return (is);
	}

	ModInt inverse() const{
		int a=x, b=mod, u=1, v=0, t;
		while(b>0){
			t=a/b;
			a-=t*b;
			swap(a,b);
			u-=t*v;
			swap(u,v);
		}
		return ModInt(u);
	}
	
	ModInt pow(int e) const{
		long long a=1,p=x;
		while(e>0){
			if(e%2==0){p=(p*p)%mod; e/=2;}
			else {a=(a*p)%mod; e--;}
		}
		return ModInt(a);
	}
};

using modint=ModInt<pri>;

signed main(){
	int N; cin>>N;
	vector<string> fie(2); cin>>fie[0]>>fie[1];
	int ans=0; bool prev=true; //trueなら二段組で～～す
	for(int i=0;i<N;i++){
		if(i==0 and fie[0][i]==fie[1][i]){ans=3; prev=false;}
		else if(i==0 and fie[0][i]!=fie[1][i]){ans=6; i++;}
		else{
			if(fie[0][i]==fie[1][i]){
				if(prev){prev=false; continue;}
				else {
					ans*=2;
					ans%=pri;
				}
			}
			else{
				i++;
				if(prev){
					ans*=3;
					ans%=pri;
				}
				else {
					prev=true;
					ans*=2;
					ans%=pri;
				}
			}
		}
	}
	cout<<ans<<endl;
}

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

using namespace std;

long long cnt(long long n) {
	long long t = 1, ret = 0;
	for (int i = 0;i <= 50;++i) {
		long long tmp = 0;

		if (t - 1 > n)
			break;

		tmp += (n - (t - 1)) / (t * 2) * t;
		tmp += min((n - (t - 1)) - (n - (t - 1)) / (t * 2) * (t * 2), t);

		if (tmp % 2 == 1)
			ret += (1LL << i);

		t *= 2;
	}

	return ret;
}

int main() {
	long long a, b;
	scanf("%lld %lld", &a, &b);

	printf("%lld", cnt(a - 1) ^ cnt(b));

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define maxs(x,y) x = max(x, y)
#define mins(x,y) x = min(x, y)
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];
    int m;
    cin >> m;
    vector<int> q(m);
    REP(i, m) cin >> q[i];


    vector<int> sum;    
    for(int bit = 0; bit < (1<<n); bit++) {
        int tmp = 0;
        for(int i = 0; i < n; i++) {
            if(bit & (1<<i)) {
                tmp += a[i];
            }
        }
        sum.push_back(tmp);
    }

    for(int i = 0; i < m; i++) {
        bool can = 0;
        for(int j = 0; j < sum.size(); j++) {
            if (q[i] == sum[j]) can = 1;
        }
        cout << (can ? "yes" : "no") << endl;
    }

    return 0;

}



/*
int main() {

    int n, q;
    vector<int> A(n);
    vector<int> m(q);

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

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

    vector<int> sum;

    for (int bit = 0; bit < (1 << n); bit++) {

        int tmp = 0;

        for (int i = 0; i < n; i++) {
            if (bit & (1 << i)) {
                tmp += A[i];
            }
        }
        
        sum.push_back(tmp);
    }

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

        bool can = false;

        for (int j = 0; j < sum.size(); j++) {
            if (m[i] == sum[j]) {
                can = true;
            }
        }

        if (can) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }

    return 0;

}
*/


Measured memory_bytes: 6976
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

template<class T, class S> inline bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S> inline bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}








int main(){
    int N; std::cin >> N;
    std::vector<long double> p(N);
    for(int i(0); i < N; ++i) std::cin >> p[i];
    // i枚投げてj枚表
    std::vector<std::vector<long double>> dp(N+1, std::vector<long double>(N+1, 0.0L));
    dp[1][0] = 1 - p[0]; dp[1][1] = p[0];
    for(int i(2); i <= N; ++i){
        for(int j(0); j <= i; ++j){
            if(!j) dp[i][j] = dp[i-1][j] * (1 - p[i-1]);
            else dp[i][j] = dp[i-1][j-1] * p[i-1] + dp[i-1][j] * (1 - p[i-1]);
        }
    }
    long double ans(0.0L);
    for(int i(N/2 + 1); i <= N; ++i){
        ans += dp[N][i];
    }
    std::cout << std::fixed << std::setprecision(10) << ans << std::endl;
    return 0;
}


Measured memory_bytes: 141056
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,dummy=0;
    cin>>n>>m;
    if(n>8 || m>8)
    {
        cout<<":("<<endl;
    }
    else
    {
        cout<<"Yay!"<<endl;
    }
   return 0;
}

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

int abs(int x) {
  if(x >= 0) {
    return x;
  }
  else {
    return -1 * x;
  }
}

int main() {
  int A;
  cin >> A;
  if(A == 5) {
    cout << "YES" << endl;
  }
  else if(abs(A - 5) == 2) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 3592
#include <iostream>
#include <stdio.h>

using namespace std;

int m, n;
double p[16][20];
double memo[17][1<<16];

double calc(int clear, int state)
{
	if(clear >= n) return 1.0;
	if(memo[clear][state] > -1e8) return memo[clear][state];
	
	int nstate;
	double ret = 0.0, sum, pro;
	for(int i = 0; i < m; i++){
		if(state & (1<<i)) continue;
		nstate = state | (1<<i);
		sum = 0, pro = 1;
		for(int j = clear+1; j <= n; j++){
			sum += pro * (1 - p[i][j]) * calc(j-1, nstate);
			pro *= p[i][j];
		}
		sum += pro;
		ret = max(ret, sum);
	}
	return memo[clear][state] = ret;
}

int main(void)
{
	cin >> m >> n;
	for(int i = 0; i < m; i++){
		for(int j = 1; j <= n; j++){
			cin >> p[i][j];
		}
	}
	
	for(int i = 0; i <= n; i++){
		for(int j = 0; j < (1 << m); j++){
			memo[i][j] = -1e9;
		}
	}
		
	
	printf("%.11f\n", calc(0, 0));
	return 0;
}

Measured memory_bytes: 11964
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl
const int N = 1e5;  // limit for array size
ll n;  // array size

int sum(int i){
	int a=0;
	while(i!=0){
		a+=i%10;
		i/=10;
	}
	return a;
}

int main(){
	int n;cin>>n;
	
    int b=100000;
    for(int i=1;i<n;i++){
    	b=min(b,sum(i)+sum(n-i));
	}
	cout<<b<<endl;
	return 0;
}

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

int main(){
	ll n,a,b;
	cin >> n >> a >> b;
	if(a>b) swap(a,b);
	if ((b-a)%2==0) cout << (b-a)/2;
	else {
		cout << min(a + (b-a-1)/2, n-b+1+(b-a-1)/2);
	}
}


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

using namespace std;

int main(int argc, char *argv[]) {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> a(10, vector<int>(10));
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> a[i][j];
    }
  }
  for (int k = 0; k < 10; k++) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int t;
      cin >> t;
      if (t != -1) ans += a[t][1];
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

constexpr int64 P = 1000000007;

struct FiniteField {
 private:
  int64 x;
  static inline int64 Normalize(int64 x) {
    if (0 <= x && x < P) return x; x %= P; if (x < 0) x += P; return x;
  }
 public:
  FiniteField(int64 x) : x(Normalize(x)) {}
  FiniteField() : x(0) {}
  int64 Value() const { return x; }
  inline FiniteField operator+(FiniteField o) const {
    FiniteField r(*this); r += o; return r;
  }
  inline FiniteField operator-(FiniteField o) const {
    FiniteField r(*this); r -= o; return r;
  }
  inline FiniteField operator* (FiniteField o) const {
    FiniteField r(*this); r *= o; return r;
  }
  inline FiniteField operator/ (FiniteField o) const {
    FiniteField r(*this); r /= o; return r;
  }
  inline void operator+= (FiniteField o) { x = (x + o.x) % P; }
  inline void operator-= (FiniteField o) { x = (x + P - o.x) % P; }
  inline void operator*= (FiniteField o) { x = (x * o.x) % P; }
  void operator/=(FiniteField o) {
    int64 p = P - 2; while (p) { if (p % 2) { *this *= o; } o *= o; p /= 2; }
  }
};

ostream& operator<<(ostream& s, const FiniteField& v) { s << v.Value(); return s; }

tuple<vector<FiniteField>, vector<FiniteField>> MakeFactorialTables(int n) {
  vector<FiniteField> factorials(n + 1);
  vector<FiniteField> inverse_factorials(n + 1);
  factorials[0] = 1;
  for (int i = 1; i <= n; i++) {
    factorials[i] = factorials[i - 1] * i;
  }
  inverse_factorials[n] = FiniteField(1) / factorials[n];
  for (int i = n; i >= 1; i--) {
    inverse_factorials[i - 1] = inverse_factorials[i] * i;
  }
  return make_tuple(factorials, inverse_factorials);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, k;
  cin >> n >> k;
  vector<int64> xs(n);
  for (int i = 0; i < n; i++) {
    cin >> xs[i];
  }

  vector<FiniteField> fs, i_fs;
  tie(fs, i_fs) = MakeFactorialTables(n + 1);
  auto c_fn = [&](int n, int k) -> FiniteField {
    if (k < 0 || k > n) return 0;
    return fs[n] * i_fs[k] * i_fs[n - k];
  };

  auto solve_max_fn = [&]() -> FiniteField {
    map<int64, int> kvs;
    for (int64 x : xs) {
      kvs[x]++;
    }
    int count = 0;
    FiniteField used_combinations = 0;
    FiniteField r = 0;
    for (const auto& kv : kvs) {
      count += kv.second;
      if (count >= k) {
        r += FiniteField(kv.first) * (c_fn(count, k) - c_fn(count - kv.second, k));
      }
    }
    return r;
  };
  auto s1 = solve_max_fn();
  
  for (int i = 0; i < n; i++) {
    xs[i] *= -1;
  }
  auto s2 = solve_max_fn();
  // cout << s1 << " " << s2 << endl;
  cout << s1 + s2 << endl;
}

Measured memory_bytes: 8272
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        scanner.close();
        int lock = N;
        for(int i =0; i<2;i++){
        lock *= N;
        }
        
        System.out.println(lock);
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int H,W;
    cin >> H >> W;
    string C[H];
    for(int i=0;i<H;i++) cin >> C[i];
    for(int i=0;i<H;i++){
        cout << C[i] << endl << C[i] << endl;
    }
    
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  double a,b,h,m,x,y,z;
  double pi=3.1415926535;
  cin>>a>>b>>h>>m;
  
  y=30*h+m/2;
  z=6*m;
  if(y>z){
    x=a*a+b*b-2*a*b*cos((y-z)*pi/180);
    cout<<fixed<<setprecision(11) <<pow(x,0.5)<<endl;
  }
  else{
    x=a*a+b*b-2*a*b*cos((z-y)*pi/180);
    cout<<fixed<<setprecision(11) <<pow(x,0.5)<<endl;

  }

}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;//typo用
using itn = int;//typpo用
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl//1次元配列の出力
#define rrdebug(i, j, x) rep(i, alength(x))rep(j, alength(x[i]))cout << #x << "[" << i << "][" << j << "]:" << x[i][j] << endl//二次元配列の出力
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = acos(-1);
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) {a = b; return true;} return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) {a = b; return true;} return false; }
intl kai(intl k){//k!を求める関数
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl digit10(intl a){//aを10進数で表したときの桁数を求める関数
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}

//--------------入力受け取る場所,分けてた方がデバッグしやすい気がする---------------------
intl n,m;
intl a[100000];

void input_var(){
    cin >> n >> m;
    rep(i,m)cin >> a[i];
}
//-------------------------------------------------------------------------------

signed main(){
    cout << fixed << setprecision(10);
    input_var();
    bool f[n + 1];
    m1(f);
    rep(i,m)f[a[i]] = false;
    intl dp[n + 1];
    m0(dp);
    dp[0] = 1;
    if(f[1])dp[1] = 1;
    repi(i,2,n + 1){
        dp[i] = (dp[i - 1] * f[i - 1]) + (dp[i - 2] * f[i - 2]);
        dp[i] %= MOD;
    }
    //rdebug(i,dp);
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <queue>

using namespace std;

struct dipq
{
	priority_queue< int,vector<int>,less<int> > pq1;
	priority_queue< int,vector<int>,greater<int> > pq2;
	long long mn1,mn2;
	
	inline void push(int val)
	{
		if (pq1.empty()||val<=pq1.top())
		{
			if (!pq1.empty()) mn1+=pq1.top()-val;
			pq1.push(val);
		}
		else 
		{
			mn2+=val-pq1.top();
			pq2.push(val);
		}
		while (pq1.size()>pq2.size()+1)
		{
			int _val=pq1.top();
			pq1.pop();
			mn1-=1LL*(_val-pq1.top())*pq1.size();
			mn2+=1LL*(_val-pq1.top())*(pq2.size()+1);
			pq2.push(_val);
		}
		while (pq1.size()<pq2.size())
		{
			int _val=pq2.top();
			pq2.pop();
			mn2-=1LL*(_val-pq1.top())*(pq2.size()+1);
			mn1+=1LL*(_val-pq1.top())*pq1.size();
			pq1.push(_val);
		}
		return;
	}
	
	inline int get()
	{
		return pq1.top();
	}
	
	inline dipq():mn1(0),mn2(0) {}
};

inline int _abs(int a, int b)
{
	return a>b?a-b:b-a;
}

int Q;
dipq d;
long long rec;

int main()
{
	for (cin >> Q; Q--; )
	{
		int opr;
		cin >> opr;
		if (opr==1)
		{
			int a,b;
			cin >> a >> b;
			d.push(a);
			rec+=b;
		}
		else cout << d.pq1.top() << " " << d.mn1+d.mn2+rec << endl;
	}
	return 0;
}

Measured memory_bytes: 3452
#include<bits/stdc++.h>
using namespace std;
int main(void) {
  int n,m,x,b;
  cin >> n >> m >> x;
  int a[m];
  for(int i=0;i<m;++i) cin >> a[i];
  for(int i=0;i<=m;++i) {
    if(a[i] > x) {
      b = i;
      break;
    }
  }
  cout << min(b,(m-b)) << endl;
    
}



Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<pair<int,int>> hoge(n);
    
    for(int i=1;i<n+1;i++){
        hoge.at(i-1).second = i;
        cin>>hoge.at(i-1).first;
    }
    sort(hoge.begin(),hoge.end());
    for(int i=0;i<n;i++){
        cout<<hoge.at(i).second<<" ";
    }
}

Measured memory_bytes: 1536
import sys
from collections import Counter, deque, defaultdict
from math import factorial
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

n = INT()
d = LIST()
res = 0
for i in range(n-1):
    for j in range(i+1,n):
        if i != j:
            res += d[i] * d[j]

print(res)

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

enum {
    TOP = 0,
    FRONT,
    RIGHT,
    LEFT,
    BACK,
    BOTTOM
};

class dice {
public:
    dice(int top, int front) 
        : v_(6)
    {
        int right[7][7] = {};
        // change 
        right[1][2] = 3; right[1][3] = 5; right[1][4] = 2; right[1][5] = 4;
        right[2][1] = 4; right[2][3] = 1; right[2][4] = 6; right[2][6] = 3;
        right[3][1] = 2; right[3][2] = 6; right[3][5] = 1; right[3][6] = 5;
        right[4][1] = 5; right[4][2] = 1; right[4][5] = 6; right[4][6] = 2;
        right[5][1] = 3; right[5][3] = 6; right[5][4] = 1; right[5][6] = 4;
        right[6][2] = 4; right[6][3] = 2; right[6][4] = 5; right[6][5] = 3;
        v_[TOP] = top;
        v_[FRONT] = front;
        v_[BOTTOM] = 7 - top;
        v_[BACK] = 7 - front;
        v_[RIGHT] = right[top][front];
        v_[LEFT] = 7 - v_[RIGHT];
    }
    dice(vector<int> const& v)
    : v_(v)
    {}

    dice roll(int dir) {
        vector<int> res(6);
        for(int i=0; i<6; ++i) {
            res[i] = v_[rot[dir][i]];
        }
        return dice(res);
    }

    int get(int idx) {
        if(idx < 0 || 6 <= idx) {
            return -1;
        }
        return v_[idx];
    }

private:
    std::vector<int> v_;
    int rot[6][6] = {{4, 0, 2, 3, 5, 1},  // south 
                     {3, 1, 0, 5, 4, 2},  // east
                     {2, 1, 5, 0, 4, 3},  // west
                     {1, 5, 2, 3, 0, 4},  // north 
                     {0, 2, 4, 1, 3, 5},  // right(not move)
                     {0, 3, 1, 4, 2, 5}}; // left(not move)
};

int main() {
    int n;
    while(cin >> n, n) {
        int res = 1;
        dice d(1, 2);
        for(int i=0; i<n; ++i) {
            string s;
            cin >> s;
            if(s[0] == 'N') {
                d = d.roll(3);
            } else if(s[0] == 'S') {
                d = d.roll(0);
            } else if(s[0] == 'W') {
                d = d.roll(2);
            } else if(s[0] == 'E') {
                d = d.roll(1);
            } else if(s[0] == 'R') {
                d = d.roll(4);
            } else {
                d = d.roll(5);
            }
            res += d.get(TOP);
        }
        cout << res << endl;
    }
}


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

int main() {
	int w, h;
	do {
		cin >> h >> w;
		if (h == 0 && w == 0)
			break;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if(i == 0 || i == (h - 1)  || j == 0 || j == (w - 1))
					cout << "#";
				else
					cout << ".";
			}
			cout << endl;
		}
		cout << endl;
	} while (true);
	return 0;
}


Measured memory_bytes: 3072
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>
using namespace std;

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define llrp(i,n) for(long long i=0;i<n;i++)
#define llrep(i,m,n) for(long long i=m;i<=n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if
#define vcin(a); rp(i,a.size()){cin>>a[i];}
#define vcout(a); rp(i,a.size()){cout<<a[i]<<endl;}
#define llvcin(a); llrp(i,a.size()){cin>>a[i];}
#define llvcout(a); llrp(i,a.size()){cout<<a[i]<<endl;}
#define allchar(c) for(char c='a';c<='z';c++)
#define mp(a,b) make_pair(a,b)
#define bs(a,n) binary_search(a.begin(),a.end(),n)

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef long long ll;
typedef string S;
typedef pair<int,int> P;
typedef queue<int> qi;

const int mod=1e9+7;

ll modpow(ll a,ll b,ll p){
    if(b==0){
        return 1;
    }elif(b%2==0){
        return modpow((a*a)%p,b/2,p);
    }else{
        return (a*modpow(a,b-1,p))%p;
    }
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long n,a;
    cin >> n >> a;
    vll x(n);
    llvcin(x);
    long long dp[51][51][2501];
    llrep(i,0,n){
        llrep(j,0,i){
            llrep(sum,0,2500){
                if(i>=1&&j>=1&&sum>=x[i-1]){
                    dp[i][j][sum]=dp[i-1][j][sum]+dp[i-1][j-1][sum-x[i-1]];
                }elif(i>=1&&sum<x[i-1]){
                    dp[i][j][sum]=dp[i-1][j][sum];
                }elif(i==0&&j==0&&sum==0){
                    dp[i][j][sum]=1;
                }else{
                    dp[i][j][sum]=0;
                }
            }
        }
    }
    long long ans=0;
    llrep(i,1,n){
        ans += dp[n][i][i*a];
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 50944
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(), B = sc.nextInt();
		sc.close();
		long ans = (long)A*B;
		long g = gcd(A, B);
		ans /= g;
		System.out.println(ans);
		
	}
	static long gcd(long x, long y) {
        return y==0? x : gcd(y,x%y);
    }
}

Measured memory_bytes: 23764
n,m = map(int,input().split())
#行列a、ベクトルb、行列積cの初期化
a = [0 for i in range(n)]
b = [0 for j in range(m)]
c = []
#a,bの読み込み
for i in range(n):
    a[i] = input().split()
    a[i] = [int(x) for x in a[i]]
for j in range(m):
    b[j] = int(input())
#行列積計算
temp = 0
for i in range(n):
    for j in range(m):
        temp += a[i][j]*b[j]
    c.append(temp)
    temp = 0
#結果の表示
for num in c:print(num)



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

using namespace std;

int main(void)
{
    int N;
    string S;
    cin >> N >> S;
    vector<int> sum(N + 1, 0); // i番目までの白の数
    for (int i = 0; i < N; i++) sum[i + 1] = sum[i] + (int)(S[i] == '.');
    int ans = 300000;
    for (int i = 0; i <= N; i++) // 1<iを白、i+1<Nを黒
    {
        ans = min(ans, (i - sum[i]) + (sum[N] - sum[i]));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1412
n = int(input())
a = [0] + list(map(int, input().split()))
b = [0] * (n + 1)

for i in range(n, 0, -1):
    for j in range(i, n + 1, i):
        b[i] ^= b[j]
    b[i] ^= a[i]

print(sum(b))
for i in range(1, n + 1):
    if b[i] == 1:
        print(i)

Measured memory_bytes: 7220
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> lp;
typedef pair<ll,pair<ll,ll>> lpp;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T = int> void print(vector<T> v){for(auto a:v)cout<<a<<" ";cout<<endl;}

/*
ac
まっすぐk個まで進める：曲がったタイミングで精算
答えが配列の値そのままにならないような課題のときの初期値（INF）に注意
*/

ll h,w,k,x3,x2,y3,y2,ans=1e18;
priority_queue<lp, vector<lp>, greater<lp> > qu;
ll dx[]={0,0,1,-1},dy[]={1,-1,0,0};


int main(void){
	cin>>h>>w>>k;
	cin>>x3>>y3>>x2>>y2;
	x3--;
	y3--;
	x2--;
	y2--;
	vector<string> s(h);
	vector<vector<vector<ll>>> d(h, vector<vector<ll>>(w, vector<ll>(4, 1e18)));
	rep(i,h)cin>>s[i];
	d[x3][y3][0]=0;
	qu.push({0, (w*x3 + y3)*4 + 0});
	while(!qu.empty()){
		auto a = qu.top();qu.pop();
		ll cur=a.second;
		ll x=a.second/4/w, y=(a.second/4)%w, v=a.second%4;
		rep(i,4){  // 向きを変える
			if(d[x][y][i] > (d[x][y][v] + k - 1) / k * k){  // 切り上げ
				d[x][y][i] = (d[x][y][v] + k - 1) / k * k;
				qu.push({d[x][y][i], (x*w+y)*4+i});
			}
		}
		ll xx=x+dx[v], yy=y+dy[v];
		if(0<=xx && xx<h && 0<=yy && yy<w &&
		d[xx][yy][v] > d[x][y][v] + 1 && s[xx][yy]!='@'){
			d[xx][yy][v] = d[x][y][v] + 1;
			qu.push({d[xx][yy][v], (xx*w+yy)*4+v});
		}
	}
	bool ok=false;
	rep(i,4){
		if(d[x2][y2][i]!=1e18){
			ok=true;
			ans=min(ans, (d[x2][y2][i] + k - 1) / k);  // ここ1e18にならないので注意（横着はできない）（ここ気付かず数時間溶かした）
		}
	}
	cout<<(ok? ans : -1)<<endl;
	return 0;
}

Measured memory_bytes: 143972
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  ll ans = 0;
  sort(a.rbegin(), a.rend());
  int cnt = 1;
  int cur = 0;
  rep(i, n - 1) {
    ans += a[cur];
    cnt++;
    if(cnt == 2) {
      cnt = 0;
      cur++;
    }
  }
  cout << ans << endl;
}

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

    //input from txt （提出時にこの箇所は削除すること）
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    
    char T;
    cin >> T;
    if(T >= 'A' && T <= 'Z'){
        cout << 'A' << endl;
    }
    else{
        cout << 'a' << endl;
    }
}
 


Measured memory_bytes: 3628
import Data.Set (fromList,member)

data St = Open | Close deriving(Eq)

ans' _ _ [] = []
ans' s u (t0:ts) =
        a:(ans' s' u ts)
    where
        (s',a) = if member t0 u
                 then if s == Open
                      then (Close, "Closed by " ++ t0)
                      else (Open,  "Opened by " ++ t0)
                 else (s, "Unknown " ++ t0)

ans i =
    let n = read $ head i :: Int
        u = fromList $ take n $ drop 1 i 
        m = read $ head $ drop (n+1) i :: Int
        t = take m $ drop (n+2) i
    in
        ans' Close u t

main = do
    c <- getContents
    let i = lines c
        o = ans i
    mapM_ putStrLn o


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

int main() {
	long long a, b, c;
	cin >> a >> b >> c;
	long long answer = 0;
	if (b >= c) {
		cout << b + c;
	} else {
		if (b + a >= c) {
			cout << b + c;
		} else {
			c -= b + a;
			cout << b + b + a + (c > 0);
		}
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <iterator>
#include <numeric>
#include <cmath>
#include <stdio.h>

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
const ll INF = 1e15;
const ld eps = 1e-6;
const ll MOD = 1e9 + 7;

const double pi = acos(-1.0);

int main() {
	ll N, M;
	cin >> N >> M;
	vector<P> v(N);
	for (int i = 0;i < N;i++) {
		ll a, b;
		cin >> a >> b;
		v[i] = P(a, b);
	}
	ll m = 0;
	ll ans = 0;
	ll p = 0;
	sort(v.begin(), v.end());
	while (m < M) {
		if (v[p].second == 0)
			p++;
		else {
			v[p].second--;
			ans += v[p].first;
			m++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define optimizar_io ios_base::sync_with_stdio(false);cin.tie(0);
 
int main() {
    optimizar_io

    int a, b, ans = 0;
    
    cin >> a >> b;
    if (b == 1) return cout << "0\n", 0;
    int sockets = 0;
    while (sockets < b) {
    	if (ans == 0)
    		sockets += a;
    	else
    		sockets += (a - 1);
    	ans++;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
def max2(p, q):
    e, b = p[0], p[1]
    c, d = q[0], q[1]
    s = list(set([e, b, c, d]))
    m1, m2 = 1<<n, 1<<n
    for i in s:
        if a[m1]<a[i]:
            m2 = m1
            m1 = i
        elif a[m2]<a[i]:
            m2 = i
    return (m1, m2)

n = int(input())
a = list(map(int, input().split()))
g = [(i, (1<<n)) for i in range(1<<n)]
a+=[0]
res = 0
for i in range(n):
    for j in range(1<<n):
        if (1<<i)&j: g[j] = max2(g[j], g[j^(1<<i)])
ans = []
for i in range(1, 1<<n):
    res = max(res, a[g[i][0]]+a[g[i][1]])
    ans.append(res)
print(*ans, sep = '\n')

Measured memory_bytes: 123320
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] H = Console.ReadLine().Split(' ');
            int A = int.Parse(H[0]);
            int B = int.Parse(H[1]);
            int T = int.Parse(H[2]);
            int result = 0;

            
            result = (T / A) * B;

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 13140
#define LOCAL

#undef _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define MOD 1000000007LL
#define LLINF 100000000000000005LL
#define INF (int)1e9+1

// Copied from Gennady-Korotkevich's template

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
	return '"' + s + '"';
}

string to_string(const char* s) {
	return to_string((string)s);
}

string to_string(bool b) {
	return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
	bool first = true;
	string res = "{";
	for (int i = 0; i < static_cast<int>(v.size()); i++) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(v[i]);
	}
	res += "}\n";
	return res;
}

template <size_t N>
string to_string(bitset<N> v) {
	string res = "";
	for (size_t i = 0; i < N; i++) {
		res += static_cast<char>('0' + v[i]);
	}
	return res;
}

template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto& x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}\n";
	return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

template <typename A, typename B, typename C, typename D, typename E>
string to_string(tuple<A, B, C, D, E> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + "," + to_string(get<4>(p)) + ")";
}

void debug_out() {
	cerr << endl;
}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "\n[" << #__VA_ARGS__ << "]:\n", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

// End of Gennady-Korotkevich's template 

using llong = long long;
using PII = pair<int, int>;

int main() {
	int n; cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	vector<int> dp(n);
	for (int i = 1; i < n; i++) {
		if (i == 1) dp[i] = dp[i - 1] + abs(a[i] - a[i - 1]);
		else dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
	}
	cout << dp[n-1];
}

Measured memory_bytes: 4032
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

int main(void) {
	string s; cin >> s;
	int n = s.size();
	int k; cin >> k;
	vector<string> t;
	for(int l=0; l<n; l++){
		for(int r=l; r<min(n,l+k); r++){
			t.push_back(s.substr(l,r-l+1));
		}
	}
	SORT(t);
	t.erase(unique(t.begin(), t.end()), t.end());
	cout << t[k-1] << endl;
}


Measured memory_bytes: 1660
#include<bits/stdc++.h>
#define randome_generate srand(std::chrono::high_resolution_clock::now().time_since_epoch().count())
using namespace std;
bool dp[100100];
int n,k;
int a[120];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	dp[0]=false;
	for(int i=1;i<=k;i++){
		dp[i]=false;
		for(int j=1;j<=n;j++){
			if(i>=a[j]&&dp[i-a[j]]==false){
				dp[i]=true;
				break;
			}
		}
	}
	if(dp[k]==true)
		cout<<"First"<<endl;
	else
		cout<<"Second"<<endl;
	return 0;
}


Measured memory_bytes: 384