akhauriyash/Code-Regression huggingface dataset:
use proconio::input;
 
fn main() {
  input! {
    n: usize,
    m: usize,
    mut drinks: [(usize, usize);n]
  }
  drinks.sort_by(|a, b| a.0.cmp(&b.0));
  
  let mut total = 0;
  let mut count = 0;
  for (val, num) in drinks {
    for _ in 0..num {
      count += 1;
      total += val;
      if m == count {
        println!("{}", total);
        return
      }
    }
  }
}


Measured memory_bytes: 5760
#include <stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
long long cmpfunc (const void * a, const void * b) {
   return ( *(long long*)a - *(long long*)b );
}



int main(void){
   
long long int test,i,j,n,count,flag=0,o1=0,o2=0,b1,x,m,l,max,sum2,min,f,c,r,o,sum1,sum=0,y,a[100000],b[10000],count1=0,a2,b2;

scanf("%lld",&n);
for(i=0;i<n;i++){
    scanf("%lld",&a[i]);
     b[i]=a[i];
}
count=0;
qsort(b,n,sizeof(long long int),cmpfunc);
for(i=0;i<n;i++){
    if(a[i]!=b[i]){
        count++;
    }
}
if(count>2){
    printf("NO");
}else{
    printf("YES");
}
return 0;
}


Measured memory_bytes: 128
#define _USE_MATH_DEFINES //円周率を使用
#include <math.h>
#include <iomanip> //小数点以下を表示
#include <iostream>
using namespace std;

//【関数の定義】
void call(int n);

int main(void)
{
	int n; //整数

	cin >> n;

	if (n < 3 || n > 10000)
		return 0;

	call(n);

	return 0;
}

void call(int n)
{
	int i = 1;

	do
	{
		int x = i;
		int k; //カウンタ変数
		int xx[5] = {0, 0, 0, 0, 0}; //桁崩し（0は万の位、5は一の位）

		if (x % 3 == 0) //3の倍数を表示
		{
			cout << " " << i;
		}

		else //1桁でも"3"があれば表示
		{
			xx[0] = x / 10000;
			x -= (xx[0] * 10000);
			xx[1] = x / 1000;
			x -= (xx[1] * 1000);
			xx[2] = x / 100;
			x -= (xx[2] * 100);
			xx[3] = x / 10;
			x -= (xx[3] * 10);
			xx[4] = x;


			for (k = 0; k < 5; k++)
			{
				if (xx[k] == 3)
				{
					cout << " " << i;
					break;
				}
			}

		}

	} while (++i <= n);

	cout << endl;
}


Measured memory_bytes: 3096
#include<iostream>
#include<cstdio>
#include<cctype>
#define re register
using namespace std;
const int MAXN=410,mod=998244353;
int n,f[MAXN][MAXN][MAXN],res,ans,fac[MAXN],inv[MAXN],a[MAXN],b[MAXN],tot,S; 
int read()
{
	int x=0;
	char ch=0;
	while(!isdigit(ch))
		ch=getchar();
	while(isdigit(ch))
	{
		x=(x<<3)+(x<<1)+(ch^48);
		ch=getchar(); 
	}
	return x;
}
int fastpow(int a,int k)
{
	re int c=1;
	for(;k;k>>=1)
	{
		if(k&1)
			c=1ll*c*a%mod;
		a=1ll*a*a%mod; 
	}
	return c;
}
void pre(int n)
{
	fac[0]=1;
	for(re int i=1;i<=n;i++)
		fac[i]=1ll*fac[i-1]*i%mod;
	inv[n]=fastpow(fac[n],mod-2);
	for(re int i=n-1;~i;i--)
		inv[i]=1ll*inv[i+1]*(i+1)%mod;
}
int C(int n,int m)
{
	if(n<m)
		return 0;
	return 1ll*(1ll*inv[m]*inv[n-m]%mod)*fac[n]%mod;
}
int main()
{
	n=read();
	for(re int i=1;i<=n;i++)//数组A,B下标从1开始
		a[i]=read(),b[i]=read(),tot+=b[i],S+=a[i];
	pre(400);
	f[0][0][0]=mod-1;
	//f(i,j,k)=f(i-1,j,k)-\sum_{t=0}^{B_i-1} {k\choose t} f(i-1,j-A_i,k-t)A_i^t
	for(re int i=1;i<=n;i++)
		for(re int j=0;j<=S;j++)
			for(re int k=0;k<=tot;k++)
			{
				f[i][j][k]=f[i-1][j][k];
				if(j<a[i])
					continue;
				for(re int t=0,now=1;t<=min(b[i]-1,k);t++,now=1ll*now*a[i]%mod)
					f[i][j][k]=(f[i][j][k]-1ll*(1ll*C(k,t)*f[i-1][j-a[i]][k-t]%mod)*now)%mod;
				f[i][j][k]=(f[i][j][k]+mod)%mod;
			}
	//ans=\sum_{j=1}^S \frac {S}{j}\sum_{k=0}^{\sum_{i=1}^n B_i-n}\frac {f(n,j,k)}{j^k}
	for(re int j=1;j<=S;j++)
	{
		re int res=0;
		for(re int k=0;k<=tot-n;k++)
			res=(res+1ll*f[n][j][k]*fastpow(j,mod-1-k))%mod;
		ans=(ans+1ll*(1ll*S*fastpow(j,mod-2)%mod)*res)%mod;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 263808
import java.util.Scanner;

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

        for (int i = 0; i < 3; i++)
            box[i] = sc.nextInt();

        for (int i = 0; i < 3; i++) {
            for (int j = i + 1; j < 3; j++) {
                if (box[i] > box[j]) {
                    int temp;
                    temp = box[i];
                    box[i] = box[j];
                    box[j] = temp;
                }
            }
        }

        for (int i = 0; i < 3; i++)
        {
            if (i == 0)
                System.out.print(box[i]);
            else if(i==1)
                System.out.printf(" %d", box[i]);
            else if(i==2)
                System.out.println(" "+box[i]);
        }


    }

}



Measured memory_bytes: 26360
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<map>
#include<queue>
#include<iostream>
#include<cmath>
//#define int long long 
using namespace std;
inline int gi(){char tmp=getchar();int flag=1;while(tmp<'0'||tmp>'9'){if(tmp=='-'){flag=-1;tmp=getchar();break;}tmp=getchar();}int ans=0;while(tmp<='9' and tmp>='0') {ans=ans*10+tmp-'0';tmp=getchar();}return ans*flag;}
inline void write(int x){static int stk[100], top = 0;if (x == 0) { putchar('0'); putchar(' ');return; }if (x < 0) { x = -x; putchar('-'); }while (x) { stk[++top] = x % 10; x /= 10; }while (top) { putchar(stk[top--] + '0'); }putchar(' ');}
#define line() putchar('\n');
#define Mem(Arr,V) memset(Arr,V,sizeof Arr);
#define Mcpy(Arr,qwq) memcpy(Arr,qwq,sizeof qwq);
#define max3(a,b,c) max(max(a,b),c)
#define max4(a,b,c,d) max4(max3(a,b,c),d);
#define in(a) a=gi()
#define in2(a,b) in(a),in(b)
#define in3(a,b,c) in2(a,b),in(c)
#define in4(a,b,c,d) in3(a,b,c),in(d)
#define write2(a,b) write(a),write(b)
#define write3(a,b,c) write2(a,b),write(c)
#define write4(a,b,c,d) write3(a,b,c),write(d)
#define smin(a,b) a=min(a,b)
#define smax(a,b) a=max(a,b)
const int inf=2147483647 ; // 如果是 long long 记得改！
const int N =1000001;
char S[N];
signed main()
{
	int n=gi();
	char pre=0;int ans=0;	
	for(int i=1;i<=n;++i)
	{
		char tmp;
		scanf(" %c",&tmp);
		if(i==1){pre=tmp;++ans;}
		else if(pre==tmp) {continue;}
		else if(pre!=tmp) {pre=tmp;++ans;}
	}
	write(ans);
	return 0;
}

Measured memory_bytes: 256
///
// File:  c.cpp
// Author: ymiyamoto
//
// Created on Fri Sep 29 20:50:02 2017
//
#include <cstdint>
#include <iostream>

using namespace std;

static inline int64_t ceil(int64_t a, int64_t b)
{
  if (a % b == 0)
    return a / b;
  else
    return a / b + 1;
}

int32_t main()
{
  uint32_t N;
  cin >> N;

  int64_t t = 1, a = 1;
  for (uint32_t i = 0; i < N; i++) {
    int64_t T, A;
    cin >> T >> A;
    int64_t n = max(ceil(t, T), ceil(a, A));
    t = n * T;
    a = n * A;
  }

  cout << t + a << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm> // sort(ALL())
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue> // push(), front(), pop() 先入れ先出し
#include<map> // 連想配列 map<string, int>
#include<iomanip>
#include<set>
#include<utility>
using namespace std;
#define FOR(i, a, b) for(int i=(a); i<(b);  i++)
#define REP(i, n)    for(int i=0;   i<(n);  i++)
#define REP1(i, n)   for(int i=1;   i<=(n); i++)
#define pb push_back
#define mp make_pair
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define EPS 1e-7
#define ALL(obj) (obj).begin(), (obj).end()
using ul    = unsigned long;
using ll    = long long;
using ld    = long double;
using vint  = vector<int>;
using vll   = vector<ll>;
using pint  = pair<int, int>;
using pll   = pair<ll, ll>;
using vpint = vector<pint>;
using vpll  = vector<pll>;
const int INF = (int)1e9 + 1;
const int MOD = (int)1e9 + 7;
#define INT(argu) (int)(argu+EPS)



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

//  vint s(n);
//  REP(i, n) scan(s[i]);

	int a, b;

	cin >> a >> b; 

  cout << a*b << endl;

  return 0;
}


Measured memory_bytes: 3640
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func ri() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}

func gcd(a, b int) int {
	for b != 0 {
		c := a % b
		a, b = b, c
	}
	return a
}

func main() {
	sc.Split(bufio.ScanWords)
	n := ri()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = ri()
	}
	cL := make([]int, n)
	gcdL := a[0]
	for i := 0; i < n; i++ {
		gcdL = gcd(gcdL, a[i])
		cL[i] = gcdL
	}
	cR := make([]int, n)
	gcdR := a[n-1]
	for i := n - 1; i >= 0; i-- {
		gcdR = gcd(gcdR, a[i])
		cR[i] = gcdR
	}
	cL = append([]int{cR[n-1]}, cL[:n-1]...)
	cR = append(cR[1:], cL[1])
	mx := -1
	for i := 0; i < n; i++ {
		if x := gcd(cL[i], cR[i]); x > mx {
			mx = x
		}
	}
	fmt.Println(mx)
}


Measured memory_bytes: 4992
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

using Graph=vector<vector<int>>;
// グラフ、頂点の入次数、頂点数を受け取り、そのトポロジカルソートを記録した配列を返す関数
vector<int> topological_sort(Graph &G, vector<int> &indegree, int V) {
    // トポロジカルソートを記録する配列
    vector<int> sorted_vertices;

    // 入次数が0の頂点を発見したら、処理待ち頂点としてキューに追加する
    queue<int> que;
    for (int i = 0; i < V; i++) {
        if (indegree[i] == 0) {
            que.push(i);
        }
    }

    // キューが空になるまで、操作1~3を繰り返す
    while (que.empty() == false) {
        // キューの先頭の頂点を取り出す
        int v = que.front();
        que.pop();

        // その頂点と隣接している頂点の入次数を減らし、0になればキューに追加
        for (int i = 0; i < G[v].size(); i++) {
            int u = G[v][i];
            indegree[u] -= 1;
            if (indegree[u] == 0) que.push(u);
        }
        // 頂点vを配列の末尾に追加する 
        sorted_vertices.push_back(v);
    }

    // トポロジカルソートを返す
    return sorted_vertices;
}


int main(){
    int N,M;
    cin>>N>>M;
    Graph G(N),oya(N);
    vector<int> indegree(N,0);
    
    REP(i,N-1+M){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        G[a].push_back(b);
        oya[b].push_back(a);
        indegree[b]++;
    }
    vector<int> topo=topological_sort(G,indegree,N);
    vector<int> ans(N);
    vector<int> rev(N+1);
    REP(i,N) rev[topo[i]]=i;
    rev[N]=-1;

    REP(i,N){
        if(oya[i].size()==0) ans[i]=0;
        else{
            int idx=N;
            REP(j,oya[i].size()){
                int v=oya[i][j];
                if(rev[v]>rev[idx]&&rev[v]<rev[i]){
                    idx=v;
                }
            }
            ans[i]=idx+1;
        }

    }
    REP(i,N) cout<<ans[i]<<endl;

    


}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	cout << abs(a[0] - a[1]) + abs(a[1] - a[2]) << endl;
}


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

enum {
  I = 1,
  V = 5,
  X = 10,
  L = 50,
  C = 100,
  D = 500,
  M = 1000
};

int main(void) {
  string Rome;
  int sum;
  
  while(cin >> Rome) {
    sum = 0;
    
    if(Rome.size() == 1) {
      switch(Rome[0]) {
        case 'I' : sum = I;   break;
        case 'V' : sum = V;   break;
        case 'X' : sum = X;   break;
        case 'L' : sum = L;   break;
        case 'C' : sum = C;   break;
        case 'D' : sum = D;   break;
        case 'M' : sum = M;   break;
      }
    } else {
      for(int i = 0; i < Rome.size() - 1; ++i) {
        switch(Rome[i]) {
          case 'I' : {
            if(Rome[i + 1] == 'I') {
              sum += I;
            } else {
              sum -= I;
            }
            break;
          }
          case 'V' :  {
            if(Rome[i + 1] == 'I' || Rome[i + 1] == 'R') {
              sum += V;
            } else {
              sum -= V;
            }
            break;
          }
          case 'X' : {
            if(Rome[i + 1] == 'I' || Rome[i + 1] == 'V' || Rome[i + 1] == 'X') {
              sum += X;
            } else {
              sum -= X;
            }
            break;
          }
          case 'L' : {
            if(Rome[i + 1] != 'C' && Rome[i + 1] != 'D' && Rome[i + 1] != 'M') {
              sum += L;
            } else {
              sum -= L;
            }
            break;
          }
          case 'C' : {
            if(Rome[i + 1] != 'D' && Rome[i + 1] != 'M') {
              sum += C;
            } else {
              sum -= C;
            }
            break;
          }
          case 'D' : {
            if(Rome[i + 1] != 'M') {
              sum += D;
            } else {
              sum -= C;
            }break;
          }
          case 'M' : {
            sum += M;
            break;
          }
        }
      }
      switch(Rome[Rome.size() - 1]) {
        case 'I' : sum += I;   break;
        case 'V' : sum += V;   break;
        case 'X' : sum += X;   break;
        case 'L' : sum += L;   break;
        case 'C' : sum += C;   break;
        case 'D' : sum += D;   break;
        case 'M' : sum += M;   break;
      }
    }
    
    cout << sum << endl;
  }
  return 0;
}


Measured memory_bytes: 3132
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

int main() {
	ll n, m; cin >> n >> m;
	ll ans = 0;
	if (m >= 2 * n) {
		ans += n;
		m -= 2 * n;
		ans += m / 4;
	}
	else {
		ans += m / 2;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 100005
#define mp make_pair
//#define ivorysi
using namespace std;
typedef long long int64;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 + c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) out(x / 10);
    putchar('0' + x % 10);
}
int N,M;
int g[705][705];
struct node {
    int to,next;
}E[1000005];
int sumE,head[705],tot,col[705],que[705],qr;
pii conn[705];
bool f[2][705];
void add(int u,int v) {
    E[++sumE].next = head[u];
    E[sumE].to = v;
    head[u] = sumE;
}
bool dfs(int u) {
    if(col[u] == -1) col[u] = 0;
    que[++qr] = u;
    for(int i = head[u] ; i ; i = E[i].next) {
	int v = E[i].to;
	if(col[v] == col[u]) return false;
	else if(col[v] == -1) {
	    col[v] = col[u] ^ 1;
	    if(!dfs(v)) return false;
	}
    }
    return true;
}
void Solve() {
    read(N);read(M);
    int u,v;
    for(int i = 1 ; i <= M ; ++i) {
	read(u);read(v);
	g[u][v] = g[v][u] = 1;
    }
    for(int i = 1 ; i <= N ; ++i) {
	for(int j = i + 1 ; j <= N ; ++j) {
	    if(!g[i][j]) {add(i,j);add(j,i);}
	}
    }
    memset(col,-1,sizeof(col));
    for(int i = 1 ; i <= N ; ++i) {
	if(col[i] == -1) {
	    qr = 0;
	    if(!dfs(i)) {puts("-1");return;}
	    int cnt[2] = {0,0};
	    for(int j = 1 ; j <= qr ; ++j) cnt[col[que[j]]]++;
	    conn[++tot] = mp(cnt[0],cnt[1]);
	}
    }
    int cur = 0;
    f[0][0] = 1;
    for(int i = 1 ; i <= tot ; ++i) {
	memset(f[cur ^ 1],0,sizeof(f[cur ^ 1]));
	for(int j = N ; j >= 0 ; --j) {
	    if(j >= conn[i].fi) f[cur ^ 1][j] |= f[cur][j - conn[i].fi];
	    if(j >= conn[i].se) f[cur ^ 1][j] |= f[cur][j - conn[i].se];
	}
	cur ^= 1;
    }
    int ans = N * N;
    for(int i = 0 ; i <= N ; ++i) {
	if(f[cur][i]) {
	    ans = min(i * (i - 1) / 2 + (N - i) * (N - i - 1) / 2,ans);
	}
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}

Measured memory_bytes: 7244
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

	vector<int> a(n);
	vector<int> b(n);

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

	sort(b.rbegin(), b.rend());


	int mxa = -1;
	for (int i = 0; i < n; i++) {
		mxa = max(mxa, a[i]);
	}

	int ans = 0;

	int pos = 0;
	while (h > 0) {
		if (pos<n && mxa < b[pos]) {
			ans++;
			h -= b[pos];
			pos++;
		}
		else {
			ans += (h + mxa - 1) / mxa;
			cout << ans << endl;
			return 0;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
[n, a, b, c, d] = [int(i) for i in input().split()]
s = input()

if ('##' in s[b:d]) or ('##' in s[a:c]):
    print('No')
elif c > d:
    if '...' in s[b - 2:d + 1]:
        print('Yes')
    else:
        print('No') 
else:
    print('Yes')


Measured memory_bytes: 3636
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define pb push_back
#define int long long
 
 
signed main(){
 
    int a,b,c;
    cin>>a>>b>>c;
 
 
    if(a%2==0||b%2==0||c%2==0){
        cout<<0<<endl;
        return 0;
    }
    
    cout<<min(a*b,min(b*c,c*a))<<endl;
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll minn(ll x, ll y){
    if(x<y)
        return x;
    return y;
}
ll n, h[100009],ans[100009],i,k,mint,j;
int main() {
    cin>>n>>k;
    // cout<<n<<k<<endl;
    for(i=0;i<n;i++){
        cin>>h[i];
        // cout<<h[i]<<" ";
    }
    ans[0]=0;ans[1]=abs(h[1]-h[0]);
    // for(int z=0;z<n;z++)
    //     cout<<ans[z]<<" ";
    // cout<<endl;
    for(i=2;i<n;i++){
        mint = 1000000000007;
        for(j=1;j<=k && i-j>=0;j++){
            mint = minn(ans[i-j] + abs(h[i]-h[i-j]), mint);
        }
        ans[i] = mint;
        // cout<<ans[i];
    //     break;
    }
    cout<<ans[n-1];
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long int
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
int main()
{
    FAST();
    ll n,i,j,k,a,b,x,sum,mn=1000000000;
    vector<ll>v;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>k;
        v.push_back(k);
    }
    for(i=1;i<=100;i++)
    {
        sum=0;
        for(j=0;j<n;j++)
        {
            sum+=(v[j]-i)*(v[j]-i);
        }
        mn=min(mn,sum);
    }
    cout<<mn<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long 
#define pb push_back 
#define fr first
#define sc second
#define Rep(i,n) for(int i=0;i<(n);i++)
#define All(v) v.begin(),v.end()
#define Uniq(v) v.erase(unique(All(v)),v.end())
typedef pair<int, int> Pii; 
typedef pair<int, Pii> Pip;
typedef pair<string, int> Psi;
const int INF = (1<<30);
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

int H, W, N;
map<Pii, int> m;

int main()
{
  cin >> H >> W >> N;
  Rep(i, N) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    Rep(j ,3) {
      Rep(k, 3) {
	int ny = a - j, nx = b - k;
	if( ny >= 0 && nx >= 0 && ny < H-2 && nx < W-2 ) m[Pii(ny, nx)]++;
      }
    }
  }

  int ans[10] = {0};
  int cnt = 0;
  for(map<Pii, int>::iterator it = m.begin(); it != m.end(); it++) {
    if( (*it).sc ) {
      ans[(*it).sc]++;
      cnt++;
    }
  }

  ll zero = ((ll)H-2)*((ll)W-2)-(ll)cnt;
  cout <<  zero << endl;
  for(int i=1; i<10; i++) cout << ans[i] << endl;

}

Measured memory_bytes: 56448
#include<stdio.h>
#include<string.h>
#include<math.h>
void fanc(int,int,int);
int a,s[15],d[15],f,g,h;
int main(void)
{
	int flg,i,j;
	f=0;
	scanf("%d",&a);
	flg=0;
	fanc(0,0,1);
	for(i=14;i>=0;i--){
		if(s[i]==-1){
			printf("-");
			flg=1;
		}
		else if(s[i]==1){
			printf("+");
			flg=1;
		}
		else{
			if(flg==1) printf("0");
		}
	}
	printf("\n");
	return 0;
}
void fanc(int z,int x,int c)
{
	int i,j;
	if(z<15){
		if(x==a){
			for(i=0;i<z;i++) s[i]=d[i];
			f=1;
		}
		if(f==0){
			for(i=-1;i<=1;i++){
				d[z]=i;
				fanc(z+1,x+i*c,c*3);
			}
		}
	}
}

Measured memory_bytes: 2684
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<string,ll>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;



int main(){
double R;
    cin >> R;
 cout << fixed << setprecision(20);
 cout<<2*R*3.141592653589793238<<endl;
return 0;
}


Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int(i)=0;i<(n);i++)

int main(){
  int n,mi,ans=0;cin>>n;
  REP(i,n){
    int tmp;
    cin>>tmp;
    if(!i) mi=tmp;
    else mi=min(mi,tmp);
    if(mi==tmp) ans++;
  }

  cout<<ans;
}

Measured memory_bytes: 256
import numpy as np
x = int(input())
result = 1

if x == 1:
    print(result)
else:
    for i in range(2, int(np.sqrt(x) + 1)):
        j = 2
        while True:
            calc = pow(i, j)
            if calc > x:
                break
            result = max([result, calc])
            j += 1
    print(result)

Measured memory_bytes: 12396
N = int(input())
a = int(((8*N+1)**(1/2)+1)/2+0.5)
if a*(a-1) != 2*N:
    print ("No")
    
else:
    m = N * 2 // a
    X = [[m] for i in range(a)]
    print ("Yes")
    print (a)
    k = 0
    for i in range(a-1):
        for j in range(i+1, a):
            k += 1
            X[i].append(k) 
            X[j].append(k) 
    for x in X:
        print (" ".join(map(str, x)))

Measured memory_bytes: 9204
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
int main(){
  string s;
  char ab='a';
  cin>>s;
  map<char,int> ans;
  for(int i=0;i<s.length();++i){
    ++ans[s[i]];
  }
  if(ans.size()==26){
    cout<<"None"<<endl;
    return 0;
  }
  for(int i=0;i<s.length();++i){
    if(ans[ab]==0){
      cout<<ab<<endl;
      return 0;
    }
    ++ab;
  }//*/
}

Measured memory_bytes: 3740
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,K = map(int,readline().split())
R,S,P = map(int,readline().split())
T = read().rstrip().decode('utf-8')

k_to_word = [[] for _ in range(K)]
for i,x in enumerate(T):
    k = i % K
    k_to_word[k].append(x)

def solve(A):
    # 直前と同じ手は出せない、というルール
    r,s,p = 0,0,0 # 直前に出した手 -> 最大スコア
    for x in A:
        if x == 'r':
            r,s,p = max(s,p),max(r,p),max(r,s)+P
        elif x == 's':
            r,s,p = max(s,p)+R,max(r,p),max(r,s)
        elif x == 'p':
            r,s,p = max(s,p),max(r,p)+S,max(r,s)
    return max(r,s,p)

answer = sum(solve(A) for A in k_to_word)
print(answer)

Measured memory_bytes: 13492
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0;i--)
using namespace std;

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  fspcnt = 0;
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}*/


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  int64_t n,c;
  cin >> n >> c;
  vector<vector<int64_t>> d(c,vector<int64_t>(c));
  rep(i,c){
    rep(j,c){
      cin >> d[i][j];
    }
  }
  vector<vector<int64_t>> syukei(3,vector<int64_t>(c));
  rep(i,n){
    rep(j,n){
      int64_t hoge;
      cin >> hoge;
      syukei[(i+j+2)%3][hoge-1]++;
    }
  }
  int64_t miniwakan = 10000000000000000;
  rep(pi,c){
    rep(pj,c){
      rep(pk,c){
        int64_t iwakan = 0;
        if(pi == pj || pj == pk || pk == pi){
          continue;
        }
        rep(i,c){
          iwakan += syukei[0][i]*d[i][pi];
        }
        rep(i,c){
          iwakan += syukei[1][i]*d[i][pj];
        }
        rep(i,c){
          iwakan += syukei[2][i]*d[i][pk];
        }
        //cout << iwakan << endl;
        miniwakan = min(miniwakan,iwakan);
      }
    }
  }
  cout << miniwakan << endl;
        
          
  
      
}

Measured memory_bytes: 256
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
#include "../debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

int main() {
    ll N;
    cin >> N;
    V<ll> D(N);
    for(ll &e : D) cin >> e;
    sort(ALL(D));
    ll mid = N / 2;
    if(D[mid - 1] == D[mid]) cout << 0;
    else cout << D[mid] - D[mid - 1];
    cout << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod 10000000
#define int long long
#define double long double
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n, a[100010], b[100010];
signed main() {
	cin >> n;
	rep(i, n + 1)cin >> a[i];
	rep(i, n)cin >> b[i];
	int ans = 0;
	rep(i, n) {
		if (a[i] <= b[i]) {
			ans += a[i];
			b[i] -= a[i];
			a[i] = 0;
			ans += min(a[i + 1], b[i]);
			a[i + 1] = max((ll)0, a[i + 1] - b[i]);
		}
		else {
			ans += b[i];
			a[i] -= b[i];
			b[i] = 0;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
ans_list = []
z_count = 0
for i in range(5):
    b = int(input())
    c = b%10
    ans_list.append((b,c))
    if c == 0:
        z_count += 1
ans_list.sort(key = lambda x:x[1], reverse = True)
count = 0
ans = 0
for i in range(5-z_count):
    if ans_list[i][1] is not 0:
        ans += (ans_list[i][0] -ans_list[i][1] + 10)
    else:
        ans += ans_list[i][0]
if ans_list[5-z_count-1][1] is not 0:
    ans -=(10-ans_list[5-z_count-1][1])
for i in range(z_count):
    ans += ans_list[5-z_count+ i][0]

print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
#include <string.h>

int NextSundaay(char *a_acS);

int main(void) {
	char acS[4];

	//曜日を表す文字列を入力
	scanf("%s", acS);
	//曜日によって日曜日まで何日あるかを出力
	printf("%d", NextSundaay(acS));

	return 0;
}

/*********
*	入力した曜日において、次の日曜日が何日後か出力する関数
*	*a_acS 入力した曜日の文字列
*/
int NextSundaay(char *a_acS) {
	int cDays = 0;
	if (strcmp(a_acS, "SUN") == 0) {
		cDays = 7;
	}
	else if (strcmp(a_acS, "MON") == 0) {
		cDays = 6;
	}
	else if (strcmp(a_acS, "TUE") == 0) {
		cDays = 5;
	}
	else if (strcmp(a_acS, "WED") == 0) {
		cDays = 4;
	}
	else if (strcmp(a_acS, "THU") == 0) {
		cDays = 3;
	}
	else if (strcmp(a_acS, "FRI") == 0) {
		cDays = 2;
	}
	else if (strcmp(a_acS, "SAT") == 0) {
		cDays = 1;
	}
	return (cDays);
}

Measured memory_bytes: 1732
#include<iostream>

int listen_lineCount();
void listen_path(int &from,int &to);

class Lots
{
private:
	int *start_goal;
	int verLineNum;
public:
	Lots(const int lineCount);
	~Lots();
	
	void draw_line(const int from,const int to);
	void echo_goalNums();
};

//-------------------------main--------------------------------

int main()
{
	int ver_lineCount=listen_lineCount();
	Lots inst_lot=Lots(ver_lineCount);
	
	int hor_lineCount=listen_lineCount();
	
	int from,to;
	for(int roop=0;roop<hor_lineCount;roop++)
	{
		listen_path(from,to);
		inst_lot.draw_line(from,to);
	}
	
	inst_lot.echo_goalNums();
	return 0;
}

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

Lots::Lots(const int lineCount)
{
	verLineNum=lineCount;
	start_goal=new int[lineCount+1];
	
	for(int roop=1;roop<=lineCount;roop++)
	{
		start_goal[roop]=roop;
	}
}

Lots::~Lots()
{
	delete [] start_goal;
}

void Lots::draw_line(const int from,const int to)
{
	int swap=start_goal[from];
	start_goal[from]=start_goal[to];
	start_goal[to]=swap;
}

void Lots::echo_goalNums()
{
	using namespace std;
	
	for(int roop=1;roop<=verLineNum;roop++)
	{
		cout<<start_goal[roop]<<endl;
	}
}


int listen_lineCount()
{
	using namespace std;
	
	int lineCount;
	cin>>lineCount;
	
	return lineCount;
}

void listen_path(int &from,int &to)
{
	using namespace std;
	
	char delim;//カンマ区切り
	
	cin>>from>>delim>>to;
}

Measured memory_bytes: 1196
#include <cstdio>

long long p10[20];
int i,n;
long long s;

inline long long dfs(int x,int y,long long p1,long long p2,long long q1,long long q2)
{
	if (p1<p2)
		return 0;
	if (p1-p2-p10[y-x+1]>=n)
		return 0;
	if (x==y/2+1)
	{
		if (! ((p2+q2)/p10[y-1]))
			return 0;
		if ((p1+q1)-(p2+q2)==n)
			if (y&1)
				return 10;
			else
				return 1;
		else
			return 0;
	}
	bool b=false;
	if (! ((n%p10[x])/p10[x-1]))
		b=true;
	long long t=0;
	if (! b)
		for (int i=0;i<10;i++)
		{
			long long tp1=p1+p10[y-x]*i;
			long long tq2=q2+p10[x-1]*i;
			int j=(tq2+n)%p10[x]/p10[x-1];
			long long tp2=p2+p10[y-x]*j;
			long long tq1=q1+p10[x-1]*j;
			t=t+dfs(x+1,y,tp1,tp2,tq1,tq2);
		}
	else
	{
		for (int i=8;i<10;i++)
		{
			long long tp1=p1+p10[y-x]*i;
			long long tq2=q2+p10[x-1]*i;
			int j=(tq2+n)%p10[x]/p10[x-1];
			long long tp2=p2+p10[y-x]*j;
			long long tq1=q1+p10[x-1]*j;
			t=t+dfs(x+1,y,tp1,tp2,tq1,tq2);
			if (i==8)
				t=t*8;
		}
		int i=0;
		long long tp1=p1+p10[y-x]*i;
		long long tq2=q2+p10[x-1]*i;
		int j=(tq2+n)%p10[x]/p10[x-1];
		long long tp2=p2+p10[y-x]*j;
		long long tq1=q1+p10[x-1]*j;
		t=t+dfs(x+1,y,tp1,tp2,tq1,tq2);
	}
	return t;
}

int main()
{
	p10[0]=1;
	for (i=1;i<=18;i++)
		p10[i]=p10[i-1]*10;
	scanf("%d",&n);
	for (i=2;i<=18;i++)
		s=s+dfs(1,i,0,0,0,0);
	printf("%lld",s);
	return 0;
}

Measured memory_bytes: 128
import java.util.List;
import java.util.Queue;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

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

	public void execute() {
		Scanner sc = new Scanner(System.in);
		final int N = sc.nextInt();
		final int M = sc.nextInt();

		int[] a = new int[M];
		int[] b = new int[M];

		for (int i = 0; i < M; i++) {
			int ai = sc.nextInt();
			int bi = sc.nextInt();
			a[i] = ai;
			b[i] = bi;
		}

		int cnt = 0;
		for (int i = 0; i < M; i++) {
			HashMap<Integer, List<Integer>> graph = new HashMap<>();
			boolean[] visited = new boolean[N];
			int vcnt = 0;
			for (int j = 0; j < M; j++) {
				if (j == i) {
					continue;
				}
				int from = a[j] - 1;
				int to = b[j] - 1;
				if (!graph.containsKey(from)) {
					graph.put(from, new ArrayList<Integer>());
				}
				if (!graph.containsKey(to)) {
					graph.put(to, new ArrayList<Integer>());
				}
				graph.get(from).add(to);
				graph.get(to).add(from);
			}

			Queue<Integer> q = new LinkedList<>();
			q.add(0);
			while (!q.isEmpty()) {
				int node = q.remove();
				if (!visited[node]) {
					visited[node] = true;
					vcnt++;
					if (graph.containsKey(node)) {
						List<Integer> toNodes = graph.get(node);
						for (Integer to : toNodes) {
							q.add(to);
						}
					}
				}
			}
			if (vcnt < N) {
				cnt++;
			}
		}

		System.out.println(cnt);
		sc.close();
	}

}

Measured memory_bytes: 23764
n,m=[int(i) for i in input().split()]
#隣接行列の作成
rinsetsu=[[0 for _ in range(n)] for _ in range(n)]
for i in range(m):
    a,b=[int(j) for j in input().split()]
    rinsetsu[a-1][b-1]=1
    rinsetsu[b-1][a-1]=1
visited=[False]*n
ans=0
flag=True
#隣接している島が1つ→訪問済みにしその隣接を隣接行列から削除
#繰り返していくと連結(ループ)だけが残る
while flag:
    flag=False
    for i in range(n):
        if not visited[i] and sum(rinsetsu[i])==1:
            visited[i]=True
            ans+=1
            flag=True
            for j in range(n):
                if rinsetsu[i][j]==1:
                    rinsetsu[j][i]=0
print(ans)

Measured memory_bytes: 3064
H,W = map(int,input().split())

ODD = []
PAIR = [] #出力リスト
BACK = [0,0]
for i in range(H):
    A = list(map(int,input().split()))
    RangeW = range(W)
    if i%2==1: RangeW = RangeW[::-1]
    for j in RangeW:
        if A[j]%2==1:
            if ODD: #空じゃない
                ODD.pop()
                PAIR.append(BACK+[i+1,j+1])
            else:
                ODD.append([i+1,j+1])
        else:
            if ODD:
                PAIR.append(BACK+[i+1,j+1])
        BACK = [i+1,j+1]

print(len(PAIR))
for p in PAIR:
    print(" ".join([str(s) for s in p]))

Measured memory_bytes: 27972
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

int main() {
	long long H, W;
	cin >> H >> W;
	if (H == 1 || W == 1) cout << "1" << endl;
	else cout << (H * W + 1LL) / 2LL << endl;
	return 0;
}

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

using namespace std;

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair
#define fi first
#define se second

typedef long long lli;
typedef pair<int, int> ii;
typedef pair<lli, lli> ll;

lli pref[100005], urutan[100005];

int main() {
	lli n, x, m, value, cycle, ans, hasil, sisa;
	scanf("%lld %lld %lld", &n, &x, &m);
	memset(urutan, 0, sizeof urutan);
	pref[0] = 0;
	for (lli i = 1; i <= n; i++) {
		if (urutan[x] < 1) {
			urutan[x] = i;
			pref[i] = pref[i - 1] + x;
			x = (x * x) % m;
		}
		else {
			cycle = i - urutan[x];
			ans = pref[urutan[x] - 1];
			value = pref[i - 1] - ans;
			n -= (urutan[x] - 1);
			hasil = n / cycle;
			sisa = n % cycle;
			ans += (hasil * value);
			ans += (pref[urutan[x] + sisa - 1] - pref[urutan[x] - 1]);
			printf("%lld\n", ans);
			return 0;
		}
	}
	printf("%lld\n", pref[n]);
	return 0;
}

Measured memory_bytes: 4880
import heapq
import sys
input = sys.stdin.readline


def _heappush_max(heap, item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap)-1)


def _heappop_max(heap):
    """Maxheap version of a heappop."""
    lastelt = heap.pop()    # raises appropriate IndexError if heap is empty
    if heap:
        returnitem = heap[0]
        heap[0] = lastelt
        heapq._siftup_max(heap, 0)
        return returnitem
    return lastelt


def main():
    n, m = map(int, input().split())

    if n == 1:
        a = int(input())
        for i in range(m):
            a //= 2
        print(a)
        exit()

    a = (list(map(int, input().split())))
    heapq._heapify_max(a)

    for i in range(m):
        tmp = _heappop_max(a) // 2
        _heappush_max(a, tmp)

    print(sum(a))


if __name__ == '__main__':
    main()


Measured memory_bytes: 14380
# import sys
# input = sys.stdin.readline
import itertools
import collections
from decimal import Decimal
from functools import reduce
import heapq

def main():
    n = int(input())
    a = input_list()
    aa = a + a
    aa.sort(reverse=True)
    ans = 0
    for i in range(1, n):
        ans += aa[i]
    print(ans)


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


def bfs(H, W, black_cells, dist):
    d = 0
    while black_cells:
        h, w = black_cells.popleft()
        d = dist[h][w]
        for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
            new_h = h + dy
            new_w = w + dx
            if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:
                continue
            if dist[new_h][new_w] == -1:
                dist[new_h][new_w] = d + 1
                black_cells.append((new_h, new_w))
    return d


def input_list():
    return list(map(int, input().split()))


def input_list_str():
    return list(map(str, input().split()))


if __name__ == "__main__":
    main()


Measured memory_bytes: 107848
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=max(x,a)
#define chmin(x,a) x=min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
using Edge=pair<int,ll>;
using Graph=vector<vector<int> >;//ll or Edge
using Edge=pair<int,ll>;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// sort_reverse...greater<ll>()
// g++ -o a a.cpp -Wall -lm -std=c++17

int main(){
    ll n;cin>>n;
    VI l(n);rep(i,n)cin>>l[i];
    sort(ALL(l));
    ll ans=0;
    rep(i,n){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                if(l[i]+l[j]>l[k] && l[i]!=l[k] && l[k]!=l[j] && l[j]!=l[i])ans++;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3628
/* ****TCIITB**** */

#include<bits/stdc++.h>
#define io          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

// #define N  100005
ll n,p;
ll ans;

  

int main()
{
	
	io

	
	cin>>n>>p;
	if(n==1 || p==1)
	{
		cout<<p<<endl;
		exit(0);
	}
	std::map<ll,ll> c;
	rep(i,1,sqrt(p)+1)
	{
		if(!(p%i))
		{
			c[i]++;
			if((p/i)!=i)
			{
				c[p/i]++;
			}
		}

	}
	for(auto i:c)
	{
		ll z=i.F;
		ll cnt=0;
		ll zz=p;
		if(z==1)
			continue;
		while(zz>1)
		{
			if(!(zz%z))
			{
				zz/=z;

				cnt++;
			}
			else
				break;
		}
		if(cnt>=n)
			ans=z;
	}
	cout<<max(1ll,ans);

}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define INF 1000000000
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));

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

	int N;
	cin>>N;
	set<int>ans;
	REP(i,N){
		int a;
		cin>>a;
		ans.insert(a);
	}
	cout<<ans.size()<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<functional>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <string.h>
#include <string>
#include <math.h>
#include <time.h>
#include <vector>
#include <queue>
#include<stack>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
const int M = 1000000007;
int n;
vector<vector<int>> g;
int dp[100005][2];
int calc(int idx, bool prev, int parent) {
	if (g[idx].size() == 1 && parent != -1)
		return 1;
	int &ret = dp[idx][prev];
	if (ret != -1)
		return ret;
	ret = 1;
	for (int i = 0; i < g[idx].size(); ++i) {
		if (g[idx][i] == parent)
			continue;
		if (prev)
			ret = 1LL * ret * calc(g[idx][i], !prev, idx) % M;
		else
			ret = 1LL * ret * (calc(g[idx][i], !prev, idx) + calc(g[idx][i], prev, idx)) % M;
	}
	return ret;
}
int main() {
	//freopen("src.txt", "r", stdin);
	memset(dp, -1, sizeof dp);
	cin >> n;
	g.resize(n);
	for (int i = 0; i < n - 1; ++i) {
		int u, v;
		scanf("%d%d", &u, &v);
		--u; --v;
		g[u].push_back(v);
		swap(u, v);
		g[u].push_back(v);
	}
	cout << (calc(0, true, -1) + calc(0, false, -1)) % M;
	return 0;
}

Measured memory_bytes: 14848
# coding: utf-8
# Your code here!
bef = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
aft = "DEFGHIJKLMNOPQRSTUVWXYZABC"

s = list(input())
for i in range(len(s)):
   for j in range(len(aft)):
      if s[i] == aft[j]:
         #print("@", aft[j], bef[j])
         s[i] = bef[j]
         print(s[i], end = "")
         break
print("")


Measured memory_bytes: 5720
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			double velocity = sc.nextDouble();
			double t = velocity / 9.8;
			double y = 4.9 *  Math.pow(t, 2);
			double N = (y + 5) / 5;
			int ans = (int)N;
			if(ans < N) System.out.println(ans + 1);
			else System.out.println(ans);

		}
	}
}

Measured memory_bytes: 27384
// LightOj Pass : qavajxyq

#include <bits/stdc++.h>
#define deb(x)     cerr << (#x) << " : " << x << "\n"
#define ll long long int
#define ld long double
using namespace std;
const ll MOD = 1e9 + 7 ;
const ll INF = 1e18;

ll powmod(ll a, ll b, ll mod = MOD){
	ll res = 1ll;
	b %= (mod - 1ll), a %= mod;
	while(b){
		if(b%2 == 1)	res = (res * a) % mod;
		a = (a * a) % mod;
		b /= 2;
	}
	return res;
}

int main(){	

 
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	int n, m;
	cin >> n >> m;
	ll dp[n+1][m+1];
	string arr[n];

	for(int i = 0; i < n; i++)	cin >> arr[i];
	memset(dp, -1, sizeof(dp));

	dp[0][0] = arr[0][0] == '#';
	int cnt;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			if(!i and !j)	continue;
			dp[i][j] = INF;
			if(j)	{
				if(arr[i][j-1] == '.' and arr[i][j] == '#')	cnt = 1;
				else	cnt = 0;

				dp[i][j] = min(dp[i][j], dp[i][j-1] + cnt);
			}
			if(i)	{
				if(arr[i-1][j] == '.' and arr[i][j] == '#')	cnt = 1;
				else	cnt = 0;

				dp[i][j] = min(dp[i][j], dp[i-1][j] + cnt);
			}
		}
	}

	cout << dp[n-1][m-1];
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#define endl '\n'
using namespace std;
int main()
{
    int A,B;
    cin>>A>>B;
    int cnt = 0, socket = 1;
    while(socket<B)
    {
        socket--;
        socket += A;
        cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define mod 1000000007 
#define rep(i,j,l) for(int i=j;i<=l;i++)
#define dec(i,j,l) for(int i=j;i>=l;i--)
#define input(a,n) rep(i,0,n-1)cin>>a[i]
using namespace std;
typedef long long ll;
typedef unsigned long long ull; 
/* int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1}; */ // 4 Direction
/* int dx[] = {1,-1,0,0,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1,1,-1}; */ // 8 Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; */ // Knight Direction
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; */ // Hexagonal Direction


int main()
{  ios_base::sync_with_stdio(0); 
   cin.tie(NULL);
   int t,n,i,q,x,mn,k;
   cin>>n>>k;
   int a[n]; 
   input(a,n);
   int cost[n];
   cost[0]=0;
   cost[1]=abs(a[0]-a[1]);
   rep(i,2,n-1) 
    { mn=INT_MAX;
        dec(j,i-1,i-min(k,i))  
         { mn=min(mn,abs(a[i]-a[j])+cost[j]);  
         
             //cout<<j<<' ';
         }
      cost[i]=mn; //cout<<'\n';
    }
   cout<<cost[n-1];
   return 0;            
}


Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
  int n,x;
  int i,j,r;
  while(1)
    {
      scanf("%d%d",&n,&x);
      if((n==0)&&(x==0)) break;
      r=0;
      for(i=1;i<=n;i++)
	{
	  for(j=i+1;j<=n;j++)
	    {
	      if((x-(i+j)<=n)&&(x-(i+j)>j)) r++;
	    }
	}
      printf("%d\n",r);
    }
  return 0;
}

Measured memory_bytes: 600