akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void) {
    char S[5];
    scanf("%s", S);
    if ((S[0]=='A' && S[1]=='A' && S[2]=='A') || (S[0]=='B' && S[1]=='B' && S[2]=='B')) printf("No");
    else printf("Yes");
    return 0;
}

Measured memory_bytes: 128
n=int(input())
s=input()

ans = s.count('R')*s.count('G')*s.count('B')

for i in range(n-1):
    for j in range(i+1,n):
        k=j+j-i
        if k<n:
            if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
                ans-=1
print(ans)
        

Measured memory_bytes: 68008
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
	    	Scanner sc = new Scanner(System.in);
	    	int n = sc.nextInt();
	    	int k = sc.nextInt();
	    	int[] h = new int[n];
	    	int min = 0;
	    	int temp = 0;
	    	List<Integer> list = new ArrayList<>();
	    	for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			list.add(h[i]);
		}
	    	Collections.sort(list);
	    	min = list.get(k-1) - list.get(0);
	    	for (int i = 0; i <= n - k; i++) {
			temp = list.get(i+k-1) - list.get(i);
			if (temp < min) {
				min = temp;
			}
		}
	    	System.out.println(min);
	}
}


Measured memory_bytes: 62580
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> as(n);
    for (auto& a : as)
    {
        cin >> a;
    }
    int num = 1;
    for (auto a : as)
    {
        if (num == a)
        {
            num++;
        }
    }
    if (num == 1)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << (n - (num - 1)) << endl;
    }
}


Measured memory_bytes: 1024
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

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

int main(){
	int n;
	scanf("%d",&n);
	long a[3*n];
	int i;
	
	for(i=0;i<3*n;i++){
		scanf("%ld",a+i);
	}
	
	qsort(a,3*n,sizeof(long),cmp);
	
	long long int total=0;
	for(i=0;i<n;i++){
		total+=a[i*2+1];
	}
	
	printf("%lld\n",total);
	
    return 0;
}


Measured memory_bytes: 4860
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)


function main()
	n = readline() |> parseInt
	p = Array{Int}(n)
	for i in 1:n
		p[i] = readline() |> parseInt
	end
	q = zeros(Int,n)
	for i in 1:n
		q[p[i]] = i
	end
	t = 1
	temp = 1
	for i in 2:n
		if q[i]>q[i-1]
			temp += 1
			t = max(t,temp)
		else
			temp = 1
		end
	end
	println(n-t)
end
main()

Measured memory_bytes: 139916
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def fi(): return float(input())
def mfi(): return map(float, input().rstrip().split())
def lmfi(): return list(map(float, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
def exit(*arg): print(*arg); sys.exit()
# template


def main():
    X = ii()
    n = X // 100
    for i in range(n, 0, -1):
        if(X - 100 * i < 0):
            break
        if(5 * i < X - 100 * i):
            continue
        else:
            exit(1)
    print(0)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import java.util.*;

public class Main{

    int n,m;
    int[] h,w;

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            n = sc.nextInt();
            m = sc.nextInt();
            if(n==0 && m==0) break;

            h = new int[n];
            w = new int[m];
            int hsum = 0, wsum = 0;
            for(int i=0; i<n; i++){
                h[i] = sc.nextInt();
                hsum += h[i];
            }
            for(int i=0; i<m; i++){
                w[i] = sc.nextInt();
                wsum += w[i];
            }

            int[] hh = new int[hsum+1];
            int[] ww = new int[wsum+1];

            for(int i=0; i<n; i++){
                int sum = 0;
                for(int j=i; j<n; j++){
                    sum += h[j];
                    hh[sum]++;
                }
            }

            for(int i=0; i<m; i++){
                int sum = 0;
                for(int j=i; j<m; j++){
                    sum += w[j];
                    ww[sum]++;
                }
            }

            int ans = 0;
            for(int i=0; i<=Math.min(hsum,wsum); i++){
                ans += hh[i]*ww[i];
            }

            System.out.println(ans);
        }
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 18000
program abc161b
  implicit none
  integer :: n, m
  integer,allocatable :: a(:)
  read *, n, m
  allocate(a(n))
  read *, a
  if (count(a*4*m>=sum(a))>=m) then
     print *, 'Yes'
  else
     print *, 'No'
  end if
end program abc161b


Measured memory_bytes: 384
#include <stdio.h>
int main()
{
	double n;
	double x;
	double s;
	scanf("%lf",&n);
	int i; 
	for ( i = 1; i <= n; i++ )
	{
		if ( i % 2 == 1 )
			x++;
	}
	s = x / n;
	printf("%.10f",s);	
	
	return 0; 
}

Measured memory_bytes: 128
//
#include <vector>
#include <set>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
//
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
constexpr ll BIGP = 1000000007L;
constexpr ll INF_I = std::numeric_limits<ll>::max();
constexpr ld INF_F = std::numeric_limits<float>::infinity();
constexpr ld PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll l;
    cin >> l;
    //
    double L = double(l);
    double s = L / double(3.0);
    double s3 = s * s * s;
    printf("%.10f", s3);
    return 0;
}

Measured memory_bytes: 3204
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> cnt(n, 1), red(n);
  red[0] = 1;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    if (red[x]) {
      red[y] = 1;
      if (cnt[x] == 1) red[x] = 0;
    }
    cnt[x]--;
    cnt[y]++;
  }
  cout << accumulate(red.begin(), red.end(), 0) << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <math.h>
#include <map>
#include <stdio.h>
#include <ctype.h>
#include <algorithm>
#include <stdlib.h>
#include <stack>
#include <queue>
#include <bitset>
#include <memory.h>

using namespace std;



int check(int num_counter[], int now, int flag);


int main() {
    char c_num[13];
    int i_num[14];
    while(cin>>c_num[0]){
        for(int i=1; i<13; i++)cin>>c_num[i];
        
        int ans_flag=0;
        int first=0;
        for(int i=1; i<=9; i++){
            for(int j=0; j<13; j++)i_num[j]=c_num[j]-'0';
            i_num[13]=i;
            
            int num_counter[12]={0};
            for(int j=0; j<14; j++)num_counter[i_num[j]]++;
            
            int now=1;
            int flag=0;
            int ans = 0;
            int pass= 0;
        
            for(int j=1; j<=9; j++){
                if(num_counter[j]>=5)pass++;
            }
            

            if(pass==0)ans = check(num_counter, now, flag);
            if(ans==1&&first==0){
                cout<<i;
                first++;
                ans_flag++;
            }else if(ans==1){
                cout<<" "<<i;
                ans_flag++;
            }
            
    
        }
        if(ans_flag==0)cout<<0;
        cout<<endl;
        
        
        
    
    }
    return 0;
}

int check(int num_counter[], int now, int flag){
    if(now==10){
        return 1;
    }
    int num_counter_temp[12];
    if(num_counter[now]==5){
        return 0;
    }
    if(num_counter[now]>0&&num_counter[now+1]>0&&num_counter[now+2]>0){
        memcpy(num_counter_temp, num_counter, sizeof(int)*12);
        num_counter_temp[now]--;
        num_counter_temp[now+1]--;
        num_counter_temp[now+2]--;
        if(check(num_counter_temp, now, flag)==1)return 1;
    }
    if(num_counter[now]>=3){
        memcpy(num_counter_temp, num_counter, sizeof(int)*12);
        num_counter_temp[now]-=3;
        if(check(num_counter_temp, now, flag)==1)return 1;
    }
    if(num_counter[now]>=2&&flag==0){
        memcpy(num_counter_temp, num_counter, sizeof(int)*12);
        num_counter_temp[now]-=2;
        if(check(num_counter_temp, now, flag+1)==1)return 1;
    }
    if(num_counter[now]==0){
        memcpy(num_counter_temp, num_counter, sizeof(int)*12);
        if(check(num_counter_temp, now+1, flag)==1)return 1;
    }
    
    
    return 0;
    
    
}

Measured memory_bytes: 1140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define inf (int)1e9+7

int main() {
    int n; cin >> n;
    int four = 0, two = 0;
    int a[n]; rep(i, n) {cin >> a[i]; if (a[i] % 4 == 0) four++; else if (a[i] % 2 == 0) two++;}
    n -= 2 * four;
    if (n == 1 || two >= n) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <stdlib.h>
#include <list>
#include <map>
#include <utility>
#include <set>
#include <bitset>
#include <vector>
#define pi acos(-1.0)
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fLL
#define ms(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=5e5+5;
int min3(int a,int b,int c)
{
    return min(min(a,b),c);
}
int max3(int a,int b,int c)
{
    return max(max(a,b),c);
}
int gcd(int x, int y)
{
    if(y==0)return x;
    return gcd(y, x%y);
}
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int dir[4][2]={1,0,0,1,-1,0,0,-1};
char s[405][405];
int f[maxn];
int cnt[maxn];
int vis[maxn];
int Hash(int x,int y)
{
    return x*405+y;
}
int Find(int x)
{
    return x==f[x]?x:f[x]=Find(f[x]);
}
int join(int x,int y)
{
    x=Find(x);
    y=Find(y);
    if(x!=y)
    {
        f[x]=y;
        cnt[y]+=cnt[x];
        vis[y]+=vis[x];
    }
}
void init()
{
    for(int i=0;i<=maxn;i++)
    {
        f[i]=i;
        cnt[i]=1;
    }

}
int main()
{
    int h,w;
    init();
    scanf("%d%d",&h,&w);
    for(int i=1;i<=h;i++)scanf("%s",s[i]+1);
    for(int i=1;i<=h;i++)
        for(int j=1;j<=w;j++)
            if(s[i][j]=='#')vis[Hash(i,j)]=1;
    for(int i=1;i<=h;i++)
    {
      for(int j=1;j<=w;j++)
      {
          for(int k=0;k<4;k++)
          {
              int x=i+dir[k][0];
              int y=j+dir[k][1];
              if(x>0 && y>0 && x<=h && y<=w && s[i][j]!=s[x][y])
              {
                  join(Hash(i,j),Hash(x,y));
              }
          }
      }
    }
    ll ans=0;
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            int xx=Find(Hash(i,j));
            if(cnt[xx]>1)
            {
                ans+=1ll*vis[xx]*(cnt[xx]-vis[xx]);
                cnt[xx]=0;
            }
        }
    }
    printf("%lld\n",ans);


    return 0;
}


Measured memory_bytes: 4992
#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>;
const ll mod = 1e9 + 7;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  vector<int> pos, neg;
  rep(i, n) {
    cin >> a.at(i);
    if (a.at(i) < 0) neg.push_back(a.at(i));
    else pos.push_back(a.at(i));
  }

  bool ok = true;
  if (pos.size() == 0) {
    ok = (k % 2 == 0);
  } else {
    if (n == k) ok = (neg.size() % 2 == 0);
  }

  mint ans = 1;
  if (!ok) {
    // 正になる組み合わせがない場合は絶対値が小さい順に選ぶ
    sort(a.begin(), a.end(), [](int x, int y) {
      return abs(x) < abs(y);
    });
    rep(i, k) ans *= a.at(i);
  } else {
    // 正にできる場合は、正にできる範囲で2つの値の積が大きくなる順に選ぶ
    sort(pos.begin(), pos.end());
    sort(neg.rbegin(), neg.rend());

    if (k % 2 == 1) {
      ans = pos.back();
      pos.pop_back();
    }

    vector<ll> p;
    while (pos.size() > 1) {
      ll tmp = pos.back(); pos.pop_back();
      tmp *= pos.back(); pos.pop_back();
      p.push_back(tmp);
    }
    while (neg.size() > 1) {
      ll tmp = neg.back(); neg.pop_back();
      tmp *= neg.back(); neg.pop_back();
      p.push_back(tmp);
    }
    sort(p.rbegin(), p.rend());

    rep(i, k/2) ans *= p.at(i);
  }

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

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

#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define mp make_pair
#define all(x) (x).begin(), (x).end()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 2e5 + 123;
int k, n, a[N];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	cin >> k >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	int ans = a[n];
	ans = min(ans, a[n] - a[1]);
	for (int i = 2; i <= n; i++) {
		int res = min(a[i] + k - a[i - 1], k - a[i] + a[i - 1]);
		ans = min(ans, res);
	}
	cout << ans;
}


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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextLong();
        long k = sc.NextLong();

        long answer = Math.Max(0, n - k + 1);

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 27500
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}


int main(){
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  int n = s.size();

  const int DIV = 13, MOD = 1e9+7;
  // dp[i][j]: 1の位から i-1の位までを考慮した時の値を13で割ったあまりがj
  vector<vector<ll>> dp(n+1, vector<ll>(DIV, 0));
  dp[0][0] = 1;
  ll pow10_i = 1;
  for(int i=0; i<n; i++){
      for(int j=0; j<DIV; j++){
          for(int k=0; k<10; k++){
              if(s[i] == '?'){
                int c = (j + k*pow10_i) % DIV;
                dp[i+1][c] = (dp[i+1][c] + dp[i][j])%MOD;
                // cout << " i: " << i << " pow10_i: " << pow10_i << " j: " << j << " k: " << k << " c: " << c << " dp[i][j]: " << dp[i][j] << " dp[i+1][c]: " << dp[i+1][c]  << endl; 
              }
              else{
                k = (s[i]-'0');
                int c = (j + (s[i]-'0')*pow10_i) % DIV;
                dp[i+1][c] = (dp[i+1][c] + dp[i][j])%MOD;
                // cout << " i: " << i << " pow10_i: " << pow10_i <<" j: " << j << " k: " << k << " c: " << c << " dp[i][j]: " << dp[i][j] << " dp[i+1][c]: " << dp[i+1][c]  << endl;
                break;
              }
          }

      }
      pow10_i = ((pow10_i * 10) % DIV) % MOD;//こっちが正解（%MODも入れて良い,意味ないけど)
      //pow10_i = (pow10_i * 10) % MOD;//こっちだけだとダメ
  }

  // cout << " dp: " << endl; print_vec2(dp);
  cout << dp[n][5] << endl;

}


Measured memory_bytes: 16652
#include <iostream>
#include <cmath>
#include <vector>
#include <iomanip>

using namespace std;

int x[10];
int y[10];
double cost[10][10];

double sum = 0.0;

void travel_recursive(int i, vector<bool> visited, double accum_cost)
{
    bool finish = true;
    visited[i] = true;

    for (int j = 0; j < visited.size(); j++){
        if (visited[j]) {
            continue;
        } else {
            finish = false;
            travel_recursive(j, visited, accum_cost + cost[i][j]);
        }
    }

    if (finish) {
        sum += accum_cost;
    }
}

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

    // 各町から街への距離を事前計算
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (i == j) {
                cost[i][j] = 0.0;
            } else {
                int x_dist = (x[i] - x[j]);
                int y_dist = (y[i] - y[j]);
                double d = x_dist * x_dist + y_dist * y_dist;
                cost[i][j] = sqrt(d);
            }
        }
    }

    vector<bool> visited(N);
    for (int i = 0; i < N; i++) {
        double accum_cost;
        travel_recursive(i, visited, accum_cost);
    }

    int n_cases = 1;
    for (int i = 2; i <= N; i++) {
        n_cases *= i;
    }

    cout <<  std::setprecision(14) << sum / n_cases << endl;
    
}


Measured memory_bytes: 256
import sys #追加
sys.setrecursionlimit(500*500) #追加

N=int(input().strip())
a=[0]*(N-1) # # of lines
b=[0]*(N-1)
#to=[[] for j in range(N-1)] # points
ans=[0]*(N-1)

class data:
    def __init__(self):
        self.to=[[] for j in range(N)] # N points
        self.id=[[] for j in range(N)] # N points

def dfs(v,p,c_p): # vertices & parent idx & color from parent
    lst=data.to[v] # children list
    c=1
    for i,child in enumerate(lst):
        if child==p:
            continue
        if c_p==c:
            c+=1
        ans[data.id[v][i]]=c
        c+=1
        dfs(child,v,c-1)

data=data()
for i in range(len(a)):
    a,b=list(map(int,input().strip().split()))
    a-=1
    b-=1
    data.to[a].append(b)
    data.id[a].append(i) # index of the line
    data.to[b].append(a)
    data.id[b].append(i)

#print(data.to)

dfs(0,-1,-1)
print(max(ans))
for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 87784
import sys
sys.setrecursionlimit(10**7)

n, a, b, c = map(int, input().split())
l = [int(input()) for _ in range(n)]

mp = [float('inf')]
def f(i, anum, alen, bnum, blen, cnum, clen):
    if i == n:
        if alen * blen * clen == 0:
            return
        mp[0] = min(mp[0], abs(anum-a)+10*(alen-1) + abs(bnum-b)+10*(blen-1) + abs(cnum-c)+10*(clen-1))
    else:
        f(i+1, anum+l[i], alen+1, bnum, blen, cnum, clen)
        f(i+1, anum, alen, bnum+l[i], blen+1, cnum, clen)
        f(i+1, anum, alen, bnum, blen, cnum+l[i], clen+1)
        f(i+1, anum, alen, bnum, blen, cnum, clen)

f(0, 0, 0, 0, 0, 0, 0)


print(mp[0])

Measured memory_bytes: 42204
#include <stdio.h>
int main()
{
    int x,a,b;
    scanf("%d%d%d",&x,&a,&b);
    if((b-a)<=x)
    {
        if(b>a)
        {
            printf("safe");
        }
        else
        {
            printf("delicious");
        }
    }
    else
    {
        printf("dangerous");
    }
    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

char S[505050];
int N, Q;
int L[101010], R[101010];
int dp[505050][27];

/*
int uf[505050];

int root(int p)
{
	return uf[p] < 0 ? p : (uf[p] = root(uf[p]));
}
void join(int p, int q)
{
	p = root(p);
	q = root(q);
	if (p != q) {
		uf[p] += uf[q];
		uf[q] = p;
	}
}
*/
vector<int> ch[505050];
int lf[505050], rg[505050];
int idx;

void visit(int p)
{
	if (lf[p] != -1) return;
	lf[p] = idx++;
	for (int q : ch[p]) visit(q);
	rg[p] = idx;
//	printf("%d: %d %d\n", p, lf[p], rg[p]);
}
int dbl[505050][20];

int main()
{
	scanf("%s%d", S, &Q);
	N = strlen(S);
	for (int i = 0; i < Q; ++i) {
		scanf("%d%d", L + i, R + i);
		--L[i];
	}
	for (int i = N - 1; i >= 0; --i) {
		for (int j = 0; j <= 26; ++j) {
			dp[i][j] = N + 10;
		}
		dp[i][S[i] - 'a'] = i + 1;
		for (int j = (int)(S[i] - 'a') + 1; j <= 26; ++j) {
			if (dp[i][j - 1] < N) {
				int ij = dp[i][j - 1];
				dp[i][j] = min(dp[i][j], dp[ij][j - 1]);
			}
		}
		if (dp[i][26] < N) {
			int i26 = dp[i][26];
			for (int j = 0; j < (int)(S[i] - 'a'); ++j) {
				dp[i][j] = min(dp[i][j], dp[i26][j]);
			}
		}
	}
//	for (int i = 0; i < N; ++i) printf("%d: %d\n", i, dp[i][26]);
	for (int i = 0; i < N; ++i) if (dp[i][26] <= N) {
		ch[dp[i][26]].push_back(i);
	}

	for (int i = 0; i < N; ++i) dbl[i][0] = dp[i][26];
	for (int i = 1; i < 20; ++i) {
		for (int j = 0; j < N; ++j) {
			dbl[j][i] = (dbl[j][i - 1] < N ? dbl[dbl[j][i - 1]][i - 1] : (N + 10));
//			printf("%d %d: %d\n", i, j, dbl[j][i]);
		}
	}
	idx = 0;
	for (int i = 0; i <= N; ++i) lf[i] = -1;
	for (int i = N; i >= 0; --i) visit(i);

	for (int i = 0; i < Q; ++i) {
		int l = L[i], r = R[i];
		for (int j = 19; j >= 0; --j) {
			if (l < N && dbl[l][j] <= r) {
//				printf("%d -> %d\n", l, dbl[l][j]);
				l = dbl[l][j];
			}
		}
//		printf("%d, %d\n", l, r);
		bool isok = l == r;
		puts(isok ? "Yes" : "No");
	}
	return 0;
}


Measured memory_bytes: 133888
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (1E9+7)
#define PI 3.1415926535897932384626433832795

struct edge {
	vi c;
	int depth = 0,p=-1;
};

vector<edge> G(0);

void setdepth(int n, int d) {
	G[n].depth = d;
	rep(i, G[n].c.size()) {
		setdepth(G[n].c[i], d + 1);
	}
}

int main() {
	int n,m,id,num,in;
	cin >> n;
	G.resize(n);
	rep(i, n) {
		cin >> id >> num;
		rep(j, num) {
			cin >> in;
			G[id].c.push_back(in);
			G[in].p = id;
		}
	}
	rep(i, n) {
		if (G[i].p == -1) {
			id = i;
		}
	}
	setdepth(id, 0);
	rep(i, n) {
		//"node 0: parent = -1, depth = 0, "
		cout << "node " << i << ": parent = " << G[i].p;
		cout << ", depth = " << G[i].depth << ", ";
		if (G[i].p == -1) {
			cout << "root";
		}
		else if (G[i].c.size() == 0) {
			cout << "leaf";
		}
		else cout << "internal node";
		cout << ", [";
		rep(j, G[i].c.size()){
			cout << G[i].c[j] << (j < G[i].c.size()-1 ? ", " : "");
		}
		cout << "]" << endl;
	}
}


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


int main() {
int N;
cin>>N;
vector<long> a(N);
vector<long> b(N+1);
vector<long> c(N);
for(int i=0;i<N;i++) cin>>a[i];
for(int i=0;i<N;i++) b[a[i]]++;
//for(int i=1;i<=N;i++){
//  cout<<b[i]<<endl;
//}
long ans=0;
for(int i=1;i<=N;i++){
  ans += max(long(0),b[i]*(b[i]-1)/2);
  //cout<<ans<<endl;
}
//cout<<ans<<endl;

for(int i=0;i<N;i++){
  int x=a[i]; //1
  int y=b[x]; //3
  //cout<<x<<endl;
  //cout<<y<<endl;
  long tmp = ans-(y*(y-1)/2);
  tmp +=  (y-1)*(y-2)/2;
  cout<<tmp<<endl;
}

//cout<<ans<<endl;
}


Measured memory_bytes: 7296
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>

using namespace std;

typedef struct n{
    int Key;
    n *prev,*next;
} Node;

Node *nil;
const string COMMAND[4] = {
    "insert",
    "deleteFirst",
    "deleteLast",
    "delete"
};

void init(){
    nil = (Node *)malloc(sizeof(Node));
    nil -> next = nil;
    nil -> prev = nil;
}

void intsert(int Key){
    Node *x;
    x = (Node *)malloc(sizeof(Node));
    x -> Key = Key;
    x -> next = nil -> next;
    nil -> next -> prev = x;
    x -> prev = nil;
    nil -> next = x;
}

void deleteNode(Node *t){
    if(t == nil) return;
    t -> next -> prev = t -> prev;
    t -> prev -> next = t -> next;
    free(t);
}

void deletefirst(){
    deleteNode(nil -> next);
}

void deletelast(){
    deleteNode(nil -> prev);
}

Node* SearchNode(int Key){
    Node *ser;
    ser = nil -> next;
    while (ser != nil && ser -> Key != Key) {
        ser = ser -> next;
    }
    return ser;
}

void delete_X(int Key){
    deleteNode(SearchNode(Key));
}

void ReadCommand(){
    char comm[16];
    scanf("%s",comm);
    if ( comm == COMMAND[0] ){
        int Key;
        scanf("%d",&Key);
        intsert(Key);
    }else if (comm == COMMAND[1]){
        deletefirst();
    }else if (comm == COMMAND[2]){
        deletelast();
    }else{
        int Key;
        cin >> Key;
        deleteNode(SearchNode(Key));
    }
}

void printNode(){
    Node *k;
    k = nil -> next;
    while (k != nil) {
        if (k -> next != nil) {
            printf("%d ",k -> Key);
        }else{
            printf("%d\n",k -> Key);
        }
        k = k -> next;
    }
}

int main(){
    init();
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) ReadCommand();
    printNode();
    return 0;
}

Measured memory_bytes: 32452
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define bew ios_base::sync_with_stdio(false);cin.tie(NULL);

int dp[3001][3001];

int rec(int ar[],int i,int j)
{
    if(i>j)
    return 0;
    if(i==j)
    return ar[i];
    if(dp[i][j]!=-1)
    return dp[i][j];
    dp[i][j]=max(ar[i]+min(rec(ar,i+2,j),rec(ar,i+1,j-1)),ar[j]+min(rec(ar,i+1,j-1),rec(ar,i,j-2)));
    return dp[i][j];
}
signed main()
{
    bew;
    int n;
    cin>>n;
    memset(dp,-1,sizeof dp);
    int ar[n],sum=0;
    for(int i=0;i<n;++i)
    cin>>ar[i],sum+=ar[i];
    int sc=rec(ar,0,n-1);
    cout<<2*sc-sum;
    
    
    return 0;
}

Measured memory_bytes: 70784
#include <iostream>

using namespace std;

int main()
{
   int n;
   cin>>n;
   int u=n%10;
   if(u==0|| u==1||u==6||u==8)
   {
       cout<<"pon";
       return 0;
   }
   else
   {
    if(u==2||u==4||u==5||u==7||u==9)
    {
        cout<<"hon";
    }
    else
    {
        cout<<"bon";
    }
   }

}


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

int main(){
    int a,b;
    cin >> a >> b;
    if(a == b){
        cout <<  "a == b" << endl;
    }else if (a > b)
    {
        cout << "a > b" << endl;
    }else{
        cout << "a < b" << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3052
AV = input()
BW = input()
T = int(input())
A = int(AV.split(" ")[0])
V = int(AV.split(" ")[1])
B = int(BW.split(" ")[0])
W = int(BW.split(" ")[1])
if (A <= B) and (A+V*T >= B+W*T):
    print("YES", end="")
elif (A > B) and (A-V*T <= B-W*T):
    print("YES", end="")
else:
    print("NO", end="")

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

using namespace std;

int n;
vector <char> s;
int main(){
  char inp;
  int left=0;
  int count=0;

  cin >> n;
  for(int i =0;i<n;i++){
    cin >> inp;
    s.push_back(inp);
  }

  for(int i =0;i<n+count;i++){
    if(s[i]=='(') left++;
    else{
      if(left!=0){left--;}
      else{
	s.insert(s.begin(),'(');
	count++;
	i++;
      }
    }
  }
  
  for(int i=0;i<left;i++){
    s.insert(s.end(),')');
    count++;
  }
  
  for(int i=0;i<n+count;i++){cout << s[i];}
  cout << endl;
  return 0;
}


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

int main(){
  char a,b;
  cin >> a >>b;
  int x,y;
  if(a=='H' && b=='H') cout << 'H';
  if(a=='H' && b=='D') cout << 'D';
  if(a=='D' && b=='H') cout << 'D';
  if(a=='D' && b=='D') cout << 'H';
  return 0;
}


Measured memory_bytes: 256
// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//


#define _USE_MATH_DEFINES
#include<math.h>

//#include<cmath>

#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>



//#include "Ants.h"
using namespace std;
typedef long long ll;
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<n;i++)
#define show(s) cout<<s<<endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define LINF (1000000000000000000ll)

//typedef pair < int, int> P;
ll gcd(ll a, ll b) {//最大公約数を求める///最大公倍数a*b/gcd(a,b)
	if (b == 0) return a;
	return gcd(b, a % b);
}

ll lcd(ll a, ll b) {//最小公倍数を求める　b=0のときaを返す
	if (b == 0) return a;
	return (a / gcd(a, b)) * b;
}
vector<int> divnum(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p;
}
int keta(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p.size();
}

int N, P;
string S;
ll surp[1000000];
ll dp[1000000];
int main()
{
	cin >> N >> P;
	cin >> S;

	reverse(S.begin(), S.end());
	ll ans = 0;
	if (10 % P == 0) {
		rep(i, N) {
			if ((S[i] - '0') % P == 0) {
				ans += N - i;
			}
		}
		cout << ans << endl;
		return 0;
	}
	ll X = 1;
	rep(i, N) {
		surp[i + 1] = (X * (S[i] - '0') + surp[i]) % P;
		//cout << S[i] << " " << X*S[i] << " " << surp[i + 1] << endl;
		X *= 10; X %= P;

	}
	dp[0] = 1;
	rep(i, N) {
		ans += dp[surp[i + 1]];
		dp[surp[i + 1]]++;
		//cout << S[i] << " " << surp[i + 1] << " " << dp[surp[i + 1]] << endl;
	}
	cout << ans << endl;

}

Measured memory_bytes: 4740
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int INF = pow(10, 7);
int main(){
  int h, w;cin>>h>>w;
  int cost[11][11];
  for(int i=0;i<=9;i++){
  	for(int j=0;j<=9;j++)cin>>cost[i][j];
  }
  for(int k=0;k<=9;k++){
    for(int i=0;i<=9;i++){
      for(int j=0;j<=9;j++){
        cost[i][j]=min(cost[i][j], cost[i][k]+cost[k][j]);
      }
    }
  }
  int ans=0;
  for(int i=0;i<h;i++){
  	for(int j=0;j<w;j++){
      int a;cin>>a;
      if(a==-1)continue;
      ans += cost[a][1];
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
///source: https://atcoder.jp/contests/abc149/submissions/9237911
long long n, m;
vector<long long> a, sum;

long long solve();
long long check(long long x);

int main() {
  cin >> n >> m;
  a.resize(n);
  for(int i = 0; i < n; ++i) cin >> a[i];
  sort(a.begin(), a.end(), greater<long long>());
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long res = 0, l = 0, r = 2*a[0]+1;
  ///while(r  > l) { DILE TLE ASHE

  while(r  > l+1) {
    long long now = (l + r) / 2;
    if(check(now) >= m)
      l = now;
    else
      r = now;
  }
  sum = a;
  for(int i = 1; i < n; ++i) sum[i] += sum[i - 1];
  for(int i = 0; i < n; ++i) {
    if(a[0] + a[i] < l) continue;
    long long now = upper_bound(a.begin(), a.end(), l - a[i], greater<long long>()) - a.begin();

    res += now * a[i] + sum[now - 1];
  }
  res -= l * (check(l) - m);
  return res;
}

long long check(long long x) {
  long long cnt = 0;
  for(int i = 0; i < n; ++i) {
    if(a[0] + a[i] < x) continue;
    cnt += upper_bound(a.begin(), a.end(), x - a[i],greater<long long>()) - a.begin();
  }
  return cnt;
}


Measured memory_bytes: 1792
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef map<int, int> mii;
typedef map<char,int> mci;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vii;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define F first
#define S second
#define in insert
const int INF = 1e9 + 7;
int main(){
    string s; cin>>s;
    for(int i = 0; i < s.size(); i++){
        if(i%2==0 && s[i]=='L' || i%2==1 && s[i]=='R') {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
}

Measured memory_bytes: 256
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<fstream>
#include<map>
#include<iostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
#define rep(i,n) for (int i=1;i<=n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define flush fflush(stdout)
char a[200005];
ll sz;
ll ans=0;
ll cnt[200];
int main()
{
    ios::sync_with_stdio(false);
    cin>>a;
    sz=strlen(a);
    ans=sz*(sz-1)/2+1;
    for (int i=0;i<sz;i++) cnt[a[i]]++;
    for (int i='a';i<='z';i++){
    	ans-=cnt[i]*(cnt[i]-1)/2;
    }
    cout<<ans;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
    int n;
    string s;
    cin>>n>>s;
    int R[4001]={},G[4001]={},B[4001]={};
    for(int i=0;i<n;i++){
        if(s[i]=='R') R[i]++;
        if(s[i]=='G') G[i]++;
        if(s[i]=='B') B[i]++;
        R[i+1]=R[i];
        G[i+1]=G[i];
        B[i+1]=B[i];
    }
    ll ans=0;
    for(int i=0;i<n-2;i++){
        for(int j=i+1;j<n-1;j++){
            if(s[i]==s[j]) continue;
            if((s[i]=='R'&&s[j]=='G')||(s[i]=='G'&&s[j]=='R')){
                ans+=B[n-1]-B[j];
                if(2*j-i<4000){
                    if(s[2*j-i]=='B') ans--;
                }
            }
            if((s[i]=='R'&&s[j]=='B')||(s[i]=='B'&&s[j]=='R')){
                ans+=G[n-1]-G[j];
                if(2*j-i<4000){
                    if(s[2*j-i]=='G') ans--;
                }
            }
            if((s[i]=='B'&&s[j]=='G')||(s[i]=='G'&&s[j]=='B')){
                ans+=R[n-1]-R[j];
                if(2*j-i<4000){
                    if(s[2*j-i]=='R') ans--;
                }
            }
        }
    }
    cout<<ans;
}

Measured memory_bytes: 3692
//
//  main.cpp
//  B - ROT N
//
//  Created by Hashizo on 2019/11/24.
//  Copyright © 2019 Hashizo. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <regex>
#include <cmath>

using namespace std;
 
#undef LONG_MAX
#undef LONG_MIN
 
#define LONG_MAX    9223372036854775807
#define LONG_MIN    (-LONG_MAX  -1)
 
#define ll long long
 
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
 
#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())

int main(int argc, const char * argv[]) {
	ll n;
	cin >> n;

	string s;
	cin >> s;

	
	char *before;
	before = (char *)s.c_str();
	
	char after[s.size()+1];
	REP(i,sizeof(after)) {
		after[i] = 0;
	}
	
	REP(i,s.size()) {
		after[i] = (*(before+i))+n;
		if ((char(after[i])) > 'Z') {
			after[i] -= 26;
		}
	}

	cout << after << endl;
	return 0;
}


Measured memory_bytes: 256
lines = readlines.map{|line| line.split(' ')}
a=lines[0][0].to_i
b=0
c=0
for i in 0..a
  if b==1 then
    c=c+lines[i][1].to_i
  end
  if lines[a+1][0]==lines[i][0] then
   b=1
  end
end
puts c

Measured memory_bytes: 1916
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#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;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
int main(){
  int a,b;
  cin >> a >> b;
  if(a*b == 15) cout << "*" << endl;
  else if(a + b == 15) cout << "+" << endl;
  else cout << "x" << endl;


  return 0;
}


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

int main(int argc, char** argv) {
    string dia;
    cin >> dia;
    int tam;
    int qtdDias[23];
    qtdDias[22]=7;
    qtdDias[10]=6;
    qtdDias[14]=5;
    qtdDias[0]=4;
    qtdDias[17]=3;
    qtdDias[1]=2;
    qtdDias[8]=1;
    tam=dia[0]+dia[1]+dia[2];
    cout << qtdDias[tam-224];
    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;
 
int main()
{
    int nn, c, a, n;
 
    cin >> nn;
    while (nn--) {
	int cnt = 0;
	cin >> c >> a >> n;
	while (true) {
	    if (c >= 1 && a >= 1 && n >= 1) {
		c--; a--; n--;
		cnt++;
	    } else if (c >= 2 && a >= 1) {
		c -= 2;
		a--;
		cnt++;
	    } else if (c >= 3) {
		c -= 3;
		cnt++;
	    } else {
		break;
	    }
	}
	cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 3096
import sys
import math
import heapq
n, m = [int(i) for i in sys.stdin.readline().split()]
a_ls = [-int(i) for i in sys.stdin.readline().split()]
heapq.heapify(a_ls)
for i in range(m):
    _max = - heapq.heappop(a_ls)
    heapq.heappush(a_ls, - _max / 2)
a_ls = [math.floor(-i) for i in a_ls]
print(sum(a_ls))

Measured memory_bytes: 14380
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let (n,t) = get!(usize, usize);
    let mut ab = get!(usize, usize; n);
    ab.sort_by_key(|&(a,_)| a);

    let mut dp = vec![vec![0; t]; n+1];
    for i in 0..n {
        for j in 0..t {
            dp[i+1][j] = if j >= ab[i].0 {
                max!(dp[i][j], dp[i][j-ab[i].0] + ab[i].1)
            } else {
                dp[i][j]
            };
        }
    }

    let mut mx = 0;
    for i in 0..n {
        mx = max!(mx, dp[i][t-1]+ab[i].1);
    }
    println!("{}", mx);
}


Measured memory_bytes: 94588
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <functional>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						(1000 * 1000 * 1000 * 2)
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define	BitSetV(Val,Bit)		((Val) |= (Bit))			
#define	BitTstV(Val,Bit)		((Val) & (Bit))				
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
// 枝定義
struct Edge
{
	int	to;
	ll	dist;
	Edge(){}
	Edge(int to, ll dist): to(to), dist(dist){}
};

// グラフ定義(二次元配列)
template <class E>
using Graph = vector<vector<E>>;
 
// ダイクストラ
template<class D, D infVal>
class Dijkstra 
{
public:
	// res[i] = sからiまでの最短距離
	vector<D> res;

	// 復元パス
//	vector<int> pathList;

private:
	vector<int> pathRev;
    
public:
	template<class E>
	Dijkstra(const Graph<E> &G, int startFrom)
	{
		int V = (int)G.size();
		res = vector<D>(V, infVal);
		pathRev.resize(V, -1);

		using P = pair<D, int>;
		priority_queue<P, vector<P>, greater<P>> que;
		que.push(P(0, startFrom));
		res[startFrom] = 0;

		while (!que.empty()) {
			P p = que.top(); que.pop();
			int egdeFrom = p.second;

			// 違う最短距離がキューにあるのでスキップ
			if (res[egdeFrom] < p.first) {
				continue;
			}

			// 最短距離を更新
			for (E edge : G[egdeFrom]) {
				D nextDist = p.first + edge.dist;
				if (nextDist < res[edge.to]) {
					res[edge.to] = nextDist;
					pathRev[edge.to] = egdeFrom;
					que.push(P(nextDist, edge.to));
				}
			}
		}
	}

	// 経路を取得する
	vector<int> getPath(int dstPos)
	{
		vector<int> pathList;
		
		while (dstPos != -1) {
			pathList.push_back(dstPos);
			dstPos = pathRev[dstPos];
		}
		reverse(pathList.begin(), pathList.end());
		return pathList;
	}
};

int main()
{
	int N, M;
	cin >> N >> M;
	Graph<Edge>	G(N);
	REP(i, M) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		G[a].emplace_back(Edge(b, 1));
		G[b].emplace_back(Edge(a, 1));
	}

	Dijkstra<ll, INF> dijk(G, 0);
	if (2 == dijk.res[N - 1]) {
		cout << "POSSIBLE" << endl;
	} else {
		cout << "IMPOSSIBLE" << endl;
	}

	return 0;
}



Measured memory_bytes: 19680
import java.util.Scanner;
class Stac{
	int num;
	public Stac(String str) {
		num=Integer.parseInt(str);
	}
	public void Show() {
		System.out.println(num);
	}
}

public class Main{
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int i=0;
        String str="";
        Stac[] stac=new Stac[100];
        while(scan.hasNext()) {
        	str=scan.next();
        	if(str.equals("+")) {
        		stac[i-2].num=stac[i-2].num+stac[i-1].num;
        		i-=2;
        	}
        	else if(str.equals("-")) {
        		stac[i-2].num=stac[i-2].num-stac[i-1].num;
        		i-=2;
        	}
        	else if(str.equals("*")) {
        		stac[i-2].num=stac[i-2].num*stac[i-1].num;
        		i-=2;
        	}
        	else {
        		stac[i]=new Stac(str);
        	}
        	i++;
        }
        stac[0].Show();
	}
}


Measured memory_bytes: 26172
#include<stdio.h>
main(){
  int i,n,m;
  for(i=1;;i++){
    scanf("%d %d",&n,&m);
    if(n==0 && m==0)break;
    if(n>m)printf("%d %d\n",m,n);
    else printf("%d %d\n",n,m);
  }
  return 0;
}


Measured memory_bytes: 2044
package main

import (
  "fmt"
)

func main() {
  var n int
  fmt.Scan(&n)
  
  count_ac := 0
  count_wa := 0
  count_tle := 0 
  count_re := 0
  
  a := make([]string, n)
  
  for i := 0; i < len(a); i++ {
    fmt.Scan(&a[i])
  }
  
  for j := 0; j < len(a); j++ {
    if a[j] == "AC" {
      count_ac += 1
    } else if a[j] == "WA" {
      count_wa += 1
    } else if a[j] == "TLE" {
      count_tle += 1
    } else if a[j] == "RE" {
      count_re += 1
    }
  }
  
   	fmt.Println("AC x",count_ac)
   	fmt.Println("WA x", count_wa)
	fmt.Println("TLE x", count_tle)
	fmt.Println("RE x", count_re)
}

Measured memory_bytes: 6828