akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;
const long long MAXN=100005;
long long n,m,k,top;
long long a[MAXN];
long long id[MAXN],st[MAXN],ans[MAXN];
bool vis[MAXN];
int main()
{
	//freopen("rabbit.in","r",stdin);
	//freopen("rabbit.out","w",stdout);
	scanf("%lld",&n);
	for(long long i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		id[i]=i;
	}
	for(long long i=n;i>=1;i--)
		a[i]-=a[i-1];
	scanf("%lld %lld",&m,&k);
	for(long long i=1;i<=m;i++)
	{
		long long x;
		scanf("%lld",&x);
		swap(id[x],id[x+1]);
	}
	for(long long i=1;i<=n;i++)
	{
		if(!vis[i])
		{
			top=0;
			for(long long j=i;!vis[j];j=id[j])
			{
				st[++top]=j;
				vis[j]=1;
			}
			for(long long j=1;j<=top;j++)
			{
				ans[st[j]]=a[st[(k+j-1)%top+1]];
			}
		}
	}
	for(long long i=1;i<=n;i++)
	{
		ans[i]+=ans[i-1];
		printf("%lld\n",ans[i]);
	}
	fclose(stdin);
	fclose(stdout);
}

Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const long long mod = 1e9 + 7;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

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

ll powMod(ll n, ll k, ll m) {
	if (k == 0) {
		return 1;
	} else if (k % 2 == 1) {
		return powMod(n, k - 1, m) * n % m;
	} else {
		ll t = powMod(n, k / 2, m);
		return t * t % m;
	}
}

int main() {
	string s;
	cin >> s;
	
	string t = s;
	string u = t;
	reverse(all(u));
	if (t != u) {
		cout << "No" << endl;
		return 0;
	}

	t=s.substr(0, (s.size()-1)/2);
	u=t;
	reverse(all(u));
	if (t != u) {
		cout << "No" << endl;
		return 0;
	}

	t = s.substr((s.size() + 3) / 2 - 1, s.size());
	u = t;
	reverse(all(u));
	if (t != u) {
		cout << "No" << endl;
		return 0;
	}

	cout << "Yes" << endl;
}

Measured memory_bytes: 256
a,b,c,d = map(int,input().split())

turn = 0
while a > 0 and c > 0:
    if turn == 0:
        c -= b
    else:
        a -= d
    turn = (turn + 1) % 2

if a > 0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9168
<?php
$n = trim(fgets(STDIN));
$array = ["AC" => 0, "WA" => 0, "TLE" => 0, "RE" => 0];
for ($i=0; $i < $n; $i++) { 
	$code = trim(fgets(STDIN));
	$array[$code] += 1;
}

foreach ($array as $key => $value) {
	echo $key . " x " . $value . "\n";
}

Measured memory_bytes: 16064
#include <iostream>
#include <cmath>
#include <climits>
#include <string>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long;

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

    if (N.at(0) == N.at(1) && N.at(1) == N.at(2)) {

        cout << "Yes" << endl;

    }

    else if (N.at(1) == N.at(2) && N.at(2) == N.at(3)) {

        cout << "Yes" << endl;

    }

    else {
        cout << "No" << endl;
    }

}


Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <string.h>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
#define INF 100000000

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


int main(void) {
    int x, y, z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y;
}


Measured memory_bytes: 256
<?php

fscanf(STDIN, '%s', $inputString);

$isEasyToStep = true;

for ($is = 0; $is < strlen($inputString); $is++) {

    if ($is % 2 === 0 && $inputString[$is] === 'L') {
        $isEasyToStep = false;
    }
    else if($is % 2 === 1 && $inputString[$is] === 'R') {
        $isEasyToStep = false;
    }
}

if ($isEasyToStep) {
    echo 'Yes'. PHP_EOL;
}
else{
    echo 'No'. PHP_EOL;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int n,m,q,a[N],b[N],c[N],mx[N],col[N];
vector<int>g[N];
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
#define gc getchar
inline int read()
{
    int ret=0,f=0;char c=gc();
    while(!isdigit(c)){if(c=='-')f=1;c=gc();}
    while(isdigit(c)){ret=ret*10+c-48;c=gc();}
    if(f)return -ret;return ret;
}
void dfs(int x,int y,int z)
{
	if(mx[x]>=y)return;
	mx[x]=y;
	if(!col[x])col[x]=z;
	if(y==0)return;
	for(int i=0;i<g[x].size();i++)
	{
		int v=g[x][i];
		dfs(v,y-1,z);
	}
}
int main()
{
	memset(mx,-1,sizeof(mx));
	n=read();m=read();
	for(int i=1;i<=m;i++)
	{
		int x=read(),y=read();
		g[x].push_back(y);
		g[y].push_back(x);
	}
	q=read();
	for(int i=1;i<=q;i++)
	{
		a[i]=read();b[i]=read();c[i]=read();
	}
	for(int i=q;i;i--)
		dfs(a[i],b[i],c[i]);
	for(int i=1;i<=n;i++)printf("%d\n",col[i]);
}

Measured memory_bytes: 38904
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int op(int a, int b){
    int c = max(a,b);
    return c;
}

int e(){
    return 0;
}

int main(){
    int N,K;
    cin >> N >> K;
    vector<int> A(N);
    rep(i,N){
        cin >> A[i];
    }
    segtree<int, op, e> seg(300008);
    rep(i,N){
        int L = max(0, A[i] - K);
        int R = min(A[i] + K, 300000);
        int x = seg.prod(L,R + 1);
        seg.set(A[i], x + 1);
    }
    int ans = seg.prod(0, 300008);
    cout << ans << endl;
}

Measured memory_bytes: 9636
import java.util.*;

public class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args){
        while(true){
            int n=sc.nextInt();
            if(n==0)break;
            System.out.println(run(n));
        }
    }
    static long run(int n){
        long ans =-100000;
        int[] a = new int[n];
        for(int i=0;i<n;i++){
            a[i]=sc.nextInt();
        }
        
        for(int i=0;i<n;i++){
            for(int j=i;j<n;j++){
                long sum=0;
                for(int k=i;k<=j;k++){
                    sum+=a[k];
                }
                if(sum>ans)ans=sum;
            }
        }
        return ans;
    }
}

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

int main() {
  int a,b;
  cin>>a>>b;
  if(a%2==0 or b%2==0){
    cout<<"No"<<endl;
  }
  else if (a%2!=0 and b%2!=0){
    cout<<"Yes"<<endl;
  }
  return 0;
}

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

using namespace std;

int main()
{
    int n, k ,q;
    cin >> n >> k >> q;
    int *a = new int[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    int *sorted = new int[n];
    for (int i = 0; i < n ;i++) sorted[i] = a[i];
    sort(sorted, sorted + n);

    int res = 1000000000;
    int min = 0;
    int *b = new int[n];
    int *c = new int[n];
    for (int i = 0; i <= n - q - k + 1; i++) {
        if (min < sorted[i]) min = sorted[i];
        else continue;

        //cout << min << endl;

        int ran_sum = 0;
        int ran = 0;
        int start_pos = 0;
        int bi = 0;
        int rmvbl = 0;
        int rmvbl_sum = 0;
        for (int j = 0; j <= n; j++) {
            if (j < n && a[j] >= min) ran++;
            else {
                if (ran < k) {
                    ran = 0;
                    start_pos = j+1;
                    continue;
                }
                rmvbl = ran - k + 1;
                rmvbl_sum += rmvbl;
                ran_sum += ran;

                int ci = 0;
                for (int x = start_pos; x < j; x++) {
                    c[ci] = a[x];
                    ci++;
                }
                sort (c, c + ran);
                for (int x = 0; x < rmvbl; x++) {
                    b[bi] = c[x];
                    bi++;
                }

                ran = 0;
                start_pos = j+1;
            }
        }

        //cout << rmvbl_sum << endl;
        //cout << bi << endl;

        if (rmvbl_sum < q) break;

        sort(b, b + rmvbl_sum);
        //for (int j = 0; j < rmvbl_sum; j++) cout << b[i] << " ";
        //cout << endl;
        if (b[q-1] - min < res) res = b[q-1] - min;
        //cout << res << endl;
        //cout << endl;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N,L;
	cin >> N >> L;
	VI A;
	int ans = 0;
	REP(i, N) {
		ans += (i + L);
		A.push_back(i + L);
	}
	SORT(A);
	int cnt = LLINF,ret=ans;
	REP(i, N) {
		if (abs(ans-(ans - A[i])) <= abs(ans - cnt)) {
			cnt = (ans-A[i]);

			ret = ans - A[i];
			//cout << A[i] << endl;
		}
	}
	cout << ret << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
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;}
template <class T> using heap = priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int R,G;
    cin>>R>>G;
    cout<<G*2-R<<endl;
    return 0;
}


Measured memory_bytes: 256
MOD = 10 ** 9 + 7

def f(k):
    ans = 1
    for x in range(1, k + 1):
        ans = (ans * x) % MOD
    return ans % MOD

def main(n, m):
    if n == m:
        return 2 * f(n) * f(m) % MOD
    if abs(n - m) == 1:
        return f(n) * f(m) % MOD
    return 0

if __name__ == '__main__':
    n, m = map(int, input().split())
    print(main(n, m))


Measured memory_bytes: 38512
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;
int main()
{
	int x,a,b;
	cin >> x >> a >> b;
	if(b-a<=0){
		cout << "delicious" << endl;
	}
	else if(b-a>0&&b-a<=x){
		cout << "safe" << endl;
	}
	else{
		cout << "dangerous" << endl;
	}

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using pLL = std::pair<long long, long long>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	double T, X;
	cin >> T >> X;
	cout << T / X << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = int64_t;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    map<int, int> m;
    sort(v.begin(), v.end());
    for (int i = 0; i < n; ++i) {
        m[v[i]]++;
    }
    int mx = v.back();
    if(v.front() < (mx+1)/2){
        puts("Impossible");
        return 0;
    }
    if(mx%2 == 0 && m[mx/2] != 1){
        puts("Impossible");
        return 0;
    }else if(mx%2 && m[(mx+1)/2] != 2){
        puts("Impossible");
        return 0;
    }
    for (int i = mx-(mx+1)/2+1; i <= mx; ++i) {
        if(m[i] < 2){
            puts("Impossible");
            return 0;
        }
    }
    puts("Possible");
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_abc_a() {
	ll n, m;
	ll x, y;
	ll a, b;
	ll k;
	//string s, t;
	// ans = 0;
	string ans = "NG";

	cin >> x >> a >> b;

	ll t = -a + b;

	if (t <= 0) {
		ans = "delicious";
	}
	else if (t <= x) {
		ans = "safe";
	}
	else {
		ans = "dangerous";
	}

	cout << ans << "\n";

	return;
}


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

	solve_abc_a();

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ld long double
#define ll long long
#define ull unsigned ll
#define pll pair<ll, ll>
#define itr(a) begin(a), end(a)
#define pb push_back
#define x first
#define y second
#define endl '\n'
#define FAST cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define FILES(namein, nameout) freopen(namein, "r", stdin); freopen(nameout, "w", stdout);
#define M 1000000007
#define N 200000
#define INF 101111111111111
using namespace std;
ll n, k;
ll a[N], f[N];
bool can(ll lt){
	ll left_k = k;
	for(ll i = 0;i<n;i++){
		ll th = a[i]*f[i];
		if(th > lt){
			ll nd = th - lt;
			ll xk = nd/f[i] + (nd%f[i] > 0 ? 1 : 0);
			left_k-=xk;
		}
	}
	return left_k>=0;
}
ll binsearch(ll l, ll r){
	while(r-l>1){
		ll m = (l+r)>>1;
		if(can(m)){
			r = m;
		}else{
			l = m;
		}
	}
	for(ll i = l;i<=r;i++) if(can(i)) return i;
	return r;
}
main(){
    FAST;
    cin >> n >> k;
    for(ll i = 0;i<n;i++) cin >> a[i];
    for(ll i = 0;i<n;i++) cin >> f[i];
    sort(a, a+n);
	sort(f, f+n, greater<ll>());
	ll res = binsearch(0, 10000LL*10000LL*10000LL);
	cout << res;
}

Measured memory_bytes: 3328
import bisect
import sys

input = sys.stdin.readline

n = int(input())
l = list(map(int, input().split()))
l.sort()
cnt = 0

for i in range(0, n-2):
    for j in range(i+1, n-1):
        cnt += bisect.bisect_left(l, l[i] + l[j]) - j-1

print(cnt)


Measured memory_bytes: 3188
s = gets.chomp

s = s[0...s.size.pred]
s = s[0...s.size.pred] if s.size.odd?

while true
  break if s[0...(s.size / 2)] == s[(s.size / 2)...s.size]
  s = s[0...(s.size - 2)]
end

p s.size

Measured memory_bytes: 1788
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair <LL,LL>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

LL n,m,res,ans=0,fil,dx[]={1,-1,0,0},dy[]={0,0,1,-1};
string s[410];
bool vis[410][410],ok[410][410];
vector <pii> pass;

inline bool out(LL x,LL y)
{
	return x<0||y<0||x>=n||y>=m;
}

void dfs(LL x,LL y)
{
	rep(i,4)
	{
		LL xx=x+dx[i],yy=y+dy[i];
		if(out(xx,yy)||vis[xx][yy]||s[xx][yy]==s[x][y]) continue;
		vis[xx][yy]=true;
		if(s[xx][yy]=='.') res++;
		else pass.pb({xx,yy});
		dfs(xx,yy);
	}
}

int main()
{
	cin>>n>>m;
	rep(i,n) cin>>s[i];
	rep(i,n)
	{
		rep(j,m)
		{
			if(s[i][j]=='.'||ok[i][j]) continue;
			res=0;
			pass.clear();
			vis[i][j]=true;
			dfs(i,j);
			ans+=res*(pass.size()+1);
			rep(i,pass.size()) ok[pass[i].fi][pass[i].se]=true;
			//cout<<i<<' '<<j<<' '<<res<<endl;
		}
	}
	cout<<ans<<endl;
	rt0;
}

Measured memory_bytes: 17136
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
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
#from decimal import *

S = input()
T = list("AKIHABARA")

idx = [0, 4, 6, 8]

for x in product([0, 1], repeat=len(idx)):
	TC = T.copy()
	for i in range(len(idx)):
		if x[i]:
			TC[idx[i]] = ""

	if "".join(TC) == S:
		print("YES")
		break
else:
	print("NO")


Measured memory_bytes: 5200
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define mod 1000000007

int main() {
	int h, w;
	cin >> h >> w;
	char s[50][50];
	int blackNum = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> s[i][j];
			if (s[i][j] == '#') blackNum++;
		}
	}
	int dx[4] = {0, 1, 0, -1};
	int dy[4] = {1, 0, -1, 0};
	vector<vector<int> > result(h, vector<int>(w, -1));
	result[0][0] = 1;
	queue<pair<int, int> > qu;
	qu.push(make_pair(0, 0));
	while (!qu.empty()) {
		int x = (qu.front()).first;
		int y = (qu.front()).second;
		qu.pop();
		for (int i = 0; i < 4; i++) {
			int nx = x + dx[i];
			int ny = y + dy[i];
			if (nx < 0 || nx >= h || ny < 0 || ny >= w || s[nx][ny] == '#' ||
			    result[nx][ny] >= 0)
				continue;
			result[nx][ny] = result[x][y] + 1;
			qu.push(make_pair(nx, ny));
		}
	}
	if (result[h - 1][w - 1] < 0)
		cout << -1 << endl;
	else
		cout << h * w - blackNum - result[h - 1][w - 1] << endl;
}

Measured memory_bytes: 256
use std::io;

fn get_input() -> String {
    let mut word = String::new();
    io::stdin().read_line(&mut word).ok();
    return word.trim().to_string();
}

fn main() {
    let s = get_input();
    let t = get_input();
    
    let mut count = 0;
    for i in 0..s.len() {
        if &s[i..i+1] != &t[i..i+1] {
            count += 1;
        }
    }
    println!("{}", count);

}

Measured memory_bytes: 2652
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		String S = scan.next();
		char s[] = S.toCharArray();

		//文字の長さ
		int N = S.length();

		int count = 0;

		for(int i = 0; i< N; i++)
		{
			
			// S = abcdefgdcba N = 11
			// S[0]とS[10]比較 a == a
			// S[1]とS[9]比較 b == b
          	// ....S[4]とS[6]比較 e != g
 			if(s[i] != s[N - 1-i]) {
				count++;
			}
		}
		System.out.println(count/2);


	}
}

Measured memory_bytes: 21716
#include<stdio.h>
#define MAX 2000000001
int n,A[MAX];

void maxHeapify(int i){
  int temp,l,r,large;
  l=2*i;
  r=2*i+1;

  if(l <= n && A[l] > A[i])large = l;
  else large = i;
  if(r <= n && A[r] > A[large]) large = r;

  if(large != i){
    temp = A[i];
    A[i]=A[large];
    A[large] = temp;
  maxHeapify(large);
  }
}



int main(){
  int i;

  
  scanf("%d",&n);
  for(i=1; i<=n; i++){
    scanf("%d",&A[i]);
  }

  for(i=n/2; i>=1; i--){
    maxHeapify(i);
  }
  for(i=1; i<=n; i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 3684
#include<stdio.h>
#include<math.h>

void Duplex_Printing(){
    int a;
    scanf("%d", &a);
    double res=ceil(a/2.0);
    int res2 = res;
    printf("%d\n",res2);
}

int main()
{
    Duplex_Printing();
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k,x,y,n;
  cin>>n>>k>>x>>y;
  if(k>=n)
    cout<<n*x<<'\n';
  else
    cout<<k*x+(n-k)*y<<'\n';
  return(0);
}
  


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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){

int N, M, K;
cin >> N >> M >> K;

vector<bool>A(N * M + 1, false);

REP(i, N + 1)REP(j, M + 1){
  A[i * M + j * N - i * j *2] = true;
}

if(A[K]) yes;
else no;


}


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


using namespace std;

int Max = 1000000007;

vector<long long> Searched;

int num;

long long Find(int k) {
    long long output = 0;
    if (Searched[k] != 0) {
        return Searched[k];
    }
    if (k == 0) {
        return 1;
    }
    if (k < 3) {
        return 0;
    }
    for (int i = 3; i <= k; i++) {
        output += Find(k - i);
        output %= Max;
    }
    Searched[k] = output;
    return output;

}

int main() {

    cin >> num;
    Searched.resize(2003);
    long long output = 0;
    output = Find(num);
    cout << output;

    return 0;
}

Measured memory_bytes: 3188
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>
#define typeof(x) __typeof__(x)
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define nmod(x) (((x-1) % MOD) + MOD) % MOD + 1
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i)

#define ALL(c) (c).begin(),(c).end()
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) UB(c,x)-LB(c,x)
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define PB push_back
#define MP make_pair
#define vec vector

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

using namespace std;

struct edge {
  int to, cost;
};

const int INF = 1e18;
int MOD = 1e9+7;

template<typename T> ostream& operator << (ostream& s, const vector<T>& v) {
  int len = v.size();
  s << "[";
  for (int i = 0; i < len; i++) {
    s << v[i]; if (i < len - 1) s << " ";
  }
  s << "]";
  return s;
}


signed main()
{
  int n, m; cin >> n >> m;
  MOD = m;
  vec<int> a(n);
  rep(i, 0, n) {
    cin >> a[i];
  }

  vec< vec<int> > b(m+1, vec<int>());
  rep(i, 0, n-1) {
    b[a[i+1]].PB(i);
  }

  vec<int> c(m+2, 0);
  rep(i, 0, n-1) {
    if (mod(a[i+1] - a[i]) == 1) {
      continue;
    }
    int l = nmod(a[i]+1), r = nmod(a[i+1]-1);
    if (l <= r) {
      c[l]++; c[r+1]--;
    } else {
      c[l]++; c[m+1]--; c[1]++; c[r+1]--;
    }
  }

  vec<int> d(m+1, 0);
  rep(i, 0, m) {
    d[i+1] = d[i] + c[i+1];
  }

  vec<int> sum(m+1);
  rep(i, 0, n-1) {
    sum[1] += min(mod(a[i+1]-a[i]), mod(a[i+1]-1) + 1);
  }
  rep(x, 1, m) {
    int s = 0;
    rep(i, 0, SZ(b[x])) {
      int idx = b[x][i];
      s += mod(a[idx+1]-a[idx]) - 1;
    }
    s -= d[x];
    sum[x+1] = sum[x] + s;
  }

  SORT(sum);
  cout << sum[1] << endl;

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair <ll, ll> pll;

int main(){
        vector <pll> ab;
        ll N, K;
        cin>>N>>K;
        for(ll i=0;i<N;i++){
                ll aa, bb;
                cin>>aa>>bb;
                ab.push_back(make_pair(aa, bb));
        }
        sort(ab.begin(), ab.end());
        ll res, cnt=0;
        for(int i=0;i<(int)ab.size();i++){
                cnt+=ab[i].second;
                if(cnt>=K){
                        res=ab[i].first;
                        break;
                }
        }
        cout<<res<<endl;
        return 0;
}


Measured memory_bytes: 2420
/**
*    author:  souzai32
*    created: 21.08.2020 00:15:18
**/

#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
typedef long long ll;
using namespace std;

int main() {

    int h,w;
    cin >> h >> w;
    vector<vector<char>> s(h,vector<char>(w));
    vector<vector<bool>> t(h,vector<bool>(w));
    vector<vector<int>> d(h,vector<int>(w));
    int num=0;
    rep(i,h){
        rep(j,w){
            cin >> s.at(i).at(j);
            if(s.at(i).at(j)=='.') num++;
        }
    }
    queue<int> qh,qw;
    int x,y;

    if(s.at(0).at(0)=='#' || s.at(h-1).at(w-1)=='#') cout << -1 << endl;
    else{
        qh.push(0);
        qw.push(0);
        t.at(0).at(0)=true;
        while(!qh.empty()){
            x=qh.front(); y=qw.front();
            qh.pop(); qw.pop();
            if(x!=0){
                if(s[x-1][y]=='.'&&!t[x-1][y]){
                    t[x-1][y]=true;
                    qh.push(x-1);
                    qw.push(y);
                    d[x-1][y]=d[x][y]+1;
                }
            }if(y!=0){
                if(s[x][y-1]=='.'&&!t[x][y-1]){
                    t[x][y-1]=true;
                    qh.push(x);
                    qw.push(y-1);
                    d[x][y-1]=d[x][y]+1;
                }
            }if(x!=h-1){
                if(s[x+1][y]=='.'&&!t[x+1][y]){
                    t[x+1][y]=true;
                    qh.push(x+1);
                    qw.push(y);
                    d[x+1][y]=d[x][y]+1;
                }
            }
            if(y+1<w){
                if(s.at(x).at(y+1)=='.'&&!t.at(x).at(y+1)){
                    t[x][y+1]=true;
                    qh.push(x);
                    qw.push(y+1);
                    d[x][y+1]=d[x][y]+1;
                }
            }
        }
        if(d[h-1][w-1]) cout << num-d[h-1][w-1]-1 << endl;
        else cout << -1 << endl;
        // rep(i,h){
        //     rep(j,w) cout << d[i][j];
        //     cout << endl;
        // }
    }



    return 0;
}

Measured memory_bytes: 3612
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

//macro
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define EPS (1e-8)
#define equals(a,b)(fabs((a)-(b))<EPS)

using ll = long long;
using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vvll = vector<vll>;
//func
template<typename A, typename T>void assign2d(A&arr, ll H, ll W, T t) { arr.resize(H); REP(i, H) arr[i].assign(W, t); }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); REP(i, n)os << v[i] << (i == n - 1 ? "" : " "); return os; }
template <class T = int> inline T IN() { T x; cin >> x; return x; }
template<class T> inline void OUT(const T &x) { cout << x << "\n"; }
void YESNO(bool c) { OUT(c ? "YES" : "NO"); };
void YesNo(bool c) { OUT(c ? "Yes" : "No"); };
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); /*cout << fixed << setprecision(6);*/ } } pre__;

int main() {
	int N;
	cin >> N;
	int ans = 0;
	REP(i, N) {
		int L, R;
		cin >> L >> R;
		ans += abs(L - R) + 1;
	}
	OUT(ans);
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

using namespace std;
using ll = long long;

int main() {
  ll N, SA{}, SB{}, SD, ans{};
  cin >> N;
  vector<ll> A(N), B(N), D(N);
  for(ll &a: A) cin >> a, SA += a;
  for(ll &b: B) cin >> b, SB += b;
  for (int i = 0; i != N; ++i) {
    D[i] = A[i] - B[i];
  }
  if (SA < SB) ans = -1;
  else {
    sort(begin(D),end(D));
    int l = lower_bound(begin(D), end(D), 0) - begin(D);
    SD = accumulate(begin(D), begin(D) + l, 0ll);
    ans = l;
    for (int i = 1; N-i >= l; ++i) {
      if (SD>=0) break;
      ++ans;
      SD += D[N-i];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 5644
#include<iostream>

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

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

    int ans=0;
    rep(i,a+1){
        rep(j,b+1){
            rep(k,c+1){
                if(500*i+100*j+50*k==x)ans++;
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
import math
lista = []
for x in range(0,5):
    lista.append(int(input()))
distanciaMaxima = int(input())
passou = 0
for x in range(len(lista)):
    for y in range(x,len(lista)):
        if abs(lista[x] - lista[y]) > distanciaMaxima:
            passou = 1
if passou == 0:
    print("Yay!")
elif passou == 1:
    print(":(")


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

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
 /*long long int t;
  cin>>t;
  while(t--)
  {
  }*/
  long long int x,y,z;
  cin>>x>>y>>z;
  cout<<z<<" "<<x<<" "<<y;
  
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env pypy3
# -*- coding: utf-8 -*-

N = int(input())
a = list(map(int, input().split()))
assert len(a) == N

# 解説を参照
# https://img.atcoder.jp/arc101/editorial.pdf

def mergesort(S, f, t):
    global T

    if t - f <= 1:
        return 0

    mid = (f + t) // 2
    n1 = mergesort(S, f, mid)
    n2 = mergesort(S, mid, t)
    n = n1 + n2
    i = f
    j = mid
    k = f
    while i < mid and j < t:
        if S[i] <= S[j]:
            T[k] = S[i]
            i += 1
            n += t - j
        else:
            T[k] = S[j]
            j += 1
        k += 1

    while i < mid:
        T[k] = S[i]
        i += 1
        k += 1
    assert k == j
    for i in range(f, k):
        S[i] = T[i]
    return n

def inversion(S):
    """リストSの転倒数"""
    global T
    T = [0] * len(S)
    return mergesort(S, 0, len(S))

def n_median_larger_than_or_equal_to(x):
    """aの部分列の中央値のうちx以上のものの個数"""

    # aの要素を -1, 1 に置換したリスト
    b = [-1 if e < x else 1 for e in a]
    # bの累積和
    S = [0]
    for e in b:
        S.append(S[-1] + e)
    # Sの転倒数
    return inversion(S)

# 条件を満たす x の最大値を2分探索で探す
lo = 1
hi = max(a)

ncomb = N * (N + 1) // 2    # 部分列の個数

while lo < hi:
    mid = (lo + hi + 1) // 2
    nm = n_median_larger_than_or_equal_to(mid)
    if nm >= (ncomb + 1) // 2:
        lo = mid
    else:
        hi = mid - 1

print(lo)


Measured memory_bytes: 138172
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
#include <string>
using namespace std;

int main()
{
    double L;
    cin >> L;

    double ans = pow(L / 3, 3);

    //cout << fixed << ans << endl;
    printf("%.12f\n", ans);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll Pow(ll n,ll p){
	ll r=1;
	for(;p>0;p>>=1){
		if(p&1) r=(r*n)%mod;
		n=(n*n)%mod;
	}
	return r;
}

const int M=100005;
ll F[M];

void Init(){
	F[0]=1;
	for(int i=1;i<M;i++) F[i]=F[i-1]*i%mod;
}

ll Div(ll n,ll m){
	return n*Pow(m,mod-2)%mod;
}

ll nCk(ll n,ll k){
	return Div(F[n],F[n-k]*F[k]%mod);
}

int n,m;
vi a;

int main(){
	Init();
	cin>>n>>m;
	a=vi(m);
	for(auto &i:a) cin>>i;
	sort(a.rbegin(),a.rend());
	vl dp(1<<n);
	dp[0]++;
	for(int i=0;i<m;i++){
		vl DP=dp;
		for(int j=0;j<1<<n;j++) if(dp[j]){
			int t=(1<<n)-a[i];
			for(int k=0;k<n;k++) if(j&1<<k) t-=1<<k;
			for(int k=0;k<n;k++) if(!(j&1<<k)&&t>=(1<<k)-1){
				(DP[j|(1<<k)]+=dp[j]*nCk(t,(1<<k)-1)%mod*F[1<<k])%=mod;
			}
		}
		dp=DP;
	}
	ll res=0;
	for(int i=0;i<1<<n;i++){
		ll t=0,x=dp[i],tmp=(1<<n)-1;
		for(int j=0;j<n;j++) if(i&1<<j){
			t++;
			tmp-=1<<j;
		}
		(x*=F[tmp])%=mod;
		if(t%2==1) (x*=mod-1)%=mod;
		(res+=x)%=mod;
	}
	for(int i=0;i<n;i++) (res*=2)%=mod;
	cout<<res<<endl;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long  n,c=0;
    long long t,temp=0;
    cin >> n;
    while(n--)
    {
        cin >> t;
        if(temp>t) {
            c=c+abs(temp-t);
            t=t+abs(temp-t);
        }
        temp=t;
        //cout << temp << " " << endl;
    }
    cout << c << endl;
}


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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<double> arr(n);
	for(double& x : arr) cin >> x;
	
	while((int) arr.size() > 1) {
		sort(arr.rbegin(), arr.rend());
		double x = arr.back();
		arr.pop_back();
		x += arr.back();
		arr.pop_back();
		arr.push_back(x/2);
	}
	
	cout << fixed << setprecision(10) << arr[0] << endl;
}


Measured memory_bytes: 256
<?php

// Scan n
fscanf(STDIN, "%d", $n);
$count = 0;
while (!in_array($n, [1, 2, 4])) {
    if ($n % 2) {
        $n = 3 * $n + 1;
    } else {
        $n /= 2;
    }
    $count++;
}

echo $count + 4;

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

int main(){
  int N,i,frag;
  frag = 0;
  cin >> N;

  vector<char> vec(N);
  for(i = 0;i < N;i++){
    cin >> vec.at(i);
    if(vec.at(i) == 'Y'){
      frag = 1;
    }
  }
  //for(i = 0;i < N;i++){
  //  cout << vec.at(i) << endl;
  //}

  //cout << frag << endl;

  if(frag == 1){
    cout << "Four" << endl;
  }else{
    cout << "Three" << endl;
  }

}


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

using namespace std;

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

	int count = 0;

	for (int i = 0; i < n; ++i) {
		int minValue_point = i;
		for (int j = i + 1; j < n; ++j) {
			if (A[j] < A[minValue_point]) {
				minValue_point = j;
			}
		}
		if (minValue_point != i)
		{
			swap(A[i], A[minValue_point]);
			++count;
		}
	}

	for (int i = 0; i < n - 1; ++i) {
		cout << A[i] << " ";
	}
	cout << A[n - 1] << endl;
	cout << count << endl;
	return 0;
}


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

int main(){
	int a, b, c, d;
	scanf("%d%d%d%d", &a, &b, &c, &d);
	int ans = 0;
	bool flag = false;
	for(int i = a; i <= b; i++) {
		if(i >= c && i <= d) {
			ans++;
			flag = true;
		}
	}
	printf("%d\n", ans - flag);
}


Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef bitset<16> BS;

const ll MOD = 1E+09 + 7;
const int INF = 1E09;
const int MAX_N = 200;

int H, W;

int A[MAX_N][MAX_N];

ll d[10][10]; //d[u][v]は辺e=(u,v)のコスト(存在しない場合はINF、d[i][i]=0)

void warshall_floyd();

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

    cin >> H >> W;

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> d[i][j];
        }
    }
    warshall_floyd();

    ll ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> A[i][j];
            if (A[i][j] != -1) {
                ans += d[A[i][j]][1];
            }
        }
    }

    /*
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cout << "i = " << i << ", j = " << j << ", dp = " << dp[i][j] << "\n";
        }
    }
    */

    cout << ans << "\n";

    return 0;
}

void warshall_floyd()
{
    for (int k = 0; k < 10; k++) {
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

Measured memory_bytes: 3748
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            long total = 0;
            for(int i=0; i<n; i++){ 
                total = total + sc.nextInt();
            }
            System.out.println(total/n);
    }
}


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

typedef long long ll;
const ll maxn = 9999999999999;

int main()
{
    int n,k; cin >> n >> k;
    int a[n+5];
    ll dp[n+5];
    for(int i = 0;i < n;i++){cin >> a[i]; dp[i] = maxn;}
    dp[0] = 0;
    for(int i = 0;i < n-1;i++){
        for(int j = i+1;j <= i+k;j++){
            if(j < n && abs(a[j]-a[i])+dp[i] < dp[j])
                dp[j] = abs(a[j]-a[i])+dp[i];
        }
    }

    cout << dp[n-1] << endl;

    return 0;
}


Measured memory_bytes: 1408
while True:
    n,x = map(int, input().split())
    count = 0
    if n == 0 and x == 0:
        break
    
    for i in range(n):
        for j in range(n):
            for k in range(n):
                if i+j+k+3 == x:
                    if i != j and j != k and k != i:
                        if i <= j and j <= k:
                            count += 1
    
    print(count)


Measured memory_bytes: 5596
#include <iostream>
#include <vector>
#include <string>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cfloat>
#include <algorithm>
#define PB push_back
#define ll long long
#define ull unsigned long long
#define uint unsigned
#define PIE (3.14159265358979323846)
#define MOD 1000000007;
using namespace std;

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

    int k {}, x {};
    cin >> k >> x;

    if (k*500 >= x) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}
 
long long n;
string s;
int ans[100002];
bool flag = false;

int main(){
    cin >> n >> s;
    int are0[4] = {1,1,-1,-1}, are1[4] = {1,-1,1,-1};

    for(int i = 0; i < 4; i++){
        ans[0] = are0[i];
        ans[1] = are1[i];

        for(int j = 1; j < n; j++){
            if(s[j] == 'o'){
                if(ans[j] == 1) ans[j+1] = ans[j-1];
                else    ans[j+1] = -1 * ans[j-1];
            }
            else{
                if(ans[j] == 1) ans[j+1] = -1 * ans[j-1];
                else    ans[j+1] = ans[j-1];
            }
        }

        flag = ans[0] == ans[n];
        if(flag){
            if(s[0] == 'o'){
                if(ans[0] == 1) flag = ans[1] == ans[n-1];
                else    flag = ans[1] != ans[n-1];
            }
            else{
                if(ans[0] == 1) flag = ans[1] != ans[n-1];
                else    flag = ans[1] == ans[n-1];                
            }
        }

        if(flag){
            for(int j = 0; j < n; j++){
                if(ans[j] == 1) cout << 'S';
                else    cout << 'W';
            }
            cout << endl;
            return 0;
        }
    }
    cout << "-1\n";
}

Measured memory_bytes: 896
L, R = map(int, input().split())
if R - L >= 673:
    print(0)
elif R - L == 1:
    print((R*L)%2019)
else:
    L %= 2019
    R %= 2019
    if L > R:
        print(0)
    else:
        ans = (L*R)%2019
        for l in range(L, R):
            for r in range(l+1, R+1):
                val = (l*r)%2019
                ans = min(ans, val)
        print(ans)

Measured memory_bytes: 64432
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>

using namespace std;
typedef long long llong;
const int MOD=1000000007;

int main(int argc, char**argv){
    int n, a;
    cin >> n >> a;
    int x = n % 500;
    if (a >= x) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <list>
#include <deque>
using namespace std;
typedef pair<int, int> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;
int GCD(int a, int b){
    if(b==0) return a;
    return GCD(b, a%b);
}
int ext_euclid(int a, int b, int& x, int& y){
    if(b==0){
        x=1; y=0;
        return a;
    }
    int d = ext_euclid(b, a%b, y, x);
    y -= a/b * x;
    return d;
}

int main() {
    int x, y;
    int a, b; cin >> a >> b;
    ext_euclid(a, b, x, y);
    cout << x << " " << y << endl;
	return 0;
}


Measured memory_bytes: 3104
#include<stdio.h>
#include<string.h>
#define MAX 2000000
#define INF 1000
int H, A[MAX+1];

void heap(int i){
	int left, right, nodemax;
	int temp;
	left = 2 * i;
	right = 2 * i + 1;

	if(left <= H && A[left] > A[i] ){
		nodemax = left;
	}
	else nodemax = i;

	if(right <= H && A[right] > A[nodemax]){
		nodemax = right;
	}

	if(nodemax != i){
		temp = A[i];
		A[i] = A[nodemax];
		A[nodemax] = temp;
		heap(nodemax);
	}
}

int extract(){
	int max_ex;
	if( H < 1){
		return -INF;
	}
	max_ex = A[1];
	A[1] = A[H--];
	heap(1);
	return max_ex;
}

void increse(int i, int j){
	int temp;
	if(j < A[i]) return;
	A[i] = j;
	while(i > 1 && A[i/2] < A[i]){
		temp = A[i];
		A[i] = A[i/2];
		A[i/2] = temp;
		i = i/2;
	}
}

void insert(int i){
	H++;
	A[H] = -INF;
	increse(H,i);
}

int main(){
	int p;
	char com[10];

	while(1){
		scanf("%s",com);
		if(com[0] == 'e' && com[1] == 'n') break;
		if(com[0] == 'i'){
			scanf("%d",&p);
			insert(p);
		}
		else {
			printf("%d\n",extract());
		}
	}
	return 0;
}


Measured memory_bytes: 5600
S = input()
N = len(S)
table = [1] + [0] * 2020
exp = [1]
for i in range(N):
    exp += [exp[-1]*10 %2019]

curr = 0
for i in range(N):
    curr += int(S[N-1-i])*exp[i]
    curr %= 2019
    table[curr] += 1

ans = 0
for i in table:
    ans += i*(i-1)//2
print(ans)

Measured memory_bytes: 16340
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<array>
#include<vector>
#include<functional>
#include<unordered_map>
#include<map>
#include<numeric>
#include<limits>
#include<utility>
#include<queue>
#include<random>
using namespace std;
 
int main(){
    
    
    int x,a,b;
    
    cin >> x >> a >> b;
     
    if(x > a){
    a = x - a;
    }
   else{a = a- x;}
 
    if(x > b){
    b = x - b;
    }else{b = b - x;}
    
    
    if(a < b){
    cout << "A" << endl;
    }
    else{cout << "B" << endl;}
    
    return 0;
 
}

Measured memory_bytes: 256
def bin_search(s, i):
    l = -1
    r = len(s)
    
    while r-l>1:
        m = (l+r)//2
        
        if s[m]>i:
            r = m
        else:
            l = m
    
    return(s[l]==i)
    
n = int(input())
S = sorted(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))

counter = 0

for t in T:
    if bin_search(S, t):
        counter += 1
        
print(counter)


Measured memory_bytes: 16712
N,A,B,C,D=list(map(int,input().split()))
if N%A==0: p=N/A
else: p=N//A+1
if N%C==0: q=N/C
else: q=N//C+1
if B*p<D*q: print(int(B*p))
else: print(int(D*q))



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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

static const ll INF = 1e15;

const ll mod = 1000000007;

int main(void)
{
	ll n, k, l, r;
	cin >> n >> k >> l >> r;
	vector<ll> left(n / 2);
	vector<ll> right(n - n / 2);
	rep(i, n / 2) cin >> left[i];
	rep(i, n - n / 2) cin >> right[i];

	vector<vector<ll>> ls(left.size() + 1);
	rep(i, 1LL << left.size()) {
		ll sum = 0;
		ll p = 0;
		rep(j, left.size()) {
			if (i & (1LL << j)) {
				sum += left[j];
				p++;
			}
		}
		ls[p].push_back(sum);
	}
	vector<vector<ll>> rs(right.size() + 1);
	rep(i, 1LL << right.size()) {
		ll sum = 0;
		ll p = 0;
		rep(j, right.size()) {
			if (i & (1LL << j)) {
				sum += right[j];
				p++;
			}
		}
		rs[p].push_back(sum);
	}
	for (auto& p : ls) sort(p.begin(), p.end());
	for (auto& p : rs) sort(p.begin(), p.end());

	ll sum = 0;
	for (int i = 0; i < ls.size(); i++) {
		for (int j = 0; j < ls[i].size(); j++) {
			int c = k - i;
			if (c >= 0 && c < rs.size()) {
				ll cost = ls[i][j];
				auto p1 = upper_bound(rs[c].begin(), rs[c].end(), r - cost);
				auto p2 = lower_bound(rs[c].begin(), rs[c].end(), l - cost);
				sum += p1 - p2;
			}
		}
	}
	cout << sum << endl;
	return 0;
}



Measured memory_bytes: 23416