akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(i=1;i<=n;i++)
using namespace std;
const int maxm=250100;
struct Point
{
	void insert(double a,double b)
	{
		x=a,y=b;
	}
	double x,y;
};
Point d[520];
int fir[520],Next[maxm],End[maxm],size;
bool tag[520];
void addedge(int x,int y)
{
	Next[++size]=fir[x];
	fir[x]=size;
	End[size]=y;
}
double GetDis(Point a,Point b)
{
	return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
bool bfs(int S,int T)
{
	queue<int>que;
	while(!que.empty())que.pop();
	memset(tag,false,sizeof(tag));
	que.push(S);
	tag[S]=true;
	while(!que.empty())
	{
		int now=que.front();
		que.pop();
		if(now==T)return true;
		for(int u=fir[now];u;u=Next[u])
		{
			int ed=End[u];
			if(!tag[ed])
			{
				tag[ed]=true;
				que.push(ed);
			}
		}
	}
	return false;
}
int main()
{
	double w,h;
	int n,i;
	cin>>w>>h>>n;
	rep(i,n)
	{
		double x,y;
		cin>>x>>y;
		d[i].insert(x,y);
	}
	double L=0.0,R=1e9,ans;
	rep(i,100)
	{
		double mid=(L+R)/2.0;
	//	printf("mid=%.12f\n",mid);
		size=0;
		memset(fir,0,sizeof(fir));
		int j,k;
		rep(j,n)
		{
			if(mid>d[j].x)
			{
				addedge(j,n+1);
				addedge(n+1,j);
			}
			if(mid>w-d[j].x)
			{
				addedge(j,n+2);
				addedge(n+2,j);
			}
			double temp=mid*mid*4.0;
			for(k=j+1;k<=n;k++)
				if(temp>GetDis(d[j],d[k]))
				{
					addedge(j,k);
					addedge(k,j);
				}
		}
		if(bfs(n+1,n+2))R=mid;
		else L=mid;
		ans=mid;
	}
	printf("%.12f\n",ans);
	return 0;
}

Measured memory_bytes: 5212
import java.util.*;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int ans;
        ans = a - b*2;
        if(ans<0){
            ans = 0;
        }
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 23508
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;


constexpr int MOD = 1e9 + 7;

template<long long mod>
struct mint {
private:
    long long x;
public:
    mint(long long x = 0) :x((mod + x) % mod) {}
    mint(std::string &s) {
        long long z = 0;
        for (int i = 0; i < s.size(); i++) {
            z *= 10;
            z += s[i] - '0';
            z %= mod;
        }
        this->x = z;
    }
    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) {
        long long n = mod - 2;
        mint<mod> u = 1, b = a;
        while (n > 0) {
            if (n & 1) {
                u *= b;
            }
            b *= b;
            n >>= 1;
        }
        return *this *= u;
    }
    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*(const mint &a) const {
        mint res(*this);
        return res *= a;
    }
    mint operator/(const mint &a) const {
        mint res(*this);
        return res /= a;
    }
    friend std::ostream& operator<<(std::ostream &os, const mint &n) {
        return os << n.x;
    }
    bool operator==(const mint &a) const {
        return this->x == a.x;
    }
};

// comb (前計算O(NlogMOD) クエリO(1))
vector<mint<MOD>> FACT, IFACT;
/* 前計算(mainに)
*/
mint<MOD> comb(int n, int r) {
    if (n < 0 || r < 0 || r > n)return 0;
    if (r > n / 2) r = n - r;
    return FACT[n] * IFACT[n - r] * IFACT[r];
}

int main() {
    int n, k; cin >> n >> k;
    k = min(n, k);
    int MAX_N = 4 * 1e5;
    FACT.resize(MAX_N + 1);
    IFACT.resize(MAX_N + 1);
    FACT[0] = 1;
    IFACT[0] = 1;
    for (int i = 1; i <= MAX_N; i++) {
        FACT[i] = FACT[i - 1] * i;
        IFACT[i] = mint<MOD>(1) / FACT[i];
    }
    mint<MOD> ans = 0;
    for (int i = 0; i <= k; i++) {
        ans += comb(n, i) * comb(n - 1, n - i - 1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
#define y1 adfasfafa
const int maxn = 2e5+7;
typedef long long ll;

int n,m;
int ar[maxn];
vector<int> g[maxn];
int mx,root;
void dfs(int u,int pre,int dep){
    if(mx<dep){
        mx=dep;
        root=u;
    }
    for(int i=0;i<g[u].size();i++){
        int v=g[u][i];
        if(v==pre)continue;
        dfs(v,u,dep+1);
    }
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<n;i++){
        int a,b;scanf("%d%d",&a,&b);
        g[a].push_back(b);
        g[b].push_back(a);
    }
    mx=-1;
    dfs(1,-1,0);
    mx=-1;
    dfs(root,-1,0);
    if(mx%3==1)printf("Second\n");
    else printf("First\n");

    return 0;
}


Measured memory_bytes: 23680
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

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

template <typename T>
struct edge {
    int from, to; T cost;
    edge(int to, T cost) : from(-1), to(to), cost(cost) {}
    edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
};

template <class K, class V>
class RadixHeap {
    static constexpr int bit_length = sizeof(K)*8;
    K last;
    size_t sz, cnt;

    array<vector<pair<K, V>>, bit_length> v;
    static inline int bsr(int x){
        return x ? bit_length-__builtin_clz(x) : 0;
    }
    static inline int bsr(ll x){
        return x ? bit_length-__builtin_clzll(x) : 0;
    }

    void pull() {
        if(cnt < v[0].size()) return;;
        int i = 1;
        while(v[i].empty()) i++;
        last = min_element(v[i].begin(),v[i].end())->first;
        for (auto &&x : v[i]) v[bsr(x.first ^ last)].push_back(x);
        v[i].clear();
    }
public:
    RadixHeap() : last(0), sz(0), cnt(0) {}
    void emplace(K x, V val){
        sz++;
        v[bsr(x^last)].emplace_back(x, val);
    }

    pair<K, V> top() {
        pull();
        return v[0][cnt];
    }

    void pop() {
        pull();
        sz--;
        cnt++;
    }

    size_t size() const { return sz; }
    bool empty() const { return !sz; }
};
template <typename T>
vector<T> dijkstra(int s,vector<vector<edge<T>>> &G){
    auto n = G.size();
    vector<T> d(n, INF<T>);
    RadixHeap<T, int> Q;
    d[s] = 0;
    Q.emplace(0, s);
    while(!Q.empty()){
        T cost; int i;
        tie(cost, i) = Q.top(); Q.pop();
        if(d[i] < cost) continue;
        for (auto &&e : G[i]) {
            auto cost2 = cost + e.cost;
            if(d[e.to] <= cost2) continue;
            d[e.to] = cost2;
            Q.emplace(d[e.to], e.to);
        }
    }
    return d;
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<edge<int>>> G(n);
    for (int i = 0; i < m; ++i) {
        int a, b, c, d;
        scanf("%d,%d,%d,%d", &a, &b, &c, &d);
        a--; b--;
        G[a].emplace_back(b, c);
        G[b].emplace_back(a, d);
    }
    int s, g, v, p;
    scanf("%d,%d,%d,%d", &s, &g, &v, &p);
    s--; g--;
    cout << v-p-dijkstra(s, G)[g]-dijkstra(g, G)[s] << "\n";
    return 0;
}


Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
#define SZ(v) ((int)(v).size())
#define rep(i,n) for(int i=0;i<(n);i++)
#define foreach(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define all(v) (v).begin(),(v).end()
typedef long long ll;
typedef unsigned uint;
const int INF=0x3f3f3f3f;
int inline in(){int x=0,c;for(;(uint)((c=getchar())-'0')>=10;)
{if(c=='-')return -in();if(!~c)throw ~0;}do{x=(x<<3)+(x<<1)+(c-'0');}
while((uint)((c=getchar())-'0')<10);return x;}
int n;
const int MAXN=1e5+5;
int ghead[MAXN],gnxt[2*MAXN],gto[2*MAXN];
int path[MAXN],npath;
int col[MAXN];
bool dfs(int v,int p){
	if(v==n-1){
		npath=0;path[npath++]=v;return true;
	}
	for(int x=ghead[v];x!=-1;x=gnxt[x]){
		int to=gto[x];
		if(to!=p){
			if(dfs(to,v)){
				path[npath++]=v;return true;
			}
		}
	}
	return false;
}
void dfscol(int v,int p){
	for(int x=ghead[v];x!=-1;x=gnxt[x]){
		int to=gto[x];
		if(to!=p&&col[to]==-1){
			col[to]=col[v];
			dfscol(to,v);
		}
	}
}
int main(){
    cin.sync_with_stdio(false);cin.tie(0);
	cin>>n;
	rep(i,n)ghead[i]=-1;
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		--a;--b;
		gnxt[2*i+0]=ghead[a];ghead[a]=2*i+0;gto[2*i+0]=b;
		gnxt[2*i+1]=ghead[b];ghead[b]=2*i+1;gto[2*i+1]=a;
	}
	dfs(0,0);
	reverse(path,path+npath);
//	rep(i,npath)cout<<path[i]<<' ';cout<<endl;
	rep(i,n)col[i]=-1;
	rep(i,npath)col[path[i]]=i<(npath+1)/2?0:1;
	rep(i,npath)dfscol(path[i],path[i]);
	int na=0,nb=0;
	rep(i,n){
		if(col[i]==0)na++;
		else nb++;
	}
//	rep(i,n)cout<<col[i]<<' ';cout<<endl;
//	cout<<na<<' '<<nb<<endl;
	string ans=na>nb?"Fennec":"Snuke";
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6144
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdint>

int main() {
  intmax_t X, Y;
  scanf("%jd %jd", &X, &Y);

  intmax_t res=0;
  for (intmax_t i=X; i<=Y; i<<=1)
    ++res;

  printf("%jd\n", res);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

int main(){
  int N,M; cin >>N >>M;
  vector<int> a(N);
  vector<int> b(N);
  rep(i,0,N) cin >>a[i] >>b[i];
  vector<int> c(M);
  vector<int> d(M);
  rep(i,0,M) cin >>c[i] >>d[i];

  vector<int> ans(N);
  rep(i,0,N) {
    int temp=INT_MAX;
    rep(j,0,M) {
      int check=abs(a[i]-c[j])+abs(b[i]-d[j]);
      if (check<temp) {ans[i]=j+1; temp=check;}
    }
  }
  rep(i,0,N) cout <<ans[i] <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main()
{
  int n;
  while (scanf(" %d ", &n) == 1) {
    int c = 0;
    for (int i = 0; i <= 9; i++) {
      for (int j = 0; j <= 9; j++) {
	for (int k = 0; k <= 9; k++) {
	  for (int l = 0; l <= 9; l++) {
	    if (i + j + k + l == n) {c++;}
	  }
	}
      }
    }
    printf("%d\n", c);
  }
}

Measured memory_bytes: 0
#include <stdio.h>

int main(){
    int c[128][14] = {0};
    int n, r;
    char s, ss[] = {'S', 'H', 'C', 'D'};

    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf(" %c %d", &s, &r);
        c[s][r] = 1;
    }
    
    for (int i = 0; i < 4; i++)
    {
        s = ss[i];
        for (r = 1; r <= 13; r++)
        {
            if (c[s][r] == 0)
            {
                printf("%c %d\n", s, r);
            }
            
        }
        
    }
    return 0;
}


Measured memory_bytes: 2104
a = list(map(int, input().split()))

sum = 0

for i in range(3):
    if a[3] <= 0:
        break
    if a[i] >= a[3]:
        sum += (1 - i) * a[3]
    else:
        sum += (1 - i) * a[i]
    a[3] -= a[i]
        
print(sum)

Measured memory_bytes: 9188
import sys
def input():
    return sys.stdin.readline()[:-1]

def main():
    N, A, B = map(int, input().split())
    pair_count = N // (A+B)
    ans = A * pair_count
    length = pair_count * (A+B)
    ans += min(N-length, A)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
import sys
input = sys.stdin.readline

from heapq import heappush, heappop

N,M = map(int,input().split())
A = list(map(int,input().split()))
info = [list(map(int,input().split())) for _ in range(M)]

hq = []

for a in A:
    heappush(hq,[-a,1])
for b, c in info:
    heappush(hq,[-c,b])

ans = 0
while N > 0:
    C,B = heappop(hq)
    C *= -1
    if B < N:
        ans += C*B
        N -= B
    else:
        ans += C*N
        N = 0

print(ans)

Measured memory_bytes: 53368
#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <climits>
#include <map>
#include <stack>
using namespace std;
#define M_PI 3.141592
#define toRad 2.0*M_PI/360.0
#define inin(x) int x;cin>>x;
#define all(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" "<<x<<endl;
#define rep(i,n) for(int i=0;i<(int)n;i++)
typedef pair<int, int> pii;
int hoge(char a[4])
{
	if (a[0] == 'B')return 1;
	if (a[0] == 'O')return 3;
	if (a[1] == 'B')return 2;
	return 0;
}

int main()
{
	int t;
	char a[4];
	int ans[4] = {};
	while (scanf("%d,%s", &t, a) != EOF)
	{
		ans[hoge(a)]++;
		fill(a, a + 4, 0);
	}
	for (int i = 0; i < 4; i++)
	{
		cout << ans[i] << endl;
	}
}

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

int main() {
	int N;
	int a[210];
	int i,j;

	cin >> N;

	for (i = 0; i < N ; i++)
	{
		cin >> a[i];
	}

	int count[210];
	int same_color = 0;
	int magic_times = 0;

	for (j = 0; j < N-1; j++)
	{
		if (a[j] == a[j + 1])
			same_color++;
		else
		{
			magic_times += ((same_color+1) / 2);
			same_color = 0;
		}
	}

	if (same_color != 0)
		magic_times += ((same_color + 1) / 2);

	cout << magic_times << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
const int maxn=(int)1e6+5;
vector<int> V;
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;cin>>n;
    rep(i,1,n){int x;cin>>x;V.push_back(x);}
    V.erase(unique(V.begin(),V.end()),V.end());
    int cnt=0;
    for(auto t:V)cout<<t<<(++cnt==V.size()?'\n':' ');

}
/* 
 */


Measured memory_bytes: 3556
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        int R = 0;
        double sum = 0;
        Scanner scan = new Scanner(System.in);
        R = scan.nextInt();
        sum = R * 2 * 3.141592;
        System.out.println(sum);
        scan.close();
    }
}

Measured memory_bytes: 35940
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926525
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int h,w;cin>>h>>w;
  vector<string> s;
  REP(i,h){
    string ss;cin>>ss;
    s.push_back(ss);
  }
  REP(i,h){
    REP(j,w){
      if(s[i][j]=='.')continue;
      bool flag=true;
      if(j-1>=0 && s[i][j-1]=='#')flag=false;
      if(j+1<w && s[i][j+1]=='#')flag=false;
      if(i-1>=0 && s[i-1][j]=='#')flag=false;
      if(i+1<h && s[i+1][j]=='#')flag=false;
      if(flag){
        P("No");
        return 0;
      }
    }
  }
  P("Yes");
  return 0;
}


Measured memory_bytes: 256
from itertools import product

a=list(input())
sum=0
text=""
for i in product(["","+"],repeat=len(a)-1):
    text=""
    for j in range(len(a)-1):
        text+=a[j]+i[j]
    text+=a[len(a)-1]
    sum+=eval(text)
print(sum)
        

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

using namespace std;

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  map<int, int> r;
  r[0] = 1;
  long long ans = 0;
  for (int i = 0, s = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    s = (s + a) % m;
    if (r.count(s)) ans += r[s];
    r[s]++;
  }
  printf("%lld\n", ans);
  cerr << (double) clock() / CLOCKS_PER_SEC << '\n';
  return 0;
}

Measured memory_bytes: 3200
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define DEBUG true
#ifdef ONLINE_JUDGE
#undef DEBUG
#define DEBUG false
#endif 

using namespace std;

#define MAXN ((int)2e5+5)
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9 + 9)
#define ll long long
#define _ << " " <<
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define TRACE(x) if(DEBUG) cerr << #x << " = " << x << endl;
#define TRACE2(x,y) if(DEBUG) cerr << #x << " = " << x << " | " << #y << " = " << y << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl "\n"
#define pii pair<int,int>
#define mid ((l+r)/2)

int n,m;
int S,T;
vector <int> v[MAXN];

int dist[MAXN][3];

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);
	
	cin >> n >> m;
	for (int i = 0; i < m; ++i)
	{
		int a,b;
		cin >> a >> b;
		v[a].pb(b);
	}

	for (int i = 1; i <= n; ++i)
		for (int j = 0; j < 3; ++j)
			dist[i][j] = INF;

	cin >> S >> T;

	pii st = {0,S}; // first:dist, second:node

	priority_queue < pii, vector<pii> , greater <pii> > q;

	q.push(st); 

	while(!q.empty())
	{
		pii tmp = q.top();
		q.pop();

		int node = tmp.second;
		int dst = tmp.first;

		if(node == T && !(dst%3))
		{
			cout << dst/3 << endl;
			return 0;
		}

		for (int i = 0; i < v[node].size(); ++i)
		{
			int next = v[node][i];
			if(dist[next][(dst+1)%3] > dst)
			{
				dist[next][(dst+1)%3] = dst;
				q.push({dst+1,next});
			}
		}
	}

	cout << -1 << endl;
}

Measured memory_bytes: 9600
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
from collections import Counter

W = 0
def g_i(i, j):
    return i * W + (j+1) - 1

def dijkstra(n, start, nbl):
    """n: 頂点数, start: 始点, nbl: 隣接リスト"""
    import heapq
    WHITE = 1<<5
    GRAY = 1<<10
    BLACK = 1<<15
    color = [WHITE] * n
    distance = [INF] * n
    parent = [-1] * n
    q = []

    distance[start] = 0
    heapq.heappush(q, (0, start))
    while len(q) != 0:
        du, u = heapq.heappop(q)
        # print("u: {}, du: {}".format(u, du))
        color[u] = BLACK
        if distance[u] < du:
            continue
        for next, cost in nbl[u]:
            if color[next] != BLACK and distance[u] + cost < distance[next]:
                distance[next] = distance[u] + cost
                parent[next] = u
                color[next] = GRAY
                heapq.heappush(q, (distance[next], next))
    return (distance, parent)

def main():
    global W
    h, W = map(int, input().strip().split())
    w = W
    s = [[0] * w for _ in range(h)]
    G = [[] for _ in range(h * w)]
    for i in range(h):
        s[i] = list(input().strip())
    sc = 0
    dc = 0
    for i in range(h):
        for j in range(w):
            if s[i][j] == '#':
                sc += 1
                continue
            dc += 1
            if i != 0 and s[i-1][j] == '.':
                G[g_i(i, j)].append((g_i(i-1, j), 1))
            if i != h-1 and s[i+1][j] == '.':
                G[g_i(i, j)].append((g_i(i+1, j), 1))
            if j != 0 and s[i][j-1] == '.':
                G[g_i(i, j)].append((g_i(i, j-1), 1))
            if j != w-1 and s[i][j+1] == '.':
                G[g_i(i, j)].append((g_i(i, j+1), 1))
    # print(G)
    d, p = dijkstra(h * w, 0, G)
    # print(d[h*w - 1])
    # for i in range(h):
    #     for j in range(w):
    #         if p[g_i(i, j)] != -1:
    #             print('.', end='')
    #         else:
    #             print('#', end='')
    #     print('\n', end='')
    # print(g_i(h-1, w-2))
    # print(p[g_i(h-1, w-2)])
    # print(p)
    if d[h*w - 1] == INF:
        print(-1)
    else:
        print(dc - d[h*w - 1] - 1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 48728
#include <iostream>
#include<bits/stdc++.h>
#define int long long 
using namespace std;
const long long MOD=10000007;
const int INF=1e9+5;
// bool isPowerOfTwo(int n)
// {
// 	return (n && !(n & (n-1)));

// } 



int32_t main() {
	// your code goes here
     //long long k;cin>>k;
		long n;cin>>n;
		 long long k;cin>>k;
		vector<int >h(n);
		for(int & x: h)
		   cin>>x;
		vector<int>dp(n,INF);
		dp[0]=0;
		for(int i=0;i<n;i++)
		{
			for(int j=i+1;j<=i+k;j++)
			  {
			  	if(j < n)
			  	 dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
			  }
			  
		}
		cout<< dp[n-1]<<endl;
	


		 
	
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;

int main(){

  ll x,y;
  while(cin>>x>>y){
    if(x==0&&y==0)break;

    if(x>y)swap(x,y);
    out(x<<" "<<y);
  }

  return 0;
}



Measured memory_bytes: 3088
h,w = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(10)]
a = [list(map(int, input().split())) for _ in range(h)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j] = min(c[i][j], c[i][k]+c[k][j])
            
ans = 0
for i in range(h):
    for j in range(w):
        if (a[i][j]!=-1):
            ans += c[a[i][j]][1]
print(ans)

Measured memory_bytes: 3444
#include <cstdio>
using namespace std;

int A, B, C, D;
int len;

int main() {
    scanf("%d%d%d%d", &A, &B, &C, &D);
    for (int i = 0; i != 101; ++i)
        len += A <= i && i < B && C <= i && i < D;
    printf("%d\n", len);
    return 0;
}


Measured memory_bytes: 128
import sys

input = sys.stdin.readline

def main():
    card_list = [
        [0,0,0,0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0,0,0,0]
        ]
        
    n = int(input())
    for i in range(n):
        s, k = input().split()
        if s == "S":
            card_list[0][int(k)-1] = 1
        elif s == "H":
            card_list[1][int(k)-1] = 1
        elif s == "C":
            card_list[2][int(k)-1] = 1
        elif s == "D":
            card_list[3][int(k)-1] = 1
    
    for i in range(4):
        for k in range(13):
            if card_list[i][int(k)] == 0:
                if i == 0:
                    print("S " + str(k+1))
                elif i == 1:
                    print("H " + str(k+1))
                elif i == 2:
                    print("C " + str(k+1))
                elif i == 3:
                    print("D " + str(k+1))

if __name__ == "__main__":
    main()


Measured memory_bytes: 5612
#include<stdio.h>
int main()
{
	int i,a,b,k,k1;
	scanf("%d%d%d",&a,&b,&k);
	for(i=a;i<a+k&&i<=b;i++){
		printf("%d\n",i);	}
	if(i<b-k+1)
	i=b-k+1;
 for(k1=k;i<=b&&k1>0;i++,k1--)
 printf("%d\n",i);
	 return 0;


}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

ll powmod(ll x, ll n) { // like pow(x, n)
  ll r = 1;
  while (n) {
    if (n & 1) {
      r = r * x % MOD;
    }
    x = x * x % MOD;
    n >>= 1;
  }
  return r;
}

// Mod int
// cf. https://www.youtube.com/watch?v=1Z6ofKN03_Y
struct mint {
  ll x;
  mint(ll x = 0) : x((x + MOD) % MOD) {}
  mint& operator+= (const mint a) {
    if ((x += a.x) >= MOD) x %= MOD;
    return *this;
  }
  mint operator+ (const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint& operator-= (const mint a) {
    if ((x += MOD - a.x) >= MOD) x %= MOD;
    return *this;
  }
  mint operator- (const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint& operator*= (const mint a) {
    (x *= a.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;
  }
};

// dp[i+1][j][k]
// i .. checked until i.
// j .. the size of undefined numbers.
// k .. score
mint dp[55][55][2605];

// a. select 2 from i. they are connected with each other. a--b
// b. leave 2 numbers undefined. a, b
// c. 1 is selected, 1 is left to be undefined a--x, b (or a, x--b)
// d. select 2 and they are connected with numbers appeared above. (a--x, y--b)

int main(int argc, char** argv) {
  int N, score;
  cin >> N >> score;
  if (score % 2 == 1) { // odd
    cout << 0 << endl;
    return 0;
  }
  dp[0][0][0] = 1;
  rep(i, N) {
    rep(j, i + 1) {
      rep(k, score + 1) {
        { // a
          int nj = j;
          dp[i+1][nj][k+nj*2] += dp[i][j][k];
        }
        { // b
          int nj = j+1;
          dp[i+1][nj][k+nj*2] += dp[i][j][k];
        }
        { // c
          int nj = j;
          mint x = j*2;
          dp[i+1][nj][k+nj*2] += dp[i][j][k] * x;
        }
        if (j >= 1) {
          int nj = j-1;
          mint x = j*j;
          dp[i+1][nj][k+nj*2] += dp[i][j][k] * x;
        }
      }
    }
  }

  cout << dp[N][0][score].x << endl;
}


Measured memory_bytes: 61952
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.Set;
 
 
public class Main {

	static long MOD = 1_000_000_007;
	static int INF = 1_000_000_007;
	//二項係数関連ここから-----
	static boolean isPreprocessing = false;	//二項係数を計算するための前処理を行っているかどうかのフラグ
	static int MAX = 260;				//MAXまで階乗やそれらの逆元のテーブルを保持する。
	static long[] fac;	//fac[i] := i! % MOD
	static long[] inv;	//inv[i] := mod. MODにおける i の逆元
	static long[] finv;	//finv[i] := mod. MODにおける i! の逆元(invの累積"積")
	//二項係数関連おわり------
	
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		//int N = Integer.parseInt(sc.next());
		//long L = Long.parseLong(sc.next());
		//char[] A = sc.next().toCharArray();
		
		int N = Integer.parseInt(sc.next());
		int[] A = new int[N];
		int[] B = new int[N];
		for(int i=0; i<N;i++){
			A[i]=Integer.parseInt(sc.next());
			B[i]=A[i];
		}
		Arrays.sort(B);
		
		
		for(int a : A){
			if(a == B[N-1]){
				System.out.println(B[N-2]);
			}else{
				System.out.println(B[N-1]);
			}
		}
		
		
	}
	
	//aとbの最小公倍数を返す
	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (c/b);
	}
	
	//二項係数用の前処理
	static void COMinit(){
		//二項係数演算用前処理
		fac = new long[MAX+1];
		fac[0] = 1L;
		fac[1] = 1L;
		inv = new long[MAX+1];
		inv[1] = 1L;
		finv = new long[MAX+1];
		finv[0] = 1L;
		finv[1] = 1L;
		for(int i=2;i<MAX;i++){
			fac[i] = fac[i-1] * i % MOD;
			inv[i] = MOD - inv[(int)(MOD%i)] * (MOD/i) % MOD;
			finv[i] = finv[i-1] * inv[i] % MOD;
		}
		isPreprocessing = true;
	}
	
	//二項係数i_C_jをMODで割った余りを返す
	static long COM(int i, int j){
		if(i<j)return 0;
		if(i<0 || j<0)return 0;
		if(!isPreprocessing)COMinit();
		return fac[i] * (finv[j] * finv[i-j] % MOD) % MOD;
	}
	
}



Measured memory_bytes: 71172
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

template<typename T> T GCD(T x, T y){
    if(x < y)swap(x, y);
    if(y == 0)return x;
    return GCD(x % y, y);
}

vector<pair<ll, int>> factorize(ll n){
  vector<pair<ll, int>> res;
  for(ll i = 2; i*i <= n; i++){
    if(n % i)continue;
    res.emplace_back(i, 0);
    while(n % i == 0){
      n /= i;
      res.back().second++;
    }
  }
  if(n != 1) res.emplace_back(n, 1);
  return res;
}

int main()
{
  ll a, b; cin >> a >> b;
  ll g = GCD(a, b);
  auto f = factorize(g);
  cout << f.size() + 1 << endl;
  system("pause");
}


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

using namespace std;

int main(){
  int64_t a, b, k, takahashi, aoki;
  cin >> a >> b >> k;
  if(k < a){
    takahashi = a-k;
    aoki = b;
   }else{
    takahashi = 0;
    aoki = b-(k-a);
    if (aoki < 0){
      aoki = 0;
    }
  }
  
  cout << takahashi << " " << aoki << endl;
  
}

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

int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n, p, p1;
	long long br = 0;
	string s;
	cin >> n >> s;
	vector<bool> r(4005, false);
	vector<bool> g(4005, false);
	vector<bool> b(4005, false);
	vector<int> r1;
	vector<int> g1;
	vector<int> b1;
	for (int i = 0; i < n; i++)
	{
		if (s[i] == 'R')
		{
			r[i] = true;
			r1.push_back(i);
		}
		else if (s[i] == 'G')
		{
			g[i] = true;
			g1.push_back(i);
		}
		else
		{
			b[i] = true;
			b1.push_back(i);
		}
	}
	br = (long long)r1.size()*(long long)g1.size()*(long long)b1.size();
	for (int i = 0; i < r1.size(); i++)
		for (int j = 0; j < g1.size(); j++)
		{
			p = abs(r1[i] - g1[j]);
			p1 = (r1[i] + g1[j]) / 2;
			if (0 <= min(r1[i], g1[j]) - p && b[min(r1[i], g1[j]) - p] == true)
				br--;
			if (max(r1[i], g1[j]) + p < n && b[max(r1[i], g1[j]) + p] == true)
				br--;
			if (abs(p1 - r1[i]) == abs(p1 - g1[j]) && b[p1] == true)
				br--;
		}
	cout << br;
}


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

typedef long long ll;

int main(){

  cin.tie(0);
  ios::sync_with_stdio(false);

  int D;
  cin>>D;

  vector<ll> c(27);
  for(int i=1;i<=26;++i) cin>>c[i];
  vector<vector<ll>> s(D+1,vector<ll>(27,0));
  for(int i=1;i<=D;++i){
    for(int j=1;j<=26;++j){
      cin>>s[i][j];
    }
  }

  vector<ll> t(D+1,1);
  vector<set<ll>> next(27);
  vector<ll> test(D+1);

  ll ans=0;
  ll val=-1e10;

  for(int cnt=0;cnt<1000;++cnt){

    vector<set<ll>> nest(27);

    for(int i=1;i<=D;++i){
      test[i]=rand()%26;
      ++test[i];
    }

    for(int i=1;i<=D;++i){
      nest[test[i]].insert(i);
    }
    for(int i=1;i<=26;++i){
      nest[i].insert(0);
      nest[i].insert(D+1);
    }

    ll ch=0;
    for(int i=1;i<=D;++i){
      ch += s[i][test[i]];
      for(int j=1;j<=26;++j){
        auto k=nest[j].upper_bound(i);
        --k;
        ll l=*k;
        ch -= c[j]*(i-l);
      }
    }
    if(ch>val){
      val=ch;
      ans=ch;
      for(int i=1;i<=D;++i) t[i]=test[i];
    }
  }

  for(int i=1;i<=D;++i){
    next[t[i]].insert(i);
  }
  for(int i=1;i<=26;++i){
    next[i].insert(0);
    next[i].insert(D+1);
  }

  for(int i=0;i<1000000;++i){

    int d=rand()%D;
    ++d;
    int q=rand()%26;
    ++q;
    ll diff=0;

    //up
    ll l,r;
    auto j=next[q].lower_bound(d);
    r=*j;
    --j;
    l=*j;
    diff += s[d][q]+((r-d)*(d-l))*c[q];

    //down
    next[t[d]].erase(d);
    auto k=next[t[d]].lower_bound(d);
    r=*k;
    --k;
    l=*k;
    diff -= s[d][t[d]]+((r-d)*(d-l))*c[t[d]];

    //update
    if(diff>0){
      next[q].insert(d);
      t[d]=q;
      ans += diff;
    }
    else{
      next[t[d]].insert(d);
    }
  }

  for(int i=1;i<=D;++i) cout<<t[i]<<"\n";

  //cout<<ans<<"\n";

}

Measured memory_bytes: 3776
#include <bits/stdc++.h>
using namespace std;
const int nmax = 2e5 + 4;
long long l, n;
long long x[nmax];
long long ac[nmax];

long long solve(bool right, int s) {
  long long ans;
  if (right){
    if (!((n - s) & 1)) {
      ans = 2 * (-ac[s - 1] + ac[(s + n) / 2 - 1] + ac[(s + n) / 2] - ac[n])
      + x[(s + n) / 2] + (n - s) * l;
    } else {
      ans = 2 * (-ac[s - 1] + ac[(s + n) / 2] + ac[(s + n) / 2 + 1] - ac[n])
      - x[(s + n) / 2 + 1] + (n - s) * l;
    }
  } else {
    if (!(s & 1)) {
      ans = 2 * (ac[s / 2 - 1] + ac[s / 2] - ac[s])
      + x[s / 2] + s * l;
    } else {
      ans = 2 * (ac[s / 2] + ac[s / 2 + 1] - ac[s])
      - x[(s + 1) / 2] + s * l;
    }
  }
  return ans;
}


int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> l >> n;
  ac[0] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> x[i];
    ac[i] = ac[i - 1] + x[i];
  }

  long long maxv = 0;
  for (int start = 1; start <= n; start++) {
    for (int right = 0; right < 2; right++) {
      maxv = max(maxv, solve((bool)right, start));
    }
  }
  cout << maxv << '\n';
  return 0;
}

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

const long long INF = 1LL << 60;

long long h[101000];
long long dp[101000];

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

int main(){
    int N, K;
    cin >> N >> K;
    for(int i = 0; i < N; i++){ 
        cin >> h[i];
    }
    for(int i = 0; i < 101000; i++){ 
        dp[i] = INF;
    }

    dp[0] = 0;
    for(int i = 0; i < N; i++){ 
        for(int k = 1; k <= K; k++)
            chmin(dp[i+k], dp[i] + abs(h[i] - h[i+k]));
    }
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional>
#include <cmath>
#include <numeric>
#include <bitset>
#include <cstdint>
#include <stdexcept>
using namespace std;

// 整数型

using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;

// [0,n)を昇順/降順でループ

#define rep(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define repd(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)

// [a,b)を昇順/降順でループ

#define FOR(i, a, b) for (int i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define FORD(i, a, b) for (int i = static_cast<int>(b) - 1; i >= static_cast<int>(a); --i)

// デバッグ

#ifdef DEBUG
#include <cassert>
#define my_assert(x) assert(x)
#else
#define my_assert(x)
#define assert(x)
#endif

//////////////// //////////////// //////////////// //////////////// ////////////////
//////////////// //////////////// //////////////// //////////////// ////////////////

int main()
{
    // 高速な入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    // 浮動小数の表示の精度
    cout << fixed << setprecision(15);

    int n;
    cin >> n;
    cout << (n + 1) / 2 << endl;

    return 0;
}


Measured memory_bytes: 3568
#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;

int main() {
  int n, k;
  cin >> n >> k;
  lvec x(n);
  REP(i, n) cin >> x[i];

  x.push_back(0);
  sort(ALL(x));
  x.erase(unique(ALL(x)), x.end());

  ll ans = INF;

  REP(i, n - k + 1) {
    ll mn = min(abs(x[i]), abs(x[i + k]));
    ll mx = max(abs(x[i]), abs(x[i + k]));
    ll dist;
    if (x[i] * x[i + k] < 0) {
      dist = mn * 2 + mx;
    } else {
      dist = mn + mx;
    }
    ans = min(ans, dist);
  }

  if (k == 1) {
    ans = abs(x[0]);
  }
  print(ans);

  return 0;
}

Measured memory_bytes: 1920
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

# A, B, C = list(map(int, sys.stdin.readline().split()))
# ans = max(0, C - (A - B))
#
# print(ans)

N = int(sys.stdin.readline())
ans = 0
for i in range(1, N + 1):
    ans += len(str(i)) & 1
print(ans)


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

int main() {
	
	int n;
	cin >> n;
	vector<int> x(n);
	for(auto &i : x) cin >> i;
	int m=2000000;
	for(int i=1; i<=100; i++){
		int sum=0;
		for(int j=0; j<n; j++){
			sum += (x.at(j)-i)*(x.at(j)-i);
		}
		m = min(m,sum);
	}
	cout << m << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
  int n, hp;
  int a, b[1000000];
  int maxa=0;
  cin >> n >> hp;
  for(int i=0; i<n; i++){
    cin >> a;
    cin >> b[i];
    if(maxa < a)maxa = a;
  }
  sort(b, b+n);

  int cnt=0;
  for(int i=n-1; hp>0 && i>=0 && b[i]>maxa; i--){
    cnt++; hp-=b[i];
  }
  if(hp>0)cnt += (hp+maxa-1)/maxa;

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int> nums(n);

  int max = 0, second_max = 0;
  rep(i, n) {
      cin >> nums.at(i);
      if (nums.at(i) > max)
      {
        second_max = max;
        max = nums.at(i);
      }
      else if (nums.at(i) > second_max)
      {
          /* code */
          second_max = nums.at(i);
      }
  }
  rep(i,n) {
    if (nums.at(i) == max && nums.at(i) != second_max)
    {
        /* code */
        // max_arr.at(i) = second_max;
        cout << second_max << endl;
    }
    else
    {
        /* code */
        // max_arr.at(i) = max;
        cout << max << endl;
    }
  }
}

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

int main(){

  int a, b, c, d, h1, h2, k1, k2, sh, sk;

  cin>>h1>>h2>>k1>>k2>>a>>b>>c>>d;

  sh=a*h1+h1/10*c+b*h2+h2/20*d;
  sk=a*k1+k1/10*c+b*k2+k2/20*d;

  if(sh>sk) cout<<"hiroshi"<<endl;
  else if(sh<sk) cout<<"kenjiro"<<endl;
  else cout<<"even"<<endl;
  
  return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int x = (a + d - 1) / d;
  int y = (c + b - 1) / b;
  if(x >= y) cout << "Yes" << endl;
  else cout << "No" << endl;
} 

Measured memory_bytes: 3652
(declaim (optimize (speed 3) (debug 0) (safety 0)))

(declaim (ftype (function (string &optional) (values (vector string *) &optional)) split))
(defun split (text &optional (delim #\Space))
    (let* ((result (make-array 0
                               :element-type 'string
                               :adjustable t
                               :fill-pointer 0)))
          (loop :for c :across text
                :with temp = ""
                :do
                (cond ((char= c delim)
                       (vector-push-extend temp result)
                       (setf temp ""))
                    (t
                     (setf temp (concatenate 'string temp (string c)))))
                :finally
                (vector-push-extend temp result))
          result))

(declaim (ftype (function (integer integer) (values string &optional)) solve))
(defun solve (a b)
    (cond ((and (<= a 8) (<= b 8))
           "Yay!")
        (t ":(")))

(defun main ()
    (let* ((input (map 'vector #'parse-integer (split (read-line))))
           (a (aref input 0))
           (b (aref input 1)))
          (format t "~A~%" (solve a b))))

(main)

Measured memory_bytes: 27108
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <math.h>
#include <string>
#include <math.h>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> Q;

const ll mod = 1000000007;
const ll INF = 1000000000000;

ll n;

double v[100];


int main()
{
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> v[i];
	}
	sort(v, v + n);
	double ans = (v[0] + v[1]) / 2;
	for (int i = 2; i < n; i++)
	{
		ans = (ans + v[i]) / 2;
	}

	cout << setprecision(10) << ans << endl;

	int www;
	cin >> www;
}


Measured memory_bytes: 256
import math

n,m=map(int,input().split())
if n==1:
        print(m)
else:
        l=[]
        for i in range(1,math.floor(m**0.5)+1):
           if m%i==0 and i<=m//n:
                l.append(i)
                if m//i<=m//n:
                        l.append(m//i)
        l.sort()
        print(l[-1])

Measured memory_bytes: 3060
//58
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  int n;
  cin>>n;
  int dp[2][10001][2];
  fill(dp[0][0],dp[2][0],1<<30);
  dp[0][1][0]=dp[0][0][1]=0;
  for(int i=0;i<n-1;i++){
    int cc;
    cin>>cc;
    for(int j=0;j<n-2;j++){
      dp[!(i&1)][j+1][0]=min(dp[i&1][j][0],dp[i&1][j][1]+cc);
      dp[!(i&1)][j][1]=min(dp[i&1][j][1],dp[i&1][j][0]+cc);
    }
  }
  cout<<min(dp[(n-1)&1][n/2][0],dp[(n-1)&1][n/2][1])<<endl;
  return 0;
}
  

Measured memory_bytes: 1316
#include <iostream>
using namespace std;
bool isKaibunsuu(int n) {
    int a[5];
    a[0] = n/10000;
    a[1] = n/1000 - (n/10000)*10;
    a[2] = n/100 - (n/1000)*10;
    a[3] = n/10 - (n/100)*10;
    a[4] = n - (n/10)*10;
    if (a[0]==a[4] && a[1]==a[3]) {
        return true;
    } else {
        return false;
    }
}
int main() {
    int a, b;
    cin >> a >> b;
    int count = 0;
    for (int i=a; i<=b; i++) {
        if (isKaibunsuu(i)) count++;
    }
    cout << count << endl;
}

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

using namespace std;

bool is_prime(int n, int k = 2)
{
    if(n < k * k) { return true; }
    
    if(n % k == 0) { return false; }
    
    return is_prime(n, k + 1);
}

int main()
{
    vector<int> prime;
    
    for(int i = 2; i < 150000; i++)
    {
        if(is_prime(i))
        {
            prime.push_back(i);
        }
    }
    
    int n, m;
    
    while(true)
    {
        cin >> n >> m;
        
        if(n == -1 && m == -1) { break; }
        
        int ptr = distance(prime.begin(), lower_bound(prime.begin(), prime.end(), n + 1));
        
        vector<int> c;
        
        for(int i = ptr; i < ptr + m; i++)
        {
            for(int j = i; j < ptr + m; j++)
            {
                c.push_back(prime[i] + prime[j]);
            }
        }
        
        sort(c.begin(), c.end());
        
        cout << c[m - 1] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3128
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <unordered_set>

 
using namespace std;
 
 
int main(int argc, const char * argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    cout << (((N - 1) / 1000) + 1) * 1000 - N;

}


Measured memory_bytes: 3640
//#define NDEBUG
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;
template< typename T >
struct PairingHeap
{
	struct Node
	{
		T key;
		Node *head, *next;
	} *root = nullptr;
	bool rev;

	PairingHeap(bool rev = false) : rev(rev) {}

	Node *merge(Node *x, Node *y)
	{
		if (!x || !y) return x ? x : y;
		if ((x->key > y->key) ^ rev) std::swap(x, y);
		y->next = x->head;
		x->head = y;
		return x;
	}

	void push(const T &key)
	{
		auto t = new Node({ key, nullptr, nullptr });
		root = merge(root, t);
	}

	T top()
	{
		return root->key;
	}

	Node *_pop(Node *s)
	{
		Node *p = nullptr;
		while (s) {
			Node *a = s, *b = nullptr;
			s = s->next;
			a->next = nullptr;
			if (s) {
				b = s;
				s = s->next;
				b->next = nullptr;
			}
			a = merge(a, b);
			a->next = p;
			p = a;
		}
		while (p) {
			Node *j = p;
			p = p->next;
			s = merge(j, s);
		}
		return s;
	}

	void pop()
	{
		auto *temp = root;
		root = _pop(root->head);
	}

	bool empty() const
	{
		return !root;
	}

	void merge(PairingHeap< T > &p)
	{
		root = merge(root, p.root);
	}
};

template<typename T>
void uscan(T &d) {
	d = 0;int c = 0;
	while (c < '0' || '9' < c) c = fgetc(stdin);
	while ('0' <= c&&c <= '9') {
		d = (d << 3) + (d << 1) + c - '0';c = fgetc(stdin);
	}
}
void sscan(std::string &s) {
	s = std::string();
	int c = 0;
	while (c < 'a' || 'z' < c) c = fgetc(stdin);
	while ('a' <= c&&c <= 'z') {
		s.push_back(c);
		c = fgetc(stdin);
	}
}

int main(void) {
	std::string s;
	uint32 k;
	PairingHeap<uint32> Q(true);
	sscan(s);
	while (s[2] != 'd') {
		if (s[0] == 'e') {
			printf("%u\n", Q.top());
			Q.pop();
		}
		else {
			uscan(k);
			Q.push(k);
		}
		sscan(s);
	}
	return 0;
}


Measured memory_bytes: 49688
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
struct Point{double x,y;};
double dist(Point a,Point b) {return sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2));}

int main(void){
    int N;
    while(cin>>N,N){
        vector<Point> p(N);
        int maxcnt=1;
        rep(i,N)cin>>p[i].x>>p[i].y;
        rep(i,N){
            for(int j=i+1;j<N;j++){
                double d = dist(p[i],p[j]);
                if(d>2.0)continue;
                int sign[]={-1,1};
                rep(s,2){
                    Point C;
                    C.x = p[i].x + cos(atan2(p[j].y-p[i].y,p[j].x-p[i].x) + sign[s]*acos(d/2.0));
                    C.y = p[i].y + sin(atan2(p[j].y-p[i].y,p[j].x-p[i].x) + sign[s]*acos(d/2.0));
                    int cnt=0;
                    rep(k,N) cnt += (pow(C.x-p[k].x,2) + pow(C.y-p[k].y,2) <= 1.0001);
                    if(maxcnt<cnt)maxcnt=cnt;
                }
            }
        }
        cout<<maxcnt<<endl;
    }

    return 0;
}

Measured memory_bytes: 1392
// Making Sugoroku

// wrong answer
// 3/6

#include<iostream>
using namespace std;

int M, n, d[252];
int visited[252], visited2[252];

void rec(int start) {
    if(start < 0) return;
    if(n+1 <= start) return;
    if(visited[start]) return;
    visited[start] = 1;
    for(int i=1; i<=M; i++) {
        rec(start + i + d[start+i]);
    }
    return;
}

bool rec2(int start) {
    bool ok = false;
    if(start < 0) return false;
    if(n+1 <= start) return true;
    if(visited2[start]) return false;
    visited2[start] = 1;
    for(int i=1; i<=M; i++) {
        ok |= rec2(start + i + d[start+i]);
    }
    return ok;
}

int main()
{
    while(cin>>M, M) {
        cin>>n;
        visited[0] = 0;
        for(int i=1; i<=n; i++) {
            cin>>d[i];
            visited[i] = 0;
        }
        d[0] = 0;
        d[n+1] = 0;
        rec(0);
        bool ok = true;
        for(int i=0; i<=n; i++) {
            if(!visited[i]) continue;
            for(int j=0; j<=n; j++) visited2[j] = false;
            if(!rec2(i)) ok=false;
        }
        if(ok) cout<<"OK"<<endl;
        else cout<<"NG"<<endl;
    }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

const ll mod = 1e9 + 7;

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

    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll a = 0, b = 0, c = 0;
    REP(i, n) {
        if (s[i] == 'R') a++;
        else if (s[i] == 'G') b++;
        else c++;
    }
    ll res = a * b * c;
    REP(t, n) {
        REP(j, n) {
            ll u = t + j + 1, v = t + 2 * (j + 1);
            if (v >= n) continue;
            if (s[t] != s[u] && s[u] != s[v] && s[v] != s[t]) res--;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3664
sx,sy,tx,ty = map(int,input().split())
dx = tx-sx
dy = ty-sy
w = []
for i in range(dy):
    w.append('U')
for i in range(dx):
    w.append('R')
for i in range(dy):
    w.append('D')
for i in range(dx):
    w.append('L')
w.append('L')
for i in range(dy+1):
    w.append('U')
for i in range(dx+1):
    w.append('R')
w.append('D')
w.append('R')
for i in range(dy+1):
    w.append('D')
for i in range(dx+1):
    w.append('L')
w.append('U')
print(''.join(w))

Measured memory_bytes: 3188