akhauriyash/Code-Regression huggingface dataset:
#include "iostream"
#include "vector"
#include "iomanip"
#include "algorithm"

bool training(std::vector<long int> *a, std::vector<long int> f, std::vector<long int> *t, long int min, long int *k) {
	long int k_tmp = 0;
	std::vector<long int> a_tmp = *a;
	std::vector<long int> t_tmp = *t;
	for (int i = 0; i < a_tmp.size(); ++i){
		if (t_tmp[i] > min) {
			a_tmp[i] = min / f[i];
			t_tmp[i] = a_tmp[i] * f[i];
			k_tmp += ((*a)[i] - a_tmp[i]);
		}
	}
	if (k_tmp <= *k) {
		*k -= k_tmp;
		*a = a_tmp;
		*t = t_tmp;
		return true;
	}
	else
		return false;
}

int main() {
	long int n, k;
	std::cin >> n;
	std::cin >> k;

	std::vector<long int>a(n);
	for (long int i = 0; i < n; ++i)
		std::cin >> a[i];
	std::vector<long int>f(n);
	for (long int i = 0; i < n; ++i)
		std::cin >> f[i];

	std::sort(a.begin(), a.end());
	std::sort(f.begin(), f.end());
	std::reverse(f.begin(), f.end());

	std::vector<long int>t(n);
	long int max = 0;
	for (long int i = 0; i < n; ++i) {
		t[i] = a[i] * f[i];
		if (max < t[i])
			max = t[i];
	}

	long int min = 0;
	long int mid;

	while (max > min) {
		mid = (max + min) / 2;
		if (training(&a, f, &t, mid, &k))
			max = mid;
		else
			min = mid + 1;
	}

	std::cout << max << std::endl;
}

Measured memory_bytes: 9680
import numpy as np

n, k = map(int, input().split())

A = np.array(input().split(), np.int64)

A.sort()

posA = A[A > 0]
negA = A[A < 0]
zeros = (A==0).sum()

left = -10**18
right = 10**18

while left+1 < right:
    num = (left+right)//2
    
    less_count = 0
    
    if num >= 0:
        less_count += zeros * n
    
    limit_pair_for_pos = num // posA
    limit_idxs = np.searchsorted(A, limit_pair_for_pos, side='right')
    less_count += limit_idxs.sum()

    limit_pair_for_neg = (num+negA+1) // negA
    limit_idxs = n - np.searchsorted(A, limit_pair_for_neg, side='left')
    less_count += limit_idxs.sum()

    duplicate_cases = (A**2 <= num).sum()
    less_count -= duplicate_cases
    less_count //= 2
    
    if less_count >= k:
        right = num
    else:
        left = num

print(right)


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


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);

    ll X, Y; cin >> X >> Y;

    int ans = 0;
    while (X <= Y) {
        ans++;
        X *= 2;
    }
    cout << ans << '\n';

    return 0;
}


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

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


Measured memory_bytes: 256
import collections
import itertools


N=int(input())
A=list(map(int,input().split()))
data=collections.Counter(A)

def binbin(a,b,c):
    maxlen=max(len(bin(a)[2:]),len(bin(b)[2:]),len(bin(c)[2:]))
    data2={"x":(maxlen-len(bin(a)[2:]))*"0"+bin(a)[2:],"y":(maxlen-len(bin(b)[2:]))*"0"+bin(b)[2:],"z":(maxlen-len(bin(c)[2:]))*"0"+bin(c)[2:]}

    length=len(data2["x"])
    ite=itertools.permutations("xyz")
    for x,y,z in ite:
        data=[]
        for i in range(length):
            if not (int(data2[x][i]) + int(data2[y][i]))%2 == int(data2[z][i]):
                return(0)
    return(1)


if data[0]==N:
    print("Yes")
elif N%3==0:
    mc=data.most_common()
    if data[0] == N//3 and len(data)==2:
        print("Yes")
    elif len(data)==3 and binbin(mc[0][0],mc[1][0],mc[2][0]) and mc[0][1]==mc[1][1]==mc[2][1]:
        print("Yes")
    else:
        print("No")
else:
    print("No")


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

int main() {
  string S;
  cin >> S;
  int n = S.size(), mod2019[n+1], dig = 1, cnt[2019] = {};
  mod2019[n] = 0;
  cnt[0]++;
  for (int i=n-1; i>=0; i--) {
    mod2019[i] = (dig * (S[i]-'0') + mod2019[i+1]) % 2019;
    dig *= 10;
    dig %= 2019;
    cnt[mod2019[i]]++;
  }
  long ans = 0;
  for (int i=0; i<2019; i++)
    ans += cnt[i]*(cnt[i]-1)/2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4488
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	int n;
	string s;
	int red, blue;
	red = blue = 0;
	cin >> n;
	cin >> s;
	REP(i, n) {
		if (s[i] == 'R')red++;
		else blue++;
	}
	if (red > blue)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


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

using ll=long long;
const ll MOD=1000000007;

int main() {
  string s;
  cin >> s;
  if(s=="abc"||s=="bac"||s=="acb"||s=="bca"||s=="cab"||s=="cba")
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

void solve() {
    ll n, m;
    cin >> n >> m;
    ll h[n + 1];
    for(ll i = 1; i <= n; i++) cin >> h[i];
    vector<set<ll>> v(n + 1);
    for(ll i = 0; i < m; i++) {
        ll x, y;
        cin >> x >> y;
        v[x].emplace(h[y]);
        v[y].emplace(h[x]);
    }
    ll ans = 0;
    for(ll i = 1; i <= n; i++) {
        if(v[i].empty()) {ans++; continue;}
        if(h[i] > *v[i].rbegin()) ans++;
    }
    cout << ans;
}    

int main() {
    ios_base :: sync_with_stdio(false); 
    cin.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 17980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll n;
    cin>>n;
    for(int i = 1 ; i <= 9 ; i++){
        for(int j = 1 ; j <= 9 ; j++){
            if(i*j==n){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>

struct Line {
	int section;
	Line(const int s) : section{ s } {};
	virtual int y(const int x) const = 0;
};

struct Coordinate {
	int x, y;
	int distance_from(const Line& line) const {
		return std::abs(y - line.y(x));
	}
};
struct Line45 : public Line {
	int y(const int x) const override {
		return section + x;
	}
	Line45(const Coordinate& c) : Line{ c.y - c.x } {};
};
struct Line135 : public Line {
	int y(const int x) const override {
		return section - x;
	}
	Line135(const Coordinate& c) : Line{ c.y + c.x } {};
};


int main() {
	int n; std::cin >> n;
	std::vector<Coordinate> facility(n);
	for (auto& f : facility) std::cin >> f.x >> f.y;
	Line45 min_line45(facility.front()), max_line45(facility.front());
	Line135 min_line135(facility.front()), max_line135(facility.front());
	for (const auto& f : facility) {
		Line45 line45(f);
		Line135 line135(f);
		if (line45.section < min_line45.section) {
			min_line45 = line45;
		}
		if (line45.section > max_line45.section) {
			max_line45 = line45;
		}
		if (line135.section < min_line135.section) {
			min_line135 = line135;
		}
		if (line135.section > max_line135.section) {
			max_line135 = line135;
		}
	}
	auto min = 1;
	auto max = 400001;
	while (min < max) {
		auto mid = (min + max) / 2;
		bool can_separate = 
			std::all_of(facility.begin(), facility.end(), [mid, min_line45, max_line45, min_line135, max_line135](const Coordinate& f) {
			return (f.distance_from(min_line45) <= mid && f.distance_from(min_line135) <= mid) ||
				(f.distance_from(max_line45) <= mid && f.distance_from(max_line135) <= mid);
				}) ||
			std::all_of(facility.begin(), facility.end(), [mid, min_line45, max_line45, min_line135, max_line135](const Coordinate& f) {
					return (f.distance_from(max_line45) <= mid && f.distance_from(min_line135) <= mid) ||
						(f.distance_from(min_line45) <= mid && f.distance_from(max_line135) <= mid);
				});
				if (can_separate) {
					max = mid;
				}
				else {
					min = mid + 1;
				}
	}
	std::cout << max << '\n';
}


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


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

int main(){
  ll N,M;
  cin >> N >> M;
  vector<pair<ll,ll>> P(N);
  rep(i,N){
    cin >> P.at(i).first >> P.at(i).second;
  }
  sort(P.begin(),P.end());
  ll cnt=0,m=0;
  while(cnt<M){
    rep(i,N){
      ll t = M - cnt;
      if(t<=P.at(i).second){
        cnt += t;
        m += t * P.at(i).first;
      }else{
        cnt += P.at(i).second;
        m += P.at(i).first * P.at(i).second;
      }
    }
  }
  cout << m << endl;
}


Measured memory_bytes: 1792
let a,n,x=Array.make(4*3*10)0,read_int(),10;;for _=1to n do Scanf.scanf"%d %d %d %d
"(fun b f r v->let y=3*x*(b-1)+x*f-x+r-1 in a.(y)<-a.(y)+v)done;for b=1to 4do for f=1to 3do for r=1to 10do Printf.printf" %d"a.(3*x*(b-1)+x*f-x+r-1)done;print_newline()done;if b<>4then print_endline(String.make 20 '#')done

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

int gcd(int a, int b) {
	if (a < b) {
		int tmp = a;
		a = b;
		b = tmp;
	}
	if (b == 0) return a;
	int r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

int main() {
	int n, ans = 0;
	cin >> n;
	vector<int> a(n), l(n + 1, 0), r (n + 2, 0);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	// for (int i = 0; i < n; ++i) {
	// 	l[i + 1] = gcd(l[i], a[i]);
	// 	r[n - i] = gcd(r[n - i + 1], a[n - i - 1]);
	// }
	// for (int i = 0; i <= n; ++i) {
	// 	ans = max(ans, gcd(l[i], r[i + 2]));
	// }
	l[0] = a[0];
	for (int i = 1; i < n; ++i) {
		l[i] = gcd(a[i], l[i - 1]);
	}
	r[n - 1] = a[n - 1];
	for (int i = n - 2; i; --i) {
		r[i] = gcd(a[i], r[i + 1]);
	}
	for (int i = 0; i < n; ++i) {
		if (i == 0) {
			ans = max(ans, r[1]);
		}else if (i == n - 1) {
			ans = max(ans, l[i - 1]);
		}else {
			ans = max(ans, gcd(l[i - 1], r[i + 1]));
		}
	}
	cout << ans << "\n";
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}




template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WG = vector< Edges< T > >;
using UG = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;


main(){
  int n;
  cin>>n;
  UG es(n);
  vector<P> v(n);
  rep(i,n){
    v[i].S=i;
  }
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    a--; b--;
    v[a].F++;
    v[b].F++;
    es[a].PB(b);
    es[b].PB(a);
  }

  vector<int> c(n);
  rep(i,n){
    cin>>c[i];
  }

  sort(all(v));
  sort(all(c));
  reverse(all(c));
  vector<int> res(n,-1);

  queue<int> q;
  int t=0;
  q.push(v[0].S);
  while(!q.empty()){
    int x=q.front(); q.pop();
    //cout<<x<<endl;
    if(res[x]!=-1) continue;
    res[x]=c[t];
    t++;
    for(auto e:es[x]){
      q.push(e);
    }
  }


  int ans=0;

  rep(i,n){
    for(auto e:es[i]){
      ans+=min(res[i],res[e]);
    }
  }

  cout<<ans/2<<endl;
  rep(i,n){
    cout<<res[i]<<' ';
  }
  cout<<endl;

}


Measured memory_bytes: 1280
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;

int n;
int x;
int ar[N];

int main(){
    cin >> n >> x;
    for(int i = 1; i <= n; i++){
        cin >> ar[i];
    }
    long long ans = 0;
    for(int i = 2; i <= n; i++){
       long long nw = ar[i - 1] + ar[i];
       if(nw > x){
          ans += nw - x;
          long long dec = ar[i] - min(nw - x , 1ll*ar[i]);
          ar[i] = dec;
       } else {
          continue;
       }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#[allow(dead_code)]
fn is_whitespace(c: &char) -> bool {
    c.is_whitespace()
}

#[allow(dead_code)]
fn is_eol(c: &char) -> bool {
    ['\r', '\n'].contains(c)
}

#[allow(unused_macros)]
macro_rules! input {
    ($var:ident, $($r:tt)*) => {
        input_inner!{$var, $($r)*}
    };

    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_mut, unused_variables, bare_trait_objects)]
        let mut next = move |f: &Fn(&char)->bool| -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|f(&c))
                .take_while(|c|!f(&c))
                .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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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 ; eol ]) => {
        $next(&is_eol).split(' ').map(|x| x.parse::<$t>().unwrap()).collect::<Vec<_>>()
    };

    ($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, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, parser) => {
        $next
    };

    ($next:expr, $t:ty) => {
        $next(&is_whitespace).parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};

#[allow(dead_code)]
struct Edge {
    from: usize,
    to: usize,
}

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;
#[allow(dead_code)]
const M: usize = 1_000_000_007;

fn main() {
    input! {
        n: usize,
    }

    let mut primes = vec![0; 1001];
    for i in 2..=n {
        let mut v = i;
        for j in 2..=i {
            while v % j == 0 {
                primes[j] += 1;
                v /= j;
            }
        }
        if v > 1 {
            primes[v] += 1;
        }
    }
    let mut a = 1usize;
    for x in primes {
        a *= x + 1;
        a %= 1000000007;
    }
    println!("{}", a);
}


Measured memory_bytes: 2120
#include<stdio.h>
#include<math.h>
int main(){
    int a,b,c,d=1,wei=0,e;
    scanf("%d%d",&a,&b);
    c=b;
    while(c){
    	wei++;
    	c/=10;
	}
	for(wei;wei>0;wei--){
		d*=10;
	}
	c=a*d+b;
	e=sqrt(c);
	if(e*e==c)printf("Yes");
	else printf("No");
	return 0;
}

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


int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if (abs(b -a) <= d){
        if (abs(c - b) <= d){
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    } else if (abs(c -a) <= d){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3632
#include <stdio.h>
using namespace std;

int gcd(int x, int y) {
  if (x == 0) return y;
  if (y == 0) return x;
  if (x >= y) return gcd(y, x%y);
  else return gcd(x, y%x);
}

int main() {
  int a, b;
  scanf("%d %d", &a, &b);
  printf("%d\n", gcd(a, b));
  return 0;
}



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

public class P
{
    public int x { get; set; }
    public int y { get; set; }
    public string via { get; set; }
}

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var h = int.Parse(line[0]);
        var w = int.Parse(line[1]);
        var map = new bool[h, w];
        for (int i = 0; i < h; i++)
        {
            var s =Console.ReadLine().Trim();
            for (int j = 0; j < w; j++)
                if (s[j] == '#') map[i, j] = true;
        }
        Console.WriteLine(goDfs(map) ? "Possible": "Impossible");
    }
    public static bool   goDfs (bool[,] map)
    {
        var h = map.GetLength(0);
        var w = map.GetLength(1);
      var st = new Queue<P>();
        st.Enqueue(new P { x = 0, y = 0, via = "" });
        while (st.Count() > 0)
        {
            var t = st.Dequeue();
            if (t.x == h - 1 && t.y == w - 1 && checkVia(map, t.via)) return true;
         if (t.y + 1 < w && map[t.x, t.y +1] )  st.Enqueue(new P { x = t.x, y = t.y + 1, via = t.via + "r" });
            if (t.x + 1 < h && map[t.x+1, t.y ]) st.Enqueue(new P { x = t.x+1, y = t.y , via = t.via + "d" });
        }
        return false;   
    }
    public static bool checkVia (bool [,] map , string a)
    {
        var h = map.GetLength(0);
        var w = map.GetLength(1);
        var map2 = new bool[h, w];
        var x = 0;  var y = 0;  map2[0, 0] = true;
        for (int i = 0; i < a.Length; i++)
        {
            if (a[i] == 'r') y++;
            else x++;
            map2[x, y] = true;
        }
        for (int i = 0; i < h; i++)
            for (int j = 0; j < w; j++)
                if (map[i, j] != map2[i, j]) return false;
        return true;
    }
}


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

int f(int n) {
    int result = 0;
    while (n%2 == 0) {
        n = n / 2;
        result++;
    }
    return result;
}

int main() {
    int n; cin >> n;
    int a[200];
        for (int i=0; i<n; i++) {
            cin >> a[i];
        }
    int ans = 100;
    for (int i=0; i<n; i++) {
        ans = min(ans, f(a[i]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		long c = in.nextLong();
		long[] x = new long[n];
		long[] v = new long[n];
		for(int i=0;i<n;i++) {
			x[i] = in.nextLong();
			v[i] = in.nextLong();
		}
		
		long[] sum1 = new long[n];
		sum1[0] = v[0];
		long[] sum2 = new long[n];
		sum2[0] = v[n-1];
		for(int i=1;i<n;i++) {
			sum1[i] = sum1[i-1] + v[i];
			sum2[i] = sum2[i-1] + v[n-1-i];
		}
		
		long[] dp1 = new long[n+1];
		long[] dist1 = new long[n+1];
		if(sum1[0]-x[0]>0) {
			dp1[1] = sum1[0]-x[0];
			dist1[1] = x[0];
		}
		for(int i=1;i<n;i++) {
			if(sum1[i]-x[i]>dp1[i]) {
				dp1[i+1] = sum1[i]-x[i];
				dist1[i+1] = x[i];
			}else {
				dp1[i+1] = dp1[i];
				dist1[i+1] = dist1[i];
			}
		}
		
		long[] dp2 = new long[n+1];
		long[] dist2 = new long[n+1];
		if(sum2[0]-c+x[n-1]>0) {
			dp2[1] = sum2[0]-c+x[n-1];
			dist2[1] = c-x[n-1];
		}
		for(int i=1;i<n;i++) {
			if(sum2[i]-c+x[n-1-i]>dp2[i]) {
				dp2[i+1] = sum2[i]-c+x[n-1-i];
				dist2[i+1] = c-x[n-1-i];
			}else {
				dp2[i+1] = dp2[i];
				dist2[i+1] = dist2[i];
			}
		}
		
		long max = Math.max(dp1[n], dp2[n]);
		for(int i=1;i<n;i++) {
			if(max<dp1[i]+dp2[n-i]-Math.min(dist1[i], dist2[n-i])) {
				max = dp1[i]+dp2[n-i]-Math.min(dist1[i], dist2[n-i]);
			}
		}
		
		System.out.println(max);
		
		in.close();

	}

}


Measured memory_bytes: 92492
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    ll tmp = n / 1.08;
    if ((ll)(tmp * 1.08) != n && (ll)((tmp + 1) * 1.08) != n) cout << ":(\n";
    else if ((ll)(tmp * 1.08) == n) cout << tmp << '\n';
    else cout << tmp + 1 << '\n';
    return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
stu=[[0,0] for i in range(n)]
po=[[0,0] for i in range(m)]
for i in range(n):
    a,b=map(int,input().split())
    stu[i][0]=a
    stu[i][1]=b
for i in range(m):
    c,d=map(int,input().split())
    po[i][0]=c
    po[i][1]=d
ans=[]
for i in range(n):
    x=stu[i][0]
    y=stu[i][1]
    dis=[]
    for j in range(m):
        dis.append(abs(x-po[j][0])+abs(y-po[j][1]))
    ans.append(dis.index(min(dis)))
for i in range(n):
    print(ans[i]+1)



Measured memory_bytes: 9240
S = int(input())

if 0 < S//100 < 13:
    if 0 < S%100 < 13:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if 0 < S%100 < 13:
        print('YYMM')
    else:
        print('NA')

Measured memory_bytes: 9160
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

class UnionFind {
private:
	int n, s;
	vector<int> p_id;
	vector<vector<int>> v;
public:
	UnionFind(int n = 0) { init(n); }
	void init(int arg_n) {
		n = s = arg_n;
		p_id.clear();
		v.clear();
		inc(i, n) { p_id.PB(i); v.EB(1, i); }
	}
	int id(int i) { return p_id.at(i); }
	bool unite(int x, int y) {
		x = id(x);
		y = id(y);
		if(x == y) { return false; }
		if(v[x].size() < v[y].size()) { swap(x, y); }
		for(auto & e: v[y]) { v[x].PB(e); p_id[e] = x; }
		v[y].clear();
		s--;
		return true;
	}
	const vector<int> & operator[](int i) { return v[id(i)]; }
	int size() { return s; }
	int get_n() const { return n; }
	const vector<vector<int>> & get_v() const { return v; }
};
ostream & operator<<(ostream & os, const UnionFind & uf) {
	inc(i, uf.get_n()) { os << i << ": "; for(auto & e: uf.get_v()[i]) { os << e << " "; } os << "\n"; }
	return os;
}

// ---- ----

LL f(LL x) { return x * (x - 1) / 2; }

LL n, m, a[100000], b[100000];

int main() {
	cin >> n >> m;
	inc(i, m) { cin >> a[i] >> b[i]; a[i]--; b[i]--; }
	
	UnionFind uf(n);
	vector<LL> ans;
	LL x = f(n);
	dec(i, m) {
		ans.PB(x);
		
		if(uf.id(a[i]) != uf.id(b[i])) {
			LL as = uf[a[i]].size();
			LL bs = uf[b[i]].size();
			x += f(as);
			x += f(bs);
			x -= f(as + bs);
			uf.unite(a[i], b[i]);
		}
	}
	
	dec(i, SI(ans)) { cout << ans[i] << "\n"; }
	
	return 0;
}


Measured memory_bytes: 13744
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(), v.end()
#define PI 3.141592653589793238462643383279
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
typedef long long int ll;
typedef unsigned long long ull;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
typedef pair<ll,ll> P;
const long long MOD = 1e9+7;
const ll INF = 1LL << 60;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};

int main(){
    vector<int> a(4);
    rep(i,4)cin >> a[i];
    sort(all(a));
    cout << (abs((a[3]+a[0])-(a[1]+a[2]))) << endl;

}


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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 1000000000000
#define MOD 1000000007
#define MAX 2100000
using ll = long long;


int main(){
  string s; cin >> s;
  vector<string> y = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
  rep(i,7){
    if(y.at(i)==s){
      cout<<7-i<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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 REP(i,a) FOR(i,0,(int)(a)-1)
#define reset(a,b) memset(a,b,sizeof(a))
#define all(x) x.begin(), x.end()
#define uni(x) x.erase(unique(all(x)), x.end());
#define BUG(x) cout << #x << " = " << x << endl
#define BUGP(x) cout << #x << " = " << x._1 << ", " << x._2 << endl
#define PR(x,a,b) {cout << #x << " = "; FOR (_,a,b) cout << x[_] << ' '; cout << endl;}
#define CON(x) {cout << #x << " = "; for(auto _i:x) cout << _i << ' '; cout << endl;}
#define mod 1000000007
#define pi acos(-1)
#define eps 1e-6
#define pb push_back
#define sqr(x) (x) * (x)
#define _1 first
#define _2 second

int n, m, cnt[200005], u, v;

int main() {
	ios::sync_with_stdio(false);
	cin >> n >> m;
	while (m--) {
		cin >> u >> v;
		if (u == 1) cnt[v]++;
		if (v == n) cnt[u]++;
	}
	FOR (i, 1, n) if (cnt[i] > 1) {
		cout << "POSSIBLE";
		return 0;
	}
	cout << "IMPOSSIBLE";
}	


Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=(a);i<=(b);++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define ti3 tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
ll int MOD=1e9+7;
#define N 300000
 
using namespace std;
string alphabet("abcdefghijklmnopqrstuvwxyz");
main(){
    ll int n;
    ll int a[N];
    cin>>n;
    n=pow(2,n);
    rep(i,n){
        cin>>a[i];
    }
    ll int sum[N]={};
    ll int m[N][2]={};
    sum[1]=a[0]+a[1];
    m[0][0]=a[0];m[0][1]=0;
    rep2(i,1,n-1){
        ll int max1=a[i],max2=a[0];
        int max1pos=i,max2pos=0;
        if(max1<max2) {swap(max1,max2);swap(max1pos,max2pos);}
        rep(j,18){
            ll int t=pow(2,j);
            if(t&i){
                if(m[i-t][1]!=max1pos&&m[i-t][1]!=max2pos)
                max2=max(max2,m[i-t][0]);
                if(max2==m[i-t][0]) max2pos=m[i-t][1];
                if(max2>max1) {swap(max2,max1); swap(max2pos,max1pos);}
            }
        }
        m[i][0]=max1; m[i][1]=max1pos;
        sum[i]=max(sum[i-1],max1+max2);
    }
    rep2(i,1,n-1){
        cout<<sum[i]<<endl;
    }
   
    return 0;
}

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

int main() {
  char a;
  cin >> a;
  
  if(a=='A'){
    cout << 'T' << endl;
  }
  else if(a=='T'){
    cout << 'A' << endl;
  }
  else if(a=='C'){
    cout << 'G' << endl;
  }
  else{
    cout << 'C' << endl;
  }
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long int n,ans;
    cin>>n;
    ans=n*(n+1)/2 - 3*(n/3)*(n/3 + 1)/2 - 5*(n/5)*(n/5 + 1)/2 + 15*(n/15)*(n/15+1)/2;
    cout<<ans;
        return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long i = 0; i < n; i++)
#define erep(i, n) for(long i = 1; i <= n; i++)
const long MOD = 1000000007;

int main() {long N;
cin >> N;
vector<long> a(N);
rep(i, N) cin >> a.at(i);
sort(a.begin(), a.end());
bool nashi = false;
long ans = 1;
if(N % 2 == 1){
    if(a.at(0) != 0) nashi = true;
    for(long i = 2; i <= N - 1; i = i + 2){
        if(a.at(i - 1) != i || a.at(i) != i) nashi = true;
    }
    for(long i = 1; i <= (N - 1) / 2; i++){
        ans = ans * 2 % MOD;
    }
}
else{
    for(long i = 1; i <= N - 1; i = i + 2){
        if(a.at(i - 1) != i || a.at(i) != i) nashi = true;
    }
    for(long i = 1; i <= N / 2; i++){
        ans = ans * 2 % MOD;
    }
}

if(nashi == true) ans = 0;
cout << ans << endl;
  return 0;
 
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define emp empty()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define br break
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0, so x)
#define all(x) (x).be , (x).en
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;

int main()
{
    ios;
    ll n , l ;
    cin >> n >> l ;
    vl v;
    forn(i , 1, n ){
      ll foo = l + i - 1 ;
      v.pb(foo);
    }
    ll sum = acc(v);
    sort(all(v));
    vll ziz ;
    forn(i , 0 , n-1){
       ll res = sum - v[i] ;
       ll diff = abs(res - sum)  ;
       ziz.pb({diff , res});
    }
    sort(all(ziz));
    cout << ziz[0].se << el ;
}































Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
using namespace std;
#define PI 3.14159265358979
typedef  long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#include<set>


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

int main(void)
{
    ll n;
  
    cin>>n; 
    vector<ll> a(n+4);
    for(int i=1;i<n;i++)
    {
        ll boss;
        cin>>boss;
        a[boss] ++;

    }

    for(int i=1;i<=n;i++)
    {
        cout<<a[i]<<endl;
    }





}

Measured memory_bytes: 4844
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		while(true){
			String input = br.readLine();
			
			if(input == null){
				break;
			}
			
			int numOfJOI = 0;
			int numOfIOI = 0;
			
			for(int i = 0; i < input.length() - 2; i++){
				String sub = input.substring(i, i+3);
				if(sub.equals("JOI")){
					numOfJOI++;
				}
				else if(sub.equals("IOI")){
					numOfIOI++;
				}
			}
			
			System.out.println(numOfJOI);
			System.out.println(numOfIOI);
			
		}
	}

}

Measured memory_bytes: 25452
n = gets.to_i
h = gets.split.map(&:to_i)

ans = 0
l = 0
r = 0
while l = h.find_index{ |i| i != 0 } do
  m = 101
  l.upto(n - 1) do |i|
    v = h[i]
    break if v == 0 
    r = i
    m = v if v < m   
  end
  h.fill(l..r) do |i|
    h[i] - m
  end
  ans += m
end
puts ans



Measured memory_bytes: 3836
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner s = new Scanner(System.in);
    int a = s.nextInt();
    int b = s.nextInt();
    int c = s.nextInt();
    int sum = 0;
    int ok = 0;
    for(int i = 0; i < 1000; i++){
      sum = a + sum;
      if(sum < (double)c+0.5){
        ok = ok + b;
      }else if(sum > (double)c+0.5){
        break;
      }
    }
    System.out.println(ok);
  }
}


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

int main() {
  int A,B,C;
  cin >> A >> B >> C;
  for(int i=1;i<B+1;i++){
    if((A*i)%B==C){
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n;
  cin >> n;
  vec x(n),y(n);
  for(ll i=0;i<n;i++) cin >> x[i] >> y[i];
  ll ans=0;
  for(ll i=0;i<n;i++) {
    for(ll k=0;k<n;k++) {
      ll dx=x[k]+x[i],dy=y[k]+y[i];
      if(dx*dx+dy*dy==0) continue;
      ll sx=0,sy=0;
      for(ll j=0;j<n;j++) {
        if(dx*x[j]+dy*y[j]>=0) {
          sx+=x[j];
          sy+=y[j];
        }
      }
      ans=max(ans,sx*sx+sy*sy);
    }
  }
  cout << fixed << setprecision(20) << sqrt(ans) << endl;
}

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

int main() {
    int n, m;
    int p[100100], y[100100];
    cin >> n >> m;
    for (int i = 0; i < m; i++) cin >> p[i] >> y[i];

    vector<int> name[100100]; //vectorをたくさん作る
    for (int i = 0; i < m; i++) name[p[i]].push_back(y[i]);

    for (int i = 0; i < n; i++) sort(name[i + 1].begin(), name[i + 1].end()); //i+1なのはp>=1なので

    for (int i = 0; i < m; i++) {
        cout << setw(6) << setfill('0') << p[i];
        vector<int>::iterator itr = lower_bound(name[p[i]].begin(), name[p[i]].end(), y[i]);
        cout << setw(6) << setfill('0') << distance(name[p[i]].begin(), itr) + 1 << endl;
    }
    return 0;
}

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

#define MAX 51

bool field[MAX][MAX];
int cnt;
int H, W;

void dfs(int x, int y){
  field[x][y] = 0;
  
  for(int dx = -1 ; dx <= 1 ; dx++){
    for(int dy = -1 ; dy <= 1 ; dy++){
      int nx = x + dx;
      int ny = y + dy;
      if(0 <= nx && nx < H && 0 <= ny && ny < W && field[nx][ny] == 1) dfs(nx, ny);
    }
  }
}

int main(){
  while(cin >> W >> H){
    cnt = 0;
    if(W == 0 && H == 0) break;
    for(int i = 0 ; i < H ; i++){
      for(int j = 0 ; j < W ; j++){
	cin >> field[i][j];
      }
    }

    for(int i = 0 ; i < H ; i++){
      for(int j = 0 ; j < W ; j++){
	if(field[i][j] == 1){
	  dfs(i, j);
	  cnt++;
	}
      }
    }
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 0
import java.util.*;

class Main {
  public static String sayChristmas(int day) {
    String phrase = "Christmas";
    if(25 - day > 0) {
      for(int i = 0; i < 25 - day; i++) {
        phrase += " Eve";
      }
    }
    return phrase;
  }
  
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    
    int day = Integer.parseInt(scanner.nextLine());
    
    System.out.println(sayChristmas(day));
  }
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
inline int read(){
	int x=0;char ch=getchar();
	while (!isdigit(ch)) ch=getchar();
	while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x;
}
char s[105];
int n,ans=0x3f3f3f3f;
vector<int> vec;
int main(){
	scanf ("%s",s);n=strlen(s);
	for (int c='a';c<='z';++c){
		vec.clear();vec.push_back(-1);
		for (int i=0;i<n;++i)
			if (s[i]==c) vec.push_back(i);
		int mx=0;
		for (int i=0;i<(int)vec.size()-1;++i) mx=max(mx,vec[i+1]-vec[i]-1);
		ans=min(ans,max(mx,n-vec[vec.size()-1]-1));
	}
	printf ("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
// finish date: 2018/01/21
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define bigmod 1000000007
#define INF 500000000


int main() {
    string S;
    cin >> S;
    S = S.substr(0, S.length() - 1);
    if (S.length() % 2 == 1) S = S.substr(0, S.length() - 1);
    while (S.substr(0, S.length() / 2) != S.substr(S.length() / 2, S.length() / 2)) {
        S = S.substr(0, S.length() - 2);
    }
    cout << S.length() << endl;
    return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i

p = n / 7
q = n / 4

flag = false
(p + 1).times do |i|
  (q + 1).times do |j|
    if i * 7 + j * 4 == n then
      flag = true
      break
    end
  end
  
  if flag then
    break
  end
end
    
puts (flag ? "Yes" : "No")

Measured memory_bytes: 3836
import           Control.Applicative
import           Control.Monad
import           Data.List
import           Text.Printf

-- [5, 3, 1, 3, 4, 3]
-- [(5,-inf), (min(5,3), max(5-3,-inf)=(3,-2), (min(3,1), max(1-3,-2))=(1,-2),...]

main = do
    n<- getLine
    a<- map (read::String->Int) <$> replicateM (read n) getLine
    print $ snd $ foldl work (inf, -inf) a
      where
        inf = 10^10
        work (cur_min, ans) x = (min cur_min x, max (x-cur_min) ans)


Measured memory_bytes: 162904
#include <iostream>
using namespace std;
int C[26] = {0};
string S;
int main(){
  cin >> S;
  int N = S.size(); 
  for(int i=0;i<N;i++){
    C[S[i]-'a']++;
  }
  for(int i=0;i<26;i++){
    if(C[i]%2!=0){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

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

void solve();

int A,B,C;

int main()
{
    scanf("%d%d%d",&A,&B,&C);
    solve();
    return 0;
}

void solve()
{
    if(A % 2 || B % 2 || C % 2)
    {
        printf("0\n");
        return;
    }
    if(A == B && B == C && A == C)
    {
        printf("-1\n");
        return;
    }
    int ans = 0;
    while(!(A % 2 || B % 2 || C % 2))
    {
        ans++;
        int nA = A,nB = B,nC = C;
        A = (nB + nC) / 2;
        C = (nB + nA) / 2;
        B = (nA + nC) / 2;
    }
    printf("%d\n",ans);
    return;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>

#define rep(i,n) for (int i = 0;i < n;i++)
using ll = long long;
using namespace std;

const int INF = 1001001001;
const int MOD = 1000000007;


int main(void){
	int n;cin >> n;
	vector<int> h(n);		// コスト配列
	rep(i,n) cin >> h[i];

	queue<int> q;
	q.push(0);
	vector<int> c(n, INF);
	c[0] = 0;				// DP配列

	rep(i,n){
		int cur_v = i;
		auto change = [&](int i){
			c[cur_v+i] = min(c[cur_v+i], c[cur_v] + abs(h[cur_v+i] - h[cur_v]));
		};

		if (cur_v+1 < n){
			change(1);
			q.push(cur_v+1);
		}
		if (cur_v+2 < n){
			change(2);
			q.push(cur_v+2);
		}
	}
	cout << c[n-1] << endl;

	return 0;
}

Measured memory_bytes: 1792
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

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

	ll n, a, b;
	string s;
	cin >> n >> a >> b >> s;

	ll x = 0, y = 0;
	for (ll i = 0; i < n; i++) {
		if (s[i] == 'a') {
			if (x + y < a + b) {
				Yes();
				x++;
			}
			else No();
		}
		else if (s[i] == 'b') {
			if (x + y < a + b && y < b) {
				Yes();
				y++;
			}
			else No();
		}
		else No();
	}
}


Measured memory_bytes: 848
#![allow(non_snake_case)]

#[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)*} }; }
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)*} };}
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, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

fn main() {
    input!{
        n: String,
    }
    println!(
        "{}",
        n.chars()
            .map(|c| if c == '1' { '9' } else { '1' })
            .collect::<String>()
    );
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,hh,tot,rt,e[500010],nt[500010],hd[500010],sz[500010],a[500010],val[500010],ans;
void build(ll x,ll y,ll w){
	tot++;
	e[tot]=y;val[tot]=w;
	nt[tot]=hd[x];hd[x]=tot;
}
void dfs(ll x,ll fa,ll w){
	ll i,mx=0;
	sz[x]=1;
	//printf("%lld %lld %lld\n",x,fa,w);
	for(i=hd[x];i;i=nt[i]){
		if(e[i]==fa)continue;
		dfs(e[i],x,val[i]);sz[x]+=sz[e[i]];
		mx=max(mx,sz[e[i]]);
	}
	ans+=min(sz[x],n-sz[x])*2*w;
	mx=max(mx,n-sz[x]);
	a[x]=mx;
	if(mx<hh){
		hh=mx;rt=x;
	}
}
int main(){
	ll i,x,y,w,xlh=1e18;
	scanf("%lld",&n);
	hh=n+1;
	for(i=1;i<n;i++){
		scanf("%lld%lld%lld",&x,&y,&w);
		build(x,y,w);build(y,x,w);
	}
	dfs(1,0,0);
	//printf("%lld\n",ans);
	for(i=hd[rt];i;i=nt[i]){
		xlh=min(xlh,val[i]);
		if(a[rt]==a[e[i]]){
			printf("%lld",ans-val[i]);
			return 0;
		}
	}
	printf("%lld",ans-xlh);
}

Measured memory_bytes: 26240
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int res=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
	while(ch>='0'&&ch<='9'){res=(res<<3)+(res<<1)+ch-'0';ch=getchar();}
	return res*f;
}
void write(int x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10|'0');
}
const int N=200005;
int n,nn,a[N],b[N],l,r;
inline bool check(int k){
	for(int i=1;i<=nn;i++)
		if(a[i]<k) b[i]=0;
		else b[i]=1;
	int pos1=1e8,pos0=1e8;	
	for(int i=1;i<nn;i++)
		if(b[i]==b[i+1]){
			if(b[i]) pos1=min(pos1,min(abs(n-i),abs(n-(i+1))));
			else pos0=min(pos0,min(abs(n-i),abs(n-(i+1))));
		}
	if(pos1==1e8&&pos0==1e8)return (n&1)==b[n];
	return pos1<pos0;
}
int main(){
//	freopen("pyramid.in","r",stdin);
//	freopen("pyramid.out","w",stdout);
	n=read();nn=2*n-1;
	for(int i=1;i<=nn;i++){
		a[i]=read();
	}
	l=-1;r=1e8;
	while(r-l>1){
		int mid=(l+r)>>1;	
		if(check(mid)) l=mid;
		else r=mid;
	}	
	write(l);
	return 0;
}

Measured memory_bytes: 1792
L = int(input())
A = [int(input()) for i in range(L)]
X = [[0] * 5 for _ in range(L+1)]

X[0] = [0] * 5
for i in range(L):
    X[i+1][0] = X[i][0] + A[i]
    X[i+1][1] = min(X[i][0], X[i][1]) + (A[i] % 2 if A[i] > 0 else 2)
    X[i+1][2] = min(X[i][0], X[i][1], X[i][2]) + ((A[i]+1) % 2)
    X[i+1][3] = min(X[i][0], X[i][1], X[i][2], X[i][3]) + (A[i] % 2 if A[i] > 0 else 2)
    X[i+1][4] = min(X[i][0], X[i][1], X[i][2], X[i][3], X[i][4]) + A[i]

print(min(X[-1]))

Measured memory_bytes: 90080
#include <stdio.h>

long long dp[102][100005],w[102],v[102];
long long N,W;

long long max(long long a,long long b) {return (a>b?a:b);}

long long solve(int index,long long weight)
{
  if(index>=N) return 0;
  if(weight<w[index]) return dp[index][weight]=solve(index+1,weight);
  if(dp[index][weight]!=-1) return dp[index][weight];
  else return dp[index][weight]=max(solve(index+1,weight-w[index])+v[index],solve(index+1,weight));
}

int main()
{
  long long ans;
  scanf("%lld%lld",&N,&W);
  for(int i=0;i<N;i++)
    scanf("%lld%lld",&w[i],&v[i]);
  for(int i=0;i<102;i++)
    for(int j=0;j<100005;j++) dp[i][j]=-1;
  ans=solve(0,W);
  printf("%lld",ans);
    return 0;
}



Measured memory_bytes: 79872