akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(a, b) for(int a = 0; a < b; a++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> LL;
typedef vector<int> vi;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const int MAXN = 2e5 + 100;

ll st[4 * MAXN];
int H[MAXN], n;
ll A[MAXN];

void update(int p, int l, int r, int x, ll y) {
	if (l == r) {
		st[p] = y;
		return;
	}
	int mid = (l + r) >> 1;
	if (x <= mid) update(p << 1, l, mid, x, y);
	else update(p << 1 | 1, mid + 1, r, x, y);
	st[p] = max(st[p << 1], st[p << 1 | 1]);
	return;
}

ll query(int p, int l, int r, int x, int y) {
	if (l > y || r < x) return 0;
	if (l >= x && r <= y) return st[p];
	int mid = (l + r) >> 1;
	return max(query(p << 1, l, mid, x, y), query(p << 1 | 1, mid + 1, r, x, y));
}

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	REP(i, n) cin >> H[i];
	REP(i, n) cin >> A[i];
	REP(i, n) {
		ll maks = query(1, 0, MAXN - 90, 1, H[i] - 1);
		maks += A[i];
		update(1, 0, MAXN - 90, H[i], maks);	
	}
	cout << st[1] << '\n';
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};
// h(n, r) = c(n+r-1, r)
struct combination
{
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1)
  {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i)
    fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i)
    ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k)
  {
    if (k < 0 || k > n)
    return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

int main()
{
  int n, k;
  cin >> n >> k;
  combination C(2*n);
  auto H = [&](int n, int r) {
    return C(n+r-1, r);
  };

  mint ans = 0;
  for(int i = 0; i <= min(n-1, k); ++i) {
    ans += C(n, i) * H(n-i, i);
  }
  cout << ans.x << endl;
}

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

int main() { 
long long  a,b; 
char c; 
scanf ("%lld %c %lld" , &a ,&c , &b); 

if (c == '+') { 
printf("%lld\n",a+b) ;
  }
else {

printf("%lld\n",a-b) ; 
}

return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i, m, n) for (ll i = m; i < (n); i++)
#define RFOR(i, m, n) for (ll i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
//#define print(ele) cout << (ele) << "\n"
#define print10(ele) cout << fixed << setprecision(10) << (ele) << "\n"

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}

int main() {
  string s;
  cin >> s;
  print(s == "ABC" ? "ARC" : "ABC");
  return 0;
}

Measured memory_bytes: 3632
#include<iostream>
using namespace std;
#define int long long
#define f first
#define s second
#define INF ((long long)1e18)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define MAX 110000

int s[MAX], t[MAX], ans[MAX];
pair<int,int> x[MAX];

template<class RandomAccessIterator>
void comb_sort(RandomAccessIterator first, RandomAccessIterator second){
	long long N = second-first, h = N*10/13;
	bool flag = true;
	while(flag){
		flag = false;
		if(h==9||h==10) h = 11;
		for(int j = N-1; j-h >= 0; j--){
			if(*(first+j) < *(first+j-h)){
				swap(*(first+j),*(first+j-h));
				flag = true;
			}
		}
		if(h>1)flag = true,h = h*10/13;
		else h = 1;
	}
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int A, B, Q, a, b, c, d;
	cin>>A>>B>>Q;
	rep(i,A)cin>>s[i];rep(i,B)cin>>t[i];rep(i,Q){cin>>x[i].f;x[i].s = i;}
	comb_sort(x,x+Q);
	for(int i = 0, j = 0, k = 0; i < Q; i++){
		for(;j < A && x[i].f >= s[j];j++);for(;k < B && x[i].f >= t[k];k++);
		a = j?x[i].f-s[j-1]:INF,b = j-A?s[j]-x[i].f:INF,c = k?x[i].f-t[k-1]:INF,d = k-B?t[k]-x[i].f:INF;
		ans[x[i].second] = min(min(max(a,c),max(b,d)),min(min(a,d)*2+max(a,d),min(b,c)*2 + max(b,c)));
	}
	rep(i,Q) cout<<ans[i]<<"\n";
	return 0;
}

Measured memory_bytes: 5376
f[168],z[]={24,23,25,12,36,11,13,35,37,22,26,48,0},x,s;main(y){for(;s?++f[y*12+x+z[--s]]:~scanf("%d,%d,%d",&x,&y,&s)?s=s*4+1:0;);for(x=y=0,s=23;++s<144;s%12<10?y=fmax(y,f[s]),f[s]&&++x:0);x=!printf("%d\n%d\n",100-x,y);}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
string s;
inline long long stoi(int start,int end)
{
	long long ans=0;
	for(int i=start;i<=end;i++)
		ans=ans*10+(s[i]-'0');
	return ans;
}
inline void test_func()
{
	long long ans=0;
	for(int i=0;i<pow(2,s.size()-1);i++)
	{
		vector<int> v;
		int t=i;
		while(t)
		{
			v.push_back(t%2);
			t/=2;
		}
		while(v.size()!=s.size()-1)
			v.push_back(0);
		reverse(v.begin(),v.end());
		int cur=0;
		for(int j=0;j<v.size();j++)
		{
			if(v[j]==1)
			{
				ans+=stoi(cur,j);
				cur=j+1;
			}
		}
		ans+=stoi(cur,s.size()-1);
	}
	cout<<ans<<endl;
}
int main()
{
	cin>>s;
	test_func();
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
#include <utility>
#include <queue>
#include <vector>
#include <string>
#include <stack>
#include <random>
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
typedef long long int ll;
const ll  MOD = 1000000007;
typedef pair<ll,ll> P;
const ll INF = 100100100100100100;

ll A,B,C,D,E,F;
bool water[100];
bool sugar[100000];
int main(){
  cin >> A >> B >> C >> D >> E >> F;
  water[0] = true;
  for(int i=0;i<30;i++){
    if(water[i]){
      water[i+A] = true;
      water[i+B] = true;
    }
  }
  sugar[0] = true;
  for(int i=0;i<10000;i++){
    if(sugar[i]){
      sugar[i+C] = true;
      sugar[i+D] = true;
    }
  }
  double best = 0;
  ll ansa = A*100;
  ll ansb = 0;
  for(int i=1;i<30;i++){
    if(!water[i]) continue;
    if(i*100 > F) break;
    ll tmp = i * E;
    ll s_best = 0;
    //cerr << " " << i << endl;
    //cerr << " " << tmp << endl;
    for(int j=tmp;j>0;j--){
      if(sugar[j]){
        s_best = j;
        break;
      }
    }
    if(i*100 + s_best > F){
      s_best -= (i*100 + s_best - F);
      if(s_best < 0) s_best = 0;
    }
    //cerr << " " << s_best << endl;
    double t = 100.0 * s_best / (i*100.0 + s_best);
    //cerr << "  " << t << endl;
    if(t > best){
      //cerr << i << " " << t << " " << s_best << endl;
      best = t;
      ansa = i*100 + s_best;
      ansb = s_best;
    }
  }
  cout << ansa << " " << ansb << endl;

}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

const int maxn = 100000 + 5;
int  N, M;
int mem[maxn];

int solve()
{
	int ans[M-1]; 
	sort(mem, mem+M);
	for(int i = 0; i < M-1; i++)
	{
		ans[i] = mem[i+1] - mem[i];   
	}
	sort(ans, ans+M-1, greater<int>());
	int sum = 0;
	for(int i = 0; i < N-1; i++) sum += ans[i];
	return (mem[M-1]-mem[0])-sum;
}

int main()
{
	cin >> N >> M;
	for(int i = 0; i < M; i++) cin >> mem[i];
	if(N >= M) printf("0\n");
	else printf("%d\n", solve());
}

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

int main() {
  char c;
  cin >> c;
  if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
    cout << "vowel" << endl;
  }
  else cout << "consonant"<< endl;
}

Measured memory_bytes: 3552
// https://atcoder.jp/contests/abc142/tasks/abc142_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    printf("%.10f\n", (double)(n - n / 2) / n);
    return 0;
}


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

#define F first 
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 200010, M = 2 * N;

int n;
int a[N];

int main()
{
	cin >> n;
	for (int i = 1; i <= n; i ++ ) cin >> a[i];
	int res = 0;
	for (int i = 1; i <= n; i ++ )
		if (a[i] == i)
		{
			swap(a[i], a[i + 1]);
			res ++ ;
		}
		

	cout << res << endl;
    return 0;
}

Measured memory_bytes: 640
<?php
$card = trim(fgets(STDIN));
$cards = explode(" ",$card);
$number = trim(fgets(STDIN));
for($i = 0; $i < $number; $i++){
    if($cards[0] >= $cards[1]){
        $cards[1] += $cards[1];
    }elseif ($cards[1] >= $cards[2]) {
        $cards[2] += $cards[2];
    }
}
if($cards[0] < $cards[1] && $cards[1] < $cards[2]){
    echo "Yes";
}else{
    echo "No";
}
?>

Measured memory_bytes: 16060
import sys
sys.setrecursionlimit(100000)

def ii(): return int(input())
def iis(): return input().split()
def imi(): return map(int,iis())
def iil(): return list(imi())

k = set()
n = input()
a = input().split()
for i in a:
    if i in k:
        print('NO')
        sys.exit()
    k.add(i)
print('YES')

Measured memory_bytes: 30408
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
static const int MAX_N = 300;

#define EPS (1e-10)

class Point{
	public:
		double x, y;

		Point(double x = 0, double y = 0): x(x), y(y) {}

		Point operator + (Point p){ return Point(x + p.x, y + p.y);}
		Point operator - (Point p){ return Point(x - p.x, y - p.y);}
		Point operator * (double a){ return Point(a * x, a * y);}
		Point operator / (double a){ return Point(x / a, y / a);}

		double abs(){ return sqrt(norm());}
		double norm(){ return x * x + y * y;}

		bool operator < (const Point &p) const{
			return x != p.x ? x < p.x : y < p.y;
		}

		bool operator == (const Point &p) const{
			return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
		}
};

class Circle{
	public:
		Point c;
		double r;
		Circle(Point c = Point(), double r = 0.0): c(c), r(r) {}
};

typedef Point Vector;

int N;
Point p[MAX_N];

double arg(Vector p){return atan2(p.y, p.x);}
Vector polar(double a, double r){return Point(cos(r) * a, sin(r) * a);}

double getDistance(Point a, Point b){
	return (a - b).abs();
}

pair<Point, Point> getCrossPoints(Circle c1, Circle c2){
	double d = (c1.c - c2.c).abs();
	double a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d));
	double t = arg(c2.c - c1.c);
	return make_pair(c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a));
}

bool comp(const Point &a, const Point &b){
	return a.x < b.x;
}

int main(){
	for(;;){
		scanf("%d", &N);
		if(N == 0) break;
		for(int i = 0; i < N; i++){
			scanf("%lf %lf", &p[i].x, &p[i].y);
		}
		sort(p, p + N, comp);
		int res = 1;
		for(int i = 0; i < N; i++){
			for(int j = i + 1; j < N; j++){
				if(p[j].x - p[i].x > 2.0) break;
				else if(getDistance(p[i], p[j]) > 2.0) continue;
				pair<Point, Point> pp = getCrossPoints((Circle){p[i], 1.0}, (Circle){p[j], 1.0});
				Point p1 = pp.first, p2 = pp.second;
				int cnt1 = 2, cnt2 = 2;
				for(int k = 0; k < N; k++){
					if(k == i || k == j) continue;
					if(p[k].x - p[j].x > 1.0) break;
					if(getDistance(p1, p[k]) < 1.0) cnt1++;
					if(getDistance(p2, p[k]) < 1.0) cnt2++;
				}
				res = max(res, max(cnt1, cnt2));
			}
		}
		printf("%d\n", res);
	}
	return 0;
}



Measured memory_bytes: 3136
import sys

input = sys.stdin.readline


def main():
    N, x = map(int, input().split())
    a = list(map(int, input().split()))

    a.sort()
    ans = 0
    for i in range(N):
        if a[i] <= x:
            x -= a[i]
            ans += 1
        else:
            break

    if ans == N and x > 0:
        ans -= 1

    print(ans)


if __name__ == "__main__":
    main()


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

int main()
{
	long int a,b,c;
	cin>>a;
	double f=(2*3.141592653589793238*a);
	//cout<<f<<endl;
	printf("%lf\n",f);
	
	
	return 0;
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
#define MAX 1000005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<ll,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define vll vector<ll>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
 
ll gcd(ll n1,ll n2){
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent)
{
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%MOD;
		base=(base*base)%MOD;
		exponent/=2;
	}
	return ans;
}
set <pair<ll,int> > s;
ll arr[MAX];
ll sum=0;
ll dp1[MAX],dp2[MAX];
int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.out", "w", stdout);
	int n;
	cin>>n;
	for(int i=1;i<=3*n;i++)
	{
		cin>>arr[i];
	}
	for(int i=1;i<=n;i++)
	{
		sum+=arr[i];
		s.insert(mp(arr[i],i));
	}
	dp1[n]=sum;
	for(int i=n+1;i<=2*n;i++)
	{
		if(s.begin()->FF<arr[i])
		{
			sum-=s.begin()->FF;
			sum+=arr[i];
			s.insert(mp(arr[i],i));
			s.erase(s.begin());
		}
		dp1[i]=sum;
		//cout<<i<<" "<<sum<<endl;
	}
	sum=0;
	s.clear();
	for(int i=3*n;i>2*n;i--)
	{
		sum+=arr[i];
		s.insert(mp(-arr[i],i));
	}
	//s.clear();
	dp2[2*n+1]=sum;
	//cout<<sum<<endl;
	for(int i=2*n;i>n;i--)
	{
		//cout<<-s.begin()->FF;
		if((-s.begin()->FF)>arr[i])
		{
			sum+=s.begin()->FF;
			sum+=arr[i];
			s.insert(mp(-arr[i],i));
			s.erase(s.begin());
		}
		dp2[i]=sum;
	}
	ll ans=-10000000000000001LL;
	for(int i=n;i<=2*n;i++)
	{
		ans=max(ans,dp1[i]-dp2[i+1]);
		//cout<<i<<" "<<dp2[i+1]<<endl;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 13440
#include<stdio.h>
int main(){
	char s[10];
  	int i, n=0, x=0;
  
	scanf("%s",s);
  
	for(i=0;i<10;i++){
	 if(s[i]=='\0') break;
 	 else{
 	  if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T'){
 	  n++;
 	  if(n>x) x=n;
 	  }
	  else n=0;
 	 } 
	}
           
  	printf("%d",x);
	return 0;
}

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

using namespace std;

#define int 		long long
#define endl		"\n"
#define mod			1000000007
#define inf			1e12
#define IOS			ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

vector<int> v(200000);

int bs(int len, int n) {
	int ans = 0;
	for (int i = 0; i < n; i++)
		ans += (v[i] - 1) / len;

	return ans;
}

int32_t main() {

	IOS;

	int n, k;
	cin >> n >> k;

	int ans = 0;

	for (int i = 0; i < n; i++) {
		cin >> v[i];
		ans = max(ans, v[i]);
	}

	int lo = 1, hi = 1e9, mid;

	while (lo <= hi) {
		mid = lo + (hi - lo) / 2;

		if (bs(mid, n) <= k) {
			ans = mid;
			hi = mid - 1;
		}
		else {
			lo = mid + 1;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4684
n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
t = a.min

n = 0
i = 0
while a[i]
  if a[i] == t
    i += 1
  else
    if a[i...i+k].include?(t)
      i += k
    else
      i += k - 1
    end
    n += 1
  end
end

# ('  ' + a * '  ' + '  ').split(" #{t} ").each do |l|
#   n += (l.split.size + k - 2) / (k - 1)
# end

p n


Measured memory_bytes: 10628
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = Integer.valueOf(scan.next());
        int[] ns = new int[n];
        for(int i=0;i<n;i++) {
        	ns[i] = Integer.valueOf(scan.next());
        }
        int min = ns[0];
        int max = ns[1]-ns[0];
        for(int i=1;i<n;i++) {
        	if(max < ns[i]-min) {
        		max = ns[i]-min;
        	}
        	if(ns[i] < min) {
        		min = ns[i];
        	}
        }
        System.out.println(max);
        scan.close();
    }
}


Measured memory_bytes: 72836
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, n) for (int i = 1; i <= (n); i++)
typedef long long ll;
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;
}
int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    a--;
    ll cn = b / c - a / c;
    ll dn = b / d - a / d;
    ll cd = lcm(c, d);
    ll cdn = b / cd - a / cd;
    cout << b - a - cn - dn + cdn << endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define int long long
#define M 998244353
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define Zero(dp) memset(dp,0,sizeof(dp))
#define pb emplace_back
using namespace std;
int32_t main(){
/*
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
*/
ios
int t=1;
//cin>>t;
while(t--)
{
	int n,k;cin>>n>>k;
	int h[n];
	for(int i=0;i<n;i++)cin>>h[i];
	int dp[n];
	dp[0]=0;
	dp[1]=abs(h[1]-h[0]);
	for(int i=2;i<n;i++)
	{
		dp[i]=1e18;
		for(int j=1;j<=k;j++)
		{
			if(i-j>=0)
			{
				dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
			}
		}
	}
	cout<<dp[n-1];
}
}

Measured memory_bytes: 1792
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

mod = 10**9+7

n = int(input())
S = ["" for i in range(n)]
for i in range(n):
    S[i] = str(input())

share_count = {}
for c in S[0]:
    if c in share_count.keys():
        share_count[c] += 1
    else:
        share_count[c] = 1

for i in range(1,n):
    word = S[i]
    count = {}
    for c in word:
        if c in count.keys():
            count[c] += 1
        else:
            count[c] = 1

    for key in share_count.keys():
        if key in count.keys():
            share_count[key] = min(share_count[key],count[key])
        else:
            share_count[key] = 0

keys =  list(share_count.keys())
# keys = list(keys)
keys.sort()

ans =""
for key in keys:
    for j in range(share_count[key]):
        ans += str(key)


print(ans)


Measured memory_bytes: 6352
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <istream>
#include <ostream>

#include <cstdlib>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i,n) for(ll i=0; i < (n); ++i)
#define rrep(i,n) for(ll i=((n)-1); i >= 0; --i)

#define OPLT(T) bool operator<(const T & lop_, const T & rop_)
#define OPEQ(T) bool operator==(const T & lop_, const T & rop_)

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

istream& operator>>(istream& istr, __float128& obj) { double d; istr >> d; obj = d; return istr; };
ostream& operator<<(ostream& ostr, __float128& obj) { ostr << static_cast<double>(obj); return ostr; };

int main() {
	int N, M, K;
	cin >> N >> M >> K;
	bool f = false;
	rep(i,N+1) {
		rep(j,M+1) {
			if(i*M+j*N-i*j*2 == K)
				f = true;
		}
	}

	if(f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;


class Program {

	const long mod = 1000000007;
	//public static int[] max;

	static void Main(string[] args) {

		char[] cs = new char[] { ' ', ',' };
		int val = int.Parse(Console.ReadLine());
		//int[] vals = parseAry(Console.ReadLine().Split(cs));
		//string str = Console.ReadLine();
		//string[] strs = Console.ReadLine().Split(cs);

		//int[] vals = parseAry(Console.ReadLine().Split(cs));
		//int n = vals[0];
		//string res="";

		//int y = vals[0];
		//int x = vals[1];
		int[] sc = new int[val];
		for (int k = 0; k < val; k++) {
			sc[k] = int.Parse(Console.ReadLine());
		}
		Array.Sort(sc);
		int sum = sc.Sum();
		int flg = 0;
		if (sum % 10 == 0) {
			for (int i = 0; i < val; i++) {
				if (sc[i] % 10 != 0) { sum -= sc[i]; flg = 1; break; }
			}
			if (flg == 0) { sum = 0; }

		}

		Console.WriteLine(sum);


		return;
	}



	//　String[]  ----->  int[]
	static int[] parseAry(string[] str) {
		int[] nums = new int[str.Length];
		for (int i = 0; i < str.Length; i++) { nums[i] = int.Parse(str[i]); }
		return nums;
	}
	//　String[]  ----->  long[]
	static long[] parseAryl(string[] str) {
		long[] nums = new long[str.Length];
		for (int i = 0; i < str.Length; i++) { nums[i] = int.Parse(str[i]); }
		return nums;
	}



	//文字列を1文字ずつString[]に入れる
	static string[] strAry(String str) {
		string[] re = new string[str.Length];
		for (int i = 0; i < str.Length; i++) { re[i] = str[i].ToString(); }
		return re;
	}

}

Measured memory_bytes: 13268
#include <cstdio>
#include <string>
#include <iostream>

using namespace std;

string str;
int checked[600][600];

string check(int l,int r){
	if(l-1==r)return "Cat";
	if(str[l]!='m' || str[r]!='w')return "Rabbit";
	if(checked[l][r]!=0){
		return checked[l][r]==1?"Cat":"Rabbit";
	}
	int flag=-1;
	for(int i=l+1;i<=r-1;i++){
		if(str[i]=='e'){
			if(check(l+1,i-1)=="Cat" && check(i+1,r-1)=="Cat")flag=1;
		}
	}
	return (checked[l][r]=flag)==1? "Cat":"Rabbit";
}

int main(void){
	cin >> str;
	cout << check(0,str.size()-1) << endl;
	return 0;
}

Measured memory_bytes: 1880
def decoder(mes)
  list = [[".", ",", "!", "?", " "],
          ["a", "b", "c"],
          ["d", "e", "f"],
          ["g", "h", "i"],
          ["j", "k", "l"],
          ["m", "n", "o"],
          ["p", "q", "r", "s"],
          ["t", "u", "v"],
          ["w", "x", "y", "z"]]

  mes.split("0").map { |n|
    next if n.empty?
    row = n[0].to_i - 1
    col = (n.length - 1) % list[row].length

    list[row][col]
  }.join
end

gets.to_i.times do
  puts decoder(gets.chomp)
end

Measured memory_bytes: 8756
#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#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 main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    int ans = 0;
    for (int i = 0; i < N; i++){
        string T = S.substr(i, N - i);
        vector<int> A(N - i + 1, 0);
        int j = -1;
        A[0] = -1;
        for (int k = 0; k < N - i; k++){
            while(j >= 0 && T[k] != T[j]) j = A[j];
            j++;
            A[k + 1] = j;
        }
        for (int k = 1; k < N - i + 1; k++){
            if (k >= A[k] * 2){
                ans = max(ans, A[k]);
            }
            else{
                ans = max(ans, k / 2);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3688
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
const int MOD = 1000000007;

vector<int> to[200000];
int value[200000], v[200000];
int visited[200000] = {};

int main(){
  int N,Q;
  int a, b, p, x;
  cin >> N >> Q;
  for(int i=0;i<N-1;i++){
    cin >> a >> b;
    to[a-1].push_back(b-1);
    to[b-1].push_back(a-1);
  }
  for(int i=0;i<Q;i++){
    cin >> p >> x;
    value[p-1] += x;
  }

  queue<int> que;
  que.push(0);
  v[0] = value[0];
  visited[0] = 1;
  while(!que.empty()){
    int curr = que.front();
    que.pop();
    for(int i=0;i<to[curr].size();i++){
      if(visited[to[curr][i]] == 0){
        v[to[curr][i]] = v[curr] + value[to[curr][i]];
        que.push(to[curr][i]);
        visited[to[curr][i]] = 1;
      }
    }
  }

  for(int i=0;i<N;i++){
    if(i != 0) cout << " ";
    cout << v[i];
  }
}


Measured memory_bytes: 16628
import collections
c = {0: 0, 1: 0, 2: 1}
n = int(input())
sum = 0
for i in range(3, n + 1):
    c[i] = c[i - 1] * i // (i - 2)
cc = collections.defaultdict(int)
a = list(map(int, input().split()))
for i in a:
    cc[i] += 1
for k, v in cc.items():
    sum += c[v]
# print (c)
# print (cc)
# print (sum)
for i in range(n):
    v = cc[a[i]]
    # print (v)
    # print(c[v], c[v - 1])
    print (sum - c[v] + c[v - 1])

Measured memory_bytes: 52452
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    long long n,A[200000],B[200000],C[200000];
    long long ans=0;
    cin>>n;
    for(int i=0;i<n;i++) cin>>A[i]>>B[i];
    for(int i=0;i<n;i++) C[i]=A[i]+B[i];
    vector<pair<long long, long long>> D(n);
    for (int i = 0; i < n; i++) D[i] = make_pair(C[i], i);
    sort(D.begin(), D.end());
    for(int i=n-1;i>=0;i--){
        if((i-n+1)%2==0) ans+=A[D[i].second];
        else ans-=B[D[i].second];
    }
    cout<<ans;
}

Measured memory_bytes: 6400
n,m = map(int, input().split())
a = []
b = []
c = []
d = []

for i in range(n):
    tmp_a, tmp_b = map(int, input().split())
    a.append(tmp_a)
    b.append(tmp_b)

for i in range(m):
    tmp_c, tmp_d = map(int, input().split())
    c.append(tmp_c)
    d.append(tmp_d)

def query(x):
    res_i = 0
    res = 1e+18 + 7
    for i in range(m):
        dist = abs(a[x] - c[i]) + abs(b[x] - d[i])
        if res > dist:
            res_i = i
            res = dist
    return res_i+1

for i in range(n):
    print(query(i))


Measured memory_bytes: 3064
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
int dist[20][20];

// ベクトル
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int H, W;
char maze[20][20];

int search(int sx, int sy, int gx, int gy) {
  queue<P> que;
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++) dist[i][j] = -1;

  que.push(P(sx, sy));
  dist[sx][sy] = 0;

  while (!que.empty()) {
    // キューの先頭を取り出す
    P p = que.front();
    que.pop();

    // ゴールなら終了
    if (p.first == gx && p.second == gy) return dist[gx][gy];

    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if (0 <= nx && nx < H && 0 <= ny && ny < W && maze[nx][ny] != '#' &&
          dist[nx][ny] == -1) {
        que.push(P(nx, ny));
        dist[nx][ny] = dist[p.first][p.second] + 1;
      }
    }
  }

  return 0;
}

int main() {
  cin >> H >> W;
  REP(i, H) {
    REP(j, W) { cin >> maze[i][j]; }
  }

  int ans = 0;
  REP(sx, H) {
    REP(sy, W) {
      REP(gx, H) {
        REP(gy, W) {
          if (maze[sx][sy] != '#' && maze[gx][gy] != '#')
            ans = max(ans, search(sx, sy, gx, gy));
        }
      }
    }
  }

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


Measured memory_bytes: 256
#from functools import lru_cache
import sys
from itertools import product,combinations
from functools import reduce,lru_cache
import heapq

def vfunc(f): return lambda *lst, **kwargs: list(map(lambda *x:f(*x,**kwargs),*lst))

def list_t(l): return vfunc(lambda *args:args)(*l)

def rvfunc(f): return lambda *lst, **kwargs: list(map(lambda *x:rvfunc(f)(*x,**kwargs) if all(vfunc(lambda y:isinstance(y,list))(x)) else f(*x,**kwargs),*lst))

def reader():return vfunc(lambda l:l.split())(sys.stdin.readlines())

d,t,s = rvfunc(int)(reader()[0])
print('Yes' if d/t<=s else 'No')

Measured memory_bytes: 67548
import sys

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip() # input string
ni = lambda: int(readline().rstrip()) # input int
nm = lambda: map(int, readline().split()) # input multiple int 
nl = lambda: list(map(int, readline().split())) # input multiple int to list

n = ni() % 1000
if n == 0:
    print(0)
else:
    print(1000-n)

Measured memory_bytes: 9180
n=int(input())
a=list(map(int,input().split()))
d={}
ans=0
for key in a:
    try:
        d[key]+=1
    except:
        d[key]=1
    ans+=key

q=int(input())
for i in range(q):
    b,c=map(int,input().split())
    try:
        x=d[b]
        try:
            y=d[c]
            ans+=(c-b)*x
            d[b]=0
            d[c]+=x
            print(ans)
        except:
            d[c]=x
            ans+=(c-b)*x
            d[b]=0
            print(ans)
    except:
        print(ans)


Measured memory_bytes: 85036
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    int a, b, x;
    cin >> a >> b >> x;
    if(a > x)
        cout << "NO" << endl;
    else if(a + b < x)
        cout << "NO" << endl;
    else
        cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 256
from itertools import groupby
N, K, Q = list(map(int, input().split()))
A = tuple(int(input()) for _ in range(Q))
d = {k:len(tuple(g)) for k, g in groupby(sorted(A))}
print("\n".join("Yes" if (d.get(i, 0) + K - Q) > 0 else "No" for i in range(1, N+1)))

Measured memory_bytes: 13132
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn run() {
    input! {
        h: usize,
        w: usize,
        n: usize,
        p: [(usize1, usize1); n],
    }
    let mut g = vec![vec![h]; w];
    for (x, y) in p {
        g[y].push(x);
    }
    for i in 0..w {
        g[i].sort();
        g[i].reverse();
    }
    let mut ans = h + 1;
    let mut y = 0;
    for i in 0..h {
        while *g[y].last().unwrap() < i {
            g[y].pop();
        }
        ans = std::cmp::min(ans, *g[y].last().unwrap());
        if y + 1 < w {
            while *g[y + 1].last().unwrap() < i + 1 {
                g[y + 1].pop();
            }
            if *g[y + 1].last().unwrap() > i + 1 {
                y += 1;
            }
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 22772
#include <stdio.h>
#include <string.h>

int main(void)
{
    int a;
    int b = 0;
    int c = 0;
    scanf("%d",&a);            /* 文字列入力 */

    int e = a;

    while(a){
    b = a % 10;
    c = c + b;
    a = a / 10;
  }

int d = e % c;
if(d == 0){
    printf("Yes\n");
}else{
    printf("No\n");
}
   return 0;
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline
from heapq import heappush, heappop
def min_cost_flow_dijkstra(E, s, t, f):
    INF = 1 << 100
    NN = N
    LN = NN.bit_length()
    G = [[] for _ in range(NN)]
    for a, b, cap, c in E:
        G[a].append([b, cap, c, len(G[b])])
        G[b].append([a, 0, -c, len(G[a])-1])
    prevv = [-1] * NN
    preve = [-1] * NN
    res = 0
    while f > 0:
        h = [0] * NN
        dist = [INF] * NN
        dist[s] = 0
        Q = []
        heappush(Q, s)
        while len(Q):
            x = heappop(Q)
            d, v = (x>>LN), x % (1<<LN)
            if dist[v] < d: continue
            for i, (w, _cap, c, r) in enumerate(G[v]):
                if _cap > 0 and dist[w] > dist[v] + c + h[v] - h[w]:
                    dist[w] = dist[v] + c + h[v] - h[w]
                    prevv[w] = v
                    preve[w] = i
                    heappush(Q, (dist[w] << LN) + w)
        if dist[t] == INF:
            return -1
        for v in range(N):
            h[v] += dist[v]
        
        d = f
        v = t
        while v != s:
            d = min(d, G[prevv[v]][preve[v]][1])
            v = prevv[v]
        f -= d
        res += d * dist[t]
        v = t
        while v != s:
            G[prevv[v]][preve[v]][1] -= d
            G[v][G[prevv[v]][preve[v]][3]][1] += d
            v = prevv[v]
    return res

N, M, F = map(int, input().split())
E = []
for i in range(M):
    u, v, c, d = map(int, input().split())
    E.append((u, v, c, d))

print(min_cost_flow_dijkstra(E, 0, N-1, F))



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

int main()
{
    int N;
    cin>>N;
    int arr[N];
    int temp;
    for(int i=0; i<N; i++)
    {
        cin>>arr[i];
    }
     int length = sizeof(arr)/sizeof(arr[0]);  
     sort(arr, arr+length);
    int mid= length/2;
    int result;
    if(arr[mid-1]==arr[mid])
    {
        result=0;
    }
    else
    {
        result=arr[mid]-arr[mid-1];
    }
    cout<<result;
    return 0;
    
    
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define int long long int
#define double long double
#define inf (int)(1e15)
#define all(x) (x).begin(), (x).end()
#define pair pair<int, int>
typedef vector<int> vi;   // Vector of long long
typedef vector<vi> vvi;   // Vector of vi
typedef vector<pair> vii; // Vector of pairs
typedef vector<vii> vvii; // Vector of Vector of pairs
typedef vector<bool> vb;  // Vector of bool
#define pq priority_queue // Max heap (To convert to min heap, use negative sign before every value)
#define ff first          // For pairs
#define ss second
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, -1, 0, 1};
const int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}, dy8[] = {1, -1, 1, 0, -1, 1, -0, -1};
#define testcases(t) \
    int(t);          \
    cin >> (t);      \
    while ((t)--)
signed main()
{
    int n, cnt = 0, c1 = 0, c2 = 0, c3 = 0;
    cin >> n;
    string s[n];
    for (int i = 0; i < n; i++)
    {
        cin >> s[i];
        if (s[i][0] == 'B' && s[i][s[i].length() - 1] == 'A')
            c1++;
        else if (s[i][0] == 'B')
            c2++;
        else if (s[i][s[i].length() - 1] == 'A')
            c3++;
        for (int j = 0; j < s[i].length() - 1; j++)
        {
            if (s[i][j] == 'A' && s[i][j + 1] == 'B')
                cnt++;
        }
    }
    if (c1 == 0)
    {
        cnt += min(c2, c3);
    }
    else
    {
        if (c2 + c3)
            cnt += (c1 + min(c2, c3));
        else
            cnt += (c1 - 1);
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <random>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
int main() {
	int n;
	string s;
	cin >> s;
	n = s.length();
	cout << s.substr(0, n - 8) << endl;
    
    return 0;
}

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

int main(){
   int n;
   cin>>n;
   int *A=new int[n+1];
   for(int i=1;i<n+1;i++){
      cin>>A[i];
   }

   int x = A[n];
   int i = 0;
   int tmp=0;
   for(int j=1;j<=n-1;j++){
      if(A[j]<=x){
         i=i+1;
		 tmp=A[i];
		 A[i]=A[j];
		 A[j]=tmp;
      }
   }
   tmp=A[i+1];
   A[i+1]=A[n];
   A[n]=tmp;
   i=i+1;

   for(int j=1;j<n+1;j++){
      if(j==i){
         cout<<'['<<A[j]<<']';
      }
      else{
         cout<<A[j];
      }	
	  if(j<n){
		  cout<<' ';
	  }
	  else{
		  cout<<endl;
	  }
   }
   delete[] A;
   return 0;
}

Measured memory_bytes: 3120
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace::std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/numeric/interval.hpp>
#include <boost/numeric/interval/io.hpp>
#include <boost/intrusive/rbtree.hpp>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/linestring.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
using namespace __gnu_pbds;
using namespace::std;
namespace mp = boost::multiprecision;
typedef mp::number<mp::cpp_dec_float<0>> cfloat;
typedef mp::cpp_int cint;
typedef long long lint;
typedef long long ll;
typedef long double ldouble;
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<vector<vector<lint>>> mat3;
typedef vector<double> dvec;
typedef vector<vector<double>> dmat;
typedef vector<vector<vector<double>>> dmat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
typedef vector<vector<vector<string>>> smat3;
typedef vector<pair<lint,lint>> pvec;
typedef vector<vector<pair<lint,lint>>> pmat;
typedef vector<vector<vector<pair<lint,lint>>>> pmat3;
#define rep(i, n) for(lint i = 0; i < (lint)(n); i++)
#define irep(i) for(lint i = 0;; i++)
#define irep1(i) for(lint i = 1;; i++)
#define irep2(i) for(lint i = 2;; i++)
#define rrep(i, n) for(lint i = (lint)(n-1); i >-1; i--)
#define rrepi(i,a,b) for(lint i = (lint)(b-1); i >a-1; i--)
#define repi(i,a,b) for(lint i=lint(a);i<lint(b);i++)
#define rep2(i,a,b,c) for(lint i=lint(a);i>lint(b);i+=c)
#define all(x) (x).begin(),(x).end()
#define PI 3.141592653589793
#define dist(x1,y1,x2,y2) (pow(pow(x2-x1,2)+pow(y2-y1,2),0.5))
#define output(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"");if(i>INF/2)cout<<"INF";else cout<<i;f=1;}cout<<"\n";}while(0)
#define output2(v) for(auto j:v)output(j);
#define input(a,n) lint n;cin>>n;vector<lint>a(n);rep(i,n)cin>>a[i];
#define SUM(v) accumulate(all(v),0LL)
#define INF (1LL<<60)
#define IINF (1<<30)
#define EPS (1e-10)
#define LINF 9223372036854775807
#define MOD 1000000007
#define endl "\n"
template<typename T=lint>T in(){return *istream_iterator<T>(cin);}
inline lint gcd(lint a,lint b){return b?gcd(b,a%b):a;}
inline lint lcm(lint a,lint b){return a*b/gcd(a,b);}
inline bool chmin(auto& s,const auto& t){bool res=s>t;s=min(s,t);return res;}
inline bool chmax(auto& s,const auto& t){bool res=s<t;s=max(s,t);return res;}
vector<lint> dx={-1,1,0,0,1,1,-1,-1};
vector<lint> dy={0,0,-1,1,1,-1,1,-1};

int main(){
    lint n;
    cin>>n;
    cout<<(lint)pow(n,3);
}

Measured memory_bytes: 384
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int m, pa[100010];
vector<int> e[100010];
long long dp[100010], dp2[100010];
void dfs(int v, int p = -1) {
	dp[v] = 1;
	for (int i = 0; i < e[v].size(); i++) {
		int w = e[v][i];
		if (w == p) continue;
		pa[w] = v;
		dfs(w, v);
		dp[v] = dp[v] * (1 + dp[w]) % m;
	}
	dp2[v] = p == -1 ? 0 : 1;
}
void dfs2(int v, int p = -1) {
	vector<int> t = e[v];
	for (int k = 0; k < 2; k++) {
		long long x = 1;
		for (int i = 0; i < t.size(); i++) {
			int w = t[i];
			if (w == p) {
				x = x * (1 + dp2[v]) % m;
			} else {
				dp2[w] = dp2[w] * x % m;
				x = x * (1 + dp[w]) % m;
			}
		}
		reverse(t.begin(), t.end());
	}
	for (int i = 0; i < t.size(); i++) {
		if (t[i] != p) dfs2(t[i], v);
	}
}
int main() {
	int n;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n - 1; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		--u; --v;
		e[u].push_back(v);
		e[v].push_back(u);
	}
	dfs(0);
	dfs2(0);
	for (int i = 0; i < n; i++) {
		long long ans = dp[i] * (1 + dp2[i]) % m;
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 16512
// In the name of GOD
#include<bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

#define     IOS         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define 	setprecn(x) cout<<fixed<<setprecision(x);
#define 	ll          long long int
#define 	pb          push_back
#define 	pll         pair<ll,ll>
#define 	vll         vector<ll>
#define 	ff          first
#define 	ss          second
#define 	all(a)      (a).begin(),(a).end()
#define 	sz(x)       (ll)x.size()
#define 	mod         1000000007
#define 	inf         10000000000000007
#define 	rep(i,n)    for(ll i=0;i<n;i++)
#define 	repe(i,a,b) for(ll i=a;i<b;i++)
#define 	lbnd        lower_bound
#define 	ubnd        upper_bound
#define 	bs          binary_search

ll power(ll a,ll b,ll m=mod)
{
	if(b==0)
		return 1;
	if(b==1)
		return a;
	ll c=power(a,b/2,m);
	if(b%2==0)
		return((c%m)*(c%m))%m;
	return ((((c%m)*(c%m))%m)*(a%m))%m;
}

/********************************************************/
//	d.erase(unique(all(d)), d.end());



int main()
{
	IOS;
	ll n,k,m,i,j,c=0,cs=0,t;
	t=1;

	// cin>>t;
	string s;
	while(t--)
	{
		// reverse(a.begin(),a.end());
		cin>>n;
		// n=s.length();
		ll a[n+1],b[n];
		rep(i,n+1)
		{ 
			cin>>a[i];
			// debug3(i,i,a[i]);
		}
		rep(i,n) cin>>b[i];
		rep(i,n)
		{
			if(b[i]>a[i])
			{
				c+=a[i];
				m=min(a[i+1],b[i]-a[i]);
				a[i]=0;
				c+=m;
				a[i+1]-=m;
			}
			else
			{
				c+=b[i];
			}
			// debug3(i,m,c);
		}
		cout<<c;
		if(t!=0)
	   		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    string t;
    cin >> t;
    string s[4] = {"Sunny", "Cloudy","Rainy","Sunny"};
    rep(i,3)if(s[i] == t)cout << s[i+1] << endl;
}

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

int main(){
	long long a, b, c, d;
	long long cd, cnum, dnum, cdnum, num, ans;
	cin >> a >> b >> c >> d;
	cnum = c;
	dnum = d;
	cd = c * d;
	if(cnum < dnum){
		num = cnum;
		cnum = dnum;
		dnum = num;
	}
	num = cnum % dnum;
	while(num != 0){
		cnum = dnum;
		dnum = num;
		num = cnum % dnum;
	}
	cd /= dnum;
	/*
	if(c < d){
		for(int i = c; i >= 1; i--){
			if(i % c == 0 && i % d == 0){
				cd /= i;
				break;
			}
		}
	}
	else{
		for(int i = d; i >= 1; i--){
			if(i % c == 0 && i % d == 0){
				cd /= i;
				break;
			}
		}
	}
	*/
	if(a % c == 0) cnum = a;
	else cnum = a + c - a % c;
	if(a % d == 0) dnum = a;
	else dnum = a + d - a % d;
	if(a % cd == 0) cdnum = a;
	else cdnum = a + cd - a % cd;
	
	ans = b - a + 1;
	num = (b - a + 1) / c;
	if(cnum + c * num <= b) ans -= num + 1;
	else ans -= num;
	num = (b - a + 1) / d;
	if(dnum + d * num <= b) ans -= num + 1;
	else ans -= num;
	num = (b - a + 1) / cd;
	if(cdnum + cd * num <= b) ans += num + 1;
	else ans += num;
	
	//cout << cnum << endl << dnum << endl << cdnum << endl;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
/*package whatever //do not write package name here */

import java.io.*;
import java.util.*;
public class Main {
	public static void main (String[] args) {
		Scanner input = new Scanner(System.in);
		double n = input.nextDouble();
		double ans = (n*n*n)/27.0;
		System.out.printf("%.12f",ans);
		
	}
}

Measured memory_bytes: 22868
#define rep(i,n) for(ll i=0;i<(n);++i)

#include<iostream>
#include<fstream>
#include<iomanip>

#include<vector>
#include<array>
#include<string>
#include<bitset>
#include<queue>
#include<list>

#include<utility>

#include<algorithm>
#include<cmath>
using ll = long long;
using namespace std;

ll n,m;

inline bool isOK(ll mid,vector<ll>& a,vector<ll>& b,ll &cut){
    cut=0;
    rep(i,n){
        ll val=a[i];
        while(val>mid){val/=2;cut++;}
        if(cut>m){return(false);}
        b[i]=val;
    }
    return(true);
}

void src(){
    cin>>n>>m;
    vector<ll> a(n,0),b(n,0);
    rep(i,n) cin>>a[i];
    ll ok=1e9+1;
    ll ng=-1;
    ll cut;
    while(ok-ng>1){
        ll mid=(ok+ng)/2;
        (isOK(mid,a,b,cut) ? ok:ng) = mid;
    }
    isOK(ok,a,b,cut);
    ll morecut=m-cut;
    rep(i,morecut)
        *max_element(b.begin(),b.end())/=2;
    ll sum=0;
    rep(i,n){sum+=(ll)b[i];}
    cout<<sum<<endl;
    return;
}


int main(int argc,char* argv[]){
    //ifstream in( argv[1] );
    //cin.rdbuf(in.rdbuf());
    src();    
    return 0;
}

Measured memory_bytes: 1792