akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;
#define Pi 3.1415926535897932384626
#define mod llint(1e9+7)

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(llint a, llint b) {
	return a > b;
}

// mod. m での a の逆元 a^{-1} を計算する
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;
}

//aCbを1000000007で割った余りを求める
llint convination(llint a, llint b) {
	llint ans = 1;
	for (llint i = 0; i < b; i++) {
		ans *= a - i;
		ans %= 1000000007;
	}
	for (llint i = 1; i <= b; i++) {
		ans *= modinv(i, 1000000007);
		ans %= 1000000007;
	}
	return ans;
}

//aのb乗をmodで割った余りを求める
llint power(llint a, llint b) {
	if (b == 1)return a;
	if (b == 0)return 1;
	llint tmp = power(a, b / 2);
	tmp *= tmp;
	tmp %= mod;
	if (b % 2 == 1) {
		tmp *= a;
		tmp %= mod;
	}
	return tmp;
}

int main() {
	llint n;
	cin >> n;
	llint tmp = sqrt(n);
	for (llint i = tmp; 0 < i; i--) {
		if (n % i == 0) {
			cout << i + n / i - 2 << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int n, a, i, cnt = 0;
    scanf ("%d", &n);
    for (i = 0 ; i < n ; i++) {
        scanf ("%d", &a);
        if (i % 2 == 1) continue;
        if (a % 2 == 1) cnt++;
    }
    printf ("%d", cnt);
    return 0;
}

Measured memory_bytes: 1684
def calc(n, D):
    if D[0] != 0:
        return 0
    count = [0 for i in range(n)]
    for i in D:
        count[i] = count[i] + 1
    if count[0] != 1:
        return 0
    #for i in count:
    #    print("count",i)
    tmp = 1
    sum = 0
    for i in range(n-1):
    #    print(count[i],count[i+1])
        sum = sum + count[i]
        if sum == n:
            break
        if count[i] == 0:
            tmp = 0
            break
        tmp = tmp * (count[i]**count[i+1])
    return tmp

n = int(input())
#print("n=",n)
D = list(map(int, input().split()))

print(calc(n,D) % 998244353)



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

int main () {
    
    vector<ll> kinds;
    ll k, n; cin >> n >> k;
    for(int i = 0; i < n; i++) {
        ll aux;
        cin >> aux;
        kinds.push_back(aux);
    }

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

    ll resp = 0;

    for(int i = 0; i < k; i++) {
        resp += kinds[i];
    }
    cout << resp << endl;
    return 0;
}

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

	int n, fi, se, th, fo, x1, x2, y1, y2, z1, z2, w1, w2;
	while (true) {
		scanf("%d", &n);
		if (n == 0)
			break;
		for (int i = 0; i < n; i++) {
			scanf("%d%d%d%d%d%d%d%d", &x1, &y1, &z1, &w1, &x2, &y2, &z2, &w2);
			fi = x1 * x2 + (-1) * (y1 * y2) + (-1) * (z1 * z2)
					+ (-1) * (w1 * w2);
			se = x1 * y2 + y1 * x2 + z1 * w2 + (-1) * w1 * z2;

			th = x1 * z2 + (-1) * (y1 * w2) + z1 * x2 + w1 * y2;
			fo = x1 * w2 + y1 * z2 + (-1) * (z1 * y2) + w1 * x2;

			printf("%d %d %d %d\n", fi, se, th, fo);
		}
	}
	return 0;
}

Measured memory_bytes: 3172
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
 
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
 
 typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
 
#define int         long long
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define mp          make_pair
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
//#define hell          1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
// mp::cpp_int
 
const int hell=998244353;
 
 int power(int a,int b)
 {
  if(b==0)return 1LL;
  if(b==1)return a;
  int t=power(a,b/2);
  t*=t;
  t%=hell;
  if(b&1)return (t*a)%hell;
  else return t;
 }
 int inverse(int a)
 {
    return power(a,hell-2);
 }
 
int pw(int a,int b)
{
  int x=a;
  rep(i,1,b){a=a*x;
    a%=10000000000LL;}
  return a;
}
 
int gcd(int a,int b)
{   
  
  if(b==0)return a;
  return gcd(b-a%b,a%b);
}
 
bool cmp(pii a,pii b)
{
  return a.SS<b.SS;
}
 
 
int solve()
{  

int n;

cin>>n;

vi a(n);
rep(i,0,n)cin>>a[i];
a[0]--;
int x=a[0];

bool b=true;
rep(i,1,n)
{
   if(a[i]>x)
   {
    x=a[i]-1;continue;
   }
   else if(a[i]==x)
   {
    x=a[i];
    continue;
   }
   else 
   {
    b=false;
    break;
   }
}


if(b)
{
    cout<<"Yes";
}
else
{
    cout<<"No";
}


return 0;
}
 
signed main()
{  int t=1;
//pri();
 ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
  
   cin.exceptions(cin.failbit);                                                                    
 

 
  clock_t time_req;
 
    // Without ung pow function
                                                                                                                   
 // cin>>t;
 
    int k=1;
     
   while(t--)
     {
      //cout<<"Case #"<<k<<":"<<" ";k++;
      solve();
     }
        exit(0);
 
         time_req = clock() - time_req;
    cout <<endl<< "Processor time taken is "
      << (double)time_req/CLOCKS_PER_SEC << " seconds" << endl;
 
 
    return 0;
} 

Measured memory_bytes: 1024
n,k = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
x,y,num,ans = [0],[],40,0
for i in range(n): x.append(x[-1]+a[i])
for i in range(n):
    for j in range(i+1,n+1): y.append(x[j]-x[i])
for i in range(40,-1,-1):
    c,d = 0,ans+2**i
    for j in y:
        if d&j==d: c+=1
    if c>=k: ans = d
print(ans)

Measured memory_bytes: 22964
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

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

const double PI = acos(-1);
typedef long long ll;
#define int ll
#define fori(n) for(int i=0; i<int(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cind(d) double d; cin>>d;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a, n) vd a(n); fori(n) { cin>>a[i]; }

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;

/* How to include "exactly n/2 elements" ?
 * Like knapsack?
 * maxval(i,k,bool)=max(a[i]+maxval(i+1, k-1, true), maxval(i+1, k, false));
 */
void solve() {
    cini(n);
    cinai(a,n);

    map<pii, int> memo;
    const int INF=1e18;
    function<int(int,int)> maxval=[&](int i, int k) {
        if(k==0)
            return 0LL;

        int need=(k-1)*2+1;
        if(i+need>n)
            return -INF;

        pii key={i,k};
        auto it=memo.find(key);
        if(it!=memo.end())
            return it->second;
            
        return memo[key]=max(a[i]+maxval(i+2, k-1), maxval(i+1, k));
    };

    int ans=maxval(0, n/2);
    cout<<ans<<endl;
}

signed main() {
    cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    solve();
}



Measured memory_bytes: 35936
#include <iostream>
using namespace std;
using ll = long long;
int main() {
    ll x, k, d;
    cin >> x >> k >> d;
    ll a = abs(x) / d;
    if (a >= k) {
        cout << abs(x) - d * k << '\n';
    } else {
        k -= a;
        if (k % 2 == 0) {
            cout << abs(x) - d * a << '\n';
        } else {
            cout << abs(abs(x) - d * (a + 1)) << '\n';
        }
    }
}

Measured memory_bytes: 3656
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int atoi1(char *s)
{
    int r;
    int i;
    
    r = 0;
    while (*s != '\0'){
        r = r * 10 + *s - '0';
        s++;
    }
    return (r);
}


int main(void)
{
    char str[130];
    char str1[130];
    char str2[130];
    char str3[130];
    char str1_tmp[130];
    char str2_tmp[130];
    char str3_tmp[130];
    char dainyuu[11] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
    int i;

    // extras
    char *token;
    int sum_left;
    int sum_right;
    int flag;
    int value;
    int answer;

    while (fscanf(stdin, "%s", str) != EOF){
        token = strtok(str, "+");
        strcpy(str1, token);

        token = strtok(NULL, "=");
        strcpy(str2, token);

        token = strtok(NULL, "\n");
        strcpy(str3, token);

        strcpy(str1_tmp, str1);
        strcpy(str2_tmp, str2);
        strcpy(str3_tmp, str3);

        flag = 0;
        value = 0;
        while (value < 10){
            // str1, str2, str3縺ｮ蛻晄悄蛹・
            strcpy(str1, str1_tmp);
            strcpy(str2, str2_tmp);
            strcpy(str3, str3_tmp);

            // str1縺ｮX縺ｮ蛟､縺ｮ莉｣蜈･
            i = 0;
            while (str1[i] != '\0'){
                if (str1[i] == 'X'){
                    if (i == 0 && strlen(str1) >= 2 && value == 0){
                        str1[i] = ' ';
//                        goto NEXT;
                    }
                    else {
                        str1[i] = dainyuu[value];
                    }
                }
                i++;
            }
            
            // str2縺ｮX縺ｮ蛟､縺ｮ莉｣蜈･
            i = 0;
            while (str2[i] != '\0'){
                if (str2[i] == 'X'){
                    if (i == 0 && strlen(str2) >= 2 && value == 0){
                        str2[i] = ' ';
//                        goto NEXT;
                    }
                    else {
                        str2[i] = dainyuu[value];
                    }
                }
                i++;
            }

            // str3縺ｮX縺ｮ蛟､縺ｮ莉｣蜈･
            i = 0;
            while (str3[i] != '\0'){
                if (str3[i] == 'X'){
                    if (i == 0 && strlen(str3) >= 2 && value == 0){
                        str3[i] = ' ';
//                        goto NEXT;
                    }
                    else {
                        str3[i] = dainyuu[value];
                    }
                }
                i++;
            }

            // 險育ｮ・
            
//            printf("<%s+%s=%s>\n", str1, str2, str3);
            sum_left = atoi1(str1) + atoi1(str2);
            sum_right = atoi1(str3);

            if (sum_left == sum_right){
                answer = value;
                flag = 1;
                break;
            }
NEXT:
            value++;
        }
        if (flag == 1){
            printf("%d\n", answer);
        }
        else {
            printf("NA\n");
        }
    }
    return (0);
}



Measured memory_bytes: 2032
#include <bits/stdc++.h>
#define mp make_pair
#define X first
#define Y second
#define pii pair<ll,ll>
#define x1 dlfjl
#define x2 dkfj
#define MOD 1000000007
#define y1 dskgj
#define y2 dskfj
#define N 310
typedef long long ll;
using namespace std;
ll n,i,j,k,x,y,z,m,Q,w,h;
ll a[100500], b[100500];
int main() {
    //freopen("input.txt","r",stdin);
    cin >> n;
    for (i = 1; i <= n; i++)
        cin >> a[i];
    for (i = 1; i <= n; i++)
    {
        if (a[i] == i)
        {
            k++;
            if (i != n)
                swap(a[i], a[i+1]);
        }
    }
    cout << k << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;
 
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
 
template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
 
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<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}
 
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const int MOD = 1000000007;

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

  ll n;
  cin >> n;
  vector<ll> a(n), b(n);
  REP(i, n) cin >> a[i];
  REP(i, n) cin >> b[i];

  ll ret = 0, sum = 0, sumb = 0;
  vector<ll> v;
  REP(i, n) {
    if(a[i]-b[i] < 0) {
      ret++;
      sum += b[i]-a[i];
    } else {
      v.push_back(a[i]-b[i]);
      sumb += a[i]-b[i];
    }
  }
  sort(ALL(v), greater<>());

  if(sum > sumb) {
    cout << -1 << endl;
    return 0;
  }
  
  REP(i, v.size()) {
    if(sum <= 0) break;
    sum -= v[i];
    ret++;
  }

  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 2936
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF (2147483647)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define MAXV 110
int V,E;
vector<vector<ll> >G(MAXV,vector<ll>(MAXV,INF));//init
ll r(){ll x;cin>>x;return x;}//input longlong
void solve()
{
    cin>>V>>E;
    REP(i,V)G[i][i]=0;//init
    REP(i,E)G[r()][r()]=r();//input
    //floyd-warshall //jump when i->k=inf or k->j=inf
    REP(k,V)REP(i,V)REP(j,V)G[i][j]=(G[i][k]==INF||G[k][j]==INF?G[i][j]:min(G[i][j],G[i][k]+G[k][j]));
    //if can RELAX,negative cycle
    REP(i,V)REP(j,V)if(G[i][j]<0)REP(k,V)if(G[i][j]!=min(G[i][j],G[i][k]+G[k][j])){cout<<"NEGATIVE CYCLE"<<endl;return;}
    //output //attenion!! presentation
    REP(i,V)REP(j,V)cout<<(G[j][i]==INF?"INF":to_string(G[j][i]))<<(j==V-1?"\n":" ");
}
int main()
{
    cin.tie(0);
	ios::sync_with_stdio(false);
    solve();
    return 0;
}


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

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

int main() {
    int n;cin>>n;
    const int INF = 1000000007;
    int a[n];
    rep(i,n)cin>>a[i];
    sort(a,a+n);
    
    if(n%2==1){
        int c=0;
        rep(i,n - 1){
            if(i%2==0 && a[i+1]!=a[i]+2 || i%2==1 && a[i+1]!=a[i])c=1;
        }
        if(a[0]!=0 || c==1){
            cout<<0<<endl;
            return 0;
        }
    }
    else{
        int c=0;
       rep(i,n - 1){
            if(i%2==1 && a[i+1]!=a[i]+2 || i%2==0 && a[i+1]!=a[i])c=1;
        }
        if(a[0]!=1 || c==1){
            cout<<0<<endl;
            return 0;
        }
    }
    int ans=1;
    rep(i,n/2){
        ans*=2;
        ans%=INF;
    }
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main{
	public static void main(String[] args){

		Scanner scan = new Scanner(System.in);

		while(true){
			
			int h = scan.nextInt();
			int w = scan.nextInt();

			if(h == 0 && w == 0){
				break;
			}else{
				for(int a = 0; a < h; a++){
					for(int b = 0; b < w; b++){
						if(a == 0 || a == h - 1){
							System.out.print("#");
						}else if(b == 0 || b == w - 1){
							System.out.print("#");
						}else{
							System.out.print(".");
						}
					}
					System.out.println();
				}
				System.out.println();
			}
		}
	}
}

Measured memory_bytes: 33624
n,k=map(int,input().split())
a=list(map(int,input().split()))
l=len(bin(max(max(a),k)))-2
b=[bin(a[i])[2:].zfill(l)for i in range(n)]
s=bin(k)[2:].zfill(l)
x=""
f=True
for i in range(l):
  if f and s[i]=="0":x+="0";continue
  z=o=0
  for j in b:
    if j[i]=="0":z+=1
    else:o+=1
  if o<z:t="1"
  else:t="0"
  if s[i]+t=="10":f=False
  x+=t
x=int(x,2)
ans=0
for i in a:ans+=i^x
print(ans)

Measured memory_bytes: 20576
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
    int n = 0;
    cin >> n;
    vector<int> b(n+1);
    for (int i=1; i<n+1; i++) {
        cin >> b.at(i);
    }
    vector<int> ans;
    for (int i=n; i>=1; i--) {
        bool flag = false;
        for (int j=i; j>=1; j--) {
            if (j == b.at(j)) {
                ans.push_back(j);
                b.erase(b.begin() + j);
                flag = true;
                break;
            }
        }
        if (!flag) {
            cout << -1 << endl;
            return 0;
        }
    }
    reverse(ans.begin(), ans.end());
    for (int x : ans) {
        cout << x << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner scanner = new Scanner(System.in);

		int n = scanner.nextInt();
		int k = scanner.nextInt();
		long[] a = new long[n];
		long[] b = new long[n];
		int count = 0;
		int l=k;

		for(int i=0 ; i<n ; i++) {
			a[i] = scanner.nextLong();
		}



		for(int i=0 ; i<b.length ; i++) {
			b[i] = 1;
		}

//		for(int i=0 ; i<n-k+1 ; i++) {
//			l  = k;
//			while(l > 0) {
//				b[i] *= a[l-1+i];
//				l--;
//			}
//		}

//		for(long test : b) {
//			System.out.println(test);
//		}

		for(int i=k-1 ; i<n-1 ; i++) {
			if(a[i-(k-1)] < a[i+1]) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
		}

//		int i=0;
//
//		while(k < n) {
//
//			if(b[i] < b[i+1]) {
//				System.out.println("Yes");
//			}else {
//				System.out.println("No");
//			}
//
//			i++;
//			k++;
//		}









		scanner.close();

	}

}


Measured memory_bytes: 63276
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    long long ans = 0;
    cin >> n;
    vector<int> a(3*n);
    for(int i = 0; i < 3*n; i++){
        scanf("%d", &a[i]);
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    for(int i = 1; i < 2*n; i+=2){
        ans += a[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
n, x, m = map(int, input().split())
mn = min(n, m)
P = [] # pre_sum
sum_p = 0 # sum of pre + cycle
X = [-1] * m # for cycle check & pre_len
for i in range(mn):
    if X[x] > -1:
        cyc_len = len(P) - X[x]
        remain = P[X[x]]
        cyc = (sum_p - remain) * ((n - X[x]) // cyc_len)
        remain += P[X[x] + (n - X[x]) % cyc_len] - P[X[x]]
        print(cyc + remain)
        exit()
    P.append(sum_p)
    sum_p += x
    X[x] = i
    x = x*x % m
print(sum_p)


Measured memory_bytes: 13648
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <ctime>
using namespace std;

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

typedef vector<int> vi;
typedef pair<int,int> pii;

const int inf=1<<29;

int n;
int dp[100010];
int panel[100010];

void dijkstra(void){
	rep(i,n) dp[i]=inf;

	priority_queue <pii,vector<pii>,greater<pii> > q;
	pii init;
	init.first=0;
	init.second=0;
	dp[0]=0;
	q.push(init);
	while(!q.empty()){
		pii cur=q.top(); q.pop();

		if(dp[cur.first] < cur.second)
			continue;

		//cout << iconvert[cur.first] << " "<< cur.second << endl;

		if(panel[cur.first]){
			pii next;
			next.first=cur.first+panel[cur.first];
			next.second=cur.second;
			if(dp[next.first]>next.second){
				dp[next.first]=next.second;
				q.push(next);
			}

		}else{
			rep(i,6){
				pii next;
				next.first=cur.first+i+1;next.second=cur.second+1;
				if(dp[next.first] > next.second){
					dp[next.first]=next.second;
					q.push(next);
				}
			}
		}
	}
	return ;
}

int main(void){
	cin >> n;
	rep(i,n) cin >> panel[i];
	dijkstra();
	cout << dp[n-1] << endl;
	/*rep(i,n){
		cout << i << " " << dp[i] << endl;

	}*/
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

//-------------------------------------------------
//--Range Set Counter (Hash)
//-------------------------------------------------
template<typename T>
class RangeSet
{
private:
    ::std::vector<T> v;
    ::std::unordered_map<T, ::std::vector<int> > data;
public:
    RangeSet(const ::std::vector<T> &v_):v(v_){
        int sz = v.size();
        for(int i=0;i<sz;i++){
            T t = v[i];
            data[t].push_back(i);
        }
    }
    //query for all elements
    int query(T x){
        if (!data.count(x)) return 0;
        return data[x].size();
    }
    //query for [a, b]
    int query(int a, int b, T x){
        if (a>b) return 0;
        if (!data.count(x)) return 0;
        auto right = ::std::upper_bound(data[x].begin(),data[x].end(),b);
        auto left  = ::std::lower_bound(data[x].begin(),data[x].end(),a);
        return right-left;
    }
    //search x for [k, tail]
    int find(int k, T x){
        if (!data.count(x)) return -1;
        auto itr = ::std::lower_bound(data[x].begin(),data[x].end(),k);
        if (itr!=data[x].end()){
            return *itr;
        }else{
            return -1;
        }
    }
    //update for one point
    void update(int k, T x){
        int ei = v[k];
        auto eitr = ::std::lower_bound(data[ei].begin(),data[ei].end(),k);
        data[ei].erase(eitr);
        v[k] = x;
        if (data.count(x)){
            auto itr = ::std::lower_bound(data[x].begin(),data[x].end(),k);
            data[x].insert(itr, k);
        }else{
            data[x].push_back(k);
        }
    }
};

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    string s; cin>>s;
    vector<char> t(n);
    rep(i,n) t[i] = s[i];
    RangeSet<char> rs(t);
    int q; cin>>q;
    while(q--){
        int c; cin>>c;
        if (c==1){
            int k; char x; cin>>k>>x; k--;
            rs.update(k,x);
        }else{
            int l,r; cin>>l>>r; l--; r--;
            // cout<<l<<", "<<r<<endl;
            int cnt=0;
            rep(i,26){
                if (rs.query(l,r,(char)(i+'a'))) cnt++;
            }
            cout<<cnt<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 4892
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = nextInt(scanner);
        int ac = 0;
        int wa = 0;
        int tle = 0;
        int re = 0;
        for (int i = 0; i < n; i++) {
            switch (scanner.next()) {
                case "AC":
                    ac++;
                    break;
                case "WA":
                    wa++;
                    break;
                case "TLE":
                    tle++;
                    break;
                case "RE":
                    re++;
                    break;
            }
        }
        System.out.println("AC x " + ac);
        System.out.println("WA x " + wa);
        System.out.println("TLE x " + tle);
        System.out.println("RE x " + re);
    }


    private static int nextInt(Scanner scanner) {
        return Integer.parseInt(scanner.next());
    }

    private static long nextLong(Scanner scanner) {
        return Long.parseLong(scanner.next());
    }

    private static float nextFloat(Scanner scanner) {
        return Float.parseFloat(scanner.next());
    }

    private static double nextDouble(Scanner scanner) {
        return Double.parseDouble(scanner.next());
    }


}





Measured memory_bytes: 58108
n = int(input())
h = list(map(int, input().split()))

dp = [0] * n

for i in range(n):
    if i == 0:
        dp[i] = 0
    elif i == 1:
        dp[i] = abs(h[i]-h[i-1])
    else:
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
print(dp[n-1])


Measured memory_bytes: 13980
# -*- coding: utf-8 -*-
from heapq import heappush, heappop

A = []
inp = [None]
while inp[0] != "end":
    inp = input().split()
    if inp[0] == "insert":
        heappush(A, -int(inp[1]))
    elif inp[0] == "extract":
        print(-heappop(A))

Measured memory_bytes: 47200
N=int(input())
position_list=[0]*N

for i in range(N):
    position_list[int(i)] = list(map(int,input().split()))

import math
ans=0

for i in range(N):
    for j in range(N):
        if i != j:
            x_distance=position_list[int(i)][0]-position_list[int(j)][0]
            y_distance=position_list[int(i)][1]-position_list[int(j)][1]
            ans+=math.sqrt(x_distance**2+y_distance**2)

print(ans/N)

Measured memory_bytes: 62280
N,K = map(int,input().split())
a = list(map(int,input().split()))

ans = 10**15
for i in range(2**N):
    if bin(i).count('1')<K:
        continue
    cost = 0
    now = 0
    for j in range(N):
        if i>>j&1:
            if now>=a[j]:
                cost += now-a[j]+1
                now += 1
            else:
                now = a[j]
        else:
            now = max(now,a[j])
    ans = min(ans,cost)
print(ans)



Measured memory_bytes: 42092
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int n,m,c[100010];
vector<int> G[100010];

bool dfs(int s){
  bool res=true;
  for(int t:G[s]){
    if(c[t]!=-1){
      if(c[s]==c[t]) res=false;
    }
    else{
      c[t]=(c[s]+1)%2;
      if(!dfs(t)) res=false;
    }
  }
  return res;
}

void solve(){
  cin >> n >> m;
  rep(i,n) c[i]=-1;
  rep(i,m){
    int a,b;cin >> a >> b;
    a--;b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  ll p=0,q=0,r=0;
  rep(i,n){
    if(c[i]==-1){
      if(G[i].empty()) r+=1;
      else{
        bool f=dfs(i);
        if(f) p+=1;
        else q+=1;
      }
    }
  }
  //cout << p << " " << q << " " << r << endl;
  cout << p*p+(p+q)*(p+q)+2*r*(n-r)+r*r << endl;
}

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

Measured memory_bytes: 9984
#include <stdio.h>

int main(void)
{
	int n, i, a_i;
	int min = 1000000;
	int max = -1000000;
	long long int sum = 0;

	scanf("%d", &n);

	for (i = 0;i < n;i++) {
		scanf("%d", &a_i);
		if (a_i < min) min = a_i;
		if (a_i > max) max = a_i;
		sum += a_i;
	}

	printf("%d %d %lld\n", min, max, sum);

	return 0;
}

Measured memory_bytes: 600
#include <atcoder/convolution>
#include <atcoder/modint>
#include <cstdio>

using namespace std;
using namespace atcoder;

using mint = modint998244353;

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    vector<mint> a(n), b(m);
    for (int i = 0; i < n; i++) {
        int x;
        scanf("%d", &x);
        a[i] = x;
    }
    for (int i = 0; i < m; i++) {
        int x;
        scanf("%d", &x);
        b[i] = x;
    }
    auto c = convolution(a, b);
    for (int i = 0; i < n + m - 1; i++) {
        printf("%d ", c[i]);
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 19024
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // fixed, setprecision 
#include <math.h> // double sqrt
using namespace std;

int main(){
    int N,M;
    cin>>N>>M;
    vector<int>L(M);
    vector<int>R(M);
    for(int i=0;i<M;i++)cin>>L[i]>>R[i];
    int maxl=0,minr=100001;
    for(int i=0;i<M;i++){maxl=max(maxl,L[i]);minr=min(minr,R[i]);}
    int i=0;

   if(maxl<=minr)cout<<minr-maxl+1;
   else cout<<0;
   return 0;
}

Measured memory_bytes: 1024
// abc130c.cpp : Rectangle Cutting
#include <bits/stdc++.h>
using namespace std;
#define otf(f,x) printf(f,x)

int main(){
	double w,h,x,y;cin>>w>>h>>x>>y;
	double x0 = w/2.;
	double y0 = h/2.;
	bool f = 0;
	if((int)w%2==0 && x0==x && (int)h%2==0 && y0==y) f=1;
  	if((int)(x-x0)==0 || (int)(y-y0)==0){
		double ans = w*h/2.;
		otf("%f ", ans);
		otf("%d\n", f);
		return 0;
	}
	double a = (y-y0)/(x-x0);
	double b = y-a*x;
	double height = h;
	double width = w;
	double top = (h-b)/a;
	if(top<0.){
		top = 0.;
		height = b;
	}
	else if(w<top){
		top = 0.;
		height = a*w+b;
	}
	double bottom = -b/a;
	if(bottom<0.){
		bottom = 0.;
		height -= b;
	}
	else if(w<bottom){
		bottom = 0.;
		height -= a*w+b;
	}
	double ans1 = (top + bottom)*height/2.;
	double ans2 = w*h - ans1;
	otf("%f ", ans1<ans2? ans1: ans2);
	otf("%d\n", f);
}

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

#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define tr(c, i) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define rtr(c, i) for (typeof((c).rbegin()) i = (c).rbegin(); i != (c).rend(); --i)
#define contains(c, x) ((c).find(x) != (c).end())
#define Contains(c, x) (find(all(c), x) != (c).end())
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) REP(i, 0, (n))
#define To_String to_string< char,std::char_traits<char>,std::allocator<char> >

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

string b[] = {
	" ",
	"',.!?", "abcABC", "defDEF",
	"ghiGHI", "jklJKL", "mnoMNO",
	"pqrsPQRS", "tuvTUV", "wxyzWXYZ"
};
int main()
{
	ios_base::sync_with_stdio(0);
	string in;
	while (cin >> in) {
		in += "*";
		int p = 0;
		char c = in[0];
		ostringstream res;
		REP(i, 1, in.size()) {
			if (c != in[i]) {
				if (c == '0') {
					rep(j, p) res << ' ';
				}
				else {
					res << b[c-'0'][p%b[c-'0'].size()];
				}
				p = 0;
				c = in[i];
			}
			else {
				p++;
			}
		}
		cout << res.str() << endl;
	}
	return 0;
}

Measured memory_bytes: 0
import numpy as np
ina = input().split()
k=int(ina[0])
n=int(ina[1])
inaa = list(map(int, input().split()))
f=int(inaa[0])
inaa.pop(0)
inaa.append(k+f)
inaaa=np.array(inaa)
inaaaa=np.diff(inaaa,n=1)
print(k-np.amax(inaaaa))

Measured memory_bytes: 42692
import java.util.*;
import java.io.*;

// This file is a "Hello, world!" in Java language by OpenJDK for wandbox.

class Main
{
    public static void main(String[] args)
    {
        new Main().run();
    }
	
	final long MOD=(long)1e9+7;
	int MAX=(int)3e6;
	long[] fac=new long[MAX];
	long[] ifac=new long[MAX];
	long[] inv=new long[MAX];
	{
		fac[0]=fac[1]=ifac[0]=ifac[1]=inv[0]=inv[1]=1;
		for(int i=2;i<MAX;++i){
			fac[i]=i*fac[i-1]%MOD;
			inv[i]=MOD-inv[(int)MOD%i]*(MOD/i)%MOD;
			ifac[i]=inv[i]*ifac[i-1]%MOD;
		}
	}
	
	long comb(int n,int k){
		return fac[n]*ifac[k]%MOD*ifac[n-k]%MOD;
	}
	
	long pow(long a,long n){
		long ret=1;
		for(;n>0;n>>=1,a=a*a%MOD){
			if(n%2==1)ret=ret*a%MOD;
		}
		return ret;
	}
    
    void run(){
        Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		long[] C=new long[N];
		for(int i=0;i<N;++i)C[i]=sc.nextLong();
		Arrays.sort(C);
		long dp=1;
		long ans=0;
		for(int i=N-1;i>=0;--i){
			long res=N-1-i;
			ans+=2*(pow(2,res)+res*pow(2,res-1)%MOD)%MOD*pow(2,res)%MOD*C[i]%MOD*pow(4,i)%MOD;
			ans%=MOD;
		}
		System.out.println(ans);
    }
	
	void tr(Object...o){
		System.out.println(Arrays.deepToString(o));
	}
}
// OpenJDK reference:
//   http://openjdk.java.net/

// Java language references:
//   http://docs.oracle.com/javase


Measured memory_bytes: 135108
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<limits.h>
#define rep(i,n) for(ll i = 0; i < (ll)n; i++)
#define swap(a,b) a^=b;b^=a;a^=b;
#define chmax(a,b) {if(a < b) a = b;}
#define chmin(a,b) {if(a > b) a = b;}
using namespace std;
typedef long long ll;
ll gcd(ll, ll);
vector<bool> to_binary(int);
int sum(vector<int>);
int min(vector<int>);
int max(vector<int>);
ll nCr(ll n, ll r);

const ll INF = 1LL << 60;

typedef tuple<ll, ll> mtupl;

bool mycomp(mtupl x, mtupl y) {
	return get<1>(x) < get<1>(y);
}

vector<vector<ll>> memo;

ll get(int x, int y) {
	if (memo[x][y] != -1)
		return memo[x][y];

	if (x == 0) return 1;
	if (y < x) return 0;

	memo[x][y] = get(x, y - 1) + get(x - 1, y - 1);
	return memo[x][y];
}

ll mpow(ll a, ll b) {
	ll ans = 1;
	for (ll i = 0; i < b; i++) {
		ans *= a;
		ans %= 1000000007;
	}
	return ans;
}

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//Program Start	

	ll L, R;
	cin >> L >> R;

	ll min = LONG_MAX;
	for (ll c = 0; c < 2019 && c + L < R; c++) {
		for (ll d = c + 1; d < 2019 && d + L <= R; d++) {
			min = std::min(min,((c + L) * (d + L)) % 2019);
		}
	}

	cout << min << endl;

	/* ABC 125_c
	int N;
	cin >> N;

	vector<ll> A(N);
	rep(i, N) cin >> A[i];

	vector<ll> Forward(N), Backward(N);
	Forward[0] = A[0];
	int tmp = A[0];
	for (int i = 1; i < N; i++) {
		tmp = gcd(tmp, A[i]);
		Forward[i] = tmp;
	}

	tmp = A[N - 1];
	Backward[N - 1] = tmp;
	for (int i = N - 2; i >= 0; i--) {
		tmp = gcd(tmp, A[i]);
		Backward[i] = tmp;
	}
	*/


ProgramEndPointLabel:;

	//Program End
	system("pause");

	return 0;
}

ll nCr(ll n, ll r) {
	ll res = 1;
	for (int i = 0; i < r; i++) {
		res *= (n - i);
	}
	for (int i = 1; i <= r; i++) {
		res /= i;
	}
	return res;
}

int vsum(vector<int> v) {
	int res = 0;
	for (auto it = v.begin(); it != v.end(); it++)
		res += *it;
	return res;
}
int vmin(vector<int> v) {
	int min = INT32_MAX;
	for (auto it = v.begin(); it != v.end(); it++)
		min = std::min(min, *it);
	return min;
}
int vmax(vector<int> v) {
	int max = 0;
	for (auto it = v.begin(); it != v.end(); it++)
		max = std::max(max, *it);
	return max;
}

ll gcd(ll A, ll B) {
	int r = A % B;
	while (r != 0) {
		A = B;
		B = r;
		r = A % B;
	}

	return B;
}

vector<bool> to_binary(int x) {
	vector<bool> res;
	while (x != 0) {
		res.push_back(x % 2);
		x /= 2;
	}
	return res;
}

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

int main() {
    int n;
    int house[4][3][10];
    int b,f,r,v;
    for(int i=0;i<4;i++)
        for(int j=0;j<3;j++)
            for(int k=0;k<10;k++)
                house[i][j][k]=0;

    cin >> n;
    for(int i=0;i<n;i++)
    {
        cin >> b >> f >> r >> v;

        house[b-1][f-1][r-1] += v;
    }

    for(int i=0;i<4;i++)
    {
        for(int j=0;j<3;j++)
        {
            for(int k=0;k<10;k++)
                cout << " " << house[i][j][k];
            cout << endl;
        }
        if(i<3) {
            for(int j=0;j<20;j++)
                cout << "#";
            cout << endl;
        }
    }
}

Measured memory_bytes: 3060
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int n;
string s[100000];
int sl[100000];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    for(int i=0;i<n;i++) {
        cin>>s[i];
        sl[i]=s[i].length();
        s[i]=s[i].c_str();
    }
    ll countm=0;
    ll counta=0;
    ll countr=0;
    ll countc=0;
    ll counth=0;
    for(int i=0;i<n;i++){
        if(s[i][0]=='M') countm++;
        if(s[i][0]=='A') counta++;
        if(s[i][0]=='R') countr++;
        if(s[i][0]=='C') countc++;
        if(s[i][0]=='H') counth++;
    }
    ll ans=countm*counta*countr+countm*counta*countc+countm*counta*counth+countm*countr*countc+countm*countr*counth+countm*countc*counth
    +counta*countr*countc+counta*countr*counth+counta*countc*counth+countr*countc*counth;
    cout << ans << "\n";
}

Measured memory_bytes: 6144
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 100005;
const int mod = 1000000007;

int a[maxn];
ll b[maxn];
ll c[maxn];
ll MAX = mod * (ll)mod;

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int n;
  cin>>n;
  for(int i=0;i<=n;i++)cin>>a[i];
  if(a[0]>1){
    cout<<-1<<endl;
    return 0;
  }
  b[0] = 1 - a[0];
  for(int i=1;i<=n;i++){
    if(a[i]>b[i-1]*2){
      cout<<-1<<endl;
      return 0;
    }
    b[i] = b[i-1] * 2 - a[i];
    if(b[i]>MAX)b[i] = MAX;
  }
  c[n] = a[n];
  ll ret = c[n];
  for(int i=n-1;i>=0;i--){
    if(b[i]*2<c[i+1]){
      cout<<-1<<endl;
      return 0;
    }
    c[i] = min(c[i+1], b[i]) + a[i];
    ret += c[i];
  }
  cout<<ret<<endl;
  return 0;
}

Measured memory_bytes: 5576
from itertools import product
s = input()
op = list(product(["", "+"], repeat=len(s)))
op = [a for a in op if not a[-1] == "+"]
ans = 0
for q in op:
    e = ""
    for w in range(len(q)):
        e += s[w] + q[w]
    ans += eval(e)
print(ans)

Measured memory_bytes: 9148
a,b,c,d,e,f=map(int,open(0).read().split())
a,b,c=sorted((s*s+t*t)**.5for s,t in((a-c,b-d),(c-e,d-f),(e-a,f-b)))
d=a+b+c
s=d/2
s=(s*(s-a)*(s-b)*(s-c))**.5
print(c/(2+c/2/s*d))

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

using namespace std;

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

  vector<int> a(n, 0);
  int max = 0, max_sub = 0;
  int max_num = 0;

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

    if (a[i] == max){
      max_num++;
    }
    else if (a[i] > max){
      max_num = 1;
      max_sub = max;
      max = a[i];
    }
    else if (a[i] > max_sub)
      max_sub = a[i];
  }


  if (max_num == 1)
    for (int i = 0; i < n; i++){
      if (a[i] == max)
        cout << max_sub << endl;
      else
        cout << max << endl;
    }
  else
    for (int i = 0; i < n; i++){
      cout << max << endl;
    }
}

Measured memory_bytes: 2432
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		
		if(B % A == 0) {
			System.out.println(A+B);
		}else {
			System.out.println(B-A);
		}
		sc.close();
	}
}


Measured memory_bytes: 23124
#include<cstdio>
int main()
{
    double x,y,q,e;
    scanf("%lf%lf%lf%lf",&x,&y,&q,&e);
    printf("%lf ",x*y/2);
    if(q*2==x&&e*2==y||q*2==y&&e*2==x)
        printf("1");
    else
        printf("0");
    return 0;
}


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

int N, M, X;
vector<int> C;
vector<vector<int>> A;
const int INF = 1e+9;

void dfs(vector<int> & bit, int & res) {

	if (bit.size() == N) {
		int cost = 0;
		vector<int> skill(M);
		// 本を買ったらコストと理解度を加算する
		for (int i = 0; i < N; i++) {
			if (bit[i]) {
				cost += C[i];
				for (int j = 0; j < M; j++) {
					skill[j] += A[i][j];
				}
			}
		}
		bool ok = true;
		for (int i = 0; i < M; i++) {
			if (skill[i] < X) {
				ok = false;
				break;
			}
		}
		if (ok) res = min(res, cost);

		return;
	}

	for (int i = 0; i < 2; i++) {
		bit.push_back(i);
		dfs(bit, res);
		bit.pop_back();
	}
	return;
}

int main(void) {
	// 入力
	cin >> N >> M >> X;
	C.resize(N);
	A.resize(N, vector<int>(M));

	for (int i = 0; i < N; i++) {
		cin >> C[i];
		for (int j = 0; j < M; j++) {
			cin >> A[i][j];
		}
	}

	int res = INF;
	vector<int> bit;
	dfs(bit, res);

	if (res == INF) cout << -1 << endl;
	else cout << res << endl;

	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
using namespace std;

template<class T>
void in(vector<T>& V) {
	for (auto itr = V.begin(); itr != V.end(); itr++)cin >> *itr;
	return;
}

template<class T>
void out(vector<T>& V) {
	for (T& itr : V)cout << itr << endl;
	return;
}

vector<long long> L,P;
long long N, X;

//Lv.N、下からK枚
long long calc(long long N, long long K) {
	if (N == 1) {
		int t[]{ 0, 1, 2, 3, 3 };
		return t[K - 1];
	}
	long long ans = 0;
	K--;
	if (K == 0)return ans;
	if (K < L[N - 1])return calc(N - 1, K);
	K -= L[N - 1];
	ans += P[N - 1];
	if (K == 0)return ans;
	K--;
	ans++;
	if (K == 0)return ans;
	if (K < L[N - 1])return ans + calc(N - 1, K);
	return ans+P[N - 1];
}

int main() {
	cin >> N >> X;
	L.resize(51, 1);
	for (int l = 1; l <= 50; l++)L[l] = 2 * L[l - 1] + 3;
	P.resize(51,1);
	for (int l = 1; l <= 50; l++)P[l] = 2 * P[l - 1] + 1;
	cout << calc(N, X) << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {
	
	public static boolean search(final int cur_pos, final int n, int[] array, final int sum, final int m){
		
		for(int next_pos = cur_pos + 1; next_pos < n; next_pos++){
			final int next_value = sum + array[next_pos];
			
			if(next_value > m){
				break;
			}else if(next_value == m){
				return true;
			}else if(search(next_pos, n, array, next_value, m)){
				return true;
			}
		}
		
		return false;
	}
	
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		int[] array = new int[n];
		for(int i = 0; i < n; i++){
			array[i] = sc.nextInt();
		}
		Arrays.sort(array);
		
		final int q = sc.nextInt();
		for(int i = 0; i < q; i++){
			int m = sc.nextInt();
		
			System.out.println(search(-1, n, array, 0, m) ? "yes" : "no");
		}
	}
	
	public static class Scanner {
	    private BufferedReader br;
	    private StringTokenizer tok;

	    public Scanner(InputStream is) throws IOException {
	        br = new BufferedReader(new InputStreamReader(is));
	    }

	    private void getLine() throws IOException {
	        while (!hasNext()) { tok = new StringTokenizer(br.readLine()); }
	    }

	    private boolean hasNext() {
	        return tok != null && tok.hasMoreTokens();
	    }

	    public String next() throws IOException {
	        getLine(); return tok.nextToken();
	    }

	    public int nextInt() throws IOException {
	        return Integer.parseInt(next());
	    }
	    
	    public long nextLong() throws IOException {
	    	return Long.parseLong(next());
	    }
	    
	    public void close() throws IOException {
	        br.close();
	    }
	}

}

Measured memory_bytes: 18756
#include <bits/stdc++.h>
#include<vector>
using namespace std;
 
int main() {
 long int a,b,c,d;
  cin>>a>>b>>c;
  d=min(max(b,c)-1,a-(max(b,c))+1);
  if((b-c)%2==0)cout<<(max(b,c)-min(b,c))/2;
  else cout<<min(b-1,a-c)+(c-b+1)/2;
}

Measured memory_bytes: 256