akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

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

fn main() {
    let v = read_vec::<u64>();
    let (q, mut h, mut s, mut d) = (v[0], v[1], v[2], v[3]);
    let n = read::<u64>();
    let mut n = n * 4;

    h = min(2 * q, h);
    s = min(2 * h, s);
    d = min(2 * s, d);
    let mut ans = (n / 8) * d;
    n -= (n / 8) * 8;
    ans += (n / 4) * s;
    n -= (n / 4) * 4;
    ans += (n / 2) * h;
    n -= (n / 2) * 4;
    ans += n * q;
    println!("{:?}", ans);
}

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

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


Measured memory_bytes: 4352
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
	string s; cin >> s;
	int n = s.length();
	int x = 0;
	for (int i = 0; i < n; i++)
		x += s[i] - '0';
	cout << (x % 9 == 0 ? "Yes" : "No") << '\n';
	return 0;
}


Measured memory_bytes: 3688
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <string>
#include <iostream>
#define INF 0x3f3f3f3f
#define LL long long
#define N 4110
#define endl '\n'
using namespace std;
char a[200],b[200];
int main()
{
    int n;
    scanf("%d",&n);
    scanf("%s",a);
    scanf("%s",b);
    for(int i=0;i<n;i++)
    {
        int x=i;
        for(int j=0;j<n;j++)
        {
            if(a[x]!=b[j]) break;
            x++;
        }
        if(x==n)
        {
            cout<<i*2+n-i<<endl;
            break;
        }
        if(i==n-1) cout<<2*n<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <vector>
#define ll long long int
#define mp make_pair
#define pb push_back
#define vi vector<int>
using namespace std;
using namespace std::chrono;
long long int p=1e9 +7;
int n;
ll seq[401];
bool debugging=0;
bool outputcheck=0;
bool timecheck=0;
void init(){
    if(debugging){
        
    }
    else{
        cin>>n;
        for(int i=0;i<n;i++){
            cin>>seq[i];
        }
    }
}
long long int modpower(ll b,ll po, ll mod=p){
    long long int ans=1;
    while(po){
        if(po&1){
            ans*=b;
            ans%=mod;
        }
        b*=b;
        b%=mod;
        po>>=1;
    }
    return ans;
}
ll solve(){
   ll ans[n][n];
   ll sum[n+1];
   sum[0]=0;
   for(int i=0;i<n;i++){
       ans[i][i]=0;
       sum[i+1]=sum[i]+seq[i];
   }
   for(int i=1;i<n;i++){
       for(int j=0;j<n-i;j++){
           ans[j][j+i]=1e18;
           for(int k=j;k<j+i;k++){
               ans[j][j+i]=min(ans[j][j+i],ans[j][k]+ans[k+1][j+i]);
           }
           ans[j][j+i]+=sum[j+i+1]-sum[j];
       }
   }
   return ans[0][n-1];
}
ll solvebad(){

}
int output(){
   
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t;
	//cin >>t;
	t=1;
    srand(time(0));
	while(t--){
	   init();
	   if(debugging){
	       if(outputcheck){
	          if(solve()!=solvebad()){//checking for random input
	             output();
	          }
	       }
	       if(timecheck){
	           auto start=high_resolution_clock::now();
	           solve();
	           auto stop=high_resolution_clock::now();
	           auto duration = duration_cast<microseconds>(stop - start);
	           cout<<duration.count()<<" Fast\n";
	           start=high_resolution_clock::now();
	           solvebad();
	           stop=high_resolution_clock::now();
	           duration = duration_cast<microseconds>(stop - start);
	           cout<<duration.count()<<" Slow\n";
	       }
	   }
	   else{
	       cout<<solve()<<"\n";//solving it correctly
	   }
	}
}

Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <climits>
int square(int x){
	return x * x;
}
int main()
{
	using namespace std;
	int N, M, i, j, c, k, v, y, sub_sq, min;
	vector <int> C, x;
	while (true)
	{
		cin >> N >> M;
		if (N == 0 and M == 0) break;
		vector < vector<int> > dp(N+1);
		C.resize(M); x.resize(N);
		for (i=0;i<=N;i++){dp[i].resize(256); for (j=0;j<256;j++) dp[i][j] = INT_MAX;}
		for (i=0;i<M;i++) cin >> C[i];
		for (i=0;i<N;i++) cin >> x[i];
		dp[0][128] = 0;
		for(i = 0; i < N; i++)
		{
			for (k = 0; k < 256; k++)
			{
				v = dp[i][k];
				if (v == INT_MAX) continue; 
				for(j = 0; j < M; j++)
				{
					c = C[j];
					if (k + c > 255) y = 255; else if (k + c < 0) y = 0; else y = k + c;
					sub_sq = square(x[i]-y);
					if(v + sub_sq < dp[i+1][y]) dp[i+1][y] = v + sub_sq;
				}
			}
		}
		min = INT_MAX;
		for(k = 0; k < 256; k++) min = min <= dp[N][k] ? min : dp[N][k];  
		cout << min << endl;
	}
	return 0;
}

Measured memory_bytes: 22004
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;
const int maxn = 400100;
struct edges
{
	int to, next;
}edge[maxn];
int point[maxn] = {0}, te = 0;
int dua[maxn] = {0}, dub[maxn] = {0};
char v[maxn];
void add(int a, int b)
{
	if(v[b] == 'A')
		dua[a] ++;
	else
		dub[a] ++;
	te ++;
	edge[te].to = b;
	edge[te].next = point[a];
	point[a] = te;
}
int n, m;
int cnt;
bool flag[maxn];
queue<int> q;
int main()
{
	std::ios::sync_with_stdio(false);
	cin >> n >> m;
	for(int i = 1; i <= n; i ++)
		cin >> v[i];
	cnt = n;
	for(int i = 1; i <= m; i ++)
	{
		int a, b;
		cin >> a >> b;
		add(a, b);
		add(b, a);
	}
	for(int i = 1; i <= n; i ++)
	{
		if(dua[i] == 0 || dub[i] == 0)
			q.push(i);
		flag[i] = 1;
	}
	while(!q.empty())
	{
		int now = q.front();
		q.pop();
		if(!flag[now])
			continue;
		cnt --;
		flag[now] = 0;
		for(int e = point[now]; e; e = edge[e].next)
		{
			if(v[now] == 'A')
			{
				dua[edge[e].to] --;
				if(dua[edge[e].to] == 0 && flag[edge[e].to])
					q.push(edge[e].to);
			}
			else
			{
				dub[edge[e].to] --;
				if(dub[edge[e].to] == 0 && flag[edge[e].to])
					q.push(edge[e].to);
			}
		}
	}
	if(cnt == 0)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 8320
package main
import (
   "fmt"
   "os"
   "bufio"
   "strconv"
)
var sc = bufio.NewScanner(os.Stdin)

func main() {
  sc.Split(bufio.ScanWords)
  n := nextInt()

  var mochis []int
  for i := 0; i < n; i++ {
	  val := nextInt()
	  if !arrayExist(val, mochis) {
        mochis = append(mochis, val)
	  }
  }
  fmt.Println(len(mochis))

}

func arrayExist(element int, arr []int) (bool) {
	  for _, v := range arr {
		  if v == element {
			  return true
		  }
	  }
	  return false
}

func nextString() (string) {
	sc.Scan()
	v := sc.Text()
	return v
}

func nextInt() (int) {
	sc.Scan()
	v, e := strconv.Atoi(sc.Text())
    if e != nil { panic(e) }
    return v
}

func nextFloat() (float64) {
	sc.Scan()
	v, e := strconv.ParseFloat(sc.Text(), 64)
    if e != nil { panic(e) }
    return v
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include <string>
using namespace std;
int main() {
    string s, t;
    cin>>s>>t;
 
    int lenS=s.length();
    int lenT=t.length();
    int ans=1e4;
    for (int i=0; i+lenT<=lenS; i++) {
        int change=0;
        for (int j=0; j<lenT; j++) {
            if (s[i+j]!=t[j]) {
                change++;
            }
        }
        ans = min(ans, change);
    }
 
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<map>
#define int long long
#define ll long long
using namespace std;
signed main() {
	int n,cnt=0,sum=0;
	cin >> n;
	for (int i = 10; i <= n*10; i *= 10) {
		if(i==10)cnt += n % i;
      else sum+=(n%i-n%(i/10))/(i/10);
	}
  	if (n%(cnt+sum) == 0)cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];
#define int long long

using intpair = pair<int,int>;

void factor(map<int,int> &m, int num){
    for(int i=2; i<=sqrt(num); i++){
        int p = 0;
        while(num%i==0){
            num /= i;
            p++;
        }
        if(p > 0) m[i] = p;
    }
    if(num != 1) m[num] = 1;
}

signed main(){
    int A,B; cin >> A >> B;
    map<int,int> factor_A, factor_B;
    factor(factor_A,A); factor(factor_B,B);
    int res = 1;
    for(intpair p: factor_A){
        if(factor_B.count(p.first)){
            res++;
        }
    }
    cout << res << endl;
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> H(N);
  for (int i = 0; i < N; ++i){
    cin >> H[i];
  }
  int ans = 0;
  for (int i = 0; i < N; ++i){
    bool is_candidate = true;
    for (int j = 0; j < i; ++j){
      if (H[j] > H[i]){
        is_candidate = false;
        break;
      }
    }
    if (is_candidate){
      ++ans;
    }
  }
  cout << ans << endl;
}

  

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

int main(void){
    int N;
    string S;
    cin >> N;
    cin >> S;
    int numR = 0;
    int numW = 0;
    for(int i=0; i<N; i++){
        if(S[i] == 'R'){
            numR++;
        }else numW++;
    }
    int res = 0;
    for(int i=0; i<numR; i++){
        if(S[i] == 'W')res++;
    }
    cout << res << endl;
    return 0;
}

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

int main() {
	int N, d[101];
	cin >> N;
	int i;
	for (i = 0; i < N; i++) {
		cin >> d[i];
	}
	int M[101];
	int k = 0;
	for (i = 0; i < N; i++) {
		M[i] = 0;
		int j;
		//Mのi番目の要素を決定
		for (j = 0; j < N; j++) {
			if (M[i] < d[j]) {
				if(i==0){
					M[i] = d[j];
				}else if (d[j] < M[i-1]) {
					M[i] = d[j];
				}	
			}
		}
		if (M[i] > 0) { k++; }
	}
	cout << k;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var S string
	if _, err := fmt.Scan(&S); err != nil {
		return
	}
	length := len(S)
	halfLength := length / 2
	count := 0
	SRune := []rune(S)
	for i := 0; i < halfLength; i++ {
		if SRune[i] != SRune[length-1-i] {
			count++
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 512
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
void mysort(vector<pll> &a){sort(a.begin(),a.end()) ;}
void myrev(vector<pll> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n ; cin >> n ;
	vector<pll> gu(100001,make_pair(0,0)),ki(100001,make_pair(0,0)) ;
	for(int i=0;i<=100000;i++){
		gu.at(i).second = i ;
		ki.at(i).second = i ;
	}
	for(int i=0;i<n;i++){
		ll a ; cin >> a ;
		if(i%2==0) gu.at(a).first++ ;
		else ki.at(a).first++ ;
	}
	mysort(gu) ; myrev(gu) ;
	mysort(ki) ; myrev(ki) ;
	ll sum1 = 0 ;
	ll sum2 = 0 ;
	for(int i=0;i<=100000;i++){
		sum1 += gu.at(i).first ;
		sum2 += ki.at(i).first ;
	}
	if(gu.at(0).second!=ki.at(0).second) cout << sum1-gu.at(0).first+sum2-ki.at(0).first << endl ;
	else{
		ll sub1 = sum1-gu.at(0).first+sum2-ki.at(1).first ;
		ll sub2 = sum1-gu.at(1).first+sum2-ki.at(0).first ;
		cout << min(sub1,sub2) << endl ;
	}
}


Measured memory_bytes: 3328
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
struct node
{
	int x,y,next;
}e[100010];int len,last[100010];
inline void ins(int x,int y)
{
	len++;
	e[len].x=x;e[len].y=y;
	e[len].next=last[x];last[x]=len;
}
long long a[100010],b[100010];
bool cmp(node u,node v){return a[u.x]<a[v.x];}
int rt,fa[100010];
inline int findfa(int x)
{
	if(fa[x]!=x)fa[x]=findfa(fa[x]);
	return fa[x];
}
long long uf,tot[100010],s[100010];
inline void dfs(int x)
{
	for(int k=last[x];k;k=e[k].next)
	{
		int y=e[k].y;
		s[y]=max(s[x],a[x]-tot[y]);
		dfs(y);
	}
}
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int n=read(),m=read();
    for(int i=1;i<=n;i++){a[i]=read(),b[i]=read();a[i]=max(0LL,a[i]-b[i]),uf+=b[i];}
    for(int i=1;i<=m;i++)
    {
    	int x=read(),y=read();if(a[x]<a[y])swap(x,y);
    	e[i].x=x,e[i].y=y;
    }sort(e+1,e+m+1,cmp);
    for(int i=1;i<=n;i++)fa[i]=i,tot[i]=b[i];
    for(int i=1;i<=m;i++)
    {
    	int fx=findfa(e[i].x),fy=findfa(e[i].y);
    	if(fx!=fy){fa[fy]=fx,rt=fx,tot[fx]+=tot[fy];ins(fx,fy);}
    }dfs(rt);
    long long ans=max(a[1],s[1])+uf;
    for(int i=2;i<=n;i++)ans=min(ans,max(a[i],s[i])+uf);
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main() {
    int x;
    cin >> x;
    if (x % 100 <= 5 * (x / 100)) {
        cout << '1' << endl;
    }
    else {
        cout << '0' << endl;
    }
    return 0;
}

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


int main(){
    int n, count = 0;
    cin >> n;
    for (int i = 1; i <= n; i++){
        if((to_string(i)).length() % 2 == 1){ //の数字列を文字列に変換する
            count++;
        }
    }
    printf("%d\n", count);
    return 0;
    
}








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

#define ls(x) (x<<1)
#define rs(x) ((x<<1)|1)

using namespace std;

const int MAXN=5e5;

int n,q,tree[4*MAXN+1];
string s;

inline void build(int l,int r,int no) {
	if(l==r) {
		tree[no]=1<<(s[l-1]-97);
		return ;
	}
	int mid=(l+r)>>1;
	build(l,mid,ls(no));
	build(mid+1,r,rs(no));
	tree[no]=tree[ls(no)]|tree[rs(no)];
	return ;
}

inline void update(int l,int r,int no,int p,int v) {
	if(l==r) {
		tree[no]=1<<v;
		return ;
	}
	int mid=(l+r)>>1;
	if(p<=mid) update(l,mid,ls(no),p,v);
	else update(mid+1,r,rs(no),p,v);
	tree[no]=tree[ls(no)]|tree[rs(no)];
	return ;
}

inline int query(int l,int r,int no,int lt,int rt) {
	if(lt<=l && r<=rt) return tree[no];
	int mid=(l+r)>>1,ans=0;
	if(lt<=mid) ans=query(l,mid,ls(no),lt,rt);
	if(rt>mid) ans|=query(mid+1,r,rs(no),lt,rt);
	return ans;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>n>>s>>q;
	build(1,n,1);
	for(int i=1,ins,x,y,tmp,cnt; i<=q; ++i) {
		cin>>ins>>x;
		if(ins==1) {
			char c;
			cin>>c;
			update(1,n,1,x,c-97);
		}
		else {
			cin>>y;
			tmp=query(1,n,1,x,y);
			cnt=0;
			while(tmp) {
				if(tmp&1) ++cnt;
				tmp>>=1;
			}
			cout<<cnt<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 7068
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define reps(i,x) for(ll i=1;i<=(ll)(x);i++)
#define rrep(i,x) for(ll i=((ll)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(ll)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int main() {
  string n;
  cin >> n;
  int ans = 0;
  rep(i, 4){
    if(n[i] == '2')ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
def four(n):
    if n % 4 is 0:
        return 0
    else:
        return n

def seven(n):
    if n % 7 is 0:
        return 0
    else:
        return n

def judge(n):
    if four(n) is 0:
        return 0
    elif seven(n) is 0:
        return 0
    elif n < 4:
        return 1
    else:
        n -= 4
        return judge(n)

if judge(N) is 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
def gcd(n,m):
    while n:
        m,n = [n,m%n]
    return m

A,B = map(int,input().split())

S = gcd(A,B)

s = 1
i = 2
while True:
    if S == 1:
        break
    if i ** 2 >= S:
        break
    hoge = 0
    while S % i == 0:
        hoge += 1
        S //= i
    if hoge:
        s += 1
    i += 1

print(s + (S != 1))

Measured memory_bytes: 3064
#include<iostream>
#include<cmath>
#include <iomanip>
using namespace std;
int main(){
    int n;
    while(1){
      double s[1000] , k=0, ave ;
      cin>>n;
      if(n==0)break;
      for(int i = 0; i<n ;i++){
        cin>>s[i];
        k += s[i];
      }
      ave = k / n ;
      double l  = 0 , ans;
      for(int i = 0; i<n ;i++){
        l += (s[i]-ave)*(s[i]-ave);
      }
      ans = sqrt(l/n);
      cout<<fixed<<setprecision(10)<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3224
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
pI(x)=parse(Int,x)
pM(x::Array{SubString{String},1})=map(pI,x)
function main()
  n=pI(readline())
  println((1000-n%1000)%1000)
end
main()
if isdefined(Base, :mystdin);close(mystdin);end

Measured memory_bytes: 155928
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
// clang-format on

const ll INF = LLONG_MAX / 10;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n + 1);
    rep(i, n + 1) cin >> a[i];

    vector<ll> p(n + 1);
    p[0] = 1;
    for (int i = 1; i <= n; ++i) {
        ll r = p[i - 1] - a[i - 1];
        if (r <= 0) {
            cout << -1 << "\n";
            return 0;
        }
        p[i] = min(r * 2, INF);
    }

    rep(i, n + 1) {
        if (p[i] < a[i]) {
            cout << -1 << "\n";
            return 0;
        }
    }

    vector<ll> s(a);
    for (int i = n - 1; i >= 0; --i) s[i] += s[i + 1];

    ll ans = 0;
    rep(i, n + 1) ans += min(p[i], s[i]);
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 5636
#include<bits/stdc++.h>
using namespace std;
#define ld long double
#define lli long long int
#define vi vector<int>
#define vlli vector<lli>
#define vvi vector<vi >
#define str string
#define vs vector<str>
#define vb vector<bool>
#define slli set<lli>
#define mii map<int, int>
#define mlli map<int, lli>
#define msi map<str, int>
#define mp make_pair
#define pii pair<int, int>
#define pll pair<lli, lli>
#define vpii vector<pii >
#define vpll vector<pll >
#define pb push_back
#define loop(i, s, l, j) for(int i = s; i < l; i += j)
#define rloop(i, s, l, j) for(int i = s; i >= l; i -= j)
#define rep(i, n) loop(i,0,n,1)
#define rrep(i, n) rloop(i,n-1,0,1) 
#define fastio() ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ft first
#define sd second   
#define mit mii::iterator
#define vit vi::iterator
#define all(a) a.begin(),a.end()
#define min3(a, b, c) min(a, min(b, c))
#define mod 1000000007
#define inf 1000000000000000000
#define minval -100000000
#define idf -1000000000
/**********************************************************************************************************************************************/
int dx4[4] = {0, -1, 0, 1};
int dy4[4] = {1, 0, -1, 0};
int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
int dy8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int Power(int base,int exp){int ans=1;  while(exp > 0){if(exp&1)ans=(1LL*ans*base)%mod; exp=exp>>1; base=(1LL*base*base)%mod;}  return ans;}
/**********************************************************************************************************************************************/

void input()
{
    int n;
    cin >> n;
    lli a[n+1];
    a[0] = 0;
    rep(i,n)
    {
        cin >> a[i+1];
        a[i+1] += a[i];
    }
    

    lli dp[n+1][n+1];//dp[i][j] = min cost to make 1 object from i........j
    rep(i,n)
        dp[i+1][i+1] = 0;


    loop(l,2,n+1,1)
        loop(i,1,n+1,1)
        {
            int j = i+l-1;
            if(j > n)
                continue;
            dp[i][j] = 1000000000000000000;
            loop(k,i,j,1)
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + a[j]-a[i-1]);
        }
    cout << dp[1][n] << '\n';

}

int main()
{
    fastio();
    int q = 1;
    //cin >> q;
    while(q--)
        input();
}

Measured memory_bytes: 1536
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

template <typename T> // T : type of cost
struct BellmanFord {
    T inf = numeric_limits<T>::max(); // initial value, reused when clear() is called
    int n;                            // number of nodes
    vector<bool> negative;
    vector<T> dist; // distance from start node
    struct edge {
        int from, to;
        T cost;
        edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
    };
    vector<edge> edges;

    BellmanFord(int n) : n(n), negative(n, false), dist(n, inf){};
    // 0-indexed!
    void addEdge(int from, int to, T cost) { edges.emplace_back(from, to, cost); }
    // calculate dist[i] as a shortest distance from start to each node
    void build(int start) {
        dist[start] = 0;
        for (int i = 0; i < n; ++i) {
            for (auto &e : edges) {
                if (dist[e.from] != inf && dist[e.to] > dist[e.from] + e.cost) {
                    dist[e.to] = dist[e.from] + e.cost;
                }
            }
        }
    }
    // check whether there are negative loops along the path of interest
    bool has_negativeloop(int end = -1) {
        for (int i = 0; i < n; ++i) {
            for (auto &e : edges) {
                if (dist[e.from] != inf && dist[e.to] > dist[e.from] + e.cost) {
                    dist[e.to]     = dist[e.from] + e.cost;
                    negative[e.to] = true;
                }
                negative[e.to] = negative[e.to] | negative[e.from];
            }
        }
        if (end != -1)
            return negative[end];
        else {
            bool neg = false;
            for (int i = 0; i < n; ++i) {
                neg = neg | negative[i];
            }
            return neg;
        }
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    BellmanFord<ll> bf(n);
    for (int i = 0; i < m; ++i) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        bf.addEdge(a, b, -c);
    }
    bf.build(0);
    if (bf.has_negativeloop(n - 1))
        cout << "inf"
             << "\n";
    else {
        cout << -bf.dist[n - 1] << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	private static final long x = (long) Math.pow(10, 18);

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();

		for (int i = 0; i < w + 2; i++) {
			System.out.print("#");
		}

		System.out.println();

		for (int i = 0; i < h; i++) {
			String s = sc.next();
			System.out.print("#");
			System.out.print(s);
			System.out.print("#");
			System.out.println();
		}


		System.out.println();


		for (int i = 0; i < w + 2; i++) {
			System.out.print("#");
		}

		sc.close();
	}

}


Measured memory_bytes: 37020
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	string S;
	int len;

	cin >> S;

	S.pop_back();
	S.pop_back();

	while (S.length() > 0) {
		len = S.length() / 2;

		if (S.substr(0, len) == S.substr(len, len)) break;

		S.pop_back();
		S.pop_back();
	}

	cout << S.length() << endl;

	return 0;
}


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

vector<int64_t> sieve(int64_t n){
    vector<int64_t> ret;
    vector<bool> is_prime(n+1);
    for(int64_t i=2; i<=n; i++) is_prime[i] = true;
    for(int64_t i=2; i<=n; i++){
        if(is_prime[i]){
            ret.push_back(i);
            for(int64_t j=2*i; j<=n; j+=i) is_prime[j] = false;
        }
    }
    return ret;
}

int main(){
    int N;
    int64_t S[100000];
    cin >> N;
    for(int i=0; i<N; i++) cin >> S[i];

    int64_t cbrt = pow(1e10, 1.0/3);
    while(cbrt*cbrt*cbrt <= 1e10) cbrt++;
    auto primes3 = sieve(cbrt);

    map<int64_t, int> num;
    bool has_one = false;
    for(int i=0; i<N; i++){
        for(int64_t p : primes3){
            int64_t cube = p*p*p;
            while(S[i] % cube == 0) S[i] /= cube;
        }
        if(S[i] == 1){
            has_one = true;
        }else{
            num[S[i]]++;
        }
    }

    auto primes2 = sieve(1e5);
    map<int64_t, int64_t> pr_sqrt;
    for(int64_t p : primes2) pr_sqrt[p*p] = p;
    
    set<int64_t> used;
    int ans = has_one;
    for(auto& p : num){
        int64_t a = p.first;
        if(used.count(a)) continue;

        int64_t b = 1;
        for(int64_t pr : primes3){
            if(a % (pr*pr) == 0){
                a /= (pr*pr);
                b *= pr;
            }else if(a % pr == 0){
                a /= pr;
                b *= pr*pr;
            }
        }
        if(pr_sqrt.count(a)){
            b *= pr_sqrt[a];
        }else if(a <= 1e5){
            b *= a*a;
        }else{
            b = -1;
        }
        
        if(num.count(b)){
            used.insert(b);
            ans += max(p.second, num[b]);
        }else{
            ans += p.second;
        }
    }

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

Measured memory_bytes: 9984
import java.util.Scanner;

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

		int K = n.nextInt();
		String S = n.next();

		if(S.length() <= K) {
			System.out.println(S);

		}else {
			String[] strArray = S.split("");
				for(int i=0 ; i<K ; i++) {
					System.out.print(strArray[i]);
				}
			System.out.println("...");
		}
	}
}


Measured memory_bytes: 35784
#include <iostream>
#include <algorithm>
#include<string>
#include<cmath>
#include<stack>
#include <vector>
#include<queue>
#include <random>
#include <cstdint>
using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int high = max({ a, b, c });
	int odd = (a % 2)*4 + (b % 2)*2 + c % 2;
	if ((odd ==4||odd==3)&&high==a|| (odd == 2 || odd == 5) && high == b || (odd == 1 || odd == 6) && high == c ) {
		cout << (high - a) / 2 + (high - b) / 2 + (high - c) / 2 + 1<<endl;
	}
	else if(odd==0||odd==7){
		cout << (high - a) / 2 + (high - b) / 2 + (high - c) / 2<<endl;
	}
	else {
		cout << (high - a) / 2 + (high - b) / 2 + (high - c) / 2+2 << endl;
	}
	return 0;
}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int i = in.nextInt();
		if(N%2==1&&i%2==1) {
			System.out.print("Yes");
		}else {
			System.out.print("No");
			
		}

	}
}

Measured memory_bytes: 21844
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int l = sc.nextInt();
		String[] s = new String[n];
		for (int i = 0; i < n; i++) {
			s[i] = sc.next();
		}

		for (int i = 0; i < n-1; i++) {
			for (int j = n-1; j > i; j--) {
				if (s[j].compareTo(s[j-1]) < 0) {
					String tmp = s[j];
					s[j] = s[j-1];
					s[j-1] = tmp;
				}
			}
		}
		String ans = "";
		for (String str : s) {
			ans += str;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 27476
while True:
    arr = input().split()
    H = int(arr[0])
    W = int(arr[1])

    if H == 0 and W == 0:
        break
    else:
        edge = ''
        for i in range(W):
            edge += '#'

        inner = ''
        for i in range(W):
            if i == 0 or i == W - 1:
                inner += '#'
            else:
                inner += '.'

        for i in range(H):
            if i == 0 or i == H - 1:
                print(edge)
            else:
                print(inner)
        print('')



Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using ll = long long;
#define int long long
signed main(void){
    int h,w; cin>>h>>w;
    int n;
    cin>>n;
    int x = 0;
    vector <ll> col(h*w);
    rep(i, n){ int a; cin>>a;
        rep(j,a) col[x++] = i+1;
    }
    //rep(i, h*w) cout<<col[i]<<endl;
    x=0;
    vector <vector<int>> ans(h,vector <int>(w));
    for(int i=0;i<h;i++){
        if(i%2==0) for(int j=0;j<w;j++){
            ans[i][j] = col[x++];
        }else{
            for(int j=w-1; j>=0; j--) ans[i][j]=col[x++];
        }
    }
    rep(i, h){ rep(j, w){
        cout<<ans[i][j]<<' ';
        }
        cout<<endl;
    }
}


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

using namespace std;

const int N = 3100,mod=1e9+7;

typedef long long ll;

int f[N][N];

int main()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	s="#"+s;
	f[1][1]=1;
	for(int i=2;i<=n;i++)
	{
		if(s[i-1]=='<')
		for(int j=1;j<=i;j++)
		{
			f[i][j]=(f[i][j-1]+f[i-1][j-1])%mod;
		}
		else 
		for(int j=i;j>=1;j--)
		{
			f[i][j]=(f[i][j+1]+f[i-1][j])%mod; 
		}
	}
	ll ans=0;
	for(int i=1;i<=n;i++)
	{
		ans+=f[n][i];
		ans%=mod;
	}
	cout<<ans<<endl;
	
	
			
	
}

Measured memory_bytes: 35840
#include <bits/stdc++.h>
#define ll long long
#define ar array
#define AC ios_base::sync_with_stdio(0); cin.tie(NULL);
using namespace std;
const int M = 1e9+7;
const int N = 1e5;
int n, m ,q;
vector<int> arr;
struct query{
    int a, b, c, d;
} q_arr[55];
int ans = 0;

void dfs(int num, int pos){
    if(pos>=n){
        int tmp = 0;
        for(int i=0; i<q; i++){
            int a = q_arr[i].a, b=q_arr[i].b;
            if(arr[b]-arr[a]==q_arr[i].c){
                tmp+=q_arr[i].d;
            }
        } 
        ans = max(ans, tmp);
        return;
    }
    for(int i = num; i<=m; i++){
        arr.push_back(i);
        dfs(i, pos+1);
        arr.pop_back();
    }
}

int main(){
    AC
    cin>>n>>m>>q;
    for(int i=0; i<q; i++){
        cin>>q_arr[i].a>>q_arr[i].b>>q_arr[i].c>>q_arr[i].d;
        q_arr[i].a--;
        q_arr[i].b--;
    }
    dfs(1, 0);
    cout<<ans<<endl;
}

Measured memory_bytes: 3624
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections;

class Program
{
    static void Main(string[] args)
    {
        var sol = new Solve();
        sol.Exec();
    }
}

class Solve
{
    public void Exec()
    {
        var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int N = l[0], K = l[1];
        var H = Console.ReadLine().Split().Select(int.Parse).ToArray();

        Array.Sort(H);
        var ans = 0L;
        for (var i = N - 1; i >= 0; i--)
        {
            if (K <= 0) ans += H[i];
            else K--;
        }

        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 34432
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=2e5+9;
const double pi=acos(-1);
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    double r;
    cin>>r;
    cout<<fixed<<setprecision(20)<<2*pi*r<<'\n';

    return 0;
}


Measured memory_bytes: 3792
while n = gets.to_i
  break if n == 0
  g = n.times.map { gets.split.map(&:to_i)[1..-1] }
  t = gets.split.map(&:to_i)[1..-1]
  res = -1
  g.each_with_index do |l, i|
    if t.all?{ |v| l.include?(v) }
      if res == -1
        res = i + 1
      else
        res = -1
        break
      end
    end
  end
  p res
end

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

template <typename T>
T BinarySearch(T lo, T hi, std::function<bool(T)> pred) {
  while (lo + 1 < hi) {
    T mid = (hi - lo) / 2 + lo;
    if (pred(mid)) {
      lo = mid;
    } else {
      hi = mid;
    }
  }
  return lo;
}

int main() {
  in(ll, n);
  vector<ll> x(n), y(n);
  vector<char> u(n);
  rep(i, n) cin >> x[i] >> y[i] >> u[i];

  const ll M = 400001;
  const ll inf = numeric_limits<ll>::max();
  ll t = inf;
  rep(rot, 4) {
    // R L
    {
      vector<vector<ll>> r(M);
      rep(i, n) if (u[i] == 'R') r[y[i]].push_back(x[i]);
      rep(i, M) sort(all(r[i]));
      rep(i, n) if (u[i] == 'L') {
        const auto& ri = r[y[i]];
        if (ri.empty()) continue;
        int j = BinarySearch<int>(0, ri.size(),
                                  [&](int k) { return ri[k] < x[i]; });
        if (ri[j] < x[i]) {
          t = min(t, (x[i] - ri[j]) * 10 / 2);
        }
      }
    }
    // R U
    {
      vector<vector<ll>> r(M);
      rep(i, n) if (u[i] == 'R') r[x[i] + y[i]].push_back(x[i]);
      rep(i, M) sort(all(r[i]));
      rep(i, n) if (u[i] == 'U') {
        const auto& ri = r[x[i] + y[i]];
        if (ri.empty()) continue;
        dbg(ri.size(), x[i], ri[0]);
        int j = BinarySearch<int>(0, ri.size(),
                                  [&](int k) { return ri[k] < x[i]; });
        if (ri[j] < x[i]) {
          t = min(t, (x[i] - ri[j]) * 10);
        }
      }
    }
    // Rotate 90 degrees.
    rep(i, n) {
      int nx = 200000 - y[i];
      int ny = x[i];
      x[i] = nx;
      y[i] = ny;
      u[i] =
          map<char, char>{{'R', 'U'}, {'L', 'D'}, {'U', 'L'}, {'D', 'R'}}[u[i]];
    }
  }
  if (t == inf) {
    out("SAFE");
  } else {
    out(t);
  }
}


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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int n, m; cin >> n >> m;
    cout << n * m - n - m + 1 << endl;
    return 0;
}

Measured memory_bytes: 3576
import java.util.Scanner;

/**
 * Created by donamphuong on 25/09/2016.
 */
public class Main {
    public static void main(String[] args) {
        String original = "CODEFESTIVAL2016";
        Scanner input = new Scanner(System.in);

        if(input.hasNext()) {
            String in = input.next();
            int iter = 0;

            for(int i = 0; i < original.length(); i++) {
                if(original.charAt(i) != in.charAt(i)) {
                    iter++;
                }
            }

            System.out.println(iter);

        }
    }
}


Measured memory_bytes: 9684
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main(){
  long long n, temp;
  map<long long, int> map;
  string res = "YES";
  cin >> n;

  for(int i = 0; i < n; i++) {
    cin >> temp;
    if(map.count(temp)){
      res = "NO";
      break;
    }else{
      map[temp] = 1;
    }

  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;

int d[31][31];
int t[3][31];

int main(){
    int n, c;
    cin >> n >> c;
    rep(i, c) rep(j, c) cin >> d[i][j];

    rep(i, n){
        rep(j, n){
            int col;
            cin >> col;
            t[(i+j)%3][col-1]++;
        }
    }

    int ans = 1e9;

    rep(i, c){
        rep(j, c){
            rep(k, c){
                int sum = 0;
                if(i != j && j != k && i != k){
                    rep(l, c) sum += d[l][i] * t[0][l];
                    rep(l, c) sum += d[l][j] * t[1][l];
                    rep(l, c) sum += d[l][k] * t[2][l];
                    ans = min(ans, sum);
                }
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <set>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    int N;
    int words_size = 0;
    string before, current;
    set<string> words;
    
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> current;
        words.insert(current);
        if(words.size() == words_size){
            cout << "No" << endl;
            return 0;
        }
        words_size++;
        if(i > 0){
            if(before[before.size()-1] != current[0]){
                cout << "No" << endl;
                return 0;
            }
        }
        before = current;
    }
    
    cout << "Yes" << endl;
    
    return 0;
}


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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    ll N,A,B;
    Scll3(N,A,B);

    if( (B-A)%2 ) {
        ll ans = N*42;
        ans = min( ans, A + (B-A-1)/2 );

        ans = min( ans, N-B+1 + (N - (A+N-B+1) )/2 );

        printf ("%lld\n", ans );
    }else{
        printf ("%lld\n", (B-A)/2 );
    }

    return 0;
}



Measured memory_bytes: 256
solve :: Int -> Int -> String
solve x y
  | x `elem` [1,3,5,7,8,10,12] = if y `elem` [1,3,5,7,8,10,12] then "Yes" else "No"
  | x `elem` [4,6,9,11] = if y `elem` [4,6,9,11] then "Yes" else "No"
  | x `elem` [2] = if y `elem` [2] then "Yes" else "No"

main = do
  [x,y] <- fmap read <$> words <$> getLine :: IO[Int]
  putStrLn $ solve x y


Measured memory_bytes: 508
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

long long gcd(long long a, long long b) {
    if (a < b) return gcd(b, a);

    int r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

int main() {
    int n, m; cin >> n >> m;
    vector<long long> as(n);
    rep(i, n) cin >> as[i];

    for (auto& a: as) {
        a = a / 2;
    }

    long long res = 1;
    for (const auto& a: as) {
        res = lcm(res, a);
    }

    for (const auto& a: as) {
        if (res / a % 2 == 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    cout << (m / res + 1) / 2 << endl;
}


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair

using ll = long long;
using namespace std;

void solve() {
    string n; ll k;
    cin>>n>>k;
    int pos=0;
    while(n[pos]=='1')
    pos++;

    if(k<=pos) cout<<'1'<<'\n';
    else cout<<n[pos]<<'\n';
}

int main() 
{
    std::ios::sync_with_stdio(false); \
        std::cin.tie(NULL);
    int test;
    test=1;
    while (test--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3588
def insertionSort(A, N, g):
    for i in range(g, N):
        global count
        
        v = A[i]
        j = i - g
        while(j >= 0 and A[j] > v):
            A[j+g] = A[j]
            j = j - g
            count += 1
        A[j+g] = v

def shellSort(A, N, m, G):
    for i in range(m):
        insertionSort(A, N, G[i])
    
if __name__ == '__main__':
    N = int(input())
    A = [int(input()) for _ in range(N)]
    
    G = [0]
    for i in range(100):
        G.append(G[-1]+ 3**i)
    G.sort()
    G.remove(0)
    
    m = 0
    for i, g in enumerate(G):
        if g < N:
            m = i + 1
    if m == 0:
        m = 1
    G = G[:m]
    
    G.sort(reverse=True)
    
    count = 0
    
    shellSort(A, N, m, G)
    
    print(m)
    print(*G[:m])
    print(count)
    for a in A:
        print(a)


Measured memory_bytes: 45528
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int K = s.nextInt();
        int X=s.nextInt();
        long ans=X-(K-1);
        for(int i=0;i<(2*K-1);i++){
           System.out.print(ans);
           System.out.print("\t");
           ans++;
        }
    }
}


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

int main (void){
  int n = 0,a = 0;
  cin >> n;
  vector<string> s(n);

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

  sort(s.begin(),s.end());

  for(int i = 0;i < n;i++){
    if(s[i] != s[i + 1]){
      a++;
    }
  }

  cout << a << endl;

  return 0;
}

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

using std::cin;
using std::cout;



int main(int argc, char* argv[])
{
  std::ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int N, A, B;
  cin >> N >> A >> B;

  cout << std::min(A, B) << " " << std::max(std::max(A - (N-B), 0), std::max(B - (N-A), 0)) << "\n";

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    }    

  int main(){
      lint n,m;
      cin >>n>>m; vector<lint> A(n);
      lint ans=0;
      rep(i,n)cin >> A[i];
      sort(all(A));
        lint left=-1;
        lint right=INF;
        while(right-left>1){
            lint mid= left +(right-left)/2;
            lint count=0;
            lint y;
            rep(i,n){
                auto x=lower_bound(all(A),mid-A[i]);
                y=A.end()-x;
                count+=y;
            }
            if(count>=m)left=mid;
            else right=mid;
        }
       vector<lint> accum(n+1);
       accum[0]=0;
       rep(i,n){
           accum[i+1]=accum[i]+A[i];
       }
       rep(i,n){
            auto x=lower_bound(all(A),right-A[i]);
            lint num=A.end()-x;
            ans+=num*A[i]+accum[n]-accum[n-num];
            m-=num;
       }
       ans+=m*left;
       cout<<ans;

  }
  
  
     
  

Measured memory_bytes: 1792
#include<stdio.h>  
    main(){  
      int a;  
      scanf("%d",&a);  
      int x,y,b,p,d;  
      int c=0;  
      for(d=0;d<a;d++){  
        scanf("%d %d %d %d",&x,&y,&b,&p);  
        c=x*b+y*p;  
        if(b>=5&&p>=2){  
          c=c/5*4;  
        }  
        else if((b>5&&p<=2)&&c>(x*b+y*2)/5*4){  
          c=(x*b+y*2)/5*4;  
        }  
        else if((b<=5&&p>2)&&c>(x*5+y*p)/5*4){  
          c=(x*5+y*p)/5*4;  
        }  
        else if((b<=5&&p<=2)&&c>(x*5+y*2)/5*4){  
          c=(x*5+y*2)/5*4;  
        }  
        printf("%d\n",c);  
        c=0;  
      }  
      return 0;  
    }  

Measured memory_bytes: 600