akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(1); 
const ll mod=998244353;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=101000;
#define kill assss
int n,m,a[N],kill[N];
ll k,rm,ans;
int main() {
	scanf("%d%d%lld",&n,&m,&k);
	rep(i,0,n) scanf("%d",a+i);
	sort(a,a+n);
	rep(i,0,n) rm+=a[i];
	rep(i,0,n) {
		if (rm<=m) break;
		if (rm-a[i]>m) kill[i]=a[i];
		else {
			int l=a[i],r=m-(rm-a[i]);
			kill[i]=l-r;
		}
		rm-=a[i];
	}

	int l=-1,r=m;
	while (l+1<r) {
		int md=(l+r)>>1;
		ll s=0;
		rep(i,0,n) s+=min(max(a[i]-md,0),kill[i]);
		if (s<=k) r=md; else l=md;
	}
	rep(i,0,n) {
		int d=min(max(a[i]-r,0),kill[i]);
		k-=d;
		a[i]-=d;
		kill[i]-=d;
	}
	rep(i,0,n) if (k&&a[i]==r&&kill[i]) --k,--a[i],--kill[i];
	/*rep(i,0,n) printf("%d ",a[i]); 
	puts("");*/
	sort(a,a+n);
	rm=0;
	rep(i,0,n) rm+=a[i];
	rep(i,0,n) {
		if (rm<=m) break;
		if (rm-a[i]>m) ans+=(ll)a[i]*(a[i]+1)/2;
		else {
			int l=a[i],r=m-(rm-a[i])+1;
		//	printf("%d %d\n",l,r);
			ans+=(ll)(l+r)*(l-r+1)/2;
		}
		rm-=a[i];
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 4040
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int W = Integer.parseInt(sc.next());
        String[][] map = new String[N][W];
        int[] gyo = new int[N];
        int[] retu = new int[W];
        for(int i=0; i<N; i++) {
            String S = sc.next();
            map[i] = S.split("");
            for(int j=0; j<W; j++) {
                if(map[i][j].equals("#")) {
                    gyo[i] = 1;
                    retu[j] = 1;
                }
            }
        }
        
        for(int i=0; i<N; i++) {
            if(gyo[i] == 0) continue;
            for(int j=0; j<W; j++) {
                if(retu[j] == 0) continue;
                System.out.print(map[i][j]);
            }
            System.out.println("");
        }

    }
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    int odp = 1e9;
    for (int i = -100; i <= 100; ++i)
    {
        int k = 0;
        for (int j = 0; j < n; ++j)
            k += (a[j] - i) * (a[j] - i);
        odp = min(odp, k);
    }
    cout << odp;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>
int main(void) {
	
	char A[11], B[11], C[11];
	scanf("%s%s%s", &A, &B, &C);
	int a = strlen(A);
	int b = strlen(B);
	int c = strlen(C);
	if (A[a - 1] == B[0] && B[b - 1] == C[0]) {
		printf("YES");
	}
	else {
		printf("NO");
	}

	return 0;

}

Measured memory_bytes: 128
N,M,X = map(int,input().split())
A = list(map(int,input().split()))
number1 = 0
number2 = 0

for i in range(M):
    if X > A[i]:
        number1 += 1
    else:
        number2 += 1

if number1 > number2:
    print(number2)
else:
    print(number1)


Measured memory_bytes: 3060
fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val (a, b) = readLine()!!.split(" ").map{ it.toInt() }
    val pp = readLine()!!.split(" ").map{ it.toInt() }

    val first = pp.count { it <= a }
    val second = pp.count { it in (a + 1)..b }
    val third = pp.count { it > b }

    println(Math.min(Math.min(first, second), third))
}

Measured memory_bytes: 37920
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(){
    string s1;
    string s2;
    cin>>s1;
    cin>>s2;

    int l=s1.length();
    int m=s2.length();

    vector<vector<int>> Table(l+1,vector<int>(m+1));

    //初期設定
    for(int i=0;i<l+1;i++){
        Table[i][0]=i;
    }
    for(int j=0;j<m+1;j++){
        Table[0][j]=j;
    }

    //Table作成
    for(int i=1;i<l+1;i++){
        for(int j=1;j<m+1;j++){
            int value=min(Table[i-1][j],Table[i][j-1])+1;
            int cost;
            if(s1[i-1]==s2[j-1]){
                cost=0;
            }else{
                cost=1;
            }

            Table[i][j]=min(value,Table[i-1][j-1]+cost);
        }
    }

    //表示
    // for(int i=0;i<l+1;i++){
    //     for(int j=0;j<m+1;j++){
    //         cout<<Table[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }

    cout<<Table[l][m]<<endl;

    return 0;
}


Measured memory_bytes: 6880
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
#define endl '\n'
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

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

    int r,d,x; cin>>r>>d>>x;
    rep(i,10){
        x=r*x-d;
        cout<<x<<endl;
    }
}

Measured memory_bytes: 764
X = int(input())

X1 = X % 100

counter = 0
minusV = 5
while(X1 != 0):
    if(X1 - minusV >= 0):
        X1 = X1 - minusV
        counter += 1
    else:
        minusV -= 1

if(counter*100 <= X):
    print('1')
else:
    print('0')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  string S;
  cin >> S;
  int ans = 7;
  //if(S == "SUN") ans = 7;
  if(S == "MON") ans = 6;
  else if(S=="TUE") ans = 5;
  else if(S=="WED") ans = 4;
  else if(S == "THU") ans = 3;
  else if(S=="FRI") ans = 2;
  else if(S=="SAT") ans = 1;
  
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n;
		long odd[], even[];
		int oid, eid;

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

			even = new long[n];
			odd = new long[n*(n+1)/2 - n];
			oid = eid = 0;
			for (int i = 0; i < n*(n+1)/2; i++) {
				long k = sc.nextLong();
				if (k % 2 == 0) {
					even[eid++] = k;
				} else {
					odd[oid++] = k;
				}
			}
			Arrays.sort(odd);
			Arrays.sort(even);
			
			BigInteger e0 = new BigInteger(Long.toString(even[0]));
			BigInteger e1 = new BigInteger(Long.toString(even[1]));
			BigInteger o0 = new BigInteger(Long.toString(odd[0]));
			BigInteger e2 = (e0.multiply(e1)).divide(o0);
			long e = (long)Math.sqrt(e2.longValue());
			System.out.println(e);
			String s = "";
			for (int i = 0; i < n; i++) {
				System.out.print(s + even[i] / e);
				s = " ";
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 159056
/* به نام یزدان */
#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 21 + 3, MAX_MSK = (1 << 21) + 3, MOD = 1e9 + 7;
int n, adj[MAX_N], dp[MAX_N][MAX_MSK];

void read_input() {
	cin >> n;
	for (int i = 1; i <= n; i++)
		for (int j = 0; j < n; j++) {
			bool b;
			cin >> b;
			adj[i] |= (b & 1) << j;
		}
}

void solve() {
	dp[0][0] = 1;
	for (int msk = 0; msk < 1 << n; msk++) {
		int i = __builtin_popcount(msk);
		for (int j = 0; j < n; j++)
			if (msk >> j & 1 && adj[i] >> j & 1)
				(dp[i][msk] += dp[i - 1][msk ^ 1 << j]) %= MOD;
	}
}

void print_output() {
	cout << dp[n][(1 << n) - 1];
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	read_input();
	solve();
	print_output();
}


Measured memory_bytes: 164096
N = int(input())
S = list(input())
S.insert(0,0)
# b = S.count("#")
w = S.count(".")
black = 0
white = w
ans = 2e5
for i in range(N+1):
    if S[i] == "#":
        black += 1
    elif S[i] == ".":
        white -= 1
    # print(black,white)
    ans = min(black + white, ans)
print(ans)

Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
using vpii=vector<pair<int,int>>;
using vi=vector<int>; 
int main() {
  int n,m,s,t;
  cin>>n>>m;
  if(n==1){s=0;} else{s=n*(n-1)/2;}
  if(m==1){t=0;} else{t=m*(m-1)/2;}
  cout<<s+t<<endl;
}

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

using namespace std;

const int INF = 1e9;
const int N = 1e5;
const int MOD = 998244353;

const double PI = acos(-1);



int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    if ((a[0] == a[1] && a[0] != a[2]) || (a[1] == a[2] && a[0] != a[1]))
        cout << "Yes";
    else
        cout << "No";
}

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

total_rain = sum(ai)
rain_x1 = 0   # tatal rain except last one
for r in ai[1:-1:2]: # A1 contains sum of Mn and M1, so start from A2->ai[1]
    rain_x1 += r
    
# print(total_rain, rain_x1)
rain_mn = total_rain - rain_x1*2

rain_mx = list()
prev = rain_mn

for r in ai:
    rain_mx.append(prev)
    prev = r*2-prev

print(' '.join(map(str, rain_mx)))

Measured memory_bytes: 19144
using System;
//using System.Collections.Generic;
//using System.IO;
using System.Linq;
//using System.Text;
using static System.Console;
using static LibraryForAtCoder.Lib;
using static System.Math;

namespace LibraryForAtCoder
{
  static class Lib
  {
    public static long ReadL => long.Parse(ReadS);
    public static string ReadS => ReadLine().Trim();

    public static long[] ReadLs => ReadSs.Select(long.Parse).ToArray();
    public static string[] ReadSs => ReadS.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  }

  static class Program
  {
    static void Main()
    {
      //while (true)
        Body();
    }
    static void Body()
    {
      var arr = ReadLs;
      var n = arr[0];
      var a = arr[1];
      var b = arr[2];
      var x = b - a;
      long ans;
      if (x % 2 == 0) ans = x / 2;
      else ans = Min(a - 1, n - b) + (x + 1) / 2;
      WriteLine(ans);
    }
  }
}


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

int main() {
  
  int k,a,b;
  cin >> k >> a >>b;
  
  for ( int i = a; i <= b; i++){
    if ( i % k == 0 ){
      cout << "OK" << endl;
      return 0;
    }
  }
  
  cout << "NG" << endl;
  
  
}


Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(0)
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
typedef long long ll;
#define pri(n) printf("%d\n",n)
#define lpri(n) printf("%lld\n",n);
#define rep(i,st,ed) for(int i=st;i<ed;i++)
#define var(n) int n; scn(n)
#define F first
#define S second 
#define pb push_back
const int N=3000000;
const ll M=1e9+7;
const ll inf=1e18;

ll temp[N],cal[N];


int main()
{
	var(n);
	int a[n][n];
	int m = 1<<n;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			scn(a[i][j]);
		}
	}
	for(int i=0;i<n;i++)
	{
		if(a[0][i]==1)
			temp[(1<<i)] = 1;
	}
	for(int i=1;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(a[i][j]==1)
			{
				int val = 1<<j;
				for(int k=1;k<m;k++)
				{
					if((val&k) == 0 and (val|k) < m)
					{
						cal[(val|k)] = (cal[(val|k)] + temp[k])%M;
					}
				}
			}
		}
		for(int j = 0;j<m;j++)
		{
			temp[j] = cal[j];
			cal[j] = 0;
		}
	}
	lpri(temp[m-1]);
}

Measured memory_bytes: 37120
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class QuestionB
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力
            //string s = Console.ReadLine();

            // 整数の入力
            ulong X = ulong.Parse(Console.ReadLine());

            // 文字列配列の入力
            //string[] inputStrArray = Console.ReadLine().Split(' ');

            // 整数配列の入力
            //var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            ulong year;
            ulong cash = 100;
            
            for (year = 0; cash<X;year++)
            {
                cash = cash+ (cash)/100;
                //Console.WriteLine(cash);
            }


            Console.WriteLine(year);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 27532
#include <iostream>
#include <algorithm>
#include <vector> //動的配列
#include <string>
#include <list> //双方向リスト
#include <map> //連想配列
#include <set> //集合
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <bitset>
#include <numeric>
#include <tuple>



typedef long long ll;


using namespace std;

typedef pair<int, int> P;
#define FOR(i,a,b) for(int i=(int)(a) ; i < (int) (b) ; ++i )
#define rep(i,n) FOR(i,0,n)
#define sz(x) int(x.size())

int n, m, q;
vector<vector<int>> v; 

void dfs (vector<int> a, int* ans) {
    if (a.size() == n+1){
        int score = 0;
        rep(i,q){
            if (a[v[i][1]] - a[v[i][0]] == v[i][2]) score += v[i][3];
        }
        *ans = max(*ans, score);
        return ;
    }

    a.push_back(*a.rbegin());
    while (*a.rbegin() <= m) {
        dfs(a, ans);
        (*a.rbegin())++;
    }

}



int main(){
    cin >> n>> m >> q;
    v.resize(q, vector<int> (4,0));
    rep (i,q) {
        cin >> v[i][0] >> v[i][1] >> v[i][2] >> v[i][3];
    }
    vector<int> comb(1,1);

    int ans = 0;
    dfs(comb, &ans);

    cout << ans;
    return 0;
}

Measured memory_bytes: 3612
# C - Train Ticket
ABCD = input()

for i in range(8):
	binary = format(i, 'b').zfill(3)
	sum = int(ABCD[0])
	ans = ABCD[0]
	
	for j in range(3):
		s = ABCD[j + 1]
		
		if binary[j] == '1':
			sum += int(s)
			ans += '+' + s
		else:
			sum -= int(s)
			ans += '-' + s
	
	if sum == 7:
		ans += '=7'
		print(ans)
		break

Measured memory_bytes: 9196
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=200005;
//i_am_noob
string str;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> str;
	rep(sz(str)) cout << "x";
	cout << '\n';
	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
LRs = [tuple(map(int, input().split())) for _ in range(K)]
mod = 998244353

def diff(l):
    tmp = None
    res = []
    for elm in l:
        if tmp is None:
            res.append(elm)
            tmp = elm
        else:
            res.append(elm-tmp)
            tmp = elm

    return res

res_diff = [0] * N
res_diff[1] = -1
res = [1]

for i in range(N-1):
    for l, r in LRs:
        if i+l < N:
            res_diff[i+l] += res[i]
        if i+r+1 < N:
            res_diff[i+r+1] -= res[i]
    
    res_next = (res[-1]+res_diff[i+1])%mod
    res.append(res_next)

print(res[N-1])

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

int main(){
  int x,y,z;
  cin >> x >> y >> z;
  swap(x,y);
  swap(x,z);
  cout << x << " " << y << " " << z;
  return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<long long> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    sort(a.begin(), a.end());
    vector<long long> b(a.size());
    partial_sum(a.begin(), a.end(), b.begin());

    int ans = 1;
    for (int i = N - 1; i >= 1; i--) {
        if(i==1&&a[i]==a[i+1]){
            ans++;
        }else if (b[i - 1] * 2 >= a[i]) {
            ans++;
        }else
            break;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main( void ) {
	int i, ch, count[ 4 ] = {}, min;

	while ( ch = getchar(), ch != EOF )
		switch ( ch ) {
			case 'K': count[ 0 ]++; break;
			case 'U': count[ 1 ]++; break;
			case 'P': count[ 2 ]++; break;
			case 'C': count[ 3 ]++; break;
		}

	min = count[ 3 ];
	for ( i = 3; i--;  )
		if ( count[ i ] < min )
			min = count[ i ];

	printf( "%d\n", min );

	return 0;
}

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

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

	(void)scanf("%d %d %d",&N,&M,&C);
	(void)getchar();

	int *B;
	B = (int *)malloc(sizeof(int) *M);
	for ( int j = 0; j < M; j++) {
		(void)scanf("%d",&B[j]);
	}

	int *A;
	A = (int *)malloc(sizeof(int) * M * N);
	for ( int i = 0; i < N; i++ ) {
		for ( int j = 0; j < M; j++ ) {
			(void)scanf("%d",&A[ i * M + j ]);
		}
	}

	int sum, count = 0;
	for ( int i = 0; i < N; i++ ) {
		sum = 0;
		for ( int j = 0; j < M; j++ ) {
			sum += A[ i * M + j ] * B[j];
		}
		if ( sum + C > 0 ) count++;
	}

	printf("%d\n",count);
	free(A);
	free(B);
	return 0;
}

Measured memory_bytes: 128
n=int(input())
lst=list(map(int,input().split()))
ans=max(lst)
for i in range(ans):
    for j in range(1,n-1):
        if lst[j]==0 and lst[j-1]!=0:
            ans+=1
    if lst[-1]==0 and lst[-2]==0:
        ans-=1
    for j in range(n):
        if lst[j]!=0:
            lst[j]-=1
print(ans)

Measured memory_bytes: 67132
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

using namespace std;
typedef long long ll;

template <typename T>
struct bit{
    int n;
    vector<T> data;

    bit(int n_){
        n = 1;
        while(n < n_) n *= 2;
        data = vector<T>(n+1);
        for(int i = 0; i <= n; i++) data[i] = 0;
    }
    
    T sum(int i){
        T ret = 0;
        while(i > 0){
            ret += data[i];
            i -= i&-i;
        }
        return ret;
    }

    void add(int i, T x){
        while(i <= n){
            data[i] += x;
            i += i&-i;
        }
    }
};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int N, Q; cin >> N >> Q;
    bit<ll> bt(N);
    for(int i = 1; i <= N; i++){
        ll a; cin >> a;
        bt.add(i, a);
    }    
    for(int i = 0; i < Q; i++){
        int t; cin >> t;
        if(t == 0){
            int p; ll x; cin >> p >> x; p++;
            bt.add(p, x);
        }else{
            int l, r; cin >> l >> r; r;
            cout << bt.sum(r)-bt.sum(l) << endl;
        }
    }
}

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

int main() {
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i, n)
        cin >> a.at(i);
    
    ll min = *min_element(a.begin(), a.end());
    ll max = *max_element(a.begin(), a.end());
    ll sum = accumulate(a.begin(), a.end(), (ll)0);

    cout << min << " " << max << " " << sum << endl;
}



Measured memory_bytes: 3164
#include <stdio.h>
#include <iostream>
#include <sstream>

int main() {
    char ch;
    int sum = 0;
    std::stringstream ss;
    while ((ch = getchar()) != EOF) {
        if (ch == '\n') {
            if (sum == 0) break;
            else {
                ss << sum << std::endl;
                sum = 0;
            }
        } else {
            sum += ((int)ch - 48);
        }
    }
    std::cout << ss.str();
    
    return 0;
}


Measured memory_bytes: 3140
#include <iostream>

using namespace std;

int main() {
    int a, b;
    int N;
    cin >> a >> b >> N;

    int schedule[b + 1];
    fill(schedule, schedule + b + 1, 0);

    for (int i = 0; i < N; ++i) {
        int s, f;
        cin >> s >> f;

        if (s <= b) schedule[s]++;
        if (f <= b) schedule[f]--;
    }

    for (int j = 0; j < b + 1; ++j) {
        int f = (j > 0 ? schedule[j - 1] : 0);
        schedule[j] += f;
    }

    for (int i = a; i < b; ++i) {
        if (schedule[i] > 0) {
            cout << 1 << endl;
            return 0;
        }
    }

    cout << 0 << endl;
}


Measured memory_bytes: 3092
#include<iostream>

using namespace std;

int mid(int a,int b,int c)
{
	if(a >= b)
	{
		if(c >= a)
		{
			return a;
		}

		if(b >= c)
		{
			return b;
		}
		else
		{
			return c;
		}
	}
	else
	{
		if(c >= b)
		{
			return b;
		}

		if(a >= c)
		{
			return a;
		}
		else
		{
			return c;
		}
	}
}

int main()
{
	int A,B,C;
	int ans = 0;

	cin >> A >> B >> C;

	if(A%2 == B%2 && B%2!= C%2)
	{
		A++;
		B++;
		ans++;
	}
	else if(B%2 == C%2 && C%2 != A%2)
	{
		B++;
		C++;
		ans++;
	}
	else if(C%2 == A%2 && A%2 != B%2)
	{
		A++;
		C++;
		ans++;
	}


	int mx = max(A,max(B,C));
	int md = mid(A,B,C);
	int mn = min(A,min(B,C));

	ans += (md - mn)/2;
	ans += (mx - md);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.lang.*;

class Output extends PrintWriter {

    public Output(PrintStream io) {
        super(io);
    }

    public void printArray(int[] array, String space, String end) {
        int N = array.length;
        for(int n=0; n<N-1; n++){
            super.print(array[n]);
            super.print(space);
        }
        super.print(array[N-1]);
        super.print(end);
        super.flush();
    }
    public void printArray(int[] array){
        this.printArray(array, " ", "\n");
    }
    public void printArray(long[] array, String space, String end) {
        int N = array.length;
        for(int n=0; n<N-1; n++){
            super.print(array[n]);
            super.print(space);
        }
        super.print(array[N-1]);
        super.print(end);
        super.flush();
    }
    public void printArray(long[] array){
        this.printArray(array, " ", "\n");
    }
    public void printArray(double[] array, String space, String end) {
        int N = array.length;
        for(int n=0; n<N-1; n++){
            super.print(array[n]);
            super.print(space);
        }
        super.print(array[N-1]);
        super.print(end);
        super.flush();
    }
    public void printArray(double[] array){
        this.printArray(array, " ", "\n");
    }
    public void printArray(char[] array, String space, String end) {
        int N = array.length;
        for(int n=0; n<N-1; n++){
            super.print(array[n]);
            super.print(space);
        }
        super.print(array[N-1]);
        super.print(end);
        super.flush();
    }
    public void printArray(char[] array){
        this.printArray(array, " ", "\n");
    }
    public void printArray(Object[] array, String space, String end) {
        int N = array.length;
        for(int n=0; n<N-1; n++){
            super.print(array[n]);
            super.print(space);
        }
        super.print(array[N-1]);
        super.print(end);
        super.flush();
    }
    public void printArray(Object[] array){
        this.printArray(array, " ", "\n");
    }

}

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

        int A = sc.nextInt();
        int B = sc.nextInt();

        //solve 1 + (A-1)*X >= B
        for(int x=0; x<100; x++){
            if(1 + (A-1)*x >= B) {
                out.println(x);
                break;
            }
        }

        out.flush();
    }
}


Measured memory_bytes: 23764
#include<stdio.h>

int main(void)

{

   int a_cm=0,b_cm=0,mennseki,x;

   mennseki=a_cm*b_cm;

   scanf("%d %d",&a_cm,&b_cm);

   mennseki=a_cm*b_cm;      printf("%d ",mennseki);

   x=a_cm*2+b_cm*2;

   printf("%d\n",x);

return 0;

}




  

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;
#define inf 0x3f3f3f3f
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mp make_pair
#define pb push_back
#define sz(v) (int)v.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)

typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
const int N=1e5+7;
ll n,m,x,y,k,ans,vis[N],a[N];

int main(){
    fast;
    cin>>n;
    for1(i,n){
        cin>>x;
        a[i]=x;
    }
    for1(i,n){
        if(a[a[i]]==i) ans++;
    }
    cout<<ans/2<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#define int long long
using namespace std;
signed main(){
	int n;
	int ans[10000005]={0};
	int sum=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		for(int j=1;i*j<=n;j++){
			++ans[i*j];
		}
	}
	for(int i=1;i<=n;i++){
		sum+=i*ans[i];
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 81712
#include <algorithm>
#include <queue>
#include <iostream>
#include <vector>
#include <map>
std::vector<int> to[2505];
std::vector<int> ot[2505];
bool reachableToN[2505];
bool reachableFrom1[2505];
bool ok[2505];
long long INF=1LL<<60;

void dfs(int v){
  if(reachableFrom1[v]) return;
  reachableFrom1[v]=true;
  for(int u: to[v]){
    dfs(u);
  }
}

void rdfs(int v){
  if(reachableToN[v]) return;
  reachableToN[v]=true;
  for(int u: ot[v]){
    rdfs(u);
  }
}


int main(){
  int n, m, p;
  std::cin>>n>>m>>p;
  std::vector<std::tuple<int, int, int>> edges;
  
  for(int i=0;i<m;++i){
    int a, b, c;
    std::cin>>a>>b>>c;
    --a;
    --b;
    c-=p;
    c=-c;
    edges.emplace_back(a,b,c);
    to[a].push_back(b);
    ot[b].push_back(a);
  }
  
  dfs(0);
  rdfs(n-1);
  for(int i=0;i<n;++i){
    ok[i]=reachableFrom1[i]&&reachableToN[i];
  }

  std::vector<long long> d(n, INF);
  d[0]=0;
  bool upd=true;
  int step=0;
  while(upd){
    upd=false;
    for(int i=0;i<m;++i){
      int a, b, c;
      std::tie(a,b,c)=edges[i];
      if(!ok[a])continue;
      if(!ok[b])continue;
      long long newD=d[a]+c;
      if(newD<d[b]){
	upd=true;
	d[b]=newD;
      }
    }
    ++step;
    if(step>n){
      std::cout<<-1<<std::endl;
      return 0;
    }
  }
  int ans=-d[n-1];
  ans=std::max(0, ans);
  std::cout<<ans<<std::endl;

  return 0;
}


Measured memory_bytes: 640
#include<iostream>

using namespace std;
int main()
{
  int N;
  cin >> N;
  int d[110];
  for (int i=0; i < N; i++) {
    cin >> d[i];
  }
  int n[110] = {0};
  for (int i=0; i < N; i++) {
    n[d[i]] ++;
  }
  int res = 0;
  for (int i=1; i <= 100; i++) {
    if (n[i]) res++;
  }
  cout << res << endl;
  return 0;
}


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

int main()
{
    int n;
    while(1){
        vector<int>vec;
        int ans=-100000;
        cin>>n;
        vector<int>dp(n);
        if(n==0)break;
        for(int i=0;i<n;i++){
            int a;cin>>a;
            vec.push_back(a);
        }
        dp[0]=vec[0];
        for(int i=1;i<n;i++){
            dp[i]=max(dp[i-1]+vec[i],vec[i]);
        }
        for(int i=0;i<n;i++){
            ans=max(ans,dp[i]);
        }
        cout<<ans<<endl;
    }
    return 0;
}

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

int main(){
    int N;
    int a=0;
    cin >> N;
    for(int i = 1; i <= N; i++) {
        if (i < 10)
            a++;
        else if (i >= 100 && i < 1000)
            a++;
        else if (i >= 10000 && i < 100000)
            a++;
    }

        cout << a << endl;


     return 0;
}

Measured memory_bytes: 256
require 'matrix'

def cross(x1, y1, x2, y2, x3, y3, x4, y4)
  a = Matrix[[x2 - x1, x3 - x4], [y2 - y1, y3 - y4]].lup.solve([x3 - x1, y3 - y1]) rescue nil
  return false unless a
  s, t = a[0], a[1]
  f = ((0 <= s and s <= 1) and (0 <= t and t <= 1))
  f ? Vector[x1 + s * (x2 - x1), y1 + s * (y2 - y1)] : false
end

until (given = $<.gets.split.map(&:to_i)) == [0] * 4
  x, y = [], []
  x[0], y[0], x[1], y[1] = given
  x[2], y[2], x[3], y[3] = $<.gets.split.map(&:to_i)
  x[4], y[4], x[5], y[5] = $<.gets.split.map(&:to_i)
  p1 = cross(x[0], y[0], x[1], y[1], x[2], y[2], x[3], y[3]) 
  p2 = cross(x[2], y[2], x[3], y[3], x[4], y[4], x[5], y[5]) 
  p3 = cross(x[4], y[4], x[5], y[5], x[0], y[0], x[1], y[1])
  str = "kyo"
  if p1 and p2 and p3
    v1 = p2 - p1
    v2 = p3 - p1
    s = Rational((v1[0] * v2[1] - v1[1] * v2[0]).abs, 2)
    if s.nonzero?
      idx = nil
      [Float::INFINITY, 1_900_000, 1_000_000, 100_000, 0].each_cons(2).with_index do |a, i|
        idx = i if a[1] <= s and s < a[0]
      end
      str = %w(dai-kichi chu-kichi kichi syo-kichi)[idx]
    end
  end
  puts str
end



Measured memory_bytes: 7324
nums = map(int, raw_input().split())

for i in range(2):
    for j in range(2-i):
        if nums[j] > nums[j+1]:
            temp      = nums[j]
            nums[j]   = nums[j+1]
            nums[j+1] = temp

print(str(nums[0]) + " " + str(nums[1]) + " " + str(nums[2]))

Measured memory_bytes: 6376
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int n,m,x; cin >>n >>m >>x;
      vector<int> b(n+1);
      for (int i=0; i<m; i++){
        int buf; cin >>buf;
        b.at(buf) = 1;
      }
      
      int cost1=0, cost2=0;
      for (int i=0; i<=n; i++){
        if (i<=x) cost1 += b.at(i);
        else cost2 += b.at(i);
      }
      cout <<min(cost1,cost2) <<endl;
    }

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

int main () {
  int A,B,C;
  cin>>A>>B>>C;
  int max = A;
  if(B>max){ 
    max = B;
  }
  if(C>max){
    max = C;
  }
  cout<<A+B+C-max<<endl;
}

Measured memory_bytes: 256
/*
AUTHOR : Chandan Agrawal
College : Poornima College of Engg. jaipur, Raj
Mail : chandanagrawal23@gmail.com
*/

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define MAX 100050

#define ll long long
#define ld long double
#define lli long long int

#define pb emplace_back
#define INF 1000000000
#define mod 1000000007

// trignometric function always give value in Radians only
#define PI acos(-1) //3.1415926535897932384626433832795028
#define dsin(degree) sin(degree*(PI/180.0))
#define dcos(degree) cos(degree*(PI/180.0))
#define dtan(degree) tan(degree*(PI/180.0))

#define rsin(radian) sin(radian)
#define rcos(radian) cos(radian)
#define rtan(radian) tan(radian)

#define loop(i,n) for (lli i = 0; i < n; i++)
#define loopitr(xt,vec) for (auto xt : vec)
#define FOR(i,a,b) for (lli i = a; i < b; i+=1)
#define loop_rev(i,n) for (lli i = n-1; i >= 0; i--)
#define FOR_REV(i,a,b) for (lli i = a; i >= b; i--)
#define itr :: iterator it
#define WL(t) while(t --)

#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(x) int(x.size())
#define F first
#define S second

#define mii map<lli,lli>
#define vi vector<lli>
#define vbool vector<bool>
#define seti set<lli>
#define pii pair<lli,lli>
#define pcc pair<char , char>

#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) (a/gcd(a,b))*b
#define abs(x) ((x < 0)?-(x):x)

#define endl '\n'

template <typename T>
void print(T x){cout<<x<<endl;}
template <typename T1, typename T2>
void print2(T1 x,T2 y){cout<<x<<" "<<y<<endl;}
template <typename T1, typename T2,typename T3>
void print3(T1 x, T2 y,T3 z){cout<<x<<" "<<y<<" "<<z<<endl;}

#define scanarr(a,n) for(lli i=0;i<n;i++)    cin>>a[i];
#define scanvector(a,n) for(lli i=0;i<n;i++){ lli x ; cin>>x; a.pb(x);}

#define printarr(a,n) for(lli i=0;i<n;i++)   cout<<a[i]<<" "; cout<<endl;
#define printvector(vec) for(auto xt : vec) cout<<xt<<" ";    cout<<"\n";

#define FD(N) fixed<<setprecision(N)

#define deb(x) cout<<#x<<" "<<x<<endl;

// chandan1,2
void chandan1(){int y=1;return;}
void chandan2(){
        loop(i,10){
        lli x=1;
    }
    return(chandan1());
}



int main(){
fastio
lli t=1;
//cin>>t;
chandan2();
while(t--) {
    lli a,b,c,k;
    cin>>a>>b>>c>>k;
    while(c<=b and k!=0){
        c*=2;
        k--;
    }
    
    while(b<=a and k!=0){
        b*=2;
        k--;
    }
    
    while(c<=b and k!=0){
        c*=2;
        k--;
    }
    
     while(b<=a and k!=0){
        b*=2;
        k--;
    }
    
    if(c>b and b>a)
        print("Yes");
    else
        print("No");
    
    
  }
return 0;
}


Measured memory_bytes: 3648
x, n = map(int, input().split())
p = list(map(int, input().split()))
xp =x; xm =x
for i in range(n+1):
    if not (xm in p):
        print(xm)
        break
    if not (xp in p):
        print(xp)
        break
    xp += 1
    xm -= 1

Measured memory_bytes: 61868
m,d = map(int,input().split())
t_cnt = 0
for mon in range(1,m+1):
  for dd in range(22,d+1):
      d1 = dd%10
      if d1<2:
          continue
      d10 = (dd - d1)//10
      if d1*d10 == mon:
        t_cnt += 1

print(t_cnt)


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

int N, W;
vector<int> values, weights;

const int MAX_N = 100;
const int MAX_VALUE = 100010;
const int INF = 1000000010;
int dp[MAX_VALUE];

int main()
{
  cin >> N >> W;
  values = vector<int>(N+1);
  weights = vector<int>(N+1);

  for (int i = 0; i < N; i++)
    cin >> values[i] >> weights[i];

  fill(dp, dp+MAX_VALUE, INF);
  dp[0] = 0;
  for (int i = 0; i < N; i++) {
    for (int v = MAX_VALUE-1; v >= 0; v--) {
      int new_v = v+values[i];
      if (new_v < MAX_VALUE)
        dp[new_v] = min(dp[new_v], dp[v] + weights[i]);
    }
  }

  for (int v = MAX_VALUE-1; v >= 0; v--) {
    if (dp[v] <= W) {
      cout << v << endl; 
      break;
    }
  }

  return EXIT_SUCCESS;
}




Measured memory_bytes: 3552
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=200005,p=1000000007;
int read(){
	int f=1,g=0;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int n,m,a[N],ans;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	n=read();m=read();
	for (int i=1;i<=n;i++)a[i]=read();
	sort(a+1,a+n+1);
	for (int i=1;i<n;i++)
	if (a[i]<=m){
		m-=a[i];ans++;
	}
	if (m==a[n]) ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
// In The Name Of God
#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define mp make_pair
#define pb push_back
#define int long long
#define ll long long
#define for2(a,b,c) for(int (a) = (b); (a) < (c); (a)++)
#define setp cout << fixed << setprecision(15)
#define endl "\n"
#define minit(a,b) a = min(a,b)
#define maxit(a,b) a = max(a,b)
#define PII pair<int,int>
#define Vec vector<int>
#define error(x) cerr << #x << " = " << (x) << endl;
#define all(x) (x).begin() , (x).end()

const int maxn = 2e5+100;
int a[maxn];
int b[maxn];

int32_t main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n; cin >> n;
    for2(i,0,n) cin >> a[i] >> b[i];
    bool e = 1;
    int ans = 0;
    int t = 0;
    int sum = 0;
    int mx = -1;
    for2(i,0,n){
        sum += a[i]+b[i];
        if(a[i] != b[i]) e = 0;
        if(a[i] > b[i]){
            if(mx == -1) mx = b[i];
            mx = min(mx,b[i]);
        }
    }
    sum /= 2;
    ans = sum-mx;
    if(e) ans = 0;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 640
#include<cstdio>
#include<string.h>
using namespace std;

int main(){
	long long a,b,k;
	scanf("%lld%lld%lld",&a,&b,&k);
	if(k % 2 == 1){
		for(int i = 1;i <=k + 1;i++){
			if(a % 2 == 1){
				a = a - 1;
				b = b + a / 2;
				a = a - a / 2;
			}
			else if(a % 2 == 0) {
				b = b + a / 2;
				a = a - a / 2;
			}
			if(i == k) break;
			if(b % 2 == 1){
				b = b - 1;
				a = a + b / 2;
				b = b - b / 2;
			}
			else if(b % 2 == 0) {
				a = a + b / 2;
				b = b - b / 2;
			}
			i++;
		}
	}
	if(k % 2 == 0){
		for(int i = 1;i <=k;i++){
			if(a % 2 == 1){
				a = a - 1;
				b = b + a / 2;
				a = a - a / 2;
			}
			else if(a % 2 == 0) {
				b = b + a / 2;
				a = a - a / 2;
			}
			if(b % 2 == 1){
				b = b - 1;
				a = a + b / 2;
				b = b - b / 2;
			}
			else if(b % 2 == 0) {
				a = a + b / 2;
				b = b - b / 2;
			}
			i++;
		}
	}
	printf("%lld %lld\n",a,b);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef unsigned long long ull;
typedef long long ll;
typedef double db;

#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define pi pair<int,int>
#define vi vector<int>
#define pL pair<ll,ll>
#define vL vector<ll>
#define vp vector<pi>
#define vpL vector<pL>

const int MX=200000;
const int inf=1e9;
const ll mod=1e9+7;

vector<int>f[MX], b[MX], v;

int vis[MX], vis3[MX], ans[MX];

void dfs(int x, int p)
{
    vis[x]=1; v.push_back(x);
    for(auto u:f[x])
    {
        if(u==p || vis[u]) continue;
        dfs(u, x);
    }
}

int main()
{
    FasterIO;

    int tc, cs=1, n, m, k;
    cin>>n>>m>>k;
    for(int i=1; i<=m; i++)
    {
        int x, y;
        cin>>x>>y;
        f[x].push_back(y);
        f[y].push_back(x);
    }
    for(int i=1; i<=k; i++)
    {
        int x, y;
        cin>>x>>y;
        b[x].push_back(y);
        b[y].push_back(x);
    }
    ll sm=0;
    for(int i=1; i<=n; i++)
    {
        if(vis[i]==0)
        {
            v.clear();
            dfs(i, 0);
            for(auto x:v) vis3[x]=1;
            for(auto x:v)
            {
                ll cnt=v.size(), cnt1=1+f[x].size();
                for(auto y:b[x])
                {
                    if(vis3[y]) cnt1++;
                }
                ans[x]=cnt-cnt1;
            }
            for(auto x:v) vis3[x]=0;
        }
    }
    for(int i=1; i<=n; i++) cout<<ans[i]<<' ';
    cout<<endl;
    return 0;
}


Measured memory_bytes: 18940
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<=(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<si> vsi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 文字変換　
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned Euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return Euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int digit_sum(int n) {
  int sum=n%10;
  while(n!=0) {
    n/=10;
    sum+=n%10;
  }
  return sum;
}

vpll PrimeFactorization(ll n) {
  vpll res;
  for (ll i=2; i*i<=n; i++) {
    if(n%i!=0) continue;
    ll ex=0;
    while(n%i==0) {
      ex++;
      n/=i;
    }
    res.push_back(pll(i,ex));
  }
  if(n!=1) res.push_back(pll(n,1));
  return res;
}


int main() {  
  int n,k;
  cin >> n >> k;
  vi h(n);
  REP(i,n) cin >> h[i];
  vi dp(n+1,INF);
  dp[0]=0;
  dp[1]=0;
  REPD(i,2,n) {
    REP1(j,k) {
      if(i-j>=1) {
        dp[i]=min(dp[i],dp[i-j]+abs(h[i-1]-h[i-1-j]));
      }
    }
  }
  cout << dp[n] << endl;
  return 0;
}


Measured memory_bytes: 3976
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include <set>
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f3f
#define pi 3.1415926535898
using namespace std;

int main()
{
    int x;
    cin>>x;
    if(x>=400&&x<=599)
    {
        cout<<8<<endl;
    }
    else if(x>=600&&x<=799)
    {
        cout<<7<<endl;
    }
    else if(x>=800&&x<=999)
    {
        cout<<6<<endl;
    }
    else if(x>=1000&&x<=1199)
    {
        cout<<5<<endl;
    }
    else if(x>=1200&&x<=1399)
    {
        cout<<4<<endl;
    }
    else if(x>=1400&&x<=1599)
    {
        cout<<3<<endl;
    }
    else if(x>=1600&&x<=1799)
    {
        cout<<2<<endl;
    }
    else if(x>=1800&&x<=1999)
    {
        cout<<1<<endl;
    }
    return 0;
}

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

int main(){
	
	int n, i;
	
	cin>>n;
	
	vector<int>dp(n),h(n);
	
	for(i=0;i<n;i++){
	
	cin>>h[i];
	
       }
       
	dp[0]=0; dp[1]=abs(h[1]-h[0]);
	
	for(i=2;i<n;i++){
		
		dp[i]=min ( dp[i-1] +abs(h[i] -h[i-1]) ,dp[i-2] +abs( h[i] -h[i-2]));
	
	}
	
	cout<<dp[n-1];
}

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

string S;

set<string> rec(int idx, int bit) {
	// cerr << idx << ":" << bitset<27>(bit) << endl;
	if (idx == S.size()) return set<string>({""});

	set<string> ret;

	char c = S[idx];
	int ci = c - 'a';

	if ((bit >> ci) & 1) {
		set<string> res = rec(idx + 1, bit);
		for(string s : res) {
			s.insert(s.begin(), c);
			ret.insert(s);
		}
	}

	if (!((bit >> (ci + 1)) & 1)) {
		set<string> res = rec(idx + 1, bit + (1 << (ci + 1)));
		for(string s : res) {
			s.insert(s.begin(), c + 1);
			ret.insert(s);
		}
	}

	return ret;
}

bool solve(){
	cin >> S;
	if (S == "#") return false;

	auto ans = rec(0, (1 << 26) + 1);
	cout << ans.size() << endl;
	for(int i = 0; i < 5; ++i) {
		if (ans.empty()) break;
		cout << *(ans.begin()) << endl;
		ans.erase(ans.begin());
	}

	vector<string> st;
	for(int i = 0; i < 5; ++i) {
		if (ans.empty()) break;
		st.push_back(*(--ans.end()));
		ans.erase(--ans.end());
	}

	while (!st.empty()) {
		cout << st.back() << endl;
		st.pop_back();
	}
	return true;
}

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


Measured memory_bytes: 6216
N = int(input(""))
K = int(input(""))
a = input("").split(" ")
a = [int(aa) for aa in a]
ans = 0
for x in a:
    if (K-x) < x:
        ans += (K-x)*2
    elif (K-x) >= x:
        ans += x*2
print(ans)


Measured memory_bytes: 9188
import java.io.*
import java.util.*

var pw = PrintWriter(System.out)
const val MOD = 2
fun solve(N: Long, A: LongArray){
    fun powOfTwo(x: Long):Int{
        var count = 0
        var ret = x
        while(ret % 2 == 0L){
            ret /= 2
            count++
        }
        return count
    }
    pw.println(A.map{ powOfTwo(it) }.min()!!)
    pw.flush()
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toLong()
    val A = LongArray(N.toInt())
    for (i in 0 until N.toInt()) {
        A[i] = sc.next().toLong()
    }
    solve(N, A)
}



Measured memory_bytes: 29696
#include<bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#define ll long long
#define ull unsigned long long
#define LLMax LLONG_MAX
#define LLMin LLONG_MIN
#define Max INT_MAX
#define Min INT_MIN
#define FOR1(i,a,b) for(int i=(a);i<(b);i++)
#define FOR2(i,a,b) for(int i=(a);i<=(b);i++)
#define DWN(j,b,a) for(int j=(b);j>=(a);j--) 
#define SET0(a) memset(a,0,sizeof(a))
#define SETN1(a) memset(a,-1,sizeof(a))
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
//#define int long long
const int INF=0x3f3f3f3f;
const int NINF=-INF-1;
const double PI=acos(-1); 
const int mod=1e9+7;
const int maxn=2e5+50;
using namespace std;
int a[maxn];
int main() {
	//IOS;
	int n;
	cin>>n;
	FOR1(i,1,n) {
		int temp;
		cin>>temp;
		a[temp]++;
	}
	FOR2(i,1,n)
		cout<<a[i]<<'\n';
	return 0;
}

Measured memory_bytes: 4412
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  vector<int> A(N), B(N), C(N);
  FOR(i,0,N) cin >> A[i];
  FOR(i,0,N) cin >> B[i];
  FOR(i,0,N) cin >> C[i];
  ll ans = 0;
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());
  // 真ん中固定
  FOR(i,0,N) {
    ll tmp = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
    tmp *= N - (upper_bound(C.begin(), C.end(), B[i]) - C.begin());
    ans += tmp;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

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

	int count = 0;
	int mn = n;
	for (auto c : str) {
		if (c == 'E') {
			++count;
		}
	}
	bool flg = false;
	for (auto c : str) {
		if (flg) { ++count; flg = false; }
		if (c == 'E') {
			--count;
		} else if (c == 'W') {
			flg = true;
		}
		mn = min(mn, count);
	}
	cout << mn << endl;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

signed main () {
  cin.tie(0);
  cout << setprecision(10);

  int n;cin >> n;
  map<int, int> m;
  REP(i, n) {
    int a; cin >> a;
    m[a]++;
  }

  ll ans = 0;

  for(ll x = (1ll<<31);x>=1;x>>=1) {
    for(auto& p : m) {
      if(m.count(x-p.first) == 0) continue;
      int r = 0;
      if(p.first * 2 == x) {
        r = p.second / 2;
      } else {
        r = min(p.second, m[x - p.first]);
      }
      ans += r;
      p.second -= r;
      m[x - p.first] -= r;
    }
  } 

  cout << ans << endl;
  
}


Measured memory_bytes: 9600