akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,m;cin>>n>>m;
  vector<ll>a(n+1);
  rep(i,m){
    ll l,r;cin>>l>>r;
    l--;
    a[l]++;
    a[r]--;
  }
  rep(i,n)a[i+1]+=a[i];
  ll cnt=0;
  rep(i,n)if(a[i]==m)cnt++;
  cout<<cnt<<endl;
  return 0;

}


Measured memory_bytes: 1024
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>

std::vector<std::vector<long long> > to(100000+5);
long long N;
std::vector<long long> length(100000+5);

void dfs(long long start, long long parent=-1){
  for (long long i=0; i<to[start].size(); i++){
    if (to[start][i]==parent){
      continue;
    }
    length[to[start][i]] = length[start]+1;
    dfs(to[start][i], start);
  }
  return;
}

void calculate_dist(long long start){
  length[start] = 0;
  dfs(start);
  return;
}

int main(){
  scanf("%lld", &N);
  long long takahashi, aoki;
  scanf("%lld",&takahashi);
  scanf("%lld", &aoki);
  takahashi--;
  aoki--;
  
  long long temp1, temp2;
  for (long long i=0; i<N-1; i++){
    scanf("%lld",&temp1);
    scanf("%lld",&temp2);
    temp1--;
    temp2--;
    to[temp2].push_back(temp1);
    to[temp1].push_back(temp2);
  }

  calculate_dist(aoki);
  std::vector<long long > dist_aoki = length;
  calculate_dist(takahashi);
  std::vector<long long > dist_takahashi = length;

  long long ans = 0;
  for (long long i=0; i<N; i++){
    //printf("dist_aoki[%lld]=%lld\n", i, dist_aoki[i]);
    //printf("dist_takahashi[%lld]=%lld\n", i, dist_takahashi[i]);
    if (dist_aoki[i] > dist_takahashi[i]){
      ans = fmax(ans, dist_aoki[i]);
    }
  }
  ans--;
  printf("%lld\n", ans);
  return 0;
}


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

int main() {
  int N,M,max = 0;
  cin >> N;
  vector<string>S(N),T(M);
  
  for ( int i = 0 ; i < N ; i++ )
    cin >> S.at(i);
  cin >> M;
  for ( int j = 0 ; j < M ; j++ )
    cin >> T.at(j);
  
  for ( int k = 0 ; k < N ; k++ ) {
    int count = 0;
    for ( int l = 0 ; l < N ; l++ ) {
      if ( S.at(l) == S.at(k))
        count++;
    }
    for ( int m = 0 ; m < M ; m++ ) {
      if ( T.at(m) == S.at(k))
        count--;
    }
    if ( count > max )
      max = count;
  } 
  cout << max << endl;
}    

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;
ll prime(ll x){
   if(x<=1)return false;
   for(int i=2;i<=int(sqrt(x));i++){
	   if(x%i==0)return false;
   }return true;
}
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
template <typename T>
inline void read(T &x) {
	char c = getchar(); int w = 1; x = 0;
	while (!isdigit(c))
		(c == '-') && (w = -w), c = getchar();
	while (isdigit(c))
		x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar();
	x *= w;
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
		  dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
int main(){
	fast;
	string a,b;
	cin>>a>>b;
	ll sum=0;
	for(int i=0;i<3;i++){
		if(a[i]==b[i])sum++;
	}cout<<sum<<endl;
	return 0;
}/*『你强归你强，我永不示弱』*/


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int A[5][4][11];
    int n, b, f, r, v;
    cin >> n;
    
    for (int i = 1; i < 5; i++){
        for (int j = 1; j < 4; j++){
            for (int k = 1; k < 11; k++){
                A[i][j][k] = 0;
            }
        }
    }
    for (int i = 1; i <= n; i++){
        cin >> b >> f >> r >> v;
        A[b][f][r] += v;
    }
    for (int i = 1; i < 5; i++){
        for (int j = 1; j < 4; j++){
            for (int k = 1; k < 11; k++){
                cout << ' ' << A[i][j][k];
            }
            cout << endl;
        }
        if(i == 4)continue;
        else{
            cout << string(20, '#') << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int mod=1000000007;

int main()
{
	string a,b,ans="";
	int i,j;
	cin>>a>>b;
	int n=a.length(),m=b.length();
	int dp[n+1][m+1];
	if(a[0]==b[0]) j=1; 
	else j=0;
	for(i=0;i<=m;i++) dp[0][i]=0;
	for(i=0;i<=n;i++) dp[i][0]=0;
 	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			if(a[i-1]==b[j-1]) dp[i][j]=1+dp[i-1][j-1];
			else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		}
	}
//	cout<<dp[n-1][m-1];
	int p=dp[n][m];
	i=n,j=m;
	while(p)
	{
		if(a[i-1]==b[j-1]) 
		{
		ans.pb(a[i-1]); i--; j--; p--;
		}
		else if(i&& dp[i][j]==dp[i-1][j]) i--;
		else j--;
		
	}
	reverse(ans.begin(),ans.end());
	cout<<ans;
	return 0;

}

Measured memory_bytes: 35456
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n, k, s = [int(x) for x in input().split()]
    ans = [0] * n
    for i in range(n):
        if i < k:
            ans[i] = s
        else:
            x = n - k
            z = s + 1
            if s == int(1e9):
                z -= 10
            ans[i] = z
    print(*ans)


t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

abc

"""


Measured memory_bytes: 14216
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <climits>
#include <memory>
#include <sstream>
#include <iomanip>
#include <cstdio>

using namespace std;

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	long long n, a, b, c, d, e;
	cin >> n;
	cin >> a;
	cin >> b;
	cin >> c;
	cin >> d;
	cin >> e;
	long long tmp = min(a,min(b,min(c,min(d,e))));
	long long ans = 4 + n / tmp;
	if (n%tmp != 0)ans++;
	cout << ans << endl;
	return 0;
}

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

set<char> digits;

bool check(int n) {
	stringstream ss;
	ss << n;
	string s = ss.str();
	for (int i = 0; i < s.size(); i++) {
		if(digits.count(s[i])) return 1;
	}
	return 0;
}

int main() {
#ifdef _DEBUG
	freopen("in" , "r", stdin );
	freopen("out", "w", stdout);
#endif
	ios::sync_with_stdio(0); cin.tie(0);
	int n, k; cin >> n >> k;
	for (int i = 0; i < k; i++) {
		char c; cin >> c;
		digits.insert(c);
	}
	while(check(n)) n++;
	cout << n << '\n';
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_imports)]
use proconio::input;
use std::cmp::max;
use std::cmp::min;
use std::collections::HashMap;
use std::collections::VecDeque;

fn main() {
    input! {
        N: usize,
        K: usize,
    }

    // 2(a + b + c) % K == 0

    if K % 2 == 0 {
        // a + b + c % (K/2) == 0
        // a, b, cはそれぞれ (K/2)の倍数

        // ききき、ぐぐぐ
        let k = K / 2;
        dbg!(k);
        let c: usize = N / k;
        dbg!(c);
        let ans = if c % 2 == 0 {
            (c / 2) * (c / 2) * (c / 2) + (c / 2) * (c / 2) * (c / 2)
        } else {
            ((c - 1) / 2 + 1) * ((c - 1) / 2 + 1) * ((c - 1) / 2 + 1) + (c / 2) * (c / 2) * (c / 2)
        };
        println!("{}", ans);
    } else {
        let c: usize = N / K;
        let ans = c * c * c;
        println!("{}", ans);
    }
}


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

using namespace std;

int main(){
  string S; cin>>S;
  if(S.size()==2){ cout<<S;}
  else{
    for(int i=S.size()-1;i>=0;i--){
      cout<<S[i];
    }
  }
  cout<<endl;

  return 0;
}


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

int main()
{
	int n;
	int a[100100];
	int ans[100100];
	int l=0;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	
	for (int k = 0; k < n; k++) {
		l = 0;
			while (a[l]!=k+1) {
				l = l + 1;
			}
			ans[k] = l + 1;
	}

	for (int i = 0; i < n;i++) {
		cout << ans[i] << " ";
	}
}

Measured memory_bytes: 1664
#include <stdio.h>

int main()
{
	int data[10],N,
		B,C,		/*B,CÌêÔãÌ*/
		check,
		i,j;
	
	scanf("%d",&N);
	for(i=0;i<N;i++){
		/*ú»*/
		check=1;
		B=0;
		C=0;
		for(j=0;j<10;j++){
			scanf("%d",&data[j]);		/*óüÍ¾¯ÇAscanfÍspaceæØèÅobt@ÉcÁÄ¢éÌÅ*/
		}
				
		/**/
		for(j=0;j<10;j++){
			if(data[j]>B){
				B=data[j];
			}else if(data[j]>C){
				C=data[j];
			}else{
				check=0;			/*falth*/
				break;
			}
		}
		if(check){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	}
	
	return 0;
}

Measured memory_bytes: 0
n = int(input())
list1 = list(map(int,input().split()))

a = sum(list1)/2
length = 0
index = 0

#要素数が２のときは特例
if n == 2:
    print(abs(list1[1]-list1[0]))
    exit()

for i in range(n):
    if a <= length:
        index = i
        break
    length += list1[i]

o = sum(list1[:index])
p = sum(list1[index:])

q = sum(list1[:index-1])
r = sum(list1[index-1:])

print(min(abs(o-p),abs(q-r)))

Measured memory_bytes: 89936
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;

int main(int argc, char *argv[]){
	ios::sync_with_stdio(false);
	int a, b, x = 0, y = 0;
	cin >> n >> a >> b;
	REP(i, n){
		char c;
		cin >> c;
		int ans = 0;
		if(c == 'a'){
			if(x + y < a + b){
				x ++;
				ans = 1;
			}else {
				ans = 0;
			}
		}
		if(c == 'b'){
			if(x + y < a + b && y < b){
				y ++;
				ans = 1;
			}else {
				ans = 0;
			}
		}
		if(c == 'c'){
			ans = 0;
		}
		cout << (ans ? "Yes" : "No") << endl;
	}
	return 0;
}


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

const int MAXN = 200005;
const int MOD = 1000000007;

int n, a[MAXN];

int main(){
	scanf("%d", &n);
	
	long long sum = 0, res = 0;
	for(int i = 0; i < n; i++){
		scanf("%d", &a[i]);
		
		res = (res + a[i] * sum) % MOD;
		sum = (sum + a[i]) % MOD;
	}
	printf("%lld\n", res);
	
	return 0;
}


Measured memory_bytes: 4608
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
#define MAX 120
typedef long long ll;

int main(){
  ll N,data[210000],abc[210000],a,b;
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>data[i];
    abc[i]=data[i];
  }
  sort(data,data+N);
  
  
  a=data[N/2-1];
  b=data[N/2];

  for(int i=0;i<N;i++){
    if(abc[i]<=a) cout<<b<<endl;
    else cout<<a<<endl;
  }
  
}


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

using namespace std;

#define rep(i, n) for(int i=0; i<(int)(n); i++)

int main() {
    string S, T;
    cin >> S >> T;

    rep(i, S.size()){
        if(S.at(i) != T.at(i)){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

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

int main(){
    string s;
    cin >> s;
    if ( s == "Sunny" )       cout << "Cloudy" << endl;
    else if ( s == "Cloudy" ) cout << "Rainy" << endl;
    else                      cout << "Sunny" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <cmath>
#include <unordered_map>
#include <algorithm>
#include <iomanip>

using namespace std;


int n;
vector<vector<pair<int, int>>> t;
vector<int> a;
vector<int> done;

void next(int i) {
	done[i] = 1;
	for(auto&& p : t[i]) {
		int k = p.first;
		int w = p.second;
		if (w % 2) {
			a[k] = a[i] == 0 ? 1 : 0;
		}
		else {
			a[k] = a[i];
		}
		if (done[k] == 0) {
			next(k);
		}
	}
}


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

	t.resize(n);
	a.resize(n);
	done.resize(n);

	for (int k = 0; k < n - 1; ++k) {
		int u, v, w;
		cin >> u >> v >> w;
		t[u - 1].emplace_back(v - 1, w);
		t[v - 1].emplace_back(u - 1, w);
		a[k] = 0;
	}
	
	next(0);

	for (auto&& aa : a) {
		cout << aa << endl;
	}

	
	
	return 0;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    vector<ll> A(N);
    // 累積和
    vector<ll> B(N, 0);
    ll total = 0;

    REP(i, N){
        cin >> A[i];
        total += A[i];
        B[i] = total;
    }
    // REP(i, N){
    //     cout << i << " " << B[i] << endl;
    // }

    ll ans = INF;
    ll lp = 0;
    ll rp = 2;
    for(ll i=1; i<=N-3; i++){
        ll maxv = 0;
        ll minv = INF;

        // Lについての処理
        ll templ = abs(B[lp] - (B[i]-B[lp]));
        ll lid = lp;
        for(ll j=lp; j<i; j++){
            ll next = abs(B[j] - (B[i]-B[j]));
            if(next <= templ){
                lid = j;
                templ = next;
            }
            else{
                break;
            }
        }
        lp = lid;
        maxv = max(B[lp], B[i]-B[lp]);
        minv = min(B[lp], B[i]-B[lp]);

        // Rについての処理
        ll tempr = abs((B[rp]-B[i]) - (total-B[rp]));
        ll rid = max(rp, i+1);
        for(ll j=rp; j<N; j++){
            ll next = abs((B[j]-B[i]) - (total-B[j]));
            if(next <= tempr){
                rid = j;
                tempr = next;
            }
            else{
                break;
            }
        }
        rp = rid;
        maxv = max(maxv, B[rp]-B[i]);
        maxv = max(maxv, total-B[rp]);
        
        minv = min(minv, B[rp]-B[i]);
        minv = min(minv, total-B[rp]);

        ans = min(ans, maxv-minv);
        // cout << lp << " " << i << " " << rp << " : " << maxv-minv << endl; 
        // cout << "max:" << maxv << " min:" << minv << endl;
        // cout << "B[lp]:" << B[lp] << " B[i]:" << B[i] << " B[rp]:" << B[rp] << endl;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int r,d,x[11];
    scanf("%d%d%d",&r,&d,&x[0]);
    for(int i=0;i<10;i++){
        x[i+1]=r*x[i]-d;
        printf("%d\n",x[i+1]);
    }
}

Measured memory_bytes: 256
A,B = map(int,input().split())
a1 = A/0.08
if a1!=int(A/0.08):
    a1 = int(A/0.08)+1
else:
    a1 = int(A/0.08)
a2 = (A+1)/0.08
if a2!=int((A+1)/0.08):
    a2 = int((A+1)/0.08)+1
else:
    a2 = int((A+1)/0.08)
b1 = B/0.1
if b1!=int(B/0.1):
    b1 = int(B/0.1)+1
else:
    b1 = int(B/0.1)
b2 = (B+1)/0.1
if b2!=int((B+1)/0.1):
    b2 = int((B+1)/0.1)+1
else:
    b2 = int((B+1)/0.1)
X = range(a1,a2)
Y = range(b1,b2)
x = -1
for i in X:
    if i in Y:
        x = i
        break
print(x)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

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

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define sum(x) accumulate(all(x),0)
#define pc(x) __builtin_popcount(x)
#define gll greater<ll>()

void solve(){
 ll x;
  cin >> x;
  
 ll kyu=8;
 rep(i,0,8){
  if(400+200*i<=x&&x<600+200*i) {
    cout << kyu << endl; 
    return;
  }
   kyu--;
 }

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

Measured memory_bytes: 3636
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (N, K) = read!(usize, usize);

    let mut p = 0.0;
    for d in 1..N + 1 {
        let mut h = 0;
        let mut t = d;
        while t < K {
            t *= 2;
            h += 1;
        }
        // debug!((d, h));
        p += 1.0 / (1 << h) as f64;
    }
    p /= N as f64;

    println!("{}", p)
}


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

int main(){
  int N, D;
  cin >> N >> D;
  
  if (N % (2 * D + 1) == 0) {
    cout << (N / (2 * D + 1)) << endl;
  }
  
  else {
    cout << 1 + (N / (2 * D + 1)) << endl;
  }
    
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>   //PBDS
#include <ext/pb_ds/tree_policy.hpp>       //PBDS
#define int long long int
#define vi vector<int>
#define vii vector<pair<int,int>>
#define pi pair<int,int>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define mi map<int,int>
#define PI   3.141592653589
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define f(i,x,n) for(int i=x;i<n;i++)
#define rf(i,x,n) for(int i=n-1;i>=x;i--)
#define check(x)   cerr<<#x<<" : "<<x<<endl;
#define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
#define fbo find_by_order                    //return iterator PBDS
#define ook order_of_key                     //return number :)) PBDS
#define baar exit(0)
using namespace __gnu_pbds;
using namespace std;
int powmod(int base,int exponent,int mod)
{
	int ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
signed main()
{
	fast
	int n;
	cin>>n;
	map<string,int>mp;
	f(i,0,n)
	{
		string s;
		cin>>s;
		mp[s]++;
	}
	cout<<"AC x "<<mp["AC"]<<endl;
	cout<<"WA x "<<mp["WA"]<<endl;
	cout<<"TLE x "<<mp["TLE"]<<endl;
	cout<<"RE x "<<mp["RE"]<<endl;
	//cerr << "Time elapsed: " << clock() / 1000 << " ms" << endl;
    return 0;
}

Measured memory_bytes: 3660
a,b = map(int,input().split())
s = input()
s_list = s
s_list = list(s_list)
num = ['0','1','2','3','4','5','6','7','8','9']
flg = False
cnt = 0

for i in range(len(s_list)):
    if i == a:
        if s_list[i] != '-':
            print('No')
            exit()
    elif s_list[i] not in num:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 3064
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()
A = [k for k, g in groupby(A)]
A = [300]+A+[0]
money = 1000
kabu = 0
for i in range(1, len(A)-1):
    if A[i-1] > A[i] < A[i+1]:  # かう
        n = money//A[i]
        money -= A[i]*n
        kabu += n
    if A[i-1] < A[i] > A[i+1]:  # うる
        money += kabu*A[i]
        kabu = 0
print(money)


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

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

#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()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int INF = 1001001001;

int main()
{   
    int n, x, y;
    cin >> n >> x >> y;
    --x, --y;
    vvi g(n);
    rep(i, n-1) {
        g[i].push_back(i+1);
        g[i+1].push_back(i);
    }
    g[x].push_back(y); g[y].push_back(x);

    vvi dist(n, vi(n, -1));
    rep(i, n) {
        queue<P> q;
        q.push({i, 0});
        while(!q.empty()) {
            auto x = q.front(); q.pop();
            int p = x.first, d = x.second;
            if(dist[i][p] != -1) continue;
            dist[i][p] = d;
            for(int np : g[p]) {
                q.push({np, d+1});
            }
        }
    }

    vi ans(n-1);
    rep(i, n){
        for(int j = i+1; j < n; j++) {
            int c = dist[i][j];
            ans[c-1]++;
        }
    }

    for(int x : ans) cout << x << endl;

    return 0;
}


Measured memory_bytes: 19092
N, M = map(int, input().split())
edges = [list(map(int, input().split())) for _ in range(M)]

class UnionFind:
    def __init__(self, n):
        self.par = list(range(n))
        self.rank = [0] * n
        self.size = [1] * n
        
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
        
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if x == y:
            return
        
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1
        elif self.rank[x] < self.rank[y]:
            x, y = y, x
        
        self.par[y] = x
        self.size[x] += self.size[y]
                
    def is_same(self, x, y):
        return self.find(x) == self.find(y)
    
    def get_size(self, x):
        return self.size[self.find(x)]

t = UnionFind(N)
ans = [0] * M
ans[0] = N * (N - 1) // 2
for i, (a, b) in enumerate(reversed(edges[1:])):
    a -= 1
    b -= 1
    if not t.is_same(a, b):
        ans[i + 1] = ans[i] - t.get_size(a) * t.get_size(b)
        t.unite(a, b)
    else:
        ans[i + 1] = ans[i]
    
print(*ans[::-1], sep='\n')


Measured memory_bytes: 115160
# coding: utf-8

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

res = 0
for i in range(N):
    atk = B[i] if B[i] <= A[i] else A[i]
    B[i] = B[i] - atk
    res = res + atk

    atk = B[i] if B[i] <= A[i+1] else A[i+1]
    A[i+1] = A[i+1] - atk
    B[i] = B[i] - atk
    res = res + atk

print(res)

Measured memory_bytes: 82148
n = int(input())
s = [ str(input()) for _ in range(n)]
d = {}
for i in range(n):
      if s[i] in d:
            d[s[i]] +=1
      else:
            d[s[i]] = 1
d = sorted(d.items(),key=lambda x: x[1],reverse=True)
m = d[0][1]
ans = []
for i in range(len(d)):
      if d[i][1]==m:
            ans.append(d[i][0])
      else:
            break
ans.sort()
for i in range(len(ans)):
      print(ans[i])


Measured memory_bytes: 44688
#include<bits/stdc++.h>
using namespace std;
int main(){
int a;
  cin>>a;
  
  if(1<=a&&a<=9)
    cout<<a<<endl;
  else if(9<a&&a<100)
    cout<<9<<endl;
  else if(100<=a&&a<=999)
    cout<<10+(a-100)<<endl;
  else if(999<a&&a<10000)
    cout<<909<<endl;
  else if(10000<=a&&a<=99999)
    cout<<910+(a-10000)<<endl;
  else
    cout<<90909<<endl;
} 


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(int i=(l);i<(r);++i)
//-------
const int N = 2e5 + 7;
const ll LINF = 1e18 + 7;
int n, a[N];
ll sum[N];
int main() {
	scanf("%d", &n);
	rep(i, 1, n + 1) scanf("%d", a + i);
	rep(i, 1, n + 1) sum[i] = sum[i - 1] + a[i];
	ll ans = LINF;
	rep(i, 1, n) {
		ans = min(ans, abs(sum[i] - (sum[n] - sum[i])));
	}
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

int main(){
    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

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

    cout << k - res << endl;
}

Measured memory_bytes: 1024
import           Data.List
main = do
  [_, m] <- map read . words <$> getLine :: IO [Integer]
  as     <- map read . words <$> getLine :: IO [Integer]
  let mod_cum = map (`mod` m) $ scanl (+) 0 as
      ans =
        sum $ map ((\x -> x * (x - 1) `div` 2) . length) (group $ sort mod_cum)
  print ans



Measured memory_bytes: 39932
a=input()
b=input()
c=input()
teban = 0
while 1:
  if teban==0:
    if len(a)==0:
      print('A')
      break
    teban = ord(a[0]) - ord('a')
    a = a[1:]
  elif teban==1:
    if len(b)==0:
      print('B')
      break
    teban = ord(b[0]) - ord('a')
    b = b[1:]
  elif teban==2:
    if len(c)==0:
      print('C')
      break
    teban = ord(c[0]) - ord('a')
    c = c[1:]

Measured memory_bytes: 3064
N = int(input())
X = list(map(int, input().split()))
order = {}
for idx, x in enumerate(X):
    order[idx] = x

X.sort()
m = N // 2
l = X[m - 1]
r = X[m]

for idx in range(N):
    x = order[idx]
    if x <= l:
        print(r)
    else:
        print(l)


Measured memory_bytes: 40740
#include<iostream>
using namespace std;
int n,k;
int a[100001];
int one[100001];
int t[100001];
void cpy(int* u,int* w){
	for(int i=1; i<=n ;i++) w[i]=u[i];
}
int out(int* u){
	for(int i=1; i<=n ;i++) cout << u[i] << ' ';
	cout << endl;
	return 0;
}
void mul(int* u,int* v,int* w){
	for(int i=1; i<=n ;i++) t[i]=v[u[i]];
	cpy(t,w);
}
void inv(int* u,int* w){
	for(int i=1; i<=n ;i++) t[u[i]]=i;
	cpy(t,w);
}
void pw(int* u,int k,int* w){
	if(k==0){
		cpy(one,w);
		return;
	}
	if(k%2==1){
		pw(u,k-1,w);mul(w,u,w);
	}
	else{
		pw(u,k/2,w);mul(w,w,w);
	}
}
int p[100001];
int q[100001];
int r[100001];
int s[100001];
int x[100001];
int y[100001];
int invp[100001];
int invq[100001];
int main(){
	ios::sync_with_stdio(false);
	cin >> n >> k;
	for(int i=1; i<=n ;i++) cin >> p[i];
	for(int i=1; i<=n ;i++) cin >> q[i];
	for(int i=1; i<=n ;i++) one[i]=i;
	if(k==1) return out(p);
	if(k==2) return out(q);
	inv(p,invp);
	inv(q,invq);
	//out(t);out(invq);
	if(k%6==1) cpy(p,r);
	if(k%6==2) cpy(q,r);
	if(k%6==3) mul(invp,q,r);
	if(k%6==4) cpy(invp,r);
	if(k%6==5) cpy(invq,r);
	if(k%6==0) mul(p,invq,r);
	//out(r);
	mul(invq,p,s);mul(s,q,s);mul(s,invp,s);
	int pl=(2*k-4)/3;
	pw(s,pl/4,x);
	if(pl%4>=1) mul(x,invq,x);
	if(pl%4>=2) mul(x,p,x);
	if(pl%4>=3) mul(x,q,x);
	mul(x,r,y);
	inv(x,x);
	mul(y,x,y);
	out(y);
}

Measured memory_bytes: 4864
/* 
 * Author: aps
 * Time: 29-06-2019 17:31:32
**/
#include<bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef pair<int,int> pii;

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

inline ll add(ll x, ll y) { x += y; if (x >= mod) x -= mod; return x;}
inline ll sub(ll x, ll y) { x -= y; if (x < 0) x += mod; return x;}
inline ll mul(ll x, ll y) { return ((x % mod) * (y % mod)) % mod;}
inline ll power(ll a, ll b) {
    ll x = 1;
    while (b) {
        if (b & 1) x = mul(x, a);
        a = mul(a, a);
        b >>= 1;
    }
    return x;
}
inline ll inv(ll a) { return power(a, mod - 2);}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    vector<char> v;
    for(int i=0;i<4;i++){
        char ch; cin >> ch;
        v.pb(ch);
    }
    sort(all(v));
    if(v[0] == v[1] and v[2] == v[3] and v[1] != v[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
            int A = sc.nextInt();
            int B = sc.nextInt();
            int C = sc.nextInt();
        sc.close();
        
        if((A<C&&C<B) || (B<C&&C<A)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 25300
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e5 + 10;
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	vector<int> v(n);
	for (auto& x : v) cin >> x;
	sort(v.begin(), v.end());
	cout << v.back() - v.front() << endl;
	return 0;
}

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

int main(){ 
  Int N;
  cin >> N;
  vector<Int> A(N), B(N), C(N);
  rep(i,N) cin >> A[i];
  rep(i,N) cin >> B[i];
  rep(i,N) cin >> C[i];
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  sort(C.begin(),C.end());
  
  vector<Int> BtoA(N,0), BtoC(N,0);
  
  rep(i,N) {
    auto ite = lower_bound(A.begin(),A.end(),B[i]);
    BtoA[i] = ite - A.begin();
  }
  
  rep(i,N) {
    auto ite = upper_bound(C.begin(),C.end(),B[i]);
    BtoC[i] = C.end() - ite;
  }
  

  Int ans = 0;
  rep(i,N) {
    ans += BtoA[i] * BtoC[i];
  }
  
  cout << ans << endl;

}

Measured memory_bytes: 4224
// ~maqsat~

// #pragma GCC target ("avx2")
// #pragma GCC optimize ("Ofast")
// #pragma GCC optimize ("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define F first
#define S second
#define in insert
#define pb push_back
#define eb emplace_back
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define count1 __builtin_popcountl
#define debug(x) cerr << (#x) << " = " << (x) << "\n"
#define ACCELERATE ios_base::sync_with_stdio(false),cin.tie(nullptr)
#define fre(f) if(fopen(f".in", "r")) freopen(f".in", "r", stdin),freopen(f".out", "w", stdout)
#define ever ;;

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

using ll = long long;
using ull = unsigned long long;
// using big = __int128_t; // -10^38...10^38
using db = double;
using ld = long double;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> inline void cmin(T &a, T b) { a = min(a, b); }
template <class T> inline void cmax(T &a, T b) { a = max(a, b); }

const int oo = 0x3f3f3f3f;
const ll N = 2e5 + 123;
const ll MOD = 1e9 + 7;
const ll INF = 1e15 + 9;
const db EPS = 1e-9;
const db PI = acos(-1); // 3.14159265358979323846
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};

ll get(ll l, ll r) {
	ll sum1 = (l + 1) * l / 2;
	ll sum2 = (r + 1) * r / 2;
	return sum2 - sum1;
}

main() {
#ifdef ZVER
	cerr << "Ready\n";
#endif
	fre("");
	ACCELERATE;

	int n, k;
	cin >> n >> k;
	
	int a[N];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	
	ll sum = 0;
	db ans = 0;
	int l = 0, r = k - 1;
	for (int i = l; i <= r; i++) {
		sum += a[i];
	}
	
	cmax(ans, (get(k - 1, sum) * 1.) / (sum - k + 1));
	
	while (r + 1 < n) {
		sum -= a[l];
		l++;
		r++;
		sum += a[r];
		cmax(ans, (get(k - 1, sum) * 1.) / (sum - k + 1));
	}
	
	cout << fixed << setprecision(9) << ans;
	
	return 0;
}


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

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;
const int INF = 2147483647;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//myfuncs
//素数判定
template<class T> inline T isPrime(T x) {
	bool ret = true;
	if (x < 2) {
		ret = false;
	}
	for (LL i = 2; i <= sqrt(x); i++) {
		if (x%i == 0) {
			ret = false;
		}
	}
	return ret;
}

//Union FInd
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

//main code

int main(int argc, char const* argv[])
{
    int n,k;
    cin >> n >> k;
    VI a(n+1,0);
    for (int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        a[tmp]++;
    }
    SORT(a);
    LL ans = 0;
    for (int i = 0; i <= n-k; i++) {
            ans += a[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
    int m;
    while(scanf("%d",&m)!=EOF)
    {
        int i,fla,t,xm,hw,flag=0;
        for(i=0; i<m; i++)
        {
            scanf("%d",&t);
            if(i==0)
            {
                fla=t;
            }
            if(i>flag)
                xm=t-fla;
            if(fla>t)
            {
                fla=t;
                flag=i;
            }
            if(i==1)
            {
                hw=xm;
            }
            if(i>1)
                if(hw<xm)
                {
                    hw=xm;
                }
        }
        printf("%d\n",hw);
    }
    return 0;
}



Measured memory_bytes: 2080
import sys

N = int(sys.stdin.readline().strip())
cost_list = list(map(int, sys.stdin.readline().strip().split(" ")))
dp = [10**9 for _ in range(N)]
dp[0] = 0
dp[1] = abs(cost_list[1] - cost_list[0])

for i in range(2, N):
    dp[i] = min(dp[i-2] + abs(cost_list[i] - cost_list[i-2]), dp[i-1] + abs(cost_list[i] - cost_list[i-1]))

print(dp[N-1])


Measured memory_bytes: 13976
#include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>

using namespace std;

int a[200001],n,fa[200001],cnt,maxn,minn=2147483647;
bool vis[200001],b[21];
vector<int> point[200001];

int dfs(int x){
	int maxn=0;
	for(int v:point[x])if(!vis[v])dfs(v);
	for(int v:point[x])if(!vis[v])b[a[v]]=true;
	while(b[a[x]])++a[x];
	for(int v:point[x])if(!vis[v])b[a[v]]=false;
}

int main(){
	scanf("%d",&n);for(int i=1;i<=n;++i)scanf("%d",fa+i),point[fa[i]].push_back(i);
	int x=1;while(!vis[x=fa[x]])vis[x]=true;memset(vis,false,sizeof(vis));while(!vis[x=fa[x]])vis[x]=true;
	for(int i=1;i<=n;++i)if(vis[i])dfs(i),++cnt,maxn=max(maxn,a[i]),minn=min(minn,a[i]);
	puts(maxn!=minn||(cnt%2==0)?"POSSIBLE":"IMPOSSIBLE");
}

Measured memory_bytes: 11904
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265359
using namespace std;

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

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


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

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

vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
}
  
  int amari, x = 0;
  
  for ( int j = 0; j < 30; j++) {

    for ( int i = 0; i < N; i++) {
      amari += vec.at(i) % 2;
    }
  
    if ( amari == 0 ) {
      for ( int i = 0; i < N; i++) {
        vec.at(i) /= 2;
      }  
        x++;
    }
      
    else {  
      break;
    }
  }
  
cout << x << endl;
               
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
 
using namespace std;
 
int main()
{
    int    a, b;
    double c;
    int    C;
 
    cin >> a >> b >> C;
     
    double S = (1.0 / 2.0) * a * b * sin(C * (double)M_PI / 180.0);
     
    c = (double)sqrt(a * a + b * b - 2 * a * b * (cos(C * (double)M_PI / 180.0)));
 
    double L = a + b + c;
 
    double h = 2.0 * S / a;
 
    cout << fixed << setprecision(13) << S << " " << setprecision(13) << L << " "
                  << setprecision(13) << h << endl;
    
    return (0);
}

Measured memory_bytes: 3512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define inf (int)1e9+7
#define eb emplace_back

int main() {
    int h, w; cin >> h >> w;
    char s[h][w]; rep(i, h) rep(j, w) cin >> s[i][j];
    int sum[h + 1][w + 1];
    rep(i, h + 1) rep(j, w + 1) sum[i][j] = 0;
    rep(i, h) {if (s[i][0] == '#') continue; sum[i][0] = 1;}
    rep(i, h) {
        rrep(j, 1, w) {
            if (s[i][j] == '#') continue;
            sum[i][j] = sum[i][j - 1] + 1;
        }
    }
    //rep(i, h) {rep(j, w) cout << sum[i][j] << " "; cout << endl;}
    rep(i, h) {
        for (int j = w - 2; j >= 0; --j) {
            if (s[i][j] == '#') continue;
            chmax(sum[i][j], sum[i][j + 1]);
        }
    }
    //cout << endl; rep(i, h) {rep(j, w) cout << sum[i][j] << " "; cout << endl;}
    int sum2[h][w]; rep(i, h) rep(j, w) sum2[i][j] = 0;
    
    /*
    rrep(i, 1, h + 1) {
        rep(j, w + 1) {
            if (s[i][j] == '#') continue;
            sum[i][j] = sum[i - 1][j] + 1;
        }
    }
     */
    rep(j, w) {if (s[0][j] == '#') continue; sum2[0][j] = 1;}
    rrep(i, 1, h) {
        rep(j, w) {
            if (s[i][j] == '#') continue;
            sum2[i][j] = sum2[i - 1][j] + 1;
        }
    }
    //rep(i, h) {rep(j, w) cout << sum2[i][j] << " "; cout << endl;}
    for (int i = h - 2; i >= 0; --i) {
        rep(j, w) {
            if (s[i][j] == '#') continue;
            chmax(sum2[i][j], sum2[i + 1][j]);
        }
    }
    //rep(i, h) {rep(j, w) cout << sum2[i][j] << " "; cout << endl;}
    rep(i, h) rep(j, w) sum[i][j] += sum2[i][j];
    //rep(i, h) {rep(j, w) cout << sum[i][j] << " "; cout << endl;}
    int mmax = 0;
    rep(i, h) rep(j, w) chmax(mmax, sum[i][j]);
    cout << mmax - 1 << endl;
}


Measured memory_bytes: 35456
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <vector>

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

	std::vector<int> value = {1};

	for(int base : {6, 9}) {
		int i = 1;
		while(true) {
			if(std::pow(base, i) <= N) {
				value.emplace_back(std::pow(base, i));
			} else {
				break;
			}
			i++;
		}
	}

	std::sort(value.begin(), value.end());
	
	std::vector<int> cost(N + 1, std::numeric_limits<int>::max());
	cost[0] = 0;

	for(int i = 1; i <= N; i++) {
		for(int v : value) {
			if(v <= i) {
				cost[i] = std::min(cost[i], 1 + cost[i - v]);
			} else {
				break;
			}
		}
	}

	std::cout << cost[N] << std::endl;

	return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <string>

using namespace std;

int u[400],v[400];
string w[400];

int main(){
    int n,m,s,e;
    char str[7];
    string dist[40];
    bool visited[40],change;
    
    while(true){
        scanf("%d %d %d %d",&n,&m,&s,&e);
        
        if(n == 0) break;
        
        for(int i = 0;i < m;++i){
            scanf("%d %d %s",&u[i],&v[i],str);
            w[i] = string(str);
        }
        
        memset(visited,0,sizeof visited);
        
        dist[e] = "";
        visited[e] = true;
        change = false;
        
        for(int it = 0;it <= 6*n;++it){
            for(int i = 0;i < m;++i){
                if(visited[ v[i] ]){
                    string aux = w[i] + dist[ v[i] ];
                    
                    if(!visited[ u[i] ] || aux < dist[ u[i] ]){
                        dist[ u[i] ] = aux;
                        if(it >= n - 1 && u[i] == s) change = true;
                    }
                    
                    visited[ u[i] ] = true;
                }
            }
        }
        
        if(change || !visited[s]) puts("NO");
        else puts(dist[s].c_str());
    }
    
    return 0;
}

Measured memory_bytes: 1316
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

signed main() {
  INIT;
  VAR(int,n,k);
  int cnt=0,ans=-1;
  map<int,int> mp;
  REP(i,n){
    VAR(int,a,b);
    mp[a] += b;
  }

  EACH(mi,mp){
    cnt += mi.second;
    if(cnt>=k) {
      ans=mi.first;
      break;
    }
  }
  OUT(ans)BR;
  return 0;
}


Measured memory_bytes: 4224