akhauriyash/Code-Regression huggingface dataset:
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve

int main(int argc, char const* argv[])
{
  int n;
  vector<int> vec;
  while(cin >> n){
    if(n != 0)vec.pb(n);
    else{
      cout << vec[vec.size() - 1] << endl;
      vec.pop_back();
    }
  }
	return 0;
}



Measured memory_bytes: 3116
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
# mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

a = inp()
b = inp()
l = [1, 2, 3]
l.remove(a)
l.remove(b)
print(l[0])



Measured memory_bytes: 74424
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
int main(void){
    // Your code here!
 int a,b,c,k;
 cin >> a >> b >> c >> k;
 while(b<=a && k>0)
 {
  b*=2;
  k--;
 }
 while(c<=b && k>0)
 {
  c*=2;
  k--;
 }
 if(b>a && c>b)
 cout << "Yes";
 else
 cout << "No";
 return 0;
}

Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int main(){
	int a,b;
for(int j = 1; j<10; j++){
	a = j;
	
	for(int i = 1; i<10; i++){
		b = i;
		
		cout << a << "x" << b << "=" << a*b << endl;
		

	}
}
}

Measured memory_bytes: 1116
<?php
while (true) {
    list($height, $width) = getInputExplodeBySpaces();
    
    if ($height == 0 && $width == 0) {
       break;
    }
    
    $rectangle = new Rectangle($height, $width);
    $rectangleParts = $rectangle->setRectangleParts();

    echo $rectangle->mergeRectangleParts($rectangleParts);
}
 
function getInputExplodeBySpaces()
{
    return explode(' ', trim(fgets(STDIN)));
}
  
class Rectangle
{
    public $height;
    public $width;
    public $hashSymbol  = '#';
    
    public function __construct($height, $width)
    {
        $this->height = $height;
        $this->width  = $width;
    }

    public function setRectangleParts()
    {
        for ($i = 0; $i < $this->height; $i++) {
            for($j = 0; $j < $this->width; $j++) {
                $rectangleParts[$i][$j] = $this->hashSymbol;
            }
        }
        return $rectangleParts;
    }
    
    public function mergeRectangleParts($rectangleParts)
    {
        for ($i = 0; $i < $this->height; $i++) {
            $lines[] = implode($rectangleParts[$i]).PHP_EOL;
        }
        return implode($lines).PHP_EOL;
    }
}

Measured memory_bytes: 19048
#include <iostream>
#include <algorithm>
using namespace std;
#define MAX 100

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

int G[MAX+2][MAX+2], m, n;

bool dfs(int D[MAX+2][MAX+2], int x, int y, int num){
	if(x*y==0 || x==(m+1) || y==(n+1) ) return true;
	if(G[x][y] == 1 && num==0)  return false;
	if(D[x][y] >= num+1)  return false;
	D[x][y] = num+1;
	for(int r=0; r<4; r++){
		if(dfs(D, x+dx[r], y+dy[r], (G[x][y]==0||G[x+dx[r]][y+dy[r]]==1)?(num):(num-1))){
			return true;
		}
	}
	return false;
}


int main(void){
	while(cin>>m>>n, m){
		int sx,sy;
		char c;
		for(int i=1; i<=n; i++){
			for(int j=1; j<=m; j++){
				cin >> c;
				if(c == '&'){
					G[j][i] = 0;
					sx = j;
					sy = i;
				}else if(c=='#'){
					G[j][i] = 1;
				}else{
					G[j][i] = 0;
				}
			}
		}
		for(int i=0; i<100; i++){
			int D[MAX+2][MAX+2]={0};
			if(dfs(D,sx,sy,i)){
				cout << i <<endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int N = 37, C[100][100];
int main() {
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++)C[i][j] = (N + 2) +i*N + j;
	}
	cout << N*(N + 1) + 1 << " " << N + 1 << endl;
	cout << "1"; for (int i = 0; i < N; i++)cout << " " << i + 2; cout << endl;
	for (int i = 0; i < N; i++) {
		cout << "1"; for (int j = 0; j < N; j++)cout << " " << C[i][j]; cout << endl;
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cout << i + 2;
			for (int k = 0; k < N; k++) {
				cout << " " << C[k][(j + k*i) % N];
			}
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int sx = sc.nextInt();
		int sy = sc.nextInt();
		int tx = sc.nextInt();
		int ty = sc.nextInt();
		for (int i = 0; i < ty - sy; i++) {
			System.out.print("U");
		}
		for (int i = 0; i < tx - sx; i++) {
			System.out.print("R");
		}
		for (int i = 0; i < ty - sy; i++) {
			System.out.print("D");
		}
		for (int i = 0; i < tx - sx; i++) {
			System.out.print("L");
		}
		System.out.print("L");
		for (int i = 0; i < ty - sy + 1; i++) {
			System.out.print("U");
		}
		for (int i = 0; i < tx - sx + 1; i++) {
			System.out.print("R");
		}
		System.out.print("D");
		System.out.print("R");
		for (int i = 0; i < ty - sy + 1; i++) {
			System.out.print("D");
		}
		for (int i = 0; i < tx - sx + 1; i++) {
			System.out.print("L");
		}
		System.out.print("U");
	}
}

Measured memory_bytes: 24896
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define vint vector<int>
#define pri_que priority_queue
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

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

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

        //if(i<6) cout<<0<<endl;

        int res=0;

        for(int x=1; x*x<n; x++){
            //for(int y=1; y*y<n-x*x; y++){
            for(int y=x; y*y<n-x*x; y++){
                //for(int z=1; z*z<n-x*x-y*y; z++){
                for(int z=y; z*z<n-x*x-y*y; z++){
                    if((x*x+y*y+z*z+x*y+y*z+z*x)==i){
                        set<int> set;
                        //if(i==6) cout<<x<<' '<<y<<' '<<z<<endl;
                        set.insert(x); set.insert(y); set.insert(z);
                        int diff=set.size();
                        if(diff==3) res+=6;
                        else if(diff==2) res+=3;
                        else if(diff==1) res+=1;
                        else res=0;
                        //goto end;
                    }
                }
            }
        }
        //end:
            cout<<res<<endl;
    }
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,x; cin>>a>>b>>x;
    if (a<=x && x<=a+b){
        cout<<"YES\n";
    }else{
        cout<<"NO\n";
    }
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
N,X,Y=map(int,input().split())
X-=1
Y-=1

ans=[0]*N
for n in range(N-1):
    for tgt in range(n+1,N):
        temp=min(abs(tgt-n),abs(n-X)+abs(Y-tgt)+1)
        #print(n,tgt,temp)
        ans[temp]+=1


for a in ans[1:]:
    print(a)


Measured memory_bytes: 46172
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);let input_i=-1;const tn=():number=>{input_i++;return Number(input[input_i])};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{input_i++;return String(input[input_i])};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{const t=[...ar];return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{const t=[...ar];return t.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1]}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const deduplicate=(a:any[]):any[]=>{return Array.from(new Set(a))};
const main=()=>{
  let [n,m]=tnn(2),st=[]
  for(let i=0;i<m;i++){
    let h=tn()
    st.push(tnn(h))
  }
  let p=tnn(m),c=0
  for(let i=0;i<(1<<n);i++){
    let bit=i.toString(2),f=true
    for(let j=0;j<st.length;j++){
      let on=0
      for(let k=0;k<st[j].length;k++){
        if(i & 1<<st[j][k]-1)on++
      }
      if(on%2!=p[j])f=false
    }
    if(f)c++
  }
  to(c)
}
main()


Measured memory_bytes: 7612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    vector<int> v;
    v.push_back(abs(a-b));
    v.push_back(abs(b-c));
    v.push_back(abs(c-a));
    sort(v.begin(), v.end());
    cout << v[0] + v[1] << endl;
    return 0;
}

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

using namespace std;

int main() {
  int c = 1;
  string n;
  cin >> n;
  for (int i = 0; i < (int)n.size()-1; ++i) {
    c = n[i] == n[i+1] ? c + 1 : 1;
    if (c == 3) break;
  }
  cout << (c == 3 ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define EPS 1e-8
using namespace std;
typedef vector <double> vec;
typedef vector <vec> mat;

vec gauss(const mat& A,const vec&b){
  int n=A.size();
  mat B(n,vec(n+1));
  
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++) B[i][j]=A[i][j];

  for(int i=0;i<n;i++)B[i][n]=b[i];

  for(int i=0;i<n;i++){
    int pivot=i;
    for(int j=i;j<n;j++){
      if(abs(B[j][i])>abs(B[pivot][i]))pivot=j;
    }
    swap(B[i],B[pivot]);
    if(abs(B[i][i])<EPS)return vec();
    
    for(int j=i+1;j<=n;j++) B[i][j]/=B[i][i];
    for(int j=0;j<n;j++){
      if(i!=j){
	for(int k=i+1;k<=n;k++)B[j][k]-=B[j][i]*B[i][k];
      }
    }
  }
    vec x(n);
    for(int i=0;i<n;i++) x[i]=B[i][n];
    return x;
}



int main(){
  while(1){
    mat A(2,vec(2));
    vec b(2);
    if(!(cin>>A[0][0]))break;
    cin>>A[0][1]>>b[0];
    cin>>A[1][0]>>A[1][1]>>b[1];
    vec ans=gauss(A,b);
    printf("%.3f %.3f\n",ans[0],ans[1]);
  }
  return 0;
}

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

using namespace std;
using int64 = long;

// nCr = n! / (n-r)!r!
int64 nCr(int64 n, int64 r) {
    if (n <= r) return 1;
    __int128 nn = 1;
    __int128 rr = 1;
    for (__int128 i=0; i<r; i++) {
        nn *= n - i;
        rr *= i+1;
    }
    return nn / rr;
}

int main () {
    int n,p;
    cin >> n >> p;
    vector a(n,0);
    for (int i=0; i<n; i++) cin >> a[i];

    vector cnt(2,0);
    for (const auto &item : a) cnt[item%2]++;

    int64 ans = (1LL << cnt[0]);
    int64 tmp = 0;
    for (int64 i=p; i<=cnt[1]; i+=2) tmp += nCr(cnt[1], i);
    ans *= tmp;

    cout << ans << endl;
}

Measured memory_bytes: 3132
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

int main(){
  char alpha;
  cin >> alpha;
  string ans;
  if('a'<= alpha && alpha<='z') ans="a";
  else ans="A";

  cout << ans << endl;

  return 0;
}


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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    map<string, int> cnt;
    rep(i, n) {
        string s;
        cin >> s;
        cnt[s]++;
    }
    for (string i : { "AC", "WA", "TLE", "RE" }) {
        cout << i << " x " << cnt[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3640
//Wizard in Maze 

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define YN(flag) (flag?"Yes":"No")
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

int h,w,ch,cw,dh,dw;

bool onboard(int a,int b){
    if(a<0||a>=h||b<0||b>=w)return false;
    else return true;
}

signed main (){
    cin>>h>>w>>ch>>cw>>dh>>dw;
    ch--,cw--,dh--,dw--;
    vecrep(h,a,string);
    int dx[4]={1,0,-1,0};
    int dy[4]={0,1,0,-1};
    int ddx[5]={-2,-1,0,1,2};
    int ddy[5]={-2,-1,0,1,2};

    deque<P>q;
    vector<vector<int>>dist(h,vector<int>(w,inf));
    vector<vector<int>>seen(h,vector<int>(w,0));

    q.push_front(mp(ch,cw));
    dist[ch][cw]=0;
    seen[ch][cw]=2;

    while(!q.empty()){
        P t = q.front();
        q.pop_front();
        rep(i,0,4){
            if(!onboard(t.first+dy[i],t.second+dx[i]))continue;
            if(a[t.first+dy[i]][t.second+dx[i]]=='#'||seen[t.first+dy[i]][t.second+dx[i]]==2)continue;
            seen[t.first+dy[i]][t.second+dx[i]]=2;
            dist[t.first+dy[i]][t.second+dx[i]]=min(dist[t.first][t.second],dist[t.first+dy[i]][t.second+dx[i]]);
            q.push_front(mp(t.first+dy[i],t.second+dx[i]));
        }
        rep(i,0,5)rep(j,0,5){
            if(!onboard(t.first+ddy[i],t.second+ddx[j]))continue;
            if(a[t.first+ddy[i]][t.second+ddx[j]]=='#'||seen[t.first+ddy[i]][t.second+ddx[j]]==1||seen[t.first+ddy[i]][t.second+ddx[j]]==2)continue;
            seen[t.first+ddy[i]][t.second+ddx[j]]=1;
            dist[t.first+ddy[i]][t.second+ddx[j]]=dist[t.first][t.second]+1;
            q.push_back(mp(t.first+ddy[i],t.second+ddx[j]));
        }
    }
    if(dist[dh][dw]==inf)cout<<-1<<nnn;
    else cout<<dist[dh][dw]<<nnn;
    return 0;
}


Measured memory_bytes: 21340
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long int ll;
static const int MAX_N = 100000;

int W, H;
int N;
int X[MAX_N], Y[MAX_N];

int X2[MAX_N], Y2[MAX_N];

int main(){
	scanf("%d %d", &W, &H);
	scanf("%d", &N);
	for(int i = 0; i < N; i++){
		scanf("%d %d", &X[i], &Y[i]);
		X2[i] = X[i];
		Y2[i] = Y[i];
	}

	sort(X2, X2 + N);
	sort(Y2, Y2 + N);

	ll sumX = 0, sumY = 0;
	ll sumX1 = 0, sumY1 = 0;
	for(int i = 0; i < N; i++){
		sumX += 2LL * abs(X2[i] - X2[N / 2 - 1]);
		sumY += 2LL * abs(Y2[i] - Y2[N / 2 - 1]);
		sumX1 += 2LL * abs(X2[i] - X2[N / 2]);
		sumY1 += 2LL * abs(Y2[i] - Y2[N / 2]);
	}

	ll res = 1LL << 60;
	int resX, resY;
	for(int i = 0; i < N; i++){
		ll sum = 0;
		int X_, Y_;
		if(N % 2 == 0){
			if(X[i] <= X2[N / 2 - 1]){
				X_ = X2[N / 2];
				sum += sumX1;
			}else{
				X_ = X2[N / 2 - 1];
				sum += sumX;
			}
			if(Y[i] <= Y2[N / 2 - 1]){
				Y_ = Y2[N / 2];
				sum += sumY1;
			}else{
				Y_ = Y2[N / 2 - 1];
				sum += sumY;
			}
		}else{
			sum += sumX1 + sumY1;
			X_ = X2[N / 2];
			Y_ = Y2[N / 2];
		}
		sum -= abs(X[i] - X_) + abs(Y[i] - Y_);
		if(sum == res){
			if(X_ < resX || (X_ == resX && Y_ < resY)){
				resX = X_;
				resY = Y_;
			}
		}else if(sum < res){
			res = sum;
			resX = X_;
			resY = Y_;
		}
	}
	printf("%lld\n", res);
	printf("%d %d\n", resX, resY);
	return 0;
}



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

using namespace std;

#define EPS 1e-10
#define INF 1e9

struct sphere {
  double x,y,z,r;
};

bool eq(double a,double b) {
  return fabs(a-b)<EPS;
}

double f(double a) { return a*a; }

double dist(sphere a,sphere b) {
  double d=sqrt(f(a.x-b.x)+f(a.y-b.y)+f(a.z-b.z));
  if(d<=a.r+b.r) return 0;
  return d-(a.r+b.r);
}

template <typename T> 
T prim(vector<vector<pair<int, T> > > G) {
	T cost = 0;
	const int N = G.size();
	vector<bool> used(G.size());
	priority_queue<pair<T, int>, vector<pair<T, int> >, greater<pair<T, int> > > pq;
	pq.push(make_pair(0, 0));
	while (!pq.empty()) {
		pair<T, int> p = pq.top(); pq.pop();
		int now = p.second;
		if (used[now]) continue;
		used[now] = true;
		cost += p.first;
		for (auto e : G[now])
			pq.push(make_pair(e.second, e.first));
	}
	return cost;
}

int main() {
  int n;
  while(cin >> n,n) {
    vector<sphere> s(n);
    for(auto &a:s) cin >> a.x >> a.y >> a.z >> a.r;
    vector<vector<pair<int,double> > > G(n);
    for(int i=0;i<n;++i) {
      for(int j=i+1;j<n;++j) {
	double d=dist(s[i],s[j]);
	G[i].push_back(make_pair(j,d));
	G[j].push_back(make_pair(i,d));
      }
    }
    printf("%.3f\n",prim(G));
  }
  
  return 0;
}



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

typedef ostringstream OSS; typedef istringstream ISS;
typedef long long LL;
typedef pair<int, int> PII;  typedef pair<LL, LL> PLL;
typedef vector<int>    VI;   typedef vector<VI>   VVI;   typedef vector<VVI>   VVVI;
typedef vector<LL>     VLL;  typedef vector<VLL>  VVLL;  typedef vector<VVLL>  VVVLL;
typedef vector<double> VD;   typedef vector<VD>   VVD;   typedef vector<VVD>   VVVD;
typedef vector<string> VS;   typedef vector<VS>   VVS;   typedef vector<VVS>   VVVS;
typedef vector<bool>   VB;   typedef vector<VB>   VVB;   typedef vector<VVB>   VVVB;
typedef vector<PII>    VPII; typedef vector<VPII> VVPII; typedef vector<VVPII> VVVPII;
typedef vector<PLL>    VPLL; typedef vector<VPLL> VVPLL; typedef vector<VVPLL> VVVPLL;

typedef unsigned int  UI;
typedef vector<UI>    VUI;
typedef vector<VUI>   VVUI;

#define fst first
#define snd second
// #define Y first
// #define X second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x)  (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define RANGE(x, l, r) ((l) <= (x) && (x) <= (r))
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define rrep(i, N) for (int i = N - 1; i >= 0; i--)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define RREP(i, N, last) for (int i = (init - 1); i >= last; i--)
#define MAXUD(orig, target) orig = max(orig, target)
#define MINUD(orig, target) orig = min(orig, target)
#define DUMP(x) cerr << #x << " = " << (x) << endl

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a)   { OSS oss; oss << a; return oss.str(); };

template<typename T=int> inline void dump(vector<T> vs, bool ent=false) { rep(i, vs.size()) cout << vs[i] << (i+1==vs.size() ? '\n' : ' '); if (ent) cout << endl; }
template<typename T = int> inline void dump(vector<vector<T>> vs, bool ent=false) { rep(i, vs.size()) dump<T>(vs[i]); if (ent) cout << endl; }

const int    INF  = 0x3f3f3f3f;
const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
const int    DX[] = {1,  0, -1, 0};
const int    DY[] = {0, -1,  0, 1};
const double EPS  = 1e-12;
// const double PI   = acos(-1.0);

template<typename T = int> inline T in() { T x; cin >> x; return x; }
template<typename T = int> inline vector<T> in(int n) { vector<T> xs(n); rep(i, n) cin >> xs[i]; return xs; }
template<typename T = int> inline vector<vector<T>> in(int n, int m) { vector<vector<T>> xs(n, vector<T>(m)); rep(i, n) rep(j, m) cin >> xs[i][j]; return xs; }

int main(void) {
    string s = in<string>();

    int cnt = 0;
    rep(i, s.size() - 1) {
        cnt += s[i] != s[i + 1];
    }

    cout << cnt << endl;

    return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <cstring> 
using namespace std;
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mpp make_pair
#define int long long int
#define F first
#define mem(a,b) memset(a,b,sizeof(a))
#define F first
#define S second
#define MOD 998244353
#define in_range(x, y, r, c) (x < r && y < c && x >= 0 && y >= 0)
#define MAXN 200008
#define MAXI 10000000000007

std::vector<pair<int, string>> v;
void func(string s, int last){
	if(s.length()==11)
		return;
	v.pb(make_pair(s.length(), s));
	if(last==0){
		func(s+"0", 0);
		func(s+"1", 1);
	}
	else if(last==9){
		func(s+"8", 8);
		func(s+"9", 9);
	}
	else{
		func(s+to_string(last-1), last-1);
		func(s+to_string(last), last);
		func(s+to_string(last+1), last+1);
	}
}
 
signed main(){
 
    fast;
    
    #ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    
    int k, i;
    cin>>k;
    for(i=1;i<=9;i++){
    	func(to_string(i), i);
    }
    sort(v.begin(), v.end());
    //cout<<v.size()<<endl;
    cout<<v[k-1].second<<endl;
}

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

#define ll long long
#define pb push_back
#define eb emplace_back
//#define st first
#define sc second

using namespace std;

const ll mod = 1e9 + 7;
const int e = 1e6 + 69;
const int base = 311;

// dung inverse module de tinh nCk
// beginer 87
// mbeginer 161
// cach tao hoan vi tu n so : n*(n+1)/2;

//vector<pair<ll,ll>>adj[e];
//vector<ll>adj[e];

/*ll Pow(ll n, ll dem)
{
    if(dem == 0) return 1;
    if(dem == 1) return n ;
    ll t = Pow(n, dem/2);
    if(dem % 2 == 0) return (t*t);
    else return ((t * t) * n);
}*/

/*ll C(ll k, ll n)
{
    if(k == 0) return 1;
    if(n < k) return 0;
    return (gt[n]%mod * (igt[k]%mod * igt[n-k]%mod)%mod)%mod;
}*/

int main()
{
   ll a, b, c;
   cin >> a >> b >> c;
   cout << c <<" "<< a <<" "<< b;
}
/*

*/


Measured memory_bytes: 256
import sys
import socket

hostname = socket.gethostname()

if hostname == 'F451C':
    sys.stdin = open('a1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main_0():
    H, A = read_int_list()
    res = 0
    for i in range(10001):
      H = H - A
      res += 1
      if H <= 0:
        break
    print(res)


def main_1():
    H, A = read_int_list()
    res = H // A
    if H % A != 0:
      res += 1
    print(res)


def main():
    H, A = read_int_list()
    res = 0
    while H > 0:
      H -= A
      res += 1
    print(res)

main()


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int x,a,b;
  cin>>x>>a>>b;
  if(abs(x-a)<abs(x-b)){
    cout<<"A"<<endl;
  }else{
    cout<<"B"<<endl;
  }
  return 0;
}


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

const int N = 1e5+7;
vector<int> cld[N];

int dfs(int u) {

    vector<int> dep;
    for (int v: cld[u])     dep.push_back(dfs(v));
    sort(dep.rbegin(), dep.rend());

    int ans = 0;
    for (int i=0; i<dep.size(); i++)    ans = max(ans, dep[i]+i+1);
    return ans;
}

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

    int n;
    cin>>n;

    for (int i=2; i<=n; i++) {
        int p;
        cin>>p;
        cld[p].push_back(i);
    }

    cout<<dfs(1)<<endl;
}


Measured memory_bytes: 19916
#include <bits/stdc++.h>
#define mp make_pair
#define ff first
#define ss second
 
using namespace std;
using vi=vector<int>;
using pii=pair<int, int>;
using ull=unsigned long long;
using ll=long long;
 
int main()
{
	unsigned long n; cin >> n;

	int aux = sqrt(n);
	unsigned long ans = 999999999999;

	for (int i = 1; i <= aux; i++)
	{
		if (i*(n/i) == n)
			ans = min(ans, (i + (n/i) - 2));
	}

	cout << ans << "\n";
}


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


int main()
{
    int n;
    cin>>n;
    long long int s=0;
    for(int i=1;i<=n;i++){
        if(i%3!=0 && i%5!=0){
            s=s+i;
        }
    }
    cout<<s<<endl;
    
    
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	int n,m; cin>>n>>m;
	VL a(n),b(n); ll ans=0;
	rep(i,n) cin>>a[i],a[i]%=m;
	rep(i,n){
		if(i)	b[i] = (b[i-1]+a[i])%m;
		else b[i] = a[i];
		if(b[i]==0) ans++;
		cerr<<b[i]<<' ';
	}
	cerr<<endl;
	sort(ALL(b));
	ll cnt=1;
	reps(i,n){
		if(b[i]==b[i-1]) cnt++;
		else{
			if(cnt>1) ans+=cnt*(cnt-1)/2;
			cnt=1;
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int n,t;
    cin>>n>>t;
    int ans=10000;
    
    for(int i = 0; i < n; i++)
    {
        int c,tt;
        cin>>c>>tt;
        if(tt<=t)
        {
            ans=min(ans,c);
        }
    }
    if(ans==10000) cout<<"TLE"<<endl;
    else cout<<ans<<endl;
 
    return 0;
}

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

using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#define int  long long int
	#define pb push_back
	#define fe first
	#define ld long double
 	#define lb lower_bound 
	#define ub upper_bound
	#define pii pair<pair<int,int>,pair<int,int> >
	#define se second
	#define endl "\n"
	#define pi pair<int, int>
	#define mi          map<int,int>
	#define mii         map<pi,int>
	#define vi vector<int> 
	#define vvi vector<vi>
	#define bs   binary_search
	#define rep(i,a,b) for(int i=a;i<b;i++)
	#define rep1(i,a,b) for(int i=a;i<=b;i++)	
	#define all(c) (c).begin(),(c).end()
	#define sz(x)       (int)x.size() 
	#define PI 3.14159265358979323846
	
	 const int N =3e5+5;
	 const int lg=20;
	
	 int mod= 1e9+7;
	 int dx[4]={0,0,+1,-1};
	 int dy[4]={+1,-1,0,0};  
	 
	 
	int po(int a, int b) {
		a %= mod;
		int res = 1;
		while (b > 0) {
			if (b & 1)
				res = (res * a) % mod;
			a =(a*a) % mod;
			b >>= 1;
		}
		 return res;	
	   }   
	   
mi mp;	   


void solve() {
	  
	  int n;
	  cin>>n;
	  vi a(n,0),b(n,0);
	  rep(i,0,n) {
		    cin>>a[i]>>b[i];
		  }
		  
		  sort(all(a));
		  sort(all(b));
		  
		  int x=0,y=0;
		  
		  if(n%2==1) {
			    x=a[n/2];
			    y=b[n/2];
			  }
		  else {
			     x=a[n/2-1]+a[n/2];
			     y=b[n/2-1]+b[n/2];
			  }	  
			  
			  cout<<y-x+1<<endl;		    
			  
		  } 
 
int32_t main() {
	cool;
	int t=1;	
	   //~ cin>>t;
	while(t--)
	   solve();		   
	   
	   return 0;	   
}


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

const long long MOD = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long n; cin >> n;
    long long ans = 1;
    long long x[3] = {0, 0, 0};
    for(int i = 0; i < n; i++){
        long long a;
        cin >> a;
        int cnt = 0;
        for(int j = 0; j < 3; j++) if(x[j] == a) cnt++;
        ans = (ans * cnt) %MOD;
        if(x[0] == a) x[0]++;
        else if(x[1] == a) x[1]++;
        else x[2]++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
ll N;
  cin >>N;
  string S;
  cin >>S;
  vl vec(N);
  rep(i,N) {
if(S.at(i)=='E') {
vec.at(i)=0;
}
    else {
      vec.at(i)=1;
    }
  }
  
  //sumofeast
  
  vl sume(N+1);
  sume.at(0)=0;
  vl sumw(N+1);
  sumw.at(0)=0;
  repl(i,1,N+1) {
    if(vec.at(i-1)==0) {
    sume.at(i)=sume.at(i-1)+1;
      sumw.at(i)=sumw.at(i-1);
    }
    else {
      sumw.at(i)=sumw.at(i-1)+1;
      sume.at(i)=sume.at(i-1);
    }
  }
  
  
  vl fin(N);
  rep(i,N) {
    fin.at(i)=sumw.at(i)-sumw.at(0)+sume.at(N)-sume.at(i+1);
  }
  
  
  sort(all(fin));
  cout<<fin.at(0)<<endl;
}
  
  
  
  
  

Measured memory_bytes: 9988
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;


int main() {
    ll n,x,index=0,cnt=0;
    cin >> n >> x;
    vector<ll>child(n);
    vector<ll>snake_child(n);
    rep(i, n)cin >> child[i];
    sort(all(child));
    rep(i, n) {
        if (x >= child[i])x -= child[i];
        else break;
        if (i != n - 1)snake_child[i] = child[i];
        else snake_child[i] = x+child[i];
    }
    rep(i, n)if (child[i] == snake_child[i])cnt++;
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include <utility>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(){
    int n,ans=0;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);

    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n-1) cin >> c[i];

    rep(i,n){
        ans+=b[a[i]-1];
        if(a[i+1] == a[i]+1 && i+1<n)
            ans+=c[a[i]-1];
    }

    cout << ans <<endl;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#define ll long long
#define inf 100005
#define mod 1000000007
using namespace  std;

vector<vector<ll>>g(inf);
vector<ll>indgree(inf);
vector<ll>dist(inf);
bool visted[inf];



int main(){
	string s;
	cin>>s;
	ll res=0;
	for(ll i=0;i<s.length();i++){
		res+=s[i]-'0';
	}
	if(res%9==0){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	//cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 7520
using System;

namespace Rounding
{
    class Program
    {
        static void Main(string[] args)
        {
            string w = Console.ReadLine();
            string[] wn = w.Split(' ');
            if(int.Parse(wn[0]) < int.Parse(wn[1]))
            {
                Console.WriteLine("0");
            }
            else
            {
                Console.WriteLine("10");
            }

        }
    }
}


Measured memory_bytes: 11092
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rep3(var, min, max) for (ll (var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll (var) = (max) - 1; (var) + 1 > (min); --(var))
#define Mp(a,b) make_pair((a),(b))
#define F first
#define S second
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll MOD = 1e9 + 7;
ll INF =1e18;
int n;
V vec(1e7,-1);
int saiki(int k){//再帰関数でやってみた
    if(k==0)return 0;
    if(vec[k]!=-1)return vec[k];
    int temp=k;
    for(int i=1;i<=k;i*=6){
        chmin(temp,(saiki(k-i)+1));
    }
    for(int i=1;i<=k;i*=9){
        chmin(temp,(saiki(k-i)+1));
    }
    return vec[k]=temp;
}
int main() {
    cin>>n;
    cout<<saiki(n)<<endl;
}

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

using namespace std;
typedef vector<vector<bool> > matrix;
typedef pair<int,int> P;

matrix mult(const matrix &m, const matrix &n) {
  int size = m.size();
  matrix ans(size,vector<bool>(size, false));
  for (int x=0; x<size; x++)
    for (int y=0; y<size; y++)
      for (int i=0; i<size; i++)
	ans[x][y] = ans[x][y]||(m[i][y]&&n[x][i]);
  return ans;
}

matrix power(matrix m, int c) {
  int size = m.size();
  matrix ans(size, vector<bool>(size, false));
  for (int i=0; i<size; i++)
    ans[i][i] = true;
  for(; c!=0; c>>=1) {
    if ((c&1) == 1)
      ans = mult(ans, m);
    m = mult(m,m);
  }
  return ans;
}

int main() {
  int N,M,Z;

  while (cin >> N >> M >> Z, N) {
    vector<vector<int> > station(N, vector<int>(N, -1));
    matrix road(2*M, vector<bool>(2*M, false));
    vector<P> roadlist(2*M);

    for (int i=0; i<M; i++) {
      int s,d;
      cin >> s >> d;
      station[s-1][d-1] = i*2;
      station[d-1][s-1] = i*2+1;
      roadlist[i*2] = P(s,d);
      roadlist[i*2+1] = P(d,s);
    }

    for (int i=0; i<N; i++) {
      for (int j=0; j<N; j++) {
	int from,to;
	if((from = station[i][j]) != -1) {
	  for (int k=0; k<N; k++) {
	    if ((to = station[j][k]) != -1) {
	      road[from][to] = (i!=k);
	    }
	  }
	}
      }
    }

    bool flag = false;

    if (Z == 1) {
      flag = (station[0][N-1]!=-1);
    } else {    
      matrix fin(power(road,Z-1));
      for (int from=0; from<2*M; from++)
	for (int to=0; to<2*M; to++)
	  if (fin[from][to] &&
	      roadlist[from].first==1 && 
	      roadlist[to].second==N)
	    flag = true;
    }

    if (flag)
      cout << "yes" << endl;
    else
      cout << "no" << endl;      
  }
}

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

using namespace std;
using ll = long long;
using P = pair<int, int>;

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

const int mod = 1e9 + 7;

ll f(int x, int y) {
  if (x == 0 && y == 0) return 1;
  if (x < 0 && y < 0) return 0;
  return (f(x - 2, y - 1) % mod + f(x - 1, y - 2) % mod) % mod;
}

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

ll choose(ll n, ll k) {
  ll x = 1, y = 1;
  rep(i, k) {
    x = x * (n - i) % mod;
    y = y * (i + 1) % mod;
  }
  return x * modpow(y, mod - 2) % mod;
}

int main() {
  int x, y;
  cin >> x >> y;

  vector<P> move;
  rep(i, max(x, y)) {
    int a = i, b = y - 2 * a;
    if (a + 2 * b == x) {
      move.push_back({a, b});
    }
  }

  ll ans = 0;
  for (auto p : move) {
    ans = choose(p.first + p.second, p.first);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int N,i,j,sum=0;
    int d[100];
    
    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%d",&d[i]);
    }
    
    for(i = 0;i<N;i++){
        for(j=i+1;j<N;j++){
            sum+=d[i]*d[j];
        }
    }
    printf("%d\n",sum);
    return 0; 
}

Measured memory_bytes: 128
a,b,k = gets.chomp.split(" ").map(&:to_i)
ans = []
if b - a < 2 * k
    ans = (a..b).to_a
else
    for i in 0..k-1
        ans.push(a + i)
    end
    for i in b-k+1..b
        ans.push(i)
    end
end
print(ans.join(" "))

Measured memory_bytes: 1788
#pragma region head
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
#define double long double
typedef double ld;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);

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

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

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

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
#pragma endregion

signed main() {
  int N, A;
  cin >> N >> A;
  vector<int> x(N);
  rep(i, N) {
    cin >> x[i];
  }

  vector<vector<vector<int>>> dp(N + 1,
                                 vector<vector<int>>(N + 1, vector<int>(2501)));
  dp[0][0][0] = 1;
  rep(i, N) {
    rep(j, N + 1) {
      rep(k, 2501) {
        if (dp[i][j][k] == 0)
          continue;
        dp[i + 1][j][k] += dp[i][j][k];
        if (j + 1 <= N) {
          dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
        }
      }
    }
  }


  int ans = 0;
  repp(j, 1, N) {
    rep(k, 2501) {
      if (A * j == k)
        ans += dp[N][j][k];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 52224
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
//author wjl

using namespace std;
#define LL long long
#define Rint register int
#define U unsigned
#define forn(i,a,b) for(int i = a;i <= b;++i)
#define nfor(i,a,b) for(int i = a;i >= b;--i)
#define pii pair<int ,int>
#define MS0(X) memset(X,0,sizeof(X))
#define MSf(X) memset(X,false,sizeof(X))
#define MS1(X) memset(X,-1,sizeof(X))
#define BR printf("--------------------\n")
#define pb push_back
#define rep(i,a,b) for(Rint i=a;i<=b;++i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const double PI=atan(1.)*4.;
const int maxn=1e6+5;
const int inf = 0x3f3f3f3f;
const int mod=1e9+7;
const double e=2.71828182845904523536;
int dirx[8]={1,0,-1,0,1,-1,-1,1};
int diry[8]={0,1,0,-1,1,1,-1,-1};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    cout<<n*n;
    return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(ll i=x;i<y;i++)
#define frr(i,x,y) for(ll i=x-1;i>=y;i--)
#define inf 10000000000000000
const ll mod=1000000007;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b)
{
    ll ans=1;
    while(b!=0)
    {
        if(b&1)
        {
            ans*=a;
            ans%=mod;
        }
        a=(a*a);
        a%=mod;
        b>>=1;
    }
    return ans%mod;
}
void solve()
{
    ll n,h;
    cin>>n>>h;
    vector<PLL> arr(n);
    VL b;
    fr(i,0,n)
    {
        cin>>arr[i].F>>arr[i].S;
        b.pb(arr[i].S);
    }
    sort(ALL(arr));
    PLL tmp=arr[n-1];
    ll ct=0;
    sort(ALL(b));
    ll ans=mod;
    //ll ct=0;
    frr(i,n+1,0)
    {
        if(i)
        {
            h-=b[i-1];
            ct++;
        }
        ll cost=0;
        if(h>0)
        {
            cost=(h+tmp.F-1)/tmp.F;

        }
        ans=min(ans,ct+cost);
    }
    cout<<ans<<endl;
	return;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t=1;
    //cin>>t;
    while(t--)
    {
    	solve();
    }
	return 0;
}

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

using ll = long long int;
using P = pair<int, int>;
using P3 = pair<int,P>;
using PP = pair<P, P>;
constexpr int INF = 1<<29;

bool chmin(int &a, int b){
    if(a > b){
        a = b;
        return true;
    }
    return false;
}

bool solve(){
    int n, m;
    cin >> n >> m;
    if(n == 0) return false;
    vector<vector<int> > d(n, vector<int>(n,INF));
    for(int i=0;i<n;i++){
        d[i][i] = 0;
    }
    for(;m>0;m--){
        int x, a, b;
        cin >> x >> a >> b;
        a--; b--;
        if(x == 0){
            cout << (d[a][b] < INF ? d[a][b] : -1) << endl;
        }else{
            int c;
            cin >> c;
            if(chmin(d[a][b], c)){
                d[b][a] = c;
                for(int i=0;i<n;i++){
                    for(int j=0;j<n;j++){
                        chmin(d[i][j], d[i][a]+d[a][b]+d[b][j]);
                        chmin(d[i][j], d[i][b]+d[b][a]+d[a][j]);
                    }
                }
            }
        }
    }
    return true;
}

int main(){
    while(solve());
    return 0;
}



Measured memory_bytes: 3156
import scala.annotation.tailrec

object Main {
  val SEA = 0
  val LAND = 1

  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    while (true) {
      val Array(nx, ny) = readLine().split(" ").map(_.toInt)
      if (nx == 0 && ny == 0) return
      
      val list = for {
        yi <- 0 until ny
        (t, xi) <- readLine().split(" ").map(_.toInt).zipWithIndex
        if t == LAND
      } yield {
        (xi, yi)
      }

      println(count(list.toSet))
    }
  }

  @tailrec
  def count(lands: Set[(Int, Int)], n: Int = 0): Int = {
    if (lands.isEmpty) {
      n
    } else {
      count(lands &~ splitIsland(lands), n + 1)
    }
  }

  def splitIsland(lands: Set[(Int, Int)]): Set[(Int, Int)] = {
    import scala.collection.mutable

    val one = mutable.Set[(Int, Int)]()

    def eachPosition(x: Int, y: Int): Unit = {
      for {
        xi <- x - 1 to x + 1
        yi <- y - 1 to y + 1 if lands.contains((xi, yi)) && !one.contains((xi, yi))
      } {
        one += ((xi, yi))
        eachPosition(xi, yi)
      }
    }

    val (x, y) = lands.head
    eachPosition(x, y)
    one.toSet
  }
}



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

using namespace std;
#define int long long
const int maxn = 1000;
int seq[maxn];
int vis[maxn];
int maxv = -1e16;
int n;
int rec(int a,int num){
    int cnum = num;
    if (a > n){
        maxv = max(maxv,num);
        return 0;
    }
    if (vis[a]){
        rec(a + 1,num);
        return 0;
    }
    if (a > n / 2){
        if (seq[a] < 0) cnum -= seq[a];
        rec(a + 1,cnum);
        return 0;
    }
    if (a > n / 3){
        if (vis[a * 2]){
            if (seq[a] < 0) cnum -= seq[a];
            rec(a + 1,cnum);
            return 0;
        }
        if (seq[a] + seq[2 * a] < min(0ll,seq[2 * a])){
            cnum -= seq[a] + seq[2 * a];
            vis[2 * a] = 1;
            rec(a + 1, cnum);
            vis[2 * a] = 0;
            return 0;
        }else {
            rec(a + 1,num);
            return 0;
        }
    }
    rec(a + 1,num);

    for (int j = a;j <= n;j+= a){
        if (vis[j] == 0) cnum -= seq[j];
        vis[j] += 1;
    }
    rec(a + 1,cnum);

    for (int j = a;j <= n;j+= a){
        vis[j] -= 1;
    }
}
int32_t main(){

	//int n;
	cin >> n;
	int sum = 0;
	for (int i = 1;i <= n;i++ ){
        cin >> seq[i];
        sum += seq[i];
	}
	rec(1,sum);
	cout << maxv << endl;
	return 0;
}


Measured memory_bytes: 256