akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> primeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)



int main() {
	ll n, a, b,ans,tmp;
	in(n);
	in(a);
	in(b);


	if ((b - a) % 2 == 1){ 
		if (b - 1 < n - a) {
			ans = b - 1;
		}
		else {
			ans = n - a;
		}

		if (a-1 < n - b ) {
			tmp = ((b - a - 2) / 2) + a + 1;
		}
		else {
			tmp = ((n - (a + n - b + 1)) / 2) + n - b + 1;
		}

		if (tmp > 0 && ans > tmp) {
			ans = tmp;
		}
	}
	else {
		ans = (b - a) / 2;
	}
	outn(ans);
	
	return 0;


}


Measured memory_bytes: 256
#!python3

import sys
sys.setrecursionlimit(1000000000)
iim = lambda: map(int, input().rstrip().split())

def resolve():
    N, Q = iim()
    S = [i for i in range(N)]
    W = [0] * N
    R = [0] * N

    def find(x):
        if S[x] == x:
            return x

        i = find(S[x])
        W[x] += W[S[x]]
        S[x] = i
        return i

    def relate(x, y, w):
        i = find(x)
        j = find(y)

        if R[i] < R[j]:
            S[i] = j
            W[i] = w - W[x] + W[y]
        else:
            S[j] = i
            W[j] = -w - W[y] + W[x]
            if R[i] == R[j]:
                R[i] += 1

    def diff(x, y):
        i = find(x)
        j = find(y)

        if i != j: return "?"

        return W[x] - W[y]

    ans = []
    for com, *xyz in (map(int, s.split()) for s in sys.stdin):
        if com == 0:
            relate(*xyz)
        else:
            ans.append(diff(*xyz))
    print(*ans, sep="\n")

if __name__ == "__main__":
    resolve()



Measured memory_bytes: 16040
#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() {
    string w;
    cin >> w;
    sort(w.begin(),w.end());
    bool flag=true;
    if(w.size()%2==1){
        cout << "No" << endl;
    }
    else{
        for(int i=0;i<w.size();i+=2){
            if(w.at(i)!=w.at(i+1))flag=false;
        }
        if(flag) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}


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

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<long long> a(n);
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	
	cout << *max_element(a.begin(), a.end()) - *min_element(a.begin(), a.end()) << endl;	
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define mkp make_pair
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,a,b)for(int i=a;i<b;i++)
#define repre(i,a,b)for(int i=a;i<=b;i++)
#define clr1(arr) memset(arr,-1,sizeof(arr));
#define clr0(arr) memset(arr,0,sizeof(arr));
#define pi pair<int,int>
#define pii pair<int,pi>
#define sortV(v) v.begin(),v.end()
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> orderedSet;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> orderedMSet;
//*p.find_by_order(index) return value at index
//p.order_of_key(key) return index
// DSU
/*
const int maxn=100009;
int arr[maxn];
int sz[maxn];
void init(){rep(i,maxn){arr[i]=i;sz[i]=1;}}
int root(int a){while(a!=arr[a]){arr[a]=arr[arr[a]];a=arr[a];}return a;}
int check(int a,int b){if(root(a)==root(b))return 1;return 0;}
int un(int a,int b)
{
  int roota=root(a);int rootb=root(b);
  if(sz[roota]>=sz[rootb]){sz[roota]+=sz[rootb];arr[rootb]=roota;}
  else {sz[rootb]+=sz[roota];arr[roota]=rootb;}
}
*/

//Dijkstra
/*
const int maxn=0x3f3f3f3f;
void dijkstra(int n,int dist[],vector<pi >adj[],int s)
{
  int visited[n+1];
  repre(i,0,n)
  {
    visited[i]=0;
    dist[i]=maxn;
  }
  dist[s]=0;
  priority_queue<pi ,vector<pi>,greater<pi> >p;
  p.push(mkp(0,s));
  while(p.empty()==false)
  {
    pi temp=p.top();
    p.pop();
    if(visited[temp.ss])continue;
    visited[temp.ss]=1;
    int u=temp.ss;
    rep(i,adj[u].size())
    {
      if(dist[u]+adj[u][i].ss<dist[adj[u][i].ff])
      {
        dist[adj[u][i].ff]=dist[u]+adj[u][i].ss;
        p.push(mkp(dist[adj[u][i].ff],adj[u][i].ff));
      }
    }
  }
}*/
bool cmp(const pi& a,const pi& b)
{
  if(a.ff==b.ff)
  {
    return a.ss>b.ss;
  }
  return a.ff>b.ff;
}
int32_t main()
{
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  fastio
  int n,m;
  cin>>n>>m;
  vector<pi >v;
  rep(i,n)
  {
    int day,prof;
    cin>>day>>prof;
    v.pb(mkp(prof,day));
  }
  sort(sortV(v),cmp);
  int prof=0;
  int dp[m+1];
  clr1(dp);
  int free[m+1];
  repre(i,0,m)free[i]=i-1;
  rep(i,v.size())
  {
    int freeIndex=m-v[i].ss;
    while(freeIndex>=0)
    {
      if(dp[freeIndex]==-1)
      {
        dp[freeIndex]=i;
        free[freeIndex+1]=free[freeIndex];
        prof+=v[i].ff;
        break;
      }
      if(dp[free[freeIndex]]!=-1 && free[freeIndex]!=-1)
        free[freeIndex]=free[free[freeIndex]];
        freeIndex=free[freeIndex];
    }
  }
  cout<<prof<<endl;
  return 0;
}


Measured memory_bytes: 3568
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        // 入力
        int[] nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nk[0];
        var k = nk[1];
        int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();

        Console.WriteLine(Math.Ceiling((double)(n - 1) / (k - 1)));

    }

}


Measured memory_bytes: 20064
N, W = map(int, input().split())

wvs = [list(map(int, input().split())) for _ in range(N)]

dp = [[0] * (W+1) for _ in range(N+1)]

for i, (w, v) in enumerate(wvs):
    i += 1
    for j in range(W+1):
        if j < w:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = max(dp[i-1][j - w] + v, dp[i-1][j])

print(dp[N][W])


Measured memory_bytes: 120044
import numpy as np

a, b, h, m = map(int, input().split())

# 時針は1時間で 30°回る , 1分で 0.5°回る
# 分針は1分で 6°回る

# +90°- Θ

# 時針
hour = np.array([a*np.cos(np.radians(90)-(np.radians(30*h)+np.radians(0.5*m))), a*np.sin(np.radians(90)-(np.radians(30*h)+np.radians(0.5*m)))])

minute = np.array([b*np.cos(np.radians(90)-(np.radians(6*m))), b*np.sin(np.radians(90)-(np.radians(6*m)))])

diff = hour - minute

print(np.linalg.norm(diff))

Measured memory_bytes: 27268
#include <stdio.h>


int wall[100];
int out[51];

int main(void)
{
    int N, M;
    int a, L;
    int i, j;
    int start, end, pos;
    int len;
    int flag;
    
    scanf("%d%d", &N, &M);
    
    for (i = 0; i < M; i++){
        scanf("%d%d", &a, &L);
        
        for (j = a; j < a + L; j++){
            wall[j % N] = 1;
        }
    }

#if 0
for (i = 0; i < N; i++){
    printf("%d", wall[i]);
}
printf("\n");
#endif

    for (start = 0; start < N; start++){
        if (wall[start] == 0){
            break;
        }
    }
    if (start == N){
        printf("%d 1\n", N);
        goto END;
    }
//printf("start=%d\n", start);
    pos = start;
    len = 0;
    flag = 0;
    do {
        if (len == 0){
            if (wall[pos] == 1){
                len = 1;
//printf("+");
            }
        }
        else {
            if (wall[pos] == 1){
                len++;
            }
            else {
                out[len]++;
//printf("len=%d\n", len);
                len = 0;
                flag = 1;
            }
        }
        pos++;
        pos %= N;
    } while (pos != start);
    if (len > 0){
        out[len]++;
        flag = 1;
    }
    
    if (flag == 0){
        printf("0 0\n");
    }
    else {
        for (i = 50; i >= 0; i--){
            if (out[i] > 0){
                printf("%d %d\n", i, out[i]);
            }
        }
    }
    
END:;
    return (0);
}



Measured memory_bytes: 2112
//coded by not_surrender

#pragma GCC optimize( "Ofast" )

#include <bits/stdc++.h>

#define MAXN 1010
#define oo (1<<30)
#define MOD 1000000007
#define mid ((a+b)/2)
#define L (nod*2)
#define R (nod*2+1)
#define pb push_back

using namespace std;

typedef long long ll;
typedef vector <int> vi;

int N, M, dp[MAXN][MAXN];

char S[MAXN][MAXN];

int main(){

    #ifndef ONLINE_JUDGE
        //~ freopen( "a.txt", "r", stdin );
    #endif // ONLINE_JUDGE

    ios_base::sync_with_stdio( false );
    cin.tie( NULL ), cout.tie( NULL );
    
    cin >> N >> M;
    
    for ( int i = 1; i <= N; ++i )
		for ( int j = 1; j <= M; ++j )
			cin >> S[i][j];
	
	dp[1][1] = 1;
	for ( int i = 1; i <= N; ++i )
		for ( int j = 1; j <= M; ++j ){
			if ( S[i+1][j] == '.' )
				dp[i+1][j] = (dp[i+1][j]+dp[i][j])%MOD;
			if ( S[i][j+1] == '.' )
				dp[i][j+1] = (dp[i][j+1]+dp[i][j])%MOD;
		}
	
	cout << dp[N][M] << '\n';
	
return 0;
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
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; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;


int main(){

    vector<set<int>> indices(26, set<int>({100000000}));

    int N, Q;
    string S;
    cin >> N >> S >> Q;

    rep(i,N) indices[S[i]-'a'].insert(i);

    rep(i,Q){
        int type; cin >> type;
        if (type == 1){
            int index; cin >> index;
            index--;
            char letter; cin >> letter;
            indices[S[index]-'a'].erase(index);
            indices[letter-'a'].insert(index);
            S[index] = letter;
        }
        else{
            int left, right;
            cin >> left >> right;
            left--;
            int ans = 0;
            rep(i,26){
                int left_index = *indices[i].lower_bound(left);
                int right_index = *indices[i].lower_bound(right);
                if (right_index > left_index) ans++;
            }
            cout << ans << endl;
        }
    }
}

Measured memory_bytes: 27200
using System;
using System.Linq;

class Program {
  static void Main() {
    var arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int x = arr[0];
    int a = arr[1];
    int b = arr[2];
    if (Math.Abs(x - a) < Math.Abs(x - b)) {
      Console.WriteLine("A");
    } else {
      Console.WriteLine("B");
    }
  }
}

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


int main(){
	char g[42] = {97,102,107,112,117,122,98,103,108,113,118,46,99,104,109,114,119,63,100,105,110,115,120,33,101,106,111,116,121,32};
	string s,a;
	while(cin >> s,!cin.eof()){
		a = "";
		for(int i = 0;i < s.size();i += 2){
				int l = s[i] - '0', r = s[i+1] - '0';
				if(s.size() % 2 || l < 1 || r < 1 || l > 6 || r > 5){a = "NA";break;}
			a += g[r * 6 + l - 7];
		}
		cout << a << endl;
	}	
}

Measured memory_bytes: 0
#!/usr/bin/env python3
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    N = int(readline())
    As = map(int, readline().split())
    ans = 0
    for a in As:
        ans += 1 / a
    print(1/ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)
#define Yes(condition) if(condition){ cout << "Yes" << '\n'; }else{ cout << "No" << '\n'; }
#define YES(condition) if(condition){ cout << "YES" << '\n'; }else{ cout << "NO" << '\n'; }
#define yes(condition) if(condition){ cout << "yes" << '\n'; }else{ cout << "no" << '\n'; }




int main() {
    ll n, m;
    cin >> n >> m;
    vector<vector<ll>> g(n, vector<ll>(n, INF));
    REP(i, n){
        g[i][i] = 0;
    }
    struct edge{
        ll from, to, cost;
    };
    vector<edge> v;
    REP(i, m){
        ll a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        g[a][b] = c;
        g[b][a] = c;
        v.push_back({a, b, c});
    }
    REP(k, n){
        REP(i, n){
            REP(j, n){
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }
    ll ans = 0;
    REP(i, m){
        auto t = v[i];
        bool ok = true;
        REP(j, n && ok){
            REP(k, n && ok){
                if(g[j][t.from] + t.cost + g[t.to][k] == g[j][k]){
                    ok = false;
                }
            }
        }
        if(ok){
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans = 0;
    int sum = 0;
    REP(i,n){
        int d;
        cin >> d;
        ans -= d*d;
        sum += d;
    }
    ans += sum*sum;
    cout << ans/2 << endl;

    return 0;
}

Measured memory_bytes: 256
require 'set'

N,M = gets.split.map(&:to_i)
H = [0] + gets.split.map(&:to_i)
s = Set.new(1..N)
M.times do
  a,b = gets.split.map(&:to_i)
  s.delete(a) if H[a]<=H[b]
  s.delete(b) if H[b]<=H[a]
end
puts s.size

Measured memory_bytes: 26488
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline
    n,m, c = map(int, input().split())
    bb = list(map(int, input().split()))
    count = 0
    for _ in range(n):
        result = c
        for i, num in enumerate(list(map(int, input().split()))):
            result += bb[i]*num
        if result > 0:
            count += 1
    print(count)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define sz(x) int(x.size())
using ll = long long;
using P = pair<int,int>;
const ll LLINF = numeric_limits<long long>::max();
const int mod = 1000000007;
const int INF = 1001001001;

int main()
{
    int x[5];
    for(int i=0;i<5;i++){
        cin >> x[i];
    }

    for(int i=0;i<5;i++){
        if(x[i] == 0){
            cout << i +1 <<endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 3620
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <vector>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> II;
typedef pair<LL, II> III;
typedef priority_queue<III, vector<III>, greater<>> Queue;
static const LL INF = 1LL << 60;

LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
LL lcm(LL a, LL b) { return (a / gcd(a, b)) * b; }

#ifdef _DEBUG
const LL MX = 10000;
#else
const LL MX = 1000000;
#endif

vector<int> gen_primes(int m) {
	vector<int> primes;
	primes.push_back(2);
	for (int i = 3; i <= m; i += 2) {
		for (int prime : primes) {
			if (i < prime * prime) {
				primes.push_back(i);
				break;
			}
			if ((i % prime) == 0) {
				break;
			}
		}
	}
	return primes;
}

void solve(long long N, std::vector<long long> &A) {
	vector<vector<int>> p(MX+1);
	vector<int> f(MX + 1);
	LL g = -1;
	for (int i = 2; i <= MX; ++i) {
		if (p[i].empty()) {
			for (int j = i; j <= MX; j += i) {
				p[j].emplace_back(i);
			}
		}
	}
	for (int i = 0; i < N; ++i) {
		for (auto x : p[A[i]]) {
			f[x] += 1;
		}
		if (i) {
			g = gcd(g, A[i]);
		} else {
			g = A[i];
		}
	}
	bool pc = true;
	for (int i = 2; i <= MX; ++i) {
		if (f[i] >= 2) {
			pc = false;
		}
	}
	string ans = "";
	if (pc) {
		ans = "pairwise coprime";
	} else if (g == 1) {
		ans = "setwise coprime";
	} else {
		ans = "not coprime";
	}
	cout << ans << endl;
}

int main() {
    long long N;
	scanf("%lld", &N);
	std::vector<long long> A(N);
	for (int i = 0; i < N; i++) {
		scanf("%lld", &A[i]); // A[i]--;
	}
	solve(N, A);
	return 0;
}


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

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

  vector<int long long> a(n+1);

  a[0] = 2;
  a[1] = 1;

  if(n<=1){
    cout<<a[n]<<endl;
  }
  else{
    for(int i = 2;i <= n;i++){
    a[i] = a[i-1]+a[i-2];
   }

  cout << a[n] <<endl;
  }
}


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

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; }

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;


int main() {
   int n;
   cin >> n;
   vector<int>l(n);
   rep(i, 0, n)cin >> l[i];
   ll cnt = 0;
   sort(l.begin(),l.end());
   rep(i, 0, n){
       rep(j, i+1, n){
           int k = lower_bound(l.begin(),l.end(),l[i]+l[j])-l.begin();
           cnt += max(k-(j+1),0);
       }
   }
   cout << cnt << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
	public static void Main()
	{
		var n = ReadLine().Split().Select(ushort.Parse).ToArray();
		var a = ReadLine().Split().Select(ushort.Parse).ToArray();
		Sort(a);
		Reverse(a);
		var sum = a.Select((x, i) => new { x, i }).Where(x => x.i < n[1]).Sum(x => x.x);
		WriteLine(sum);
	}
}


Measured memory_bytes: 19268
A, B, C, D, E, F = gets.chomp.split.map(&:to_i)

ans = -1
ret = []

0.upto(F/100) do |a|
  0.upto(F/100) do |b|
    water = a * A + b * B
    w = water * 100
    next if w > F
    sugar = water * E

    0.upto(F/C) do |c|
      0.upto(F/D) do |d|
        s = c * C + d * D

        next if w + s > F

        if s <= sugar
          next if (w + s).zero?

          if ans < (100 * s) / (w + s).to_f
            ans = (100 * s) / (w + s).to_f
            ret = [w + s, s]
          end
        end
      end
    end
  end
end

puts ret.join(' ')


Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int h = scanner.nextInt(), w = scanner.nextInt();
		for (int i = 0; i < h; i++) {
			String string = scanner.next();
			System.out.println(string);
			System.out.println(string);
		}
		scanner.close();
	}
}

Measured memory_bytes: 22868
N = gets.to_i
XYs = readlines.map{|l| l.split.map(&:to_i)}

def fail
  puts -1
  exit
end

pty = XYs.map{|x, y| (x + y).even? ? :e : :o}.uniq
fail if pty.size > 1
ds = (0 .. 30).map{|i| 1 << i}.reverse
ds << 1 if pty == [:e]
uvs = XYs.map{|x, y| [x + y, x - y]}
puts ds.size
puts ds.join(' ')
uvs.each do |u, v|
  u0, v0, w = 0, 0, ""
  ds.each do |d|
    case [u > u0, v > v0]
    when [true,  true]
      w += 'R'
      u0 += d; v0 += d
    when [false, false]
      w += 'L'
      u0 -= d; v0 -= d
    when [true,  false]
      w += 'U'
      u0 += d; v0 -= d
    when [false, true]
      w += 'D'
      u0 -= d; v0 += d
    end
  end
  puts w
end

Measured memory_bytes: 2172
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>

using namespace std;

const int MAX = 1000000;
bool prime[MAX];
vector<int> V;
int N,P;

void make(){
  memset(prime,true,sizeof(prime));

  prime[0] = prime[1] = false;

  for(int i = 2; i*i < MAX; i++)
    if(prime[i])
      for(int j = 2; i*j < MAX; j++)
	prime[i*j] = false;

  for(int i = 0; i < MAX; i++)
    if(prime[i]) V.push_back(i);
 
}

void solve(){

  vector<int> M;
  vector<int>::iterator ite = upper_bound(V.begin(),V.end(),N);

  for(vector<int>::iterator i = ite; i < ite+200; i++)
    for(vector<int>::iterator j = i; j < ite+200; j++)
      M.push_back(*i+*j);

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

  cout << M[P-1] << endl;
}

int main(){
  make();
  while(cin >> N >> P){
    if(N == -1 && P == -1) break;
    solve();
  }
  return 0;
}

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

using namespace std;
using ll = long long;

int main(){
    ll H,W;
    while(cin>>H>>W and H>0 and W>0){
        for(ll i=0;i<H;++i){
            for(ll j=0;j<W;++j){
                if((i+j)%2==0){
                    cout<<'#';
                }
                else{
                    cout<<'.';
                }
            }
            cout<<endl;
        }
        cout<<endl;
    }
}


Measured memory_bytes: 3136
#include <iostream>
#include <vector>

typedef long long ll;
using namespace std;

// a^p
// 2^3 = 2 * 2^2
// 2^2 = 2 * (2^1)
// 2^1 = 2
ll modpow(ll a, ll p, ll mod) {
  if (p == 0) return 1;

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

// nCa を求める
ll modCombination(ll n, ll a, ll mod) {
  if (n - a < a) {
    return modCombination(n, n - a, mod);
  }

  ll denominator = 1; // 分母
  ll numerator = 1; // 分子

  for (ll i = 0; i < a; i++) {
    denominator *= a - i;
    numerator *= n - i;
    denominator %= mod;
    numerator %= mod;
  }

  return numerator * modpow(denominator, mod - 2, mod) % mod;
}

 vector<pair<ll, ll>> prime_factorize(ll n) {
   vector<pair<ll, ll>> res;

   for (ll i = 2; i * i <= n; i++) {
     if (n % i == 0) {
       ll num = 0;
       while (n % i == 0) {
         num++;
         n /= i;
       }
       res.push_back(make_pair(i, num));
     }
   }

   if (n != 1) {
     res.push_back(make_pair(n, 1));
   }

   return res;
 }

 ll MOD = 1000000007;

int main() {
  ll N, M;
  cin >> N >> M;
  vector<pair<ll, ll>> primeFactors = prime_factorize(M);

  ll ans = 1;
  for (auto e : primeFactors) {
    ll base = e.first;
    ll exponent = e.second;

    ans *= modCombination(exponent + N - 1, N - 1, MOD);
    ans %= MOD;
  }

  cout << ans % MOD << endl;

  return 0;
}

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

using namespace std;

#define _int64 long long

int a[200000];

int main()
{
  int i,j,n,c,k,nowmin,ans,cnt;
  scanf("%d%d%d",&n,&c,&k);
  for (i=0;i<n;i++)
    scanf("%d",&a[i]);
  sort(a,a+n);
  nowmin=1100000000;
  ans=0;
  cnt=0;
  for (i=0;i<n;i++)
  {
    if (a[i]>nowmin+k)
    {
      ans++;
      cnt=0;
      nowmin=1100000000;
    }
    cnt++;
    if (a[i]<nowmin) nowmin=a[i];
    if (cnt==c)
    {
      cnt=0;
      nowmin=1100000000;
      ans++;
    }
  }
  if (cnt>0) ans++;
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 640
N,K = map(int,input().split())
A = list(map(int,input().split()))

dp = [0 for i in range(K+1)]
for i in range(K+1) :
    for a in A :
        if i-a < 0 :
            pass
        elif i-a == 0 :
            dp[i] = "First"
            break
        elif dp[i-a] == "Second" :
            dp[i] = "First"
            break
    else :
        dp[i] = "Second"
ans = dp[K]
print(ans)


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

using namespace std;

int main()
{
	int N, M, D;

	while (true)
	{
		scanf("%d", &N);
		scanf("%d", &M);

		if (N == 0 && M == 0) { break; }

		vector<int> C; C.push_back(0);

		for (int i = 0; i < N; i++)
		{
			scanf("%d", &D);

			if (D <= M)
			{
				C.push_back(D);
			}
		}

		vector<int> r;

		for (int i = 0; i < C.size(); i++)
		{
			for (int j = i; j < C.size(); j++)
			{
				if (C[i] + C[j] <= M)
				{
					r.push_back(C[i] + C[j]);
				}
			}
		}

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

		int ret = 0;

		for (int i = 0; i < r.size(); i++)
		{
			int ptr = upper_bound(r.begin(), r.end(), M - r[i]) - r.begin() - 1;
			
			if (ptr >= 0)
			{
				ret = max(ret, r[i] + r[ptr]);
			}
		}

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

	return 0;
}

Measured memory_bytes: 6896
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double pi = acos(-1);
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

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

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) {
	for (auto &e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

//↑template↑




void COMinit() {
	fac[0] = 1, fac[1] = 1, finv[0] = 1, finv[1] = 1, inv[1] = 1;
	for (int i = 2; i < 100005; ++i) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

//calc
long long COM(long long n, long long k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


void dijkstra(int n) {
	priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>que;
	fill(dij.begin(), dij.end(), INF);
	dij[n] = 0;
	que.push(pair<ll, ll>(0, n));

	while (!que.empty()) {
		pair<ll, ll>p = que.top();
		que.pop();
		ll mon = p.second;
		if (dij[mon] < p.first) continue;
		for (int i = 0; i < G[mon].size(); ++i) {
			edge e = G[mon][i];
			if (dij[e.to] > dij[mon] + e.cost) {
				dij[e.to] = dij[mon] + e.cost;
				que.push(pair<ll, ll>(dij[e.to], e.to));
			}
		}
	}
}



int main() {
	ll a, b;
	cin >> a >> b;
	COMinit();

	for (int i = 0; i < b; ++i) {
		cout << COM(a - b + 1, i + 1)*COM(b - 1, i) % MOD << endl;;
	}
}

Measured memory_bytes: 3584
#include<iostream>
using namespace std;
int main()
{
	int a, b, T;
	char c;
	while (	cin >> a >> c >> b) {
		if (c == '+')cout << a + b << endl;
		if (c == '-')cout<<a-b<<endl;
		if (c == '*')cout<<a*b<<endl;
		if (c == '/')cout<<a/b<<endl;
		if (c == '?')break;
	}
	return 0;

}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
#define deb(x) cout << #x << "  = " << x << endl
typedef long long int ll;
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)

#define dbg2(x, y)                                                       \
    {                                                                    \
        cout << #x << ": " << (x) << " , " << #y << ": " << (y) << endl; \
    }
#define fo(i, n) for (int i = 0; i < n; i++)
#define fok(i, k, n) for (int i = k; i < n; i++)
#define foA(i, A) for (auto i : A)
const int mxN=101;
const int modd=1e9+7;
int a[mxN];
int suf[mxN];
int dp[mxN][100003];

int ans=0, n;
int rfun(int ind, int k){
    //dbg2(ind, k);deb(ans);
    if(ind==n){
        // ans++;if(ans>=modd){ans-=modd;}
        return 1;
    }
    if(k<0)return 0;
    if(dp[ind][k]!=-1)return dp[ind][k];
    int an=0;
    for(int i=max(0, (k-suf[ind+1]));i<=min(k, a[ind]);i++){
        //dbg2(i, ind);
        an+= rfun(ind+1, k-i);
        an%=modd;
    }
    return dp[ind][k]=an;
}

int main(){
    int k;cin>>n>>k;
    fo(i, n)cin>>a[i];
    sort(a, a+n);
    memset(dp, -1,sizeof dp);
    suf[n-1]=a[n-1];
    for(int i=n-1;i>=0;i--){
        suf[i]=suf[i+1]+a[i];
    }
    for(int j=0;j<=k;j++){
        if(j<=a[0])dp[0][j]=1;
        else dp[0][j]=0;
    }
    for(int i=1;i<n;i++){
        vector<int>v(k+1, 0);
        v[0]=dp[i-1][0];
        for(int j=1;j<=k;j++)v[j]=(dp[i-1][j]+v[j-1])%modd;
        for(int j=0;j<=k;j++){
            if(j>a[i]){
                dp[i][j]=(v[j]-v[j-a[i]-1]+modd)%modd;;
            }
            else dp[i][j]=v[j];
        }
    }
    ans=dp[n-1][k];
    //ans= rfun(0, k);
    cout<<ans;
}

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

int U[105], V[105], A[105], B[105];
int C[55], D[55];

long long distances[55][10005];

typedef tuple<long long int, int, int> ti; //time, node number, silver coins
vector<tuple<int, int, int> > adjList[55];

void dijkstra(int S)
{
	priority_queue<ti, vector<ti>, greater<ti> > minHeap;
	minHeap.push( make_tuple(0, 1, min(S, 10000)) );
	
	while(!minHeap.empty())
	{
		ti curr = minHeap.top();
		minHeap.pop();
		
		long long time = get<0>(curr);
		int nodeNum = get<1>(curr), silverCoins = get<2>(curr);
		
		if(distances[nodeNum][silverCoins] != time)
			continue;
			
		vector<tuple<int, int, int> >::iterator itr;
		
		
		for(itr = adjList[nodeNum].begin(); itr != adjList[nodeNum].end(); itr++)
		{
			int nextNode = get<0>(*itr), Ai = get<1>(*itr), Bi = get<2>(*itr);
			if(silverCoins - Ai < 0)
				continue;
					
			if(distances[nodeNum][silverCoins] + Bi < distances[nextNode][silverCoins - Ai])
			{
				distances[nextNode][silverCoins - Ai] = distances[nodeNum][silverCoins] + Bi;
				minHeap.push(make_tuple(distances[nextNode][silverCoins - Ai], nextNode, silverCoins - Ai));
			}
		}
		
		int Ci = C[nodeNum], Di = D[nodeNum];
		if(distances[nodeNum][silverCoins] + Di < distances[nodeNum][min(10000, silverCoins + Ci)])
		{
			distances[nodeNum][min(10000, silverCoins + Ci)] = distances[nodeNum][silverCoins] + Di;
			minHeap.push( make_tuple(distances[nodeNum][min(10000, silverCoins + Ci)], nodeNum, min(10000, silverCoins + Ci)) );
		}
	}
}

int main()
{
	int N, M, S;
	scanf("%d%d%d", &N, &M, &S);
	
	int i;
	for(i = 1; i <= M; i++)
	{
		scanf("%d%d%d%d", &U[i], &V[i], &A[i], &B[i]);
		adjList[U[i]].push_back(make_tuple(V[i], A[i], B[i]));
		adjList[V[i]].push_back(make_tuple(U[i], A[i], B[i]));
	}
	
	for(i = 1; i <= N; i++)
	{
		scanf("%d%d", &C[i], &D[i]);
	}
	
	for(i = 1; i <= N; i++)
	{
		for(int j = 0; j < 10005; j++)
		{
			distances[i][j] = (1ll << 62);
		}
	}
	
	distances[1][min(S, 10000)] = 0;
	dijkstra(S);
	for(i = 2; i <= N; i++)
	{
		long long minimum = (1ll << 62);
		for(int j = 0; j < 10005; j++)
			minimum = min(minimum, distances[i][j]);
			
		printf("%lld\n", minimum);
	}
}


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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll A[2005];

//! [自分がiを引いた時の]=(最大値、最小値)
pll dp[2005];

int main()
{
    ll N, Z, W;
    cin >> N >> Z >> W;
    A[0] = W;
    REP(i, N)
    {
        cin >> A[i + 1];
    }

    for (int i = N - 1; i >= 0; --i)
    {
        pll m(-INF, INF);
        for (int j = i + 1; j < N; ++j)
        {
            m.first = std::max(m.first, dp[j].second);
            m.second = std::min(m.second, dp[j].first);
        }
        dp[i].first = std::max(abs(A[N] - A[i]), m.first);
        dp[i].second = std::min(abs(A[N] - A[i]), m.second);
    }
    cout << dp[0].first << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define si short int
#define speed ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pill pair<ll,ll>
#define f first
#define s second
#define pilc pair<ll,char>
#define all(a) (a).begin(),(a).end()
#define rep(s,e,step) for(int i = (s); i < (e) ; i += step)
#define vrep(s,e,step) for(int j = (s); j < (e) ; j += step)
#define ex exit(0)
#define sz(a) (a).size()


using namespace std;

const ll N = 2e5 + 10;
const ll big = 1e18;
const ll block = 800;
const ll mod = 1e6;

ll a, b, n;

int main() {
	speed;
	cin >> a >> b >> n;
	cout << (a * min(n, (b - 1)) / b) ;
}

/*

0 133 14 135 28 137 42 139 56 141 70 143

*/



Measured memory_bytes: 3652
#include<string>
#include<iostream>

using namespace std;

bool isA(string s)
{
	int len=s.length();
	if(len<6)					return false;
	if(s.substr(0,2)!=">'")		return false;
	if(s.substr(len-1)!="~")	return false;

	s=s.substr(2,len-3);
	len=s.length();
	if(len%2==0)		return false;
	if(s[len/2]!='#')	return false;
	if(s.substr(0,len/2)!=string(len/2,'='))	return false;
	if(s.substr(len/2+1)!=string(len/2,'='))	return false;
	return true;
}

bool isB(string s)
{
	int len=s.length();
	if(len<6)					return false;
	if(s.substr(0,2)!=">^")		return false;
	if(s.substr(len-2)!="~~")	return false;

	s=s.substr(2,len-4);
	len=s.length();
	if(len%2==1)	return false;
	bool b=true;
	for(int i=0;i<len;i+=2){
		if(s[i+0]!='Q')	b=false;
		if(s[i+1]!='=')	b=false;
	}
	return b;
}

int main()
{
	int n;	cin>>n;
	string snake;
	while(n--){
		cin>>snake;
		if     (isA(snake))	cout<<'A'<<endl;
		else if(isB(snake))	cout<<'B'<<endl;
		else				cout<<"NA"<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#define maxn 100010
using namespace std;
int n,d[maxn];
// d: 01: sheep; 1: wolf
char s[maxn];
int f(int a,int b,char ch) {
	if (b==0) {
		if (ch=='o')
			return a;
		else return 1-a;
	}
	else {
		if (ch=='o')
			return 1-a;
		else return a;
	}
}
int main() {
	scanf("%d %s",&n,s);
	bool t=true;
	for (int i=0;i<=1;i++) {
		for (int j=0;j<=1;j++) {
			d[1]=i; d[2]=j;
			for (int k=2;k<=n;k++) {
				d[k+1]=f(d[k-1],d[k],s[k-1]);
			}
			if (d[n+1]==d[1]&&f(d[n],d[1],s[0])==d[2]) {
				for (int k=1;k<=n;k++)
					if (d[k]==0)
						printf("S");
					else printf("W");
				printf("\n");
				t=false;
				break;
			}
		}
		if (!t)
			break;
	}
	if (t)
		printf("-1\n");
	return 0;
}

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

int main () {
  int A , B , C ;
  cin >> A >> B >> C ;
  if(A==B && A != C){
    cout << "Yes" << endl;
  }
  else if(A==C && A != B ) {
   cout << "Yes" << endl;
  }
  else if(B==C && A !=B) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

using namespace std;

const int MAXN = 500005;

int n;
string s;
int p[MAXN], ok[2][MAXN];

void calc (int ind) {
    ok[ind][0] = 1;
    p[0] = 0;
    for (int i = 1; i < n; i++) {
        int curr = p[i - 1];
        while (curr > 0 && s[curr] != s[i]) curr = p[curr - 1];
        if (s[curr] == s[i]) curr++;
        p[i] = curr;
        int r = i + 1 - curr;
        if (!((i + 1) % r == 0 && (i + 1) / r >= 2)) ok[ind][i] = 1;
    }
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> s;
    n = s.size();
    bool isti = 1;
    for (int i=0; i<n; i++) {
        if (i > 0 && s[i] != s[i - 1]) isti = 0;
    }
    if (isti) {
        cout << n << endl << 1;
        return 0;
    }
    calc(0);
    reverse(s.begin(), s.end());
    calc(1);
    if (ok[0][n - 1]) {
        cout << 1 << endl << 1;
        return 0;
    }
    int cnt = 0;
    for (int i=0; i<n-1; i++) {
        if (ok[0][i] == 1 && ok[1][n - i - 2] == 1) cnt++;
    }
    cout << 2 << endl << cnt;
    return 0;
}


Measured memory_bytes: 6684
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));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).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int n;
const ll t = 2000000000000ll;
int main(int argc, char *argv[]){
	ios::sync_with_stdio(false);
	cin >> n;
	vi v(2*n);
	REP(i, 2*n) cin >> v[i];
	sort(ALL(v));
	int ans = 0;
	REP(i, n) ans += v[2 * i];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import itertools

def resolve():
    N = int(input())
    P_list = tuple(map(int, input().split()))
    Q_list = tuple(map(int, input().split()))

    N_list = [(i+1) for i in range(N)]
    N_permutations_list = itertools.permutations(N_list)

    i = 1
    for i_list in N_permutations_list:
        if i_list == Q_list:
            a = i
        if i_list == P_list:
            b = i
        i += 1

    print(abs(a-b))


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
  vector<string> pattern(8), ans(8);
  for (int i = 0; i < 8; ++i) {
    cin >> pattern[i];
    ans[i] = pattern[i];
  }

  for (int r = 90; r <= 270; r += 90) {
    for (int i = 0; i < 8; ++i) {
      for (int j = 0; j < 8; ++j) 
	ans[j][7-i] = pattern[i][j];
    }

    cout << r << endl;
    for (int i = 0; i < 8; ++i)
      cout << ans[i] << endl;
    pattern = ans;
  }

  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<stdlib.h>
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
	long long int a[10];
	long long int n;
	long long int t = 0;
	long long int sum = 0;
	cin >> n;
	for(int i = 0; i < 5; i++){
		cin >> a[i];
		if(a[i] > a[i-1] && i > 0)a[i] = a[i-1];
		//sum += a[i];
	}
	//long long int b[10];
	for(int i = 0; i < 5; i++){
		sum += a[4];
	}
	t += (n/sum) *5;
	t += 4;
	//cout << t << endl;
	n = n%sum;

	//n-=a[4];
	//cout << n << endl;
	for(int i = 4; i >= 0;i--){
		if(n > 0)t++;
		n -= a[4];
		//cout << n << endl;
	} 
	
	cout << t;	
	
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 100100100100;


ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}

int keta(ll num){
    int digits = 0;
    while(num > 0){
        num /= 10;
        digits++;
    }
    return digits;
}


int main(){
    int N;
    cin >> N;
    vector<int> t(N), x(N), y(N);
    rep(i, N) cin >> t[i] >> x[i] >> y[i];
    int nx = 0, ny = 0;
    rep(i, N){
        int dist = (x[i] - nx) + (y[i] - ny);
        if(i == 0){
            if(dist > t[0]){
                cout << "No" << endl;
                return 0;
            }
            if((t[0] - dist) % 2 == 1){
                cout << "No" << endl;
                return 0;
            }
        }else{
            if(dist > t[i] - t[i - 1]){
                cout << "No" << endl;
                return 0;
            }
            if(((t[i] - t[i- 1]) - dist) % 2 == 1){
                cout << "No" << endl;
                return 0;
            }
        }
        nx = x[i];
        ny = y[i];
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 1408
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lop(c,l) for(int c=1;c<=(l);++c)
#define loop(c,l) for(int c=0;c<(l);++c)
using namespace std;

#define int long long
const int mod=1000000007;
int n,pre;
int arr[200001],dp[200001],cnt[200001];
inline int add(const int& a,const int& b){
	 return (a+b)%mod;
}
signed main(signed,char**,char**){
	scanf("%lld",&n);
	lop(i,n) scanf("%lld",&arr[i]);
	dp[0]=1;
	lop(i,n){
		if(arr[i]!=arr[i-1]){
			dp[i]=add(dp[pre],cnt[arr[i]]);
			cnt[arr[i]]=add(cnt[arr[i]],dp[pre]);
			pre=i;
		}
	}
	printf("%lld",dp[pre]);
	exit(0);
}

Measured memory_bytes: 4992
#include <iostream>

using namespace std;

int solve(int n) {
    int total = 0;
    int count = 0;
    for (int i = 1, j = 1; i < n; ++i) {
        while (total < n) {
            total += j;
            ++j;
        }
        if (total == n) {
            ++count;
        }
        total -= i;
    }
    return count;
}

int main() {
    int n;
    while (true) {
        cin >> n;
        if (n == 0) {
            return 0;
        }
        cout << solve(n) << endl;
    }
}

Measured memory_bytes: 1164
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
#define rg register
#define MX 1005
inline int read()
{
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
	return x*f;
}
struct Edge
{
	int v,nxt;
}edge[MX<<1];
int n,cnt,head[MX],v[MX],f[2][5005],g[MX];
inline void add_edge(int x,int y)
{edge[++cnt].v=y;edge[cnt].nxt=head[x];head[x]=cnt;}
void dfs(int x,int fa)
{
	for(int i=head[x];i;i=edge[i].nxt)
		if(edge[i].v!=fa) dfs(edge[i].v,x);

	memset(f[0],inf,sizeof(f[0]));
	f[0][0]=0;
	int cur=0;
	for(int i=head[x];i;i=edge[i].nxt)
	{
		int y=edge[i].v;if(y==fa) continue;
		cur^=1;
		memset(f[cur],inf,sizeof(f[cur]));
		for(int j=0;j<=v[x];j++)
		{
			//f[cur][j]=inf;
			if(j>=v[y]) f[cur][j]=min(f[cur][j],f[cur^1][j-v[y]]+g[y]);
			if(j>=g[y]) f[cur][j]=min(f[cur][j],f[cur^1][j-g[y]]+v[y]);
		}
	}
	for(int i=0;i<=v[x];i++)
		g[x]=min(g[x],f[cur][i]);
}
int main(){
	//freopen("a.in","r",stdin);
	n=read();
	for(int i=2;i<=n;i++)
	{
		int a=read();
		add_edge(i,a);
		add_edge(a,i);
	}
	
	for(int i=1;i<=n;i++) v[i]=read();
	
	memset(g,inf,sizeof(g));
	dfs(1,-1);
	
	if(g[1]!=inf) printf("POSSIBLE\n");
	else printf("IMPOSSIBLE\n");
	
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define vii vector<int>
#define vll vector<long long>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n;
    int ans = 0;
    rep(i, 0, n) {
        int x; cin >> x;
        bool flag = (x >= 2 ? true : false);
        for (int j = 2; j * j <= x; ++j) {
            if (x % j == 0) flag = false;
        }
        if (flag) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3236