akhauriyash/Code-Regression huggingface dataset:
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 k = Integer.parseInt(sc.next());
	    
	       
	    int[] altura = new int[n];
	    int[] custo = new int[n];
	    
	    Arrays.fill(custo, Integer.MAX_VALUE);
	    custo[0] = 0;
	    
	    for(int i = 0; i < n; i++) altura[i] = Integer.parseInt(sc.next());
	    
	    for(int i = 0; i < n; i++) {
	      for(int j = 1; j <= k && i + j < n; j++) {
	        custo[i+j] = Math.min(custo[i+j], custo[i] + Math.abs(altura[i+j] - altura[i]));
	      }
	    }
	    
	    System.out.println(custo[n-1]);
	  }


}


Measured memory_bytes: 49388
use std::fmt::Write;

fn main() {
    let n: usize = read();
    let mut graph: Vec<Vec<i32>> = vec![vec![0;n + 1]; n + 1];
    for _ in 0..n {
        let input: Vec<i32> = read_as_vec();
        let v: usize = input[0] as usize;
        let slice: &[i32] = &input[2..];
        for &i in slice {
            graph[v][i as usize] = 1;
        }
    }

    for vec in &graph[1..] {
        println!("{}", join(' ', &vec[1..]));
    }
    //println!("{:?}", graph);
}

fn join<T: std::fmt::Display>(delimiter: char, arr: &[T]) -> String {
    let mut text = String::new();
    for (i, e) in arr.iter().enumerate() {
        if i > 0 {
            text.push(delimiter);
        }
        write!(text, "{}", e).unwrap();
    }
    text
}

fn read<T: std::str::FromStr>() -> T {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    input.trim().parse::<T>().ok().unwrap()
}

fn read_as_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse::<T>().ok().unwrap())
        .collect()
}


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

const int N = 2e5+9;

char s[N];
int dp[N][7];

bool same(int l, int r, int L, int R) {
    if (L <= 0) return 0;
	for (int i = l; i <= r; i ++) if (s[i] != s[i-l+L]) return 0;
	return 1;
}

int main() {
    scanf("%s", s+1);
    int n = strlen(s+1);
    for (int i = 0; i < 7; i ++) dp[0][i] = 0;
    for (int i = 1; i <= n; i ++) {
        for (int j = 1; j < 7; j ++) {
            if (i == j) {
				dp[i][j] = 1;
				continue;
            }
            for (int jj = 1; jj < 7; jj ++) {
                if (i < j + jj) continue;
                if (j != jj) dp[i][j] = max(dp[i][j], dp[i-j][jj] + 1);
                else if (!same(i-j+1, i, i-j-jj+1, i-j)) dp[i][j] = max(dp[i][j], dp[i-j][jj]+1);
            }
        }
    }
    int ans = 0;
    for (int i = 1; i < 7; i ++) ans = max(ans, dp[n][i]);
    printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 5888
#pragma GCC optimize(2) 
#include<iostream>
 
using namespace std;
const int mod=998244353;
long long a[100010];
long long n,x;
long long ksm(long long a,long long b){
	long long res=1;
	while(b){
		if(b&1){
			res=(res*a)%mod;
		}
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}
 
int main(){
	scanf("%lld",&n);
	int flag=0;
	scanf("%lld",&x);
	int ans=x;
	if(x!=0) flag=1;
	for(int i=1;i<n;i++){
		scanf("%lld",&x);
		a[x]++;
		if(x==0) flag=1;
		if(x>ans){
			ans=x;
		}
	}
	
	if(flag){
		printf("0\n");
	}
	else{
	long long sum=1;
		for(int i=1;i<ans;i++){
			if(a[i]==0){
				flag=1;
				break;
			}
			sum*=ksm(a[i],a[i+1]);
			sum%=mod;
		}
		if(flag) printf("0\n");
		else printf("%lld\n",sum);
	}
	return 0;
} 

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

int main() {
    string str;
    string order;
    string p;
    int a, b;
    int q;

    cin >> str;
    cin >> q;

    for(int i = 0; i < q; i++) {
        cin >> order >> a >> b;
        if(order=="replace") {
            cin >> p;
          	string str1, str3;
          	str1 = str.substr(0, a);
          	str3 = str.substr(b+1, str.size()-b);
            str = str1 + p + str3;
        }
        else if(order=="reverse") {
          	string tmp = str.substr(a, b-a+1);
          	for(int j = 0; j < tmp.size(); j++) {
            	str[b-j] = tmp[j];
            }
        }
        else if(order=="print") {
            cout << str.substr(a, b-a+1) << endl;
        }
    }
}


Measured memory_bytes: 3172
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
count = 0
ans = 0

N,D = I()

for i in range(N):
    X,Y = I()
    if X**2 + Y**2 <= D**2:
        ans += 1
print(ans)




Measured memory_bytes: 69868
import numpy as np

N, M, C = map(int, input().split())
B = np.array(list(map(int, input().split())))
A = np.array([list(map(int, input().split())) for _ in range(N)])

ans_list = np.dot(A, B.T) + C * np.ones(N).T
ans = np.count_nonzero(ans_list > 0)
print(ans)

Measured memory_bytes: 12384
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = int64_t;
using P = pair<ll,ll>;
ll INF = 1000000007;
// ll INF = 9223372036854775807;
// ll INF = 998244353;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    ll d,t,s;
    cin >> d >> t >> s;
    if(d<=s*t){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3644
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  
  cout<<min(c,b/a)<<endl;
  
  return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#include <stdio.h>
#include <cmath>

using namespace std;

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;

//階乗
int factorial(int k){
    int result=1;
    for (int i=1;i<=k;++i){
        result*=i;
    }
    return result;
}

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

    vector<int>cnt(9);

    int ans=0;

    rep(i,n){
        int a;
        cin>>a;

        if(a<400){cnt[0]++;}
        else if (a<800){cnt[1]++;}
        else if (a<1200){cnt[2]++;}
        else if (a<1600){cnt[3]++;}
        else if (a<2000){cnt[4]++;}
        else if (a<2400){cnt[5]++;}
        else if (a<2800){cnt[6]++;}
        else if (a<3200){cnt[7]++;}
        else cnt[8]++;
    }


    rep(i,8)if(cnt[i]>0)ans++;

    if(cnt[8]==0)cout<<ans<<" "<<ans<<endl;

    else cout<<max(ans,1)<<" "<<ans+cnt[8]<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

typedef struct {
	int key, id;
} data;

void merge_sort(data x[], int n)
{
	static data y[200001] = {};
	if (n <= 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p].key < x[q].key)? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

int main()
{
	int i, j, k, R, C, N, x[2], y[2];
	data d[200001];
	scanf("%d %d %d", &R, &C, &N);
	for (i = 1, k = 0; i <= N; i++) {
		scanf("%d %d %d %d", &(x[0]), &(y[0]), &(x[1]), &(y[1]));
		if (x[0] > 0 && x[0] < R && y[0] > 0 && y[0] < C) continue;
		else if (x[1] > 0 && x[1] < R && y[1] > 0 && y[1] < C) continue;
		
		for (j = 0; j <= 1; j++) {
			if (x[j] == 0) d[k+j].key = y[j];
			else if (y[j] == C) d[k+j].key = C + x[j];
			else if (x[j] == R) d[k+j].key = R + C * 2 - y[j];
			else d[k+j].key = (R + C) * 2 - x[j];
			d[k+j].id = i;
		}
		k += 2;
	}
	merge_sort(d, k);
	
	int flag[100001] = {}, s[100001], head = 0;
	for (i = 0; i < k; i++) {
		j = d[i].id;
		if (flag[j] == 0) {
			s[head++] = j;
			flag[j] = 1;
		} else if (s[head-1] == j) head--;
		else break;
	}
	if (i >= k) printf("YES\n");
	else printf("NO\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 5300
#include <iostream>
#include <cmath>

int main(){
    int n;
    std::cin >> n;

    bool flg = false;
    int i = 0;
    while(!flg){
        if(0 < n / (int)std::pow(2, i)){
            ++i;
        }else{
            flg = true;
        }
    }

    std::cout << (int)std::pow(2, i - 1) << std::endl;

    return 0;
}


Measured memory_bytes: 256
import math

def ty(h,w):
    lenh=h/2
    if h%2==0:
        #tateb
        tatew = math.ceil(w/3)
        maxb = max(h*tatew, (w-tatew)*lenh)
        minb = min(h*tatew, (w-tatew)*lenh)
        res0 = maxb-minb
        #tates
        if w>3:
            tatew = math.floor(w/3)
            maxb = max(h*tatew, (w-tatew)*lenh)
            minb = min(h*tatew, (w-tatew)*lenh)
        res1 = maxb-minb
    else:
        #tateb
        tatew = math.ceil(w/3)
        maxb = max(h*tatew, (w-tatew)*math.ceil(lenh))
        minb = min(h*tatew, (w-tatew)*math.floor(lenh))
        res0 = maxb-minb
        #tates
        if h>3:
            tatew = math.floor(w/3)
            maxb = max(h*tatew, (w-tatew)*math.ceil(lenh))
            minb = min(h*tatew, (w-tatew)*math.floor(lenh))
        res1 = maxb-minb
    return math.floor(min(res0,res1))

h,w = map(int, input().split())
result = [100000,100000,100000, 100000]

#tate3
if h%3==0:
    result[0] = 0
elif h>3:
    result[0] = w
#yoko3
if w%3==0:
    result[1] = 0
elif w>3:
    result[1] = h

#ト
if w%3==0:
    if h%2==0:
        result[2] = 0
    elif h>2:
        result[2] = math.floor(2*w/3)
else:
    result[2] = ty(h,w)
#T
if h%3==0:
    if w%2==0:
        result[3] = 0
    elif w>2:
        result[3] = math.floor(2*h/3)
else:
    result[3] = ty(w,h)
print(min(result))


Measured memory_bytes: 3188
n,k=map(int,input().split())
h=list(map(int,input().split()))
s=sorted(h,reverse=True)
cnt=0
for i in range(n):
    cnt+=s[i]
if k>=n:
  print(0)
  exit()
else:
  for i in range(k):
    cnt-=s[i]
print(cnt)

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

int main() {
int a,b,c,d;
cin >> a >> b >> c >> d;
if(abs(c-a)<=d)cout << "Yes";
else if(abs(c-b)<=d&&abs(b-a)<=d)cout << "Yes";
else cout << "No";
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        n: u64
    }

    let mut ret = 1u64 << 60;
    for i in 1..n/2+1 {
        ret = std::cmp::min(ret, digits_sum(i, n - i));
    }
    println!("{}", ret);
}

fn digits_sum(mut a: u64, mut b: u64) -> u64 {
    let mut sum = 0;
    while a > 0 || b > 0 {
        sum += a % 10 + b % 10;
        a /= 10;
        b /= 10;
    }
    sum
}


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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	unsigned long long num;
	cin>>num;
	string str;
	while(num)
	{
		long long var=num%26;
		var=(var==0?26:var);
		str+=('a'-1+var);
		num-=var;
		num/=26;

	}
	reverse(begin(str),end(str));
	cout<<str;
}


Measured memory_bytes: 3652
import math
import itertools
def r(retu,N):#組み合わせ,数
    first=retu[0]
    length=0
    n=0
    for i in retu:
        if n==0:
            n+=1
            continue
        length+=math.sqrt((i[0]-first[0])**2+(i[1]-first[1])**2)
        first=i

    #length=math.sqrt((back[0]-front[0])**2+(back[1]-front[1])**2)
    return length

N=int(input())
S=[[int(i) for i in input().split()] for i in range(N)]
K=[]
kumi=0
for i in itertools.permutations(S):
    length=r(i,N)
    K.append(length)
    kumi+=1

print(sum(K)/kumi)


Measured memory_bytes: 4400
#include<iostream>
#include<sstream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<stack>
#define debug(a) cout << "*" << a << "*" << endl
using namespace std;
typedef long long ll; 
ll n, m;
int main()
{
	while (~scanf("%lld%lld", &n, &m))
	{
		ll l, r;
		if (n % 4 == 1)
			l = 1;
		else if (n % 4 == 2)
			l = n + 1;
		else if (n % 4 == 3)
			l = 0;
		else if (n % 4 == 0)
			l = n;
		if (m % 4 == 1)
			r = 1;
		else if (m % 4 == 2)
			r = m + 1;
		else if (m % 4 == 3)
			r = 0;
		else if (m % 4 == 0)
			r = m;
		ll ans = r ^ l ^ n;
		printf("%lld\n", ans);
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int n;
		Scanner scan = new Scanner(System.in);
		n=scan.nextInt();
		int[] a =new int[n];
		for(int i=0;i<n;i++)
		{
			a[i]=scan.nextInt();
		}
		for(int i=n-1;i>0;i--)
		{
			System.out.print(a[i]+" ");
		}
		System.out.println(a[0]);
	}
}

Measured memory_bytes: 26300
#include <stdio.h>
int k,t,type[100],max,ans;
int main() {
	scanf("%d %d",&k,&t);
	for(int i=0;i<t;i++) {
		scanf("%d",&type[i]);
		if(max<type[i]) max=type[i];
	}
	if(k%2==1){
		if(max<=k/2+1) ans=0;
		else ans = max-(k-max+1);
	} else {
		if(max<=k/2) ans=0;
		else ans = max-(k-max+1);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  queue<string> q;
  q.push("a");
  while(!q.empty()){
    string now = q.front(); q.pop();
    if(now.size() == n){
      cout << now << endl;
      continue;
    }
    auto itr = max_element(now.begin(), now.end());
    int mx = *itr - 'a';
    rep(i, mx+2){
      char add = i + 'a';
      q.push(now + add);
    }
  }
  return 0;
}

Measured memory_bytes: 7348
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <stdlib.h>
#include <time.h>
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define setDP(arr) memset(arr,-1,sizeof arr)
#define Clear(arr) memset(arr,0,sizeof arr)
#define oo 1000000000
#define inf 1000000000000000000
#define M 998244353
using namespace std;
typedef long long ll;
const int N = 1e6+300;
const int SQRTN = 320;
const int LOGN = 20;
const double PI = acos(-1);
const double TAU = 2*PI;

int n;
int dp[N];
char s[N];
int fast(int x, int y , int mod){
  if(!y)
    return 1;
  int ret = fast(x,y>>1,mod);
  ret = (ret*1ll*ret)%mod;
  if(y&1)
    ret = ret*1ll*x%mod;
  return ret;
}

int popcount(int x){
  int ctr=0;
  while(x){
    ctr+=x&1;
    x>>=1;
  }
  return ctr;
}

inline void solve(){
  cin >> n;
  dp[1]=1;
  for(int i = 2 ; i < N ; i++){
    dp[i]=dp[i%(popcount(i))]+1;
  }
  int ones=0;
  scanf("%s",s);
  for(int i = 0 ; i < n ; i++){
    ones+=s[i]=='1';
  }
  if(ones==0){
    for(int i = 0 ; i < n ; i++){
      puts("1");
    }
    return ;
  }
  int val1,val2,val3;
  val1=val2=val3=0;
  for(int i = 0 ; i < n ; i++){
    val1*=2;
    val2*=2;
    val3*=2;
    val1+=s[i]-'0';
    val2+=s[i]-'0';
    val3+=s[i]-'0';
    if(ones-1)val1%=ones-1;
    val2%=ones;
    val3%=ones+1;
  }
  for(int i = 0 ; i < n ; i++){
    if(s[i]=='0'){
      printf("%d\n",1+dp[(val3+fast(2,n-i-1,ones+1))%(ones+1)]);
    }else{
      if(ones>1)printf("%d\n",1+dp[(ones-1+val1-fast(2,n-i-1,ones-1))%(ones-1)]);
      else{
        cout << 0 << endl;
      }
    }
  }


}

signed main() {
    int t=1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 7332
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define lli long long int
#define d double
#define mod 1000000007
#define mx 200001
using namespace std;
void add_me(lli &a,lli b){
	a+=b;
	if(a>=mod) a-=mod;
}
void sub_me(lli &a,lli b){
	a-=b;
	if(a<0) a+=mod;
}
int main() {
	FIO;
	string K;
	int D;
	cin>>K;
	cin>>D;
	int n=K.length();
	vector<vector<lli>> dp(D,vector<lli>(2));
	//dp[i][j]->total ways to get remainder i with condition j(T/F)....
	dp[0][0]=1;
	for(int i=0;i<n;i++){
		vector<vector<lli>> temp_dp(D,vector<lli>(2));
		for(int j=0;j<D;j++){
			for(bool is_smaller : {false,true}){
				for(int k=0;k<10;k++){
					if(k>K[i]-'0' && !is_smaller) break;
					add_me(temp_dp[(j+k)%D][is_smaller||k<(K[i]-'0')],dp[j][is_smaller]);
				}
			}
		}
		dp=temp_dp;
	}
	lli ans=(dp[0][0]+dp[0][1])%mod;
	sub_me(ans,1);
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstring>
using namespace std;
struct node
{
	struct node *parent,*left,*right;
	int key;
};
node NIL;
node *nil = &NIL;
node *root = nil;
void setdepth(node*,int);
node* getroot(node*);
void inorder(node*);
void preorder(node*);
void insert(int);
void print();
node *find(int);

int main(){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		string s;
		cin >> s;
		if(s == "insert"){
			int key;
			cin >> key;
			insert(key);
		}
		else if(s == "print") print();
		else if(s == "find"){
			int key;
			cin >> key;
			if(find(key) != nil) cout << "yes" <<endl;
			else cout << "no" << endl;
		}
	}

	
	return 0;

}

node* getroot(node* x){
	int i=0;
	while(x->parent != nil){
		x = x->parent;
		i++;
		if(i >= 100000){
			cerr << "ERROR:GETROOT" << endl;
			break;
		}
	}
	//cerr << "root: " << x->key<< endl;
	return x;
}

void printchildren(node* x){

}

void insert(int key){
	node *x;
	x = (node*)malloc(sizeof(node));
	x->key = key;
	x->parent = x->left = x->right  = nil;
	if(root == nil) root = x;
	else{
		node* cur = root;
		node* prev = cur;
		bool isleft = true;
		while(cur != nil){
			prev = cur;
			if(key <= cur->key){
			 	isleft=true;
			 	cur = cur->left;
			}
			else {
				cur = cur -> right;
				isleft = false;
			}
		}
		x->parent = prev;
		if(isleft) prev->left = x;
		else prev -> right = x;
	}
}

void inorder(node *x){
	if(x->left != nil) inorder(x->left);
	cout << " " << x->key;
	if(x->right != nil) inorder(x->right);
}

void preorder(node *x){
	if(x == nil) return;
	else{
		cout << " " << x->key;
		preorder(x->left);
		preorder(x->right);
	}
}

void print(){
	inorder(root);
	cout << endl;
	preorder(root);
	cout << endl;
}

node* find(int key){
	node *x = root;
	while(x != nil && x->key != key){
		if(key < x->key) x = x->left;
		else x = x->right;
	}
	return x;
}

Measured memory_bytes: 21880
#include <bits/stdc++.h>
#define pb push_back

using namespace std;
using ll = long long int;
const int MOD = 1e9 + 7;

void solve()
{
	ll n; cin >> n;
	cout << 180*(n-2);
}

//  ---------------------Template---------------------------
void InputSetup()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	#ifdef LOCAL
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	#endif
}

int main(void)
{
	auto start = chrono::high_resolution_clock::now();

	InputSetup();
	solve();

	auto finish = chrono::high_resolution_clock::now();
	cerr << "Time elapsed: " << (chrono::duration<long double>(finish-start)).count() << "s\n";
}
//  ---------------------Template---------------------------

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

typedef long long ll;
ll quick_mod(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1) res*=a;
		a*=a;
		b>>=1;
	}
	return res;
}
int main(){
	ll n;
	while(cin>>n){
		ll cnt=0;
		while(n){
			n/=2;
			cnt++;
		}
		printf("%lld\n", quick_mod(2,cnt)-1);
	}
	return 0;
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    string st;
    cin >> st;
    
    string ans = "";
    rep(i, st.size()) {
        if (st[i] == '0') ans.pb('0');
        else if (st[i] == '1') ans.pb('1');
        else if (ans.size()) ans.pop_back();
    }

    std::cout << ans << std::endl;


    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define ll long long 
using namespace std;
int main(){
	ll n,m;
	cin>>n>>m;
	int a[m];ll s=0;
	for(int i=0;i<m;i++){
		cin>>a[i];
		s+=a[i];
	}
	if(s>n){
		cout<<-1<<endl;
	}
	else if(s==n){
		cout<<0<<endl;
	}
	else {
		cout<<n-s<<endl;
	}
}

Measured memory_bytes: 3208
/* Nurgazy Zhandos */

#include <bits/stdc++.h>

#define F first
#define S second

#define pf push_front
#define pb push_back
#define mp make_pair
#define pp pop_back
#define in insert

#define resize(v) v.resize(unique(all(v)) - v.begin()); 
#define all(a) a.begin(), a.end()
#define sz(a) a.size()
#define STOP return 0

#define nl '\n'

//#define int long long

using namespace std;

typedef pair <long long, long long> pll;
typedef pair <int, long long> pil;
typedef pair <long long, int> pli;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long double ld;
typedef long long ll;

const int MAX_N = 1e5 + 123;
const int inf = 1e9 + 123;
const ll INF = 1e18 + 123;
const int NN = 2e6 + 123;
const double eps = 1e-9;
const int mod = 1e9 + 7;

/*void random() {
 		unsigned int FOR;
 		asm("rdtsc" : "=A" (FOR));
	srand(FOR);
}*/

inline void fre() {
	#ifdef TEZZY
//	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
	#endif
}

inline void boost() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
}

main () {
	fre();
	boost();

	string s;
	cin >> s;

	sort(all(s));
	if(s == "abc") cout << "Yes";
	else cout << "No";
}

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

int h, w, dd[100][100], c = 0;
bool a[100][100];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

struct luoi{
    int x, y, d;
    luoi(int x1, int y1, int d1){
        x = x1;
        y = y1;
        d = d1;
    }
};

int main(){
    cin >> h >> w;
    cin.ignore();
    for (int i = 1; i <= h; i++){
        string s;
        getline(cin, s);
        int k = 0;
        for (int j = 0; j < s.size(); j++){
            if (s[j] == '.') k++, a[i][k] = true;
            else if (s[j] == '#') c++, k++, a[i][k] = false;
        }
    }
    /*for (int i = 1; i <= h; i++, cout << endl)
        for (int j = 1; j <= w; j++) cout << a[i][j] <<" ";*/
    if (!a[1][1] || !a[h][w]) cout << -1;
    else{
        queue<luoi> q;
        luoi u(h, w, 1);
        q.push(u);
        while(!q.empty()){
            u = q.front();
            q.pop();
            for (int i = 0; i < 4; i++){
                int xx = u.x + dx[i];
                int yy = u.y + dy[i];
                if (0 < xx && xx <= h && 0 < yy&&yy<= w &&a[xx][yy]&&!dd[xx][yy]){
                    dd[xx][yy] = u.d + 1;
                    q.push(luoi(xx, yy, u.d + 1));
                }
            }
        }
        if (dd[1][1] == 0) cout << -1;
        else cout << h*w - c - dd[1][1];
    }
}

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

int main()
{
	int n, x, count = 0;
	
	while (1)
	{
		count = 0;
		cin >> n >> x;

		if (n == 0 && x == 0)
		{
			break;
		}

		for (int k = 1; k <= n; k++)
		{
			for (int j = k + 1; j <= n; j++)
			{
				for (int i = j + 1; i <= n; i++)
				{
					if (i + j + k == x)
					{
						count++;
					}
				}
			}
		}
		
		cout << count << endl;
	}


	return 0;
}

Measured memory_bytes: 1160
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
//#define all(x , n) x+1,x+n+1
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define sz(x) (int)x.size()
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;


using ll = long long;
using ld = long double;

//#define int ll

const int N = 1e4+54, mod = 1e9 + 7, mod1 = 998244353;
const int MAX = 1e5 + 11 , T = 2000;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const long double INF3 = 1e8 + 11;
const int base = 500;
const int P = 37;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const int LOG = 20;
const double EPS = 1e-4;
const double PI = acos(-1.0);

template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


typedef pair <int, int> pii;        // #include <ext/pb_ds/assoc_container.hpp>y01
typedef pair <ll, ll> pll;         // #include <ext/pb_ds/tree_policy.hpp>
typedef vector <int> vi;          // #include <ext/rope>
                                  // #include <ext/rope>
                                 // #include <ext/rope>
bool prime(int n) {             // template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
    for(int i=2;i<=sqrt(n);i++){
        if(n%i==0){return 0;}
    }return 1;}
int query = 0;
ll bp(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;}
///////////////////////////////////////////////////////////

void solve() {
    ll a;
    cin >> a;
    cout << a + a*a + a*a*a;
}

/*
12 13 14


0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7
5 6 7 8 9 10 11 12
+8
+8
+8 -9
+8 -9
+8 -9
+8 -9
+8 -9
+8 -9
+8 -9


*/

main() {
    file("A");
    ios;
    int tt = 1;
    if(query == 1)
        cin >> tt;
    if(query == 2)
        tt = INF1;
    while(tt --) {
        solve();
    }
    return 0;
}


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

int main() {
  ll MOD = 1000000007;
  ll N, k;
  cin >> N >> k;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++) {
    cin >> A[i];
  }
  
  ll f = 0;
  for (ll i = N-2; i >= 0; i--) {
    for (ll j = N-1; j >= i+1; j--) {
      if (A[i] > A[j]) f = (f+1)%MOD;
    }
  }
  ll r = 0;
  for (ll i = 1; i < N; i++) {
    for (ll j = 0; j < i; j++) {
      if (A[j] < A[i]) r = (r+1)%MOD;
    }
  }
  
  ll d = f+r;
  ll n = (k*(k-1)/2)%MOD;
  cout << ((k*f%MOD)+(n*d%MOD))%MOD << endl;
}

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

#pragma region Macros
using ll = long long;
#define int ll
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
#define IOS\
    ios::sync_with_stdio(false);\
    cin.tie(0);\
    cout.tie(0);
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SORT(name) sort(name.begin(), name.end())
#define RSORT(name)\
    SORT(name);\
    reverse(all(name));
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
template <class T> inline void print(T x){ cout << x << '\n';}
template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
#pragma endregion

#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

template <typename T> T gcd(T a, T b) { while (a) { b %= a; swap(a, b); } return b; }

// 素因数分解をして結果を map で返す
// first: 素数, second: 素数 first の数
// 計算量 O(√n)
map<ll, ll> PrimeFactor(ll n) {
    map<ll, ll> res;
    for(ll i = 2; i * i <= n; ++i) {
        while(n % i == 0) {
            ++res[i];
            n /= i;
        }
        if(LLINF / i <= i) { break; }  // オーバーフロー警察
    }
    if(n != 1) { res[n] = 1; }
    return res;
}

const int MOD = 1000000007;
const int MAX_N = 100010;

int N;
V<> A;

signed main() {
    IOS;

    cin >> N;
    A.resize(N);
    REP(i, N) { 
        cin >> A[i];
    }

    bool isPairWise = true;
    set<int> exist;
    REP(i, N) {
        auto res = PrimeFactor(A[i]);
        for(auto& tmp : res) {
            if(exist.find(tmp.first) != exist.end()) {
                isPairWise = false;
                break;
            }
            exist.insert(tmp.first);
        }
        if(!isPairWise) { break; }
    }
    if(isPairWise) {
        print("pairwise coprime\n");
        return 0;
    }

    int val = A[0];
    REP(i, N) {
        val = gcd(val, A[i]);
    }
    if(val == 1) {
        print("setwise coprime\n");
        return 0;
    }
    print("not coprime\n");

    return 0;
}


Measured memory_bytes: 11116
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		String S = scan.nextLine();
		int pow_of_ten = 1;
		int sum = 0;
		int[] remainder = new int[2019];

		for(int i = S.length() - 1; i >= 0; i--){
			sum += (S.charAt(i) - '0') * pow_of_ten;
			pow_of_ten *= 10;
			sum %= 2019;
			pow_of_ten %= 2019;
			remainder[sum] += 1;
			//System.out.println(sum);
		}

		int answer = 0;
		remainder[0] += 1;
		for(int i = 0; i < 2019; i++){
			//System.out.println(remainder[i]);
			int m = remainder[i];
			answer += (m * (m - 1)) / 2;
		}
		System.out.println(answer);
	}
}


Measured memory_bytes: 41684
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<iostream>
#include<algorithm>
#define N 1000001
#define int long long
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;	
}
using namespace std;
const int mod=1000000007;
int n,ans,jc[N],sum[N],inv[N];
main()
{
	re(n);	
	jc[0]=1;
	inv[0]=inv[1]=1;
	for(int i=1;i<=n;++i)jc[i]=i*jc[i-1]%mod;
	for(int i=2;i<=n;++i)
		inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
	for(int i=(n+1)/2,x=(n-1)/2,y=1,j=jc[x];i<n;++i)	
	{
		sum[i]=j*jc[i]%mod;
		ans=(ans+i*(sum[i]-sum[i-1]))%mod;
		if(i+2<n)j=1ll*j*(++x)%mod;
		if(y<x)j=1ll*j*inv[++y]%mod;
		if(i+2<n && n-3-y>(n-i-2)*2-1)j=1ll*j*inv[++y]%mod;
	}
	printf("%lld\n",(ans+mod)%mod);
}

Measured memory_bytes: 21632
n = int(input())
N = len(str(n))
k = int(input())
s = [int(i) for i in str(n)]
dpi = [[0]*(k+1) for _ in range(N+1)]
dpj = [[0]*(k+1) for _ in range(N+1)]
dpi[0][0] = 1
for i in range(N):
    for j in range(k+1):
        dpi[i+1][j] += dpi[i][j]*(s[i]==0)
        dpj[i+1][j] += dpj[i][j]+dpi[i][j]*(s[i]>0)
        if j < k:
            dpi[i+1][j+1]+=dpi[i][j]*(s[i]>0)
            dpj[i+1][j+1]+=dpj[i][j]*9+dpi[i][j]*max(0,s[i]-1)
print(dpi[N][k]+dpj[N][k])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
ll f[1000000];
int main(void){

    ll n, m;
    cin >> n >> m;
    map<ll, ll> ans;

    rep(i, 0, m){
        ll t1;
        string t2;

        cin >> t1 >> t2;
        t1--;
        if(t2 == "AC"){
            f[t1] = 1;
        }else{
            if(f[t1] == 0){
                ans[t1]++;
            }
        }
    }

    ll count = 0;
    ll ac = 0;
    rep(i, 0, n){
        if(f[i] == 1){
            count += ans[i];
            ac++;
        }
    }
    cout << ac << " " << count << endl;
    return 0;
}


Measured memory_bytes: 7296
#include<iostream>
#include<cmath>
using namespace std;
#define M 256

int I[M+1];
int R[M+1];
int O[M+1];
int N;

long double getEntropy( int S, int A, int C ){
    R[0] = S;
    for ( int i = 1; i <= N; i++ ){
	R[i] = (A*R[i-1]+C)%M;
    }
    for ( int i = 1; i <= N; i++ ){
	O[i] = (I[i] + R[i])%M;
    }

    long double H = 0;
    int cnt[M+1];
    for ( int i = 0; i <= M; i++ ) cnt[i] = 0;
    for ( int i = 1; i <= N; i++ ) cnt[O[i]]++;

    for ( int i = 0; i <= M; i++ ){
	if ( cnt[i] > 0){
	    long double x = 1.0*cnt[i]/N;
	    H += x*log(x);
	} 
    }
    return -1*H;
}
#define EPS (1e-12)
void compute(){
    int S, A, C;
    long double minv = (1<<21);
    //long double maxv = -1*(1<<21);
    for ( int s = 0; s <= 15; s++ ){
	for ( int a = 0; a <= 15; a++ ){
	    for ( int c = 0; c <= 15; c++ ){
		long double e = getEntropy(s, a, c);
		if ( minv-EPS > e ){
		    //		    cout << e << endl;
		    S = s; A = a; C = c;
		    minv = e;
		}
	    }
	}
    }
    cout << S << " " << A << " " << C << endl;
}

main(){
    while(1){
	cin >> N;
	if ( N == 0 ) break;
	for ( int i = 1; i <= N; i++ ) cin >> I[i];
	compute();
    }
}

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll A, B;
  IN(A,B);
  REP(i,10001){
    double tmp_A = (double)i*8.0/100.0;
    double tmp_B = (double)i*10.0/100.0;

    if((ll)tmp_A == A && (ll)tmp_B == B){
      OUT(i);
      return 0;
    }
  }

  OUT(-1);
  return 0;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  	int N;
    //入力受付
    cin >> N;
    int num[N];

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

    //わりまくる
    int ans = 0;
    while(1){
        for(int i=0; i<N; i++){
            if( (num[i] % 2) == 0){
                num[i] = num[i] / 2;
            } else{
                cout << ans << endl;
                return 0;
            }
        }
        ans++;
    }
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    static int[] A;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        A = sc.nextIntArray(3);
        System.out.println( solve() );
    }


    static int solve() {
        return min(cost(0, 1, 2), cost(0, 2, 1), cost(1, 0, 2), cost(1, 2, 0), cost(2, 0, 1), cost(2, 1, 0));
    }

    static int cost(int a, int b, int c) {
        return Math.abs(A[b] - A[a]) + Math.abs(A[c] - A[b]);
    }

    static int min(int... cs) {
        int min = 200;
        for (int c : cs) {
            min = Math.min(min, c);
        }
        return min;
    }

    @SuppressWarnings("unused")
    static class FastScanner {
        private BufferedReader reader;
        private StringTokenizer tokenizer;
        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }
        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken("\n");
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }
        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 22996
n = int(input())
num_list = list(map(int, input().split()))
def insertion_sort(lst):
    n = len(lst)
    for i in range(n):
        current = lst[i]
        j = i - 1
        while j >= 0 and lst[j] > current:
            lst[j + 1] = lst[j]
            j -= 1
        lst[j + 1] = current
        map_lst = map(str, lst)
        print(" ".join(map_lst))
insertion_sort(num_list)


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

using namespace std;

int main() {
    map<string, string> mymp;
    mymp["Sunny"] = "Cloudy";
    mymp["Cloudy"] = "Rainy";
    mymp["Rainy"] = "Sunny";

    string s; cin >> s;
    cout << mymp[s] << '\n';

    return 0;
}

Measured memory_bytes: 256
//       Author: Mostafa Mounir Shehab
 
#include <bits/stdc++.h>
using namespace std;
 
#define PI  3.14159265  // PI = acos(-1)
#define EPS (1e-10)
#define endl "\n"
#define SZ(v) (int)(v.size())
typedef long long ll;
typedef long double ld;
//template <class Type>
 
 
void Fast(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL);
}
 
inline int D(){
	int t;
	scanf("%d",&t);
	return t;
}
inline ll llD(){
	ll t;
	scanf("%lld",&t);
	return t;
}
 
 
ll MOD=1e9 + 7; 
const int N=1e5 + 5;
ll arr[N][4];
ll dp[N][4];
ll OO=1e13; 
 
ll n,m,k,cnt,SU,idx,len,MN,MX;
ll l,r,mid;
ll a,b,c,d,s;
vector<ll> vec;
 
ll Solve(int idx,int last){
	ll &ret=dp[idx][last];
	
	if(~ret)
		return ret;
	
	if(idx == n)
		return 0;
	
	for(int i=1;i<=3;++i)
		if(last != i)
			ret = max(ret , arr[idx][i] + Solve(idx+1,i));
	
	return ret;

}

 
 
 
int main(){

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

	
		
}
 
 


Measured memory_bytes: 14336
//
//  main.cpp
//  At_Coder_Group_Contest
//
//  Created by Uttam Datta on 01/06/19.
//  Copyright © 2019 Uttam Datta. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector <long long int> A;
long long int N;

long long int ans(){
    long long int res = 0;
    sort(A.begin(), A.end());
    long long int i = A.size()-2;
    long long int done = 0;
    while(i >= 0 && done != N){
        res += A[i];
        
        i -= 2;
        done++;
    }
    return res;
}

int main(){
    cin >> N;
    A.clear();
    A.resize(3*N);
    for(long long int k =0; k < 3*N; k++){
        cin >> A[k];
    }
    cout << ans() << endl;
}


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

#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define sortv(v) sort(v.begin(),v.end());
#define sorta(a,n) sort(a,a+n);
#define arrayin(a,n) for(int i=0;i<n;i++) cin>>a[i];
#define arrayout(a,n) for(int i=0;i<n;i++) cout<<" ";cout<<"\n";
#define whatIs(x) cout<<#x<<" is "<<x<<endl;
#define fillA(a,value) memset(a,value,sizeof(a));
#define len(s) s.length()
#define reached cout<<"reached "<<endl;
#define INF INT_MAX //Infinity
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define MOD 1000000007
#define fi first
#define se second
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define vi64 vector<lli>
#define viii vector<tuple<int,int,int>>
#define prq priority_queue<int>
#define mii map<int,int>
#define msi multiset<int>
#define nl "\n"
#define sii set<int,int>
#define sz size

typedef long long int lli;
typedef unsigned long long int ulli;
typedef double ld;

using namespace std;

int main()
{
	fio;
	/*int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
	}*/
	string s;
	cin>>s;
	map<char,int> m;
	REP(i,len(s))
	{
		m[s.at(i)]++;
	}
	int f=0;
	char ans='a';
	for(char x='a';x<='z';x++)
	{
		if(m[x]==0)
		{
			f=1;
			ans=x;
			break;
		}
	}
	if(f)
		cout<<ans<<endl;
	else cout<<"None"<<endl;
	return 0;
}

Measured memory_bytes: 512
while True:
    n,x = map(int,input().split())
    
    if n == 0 and x == 0:
        break

    count = 0
    
    for i in range(1,n):
        for j in range(i+1,n):
            if (x - i - j) <= n and (x - i - j) > j:
                
                count = count + 1
                
    print('{}'.format(count)) 

Measured memory_bytes: 5596
#include <bits/stdc++.h>
 
//#include <unistd.h>
//#include <iostream>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
//int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
//int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
//const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'


signed main() {
	fio();
	int n;
	cin >> n;
	vi a(n);
	rep (i, n) cin >> a[i];

	bool flag = true;
	rep (i, n) {
		if (a[i] % 2 == 0) {
			if (a[i] % 3 != 0 and a[i] % 5 != 0) {
				flag = false;
			}
		}
	}
	if (flag) {
		cout << "APPROVED" << endl;
	}
	else {
		cout << "DENIED" << endl;
	}
}

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

int main(){
	int n;
	while(cin >> n,n){
		int w,h;
		cin >> w >> h;
		int map[h][w];
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				map[i][j]=0;
			}
		}
		int x,y;
		for(int i=0;i<n;i++){
			cin >> x >> y;
			map[y-1][x-1]=1;
		}
		int s,t;
		cin >> t >> s;
		int m=0;
		for(int i=0;i<=h-s;i++){
			for(int j=0;j<=w-t;j++){
				int count=0;
				for(int k=0;k<s;k++){
					for(int l=0;l<t;l++){
						if(map[k+i][l+j]==1){
							count++;
						}
					}
				}
				m=max(m,count);
			}
		}
		cout << m << endl;
	}
}

Measured memory_bytes: 3044