akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
#define Fast ios_base::sync_with_stdio(0), cin.tie(0)
#define ll long long

char a[55][55];
bool vis[55][55];
int step[4][2] = {{-1,0},{1,0},{0,1},{0,-1}};
int n,m;
int click(int x,int y,int &tmp){
	vis[x][y] = 1;
	for(int i=0;i<4;i++){
		int tem_x = x + step[i][0];
		int tem_y = y + step[i][1];
		if(tem_x<n&&tem_x>=0&&tem_y<m&&tem_y>=0&&vis[tem_x][tem_y]==0){
			if(a[tem_x][tem_y]=='#'){
				tmp++;
				click(tem_x,tem_y,tmp);
			}
		}
	}
}
int main(){
	
	cin>>n>>m;
	for(int i=0;i<n;i++)cin>>a[i];
	int c = 1;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(a[i][j]=='.'||vis[i][j]==1)continue;
			int flag = 0;
			click(i,j,flag);
			if(flag==0){
				cout<<"No\n";
				c = 0;
				break;
			}
		}
		if(c==0)break;
	}
	if(c!=0)cout<<"Yes\n";
	return 0;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll K;
    cin >> K;

    ll ans = 0;
    for(ll i=1; i<=K; i++){
        for(ll j=1; j<=K; j++){
            for(ll k=1; k<=K; k++){
                ans += gcd(gcd(i, j), k);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
N = int(input())
V = list(map(int, input().split()))

for i in range(N-1):
    min1 = min(V) 
    V.remove(min1)
    min2 = min(V)
    V.remove(min2)
    V.append( (min1+min2) / 2 )

print(V[0])

Measured memory_bytes: 3060
#include <stdio.h>

void print_chessboard(int height, int width);

int main(void){

    int h, w;

    while(1){
        //input
        scanf("%d %d", &h,&w);

        if(h==0 && w==0){
            return 0;
        }
        else{
            print_chessboard(h,w);
            printf("\n");
        }
    }

}

void print_chessboard(int height, int width){

    int i,j;

    for(i=0; i<height; i++){
        //?\???°???
        if( i%2!=0){
            for(j=0; j<width; j++){
                //?\???°???
                if(j%2!=0)  printf("#");
                //??¶??°???
                else        printf(".");
            }
        }
        //??¶??°???
        else{
            for(j=0; j<width; j++){
                //?\???°???
                if(j%2!=0)  printf(".");
                //??¶??°???
                else        printf("#");
            }
        }
        printf("\n");
    }
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

map<char, char> win;

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

  ll cnt = 0;
  vector<int> ws(n), es(n);
  for (int i = 0; i < n; i++) {
    ws[i] = cnt;
    if (s[i] == 'W') cnt++;
  }
  cnt = 0;
  for (int i = n; i >= 0; i--) {
    es[i] = cnt;
    if (s[i] == 'E') cnt++;
  }

  int ans = n;
  for (int i = 0; i < n; i++) {
    ans = min(ans, es[i] + ws[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 6116
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int main(){
  int N;
  cin >> N;
  
  vector<vector<int>> dist(N,vector<int>(N));
  for(int i = 0; i < N; ++i)
    for(int j = 0; j < N; ++j)
      dist[i][j] = min({i,N-1-i,j,N-1-j});

  int ans = 0;
  vector<vector<bool>> exist(N,vector<bool>(N,true));
  for(int i = 0; i < N*N; ++i){
    int p;
    cin >> p;
    --p;
    int h = p/N, w = p%N;
    ans += dist[h][w];
    // cerr << h << " " << w << " " << dist[h][w] << endl;
    exist[h][w] = false;
    queue<pair<int,int>> Q;
    Q.emplace(h,w);
    int dx[] = {1,0,-1,0}, dy[] = {0,1,0,-1};
    while(Q.size()){
      auto [x, y] = Q.front();
      Q.pop();
      int d = dist[x][y] + exist[x][y];
      for(int i = 0; i < 4; ++i){
        int x_ = x + dx[i], y_ = y + dy[i];
        if(x_ >= 0 and x_ < N and y_ >= 0 and y_ < N and dist[x_][y_] > d){
          dist[x_][y_] = d;
          Q.emplace(x_,y_);
        }
      }
    }
  }
  cout << ans << endl;
}


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

signed main()
{
	int n,d;
	cin>>n>>d;
	
	int x,y,cnt=0;
	for(int i=1;i<=n;i++)
	{
		cin>>x>>y;
		int a=x*x+y*y;
		if(a<=d*d)
			cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n), f(n);
    rep(i, n)cin >> a[i];
    rep(i, n)cin >> f[i];
    sort(all(a)); sort(rall(f));
    ll ng = 0, ok = inf;
    while(ok-ng > 1){
        ll mid = (ok + ng) / 2;
        ll cnt = 0;
        rep(i, n){
            if(mid <= a[i]*f[i]){
                ll now = a[i]*f[i]-mid;
                cnt += (now+f[i]-1)/f[i];
            }
        }
        if(cnt <= k)ok = mid;
        else ng = mid;
    }
    if(accumulate(all(a), 0LL) <= k)cout << 0 << endl;
    else cout << ok << endl;
}


Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
using namespace std;

void solve(){
  long long int a, b, c; cin >> a >> b >> c;
  if(c - a - b > 0 && 4 * a * b < (c - a - b) * (c - a - b)) cout << "Yes\n";
  else cout << "No\n";
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
long long mod = 1000000007;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define rep(i, a, n) for (long long i = a; i < (n); i++)
long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return (t * t) % mod;
    } else {
        return (modpow(m, n - 1) * m) % mod;
    }
}
 
template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
// long long mod = 998244353;
long long power(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}
 
long long moddiv(long long a, long long b) { return (a * modpow(b, mod - 2)) % mod; }
 
const ll INF = 1LL << 60;
 
void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}
 
ll nCkmod(ll n, ll k) {
    ll denomi = 1;
    for (int i = n; i > n - k; i--) {
        denomi *= i;
        denomi %= mod;
    }
    ll numera = 1;
    REP(i, k) {
        numera *= (i + 1);
        numera %= mod;
    }
    return moddiv(denomi, numera);
}
map<ll, ll> cnt;
void primeFactors(long long n) {
    while (n % 2 == 0) {
        cnt[2]++;
        n = n / 2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2) {
        while (n % i == 0) {
            cnt[i]++;
            n = n / i;
        }
    }
    if (n > 2) {
        cnt[n]++;
    }
}
int main() {
    ll n, k;
    cin >> n >> k;
    rep(i, 1, k + 1) {
        ll ans = 0;
        ans += 2 * (nCkmod(k - 1, i - 1)) * (nCkmod(n - k - 1, i - 1));
        ans += (nCkmod(k - 1, i - 1)) * (nCkmod(n - k - 1, i - 2));
        ans += (nCkmod(k - 1, i - 1)) * (nCkmod(n - k - 1, i));
        if(i == 1){
            ans--;
        }
      ans %= mod;
        cout << ans << endl;
    }
}

Measured memory_bytes: 3648
#include<iostream>
using namespace std;
string s;
int main(){
    cin>>s;
    bool ok=1;
    int a=s.size();
    for(int i=0;i<a;i++){
        int cnt=0;
        for(int j=0;j<a;j++){
            if(s[i]==s[j])cnt++;
        }
        if(cnt%2==1){
            ok=0;
            break;
        }
    }
    cout<<(ok?"Yes":"No")<<endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <numeric>
#define rep(i,n) for (int i = 0;i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
int INF = 1e9;

const int mod = 1000000007;
class mint {
	long long x;
public:
	mint(long long 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 {
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res*=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 {
		mint res(*this);
		return res/=a;
	}
	friend ostream& operator<<(ostream& os, const mint& m){
		os << m.x;
		return os;
	}
};

struct combination {
	vector<mint> fact, ifact;
	combination(int n):fact(n+1),ifact(n+1) {
		assert(n < mod);
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n]*ifact[k]*ifact[n-k];
	}
};

int main(){
	int h,w,a,b;cin >> h >> w >> a >> b;
	combination c(200005);
	mint ans = 0;
	for(int i = 1;i <= a;i++){
		mint now = c(h-a+i-2+b,b-1);
		now*=c(w+a-b-i-1,w-b-1);
		//cout << c(h-a+i-2+b,b-1) << " " << now << endl;
		ans += now;
	}
	cout << c(h+w-2,h-1)-ans << endl;

} 
 

Measured memory_bytes: 6412
#include<bits/stdc++.h>
using namespace std;
int main()
{
	 int n;
	 cin>>n;
	 int h;
	 for(int i=1;;i++)
	 {  
	    h=i*111;
	   if(h>=n)break;
	 }
	 cout<<h<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
int cube(int v, int h);


int main(int argc, char *argv[]){
  int v, h,sq,rim;
  scanf("%d",&v);
  scanf("%d",&h);
  sq = cube(v,h);
  auto lmd = [v, h](int v, int h) -> int{return (2*v + 2*h);};
  rim = lmd(v, h);
  std::cout << sq;
  std::cout << " ";
  std::cout << rim << std::endl;
  return 0;
}
int cube(int v, int h){
  int i = v * h;
  return i;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
using P = pair<int, int>; 
using ll = long long;

int main()
{
  int n;
  cin >> n;
  int k;
  cin >> k;
  int a[n];
  ll sum = 0;
  rep(i, n){
    cin >> a[i];
    sum += a[i];
  }
  int ans = 0;
  sort(a, a + n, greater<>());
  rep(i, k) {
    sum -= a[i];
    if(i + 1 == n) break;
  }
  if(sum < 0) sum = 0;
  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 4380
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const ll MOD=1000000007;
struct mint { int n; mint(int n_ = 0) : n(n_) {} };
mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
mint operator+(mint a, mint b) { int x = a.n + b.n; return x - (x >= MOD) * MOD; }
mint operator-(mint a, mint b) { int x = a.n - b.n; return x + (x < 0) * MOD; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
istream &operator>>(istream &i, mint &a) { return i >> a.n; }
ostream &operator<<(ostream &o, mint a) { return o << a.n; }
 
vector<mint> F_{1, 1}, R_{1, 1}, I_{0, 1};
 
void check_fact(int n) {
  for (int i = I_.size(); i <= n; i++) {
    I_.push_back(I_[MOD % i] * (MOD - MOD / i));
    F_.push_back(F_[i - 1] * i);
    R_.push_back(R_[i - 1] * I_[i]);
  }
}
 
mint I(int n) { check_fact(abs(n)); return n >= 0 ? I_[n] : -I_[n]; }
mint F(int n) { check_fact(n); return n < 0 ? 0 : F_[n]; }
mint R(int n) { check_fact(n); return n < 0 ? 0 : R_[n]; }
mint C(int n, int r) { return F(n) * R(n - r) * R(r); }
mint P(int n, int r) { return F(n) * R(n - r); }
mint H(int n, int r) { return n == 0 ? (r == 0) : C(n + r - 1, r); }

mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; ++i) {
    for (int j = 0; j <= i; ++j) {
      c[i + 1][j] += c[i][j];
      c[i + 1][j + 1] += c[i][j];
    }
  }
}
mint comb(int n, int k) { return c[n][k]; }
// 0個のグループ相当に変換
mint f2(int n, int k) { return comb(n + k - 1, k - 1); }
// n個をkグループに分ける方法
mint f(int n, int k) {
  if (n < k) return 0;
  if (n == 0 && k == 0) return 1;
  return f2(n -k, k);
}

int main() {
  init();
  int n, k;
  cin >> n >> k;

  for (int i = 1; i <= k; ++i) {
    mint blue = f(k, i);
    mint red = 0;
    // f2(n - k - (i - 1), i + 1);
    {
      red += f(n - k, i - 1);
      red += f(n - k, i);
      red += f(n - k, i);
      red += f(n - k, i + 1);
    }
    mint ans = blue * red;
    printf("%lld\n", ans.n);
  }

  return 0;
}


Measured memory_bytes: 62848
import java.util.Scanner;

public class Main {

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

		int a = scan.nextInt();
		int b = scan.nextInt();
		
		System.out.println(a * b + " " + (a + b) * 2);
		
		scan.close();

	}

}

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

int main()
{
    int N, D;
    cin >> N >> D;

    vector<vector<int> > X(N, vector<int>(D));
    for (int i=0; i<N; i++) {
        for (int d=0; d<D; d++) {
            int x;
            cin >> X.at(i).at(d);
        }
    }

    int ct=0;
    for (int i=0; i<N-1; i++) {
        for (int j=i+1; j<N; j++) {
            int s = 0;
            for (int d=0; d<D; d++) {
                s += pow((X.at(i).at(d) - X.at(j).at(d)), 2);
            }
            for (int p=0; p<127; p++) {
                if (s == pow(p, 2)) {
                    ct++;
                    break;
                }
            }
        }
    }

    cout << ct << endl;
    
    return 0;
}

Measured memory_bytes: 504
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  string a,b,c,ans;
  cin >> a >> b >> c;
  a = a[0];
  b = b[0];
  c = c[0];
  ans = a+b+c;
  transform(ans.begin(),ans.end(),ans.begin(),::toupper);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define INF 1e9

int main() {
  long long N;
  cin >> N;
  
  vector <long long> W(N);
  rep(i, N) cin >> W[i];
  
  long long sum_all = 0;
  rep(i, N) {
    sum_all += W[i];
  }
  
  long long S1 = 0, S2 = 0;
  long long answer = INF;
  rep(i, N) {
    S1 += W[i];
    S2 = sum_all - S1;
    answer = min(answer, abs(S1 - S2));
  }
  cout << answer << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

void shuffle(int *p,int k,int arraynum){
	int first[200];
	int second[200];
	int i;
	for(i=0;i<k;i++){
		first[i] = p[i];
	}
	for(;i<arraynum*2;i++){
		second[i-k] = p[i];
	}
	for(i=0;i<2*arraynum;i++){
		if(i<(arraynum*2-k)){
			p[i] = second[i];
		}
		else{
			p[i] = first[i+k-arraynum*2];
		}
	}
}

void refshf(int *p,int arraynum){
	int first[200];
	int second[200];
	int i;
	
	for(i=0;i<arraynum;i++){
		first[i] = p[i];
		second[i] = p[i+arraynum];
	}
	
	
	for(i=0;i<2*arraynum;i++){
		switch(i%2){
			case (0):p[i] = first[i/2];break;
			case (1):p[i] = second[i/2];break;
		}
	}
}

void center(int *shfjudge,int *array,int arraynum,int times){
	int i;
	for(i=0;i<times;i++){	//sizeof(ポインタ)は出来ない事に注意
		switch(shfjudge[i]){
			case 0: refshf(array,arraynum);break;
			default: shuffle(array,shfjudge[i],arraynum);break;
		}
	}
	for(i=0;i<arraynum*2;i++){
		printf("%d\n",array[i]);
	}
}

int main(void)
{
	int arraynum,times;
	int *shfjudge,*array;
	
	scanf("%d",&arraynum);
	array = (int *)calloc(2*arraynum,sizeof(int));
	if(array == NULL){
		printf("失敗1");
		return EXIT_FAILURE;
	}
	scanf("%d",&times);
	shfjudge = (int *)calloc(times,sizeof(int));
	if(shfjudge == NULL){
		printf("失敗2");
		return EXIT_FAILURE;
	}
	
	int i;
	for(i=0;i<arraynum*2;i++){
		array[i] = i+1;
	}	
	for(i=0;i<times;i++){
		scanf("%d",&shfjudge[i]);
	}
	center(shfjudge,array,arraynum,times);
	free(array);
	free(shfjudge);
	return 0;
}


Measured memory_bytes: 2036
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<usize> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    let mut cnt: Vec<usize> = vec![0; 22];

    let mut ans: usize = 0;
    let mut r: usize = 0;
    for l in 0..n {
        // cntの要素に2以上が現れるまでrを進める。
        while r < n {
            let mut check = true;
            for i in 0..20 {
                if a[r] >> i & 1 == 1 && cnt[i] > 0 {
                    check = false;
                }
            }
            if check {
                for i in 0..20 {
                    if a[r] >> i & 1 == 1 {
                        cnt[i] += 1;
                    }
                }
                r += 1;
            } else {
                break;
            }
        }
        ans += r - l;
        if r == l {
            r += 1;
        }
        for i in 0..20 {
            if a[l] >> i & 1 == 1 {
                cnt[i] -= 1;
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 8444
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
class E { static void Main() { new K(); } }
class K
{
	int F() { return int.Parse(Console.ReadLine()); }
	int[] G() { return Console.ReadLine().Split().Select(_ => int.Parse(_)).ToArray(); }
	public K()
	{
		Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
		var N = F();
		Console.WriteLine(N * (N + 1) / 2);
		Console.Out.Flush();
	}
}

Measured memory_bytes: 2648
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#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<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const ll mod = 1000000007;
const ll INF = mod * mod;
#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 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 complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
//#define int long long

void solve() {
    int n; cin >> n;
    ll a[100100];
    rep(i, n) {
        cin >> a[i];
    }
    ll dp[100100][2];
    dp[0][0] = a[0]; dp[0][1] = -INF;
    rep1(i, n) {
        dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]) + a[i];
        dp[i][1] = max(dp[i - 1][0] - 2 * a[i - 1], dp[i - 1][1] + 2 * a[i - 1]) - a[i];
    }
    cout << dp[n][0] << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll N=1000000007;
//ll power(ll a,ll b,ll mod)
//{
//    ll result=1;
//    while(b>0)
//    {
//        if(b%2==1)
//            result=(result*a)%mod;
//        a=(a*a)%mod;
//        b=b/2;
//    }
//    return result;
//}
//ll d,x,y;
//void extendedEuclid(ll a,ll b)
//{
//    if(b==0)
//    {
//        d=a; x=1; y=0;
//    }
//    else
//    {
//        extendedEuclid(b,a%b);
//        ll temp=x; x=y; y=temp-(a/b)*y;
//    }
//}
//ll modInverse(ll a,ll m)
//{
//    extendedEuclid(a,m);
//    return (x%m+m)%m;
//}
//ll lcm(ll a,ll b)
//{
//    if(a==0||b==0)
//        return 0;
//    return (a*b)/(__gcd(a,b));
//}
//void sieve(ll n)
//{
//    bool isPrime[n+1];
//    isPrime[0]=false; isPrime[1]=false;
//    for(ll i=2;i<=n;i++)
//        isPrime[i]=true;
//    for(ll i=2;i<=n;i++)
//    {
//        if(isPrime[i]==true)
//        {
//            for(ll j=i*i;j<=n;j+=i)
//                isPrime[j]=false;
//        }
//    }
//}
//bool isPowerOfTwo(ll n)
//{
//    return (n&&!(n&(n-1)));
//}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,i;  cin>>n;
    string s;
    while(n>0){
        n--;   s+=(n%26)+'a';   n=n/26;
    }
    reverse(s.begin(),s.end());  cout<<s;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int mod = 1000000007;

ll factorial(ll x){
    if (x==0)return 1;
    if (x==1) return 1;
    else return x * factorial(x-1) % mod;
}


int main() {
    ll N, M;
    cin >> N >> M;
    if (abs(N-M) > 1){
        cout << 0 << endl;
        return 0;
    }
    int ans;
    if(N==M){
        ans = (factorial(N) % mod * factorial(M) % mod * 2 % mod)%mod;   
    }
    else {
        ans = (factorial(N) % mod * factorial(M) % mod)%mod; 
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
import sys
input = sys.stdin.readline
import numpy as np


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


p = np.pi
h_m = h * 60 + m

arg_min = 2 * p / 60 * m
arg_hor = 2 * p / 720 * h_m

the = float(abs(arg_min-arg_hor))

ans = np.sqrt(a**2 + b**2 - 2 *a*b*np.cos(the))

print(ans)


Measured memory_bytes: 27196
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;++i)
int main(){
  ll n;
  cin >> n;
  char s[n+1];
  ll r[n],g[n],q=0,w=0,e=0;
  cin >> s;
  rep(i,n){
    if(s[i]=='R'){
      r[q]=i;
      q++;
    }
    if(s[i]=='G'){
      g[w]=i;
      w++;
    }
    if(s[i]=='B'){
      e++;
    }
  }
  ll ans=q*w*e;
  rep(i,q){
    rep(j,w){
      if(r[i]+r[i]-g[j]>-1&&r[i]+r[i]-g[j]<n&&s[r[i]+r[i]-g[j]]=='B')ans--;
      if(g[j]-r[i]+g[j]>-1&&g[j]-r[i]+g[j]<n&&s[g[j]-r[i]+g[j]]=='B')ans--;
      if((r[i]+g[j])%2==0&&s[(r[i]+g[j])/2]=='B')ans--;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
  
int main(){
  int N;
  cin >> N;
  double A=0;
  vector<int> X(N),Y(N);
  for(int i=0;i<N;i++){
    cin >> X.at(i) >> Y.at(i);
  }
  for(int i=0;i<N-1;i++){
    for(int j=i+1;j<N;j++){
      int X1=X.at(i)-X.at(j);
      int Y1=Y.at(i)-Y.at(j);
      A+=sqrt(X1*X1+Y1*Y1);
    }
  }
  double ans=2*A/N;
  cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 3832
#include <cstdio>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <algorithm>
#include <set>
#include <deque>
#include <utility>
#include <chrono>
#include <sstream>
#include <iomanip>
using namespace std;
#define MOD 1000000007
#define PI 3.14159265358979
#define rep(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define rer(i, l, r) for (int (i) = (int)(l); (i) <= (int)(r); (i)++)
#define reu(i, l, r) for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define each(i, v) for (auto i : v)
#define D(x) cout << x << endl
#define d(x) cout << x
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pub(x) push_back(x)
#define pob() pop_back()
#define puf(x) push_front(x)
#define pof() pop_front()
#define mp(x, y) make_pair((x), (y))
#define fi first
#define se second
#define setp(x) setprecision(x)
#define mset(m, v) memset(m, v, sizeof(m))
static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }

//static const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//#define int ll

int main() { 
        int a, b, c;
        cin >> a >> b >> c;
        bool flag = false;
        rep(i, 101) {
                if (i * a % b == c) flag = true;
        }
        puts(flag ? "YES" : "NO");
        return 0;
}



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

signed main(){

  int n; cin >> n;
  map<int,int> mp;
  for(int i = 0; i < n; i++){
    int a,b; cin >> a >> b;
    mp[a] = b;
  }

  auto p1 = *mp.begin();
  auto p2 = *mp.rbegin();
  //int ans = p2.first + min(p2.second, p1.second - p2.second);
  int ans = p2.first + p2.second;
  cout << ans << endl;

  return 0;
}


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

using namespace std;

int main() {
  int X, Y;
  cin >> X >> Y;
  if (2 * X <= Y && Y <= 4 * X && Y % 2 == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

int main() {
    
    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
    
    int N, H, W;
    cin >> N >> H >> W;
    
    cout << (N - H + 1) * (N - W + 1) << "\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{

	static int[] list;
	static int pp = 0, pn = 1; // pp?§?????????????????????????????§???????????????????????????????pn

	public static void main(String[] args){

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[][] v = new int[n+1][n+1];
		int[] d = new int[n+1];

		for(int i = 0; i < n; i++){
			int u = scan.nextInt();
			int k = scan.nextInt();
			d[u] = -1;
			for(int j = 1; j <= k ; j++)
				v[u][j] = scan.nextInt();
		}

		d[1] = 0; // ???1??????????????¢???0
		list = new int[n+1];
		list[0] = 1; // ?§????????????????1??????

		Bsearch(v, d);

		for(int i = 1; i <= n; i++)
			System.out.println(i + " " + d[i]);

		scan.close();
		System.exit(0);
	}

	private static void Bsearch(int[][] v, int[] d){
		for(; pp < pn; pp++){
			int fr = list[pp]; // fr????§????????§???????????????????????????????
			for(int i = 1; i < v[fr].length-1; i++){
				int to = v[fr][i]; // ?§????????????????????????????
				if(d[to] == -1){ // ???????????§????????¢???-1??????
					d[to] = d[fr] + 1; // ??????????????¢????§?????????§????????¢+1
					list[pn] = to; // ?§?????????????????????????????´?
					pn++; // ???????????????????????????+1
					// 2??????1??????????????¨???list[pn++] = to??????????????????????????????pn???+1?????????????????????????????????
				}
			}
		}
	}
}

Measured memory_bytes: 28756
/**
 *    author        : Saurav Paul 
 *    created       : August 21, 2020 12:16 PM
 *    Problem Name  : B - Minor Change
 *    Problem Limit : 2000 ms , 1024 MB
 *    Problem Url   : https://atcoder.jp/contests/abc172/tasks/abc172_b
 *    @genarated by : ai-virtual-assistant
**/

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

using ll = long long int ;

void solve(){

    string s , t;
    cin >> s >> t;
    int cnt = 0 ;

    for(int i = 0 ; i < s.size() ; i++){
        if(s[i]!=t[i]) ++ cnt ;
    }

    cout << cnt << endl ;

}

int main(){
    ios_base::sync_with_stdio(false);

    int testcases = 1;
    for(int i = 1 ; i <= testcases ; i ++){
        solve();
    }

    return 0 ;
}


Measured memory_bytes: 3776
///in the name of God
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
#define fir first
#define sec second

const int MAXN=1000*1000+100;


int l,n,m,sv;
int bitl;
vector< pair<pair<int,int>,int> > ans;
vector <int> v;

int find_bit(int k){
    int ret=0;
    while(k){
        if(k%2) v.push_back(ret);
        k/=2;
        ret++;
    }
    return ret;
}

void pre_ans(){
    for(int i=1;i<n;i++){
        ans.push_back({{i,i+1},(1<<(n-i-1))});
        ans.push_back({{i,i+1},0});
    }
}

void output(){
    cout<<n<<" "<<m-1<<endl;
    for(int i=0;i<ans.size();i++){
        cout<<ans[i].fir.fir<<" "<<ans[i].fir.sec<<" "<<ans[i].sec<<endl;
    }
}

int main(){
    cin>>l;
    bitl=find_bit(l);
    n=bitl;
    m=v.size()+(n-1)*2;
    pre_ans();
    sv+=(1<<v.back());
    v.pop_back();
    while(v.size()){
        ans.push_back({{1,n-(v.back()-1)-1},sv});
        sv+=(1<<v.back());
        v.pop_back();
    }
   // ans.push_back({{1,n},l});
    output();
    /*for(int i=0;i<v.size();i++){
        cout<<v[i]<<endl;
    }*/
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,s,n) for(ll i = (s); i < (n); i++)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
  
  ll n;
  cin >> n;
  map<ll, ll> m;
  rep(i, 0, n) {
    ll x;
    cin >> x;
    m[x]++;
  }
  
  ll m1 = 0, m2 = 0;
  for(const auto& e : m) {
    if(e.second >= 4) {
      m2 = e.first;
      m1 = e.first;
    }
    else if(e.second >= 2) {
      m2 = m1;
      m1 = e.first;
    }
  }
  cout << m1*m2 << "\n";
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s="No";
  cin>>n;
  vector<vector<int>> a(n,vector<int> (2));
  for(int i=0;i<n;i++){
    cin>>a[i][0]>>a[i][1];
  }for(int i=0;i<n-2;i++){
    if(a[i][0]==a[i][1]&&a[i+1][0]==a[i+1][1]&&a[i+2][0]==a[i+2][1]){
      s="Yes";
      break;
    }
  }cout<<s<<endl;
}

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

int main() {
  
  string S;
  
  cin >> S;
    
  if(S.at(0)=='a' && S.at(1)=='b' && S.at(2)=='c') {
    
    cout << "Yes" << endl;
    
  } else if(S.at(0)=='a' && S.at(1)=='c' && S.at(2)=='b') {
    
    cout << "Yes" << endl;
    
  } else if(S.at(0)=='b' && S.at(1)=='a' && S.at(2)=='c') {
    
    cout << "Yes" << endl;
    
  } else if(S.at(0)=='b' && S.at(1)=='c' && S.at(2)=='a') {
    
    cout << "Yes" << endl;
    
  } else if(S.at(0)=='c' && S.at(1)=='a' && S.at(2)=='b') {
    
    cout << "Yes" << endl;
    
  } else if(S.at(0)=='c' && S.at(1)=='b' && S.at(2)=='a') {
    
    cout << "Yes" << endl;
    
  } else {
    
    cout << "No" << endl;
    
  }
  
  return 0;
  
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

struct SST{
  int segn2;
  vector<pair<int,int> > data;
  vector<int> s_data;
  
  SST(int n, vector<int> &vec){
    for(segn2=1;segn2<n;segn2*=2);
    data.assign(segn2*2,{0,0});
    s_data.assign(segn2*2,0);
    
    for(int i=0;i<n;i++){
      data[segn2+i-1] = {1-vec[i], vec[i]};
    }

    for(int i = segn2-2;i>=0;i--){
      auto A = data[i*2+1];
      auto B = data[i*2+2];
      
      data[i] = {A.first+B.first, A.second+B.second};
    }    
  }

  pair<int,int> query(int a, int b, int l=0, int r=-1, int k=0){
    if (r==-1) r += segn2;
    
    if(r < a || b < l) return {0,0};
    if(a<=l && r<=b){
      if(s_data[k]%2)
        return {data[k].second, data[k].first};
      else
        return data[k];
    }

    auto A = query(a,b,l,(l+r)/2,k*2+1);
    auto B = query(a,b,(l+r)/2+1, r, k*2+2);

    if(s_data[k]%2)
      return {A.first + B.first, A.second + B.second};
    else
      return {A.second + B.second, A.first + B.first};
  }

  pair<int,int> add(int a, int b, int l=0, int r=-1, int k=0){
    if(r==-1) r += segn2;
    if(a<=l && r <= b){
      s_data[k]++;
    }else if(a<=r && l<=b){
      auto A = add(a,b,l,(l+r)/2,k*2+1);
      auto B = add(a,b,(l+r)/2+1, r, k*2+2);

      data[k] = {A.first + B.first, A.second + B.second};
    }
    
    if(s_data[k]%2)
      return {data[k].second, data[k].first};
    else
      return data[k];
  }
};

int t = 0;
vector<int> vec;
vector<int> way[SIZE];

int b[SIZE], e[SIZE];

void dfs(int now){
  vec.push_back(now);
  b[now] = t++;
  
  for(int i=0;i<way[now].size();i++){
    dfs(way[now][i]);
  }

  vec.push_back(now);
  e[now] = t++;
}

int main(){
  int n, q;

  scanf("%d%d",&n,&q);
  
  for(int i=1;i<n;i++){
    int p;
    scanf("%d",&p);
    way[p-1].push_back(i);
  }

  dfs(0);

  vector<int> add(n*2, 0);
  
  for(int i=0;i<n;i++){
    char c;
    scanf(" %c",&c);
    add[b[i]] = c == 'W';
    add[e[i]] = c == 'W';
  }

  auto sst = SST(n*2, add);
  
  for(int i=0;i<q;i++){
    int v;

    scanf("%d",&v);
    v--;
    
    sst.add(b[v],e[v]);

    auto ret = sst.query(0,INF);
    
    if(ret.first > ret.second){
      puts("broccoli");
    } else{
      puts("cauliflower");
    }
  }
  
  return 0;

}



Measured memory_bytes: 20160
#include<bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
int main(){
long long n;
 cin>>n;
long long d[n+1][n+1]={0};
for(long long i=1;i<=n;i++){
    for(long long j=1;j<=n;j++){
        d[i][j]=GCD(i,j);
    }
}
long long ans=0;
for(long long i=1;i<=n;i++){
    for(long long j=1;j<=n;j++){
        for(long long k=1;k<=n;k++){
            ans+=GCD(i,d[j][k]);
        }
    }
}
cout<<ans<<endl;
    return 0;
}


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

int main(){
    int a, b, ans;
    cin >> a >> b;
    
    int buf = a * 10 + b * 10;
    if (buf % 20 != 0) {
        ans = (buf + 10) / 20;
    } else {
        ans = buf / 20;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<cassert>
#include<cstring>
#include<climits>
#include<map>
#include<set>

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

using namespace std;

struct Edge { int dst,w; };
struct Data {
  int cur, w, type, x;
  bool operator < ( const Data &data ) const {
    if( w != data.w ) return w > data.w;
    if( x != data.x ) return x > data.x;
    if( type != data.type ) return type > data.type;
    return cur > data.cur;
  }
};
int V,E,X;

#define MAX_V 10010
vector<Edge> G[MAX_V];
vector<int> state;
int mini[MAX_V][3][210];

void compute() {
  rep(i,V) rep(j,3) rep(k,210) mini[i][j][k] = INT_MAX;
  mini[0][0][X] = 0;
  priority_queue<Data> Q;
  Q.push((Data){0,0,0,X});
  while( !Q.empty() ) {
    Data data = Q.top(); Q.pop();
    rep(i,(int)G[data.cur].size()) {
      Edge &e = G[data.cur][i];
      int dst = e.dst;
      int nx  = max(data.x - e.w,0);
      if( nx && state[dst] != 1 && state[dst] != data.type ) continue;
      if( nx && state[dst] == data.type ) {
	nx = X;
	if( mini[dst][data.type][nx] > data.w + e.w ) {
	  mini[dst][data.type][nx] = data.w + e.w;
	  Q.push((Data){dst,data.w+e.w,data.type,nx});
	}
      } else if( nx && state[dst] == 1 ) {
	if( mini[dst][data.type][nx] > data.w + e.w ) {
	  mini[dst][data.type][nx] = data.w + e.w;
	  Q.push((Data){dst,data.w+e.w,data.type,nx});
	}
      } else if( state[dst] == 1 ) {
	assert( nx == 0 );
	if( mini[dst][1][nx] > data.w + e.w ) {
	  mini[dst][1][nx] = data.w + e.w;
	  Q.push((Data){dst,data.w+e.w,1,nx});
	}
      } else {
	int type = state[dst];
	nx = X;
	if( mini[dst][type][nx] > data.w + e.w ) {
	  mini[dst][type][nx] = data.w + e.w;
	  Q.push((Data){dst,data.w+e.w,type,nx});
	}
      }
    }
  }
  int ans = INT_MAX;
  rep(j,3) rep(k,210) ans = min(ans,mini[V-1][j][k]);
  cout << ans << endl;
}

int main() {
  cin >> V >> E >> X;
  state.resize(V);
  rep(i,V) cin >> state[i];
  rep(i,E) {
    int s,t,c;
    cin >> s >> t >> c;
    --s, --t;
    G[s].push_back((Edge){t,c});
    G[t].push_back((Edge){s,c});
  }
  compute();
  return 0;
}

Measured memory_bytes: 28608
#[allow(dead_code)]
fn rd() -> String {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    input.trim().to_owned()
}

/// 1行の文字を空白で分割してVec<T>にする。
#[allow(dead_code)]
fn rd_vec<T : std::str::FromStr>() -> Vec<T> {
    rd().split_whitespace().map(|x| x.parse().ok().unwrap()).collect()
}

/// 1つの要素を入力で受け取る
#[allow(dead_code)]
fn rd_one<T : std::str::FromStr>() -> T {
    rd().parse().ok().unwrap()
}

/// 複数回read_splitを行う
#[allow(dead_code)]
fn rd_vec_mul<T : std::str::FromStr>(count : i32) -> Vec<Vec<T>> {
    (0..count).map(|_| rd_vec()).collect()
}

/// Vecを1列で出力する
#[allow(dead_code)]
fn op_vec<T : std::fmt::Display>(item : Vec<T>, splitter : char) {
    let cnt = item.len();
    let mut c = 0;
    for i in item.iter() {
        c+=1;
        if cnt > c {print!("{}{}", i, splitter);} else {println!("{}", i);}
    }
}

fn main() {
    let input : Vec<usize> = rd_vec();
    let a : Vec<i64> = rd_vec();
    let mut heap = std::collections::BinaryHeap::<i64>::new();
    for v in a {
        heap.push(v);
    }

    for _ in 0..input[1] {
        let t = heap.pop().unwrap();
        heap.push(t/2);
    }
    println!("{}", heap.iter().sum::<i64>());
}

Measured memory_bytes: 9464
N, M = map(int, input().split())
X = list(map(int, input().split()))

Y = sorted(X)
sum_Y = []
for i in range(len(Y) - 1):
    sum_Y.append(Y[i + 1] - Y[i])

Z = sorted(sum_Y)

for i in range(N - 1):
    if Z == []:
        break
    else:
        Z.pop()

print(sum(Z))

Measured memory_bytes: 13960
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int dp[1<<16];
int n;
int t[30][30];
int main(){
	while(cin>>n,n){
		rep(i,n){
			rep(j,n+1){
				cin>>t[i][j];
			}
		}
		rep(i,1<<16){
			dp[i] = INF;
		}
		dp[0] = 0;
		rep(i,1<<n){
			if(dp[i]==INF)
				continue;
			rep(j,n){
				if(!(i&(1<<j))){//まだ訪れてないならば
					dp[i+(1<<j)] =min(dp[i+(1<<j)],dp[i]+t[j][0]);//何も装備しない
					rep(k,n){
						if(i&(1<<k)){
							dp[i+(1<<j)] = min(dp[i+(1<<j)],dp[i]+t[j][k+1]);
						}
					}
				}
			}
		}
		cout <<dp[(1<<n)-1]<<endl;
	}
	return 0;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<int> X(N);
    rep(i, N) cin >> X[i];
    int ans = 1001001001;
    rep(p, 101) {
        int now = 0;
        rep(i, N) now += (X[i] - p) * (X[i] - p);
        chmin(ans, now);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    int ans = ((N+(2*K+1)-1))/(2*K+1);
    System.out.print(ans);
  }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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

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

int N,C,X;
int D[30][39];
int t[3][30];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;cin>>N>>M;
    vector<ll> x(N),y(N),z(N);
    REP(i,N) cin>>x[i]>>y[i]>>z[i];
    ll ans=0;
    for(int pm1=-1;pm1<=1;pm1+=2){
        for(int pm2=-1;pm2<=1;pm2+=2){
            for(int pm3=-1;pm3<=1;pm3+=2){
                vector<ll> s(N);
                REP(i,N){
                    s[i] = x[i]*pm1+y[i]*pm2+z[i]*pm3;
                }
                VSORT(s);
                reverse(s.begin(),s.end());
                ll score=0;
                REP(i,M) score+=s[i];
                ans = max(ans,score);
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
n, x = map(int, input().split())
a = list(map(int, input().split()))

ans = 0
now = a[0]
if now > x:
    ans += now - x
    now = x
for i in a[1:]:
    tmp = max(0, now + i - x)
    now = i - tmp
    ans += tmp
print(ans)

Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+6;
typedef long long ll;
const int mod=1e9+7;
char s[maxn];
int q[maxn];
int main()
{
    scanf("%s",s);
    int l=strlen(s);
    int cnt=0;
    int ans=0;
    for(int i=0;i<l;i++)
    {
        if(cnt==0)q[cnt++]=s[i]-'0';
        else
        {
            if(q[cnt-1]!=s[i]-'0')ans+=2,cnt--;
            else q[cnt++]=s[i]-'0';
        }

    }

    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 2688
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
using ll = long long;
using uint = unsigned int;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;
ll MOD7 = 1000000007;
ll MOD9 = 1000000009;
vector<ll> InputVec(ll N){
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    return A;
}
void OutputVec(vector<ll> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
vector<vector<ll>> InputVec2d(ll H,ll W){
    vector<vector<ll>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<ll>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            cin >> A[yi][xi];
        }
    }
    return A;
}
vector<vector<char>> InputVec2dStr(ll H,ll W){
    vector<vector<char>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<char>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        string S;
        cin >> S;
        for (int xi = 0; xi < W; ++xi) {
            A[yi][xi] = S[xi];
        }
    }
    return A;
}
void OutputVec2d(vector<vector<ll>> A){
    for (int yi = 0; yi < A.size(); ++yi) {
        for (int xi = 0; xi < A[yi].size(); ++xi) {
            cout << A[yi][xi] << ",";
        }
        cout << endl;
    }
}
graph InputGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    return G;
}
graph InputDGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
    }
    return G;
}
void OutputGraph(graph G){
    for (int i = 0; i < G.size(); ++i) {
        cout << i << ":";
        for (int j = 0; j < G[i].size(); ++j) {
            cout << G[i][j]<< ",";
        }
        cout << endl;
    }
}
void OutputAnswerBool(bool b,bool isUpperCase = false){
    if(b){
        if(isUpperCase){
            cout << "YES" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        if(isUpperCase){
            cout << "NO" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

int main() {
    string S;
    ll X,Y,Z;
    cin >> X>>Y>>Z;
    cout << Z<<" " << X <<" "<< Y;

}


Measured memory_bytes: 256
N = int(input())
A = [int(input()) for i in range(N)]

import bisect

bilist = [A[0]]
ans = 0

for a in A[1:]:
    index = bisect.bisect_left(bilist,a)
    if index == 0:
        bisect.insort_left(bilist,a)
    else:
        bilist[index-1] = a


print(len(bilist))


    

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

using namespace std;

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

    if (S.at(2) == S.at(3) && S.at(4) == S.at(5)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include"iostream"
#include<stdlib.h>
#include<stdio.h>
#include<time.h>
#include<list>
#include<map>
#include<string>
#include<algorithm> 
#include <queue> 
#include <sstream>
#include <fstream>
#include<cmath>
#define INF 100000000000
#define LL long long
using namespace std;
map<LL , LL> m;
long long N, M, K, ans,A,B,a[5];

string s;

int main() {
	for (int i = 0; i < 5; i++) {
		cin >> a[i];
	}
	cin >> N;
	for (int i = 0; i < 4; i++) {
		for (int j = i + 1; j < 5;j++) {
			if (a[j] - a[i] > N) {
				cout << ":(" << endl;
				return 0;
			}
		}
	}
	cout << "Yay!" << endl;
	return 0;
}

Measured memory_bytes: 256