akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
typedef vector<P> vec;

namespace std{
  bool operator < (const P &a,const P &b){
    return (a.imag()==b.imag()?
            a.real()<b.real():
            a.imag()<b.imag());
  }
};

double eps=1e-8;
double PI=acos(-1);

bool eq(double a,double b){return (b-a<eps&&a-b<eps);}
bool eq(P a,P b){return (abs(a-b)<eps);}

double dot(P a,P b){return real(b*conj(a));}
double cross(P a,P b){return imag(b*conj(a));}
P project(P a,P b,P c){b-=a;c-=a;return a+b*real(c/b);}
P reflect(P a,P b,P c){b-=a;c-=a;return a+conj(c/b)*b;}
int ccw(P a,P b,P c){
  b-=a,c-=a,a=c*conj(b);
  if(a.imag()>eps)return 1;//ccw
  if(a.imag()<-eps)return -1;//cw
  if(a.real()<-eps)return 2;//ob
  if(abs(b)+eps<abs(c))return -2;//of
  return 0;//os
}

//segment ab , point c
double dist(P a,P b,P c){
  if(dot(b-a,c-a)<0)return abs(c-a);
  if(dot(a-b,c-b)<0)return abs(c-b);
  return abs(cross(b-a,c-a))/abs(b-a);
}

bool isintersect(P a,P b,P c,P d){
  return ((ccw(a,b,c)*ccw(a,b,d)<=0)&&(ccw(c,d,a)*ccw(c,d,b)<=0));
}

//segment ab , segment cd
P intersect(P a,P b,P c,P d){
  a-=d;b-=d;c-=d;
  return d+a+(b-a)*imag(a/c)/imag(a/c-b/c);
}

double dist(P a,P b,P c,P d){
  if(isintersect(a,b,c,d))return 0;
  double ab=min(dist(a,b,c),dist(a,b,d));
  double cd=min(dist(c,d,a),dist(c,d,b));
  return min(ab,cd);
}

double calcArea(vec &t){
  double res=0;
  int n=t.size();
  for(int i=0;i<n;i++)res+=cross(t[i],t[(i+1==n?0:i+1)]);
  return abs(res/2.0);
}

double Arg(P a,P b,P c){
  b-=a,c-=a;
  return arg(c*conj(b));
}

int inPolygon(vec &t,P p){
  int n=t.size();
  double sum=0;  
  for(int i=0;i<n;i++){
    P a=t[i],b=t[(i+1==n?0:i+1)];
    if( ccw(a,b,p) == 0 )return 1;// on
    sum+= Arg(p,a,b);
  }
  if( abs(sum) < eps )return 0;//out
  else  return 2;//in
}

typedef pair<double,P> Pair;

vec andrewScan(vec &t){
  int N=t.size(),C=0;
  vec R(N);
  for(int i=0;i<N;i++){
    while(2<=C&&ccw(R[C-2],R[C-1],t[i])==-1)C--;
    R[C++]=t[i];
  }
  vec res(C);
  for(int i=0;i<C;i++)res[i]=R[i];
  return res;
}

vec ConvexHull2(vec t){
  sort(t.begin(),t.end());
  vec u=andrewScan(t);
  reverse(t.begin(),t.end());
  vec l=andrewScan(t);
  for(int i=1;i+1<(int)l.size();i++)u.push_back(l[i]);
  return u;
}

vec ConvexHull(vec t){
  vector<Pair> u;
  vec R;
  int N=t.size(),K=0,C=0;
  for(int i=1;i<N;i++)if(t[i]<t[K])K=i;
  for(int i=0;i<N;i++)u.push_back(Pair(arg(t[i]-t[K]),t[i]));
  R.push_back(t[K]),C++;
  sort(u.begin(),u.end());
  for(int i=0;i<N;i++){
    P p=u[i].second;
    if(2<=C&&ccw(R[C-2],R[C-1],p)==0)continue;
    if(2<=C&&ccw(R[C-2],R[C-1],p)==2)continue;
    while(2<=C&&ccw(R[C-2],R[C-1],p)!=1)R.pop_back(),C--;
    R.push_back(p),C++;    
  }
  return R;
}

int main(){
  int n;
  cin>>n;
  vec t;
  double x,y;
  for(int i=0;i<n;i++){
    cin>>x>>y;
    t.push_back(P(x,y));
  }
  vec ans=ConvexHull(t);
  int m=ans.size();
  double maxm=0;
  
  for(int i=0;i<m;i++){
    for(int j=0;j<m;j++){
      maxm=max(maxm,abs(ans[i]-ans[j]));
    }
  }
  
  printf("%.8f\n",maxm);
  return 0;
}

Measured memory_bytes: 9660
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+2;
int cnt0[N],cnt1[N],par[N],head[N];
int findd(int x){
	if(head[x]<0){
		return x;
	}
	int y=findd(head[x]);
	head[x]=y;
	return y;
}
void unionn(int x,int y){
	x=findd(x),y=findd(y);
	if(x==y){
		return;
	}
	head[x]+=head[y];
	head[y]=x;
}
struct wow{
	int c0,c1,idx;
} temp;
struct cac{
	bool operator()(wow const& x,wow const& y){
		if(x.c1*y.c0!=y.c1*x.c0){
			return x.c1*y.c0>y.c1*x.c0;
		}
		return x.idx<y.idx;
	}
};
priority_queue<wow,vector<wow>,cac> lis;
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,i,j,k,l,x,ans=0;
	cin>>n;
	for(i=2;i<=n;i++){
		cin>>par[i];
	}
	for(i=1;i<=n;i++){
		head[i]=-1;
		cin>>j;
		if(j==1){
			cnt1[i]++;
		}
		else{
			cnt0[i]++;
		}
		temp.c0=cnt0[i];
		temp.c1=cnt1[i];
		temp.idx=i;
		if(i>1){
			lis.push(temp);
		}
	}
	while(lis.size()){
		temp=lis.top();
		lis.pop();
		j=temp.c0; k=temp.c1; l=temp.idx;
		if(j!=cnt0[l]||k!=cnt1[l]){
			continue;
		}
		x=par[l];
		x=findd(x);
		ans+=cnt1[x]*cnt0[l];
		cnt0[x]+=j;
		cnt1[x]+=k;
		assert(findd(x)!=findd(l));
		unionn(x,l);
		if(x==1){
			continue;
		}
		temp.c0=cnt0[x];
		temp.c1=cnt1[x];
		temp.idx=x;
		lis.push(temp);
	}
	cout<<ans;
}

Measured memory_bytes: 14192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for(int i = a; i < b; i++)
int main() {
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    cout << (H - h) * (W - w) << endl;
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

int main(){
  
  string s;
  cin>>s;
  string ans = "";
  int n = s.size();
  if(n==2){
    cout<<s<<endl;
  }else{
    for(int i=n-1;i>=0;i--){
      ans += s[i];
    }
    cout<<ans<<endl;
  }
  return 0;
}


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

  int x,y;
};
int main()
{
     int n;
     cin>>n;
     int cnt=0;
     int flag=0;
     node q[n];
     for(int i=0;i<n;i++)
     {
         cin>>q[i].x>>q[i].y;
     }
     for(int i=0;i<n-2;i++)
     {
         if((q[i].x==q[i].y)&&(q[i+1].x==q[i+1].y)&&(q[i+2].x==q[i+2].y))
              flag=1;
     }
     if(flag==1)
         cout<<"Yes"<<endl;
     else
        cout<<"No"<<endl;
}


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



int main(void){
  
string S;
cin>>S;
int N=S.size();
long long ans=0;
for(int bit=0;bit<(1<<(N-1));bit++){
string SS="";
 for(int i=0;i<N;i++){
     SS+=S[i];
  if(bit&(1<<i)){
   ans+=stol(SS);
   SS="";
  }
 }
 ans+=stol(SS);
 SS="";
}
 cout<<ans<<endl;   
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define int long long
#define INF 1000000000000000000
using namespace std;

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
template<typename T>
void debug(vector<vector<T>> m){ REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;} }



signed main(){

    int N, M; cin >> N >> M;
    int ans = min(N, M / 2);
    M -= 2 * ans;
    ans += M / 4;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
/* ALDS1_11_B: Depth First Search */

#include <iostream>
#include <cstdio>
#include <vector>
using std::vector;

vector<int> *graph;
int elapsed = 1;

// Search the graph recursively by depth-first search.
void traverse(int id, int found[], int finished[]) {
    if (0 < found[id]) {
        return;
    }

    found[id] = elapsed++;
    vector<int> adjs = graph[id];
    for (int i = 0; i < adjs.size(); i++) {
        traverse(adjs[i], found, finished);
    }
    finished[id] = elapsed++;
}

int main() {
    int n_v;
    scanf("%d", &n_v);

    int max_v = n_v + 1;
    graph = new vector<int>[max_v];

    for (int i = 0; i < max_v; i++) {
        int id, n_adjs;
        scanf("%d %d", &id, &n_adjs);

        for (int j = 0; j < n_adjs; j++) {
            int adj_id;
            scanf("%d", &adj_id);
            graph[id].push_back(adj_id);
        }
    }

    int found[max_v];
    int finished[max_v];
    std::fill_n(found, max_v, 0);
    std::fill_n(finished, max_v, 0);

    for (int id = 1; id < max_v; id++) {
        traverse(id, found, finished);
    }

    for (int id = 1; id < max_v; id++) {
        printf("%d %d %d\n", id, found[id], finished[id]);
    }
    return 0;
}

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

using namespace std;
main(){
  int n,s=0;
  cin>>n;
  vector<int> v(n+1);
  for(int i=1;i<=n;i++)cin>>v[i];
  for(int i=1;i<=n;i++){
    for(int  j=i+1;j<=n;j++){
      s+=v[j]*v[i]; 
    }
  }
  cout<<s;
  return 0;
}

Measured memory_bytes: 3596
#pragma warning (disable:4996)
#include"bits/stdc++.h"
#include<cassert>
#define int long long
#define MRE assert(0);
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const long long mod = 1000000007;
const long long inf = 1e17;
typedef pair<int, int> P;
struct rect {
	int L, R, H;
};
int n; 
int h[105];
int dp1[105][105], dp2[105][105];
int modpow(int a, int x) {
	int res = 1;
	while (x) {
		if (x & 1)res = res*a%mod;
		a = a*a%mod;
		x >>= 1;
	}
	return res;
}

void memo(int l, int r) {
	if (dp1[l][r] != -1)return;
	vector<P>V;
//	cout << l << ' ' << r << endl;

	int idx = l, mn = inf;
	for (int i = l; i <= r; i++)mn = min(mn, h[i]);
	int idx2 = l;

	while (1) {
		while (idx2<=r&&h[idx2] == mn)idx2++;
		if (idx2 > r)break;
		int idx3 = idx2;
		while (idx3<=r&&h[idx3] != mn)idx3++;
		V.push_back(P(idx2, idx3-1));
		idx2 = idx3 + 1;
	}

	if (V.size()) {//適切なマージ
		vector<P>V2;
		rep(j, V.size()) {
			memo(V[j].first, V[j].second);
			V2.push_back(P(dp1[V[j].first][V[j].second], dp2[V[j].first][V[j].second]));
		}
		int m = 0;
		for(int i=l;i<=r;i++)if (h[i] == mn)m++;
		int sum = 1, sum2 = 2;
		int H = h[r + 1];
		if (l)H = max(H, h[l - 1]);
		H = mn - H;
		rep(i, V2.size()) {
			sum *= V2[i].first + 2 * V2[i].second;
			sum %= mod;
			sum2 *= V2[i].second;
			sum2 %= mod;
		}
		sum = sum*modpow(2, m) % mod;
		int T = (sum + mod - sum2) % mod;
		sum2 = sum2*modpow(2, H-1) % mod;
		dp1[l][r] = T;
		dp2[l][r] = sum2;
//		cout << l << ' ' << r << ' ' << T << ' ' << sum2 << ' ' << H << endl;
	}
	else {
		int H = h[r + 1];
		if (l)H = max(H, h[l - 1]);
		int t = (modpow(2, r - l + 1) + mod - 2) % mod;
		int u = modpow(2, h[l]-H);
		dp1[l][r] = t;
		dp2[l][r] = u;
	}
}


signed main() {
	cin >> n;
	rep(i, n)cin >> h[i];
	
	/*
	int cnt = 0;
	rep(i, n - 1) {
		if (h[i]<h[i + 1] && h[i + 1]>h[i + 2]) {
			cnt += h[i + 1] - max(h[i], h[i + 2]);
			h[i + 1] = max(h[i], h[i + 2]);
		}
	}
	if (h[0] > h[1]) {
		cnt += h[0] - h[1];
		h[0] = h[1];
	}
	cnt %= mod;
	rep(i, n) {
		if (i)cout << ' '; cout << h[i];
	}cout << endl;
	*/

	rep(i, n)rep(j, n)dp1[i][j] = dp2[i][j]= -1;
	memo(0, n - 1);
	cout << (dp1[0][n - 1] + dp2[0][n - 1])%mod << endl;
}

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

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


Measured memory_bytes: 3048
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();
		
		if(a<b) {
			if(b<c) {
				if(b<c) {
					System.out.println(a + " " + b + " " + c);
				}
				
				else {
					System.out.println(a + " " + c + " " + b);
				}
			}else {
				System.out.println(c+ " " + a + " " + b);
			}
				
				
		}else {
			if(b<c) {
				if(c<a) {
					System.out.println(b + " " + c + " " + a);
				}
				
				else {
					System.out.println(b + " " + a + " " + c);
				}
			}else {
				System.out.println(c+ " " + b + " " + a);
		
			}

		}

	}
}



Measured memory_bytes: 26064
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
from operator import itemgetter
from heapq import heappush, heappop

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces


def dijkstra(s, n): # (始点, ノード数)
    dist = [inf] * n
    hq = [(0, s)] # (distance, node)
    dist[s] = 0
    seen = [False] * n # ノードが確定済みかどうか
    while hq:
        v = heappop(hq)[1] # ノードを pop する
        seen[v] = True
        for to, cost in adj[v]: # ノード v に隣接しているノードに対して
            if seen[to] == False and dist[v] + cost < dist[to]:
                dist[to] = dist[v] + cost
                heappush(hq, (dist[to], to))
    return dist

N = ni()
adj = [[] for _ in range(N)]
for _ in range(N-1):
    a, b, c = na()
    adj[a-1].append((b-1, c))
    adj[b-1].append((a-1, c))

Q, K = na()
ans = []
d = dijkstra(K-1, N)

for i in range(Q):
    x, y = na()
    x -= 1
    y -= 1
    ans.append(d[x] + d[y])

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



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

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

int main() {
    string S;
    cin >> S;
 
    // 後ろから解くかわりにすべての文字列を「左右反転」する
    reverse(S.begin(), S.end());
    for (int i = 0; i < 4; ++i) reverse(divide[i].begin(), divide[i].end());
    
    // 端から切っていく
    bool can = true;
    for (int i = 0; i < S.size();) {
        bool can2 = false; // 4 個の文字列たちどれかで divide できるか
        for (int j = 0; j < 4; ++j) {
            string d = divide[j];
            if (S.substr(i, d.size()) == d) { // d で divide できるか
                can2 = true;
                i += d.size(); // divide できたら i を進める
            }
        }
        if (!can2) { // divide できなかったら
            can = false;
            break;
        }
    }
    
    if (can) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define STEP 0.0005
// sort(a.begin(), a.end(), std::greater<int>());

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main()
{
    int n, m;
    cin >> n >> m;
    vector<string> a, b;
    rep(i, n)
    {
        string temp;
        cin >> temp;
        a.push_back(temp);
    }
    rep(i, m)
    {
        string temp;
        cin >> temp;
        b.push_back(temp);
    }
    rep(i, n - m + 1) //x
    {
        rep(j, n - m + 1) //y
        {
            if (a[i][j] == b[0][0])
            {
                rep(k, m) //x
                {
                    rep(l, m) //y
                    {

                        if (a[i + k][j + l] == b[k][l])
                        {
                            continue;
                        }
                        else
                            goto LOOPEND;
                    }
                }
                cout << "Yes" << endl;
                return 0;
            }
        LOOPEND:;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main() {
	char S[5];
	string ans = "Good";
	int i;

	cin >> S;
	for (i = 1; i < 4; i++) {
		if (S[i] == S[i - 1]) {
			ans = "Bad";
			break;
		}
	}
	cout << ans << endl;

	return 0;
}


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

int main(){
	int N;
	vector<int>L;
	cin >> N;

	for (int i = 0; i < N; i++){
		int tmp;
		cin >> tmp;
		L.push_back(tmp);
	}

	std::sort(L.begin(), L.end(), std::greater<int>());

	int sum = 0;

	for (int i = 0; i < N; i++){
		int tmp_i = L[i];

		for (int j = i + 1; j < N; j++){
			int tmp_j = L[j];
			int sub = abs(tmp_i - tmp_j);
			int add = tmp_i + tmp_j;
			for (int k = j + 1; k < N; k++){
				int tmp_k = L[k];
				
				if (sub >= tmp_k || tmp_k >= add){
					break;
				}

				sum++;
			}
		}
	}

	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)

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

	string s;
    long long sum=0;
    int l;

	cin >> s;
    l = s.length();
    
    for(int i=0; i < 1<< l-1; i++){
        int pre_i = 0;
        REP(j,l){
            if ((i>>j & 1) == 1 || j == l-1){
                sum += stoll(s.substr(pre_i,j - pre_i +1));
                pre_i = j+1;
            }
        }
    }
	cout << sum << "\n";
}

Measured memory_bytes: 256
#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 ll long long
#define pb(a) push_back(a)

ll mod = 1e9 + 7;

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

  int n, a, b;
  cin >> n >> a >> b;
  if(n == 1) cout << "Hello World" << endl;
  else cout << a + b << endl;
  return 0;
}


Measured memory_bytes: 892
N = int(input())
A = [0] + list(map(int, input().split())) + [0]
cost = [abs(A[i+1] - A[i]) for i in range(N+1)]
cost0 = sum(cost)

for i in range(1, N+1):
    if (A[i] - A[i-1]) * (A[i+1] - A[i]) > 0:
        print(cost0)
    elif (A[i-1] - A[i]) * (A[i+1] - A[i-1]) >= 0:
        print(cost0 - 2 * abs(A[i-1] - A[i]))
    else:
        print(cost0 - 2 * abs(A[i+1] - A[i]))

Measured memory_bytes: 14048
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <cmath>
using namespace std;

int main(int argc, const char * argv[]) {
  string s, t;
  cin >> s >> t;
  for(int i = 0; i < s.size(); i++){
    if(s.substr(i,s.size()-i) + s.substr(0,i) == t){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
//created by pyoxiao on 2020/04/04
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define CL(a, b) memset(a, b, sizeof(a))
using namespace std;
const int mod = 1e9 + 7;
LL fpow(LL a, LL b, LL p = mod){LL ans = 1; a %= p; while(b) {if(b & 1) ans = ans * a % p; b >>= 1; a = a * a % p;} return ans;}
LL gcd(LL a, LL b){return b == 0 ? a : gcd(b, a % b);}
LL n, k;
void solve() {
    scanf("%lld %lld", &n, &k);
    printf("%lld\n", min(n % k, k - (n % k)));
}
int main() {
    int T = 1;
    // scanf("%d", &T);
    while(T --) 
        solve();
    return 0;
}

Measured memory_bytes: 256
x, n = map(int, input().split())
li_p = list(map(int, input().split()))
li_p.sort()
i = 0
while True:
    a = x - i
    b = x + i
    if not a in li_p:
        print(a)
        break
    elif a in li_p and not b in li_p:
        print(b)
        break
    elif a in li_p and b in li_p:
        i += 1

Measured memory_bytes: 9124
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


void solve(long long n){
    i64 sum = 0;
    for(int i = 1; i <= n; ++i)
        if(i % 3 && i % 5)
            sum += i;
        cout << sum << endl;
}


signed main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3760
#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()
using i64 = int_fast64_t;
using P = pair<i64,i64>;

int main(){
    int N,K;
    cin >> N >> K;
    vector<int> w(N);
    int sum = 0;
    rep(i,N) cin >> w[i], sum += w[i];

    int ans = 1e9;
    int Max = sum+1, Min = 0;
    while(Max - Min > 1){
        int mid = (Max + Min) / 2;

        int P = 0, k = 0;
        int left = 0, right = 0;
        while(left < N){
            int p = 0;
            while(p + w[right] <= mid && right < N){
                p += w[right];
                right++;
            }
            if(left == right){
                k = 1e9;
                break;
            }
            left = right;
            P = max(P, p);
            k++;
        }
        if(k <= K) {
            ans = min(ans, P);
            Max = mid;
        } else {
            Min = mid;
        }
    }
    cout << ans << endl;
}



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

using namespace std;

const int Nmax = 2e5 + 10;
const int Mod = 1e9 + 7;
const int oo = 1e9;

char s[Nmax], t[Nmax];

int main()
{
/**
    #ifndef ONLINE_JUDGE
        ifstream cin("test.in");
        ofstream cout("test.out");
    #endif // ONLINE_JUDGE
*/

    cin >> s >> t;

    int ok = 1;
    for(int i = 0; s[i]; i++)
        if(s[i] != t[i])ok = 0;

    if(strlen(t) - 1 != strlen(s)) ok = 0;

    cout << (ok ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

#define int long long

const int INF = 1e18 + 3;

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

    int k, a, b, c;
    cin >> a >> b >> c >> k;
    if (a == b) {
    	cout << 0 << endl;
    	return 0;
    }
    k %= 120;
    while (k--) {
    	int na = b + c;
    	int nb = a + c;
    	int nc = a + b;
    	a = na;
    	b = nb;
    	c = nc;
    	int t = min({a, b, c});
    	a -= t;
    	b -= t;
    	c -= t;
    	if (max({a, b, c}) > INF) {
    		cout << "Unfair" << endl;
    		return 0;
    	}
    }
    cout << a - b << endl;
}   

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int mod = 10000007;
const int inf = 1001001001;



int main(void) {
  int a,b,m;
  cin >> a >> b >> m;
  vi p(a);
  vi q(b);
  rep(i,a) cin >> p[i];
  rep(i,b) cin >> q[i];
  vi sum(m+1);
  rep(i,m){
    int aa,bb,cc;
    cin >> aa >> bb >> cc;
    aa--;
    bb--;
    sum[i] = p[aa]+q[bb]-cc;
  }
  
  
  
  
  
  sort(ALL(p));
  sort(ALL(q));
  sum[m] = p[0] + q[0];
  sort(ALL(sum));
  cout << sum[0] << endl;
  
  
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
long long knapsack(long long val[],long long we[] ,long long W,long n)
{
    long long dp[n+1][W+1];
    for(long long i=0;i<=n;i++)
    {
        for(long long w=0;w<=W;w++)
        {
            if(i==0||w==0)
                dp[i][w]=0;
            else if(val[i-1]<=w)
                dp[i][w]=max(dp[i-1][w],dp[i-1][w-val[i-1]]+we[i-1]);
            else
                dp[i][w]=dp[i-1][w];
        }
    }
    return dp[n][W];
}
int main()
{
    int n,w;
    cin>>n>>w;
   long long a[n];
    long long we[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        cin>>we[i];}
   cout<<knapsack(a,we,w,n)<<endl;
    return 0;
}



Measured memory_bytes: 79104
n = int(input())
ps = []
mis = []
for _ in input().split():
  item = int(_)
  if item >= 0:
    ps.append(item)
  else:
    mis.append(item)
  
mis.sort(reverse = True)
ps.sort()
if len(mis) == 0:
  mis = [ps[0]]
  ps = ps[1:]
if len(ps) == 0:
  ps = [mis[0]]
  mis = mis[1:]
print(sum(ps) - sum(mis))

pre = mis[0]
for p in ps[:len(ps) - 1]:
  print(pre, p)
  pre -= p
print(ps[-1], pre)
pre = ps[-1] - pre
for m in mis[1:]:
  print(pre, m)
  pre -= m




Measured memory_bytes: 14144
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = 2e9;
const int MAX_N = 1;

int main() {
  int D, N; cin >> D >> N;
  int ans = 1;
  for (int i = 0; i < D; i++) {
    ans *= 100;
  }
  if (N == 100) N++;
  ans *= N;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
object Main extends App {
  val inputs: Seq[String] = scala.io.Source.stdin.getLines().toList
  
  val tracker = inputs(0).split(" ").map(_.toInt)
  val a = tracker(0)
  val v = tracker(1)
  val runaway = inputs(1).split(" ").map(_.toInt)
  val b = runaway(0)
  val w = runaway(1)
  val t = inputs(2).toInt

  println(solve(a, v, b, w, t))

  private def solve(a: Int, v: Int, b: Int, w: Int, t: Int): String = {
    if(a < b) {
      val speedDiff = v - w
      val positionDiff = Math.abs(b - a)

      if(0 < speedDiff && (positionDiff / speedDiff.asInstanceOf[Double]) <= t) {
        return "YES"
      } else {
        return "NO"
      }
    } else {
      val speedDiff = v - w
      val positionDiff = Math.abs(a - b)

      if(0 < speedDiff && (positionDiff / speedDiff.asInstanceOf[Double]) <= t) {
        return "YES"
      } else {
        return "NO"
      }
    }
  }
}

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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descsort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main(void)
{
    string s;
    cin>>s;
    if(s.size()%2==1){cout<<"No"<<endl;return 0;}
    bool ok=true;
    rep(i,0,s.size()){
        if(i%2){
            if(s[i]!='i'){ok=false;break;}
        }else{
            if(s[i]!='h'){ok=false;break;}
        }
    }
    if(ok)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3588
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int INF=1e9;

int main(){
    int n;
    cin >> n;
    int v[n],c[n];
    for(int i=0;i<n;i++){
        cin >> v[i];
    }
    for(int i=0;i<n;i++){
        cin >> c[i];
    }
    int ans=0;
    for(int i=0;i<n;i++){
       int res=v[i]-c[i];
       if(res>0) ans+=res;
    }
    cout << ans << endl;
}

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

int main(){
  long long int a;
  long long int b;
  while(cin >> a >> b){
    int ans;
    bool p[1001001];
    int num[1000001];

    for(int i=0;i<=2*b;i++){
      if(a-b+i<2)num[i] = 0;
      else num[i] = 1<<30;
    }

    int N = (int)sqrt(a+b);
    for(int i=2;i<=N;i++)p[i] = true;
    
    int c = 2;
    while(c<=N){
      for(int i=2*c;i<=N;i+=c)p[i] = false;

      int s = (c-(a-b)%c)%c;
      for(int j=s;j<=2*b;j+=c){
	long long int tmp = a-b+j;
	if(num[j]){

	  int cnt = 0;
	  while(!(tmp%c)){
	    tmp /= c;
	    cnt++;
	  }

	  if(cnt){
	    if(num[j] < cnt)num[j] = 0;
	    else num[j] = cnt;
	  }
	}
      }

      while(!p[++c]);
    }

    ans = 0;
    for(int i=0;i<=2*b;i++){
      if(num[i])ans++;
    }

    printf("%d\n",ans);
  }
}

Measured memory_bytes: 5712
while True:
    h,w = [int(x) for x in input().split()]
    if h == 0 and w == 0:
        break

    for i in range(h):  
        for j in range(w):
            if i == 0 or i == h-1:
                print("#",end="")
            elif j == 0 or j == w-1:
                print("#",end="")
            else:
                print(".",end="")
        print("")
    print("")
    
    
        


Measured memory_bytes: 7016
#include <iostream>

int main(){
    int i, n[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    std::cin >> i;
    
    std::cout << n[i-1] << std::endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String S = sc.next();

		int ans = Integer.parseInt(S.replace("/", ""));

		if(ans <= 20190430){
			System.out.println("Heisei");
		}
		else{
			System.out.println("TBD");
		}
	}

}

Measured memory_bytes: 21716
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define MOD 1000000007
#define INF 1000000000000000000
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

int main()
{
	string s;
	cin >> s;
	for (int i = 1; i < 4; i++)
	{
		if(s[i] == s[i - 1])
		{
			cout << "Bad";
			return 0;
		}
	}
	cout << "Good";
}

Measured memory_bytes: 256
function Main(input) {
    input = input.split("\n")
    input = input.map(e=>e.split(" "))
    input = input.map(e=>e.map(f=>parseInt(f,10)))

    var result = input[1].reduce((pre,cur,idx,src)=>{
        var array = src.slice(idx,src.length)       
        var re = array.slice(1,array.length).reduce((prev,curr)=>{
            return prev+array[0]*curr;
        },0)
        return pre + re;
    },0)    
    console.log(result);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int N,count=0;
void dfs(long long,unsigned char);
int main(){
    cin>>N;
    dfs(0,0);
    cout<<count;
    return 0;
}
void dfs(long long nextNum,unsigned char flag357){
    if(nextNum<=N){
        if(flag357==07)    // 07 is BIN 111
            count++;
        dfs(nextNum*10+3,flag357|01); // BIN 001
        dfs(nextNum*10+5,flag357|02); // BIN 010
        dfs(nextNum*10+7,flag357|04); // BIN 100
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <sstream>
#include <string>

using namespace std;

int main()
{
    string str;
    std::cin >> str;
    std::cout << str.substr (0,4) << " ";
    std::cout << str.substr (4) << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

bool used[31][31];
int g[61][31];
const int dx[]={-1,1,0,0},dy[]={0,0,-1,1};
int main(){
    int w,h;
    while(cin>>w>>h,w|h){
        memset(used,0,sizeof(used));
        rep(i,2*h-1){
            if(i%2==0){
                rep(j,w-1) cin>>g[i][j];
            }
            else rep(j,w) cin>>g[i][j];
        }
        queue<pair<pint,int> > q;
        q.push({{0,0},1});
        used[0][0]=true;
        bool flag=false;
        while(!q.empty()){
            pair<pint,int> pi=q.front();q.pop();
            rep(i,4){
                int tx=pi.first.first+dx[i],ty=pi.first.second+dy[i];
                if(tx>=0&&ty>=0&&tx<w&&ty<h&&!used[ty][tx]&&
                (i==0&&g[ty*2][tx]==0||i==1&&g[ty*2][tx-1]==0||
                i==2&&g[ty*2+1][tx]==0||i==3&&g[ty*2-1][tx]==0)){
                    if(tx==w-1&&ty==h-1){
                        cout<<pi.second+1<<endl;
                        flag=true;
                    }
                    q.push({{tx,ty},pi.second+1});
                    used[ty][tx]=true;
                }
                if(flag) break;
            }
            if(flag) break;
        }
        if(!flag) cout<<0<<endl;
    }
    return 0;
}


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

int main () {
    string s, t;
    cin >> s >> t;
    int count = t.size();
    for (int i = 0; i <= s.size() - t.size(); i++) {
        int diff = 0;
        for (int k = 0; k < t.size(); k++) {
            if (t[k] != s[i + k]) {
                diff++;
            }
        }
        count = min(count, diff);
    }
    cout << count << endl;
} 

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

const int N=1e+5+5;
long long int cnt[N],S,a[N];
int n;

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		cnt[a[i]]++;
		S+=a[i];
	}
	int q;
	cin>>q;
	while(q--)
	{
		long long int b,c;
		cin>>b>>c;
		S-=cnt[b]*b;
		S+=cnt[b]*c;
		cnt[c]+=cnt[b];
		cnt[b]=0;
		cout<<S<<"\n";
	}
}



Measured memory_bytes: 5152
import sys
import math
import heapq
from collections import defaultdict, deque
from decimal import *
def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))
mod=1000000007

H,W,k=rm()
a=[list(input()) for i in range(H)]
ans=0
for h in range(1<<H):
    for w in range(1<<W):
        count=0
        for i in range(H):
            for j in range(W):
                if (a[i][j]!='#'):
                    continue
                if h>>i&1!=0 or w>>j&1!=0:
                    continue
                count+=1
        if count==k:
            ans+=1
print(ans)

Measured memory_bytes: 78976
// Copyright (C) 2017 Sayutin Dmitry.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.

#include <iostream>
#include <vector>
#include <stdint.h>
#include <algorithm>
#include <set>
#include <map>
#include <array>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <string>
#include <assert.h>
#include <iterator>
#include <cstdint>
#include <cinttypes>

using std::cin;
using std::cout;
using std::cerr;

using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;

using std::pair;
using std::make_pair;

using std::min;
using std::abs;
using std::max;

using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif

template <typename T>
T input() {
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e) {
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

#define SZ(vec)         int((vec).size())
#define ALL(data)       data.begin(),data.end()
#define RALL(data)      data.rbegin(),data.rend()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()

int main() {
    std::iostream::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    int n = input<int>();
    vector<char> in(n);
    for (int i = 0; i != n; ++i)
        in[i] = input<char>() == 'o'; // same.
    
    for (int fst = 0; fst <= 1; ++fst) // denote Sheep with 0 and Wolf with 1
        for (int snd = 0; snd <= 1; ++snd) {
            vector<char> ans(n);
            ans[0] = fst;
            ans[1] = snd;

            auto f = [](int x, char y) {
                if (y == (1 ^ 0))
                    return x;
                else
                    return 1 - x;
            };
            
            for (int i = 0; i != n; ++i) {
                // i, i + 1 => i + 2
                ans[(i + 2) % n] = f(ans[i], in[(i + 1) % n] ^ ans[(i + 1) % n]);
            }

            if (ans[0] == fst and ans[1] == snd) { // OK
                for (int i = 0; i != n; ++i)
                    cout << "SW"[(int)ans[i]];
                cout << "\n";
                return 0;
            }
        }
    cout << "-1\n";
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  int K;
  string s;
  cin >> K >> s;
  if(s.size()<=K){
  cout << s << endl;
  }
  else{
  for(int i = 0;i < K;i++){
  cout << s.at(i);
    if (i ==K-1)
      cout << "...";
  }
  }
}

Measured memory_bytes: 3632
#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<stack>
#include<sstream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=100000+10;
int a[N];
bool cmp(int a,int b){
    return a>b;
}
int main()
{
    int n,w;
    while(~scanf("%d%d",&n,&w)){
        int x,y,_max=0;

        for(int i=0;i<n;i++){
            scanf("%d%d",&x,&a[i]);
            _max=max(_max,x);
        }
        sort(a,a+n,cmp);
        int sum=0;
        for(int i=0;i<n;i++){
           if(_max>a[i]) break;
           sum++;
           w-=a[i];
           if(w<=0) break;
        }
        if(w>0) {
            sum+=w%_max==0?w/_max:w/_max+1;
        }
        printf("%d\n",sum);
    }

    return 0;
}


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

int main(){

	int w, n;
	int num[30] = { 0 };
	int a, b;
	char c;

	cin >> w;
	cin >> n;

	for (int i = 0; i<w; i++)
		num[i] = i + 1;

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

		cin >> a >> c >> b;


		int tmp = num[a-1];
		num[a-1] = num[b-1];
		num[b-1] = tmp;


	}


	for (int i = 0; i<w; i++)
		cout << num[i] << "\n";

	return 0;

}

Measured memory_bytes: 1160
#include<stdio.h>
int main(){
  int n,k,i,j,a,b,c,e,h,mi,min;
  while(scanf("%d %d",&n,&k),n||k){
  int m[100][100]={0};
    while(k--){
      if(scanf("%d",&a),a){
	scanf("%d %d %d",&b,&c,&e);
	b--;
	c--;
	if(m[b][c]>e||m[b][c]==0)m[b][c]=m[c][b]=e;
      }
      else{
	scanf("%d %d",&b,&c);
	b--;
	c--;
	int d[100]={0};
	char f[100]={0};
	mi=b;
	for(i=0;i<n;i++){
	  f[mi]=2;
	  for(j=0;j<n;j++){
	    if(m[mi][j]==0||f[j]==2)continue;
	    if(d[j]==0||d[j]>d[mi]+m[mi][j]){
	      d[j]=d[mi]+m[mi][j];
	      f[j]=1;
	    }
	  }
	  min=2100000000;
	  for(j=h=0;j<n;j++){
	    if(f[j]!=1)continue;
	    h=1;
	    if(min>d[j]){
	      min=d[j];
	      mi=j;
	    }
	  }
	  if(!h)break;
	}
	if(d[c])printf("%d\n",d[c]);
	else    printf("-1\n");
      }
    }
  }
  return 0;
}

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

int main() {
  int n, x, y;  
  cin >> n >> x >> y;
  int ml[100009];

  for (int i = 1; i < n; i++) {
    for (int j = i+1; j <= n; j++) {
      int len = min(
        min(
          abs(j - i),
          abs(x - i) + 1 + abs(j - y)
        ),
        abs(y - i) + 1 + abs(j - x)
      );
      ml[len]++;
    }
  }

  for (int k = 1; k < n; k++) {
    cout << ml[k] << endl;
  }
}

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

int main(){
  string n;
  cin >> n;
  string ans = "No";
  if (n.at(0) == n.at(1) && n.at(1) == n.at(2) || 
      n.at(1) == n.at(2) && n.at(2) == n.at(3)) ans = "Yes";
  cout << ans << endl;
}


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

long long a(long long n) {
	if (n == 1) {
		return 1;
	}
	else
	{
		return (1 + 2 * a(n / 2));
	}
}

int main()
{
	long long h;
	cin >> h;
	cout << a(h) << endl;
	return 0;
}

Measured memory_bytes: 256
K, N = map(int, input().split())
A = list(map(int, input().split()))
max_len = (K - A[-1]) + A[0]
now = A[0]
for i in range(1, N):
    now_len = A[i] - now
    if max_len < now_len:
        max_len = now_len
    now = A[i]
print(K - max_len)

Measured memory_bytes: 26444
n = int(input())
au = list(map(int,input().split()))
ad = list(map(int,input().split()))

aur = 1
adl = 0
ans = sum(au[0:aur]) + sum(ad[adl:n])
nex = sum(au[0:aur]) + sum(ad[adl:n])
for i in range(n-1):
    nex += au[aur]
    nex -= ad[adl]
    if nex > ans:
        ans = nex
    aur += 1
    adl += 1
print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr
#define INT_MAX_HALF (INT_MAX / 2)

typedef long long ll;

using namespace std;
//using namespace boost::multiprec



int main(){

    int n,m,p;
    cin >> n >> m >> p;

    vector<pair<pair<int,int>, int>> edge;
    vector<vector<int>> edge2(n + 1);
    vector<vector<int>> step(n + 1, vector<int>(n + 1, INT_MAX / 2));

    rep(i,m){
        int a, b, c;
        cin >> a >> b >> c;

        edge.pback(mpair(mpair(a, b), -1 * c + p));
        edge2[a].pback(b);
    }

    vector<int> distance(n + 1, INT_MAX / 2);
    vector<int> prev(n + 1, -1);

    distance[1] = 0;

    for(int i = 1; i < n; i++){

        rep(j, edge.size()){

            int u = edge[j].first.first;
            int v = edge[j].first.second;
            int l = edge[j].second;

            if(distance[v] > distance[u] + l){
                distance[v] = distance[u] + l;
                prev[v] = u;
            }
        }
    }

    bool cycle = false;

    for(int k = 1; k <= n; k++){

        priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq;

        pq.push(mpair(0, k));

        while(!pq.empty()){

            int d = pq.top().first;
            int node = pq.top().second;

            //cerr << d << " " << node << endl;

            if(step[k][node] > d){
                step[k][node] = d;
                rep(i, edge2[node].size()){
                    pq.push(mpair(d + 1, edge2[node][i]));
                }
            }

            pq.pop();
        }

    }

    rep(i, edge.size()){
        int u = edge[i].first.first;
        int v = edge[i].first.second;
        int l = edge[i].second;

        if(distance[v] > distance[u] + l){
            if(step[1][u] != INT_MAX_HALF && step[v][n] != INT_MAX_HALF){
                cycle = true;
                break;
            }
        }
    }

    if(cycle){
        cout << -1 << endl;
    }else{
        int ans = 0;
        if(distance[n] < 0){
            ans = -1 * distance[n]; 
        }

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

Measured memory_bytes: 27008
import java.util.Scanner;
import java.util.Stack;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		Stack<Character> q;
		String input = "";
		while (scanner.hasNext()) {
			input = scanner.nextLine();
			if (input.equals(".")) {
				break;
			}
			q = new Stack<Character>();
			boolean badFormat = false;
			char[] ch = input.toCharArray();
			int i = 0;
			while (i < ch.length) {
				char c = ch[i];
				switch (c) {
				case '(':
				case '[':
					q.push(c);
					break;
				case ')':
					if (!q.isEmpty()) {
						if (q.peek() == '(') {
							q.pop();
						} else {
							badFormat = true;
						}
					} else {
						badFormat = true;
					}
					break;
				case ']':
					if (!q.isEmpty()) {
						if (q.peek() == '[') {
							q.pop();
						} else {
							badFormat = true;
						}
					} else {
						badFormat = true;
					}
					break;
				default:
					break;
				}
				i++;
			}
			if (q.isEmpty() && !badFormat) {
				System.out.println("yes");
			} else {
				System.out.println("no");
			}
		}
	}
}

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

int main(){
  int H,W;
  cin>>H>>W;
  vector<vector<char>> data(H,vector<char>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>data.at(i).at(j);
    }
  }
  vector<bool> row(H,false);
  vector<bool> col(W,false);
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(data.at(i).at(j)=='#'){
        row.at(i)=true;
        col.at(j)=true;
      }
    }
  }
  
  for(int i=0;i<H;i++){
    if(row.at(i)==true){
      for(int j=0;j<W;j++){
        if(col.at(j)==true){
          cout<<data.at(i).at(j);
        }
      }
      cout<<endl;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#define MAX_N 20
using namespace std;

void swap(double &x,double &y){
	double t;
	t=x;
	x=y;
	y=t;
}

double cut4(double x){
	double temp=x*1000;
	temp=(temp+0.5)/1000;
	return temp;
}

int main(){
	int n;
	double x1,x2,x3,y1,y2,y3,px,py;
	double a,b,c,d,r;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x1>>y1>>x2>>y2>>x3>>y3;
		if(x1==x2){
			swap(x2,x3);
			swap(y2,y3);
		}else if(x2==x3){
			swap(x1,x2);
			swap(y1,y2);
		}
		a=(y2-y1)/(x2-x1);
		c=(y3-y2)/(x3-x2);
		if(a&&c){
			a=-1/a;
			c=-1/c;
			b=(y1+y2)/2-a*(x1+x2)/2;
			d=(y2+y3)/2-c*(x2+x3)/2;
			px=(b-d)/(c-a);
			py=(b*c-a*d)/(c-a);
		}else if(!a){
			c=-1/c;
			d=(y2+y3)/2-c*(x2+x3)/2;
			px=(x1+x2)/2;
			py=c*(x1+x2)/2+d;
		}else if(!c){
			a=-1/a;
			b=(y1+y2)/2-a*(x1+x2)/2;
			px=(x2+x3)/2;
			py=a*(x2+x3)/2+b;
		}

		r=sqrt((px-x1)*(px-x1)+(py-y1)*(py-y1));
//		px=(px==0?0.000:px);
//		py=(py==0?0.000:py);
		printf("%.3lf %.3lf %.3lf\n",px,py,r);
	}
	return 0;
}

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

int n;
vector<int> h;
vector<int> DP;

int main()
{
	cin >> n;
	h.resize(n + 1);
	for (int i = 1; i < n+1; i++)
		cin >> h[i];

	DP.resize(n + 1);

	// can reach n, n+1; DP[n] = 0
	DP[n] = 0;
	DP[n - 1] = abs(h[n] - h[n - 1]);
	for (int i = n - 2; i >= 1; i--)
	{
		DP[i] = min(DP[i + 2] + abs(h[i + 2] - h[i]), DP[i + 1] + abs(h[i + 1] - h[i]));
	}
	cout << DP[1] << endl;
}

Measured memory_bytes: 3992
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define maxn 3003
#include <bits/stdc++.h>
using namespace std;

ll px, py, res;
priority_queue<ll> pq, col;
vector<ll> vx, vy;

int main() {
    ll n1, n2, n3;
    cin >> px >> py >> n1 >> n2 >> n3;
    for(int i=1;i<=n1;i++){
        ll x;
        cin >> x;
        vx.pb(x);
    }
    for(int i=1;i<=n2;i++){
        ll x;
        cin >> x;
        vy.pb(x);
    }
    sort(vx.rbegin(), vx.rend());
    sort(vy.rbegin(), vy.rend());
    for(int i=0;i<min(px, n1);i++){
        pq.push(-vx[i]);
    }
    for(int i=0;i<min(py, n2);i++){
        pq.push(-vy[i]);
    }
    for(int i=1;i<=n3;i++){
        ll x;
        cin >> x;
        col.push(x);
    }
    ll temp;
    temp = max(0LL, px - n1);
    while(temp--){
        res += col.top();
        col.pop();
    }
    temp = max(0LL, py - n2);
    while(temp--){
        res += col.top();
        col.pop();
    }

    while(!pq.empty() && !col.empty()){
        ll x = -pq.top();
        if(x >= col.top()) break;
        pq.pop();
        res += col.top();
        col.pop();
    }
    while(!pq.empty()){
        res += -pq.top();
        pq.pop();
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 4976