akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <bitset>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath> // 変数名にy1が使えなくなるかも…。
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>

typedef __int128_t int128_t;
std::istream &operator>>(std::istream& input, int128_t& value) { // int128_tの入力。入力が64bitに収まる前提。
    long long tmp; input >> tmp; value = tmp;
    return input;
}
std::ostream &operator<<(std::ostream& output, const int128_t value) { // int128_tの出力。出力が64bitに収まる前提。
    output << (long long)value;
    return output;
}


const int MAX_N = 200050;
int N;
int128_t A[MAX_N], B[MAX_N];

int main(int argc, char **argv) {
    std::cin >> N;
    for (int i = 1; i <= N; i++) {
        std::cin >> A[i] >> B[i];
    }

    std::vector<int> vec;

    for (int i = 1; i <= N; i++) {
        vec.push_back(i);
    }
    std::sort(vec.begin(), vec.end(), [&](const int i, const int j) {
        return B[i] < B[j];
    });

    int128_t t = 0;
    for (int i : vec) {
        t += A[i];
        if (t > B[i]) {
            std::cout << "No" << std::endl;
            return 0;
        }
    }

    std::cout << "Yes" << std::endl;

    

    //std::cout << ret << std::endl;
    
    return 0;
}

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

using namespace std;

const int MAX_N = 100000, INDEX = 1;

int n;

string s;

bool isAns(bool a1, bool an) {
    bool a[MAX_N + INDEX];

    a[1] = a1;
    a[n] = an;

    a[2] = (s[0] == 'o') != (a[1] != a[n]);

    for (int i = 3; i < n; i++) {
        a[i] = (s[i - 2] == 'o') != (a[i - 1] != a[i - 2]);
    }

//    for (int i = 1; i <= n; i++) {
//        if (a[i]) {
//            cout << 'S';
//        } else {
//            cout << 'W';
//        }
//    }
//
//    cout << endl;

    for (int i = 1; i <= n; i++) {
        if (((s[i - 1] == 'o') == a[i]) != (a[i % n + 1] == a[(i + n - 2) % n + 1])) {
//            cout << i << endl;
//            cout << (a[i % n + 1] == a[(i + n - 2) % n + 1]) << endl;

            return false;
        }
    }

    return true;
}

void writeAns(bool a1, bool an) {
    bool a[MAX_N + INDEX];

    a[1] = a1;
    a[n] = an;

    a[2] = (s[0] == 'o') != (a[1] != a[n]);

    for (int i = 3; i < n; i++) {
        a[i] = (s[i - 2] == 'o') != (a[i - 1] != a[i - 2]);
    }

    for (int i = 1; i <= n; i++) {
        if (a[i]) {
            cout << 'S';
        } else {
            cout << 'W';
        }
    }

    cout << endl;
}

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

    cin >> n;

    cin >> s;

    if (isAns(true, true)) {
        writeAns(true, true);

        return 0;
    }

    if (isAns(true, false)) {
        writeAns(true, false);

        return 0;
    }

    if (isAns(false, true)) {
        writeAns(false, true);

        return 0;
    }

    if (isAns(false, false)) {
        writeAns(false, false);

        return 0;
    }

    cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 720
#import <stdio.h>
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
int main() {
    @autoreleasepool {
        int W,H,N;
        scanf("%d %d %d", &W,&H,&N);
        int minX = 0;
        int minY = 0;
        int maxX = W;
        int maxY = H;
        for (int i=0; i<N; i++){
            int x,y,a;
            scanf("%d %d %d", &x,&y,&a);
            switch (a) {
                case 1:
                    minX = MAX(minX, x);
                    break;
                case 2:
                    maxX = MIN(maxX, x);
                    break;
                case 3:
                    minY = MAX(minY, y);
                    break;
                case 4:
                    maxY = MIN(maxY, y);
                    break;
                default:
                    break;
            }
        }
        W = MAX(maxX - minX,0);
        H = MAX(maxY - minY,0);
        printf("%d", W*H);
    }
}


Measured memory_bytes: 8988
l=list(input())
def kaibun(c):
  d=c[::-1]
  if c == d:
    return 0
  else:
    return 1
a=kaibun(l)
m=l[:int((len(l)-1)/2)]
n=l[int((len(l)+1)/2):]

b=kaibun(m)
c=kaibun(n)

if a+b+c==0:
  print('Yes')
else:
  print('No')
 

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 1e5 + 4;
vector<int>G[MAXN];
int n,m,h[MAXN];
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)scanf("%d",&h[i]);
    for(int i=1;i<=m;i++){
        int u,v;scanf("%d%d",&u,&v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        bool flag = 0;
        for(auto x:G[i]){
            if(h[x] >= h[i]) {
                flag = 1;
            }
        }
        if(!flag) ++ans;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 9340
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect
from random import *

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

N, x = reads()
A = reads()

INF = 1 << 60
smin = [[INF] * N for _ in range(N)]
for i in range(N):
  smin[i][0] = A[i]
  for j in range(1, N):
    smin[i][j] = min(smin[i][j-1], A[(i-j)%N])

ans = INF
for j in range(N):
  h = sum(smin[i][j] for i in range(N)) + x * j
  ans = min(ans, h)
print(ans)


Measured memory_bytes: 75356
/* ex3_2
  bonbonc */

#include<stdio.h>

int main(void){

	int number;

	
	scanf("%d",&number);
	number%=10;
	switch (number){
		case 2:
		case 4:
		case 5:
		case 7:
		case 9:
			printf("hon\n");
			break;
		case 0:
		case 1:
		case 6:
		case 8:
			printf("pon\n");
			break;
		case 3:
			printf("bon\n");
			break;
	}
	
	return 0;
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

int n;
int u, v;
const int N = 100005;
vector<vector<int> > G(N);
vector<int> d(N, inf);

void dfs(int v, int p) {
  for (int nv : G[v]) {
    if (nv == p) continue;
    if (chmin(d[nv], d[v] + 1)) dfs(nv, v);
  }
}

void solve() {
  cin >> n;
  cin >> u >> v;
  u--; v--;
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].eb(b);
    G[b].eb(a);
  }
  // v から一番遠いとこへ
  // ただし, u の方が近い
  d[u] = 0;
  dfs(u, -1);
  vector<int> d2 = d;
  // rep(i, n) cout << d2[i] << " "; cout << endl;

  d = vector<int>(N, inf);
  d[v] = 0;
  dfs(v, -1);
  // rep(i, n) cout << d[i] << " "; cout << endl;

  int ma = 0;
  rep(i, n) {
    if (d2[i] <= d[i]) chmax(ma, d[i]);
  }

  cout << max(0, ma - 1) << endl;
}


Measured memory_bytes: 10360
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<set>
#include<map>
#include<time.h>
#include<list>
#include<iomanip>
#include<cstring>
#define ll unsigned long long
using namespace std;
int main() 
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll int n,x, sum=0,i, flag=0;
  cin>>n;
  multiset<ll int,greater<>>a;
  for(i=0;i<n;i++) 
  {
  	cin>>x;
  	a.insert(x);
  } 
  if(n<=3){
   auto it=a.begin(), it2=it;
  advance(it2,a.size()-1);
  for(;it!=it2;it++) 
  sum+=(*it);
  cout<<sum<<endl;} 
  else
  {
  	if(n%2==1){flag=1;n=n+1;} 
  	n=n/2;
  	auto it=a.begin();
  	for(i=1;i<=n;it++,i++) 
  	{
  		if(it==a.begin()) 
  		sum+=(*it);
  		else if(i==n && flag==1)
  		sum+=(*it);
  		else
  		sum+=(2*(*it));
  	} 
  	cout<<sum<<endl;
  } 
  return 0;
} 


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


int main(){
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    ll t,i,q,j,x,y,k,temp,temp2,z,l,tt,n,m,sum=0;
    cin >> n;
    if (n>=30) cout << "Yes\n";
    else cout << "No\n";
}

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

int main() {
    int n;
    double cnt = 0.0;
    double ans = 0.0;
    cin >> n;
    vector<double> x(n), y(n);
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
        v[i] = i + 1;
    }
    do {
        int j0 = v[0] - 1;
        cnt++;
        for (int i = 1; i < n; i++) {
            int j1 = v[i] - 1;
            ans += sqrt((x[j0] - x[j1]) * (x[j0] - x[j1]) + (y[j0] - y[j1]) * (y[j0] - y[j1]));
        }
    } while (next_permutation(v.begin(), v.end()));
    cout << setprecision(8) << ans / cnt << endl;
    return 0;
}

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

class D
{
	static void Main()
	{
		Func<int[]> read = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
		var h = read();
		var a = read().GroupBy(x => x).ToDictionary(g => g.Key, g => g.Count());
		var pq = new PQ<int>(a.Keys);

		var os = new int[h[1]].Select(_ => read()).ToArray();
		foreach (var o in os)
		{
			while (o[0] > 0 && o[1] > pq.First)
			{
				var c = o[1];
				if (o[0] >= a[pq.First])
				{
					var c0 = pq.Pop();
					var d = a[c0];
					if (a.ContainsKey(c)) a[c] += d;
					else
					{
						a[c] = d;
						pq.Push(c);
					}
					a.Remove(c0);
					o[0] -= d;
				}
				else
				{
					var d = o[0];
					if (a.ContainsKey(c)) a[c] += d;
					else
					{
						a[c] = d;
						pq.Push(c);
					}
					a[pq.First] -= d;
					o[0] = 0;
				}
			}
		}
		Console.WriteLine(a.Sum(p => (long)p.Key * p.Value));
	}
}

class PQ<T> : List<T>
{
	Comparison<T> _c;
	public T First => this[0];

	public PQ(IEnumerable<T> vs = null, Comparison<T> c = null)
	{
		_c = c ?? Comparer<T>.Default.Compare;
		if (vs != null) foreach (var v in vs) Push(v);
	}

	void Swap(int i, int j) { var o = this[i]; this[i] = this[j]; this[j] = o; }
	void UpHeap(int i) { for (int j; i > 0 && _c(this[(j = (i - 1) / 2)], this[i]) > 0; Swap(i, j), i = j) ; }
	void DownHeap(int i)
	{
		for (int j; (j = 2 * i + 1) < Count; i = j)
		{
			if (j + 1 < Count && _c(this[j], this[j + 1]) > 0) j++;
			if (_c(this[i], this[j]) > 0) Swap(i, j); else break;
		}
	}

	public void Push(T v) { Add(v); UpHeap(Count - 1); }
	public T Pop()
	{
		var r = this[0];
		this[0] = this[Count - 1];
		RemoveAt(Count - 1);
		DownHeap(0);
		return r;
	}
}


Measured memory_bytes: 42788
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int ans = 0;

        switch (s) {
            case "RRR":
                ans = 3;
                break;
            case "RRS": 
            case "SRR": 
                ans = 2;
                break;
            case "RSR": 
            case "SSR":
            case "SRS":
            case "RSS":
                ans = 1;
                break;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 35636
#include<iostream>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<stack>
#include<unordered_map>
#include<bitset>
#include<limits>
#include<complex>
#include<array>
#include<numeric>
#include<functional>

using namespace std;
#define ll long long
#define ull unsigned long long
#define rrep(i,m,n) for(ll (i)=(ll)(m);(i)>=(ll)(n);(i)--)
#define rep(i,m,n) for(ll (i)=(ll)(m);i<(ll)(n);i++)
#define REP(i,n) rep(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
constexpr long double m_pi = 3.1415926535897932L;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 61;
constexpr long double EPS = 1e-10;
template<typename T> using vector2 = vector<vector<T>>;
template<typename T> using vector3 = vector<vector2<T>>;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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

struct Edge {//グラフ
	int to, rev; ll cap;
	Edge(int _to, ll _cap, int _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph& G, int from, int to, ll cap, bool revFlag, ll revCap) {//最大フロー求める Ford-fulkerson
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));//最小カットの場合逆辺は0にする
}

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

		ll n;
	cin >> n;
	Array a(n);
	REP(i, n)cin >> a[i];
	Graph g(n);
	REP(i, n - 1) {
		ll a, b; cin >> a >> b;
		a--; b--;
		add_edge(g, a, b, 1, true, 1);
	}

	auto solve = [&](auto solve, ll x, ll par)->Matrix {
		Matrix v(1, Array(2, INF));
		if (a[x] > 0)v[0][0] = a[x];
		else v[0][1] = a[x];
		for (auto e : g[x]) {
			if (e.to == par)continue;
			auto u = solve(solve, e.to, x);
			Matrix dp(v.size()+u.size(), Array(2, INF));
			REP(i, v.size()) REP(incv, 2) {
				if (v[i][incv] == INF)continue;
				REP(j, u.size()) REP(incu, 2) {
					if (u[j][incu] == INF)continue;
					//cutしないとき
					ll inc = (incv | incu);
					ll cut = i + j;
					chmin(dp[cut][inc], v[i][incv] + u[j][incu]);
					//cutするとき
					if (incu == 1 && u[j][incu] >= 0)continue;
					inc = incv;
					cut++;
					chmin(dp[cut][inc], v[i][incv]);
				}
			}
			v = dp;
		}
		return v;
	};
	Matrix dp = solve(solve, 0, -1);
	ll ans = INF;
	REP(i, dp.size()) {
		if (dp[i][0] != INF)chmin(ans, i);
		if (dp[i][1] < 0)chmin(ans, i);
	}
	cout << ans << "\n";
  
	return 0;
}


Measured memory_bytes: 2432
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  int i,n,m,p,q;
  vector<P> x;
  vector<vector<int> > y(100010);
  scanf("%d %d\n",&n,&m);
  for(i=0;i<m;i++){
    scanf("%d %d\n",&p,&q);
    x.push_back(P(p,q));
    y[p].push_back(q);
  }
  for(i=1;i<=n;i++){
    sort(y[i].begin(),y[i].end());
    y[i].erase(unique(y[i].begin(),y[i].end()),y[i].end());
  }
  for(i=0;i<m;i++){
    int max=y[x[i].first].size(),min=-1,mid;
    while(abs(min-max)>1){
      mid=(min+max)/2;
      if(y[x[i].first][mid]<=x[i].second){
        min=mid;
      }
      else{
        max=mid;
      }
    }
    printf("%06d%06d\n",x[i].first,min+1);
  }
  return 0;
}

Measured memory_bytes: 7796
var
	N,i,a,j,ni,nj:Longint;
	dp:Array[0..200000,0..3]of int64;
begin
read(N);
for i:=0 to N do for j:=0 to 2 do dp[i,j]:=-1000000000000000000;
dp[0,0]:=0;
for i:=0 to N-1 do begin
read(a);
for j:=0 to 2 do begin
if dp[i+1,j+1]<dp[i,j]then dp[i+1,j+1]:=dp[i,j];
ni:=i+2;if ni>N then ni:=N;
nj:=j;if i+2=N then inc(nj);
if dp[ni,nj]<dp[i,j]+a then dp[ni,nj]:=dp[i,j]+a;
end;
end;
writeln(dp[N,1+N mod 2]);
end.

Measured memory_bytes: 6468
#include <stdio.h>

// 1～Nまでの整数を重複なしで3つ使ってXとなる組み合わせの通り数を出力
// N,Xともに0なら終了
int main()
{
	int iInputN, iInputX;
	int iSum;
	int iCnt1, iCnt2, iCnt3;
	int iAns;

	scanf("%d %d", &iInputN, &iInputX);

	while (iInputN != 0 || iInputX != 0)
	{
		iAns = 0;
		// 全通りの組み合わせを順に調べる（１ずつ開始と終了をずらす）
		for (iCnt1 = 1; iCnt1 <= iInputN - 2; iCnt1++)
		{
			for (iCnt2 = iCnt1 + 1; iCnt2 <= iInputN - 1; iCnt2++)
			{
				for (iCnt3 = iCnt2 + 1; iCnt3 <= iInputN; iCnt3++)
				{
					
					iSum = iCnt1 + iCnt2 + iCnt3;
					if (iSum == iInputX)
					{
						//printf("%d,%d,%d\n", iCnt1, iCnt2, iCnt3);
						iAns++;
					}
				}
			}
		}

		printf("%d\n", iAns);

		scanf("%d %d", &iInputN, &iInputX);
	}


	return 0;
}


Measured memory_bytes: 2104
/*
    _________             ____    __   __    __      __       __       __   __  
   |___   ___|           /  __)  |  | |  |  |  \    /  |     /  \     |  \ |  | 
       | |     __       (  {__   |  | |  |  |   \  /   |    / /\ \    |   \|  | 
       | |    /__\       \__  \  |  |_|  |  |    \/    |   / ____ \   |       | 
       | |                __)  ) {       }  |  |\__/|  |  / /    \ \  |  |\   | 
       |_|               (____/   \_____/   |__|    |__| /_/      \_\ |__| \__| 
*/
#include<bits/stdc++.h>
#define t_suman ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long int
#define pll pair<ll,ll>
#define VP vector< pll >
#define VLL vector< ll >
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int (i) = (a); (i) < (b); (i)++)
#define rrep(i,a,b) for(int (i) = (a); (i) > (b); (i)--)
#define all(v) (v).begin(),(v).end()
#define FF first
#define SS second
#define in insert
#define out erase
#define MOD 1000000007
#define MAX 1000005
using namespace std;


int main(void)
{
	t_suman;

	ll p,n;cin>>p>>n;
	VLL arr(n);
	rep(i,0,n)cin>>arr[i];
	ll ans=arr[0]+p-arr[n-1];
	rep(i,1,n){
		ans=max(ans,arr[i]-arr[i-1]);
	}
	ans=p-ans;
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 1792
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var n = int.Parse(Console.ReadLine());
            var ai = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
            var answer = ai.Sum(x => x - 1);
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 13376
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

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

  string s; cin >> s;
  int w; cin >> w;

  string ans;
  rep(i, si(s)) if (i % w == 0) ans += s[i];

  cout << ans << endl;

  return (0);
}


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


int main(){
  int N,M,K;
  cin >> N >> M;
  vector<int> A(N);
  int sum,count;
  double test;
  sum = 0;
  test = 0;
  count = 0;
  for(int i = 0; i < N; i++){
    cin >> K;
    sum += K;
    A.at(i) = K;
  }
  test = (double)sum/(4*M);
  for(int i = 0; i < N; i++){
    if( A.at(i) >= test){
      count++;
    }
  }
  if(count >= M){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>

typedef long long ll;

using namespace std;

ll Mod = 1e9 + 7;
int main()
{
    ll N, ans = 0;
    vector <ll> tmp;

    cin >> N;
    for (ll i = 1; i <= ll(sqrt(N)); i++) {
        if (N % i == 0 && i < N/i-1) ans += (N / i - 1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int a,b,c;
int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}
int GCD() {
    int ans;
    ans=gcd(a,b);
    ans=gcd(ans,c);
    return ans;
}
int main(){
    int n;
    long long ans=0;
    cin>>n;
    for(a=1;a<=n;a++){
        for(b=1;b<=n;b++){
            for(c=1;c<=n;c++){
                ans+=GCD();
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3192
program sample
    implicit none
    character(100)::s,t
    integer(8) :: i,j,k,m,n
    integer(8)::a,b,c,d
    integer(8),allocatable::x(:),y(:)
  
    read(*,*) n
    if(mod(n,2)==1)then
        write(*,*)0
        stop
    elseif(n<10)then
        write(*,*)0
        stop
    endif
    n=n/10
   
    m=n
    do i=1,30
        
        m=m+n/(5**i)
        

    end do
    write(*,*)m


   
    stop
end program sample
  



Measured memory_bytes: 2856
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <climits>
#define bogo_sort   std::sort
#define bozo_sort   std::stable_sort
#define alles(obj)  obj.begin(), obj.end()
#define elif        else if
#define unless(flg) if(!(flg))
#define elless(flg) else if(!(flg))
#define echo        std::cout <<
#define read        std::cin >>
#define endl        std::endl
#define fin         << '\n'
#define bash        push_back
#define fish        push_front
#define makePair    std::make_pair
#define _           << ' ' <<
// type-define
#define Stack       std::stack
#define Queue       std::queue
#define Deque       std::deque
#define PQueue      std::priority_queue
#define Set         std::set
#define Vector      std::vector
#define Pair        std::pair
#define Map         std::map
#define HashMap     std::unordered_map
#define Greater     std::greater
using String  =     std::string;
using llong   =     long long;
using boolean =     bool;
using Pii     =     Pair<int, int>;
using Vi      =     Vector<int>;
using Vii     =     Vector<Pii>;
// utils
constexpr int   dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int   dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
constexpr int   INF  = 0x3f3f3f3f;
constexpr llong LINF = 0x3f3f3f3f3f3f3f3fLL;

namespace {
    template<class A, class B> A power ( llong x, llong n, llong mod ) {
        llong ans = 1;
        while ( n > 0 ) {
            if ( n & 1 ) ans = ( ans * x ) % mod;
            x = ( x * x ) % mod;
            n >>= 1;
        }
        return ans;
    }
    template<class A, class B> A power ( A x, B n ) { return power( x, n, 1000000007 ); }
    template<class A> A gcd ( A x, A y ) { return x % y ? gcd( y, x % y ) : y; }
    template<class A, class B> A lcm   ( A x,  B y ) { return ( x / gcd(x, y) * y ); }
    template<class A> inline A abs ( A n ) { return ( n < 0 ) ? -n : n; }
    template<class A, class B> inline bool chmax ( A &a, const B &b ) { return b > a ? a = b, true : false; }
    template<class A, class B> inline bool chmin ( A &a, const B &b ) { return b < a ? a = b, true : false; }
    inline boolean isMovable ( int x, int y, int w, int h ) {
        return ( x >= 0 && y >= 0 && x < w && y < h );
    }
}

namespace Rlyeh {

    Vi vi;
    int sum;

    signed call_of_Cthulhu( signed datum ) {

        int n;
        read n;
        vi.bash(0);
        for ( int i = 0; i < n; i++ ) {
            int a;
            read a;
            vi.bash(a);
        }
        vi.bash(0);

        for ( int i = 1; i < n+2; i++ ) {
            sum += abs(vi[i] - vi[i-1]);
        }
        for ( int i = 1; i <= n; i++ ) {
            int ans = 
                sum-abs(vi[i]-vi[i-1])-abs(vi[i]-vi[i+1])+abs(vi[i-1]-vi[i+1]);
            echo ans fin;
        }



        return 0;
    }
}

signed main(){std::cin.tie(0); std::ios::sync_with_stdio(false); int main_result = Rlyeh::call_of_Cthulhu(114514); return 0;}


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

#define ll long long
#define pii pair<int,int>
#define two(x) (x<<1)
#define towd(x) (x>>1)
#define pb push_back
#define mp make_pair
#define sz(x) x.size()
#define x first
#define y second

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

	string s,t;
	cin>>s>>t;
	if (sz(s)+1==sz(t)){
		t=t.substr(0,s.size());
		if (s==t){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

struct UnionFind {
	int s, num; // [0, s) の s 個の要素がある。num は非空集合の個数。
	vector<vector<int>> v;
	vector<int> find;
	
	UnionFind() { s = 0; }
	UnionFind(int s) { init(s); }
	void init(int arg_s) {
		num = s = arg_s;
		v.clear();
		find.clear();
		inc(i, s) { v.PB({i}); find.PB(i); }
	}
	bool unite(int x, int y) {
		assert(inID(x, 0, s) && inID(y, 0, s));
		if(find[x] == find[y]) { return false; }
		num--;
		if(v[find[x]].size() > v[find[y]].size()) { swap(x, y); }
		int fx = find[x];
		for(auto && e: v[fx]) { v[find[y]].PB(e); find[e] = find[y]; }
		v[fx].clear();
		return true;
	}
};

// ----

LL n, m, a[100000];
vector<LL> v[100000], w;

int main() {
	cin >> n >> m;
	inc(i, n) { cin >> a[i]; }
	UnionFind uf(n);
	inc(i, m) {
		int x, y;
		cin >> x >> y;
		uf.unite(x, y);
	}
	
	inc(i, n) { v[uf.find[i]].PB(a[i]); }
	inc(i, n) { sort(ALL(v[i])); }
	
	if(m == n - 1) { cout << 0 << endl; return 0; }
	if(n < 2 * (n - 1 - m)) { cout << "Impossible" << endl; return 0; }
	
	LL ans = 0, c = 0;
	inc(i, n) {
		inc(j, v[i].size()) {
			if(j == 0) { ans += v[i][j]; c++; } else { w.PB(v[i][j]); }
		}
	}
	
	sort(ALL(w));
	bool f = false;
	inc(i, w.size()) {
		if(c == 2 * (n - 1 - m)) { f = true; break; }
		ans += w[i];
		c++;
		if(c == 2 * (n - 1 - m)) { f = true; break; }
	}
	assert(f);
	
	cout << ans << endl;
	
	return 0;
}


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

using LL = long long int;
using uLL = unsigned long long int;
using uint = unsigned int;
using ld = long double;


int main(){
	cin.tie(NULL);
	ios_base::sync_with_stdio(0);
    string s;
    cin >> s;
    string temp = s;
    reverse(temp.begin(), temp.end());
    int n = s.size();
    string s1, s2;
    s1 = s.substr(0, (n-1)/2);
    s2 = s.substr((n+3)/2-1, n-(n+3)/2+1);
    //cout << s1 << " " << s2 << '\n';
    string s3 = s1, s4 = s2;
    reverse(s3.begin(), s3.end());
    reverse(s4.begin(), s4.end());
    if(s == temp && s1 == s3 && s2 == s4){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }

	return 0;
}


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

#define MAX 1000
#define OP  10

void Print(char S[], int x, int y);
void Reverse(char S[], int x, int y);
void Replace(char S[], char P[], int x, int y);

int main(void) {
  char str[MAX];
  char op[OP];
  char p[MAX];
  int q;
  int i = 0;
  int a, b;

  scanf("%s", str);
  scanf("%d", &q);

  while(i < q) {
    scanf("%s", op);
    scanf("%d %d", &a, &b);

    if(strcmp(op, "print") == 0) {
      Print(str, a, b);
    }
    else if(strcmp(op, "reverse") == 0) {
      Reverse(str, a, b);
    }
    else if(strcmp(op, "replace") == 0) {
      scanf("%s", p);
      Replace(str, p, a, b);
    }
    i++;
  }

  return 0;
}

void Print(char S[], int x, int y) {

  for(int i=x; i<= y; ++i) {
    printf("%c", S[i]);
  }
  printf("\n");
}

void Reverse(char S[], int x, int y) {
  char tmp;
  int i = x;
  int j = y;

  while (i <= (x+y)/2) {
    tmp = S[i];
    S[i] = S[j];
    S[j] = tmp;
    i++;
    j--;
  }
}

void Replace(char S[], char P[], int x, int y) {
  int i=x, j=0;

  while(i <= y) {
    S[i++] = P[j++];
  }
}



Measured memory_bytes: 2068
"use strict";
    
const main = arg => {
    arg = arg.split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const T = parseInt(arg[0].split(" ")[1]);
    const t = arg[1].split(" ");
    
    let answer = 0;
    
    for(let i in t) {
        if(t[parseInt(i) + 1] - t[i] < T) {
            answer += t[parseInt(i) + 1] - t[i];
        } else {
            answer += T;
        }
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 40972
import collections as cc
I=lambda:list(map(int,input().split()))
n,m=I()
h=[0]+I()
ans=0
ar=[1]*(n)
for i in range(m):
    x,y=I()
    if h[x]==h[y]:
        ar[x-1]=0
        ar[y-1]=0
    else:
        if h[x]<h[y]:
            ar[x-1]=0
        else:
            ar[y-1]=0
print(ar.count(1))

Measured memory_bytes: 91252
Imports System

Module Program
    Sub Main(args As String())

        Dim tmp As String() = Split(Console.ReadLine())
        Dim N As Integer = CInt(tmp(0))
        Dim K As Integer = CInt(tmp(1))
        Dim tmp2 As String() = Split(Console.ReadLine())
        Dim p As New List(Of Integer)

        For i As Integer = 0 To N - 1
            p.Add(CInt(tmp2(i)))
        Next

        p.Sort()

        Dim sum As Integer = 0
        For i As Integer = 0 To K - 1
            sum += p(i)
        Next

        Console.WriteLine(sum)

    End Sub
End Module


Measured memory_bytes: 28888
N,M=map(int, input().split())
AB=[ [] for _ in range(N)]
for i in range(N):
  AB[i] = list( map(int, input().split()))
AB.sort()
#print(AB)
cnt = ans = 0
for i in range(N):
  buy = AB[i][1]
  if cnt + AB[i][1] >= M:
    buy = M - cnt
  cnt += buy
  ans += buy * AB[i][0]
#  print(buy,cnt,ans)
  if cnt >= M:
    break
print(ans)



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

int main()
{
	const int N = 1000000;
	static bool P[N];
	for ( int i=2; i<N; i++)
		P[i]=true;
	for(int i=2; i*i<N; i++ )
	if(P[i])
		for(int j=i+i;j<N;j+=i)
			P[j]=false;

	int n;
	while(cin>>n)
	{
		int c=0;
		for ( int i=0; i<=n; i++ )
			if (P[i])
				c++;
		cout<< c<<endl;
	}
	return 0;

}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define INF (1<<30)
#define INFLL (1ll<<60)
#define EPS (1e-10)
using namespace std;
map <int,int> mp;
typedef pair<int, int> P;
typedef long long ll;
static const int MAX=100000;
static const int NMAX=50;
static const int MMAX=50;
int cunt[MAX+2],N; //i円引き出すのにcount[i]回必要

void solve(){
    for(int i=1;i<=MAX;i++) cunt[i] = i; //1円だけ
    
    for(int i=6;i<=MAX;i++){
        for(int j=6;j<=i;j*=6){
            if(cunt[i] > cunt[i-j] + 1)  cunt[i] = cunt[i-j] + 1;
        }
    }
    for(int i=9;i<=MAX;i++){
        for(int j=9;j<=i;j*=9){
            if(cunt[i] > cunt[i-j] + 1)  cunt[i] = cunt[i-j] + 1;
        }
    }
    cout << cunt[N] <<"\n";
}

int main(){
    cin >> N;
    solve();
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
static const long long MOD = 1000000000+7;
static const double PI = 3.141592653589793;
vector<long long> vecmodfact(2,1);

long long modpow(long long x, long long n, long long mod = 0) {
  if (mod == 0) {
      long long res=1;
    while (n > 0) {
      if (n%2 == 1) {
        res = ( res*x );
      }
      x = (x*x);
      n /= 2;
    }
    return res;
  }

  long long res=1;
  while (n > 0) {
    if (n%2 == 1) {
      res = ( res*x ) % mod;
    }
    x = (x*x) % mod;
    n /= 2;
  }
  return res;
}

long long modinverse(long long x, long long mod) {
  // mod must be prime number.
  return modpow(x, mod-2, mod);
}

long long modfact(long long n, long long mod) {
  if (vecmodfact.size()-1 >= n) return vecmodfact.at(n);
  int i=vecmodfact.size();
  vecmodfact.resize(n+1);
  for (; i<=vecmodfact.size()-1; i++) {
    vecmodfact.at(i) = vecmodfact.at(i-1)*i % mod;
  }
  return vecmodfact.at(n);
}

long long modcomb(long long m, long long n, long long mod){
  if (m < n || n < 0) return 0;
  if (n == 0 || n == m) return 1;
  long long ans = modfact(m,mod) * modinverse(modfact(n,mod), mod) % mod;
  ans = ans * modinverse(modfact(m-n,mod), mod) % mod;
  return ans;
}


long long solve(long long n, long long m, long long k, long long mod) {
  long long ans = m * modcomb(n-1,k, mod) % mod;
  ans = ans * modpow(m-1, n-k-1, mod) % mod;
  return ans;
}

int main() {
  long long mod = 998244353;
  long long n,m,k;
  cin >> n >> m >> k;

  long long ans=0;
  for (int K=0; K<=k; K++) {
    ans = (ans + solve(n,m,K, mod)) % mod;
  }

  cout << ans << endl;
}

Measured memory_bytes: 4740
/*
ID: zhaowei10
TASK:
LANG: C++14
*/
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#ifdef LOCAL
string to_string(char c) { return string(1, c); }
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
  string res = "{";
  for (int i = 0; i < v.size(); ++i) {
    res += char('0' + v[i]);
  }
  res += "}";
  return res;
}
template <size_t N>
string to_string(bitset<N> b) {
  string res = "";
  for (int i = 0; i < N; ++i) {
    res += char('0' + b[i]);
  }
  return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> t) {
  return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " +
         to_string(get<2>(t)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> t) {
  return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " +
         to_string(get<2>(t)) + ", " + to_string(get<3>(t)) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += '}';
  return res;
}

void _debug() { cerr << '\n'; }
template <typename Head, typename... Tail>
void _debug(Head H, Tail... T) {
  cerr << ' ' << to_string(H);
  _debug(T...);
}
#define debug(...) cerr << '[' << #__VA_ARGS__ << "]:", _debug(__VA_ARGS__)
#else
#define debug(...) 0
#endif

#define eb emplace_back

using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using vc = vector<char>;
using vb = vector<bool>;
using vll = vector<ll>;

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

#ifdef LOCAL
  freopen("test.in", "r", stdin);
  freopen("test.out", "w", stdout);
#else
#endif

  int n;
  cin >> n;
  vector<string> pronun = {"hon", "pon", "bon"};
  vi indices = {1, 1, 0, 2, 0, 0, 1, 0, 1, 0};
  cout << pronun[indices[n % 10]];
}


Measured memory_bytes: 3108
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

priority_queue<ll> pql;
priority_queue<ll, vector<ll>, greater<ll> > pqr;

int main(void){
	int i,q,n,cnt=0;
	ll a,b,d=0ll,l=0ll,r=0ll,m;
	bool flag = false;
	cin >> q;
	for(i=0; i<q; ++i){
		cin >> n;
		if(n==1){
			cin >> a >> b;
			if(!cnt){
				m = a;
			}else if(cnt%2){
				if(a<m){
					pql.push(a);
					pqr.push(m);
					l += a;
					r += m;
				}else{
					pql.push(m);
					pqr.push(a);
					l += m;
					r += a;
				}
				m = pql.top();
			}else{
				if(a<pql.top()){
					m = pql.top();
					pql.pop();
					pql.push(a);
					l += a;
					l -= m;
				}else if(pqr.top()<a){
					m = pqr.top();
					pqr.pop();
					pqr.push(a);
					r += a;
					r -= m;
				}else{
					m = a;
				}
			}
			++cnt; d += b;
		}else{
			cout << m << " " << (r-l)+d << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3828
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <limits>
#include <stack>
#include <queue>
#include <map>
#include <set>

using namespace std;

using ll = long long;
using ui = unsigned int;
const ll MOD = 998244353;
const ll INF = 9223372036854775807;

//B
int main() {
	ll N;
	scanf("%lld", &N);
	vector<ll> D(N);
	for (ll i = 0; i < N; i++) {
		scanf("%lld", &D[i]);
	}

	if (D[0] != 0) {
		printf("0\n");
		return 0;
	}

	vector<ll> count(N, 0);
	for (ll i = 0; i < N; i++) {
		count[D[i]]++;
	}

	if (count[0] != 1) {
		printf("0\n");
		return 0;
	}

	ll result = 1;

	for (ll i = 1; i < N; i++) {
		for (ll j = 0; j < count[i]; j++) {
			result *= count[i - 1];
			result %= MOD;
		}
	}

	printf("%lld\n", result);
}


//C
/*
int main() {
	ll N;
	scanf("%lld", &N);
	vector<ll> a(N);
	for (ll i = 0; i < N; i++) {
		scanf("%lld", &a[i]);
	}
	vector<ll> b(N);
	for (ll i = 0; i < N; i++) {
		scanf("%lld", &b[i]);
	}

	ll need = 0;
	for (ll i = 0; i < N; i++) {
		if (a[i] > b[i]) {
			need++;
		}
	}

	std::sort(a.begin(), a.end());
	std::sort(b.begin(), b.end());

	bool result = true;

	for (ll i = 0; i < N; i++) {
		if (a[i] > b[i]) {
			result = false;
			break;
		}
	}

	if (result) {
		if (need > N - 2) {
			result = false;
		}
	}

	if (result) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
}*/

//A
/*
int main() {
	ll N;
	scanf("%lld", &N);

	ll result = 0;

	for (ll i = 1; i <= N / 2; i++) {
		if (N - i != i) {
			result++;
		}
	}

	printf("%lld\n", result);
}
*/

Measured memory_bytes: 1792
//d
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
    
    int n,k;cin>>n>>k;
    double msg[n];
    for(int i=1;i<=n;i++){
        cin>>msg[i];
        msg[i]=(1.0+msg[i])/2.0;
        msg[i]+=msg[i-1]; //當前會是 從index 1~自己 的總和相加
    }
    double ans=0.0;
    for(int i=0;i+k<=n;i++) ans=max(ans,msg[i+k]-msg[i]);// 因為是連續k個數, 要減掉之前的來算總和
    
    cout<<fixed<<setprecision(20)<<ans<<endl;
}
/*
期望值:
總和/個數
(上+下底)*高/2/高->(1+p)/2
*/


Measured memory_bytes: 1792
while True:
    try:
        string = raw_input()
    except EOFError:
        break
    for i in range(10):
        translated = string.replace("X",str(i))
        left,right = translated.split("=")
        first,second = left.split("+")
        if i == 0 and any((first[0]=="0" and len(first)>1, second[0]=="0" and len(second)>1, right[0]=="0" and len(right)>1)):
            continue
        elif int(first) + int(second) == int(right):
            print i
            break
    else:
        print "NA"

Measured memory_bytes: 4264
#include<stdio.h>
int main()
{
    int N,A,B,x,y,z;
    scanf("%d%d%d",&N,&A,&B);
    x=N*A;
    if(x<B)
    {
        printf("%d\n",x);
    }
    else if(x==B)
    {
         printf("%d\n",x);
    }
    else
    {
         printf("%d\n",B);
    }
    return 0;
}


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

int main(){
	int n;
	cin >> n;
	bool flag = false;
	for(int i=1;i<10;i++){
		for(int j=1;j<10;j++){
			if(i * j == n){
				flag = true;
			}
		}
	}
	if(flag){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}


Measured memory_bytes: 3020
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

int main() {
    string S;
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>S;
    if(S[2] == S[3] && S[4] == S[5]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
v = list(map(int, input().split()))
# print(v)

v.sort(reverse=True)

while len(v) >= 2:
    last = v.pop()
    second_last = v.pop()
    new_val = (last + second_last) / 2
    v.append(new_val)

print(v[0])

Measured memory_bytes: 3060
import java.util.*;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String str = sc.next();
		
		if(N%2 == 0) {
			String front = str.substring(0,N/2);
			String back = str.substring(N/2);
			if(front.equals(back)) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
		}else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int n, k[1005], l[1005];
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> k[i] >> l[i];
	}
	long long a = k[0], b = l[0];
	for (int i = 1; i < n; ++i) {
		long long mon = max((a + k[i] - 1) / k[i], (b + l[i] - 1) / l[i]);
		a = k[i] * mon;
		b = l[i] * mon;
	}
	cout << a + b << endl;
}

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

int DP[1010][1010];

int main() {
  int n;
  cin >> n;
  for (auto t=0; t<n; t++) {
    string A, B;
    cin >> A >> B;
    int LA = (int) A.size();
    int LB = (int) B.size();
    fill(&DP[0][0], &DP[0][0]+1010*1010, 0);
    for (auto i=-1; i<LA; i++) {
      for (auto j=-1; j<LB; j++) {
        if (i == -1 || j == -1) {
          DP[i+1][j+1] = 0;
        } else if (A[i] == B[j]) {
          DP[i+1][j+1] = 1 + DP[i][j];
        } else {
          DP[i+1][j+1] = max(DP[i+1][j], DP[i][j+1]);
        }
      }
    }
    cout << DP[LA][LB] << endl;
  }
}

Measured memory_bytes: 5196
N = int(input())
d = list(map(int, input().split(' ')))
#print(N)
#print(d)

d.sort()
#print(d)

mid = N // 2

if(d[mid - 1] == d[mid]):
    count = 0
else:
    count = d[mid] - d[mid - 1]

print(count)

Measured memory_bytes: 13992
#define taskname "test"

#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define fi first
#define se second

typedef long long lli;
typedef pair<int, int> pii;

const int maxn = 16;
const lli inf = 1e18 + 7;

int n;
int x[maxn], y[maxn], p[maxn];

lli dp[maxn][(1 << maxn) + 5];

lli pre[maxn + 5], su[maxn + 5];
lli f[maxn + 5], g[maxn + 5];

void read_input()
{
    cin >> n;
    for(int i = 0; i < n; ++i)
        cin >> x[i] >> y[i] >> p[i];
}

int bits(int x)
{
    int res = 0;
    while(x > 0)
    {
        res += (x & 1);
        x >>= 1;
    }
    return res;
}

lli calc(vector<pii>&v)
{
    pre[0] = v[0].se;
    for(int i = 1; i < sz(v); ++i)
        pre[i] = pre[i - 1] + v[i].se;
    su[sz(v) - 1] = v[sz(v) - 1].se;
    for(int i = sz(v) - 2; i >= 0; --i)
        su[i] = su[i + 1] + v[i].se;
    f[0] = 0;
    for(int i = 1; i < sz(v); ++i)
        f[i] = f[i - 1] + pre[i - 1] * 1LL * (v[i].fi - v[i - 1].fi);
    g[sz(v) - 1] = 0;
    for(int i = sz(v) - 2; i >= 0; --i)
        g[i] = g[i + 1] + su[i + 1] * 1LL * (v[i + 1].fi - v[i].fi);
    lli res = inf;
    for(int i = 0; i < sz(v); ++i)
        res = min(res, f[i] + g[i]);
    return res;
}

void solve()
{
    fill_n(&dp[0][0], sizeof(dp) / sizeof(dp[0][0]), inf);
    for(int mask = 0; mask < (1 << n); ++mask)
    {
        dp[0][mask] = 0;
        for(int k = 0; k < n; ++k)
            if(mask >> k & 1) dp[0][mask] += min(abs(x[k]), abs(y[k])) * 1LL * p[k];
    }
    for(int mask = 1; mask < (1 << n); ++mask)
    {
        if(bits(mask) == 1)
        {
            dp[1][mask] = 0;
            continue;
        }
        vector<pii> vx, vy;
        for(int k = 0; k < n; ++k)
            if(mask >> k & 1)
            {
                vx.push_back(pii(x[k], p[k]));
                vy.push_back(pii(y[k], p[k]));
            }
        sort(vx.begin(), vx.end()); sort(vy.begin(), vy.end());
        dp[1][mask] = min(calc(vx), calc(vy));
    }
    for(int i = 1; i <= n; ++i)
        for(int mask = 1; mask < (1 << n); ++mask)
        {
            if(bits(mask) <= i)
            {
                dp[i][mask] = 0;
                continue;
            }
            dp[i][mask] = min(dp[i][mask], dp[i - 1][mask]);
            for(int submask = mask; submask > 0; submask = (submask - 1) & mask)
            {
                if(submask == mask) continue;
                int omask = mask ^ submask;
                for(int j = 0; j <= 1; ++j)
                    if(dp[i - j][submask] != inf && dp[i - 1][submask] != inf)
                    dp[i][mask] = min(dp[i][mask], dp[i - j][submask] + dp[j][omask]);
                //dp[i][mask] = min(dp[i][mask], dp[i - 1][submask] + dp[1][omask]);
            }
        }
    for(int i = 0; i <= n; ++i)
        cout << dp[i][(1 << n) - 1] << '\n';
}

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



Measured memory_bytes: 11812
from sys import stdin
import numpy as np

n = int(stdin.readline().strip())
h_lst = [int(x) for x in stdin.readline().strip().split()]
cost_lst = [0] * len(h_lst)
cost_lst[1] = abs(h_lst[1] - h_lst[0])

for i in range(2, n):
  from_prev = cost_lst[i-1] + abs(h_lst[i-1]-h_lst[i])
  from_second_prev = cost_lst[i-2] + abs(h_lst[i-2]-h_lst[i])
  cost_lst[i] = min(from_prev, from_second_prev)
  
print(cost_lst[-1])

Measured memory_bytes: 23084