akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std;
template<class T>il read(T &x){
	int f=1;char k=getchar();x=0;
	for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
	for(;k>='0'&&k<='9';k=getchar()) x=(x<<3)+(x<<1)+k-'0';
	x*=f;
}
template<class T>il print(T x){
	if(x/10) print(x/10);
	putchar(x%10+'0');
}
ll mul(ll a,ll b,ll mod){long double c=1.;return (a*b-(ll)(c*a*b/mod)*mod)%mod;}
it qpow(int x,int m,int mod){
	int res=1,bas=x%mod;
	while(m){
		if(m&1) res=(1ll*res*bas)%mod;
		bas=(1ll*bas*bas)%mod,m>>=1;
	}
	return res%mod;
}
const int MAXN = 262149;
int n,sz,val,mx;
multiset<int> s,S,tmp;
inl bool check(){
	multiset<int>::iterator ite;
	tmp.clear();
//	printf("sz=%d sz1=%d\n",s.size(),S.size());
	for(ite=S.begin();ite!=S.end();++ite){
//		printf("val=%d ",*ite);
		multiset<int>::iterator  ite1=s.upper_bound(*ite);
		if(ite1==s.end()) return false;
		tmp.insert(*ite1);
		s.erase(ite1);
	}
	for(ite=tmp.begin();ite!=tmp.end();ite++) S.insert(*ite);
//	printf("ok!\n");
	return true;
}
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n),sz=pow(2,n);
	for(ri i=1;i<=sz;++i) read(val),s.insert(-val),mx=max(mx,val);
	S.insert(-mx),s.erase(s.begin());
	for(ri i=0;i<n;++i)
		if(!check()){
			puts("No");
			return 0;
		}
	puts("Yes");
	return 0;
}

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

using namespace std;

#define INF 1000000000
#define INFLL 0x3f3f3f3f3f3f3f3fLL 
#define EPS 10e-9
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define st first
#define nd second
#define sz(v) int(v.size())
#define all(X) (X).begin(), (X).end()
#define FOR(I, A, B) for(int I = A; I < B; I++)
#define RFOR(I, A, B) for(int I = A; I >= B; I--)

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<iii> viii;
typedef vector<ll> vll;

int main(){
	int n;
	scanf("%d", &n);
	vll a(n);
	for(int i = 0; i< n; i++){
		scanf("%lld", &a[i]);
	}

	map<ll, ll> somas;
	ll acc = 0;
	for(ll k = 1; k < n; k++){
		somas[k] = a[0]+a[k];
	}
	vi delta(n);
	vi dind(n);
	map<ll,ll> dposs;
	for(ll i = 0; i < n; i++){
		delta[i] = a[i]-a[0];
		dind[i] = -i;
		dposs[delta[i] - dind[i]]++;
	}
	ll ans = 0;
	for(auto el : somas){
		ll d = el.st - el.nd;
		ans += dposs[d];
	}

	cout << ans << endl;


	return 0;
}


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

public class Hello
{
    public static void Main()
    {
        var d = new Dictionary<char, int>();
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var k = int.Parse(line[1]);
        for (int i = 0; i < n; i++)
        {
            var rs = Console.ReadLine().Trim();
            var s = rs[0];
            if (d.ContainsKey(s)) d[s]++;
            else d[s] = 1;
        }
        var a = new int[d.Count()];
        var p = 0;
        foreach (var x in d.OrderByDescending(y => y.Value))
            a[p++] = x.Value;
        Console.WriteLine(getAns(a, k));
    }
    public static int getAns(int[] a, int k)
    {
        var aL = a.Length;
        //if (k > aL) return 0;
        var ret = 0;
        var p = 0;
        var count = 0;
        while (true)
        {
            if (a[p] >= 1) { a[p]--; count++; }
            p++;
            if (count < k && p == aL) break;
            if (count == k && p <= aL)
            {
                ret++;
                p = 0;
                count = 0;
                Array.Sort(a);
                Array.Reverse(a);
            }
        }
        return ret;
    }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi atan(1.0)*4
#define pb(x) push_back(x)
#define in(x) insert(x)
#define fl(x,y) for(ll i=x;i<y;i++)
#define vi vector<long long>
#define vs  vector<string>
#define vp(vi,x) cin>>x; vi.pb(x);
string en="\n";
string t="hello";
string Y="YES\n";
string N="NO\n";
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define fi first
#define se second
#define clr clear()
#define sqr(a) (a*a)
#define mk make_pair
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
/*bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
LL bpow(LL a,LL b){if(b==0)return 1;LL r=bpow(a,b/2);if(b%2)return r*r*a;else return r*r;}
LL binpow(LL a,LL b){LL r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
LL binpow(LL a,LL b,LL m){a%=m;LL r=1;while(b>0){if(b&1) r=r*a%m;a=a*a%m; b>>=1;}return r;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
*/
int main()
{
    ll a,b,t,n,k,p,q,r,x,y,sum,ct=0,flag=0;
    string s,s1,s2,s3;
    char ch;
    set<char>st;
    map<char,ll>mp;
    vector<ll>v;
    cin>>s; r=0;
    for(ll i=0;i<s.size();i++)
    {
        mp[s[i]]++;
        st.insert(s[i]);
    }
    p=st.size(); ct=0;
    for(char i='a';i<='z';i++)
    {
        x=mp[i];
        if(x!=0 && x%2==0) ct++;
    }
    if(ct==p) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}






Measured memory_bytes: 3644
#include <iostream>

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

#ifdef DEBUG
    #define IFD if(true)
#else
    #define IFD if(false)
#endif

int main()
{
    int M, D;
    cin >> M >> D;

    int ans = 0;
    rep(m, M) {
        rep(d, D) {
            int d10 = (d + 1) / 10;
            int d1 = (d + 1) % 10;
            if(d1 <= 1 || d10 <= 1) continue;
            if(d1 * d10 == m + 1) {
                //cout << m + 1 << " " << d10 << " " << d1 << endl;
                ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
#define pu push
#define pb push_back
#define mp make_pair
#define INF 10000000000000000
int n,m;
ll start[100005];
ll goal[100005];
ll d[100005];
pair<ll,ll> qwe[100005];
struct edge{
	int to; ll cost;
	edge(int a,int b):to(a),cost(b){}
};
vector<edge>vec[100005];
void dijkstra(int s){
	priority_queue<P,vector<P>,greater<P> > que;
	que.pu(mp(0,s));
	fill(d,d+n,INF);
	d[s]=0;
	while(!que.empty()){
		P p=que.top(); que.pop();
		int V=p.second;
		if(d[V]<p.first) continue;
		for(int i=0;i<vec[V].size();i++){
			edge e=vec[V][i];
			if(d[e.to] > d[V]+e.cost){
				d[e.to]=d[V]+e.cost;
				que.push(mp(d[e.to],e.to));
			}
		}
	}
}
vector<ll>seg[1<<18];
ll limits,limite;
void update1(vector<ll> x,int a){
	seg[a+(1<<17)-1]=x;
}
void update(){
		for(int i=(1<<17)-2;i>=0;i--){
		seg[i].resize(seg[i*2+1].size()+seg[i*2+2].size());
		merge(seg[i*2+1].begin(),seg[i*2+1].end(),seg[i*2+2].begin(),seg[i*2+2].end(),seg[i].begin());
		}
}
int sum(int a,int b,int k,int l,int r){
	if(l>b || a>r){
		return 0;
	}else if(a<=l && r<=b){
		int rp=lower_bound(seg[k].begin(),seg[k].end(),limite)-seg[k].begin();
		return seg[k].size()-rp; 
	}else{
		return sum(a,b,k*2+1,l,(l+r)/2)+sum(a,b,k*2+2,(l+r)/2+1,r);
	}
}
int main(){
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;i++){
		int a,b;
		ll c;
		scanf("%d %d %lld",&a,&b,&c);
		vec[a].pb(edge(b,c)); vec[b].pb(edge(a,c));
	}
	dijkstra(0);
	for(int i=0;i<n;i++){
		start[i]=d[i];
	}
	dijkstra(n-1);
	for(int i=0;i<n;i++){
		goal[i]=d[i];
		qwe[i]=mp(start[i],goal[i]);
	}
	sort(qwe,qwe+n);
	for(int i=0;i<n;i++){
		vector<ll>er; er.pb(qwe[i].second);
		update1(er,i); start[i]=qwe[i].first;
	}
	update();
	int Q;
	scanf("%d",&Q);
	for(int i=0;i<Q;i++){
		scanf("%lld %lld",&limits,&limite);
		int eo=upper_bound(start,start+n,limits)-start;
		printf("%d\n",sum(0,eo-1,0,0,(1<<17)-1));
	}
}

Measured memory_bytes: 36452
#include <iostream>

int main() {
    int K, S;
    std::cin >> K >> S;

    int ret = 0;
    for (int x = 0; x <= K; ++x) {
        for (int y = 0; y <= K; ++y) {
            const int z = S - (x + y);
            if (0 <= z && z <= K) {
                ++ret;
            }
        }
    }

    std::cout << ret << std::endl;
}


Measured memory_bytes: 256
#![allow(unused_macros)]

// cf. [Rustで競技プログラミングの入力をスッキリ記述するマクロ - Qiita](https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8)
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, usize1) => {
        read_value!($next, usize) - 1
    };

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

fn main() {
    input! {
        a: i64,
        b: i64,
        c: i64,
        d: i64,
    }
    let mut ans = String::new();
    for _ in 0..(d - b) {
        ans.push('U');
    }
    for _ in 0..(c - a) {
        ans.push('R');
    }
    for _ in 0..(d - b) {
        ans.push('D');
    }
    for _ in 0..(c - a) {
        ans.push('L');
    }
    ans.push('L');
    for _ in 0..(d - b + 1) {
        ans.push('U');
    }
    for _ in 0..(c - a + 1) {
        ans.push('R');
    }
    ans.push('D');
    ans.push('R');
    for _ in 0..(d - b + 1) {
        ans.push('D');
    }
    for _ in 0..(c - a + 1) {
        ans.push('L');
    }
    ans.push('U');
    println!("{}", ans);
}


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

int gcd(int a, int b);
int gcd3(int a, int b, int c);

int main()
{
  int K;
  cin >> K;
  long ans = 0;
  for (int i = 1; i <= K; i++)
  {
    for (int j = 1; j <= K; j++)
    {
      for (int k = 1; k <= K; k++)
      {
        ans += gcd3(i,j,k);
      }
    }
  }
  cout << ans << endl;
}

int gcd(int a, int b)
{
  if (a%b==0)
    return(b);
  else
    return(gcd(b,a%b));
}

int gcd3(int a, int b, int c)
{
  int ab = gcd(a, b);
  return(gcd(ab, c));
}


Measured memory_bytes: 3636
import std.stdio;
import std.functional;
import std.string;
import std.algorithm;

const C = 100000007;

long count(string s) {
    auto r = new long[s.length];
    r[$ - 1] = 1;
    for (long i = s.length - 2; i >= 0; i--) {
        if (s[i] == s[i + 1]) {
            r[i] = r[i + 1] + 1;
        } else {
            r[i] = 1;
        }
    }
    long[][] dp = new long[][](2, s.length + 1);
    void initDP(int d) {
        long[] cdp = dp[d == 3];
        long length = s.length;
        for (int i = 1; i <= min(d, length); i++) cdp[i] = 1;
        for (int i = 2; i <= length; i++) {
            for (int j = 1; j <= d; j++) {
                if (i - j >= 1) {
                    cdp[i] = (cdp[i] + cdp[i - j]) % C;
                }
            }
        }
    }
    initDP(3);
    initDP(5);
    int i = 0;
    long ans = 1;
    while (true) {
        if (i == s.length) break;
        long c = 0;
        int d = (s[i] == '0' || s[i] == '8') ? 3 : 5;
        for (long x = 0; x < r[i]; x += d) {
            c = (c + dp[d == 3][r[i] - x]) % C;
        }
        ans = ans * c % C;
        i += r[i];
    }
    return ans;
}

void main() {
    string s;
    while (s = stdin.readln.chomp, s != "#") {
        //writeln(s, " ", count(s));
        count(s).writeln;
    }
}

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

int main(){
  int N;
  cin>>N;
  int t[N];
  int M;
  int p,x;
  int total=0;
  vector<pair<int,int>> v(M);
  for(int i=0;i<N;i++){
    cin>>t[i];
    total+=t[i];
  }
  cin>>M;
  vector<int> ans(M,total);
  for(int i=0;i<M;i++){
    cin>>p>>x;
    if(t[p-1]>=x) ans[i]-=(t[p-1]-x);
    if(t[p-1]<x) ans[i]+=(x-t[p-1]);
  }
  for(int i=0;i<M;i++){
    cout<<ans[i]<<endl;
  }
}
    

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
long long a[87];
	a[0]=2;
	a[1]=1;
	int n;
	cin>>n;
	for(int i=2;i<=n;i++){
		a[i]=a[i-2]+a[i-1];
	}
	cout<<a[n]<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long  n,arr[100005],dp[100005];
long long  f(long long  a){
	if(a>n)return 1e18;
	if(a==n)return 0;
	if(dp[a]!=-1)return dp[a];
	return dp[a]=min(abs(arr[a+1]-arr[a])+f(a+1),abs(arr[a+2]-arr[a])+f(a+2));
}
int  main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	memset(dp,-1,sizeof(dp));
	cin>>n;
	for(long long  i =1;i<=n;i++){
		cin>>arr[i];
	}
	cout<<f(1)<<endl;
}

Measured memory_bytes: 3328
N,M = map(int,input().split())
n = [0]*N
n_used = [False]*N
if N > 1:
    n[0]=1
for i in range(0,M,1):
    s,c = map(int,input().split())
    if (n_used[s-1] and n[s-1]!=c) or (s==1 and c ==0 and N != 1):
        print(-1)
        exit()
    else:
        n[s-1]=c
        n_used[s-1]=True
st = "".join(list(map(str,n)))
print(st)

Measured memory_bytes: 3188
#2020-03-18
while True:
    ta,yo = map(int,input().split())
    if ta == yo == 0:
        break
    
    for tate in range(ta):
        for yoko in range(yo):
            if tate == 0 or tate == ta-1 or yoko == 0 or yoko == yo-1 :
                print("#", end="")
            else:
                print(".", end="")
        print()
    print()


Measured memory_bytes: 7008
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(a)      (a).begin(),(a).end()
#define debug_array(a,n) for (ll bccc=(0); bccc<(n); bccc++) cout<<a[bccc]<<" "<<"\n"
#define debug_vector(a) for(ll bccc=(0); bccc<(a.size());bccc++) cout<<a[bccc]<<" "<<"\n"
#define F           first
#define S           second
#define debug_set(s) for(auto p:s) cout<<p<<" "
#define debug_map(m) for(auto p:m) cout<<p.F<<" "<<p.S<<"\n"
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;

/* ll t = 0;
ordered_multiset me;
...
me.insert({x, t++});
me.erase(me.lower_bound({x, 0}));
cout << me.order_of_key({x, 0}) << "\n";

///////////   t is insertion time
*/
//#pragma GCC optimize("Ofast")  // works very well
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long double lld;
lld pi=3.14159265358;
ll powr(ll a,ll b)
{
    ll c=1;
    ll kjk;
    for(kjk=0;kjk<b;kjk++)
        c*=a;
    return c;
}
ll hell=1000000007;
//ll hell=998244353   ;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
// to generate random number , use rng() ... eg cout<<rng();
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    ll n,x,y;
    cin>>n>>x>>y;
    ll i,j;
    ll dis[n]={0};
    for(i=1;i<=n;i++)
    {
        for(j=i+1;j<=n;j++)
        {
            ll d=j-i;
            d=min(d,abs(j-x)+1+abs(i-y));
            d=min(d,abs(j-y)+1+abs(i-x));
            dis[d]++;
            //cout<<d<<" "<<i<<" "<<j<<"\n";
        }
    }
    for(i=1;i<n;i++)
        cout<<dis[i]<<"\n";
    /*ll k,n,i;
    cin>>k>>n;
    ll a[n];
    for(i=0;i<n;i++)
        cin>>a[i];
    ll mini=hell;
    for(i=1;i<n;i++)
        mini=min(mini,k-a[i]+a[i-1]);
    mini=min(mini,(a[n-1]-a[0]));
    cout<<mini;*/
    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define INF 1e9
#define PI acos(-1)
typedef long long ll;



int main() {
	string str;
	int w;
	cin >> str >> w;
	vector<char> s;
	for (int i = 0; i < str.size(); i += w) {
		s.push_back(str[i]);
	}

	for (auto i = s.begin(); i < s.end(); i++) {
		cout << *i;
	}

	cout << endl;

	return 0;
}

Measured memory_bytes: 256
import time, sys
sys.setrecursionlimit(int(1e7))

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

friends = [[] for i in range(n)]
cands = [None for i in range(n)]
cycles = []
visited = [False for i in range(n)]
count = [0 for i in range(n)]
for _ in range(m):
    a, b = map(lambda x: int(x)-1, input().split())
    friends[a].append(b)
    friends[b].append(a)

def dfs(x):
    visited[x] = True
    cycle.add(x)
    for i in friends[x]:
        if not visited[i]:
            dfs(i)
    return


for i, v in enumerate(visited):
    if v:
        continue
    cycle = set()
    dfs(i)
    l = len(cycle)
    ind = len(cycles)
    cycles.append(cycle)
    for fr in cycle:
        cands[fr] = ind
        count[fr] = l - 1 - len(friends[fr])


for _ in range(k):
    a, b = map(lambda x: int(x)-1, input().split())
    if a in cycles[cands[b]]:
        count[a] -= 1
        count[b] -= 1

for i in count:
    print(i, end=" ")

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


int main() {
    int N; cin >> N;
    string S; cin >> S;
    string ans = "No";

    bool isSame = false;
    if (S.size() % 2 == 0) {
        for (int i = 0; i < (S.size() / 2); i++) {
            isSame = (S[i] == S[i + (S.size() / 2)]);
            if (!isSame) break;
        }
    }
    if (isSame) ans = "Yes";

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

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

int main() {
    int n;
    cin >> n;
    vector<int> h(n);
    for(auto& e : h) cin >> e;
    h.push_back(0);

    int ans = 0;
    for(int i = 0, lim = *max_element(begin(h), end(h));i <= lim;i++){
        for(int j = 0;j < n;j++){
            if(h[j] >= i && h[j+1] < i) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
 
/* ソート関数 */
int int_sort( const void * a , const void * b ) {
  /* 引数はvoid*型と規定されているのでint型にcastする */
  if( *( int * )a < *( int * )b ) {
    return 1;
  }
  else
  if( *( int * )a == *( int * )b ) {
    return 0;
  }
  return -1;
}
 
int main(void){
    int N;
    scanf("%d",&N);
    int a[N];
    for(int i=0;i<N;i++){
        scanf("%d",&a[i]);
    }
    qsort((void*)a,N,sizeof(a[0]),int_sort);
    long long int ans1=0;
    long long int ans2=0;
    for(int i=1;i<N;i++){
        if(a[i]==a[i-1]&&ans1==0){ans1=a[i];if(i!=N-1)i++;}
        else if(a[i]==a[i-1])ans2=a[i];
        if(ans2!=0)break;
    }
    long long int po=ans1*ans2;
    printf("%lld",po);
    return 0;
}

Measured memory_bytes: 892
/*
   ~~~~~~~~~~~~~~~~~~~
   \  |\/| | |\ | |  /
   /  |  | | |/ |_|  \
   ~~~~~~~~~~~~~~~~~~~
*/
#include<iostream>
#define ll long long
using namespace std;
int main()
{
	ll a,b,c,d,e;
	cin>>a>>b>>c>>d>>e;
	cout<<(c*60+d)-(a*60+b)-e<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i = 1; ; i++) if (i * i > n) {
        cout << (i - 1) * (i - 1);
        return 0;
    }
}


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

int main(){
  int a,b,c;
  
  cin>>a>>b>>c;
  if(a!=b&&a!=c&&b!=c){
    cout<<"3"<<endl;
    return 0;
  }

  if(a==b&&b==c){
    cout<<"1"<<endl;
    return 0;
  }

  cout<<"2"<<endl;
 return 0;
}


Measured memory_bytes: 256
n = int(input())

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

g = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    g[a].append(b)
    g[b].append(a)

s = []
parent = [-1]*n
order = []
s.append(0)
while s:
    v = s.pop()
    order.append(v)
    for u in g[v]:
        if u == parent[v]:
            continue
        parent[u] = v
        s.append(u)

order.reverse()
c = [1]*n
dp = [1]*n
for v in order:
    dp[v] *= g1[c[v]-1]
    dp[v] %= mod
    if parent[v] != -1:
        c[parent[v]] += c[v]
        dp[parent[v]] *= dp[v]
        dp[parent[v]] *= g2[c[v]]
        dp[parent[v]] %= mod

ans = [0]*n
order.reverse()
for v in order:
    ans[v] = dp[v]
    for u in g[v]:
        if parent[v] == u:
            continue
        temp = ans[v]
        temp *= g2[c[v]-1]
        temp *= g1[c[v]-1-c[u]]
        temp *= g1[c[u]]
        temp *= pow(dp[u], mod-2, mod)

        dp[u] *= g2[c[u]-1]
        dp[u] *= g1[c[v]-1]
        dp[u] *= temp
        dp[u] *= g2[c[v]-c[u]]
        dp[u] %= mod
        c[u] += c[v]-c[u]

for i in range(n):
    print(ans[i])

Measured memory_bytes: 128312
#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;

int main() {
	int a, b, c;
	int a1 = 0, a2 = 0;
	char ch;

	while (cin >> a >> ch >> b >> ch >> c) {
		int x =a * a + b * b;
		if (x == c*c) {
			a1++;
		}
		else {
			if (a == b) {
				a2++;
			}
		}
	}

	cout << a1 << endl;
	cout << a2 << endl;
}


Measured memory_bytes: 3092
#include<stdio.h>
#include <iomanip>
#include <iostream>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include <random>
#include <chrono>

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

using namespace std;
int main() {
	int n;
	string s;
	cin >> n >> s;
	char old='1';
	int cnt = 0;
	rep(i, n) {
		if (old != s.at(i)) {
			cnt++;
		}
		old = s.at(i);
	}
	cout << cnt;
}

Measured memory_bytes: 1144
#include <iostream>

using namespace std;

int main(){

	int m = 0;
	int f = 0;
	int r = 0;
	
	cin >> m >> f >> r;
	
	while (!(m == -1 && f == -1 && r == -1)) {

		if (m == -1 || f == -1) {

			cout << "F" << endl;

		}
		else {

			if (m + f >= 80) {

				cout << "A" << endl;

			}
			else if (m + f >= 65) {

				cout << "B" << endl;

			}
			else if (m + f >= 50 || m + f >= 30 && r >= 50) {

				cout << "C" << endl;

			}
			else if (m + f >= 30) {

				cout << "D" << endl;

			}
			else {

				cout << "F" << endl;

			}

		}

		cin >> m >> f >> r;

	}
	
	return 0;

}



Measured memory_bytes: 3096
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

using namespace std;

typedef long long ll;

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  string str; cin >> str;
  int v[4];
  for(int i=0;i<4;i++) v[i] = str[i] - '0';
  int n = 3;
  for(int i=0;i<(1 << n);i++){
    // cout << i << endl;
    int sum = v[0];
    for(int j=0;j<n;j++){
      if((i >> j) & 1){
        sum += v[j+1];
      }else{
        sum -= v[j+1];
      }
    }
    if(sum == 7){
      cout << v[0];
      for(int j=0;j<n;j++){
        if((i >> j) & 1){
          cout << '+';
        }else{
          cout << '-';
        }
        cout << v[j+1];
      }
      cout << "=7" << endl;
      return 0;
    }
  }
}

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

int main(){
	string in[100],n;
	int i = 1,ii = 1,stop = 0,si;
	while(stop == 0){
		cin >> n;
		if(n == "#"){stop = 1;}else{in[i] = n;i++;}						
	}
	string ans[i];
	for(ii = 1;i > ii;ii++){
		ans[ii] = "A";
		si = in[ii].size();
		//cout << si << endl;
		for(int iii = 0;si > iii;iii++){
			string c = in[ii].substr(iii,1);
			//cout << "[INT]" <<  c << endl;
			//cout << "[ANS][IN]" <<  ans[ii] << endl;
			if(ans[ii] == "A"){
				if(c == "1"){
					ans[ii] = "Y";
				}else if(c == "0"){
					ans[ii] = "X";
				}
			}else if(ans[ii] == "X"){
				if(c == "1"){
					ans[ii] = "Z";
				}else if(c == "0"){
					ans[ii] = "No";
				}
			}else if(ans[ii] == "Y"){
				if(c == "1"){
					ans[ii] = "No";
				}else if(c == "0"){
					ans[ii] = "X";
				}
			}else if(ans[ii] == "Z"){
				if(c == "1"){
					ans[ii] = "B";
				}else if(c == "0"){
					ans[ii] = "W";
				}
			}else if(ans[ii] == "W"){
				if(c == "1"){
					ans[ii] = "Y";
				}else if(c == "0"){
					ans[ii] = "B";
				}
			}else if(ans[ii] == "B"){
				if(c == "1"){
					ans[ii] = "X";
				}else if(c == "0"){
					ans[ii] = "Y";
				}
			}	
			//cout << "[ANS][OUT]" <<  ans[ii] << endl;
			if(iii == si - 1 and ans[ii] == "B"){ans[ii] = "Yes";}
			if(iii == si - 1){
				if(ans[ii] != "Yes"){ans[ii] = "No";}
				cout << ans[ii] << endl;
			}											
		}
	}
}

Measured memory_bytes: 1200
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		int n, l;
		n = in.nextInt();
		l = in.nextInt();
		
		String[] S = new String[n];
		for (int i = 0; i < n; i++) S[i] = in.next();
		Arrays.sort(S);
		for (int i = 0; i < n; i++) System.out.print(S[i]);
		System.out.println();
	}
}


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

const int MAX = 100000;
int dp[MAX+5];
vector<int> A;

int main() {
    int N;
    scanf("%d", &N);
    int a = 1;
    while (a <= MAX) {
        a *= 6;
        A.push_back(a);
    }
    a = 1;
    while (a <= MAX) {
        a *= 9;
        A.push_back(a);
    }
    sort(A.begin(), A.end());
    for (int i = 1; i <= N; i++) {
        dp[i] = dp[i-1] + 1;
        int p = 0;
        while (i >= A[p]) {
            dp[i] = min(dp[i], dp[i-A[p]] + 1);
            p++;
        }
    }
    printf("%d\n", dp[N]);
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
    long long int n, p, q, r, i, j, min=100000, s=0, ss=0;
    scanf("%lld", &n);
    long long int w[n];
    for(i=0; i<n; i++){
        scanf("%lld", &w[i]);
        s += w[i];
    }
    for(i=0; i<n; i++){
        ss += w[i];
        if(abs(ss*2-s)<min) min = abs(ss*2-s);
    }
    printf("%lld", min);
    
}

Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] a = new int[2][n];
		
		for (int i = 0; i < 2; i++)
			Arrays.setAll(a[i], idx -> sc.nextInt());
		
		int[] sum1 = new int[n];
		int[] sum2 = new int[n];
		sum1[0] = a[0][0];
		sum2[n - 1] = a[1][n - 1];
		
		for (int i = 1; i < n; i++) {
			sum1[i] = sum1[i - 1] + a[0][i];
			sum2[n - 1 - i] = sum2[n - i] + a[1][n - 1 - i];
		}
		
		int max = 0;
		for (int i = 0; i < n; i++) {
			int tmp = sum1[i] + sum2[i];
			max = Math.max(max, tmp);
		}
		
		System.out.println(max);
	}	
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); 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) - 1 * 100);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>

using namespace std;

int n;
int main(void) {
	cin >> n;
	int tm;
	map<int, int> mp;
	rep(i, n) {
		cin >> tm;
		mp[tm - 1]++;
		mp[tm]++;
		mp[tm + 1]++;
	}
	int ans = 0;
	for (auto kv : mp) {
		ans = max(mp[kv.first], ans);
	}
	cout << ans << endl;
	return 0;
}

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

template<class T,class F>
struct segment_tree{
  std::vector<T> data;int n;F f;T identity;segment_tree(){}
  segment_tree(int sz,T ide,F _f):f(_f),identity(ide){n=1;while(n<sz)n<<=1;data.resize(2*n,identity);}
  segment_tree(std::vector<T> const& v,T ide,F _f):f(_f),identity(ide){int sz=v.size();n=1;while(n<sz)n<<=1;data.resize(2*n,identity);for(int i=0;i<sz;++i)data[i+n]=v[i];for(int i=n-1;i>0;--i)data[i]=f(data[i<<1|0],data[i<<1|1]);}
  void set(int i,T x){i+=n;data[i]=x;while(i,i>>=1)data[i]=f(data[i<<1|0],data[i<<1|1]);}
  T fold(int l,int r)const{l=(l<0?n:l+n),r=(r<n?r+n:n<<1);T fold_l=identity,fold_r=identity;while(l<r){if(l&1)fold_l=f(fold_l,data[l++]);if(r&1)fold_r=f(data[--r],fold_r);l>>=1,r>>=1;}return f(fold_l,fold_r);}
  T fold()const{return data[1];}
  T operator[](int i)const{return data[i+n];}
  template<class Cond>int bserch(int l,Cond& cond){l+=n;T x=identity;do{while(!l&1)l>>=1;if(cond(f(x,data[l]))){while(l<n){l<<=1;if(!cond(f(x,data[l])))x=f(x,data[l++]);}return l-n;}x=f(x,data[l++]);}while((l&-l)!=l);return -1;}
};
template<class T,class F>auto make_segtree(int n,T ide,F f){return segment_tree<T,F>(n,ide,f);}

int main(){
  int n,k;
  std::cin>>n>>k;
  std::vector<int> a(n);
  for(auto& ai:a)std::cin>>ai;
  const int amax = 3e5;
  const auto max = [](int a,int b){return a<b?b:a;};
  auto dp = make_segtree<int>(amax+1,0,max);
  for(auto ai:a){
    int l = ai-k;
    int r = ai+k;
    int tmp = dp.fold(l,r+1)+1;
    dp.set(ai,tmp);
  }
  std::cout<<dp.fold()<<std::endl;
}

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

string s;
int main(){
	cin>>s;
    int res = 0;
    for (int i=0;i<3;++i){
        if (s[i]=='1'){
        ++res;
    }
    }
    cout<<res<<endl;
} 

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
	char str[101];
	int i,j,st,en,count;
	while(scanf("%s",str)!=EOF){
		for(i=0;str[i]!='\0';i++){
			if(str[i]=='@'){
				count=str[++i]-'0';
				i++;
				for(j=0;j<count;j++)printf("%c",str[i]);
			}
			else if(str[i]>='0' && str[i]<='9')printf("%c",str[i]);
			else printf("%c",str[i]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 0
def solve():
    N = int(input())
    A1, A2, A3 = map(int, input().split())
    B1, B2, B3 = map(int, input().split())

    dp = list(range(N+1))
    for i in range(N+1):
        if i+A1 <= N:
            dp[i+A1] = max(dp[i+A1], dp[i]+B1)
        if i+A2 <= N:
            dp[i+A2] = max(dp[i+A2], dp[i]+B2)
        if i+A3 <= N:
            dp[i+A3] = max(dp[i+A3], dp[i]+B3)
    N2 = dp[N]

    dp = list(range(N2+1))
    for i in range(N2+1):
        if i+B1 <= N2:
            dp[i+B1] = max(dp[i+B1], dp[i]+A1)
        if i+B2 <= N2:
            dp[i+B2] = max(dp[i+B2], dp[i]+A2)
        if i+B3 <= N2:
            dp[i+B3] = max(dp[i+B3], dp[i]+A3)
    ans = dp[N2]

    print(ans)

solve()


Measured memory_bytes: 228892
import sys
n=int(input())
a=[]
for i in range(n):
  a.append(list(map(int,input().split())))
maxmatch=n*(n-1)
day=0
q=[i for i in range(n)]
nq=[]
match=[0]*(n+1)
check=[0]*(n+1)
while q:
  day+=1
  for i in q:
    if match[i]==n-1 or check[i]==day:
      continue
    else:
      vs=a[i][match[i]]-1
      if check[vs]!=day and a[vs][match[vs]]-1==i:
        match[i]+=1
        match[vs]+=1
        match[n]+=2
        check[i]=day
        check[vs]=day
        check[n]=day
        nq.append(i)
        nq.append(vs)
      
    if i==q[-1]:
      if check[n]!=day:
        print(-1)
        sys.exit()
  if match[n]==maxmatch:
    break
  q=nq[:]
  nq=[]
        
print(day)


Measured memory_bytes: 54108
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}
	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	k := getNextInt(scanner)
	q := getNextInt(scanner)
	aa := make([]int, n)
	for i := 0; i < q; i++ {
		aa[getNextInt(scanner)-1]++
	}

	for i := 0; i < n; i++ {
		if q-aa[i] < k {
			fmt.Fprintln(writer, "Yes")
			continue
		}
		fmt.Fprintln(writer, "No")
	}
	writer.Flush()
}

func canDance(s string) string {
	n := len(s)
	for i := 0; i < n; i++ {
		if i%2 == 1 && s[i] == 'R' {
			return "No"
		}
		if i%2 == 0 && s[i] == 'L' {
			return "No"
		}
	}
	return "Yes"
}


Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
     
int main() {

  int N;
  cin >> N;
  vector<int> H(N);
  for(int i=0; i<N; i++){
    cin >> H.at(i);
  }
  
  int ans = 0;
  int count = 0;
  long long koubai;
  if(N == 1){
    cout << 0 << endl;
  }else{
  for(int i=0; i<N-1; i++){
  	koubai = H.at(i+1) - H.at(i);
    if (koubai <= 0){
      count += 1;
    } else {
      if (ans < count){
        ans = count;
      }
      count = 0;
    }
      if (ans < count){
        ans = count;
      }

  } 
    cout << ans << endl;
  }
}

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

#define vec              vector<int>
#define vecll            vector<ll>
#define vecd             vector<double>
#define vecst            vector<string>
#define vecb             vector<bool>
#define v2(v,n,m,init)   vector<vector<int>>  v(n, vector<int>(m, init))
#define vb2(v,n,m,init)  vector<vector<bool>> v(n, vector<bool>(m, init))
#define vll2(v,n,m,init) vector<vector<ll>>   v(n, vector<ll>(m, init))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
template <typename T>
bool chmax(T &a, const T& b){if(a<b){a=b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a>b){a=b; return true;} return false;}
//----------------------------------------------------------------

int main(void) {
  int n;
  cin >> n;
  arrll(a,n);
  rep(i,n){
    a[i] = 1000000000-a[i];
  }
  ll INF = 1e18;
  vecll dp(n, INF);

  rep(i,n){
    auto tmp = upper_bound(all(dp), a[i]);
    *tmp = a[i];
  }

  auto ans = lower_bound(all(dp), ll(1e18)-1);
  prt(ans-dp.begin());
}


Measured memory_bytes: 4776
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    vector<pair<int,int> > ab(n);
    for(int i=0;i<n;i++){
        cin>>ab[i].first>>ab[i].second;
    }
    sort(ab.begin(),ab.end());
    long long ans=0;
    for(int i=0;i<n;i++){
        if(m<=0)break;
        ans+=(long)ab[i].first*(long)min(m,ab[i].second);
        m-=ab[i].second;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = (int)2e5 + 5;
const int mod = (int)1e9 + 7;
using namespace std;

int a[200005];;

int main()
{
	int n; scanf("%d", &n);
	int l = 1;
	ll ans = 0, sum = 0;
	for(int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
		while((sum ^ a[i]) != sum + a[i]) sum ^= a[l++];
		sum ^= a[i];
		ans += (i - l + 1);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		if(s.length()%2==1)
			System.out.println("No");
		else {
			if(s.substring(s.length()/2).equals(s.substring(0, s.length()/2)))
					System.out.println("Yes");
			else
				System.out.println("No");
		}
	}

}


Measured memory_bytes: 21972
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>

#define rep(i,N) for(int (i)=0;(i)<(N);(i)++)
#define MOD 1000000007

using namespace std;

int main(){
	int N, K, ans = MOD,minus= -1;
	scanf("%d %d", &N, &K);
	vector<int> x(N);
	rep(i, N)scanf("%d", &x[i]);
	for (int i = 0; i <= N - K; i++) {
		if (x[i] <= 0 && 0 <= x[i + K - 1]) {
			if (0 <= x[i] + x[i + K - 1])ans = min(ans, 2 * abs(x[i]) + x[i + K - 1]);
			else ans = min(ans, abs(x[i]) + 2 * x[i + K - 1]);
		}
		else if (0 < x[i]) {
			ans = min(ans, x[i + K - 1]);
		}
		else {
			ans = min(ans, abs(x[i]));
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>

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

    std::vector<long> ans;
    if(b - a + 1 > k){
        for(long i = 0; i < k; ++i){
            ans.push_back(a + i);
            ans.push_back(b - i);
        }
    }else{
        for(int i = a; i <= b; ++i){
            ans.push_back(i);
        }
    }

    std::sort(ans.begin(), ans.end());
    ans.erase(std::unique(ans.begin(), ans.end()), ans.end());

    for(int i = 0; i < ans.size(); ++i){
        std::cout << ans.at(i) << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void solve(){
	int n;
	cin>>n;
	if(n % 2 == 0)cout<<0.5;
	else{
		cout<<double((1.0*ceil(1.0*n/2))/n);
	}
}
int main(){
	
	solve();
	
}

Measured memory_bytes: 256
from sys import exit, stderr, stdin
input = stdin.readline
# setrecursionlimit(10**7)

def debug(var, name="hoge"):
    print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
    return


def main():
    S = input().rstrip()
    LS = len(S)
    o = set(["R","U","D"])
    e = set(["L","U","D"])
    for i in range(LS):
        if i%2 == 0:# odd
            if S[i] not in o:
                print("No")
                exit()
        else:
            if S[i] not in e:
                print("No")
                exit()
    print("Yes")



if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
using P = pair<int,int>;
const int MOD = 1000000007;
#define inf 1e9

int main() {
    int n,ans=0;
    cin>>n;
    vector<int> a(n);
    bool flag=true,stop=false;;
    rep(i,n) {
        cin>>a[i];
        if (a[i]%2!=0) flag=false;
    }
    while(flag) {
        rep(i,n) {
            if (a[i]%2!=0) {
                stop=true;
                break;
            }
            a[i]/=2;
        }
        if (stop) break;
        ans++;
    }
    cout<<ans<<endl;
} 


Measured memory_bytes: 256
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <ctime>
#include <map>
#include <stack>
#include <sstream>
#include <set>
#include <fstream>
#include <cmath>

using namespace std;

int main(void)
{
	int n;

	cin >> n;
	cout << "ABC" << n << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
S = list(input())
R =[]
G = []
B = []
lr = 0
lg = 0
lb = 0
ncount = 0
for i in range(N):
    if S[i] == "R":
        R.append(i)
        lr+=1
    elif S[i] == "G":
        G.append(i)
        lg+=1
    else:
        B.append(i)
        lb+=1
    if i < N/2:
        for j in range(i+1):
            if S[i-j]!=S[i]:
                if S[i-j] != S[i+j]:
                    if S[i+j] != S[i]:
                        ncount+=1
    else:
        for j in range(N-i):
                if S[i-j]!=S[i]:
                    if S[i-j] != S[i+j]:
                        if S[i+j] != S[i]:
                            ncount+=1
print(lr*lg*lb - ncount)

Measured memory_bytes: 9256
from collections import deque
import sys

input= sys.stdin.readline

n,q = [int(i) for i in input().strip().split()]

jobs = deque()
for i in range(n):
    name,time = input().strip().split()
    jobs.append((name,int(time)))

current_time = 0

while jobs:
    name,time = jobs.popleft()
    if time > q:
        jobs.append((name,time - q))
        current_time += q
    else:
        current_time += time
        print(name, current_time)




Measured memory_bytes: 12528
n = gets.to_i
a = gets.split(" ").map(&:to_i)
i = 0
sum = 0
while i < n - 1 do
  if a[i] > a[i+1]
    sum += (a[i] - a[i+1])
    a[i+1] = a[i]
  end
  i += 1
end
puts sum


Measured memory_bytes: 27968
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int H, W;
int c[10][10];
int A[210][210];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> H >> W;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> c[i][j];
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> A[i][j];
    }
  }
  for (int k = 0; k < 10; k++) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (A[i][j] < 0) continue;
      ans += c[A[i][j]][1];
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ull unsigned long long
#define si short int
#define fo(i,a,b) for(int i=a,_E=b;i<_E;++i)
using namespace std;
struct BIT{
	ull w[32];
	inline void reset(){fo(i,0,32)w[i]=0;}
	inline void set(){fo(i,0,32)w[i]=-1;}
	inline int flip(const int &x){w[x>>6]^=1ll<<(x&63);}
	inline bool get(const int &x){return w[x>>6]&1ll<<(x&63);}
}e[2000],d[2000],s,ex[2000][2000];
inline void operator^=(BIT &a,const BIT &b){fo(i,0,32)a.w[i]^=b.w[i];}
inline void operator&=(BIT &a,const BIT &b){fo(i,0,32)a.w[i]&=b.w[i];}
inline void operator|=(BIT &a,const BIT &b){fo(i,0,32)a.w[i]|=b.w[i];}
si n,m,fa[2000];int t;
pair<si,si> q[1000*2000];
#define mp make_pair
vector<si> r[2000];
void dfs(si x,si fr){
	s.flip(x);
	ex[fr][x]=s;
	fo(i,0,r[x].size()){
		si y=r[x][i];if(y==fa[x])continue;
		fa[y]=x;dfs(y,fr);ex[fr][x]|=ex[fr][y];ex[fr][x].flip(y);
	}s.flip(x);ex[fr][x].flip(x);
}
void ins(si x,si y){
	q[t++]=mp(x,y);
	e[x].flip(y);e[y].flip(x);
	d[x].flip(y);d[y].flip(x);
}
int main(){
	cin>>n>>m;
	fo(i,0,n)d[i].set(),d[i].flip(i);
	fo(i,1,n){
		si x,y;cin>>x>>y;--x;--y;
		r[x].push_back(y);r[y].push_back(x);
	}
	fo(i,0,m){
		si x,y;cin>>x>>y;
		--x;--y;ins(x,y);
	}
	fo(i,0,n)fo(j,0,r[i].size())
		fa[r[i][j]]=i,dfs(r[i][j],i);
	fo(i,0,n)fo(j,i+1,n)ex[i][j]|=ex[j][i],ex[j][i]=ex[i][j];
	for(int i=0;i<t;++i){
		int x=q[i].first,y=q[i].second;
		s=ex[x][y];s&=e[x];s&=d[y];
		fo(j,0,32)if(s.w[j]){
			ull S=s.w[j];
			if(S&65535)fo(k,0,16)if(S&1<<k)ins(y,k^j<<6);
			S>>=16;
			if(S&65535)fo(k,0,16)if(S&1<<k)ins(y,k+16^j<<6);
			S>>=16;
			if(S&65535)fo(k,0,16)if(S&1<<k)ins(y,k+32^j<<6);
			S>>=16;
			if(S&65535)fo(k,0,16)if(S&1<<k)ins(y,k+48^j<<6);
		}
		s=ex[x][y];s&=e[y];s&=d[x];
		fo(j,0,32)if(s.w[j]){
			ull S=s.w[j];
			if(S&65535)fo(k,0,16)if(S&1<<k)ins(x,k^j<<6);
			S>>=16;
			if(S&65535)fo(k,0,16)if(S&1<<k)ins(x,k+16^j<<6);
			S>>=16;
			if(S&65535)fo(k,0,16)if(S&1<<k)ins(x,k+32^j<<6);
			S>>=16;
			if(S&65535)fo(k,0,16)if(S&1<<k)ins(x,k+48^j<<6);
		}
	}
	printf("%d",t);
}

Measured memory_bytes: 1009408
N = int(input())
A = list(map(int,input().split())) 
Q = int(input())
BC = [list(map(int,input().split())) for i in range(Q)]

from collections import defaultdict
# 1から10**5までの辞書を作成
memo = defaultdict(int)

for a in A:
    memo[a] += 1

ans = []
now_sum = sum(A)
# print(memo[2])

for ele in BC:

    now_sum += memo[ele[0]]*ele[1] - memo[ele[0]]*ele[0]
    memo[ele[1]] += memo[ele[0]]
    memo[ele[0]] = 0
    ans.append(now_sum)

for an in ans:
    print(an)


Measured memory_bytes: 43456
#include<stdio.h>
#include<string.h>
 
int Hash[16777216];
char s[13];
 
int getChar(char ch){
  if(ch=='A'){
    return 1;
  }else if(ch=='C'){
    return 2;
  }else if(ch=='G'){
    return 3;
  }
  return 4;
}
 
int getKey(){
  int sum=0,p=1;
  for(int i=0;i<strlen(s);i++){
    sum+=p*(getChar(s[i]));
    p*=4;
  }
  return sum;
}
 
int main(){
  int n;
  char com[7];
  scanf("%d",&n);
  while(n--){
    scanf("%s %s",com,s);
    if(com[0]=='i'){
      Hash[getKey()]=1;
      // printf("%d\n",getKey());
    }else{
      if(Hash[getKey()]){
        puts("yes");
      }else{
        puts("no");
      }
    }
  }
  return 0;
}

Measured memory_bytes: 7980
(* Vicfred
 * https://atcoder.jp/contests/abc131/tasks/abc131_b
 * implementation
 * *)
Scanf.scanf "%d %d\n" (fun n l ->
    let flavours = Array.init n (fun i -> l + i) in
    Array.sort (fun x y -> if x = y then 0 else if abs(x) > abs(y) then 1 else -1) flavours;
    let ans = Array.fold_left ( + ) 0 flavours in
    Printf.printf "%d\n" (ans - flavours.(0))
)



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

int main(){
    string S;
    long long K;
    cin >> S >> K;
    int s = S.size();
    vector<int> vec1(100, 0);
    vector<int> vec2(100, 0);
    int t = 1;
    int u = 0;
    long long ans = 0;
    if(s == 1){
        cout << K / 2 << endl;
    }
    else{
        for(int i = 1; i < s; i++){
            if(S.at(i) == S.at(i - 1)){
                t++;
        }
            else{
                vec2.at(u) = t;
                vec1.at(u) += t / 2;
                t = 1;
                u++;
            }
        }
        vec2.at(u) = t;
        vec1.at(u) += t / 2;
      	if(t == s){
          cout << s * K / 2 << endl;
        }
      	else{
        	for(int i = 0; i < 100; i++){
            	ans += vec1.at(i);
        	}
        	if(S.at(0) != S.at(s - 1)){
            	ans *= K;
        	}
        	else{
            	ans -= vec1.at(0) + vec1.at(u);
            	long long a = (vec2.at(0) + vec2.at(u)) / 2;
            	ans = ans * K + a * (K - 1) + vec1.at(0) + vec1.at(u);
        	}
        	cout << ans << endl;
    	}
    }
}

Measured memory_bytes: 256