akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
using namespace std;
int quad[100];

void decToQuad(int n) {
    if (n == 0) { printf("0\n"); return; }
    int idx = 0;
    while (n > 0) {
        quad[idx++] = n%4;
        n /= 4;
    }
    for (int i = idx -1; i >= 0; i--) printf("%d", quad[i]);
    printf("\n");
}


int main()
{
    int n;
    for (; ;) {
        scanf("%d", &n);
        if (n == -1) break;
        decToQuad(n);
    }
    return 0;
}


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

int X[15][15];

int main(void){
    int N, D; cin >> N >> D;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < D; j++) {
            cin >> X[i][j];
        }
    }
    
    int ans = 0;
    
    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            long long sum = 0;
            for (int k = 0; k < D; k++) {
                sum += (X[i][k] - X[j][k])*(X[i][k] - X[j][k]);
            }
            int sqr = sqrt(sum);
            if (sum == sqr*sqr) ans++;
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
// ALDS1_1_A.cpp
// Insertion Sort
#include <cstdio>
#include <vector>
using namespace std;

void trace(vector<int> &nums, int n)
{
	for (int i = 0; i < n; i++) {
		if (i > 0) printf(" ");
		printf("%d", nums[i]);
	}
	printf("\n");
}

void myswap(int &a, int &b)
{
	int t = a;
	a = b;
	b = t;
}

void insertSort(vector<int> &nums, int n)
{
	for (int i = 1; i < n; i++) {
		int key = nums[i];
		int j = i - 1;
		while (j >= 0 && nums[j] > key) {
			nums[j + 1] = nums[j];
			j--;
		}
		nums[j + 1] = key;
		trace(nums, n);
	}
}

int main()
{
	int n;
	scanf("%d", &n);
	vector<int> nums(n);
	for (int i = 0; i < n; i++)
		scanf("%d", &nums[i]);
	trace(nums, n);
	insertSort(nums, n);
	return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
map<pair<int,int>,int> mapp;
int h,w,n,a[10];
int main()
{
	scanf("%d%d%d",&h,&w,&n);
	for(int i=1;i<=n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		for(int j=max(x-2,1);j<=min(h-2,x);j++)
		{
			for(int k=max(y-2,1);k<=min(w-2,y);k++)
			{
				mapp[pair<int,int>(j,k)]++;
			}
		}
	}
	int cnt=0;
	for(map<pair<int,int>,int>::iterator it=mapp.begin();it!=mapp.end();it++)
	{
		a[it->second]++;
		cnt++;
	}
	printf("%lld\n",(long long)(h-2)*(long long)(w-2)-cnt);
	for(int i=1;i<=9;i++) printf("%lld\n",(long long)a[i]);
	return 0;
}


Measured memory_bytes: 56448
#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSData *stdinData = [[NSFileHandle fileHandleWithStandardInput] availableData];
        NSString *s = [[NSString alloc] initWithData:stdinData encoding:NSUTF8StringEncoding];
        NSArray *arr = [s componentsSeparatedByString:@" "];
        NSInteger N = [[arr objectAtIndex:0] integerValue];
        
        NSString *answer = [NSString stringWithFormat:@"%ld",N/3];
        NSFileHandle *fileHandle = [NSFileHandle fileHandleWithStandardOutput];
        [fileHandle writeData:[answer dataUsingEncoding:NSUTF8StringEncoding]];
        [fileHandle writeData:[@"\n" dataUsingEncoding:NSUTF8StringEncoding]];
        [fileHandle closeFile];
    }
    
    return 0;
}


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

#define LEN 100000

int main(void){
    char str[LEN + 1];
    int dist[LEN];
    long i, K, lastletter;
    
    char dummy;
    
    scanf("%s", str);
    scanf("%c", &dummy);
    scanf("%ld", &K);
    
    for(i = 0; i < strlen(str); i++){
        if(str[i] == 'a') dist[i] = 0;
        else dist[i] = 1 + 'z' - str[i];
        
        if(dist[i] <= K){
            str[i] = 'a';
            K -= dist[i];
        }
    }
    
    i--;
    lastletter = str[i] - 'a';
    
    lastletter += K;
    lastletter %= 26;
    
    str[i] = lastletter + 'a';
    
    printf("%s", str);
    
    return 0;
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-

n, m = map(int, input().split())
data = [list(map(int, input().split()))+[i] for i in range(m)]
dic = {}
for p, y, i in data:
    if p not in dic:
        dic[p] = [(y, i)]
    else:
        dic[p].append((y, i))
ans = []
for pre, cities in dic.items():
    cities.sort(key=lambda x: x[0])
    for i in range(len(cities)):
        ans.append(('{:0=6}{:0=6}'.format(pre, i+1), cities[i][1]))
ans.sort(key=lambda x: x[1])
for line in ans:
    print(line[0])


Measured memory_bytes: 61608
import sys
readline = sys.stdin.readline

def main():
    N = int(readline())
    S = readline().rstrip()
    res = S[:]

    pls_left = 0
    pls_right = 0
    for s in S:
        if s == '(':
            pls_right += 1
        else:
            if pls_right == 0:
                pls_left += 1
            else:
                pls_right -= 1

    res = '(' * pls_left + S + ')' * pls_right

    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,K;cin>>N>>K;
  vector<int> height(N),ans(N,1000000001);
  for(int i=0;i<N;i++)cin>>height[i];
  ans[0]=0;
  for(int i=1;i<N;i++){
    for(int j=1;j<=K;j++){
      if(i>=j)ans[i]=min(ans[i],ans[i-j]+abs(height[i]-height[i-j]));
      else break;
    }
  }
  cout<<ans[N-1]<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a<=b && b<=c){
        cout<<a<<" "<<b<<" "<<c<<endl;
    }
    else if(a<=c && c<=b){
        cout<<a<<" "<<c<<" "<<b<<endl;
    }
    else if(b<=c && c<=a){
        cout<<b<<" "<<c<<" "<<a<<endl;
    }
    else if(b<=a && a<=c){
        cout<<b<<" "<<a<<" "<<c<<endl;
    }
    else if(c<=a && a<=b){
        cout<<c<<" "<<a<<" "<<b<<endl;
    }
    else if(c<=b && b<=a){
        cout<<c<<" "<<b<<" "<<a<<endl;
    }
    return 0;
}


Measured memory_bytes: 3088
#include <iostream>

using namespace std;
double p[305][305][305],ev[305][305][305];
int n,nr1,nr2,nr3,x;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        if(x==1)
            nr1++;
        if(x==2)
            nr2++;
        if(x==3)
            nr3++;
    }

    p[nr1][nr2][nr3]=1;
    for(int c=n;c>=0;c--)
        for(int b=n;b>=0;b--)
            for(int a=n;a>=0;a--)
            {
                if(!a && !b && !c)
                    continue;

                if(a+b+c>n)
                    continue;

                double p_waste=(double) (n-(a+b+c))/n;
                double ev_waste = p_waste/ (1-p_waste) +1;
                ev[a][b][c] += ev_waste * p[a][b][c];

                if(a!=0)
                {
                    double p_go = (double) a/(a+b+c);
                    p[a-1][b][c] += p[a][b][c] * p_go;
                    ev[a-1][b][c] += ev[a][b][c] * p_go;
                }

                if(b!=0)
                {
                    double p_go = (double) b/(a+b+c);
                    p[a+1][b-1][c] += p[a][b][c] * p_go;
                    ev[a+1][b-1][c] += ev[a][b][c] * p_go;
                }

                if(c!=0)
                {
                    double p_go = (double) c/(a+b+c);
                    p[a][b+1][c-1] += p[a][b][c] * p_go;
                    ev[a][b+1][c-1] += ev[a][b][c] * p_go;
                }
            }
    cout.precision(16);
    cout<<ev[0][0][0];
    return 0;
}


Measured memory_bytes: 438528
lismn=input().split()
n=int(lismn[0])
m=int(lismn[1])
lisa=[int(x) for x in input().split()]
count=0
for i in lisa:
  if sum(lisa)/4.0/m <= i:
    count+=1
if m<=count:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
N = int(input())
Data = list(map(int,input().split()))
Ans  = [0]*N
a1 = 0
for i in range(N):
    sign = 1
    if i % 2 == 1:
        sign = -1
    a1 += (sign*Data[i])
Ans[0] = a1
for i in range(1,N):
    Ans[i] = Data[i-1]*2-Ans[i-1]

for a in Ans:
    print( a, end =' ')
print()

Measured memory_bytes: 14032
#include <bits/stdc++.h>
using namespace std;
#define lp(i, x, n) for (int i = x; i < (int)n; ++i)
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()
#define ll unsigned long long
#define N 123451

int n, k, mn = 0;
vector<int> df, el;

int gcd(int a, int b) {
        if (!b)
                return a;
        return gcd(b, a % b);
}
int main () {
        cin >> n>> k;
        lp (i, 0, n) {
                int a;
                cin >> a;
                el.push_back(a);
        }
        el.push_back(k);
        sort(all(el));
        lp (i, 0, n) df.push_back(abs(el[i + 1] - el[i]));
        lp (i, 0, n)
                mn = gcd(mn, df[i]);
        cout << mn;
        return 0;
}


/*
long long
constrain N
*/


Measured memory_bytes: 1400
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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 long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a,b;cin>>a>>b;
  if(abs(a-b)>1)cout<<"Alice"<<endl;
  else cout<<"Brown"<<endl;

  return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
int main(){
  int N,K;
  cin>>N>>K;
  long long A[200000];
  for(int i=0;i<N;i++) cin>>A[i];
  for(int i=K;i<N;i++){
    if(A[i]>A[i-K]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  
  return 0;
}

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

int main() {
  int N, A;
  cin >> N;
  cin >> A;
  
  int can = false;
  for (int i=0; i<=A; ++i) {
    if ((N-i)%500==0) {
      can = true;
      break;
    }
  }
  if (can) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<set>
#include<stack>
#include<iomanip>
#include<algorithm>
#include<unordered_map>
#include <numeric>
#include<string_view>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(i) i.begin(),i.end()
template<typename T =ll> using v = vector<T>;
template<typename T =ll> using vv = v<v<T>>;
template<typename T =ll,typename U =ll> using p = pair<T,U>;
template<typename T> T chmin(T &a,T b) {return a=min(a,b);}
template<typename T> T chmax(T &a,T b) {return a=max(a,b);}
const ll INF = (ll)1e9;
template <int MOD>
struct ModInt {
    using lint = long long;
    int val;

    // constructor
    ModInt(lint v = 0) : val(v % MOD) {
        if (val < 0) val += MOD;
    };

    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt inv() const { return this->pow(MOD - 2); }

    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
    ModInt pow(lint n) const {
        auto x = ModInt(1);
        auto b = *this;
        while (n > 0) {
            if (n & 1) x *= b;
            n >>= 1;
            b *= b;
        }
        return x;
    }

    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = lint(val) * x.val % MOD;
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }

    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }

    // I/O
    friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept { return is >> x.val; }
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};

constexpr int MOD = 1e9 + 7;
using mint = ModInt<MOD>;

void a(){

}

void b(){
    ll N; cin >> N;
    auto A = v<>(N,0); rep(i,N) cin >> A[i];
    auto B = v<>(N,0); rep(i,N) cin >> B[i];
    ll sumA = 0;
    ll sumB = 0;
    rep(i,N){
        if(A[i]<B[i])sumA+=(B[i]-A[i])/2;
        if(A[i]>B[i])sumB+=(A[i]-B[i]); 
    }

    if(sumA >=sumB){
        cout << "Yes"<<endl;
    }else{
        cout << "No" << endl;
    }

}

void c(){

}

void d(){
    
}

void e(){

} 

int main(void){
    b();
    return 0;
 }

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

int n, m;
int a[100000];
int main()
{
	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		cin >> a[i];
		n -= a[i];
	}
	if (n < 0) cout << -1;
	else cout << n;
}


Measured memory_bytes: 3568
package main

import "fmt"

func main() {
	var A, B, C int
	fmt.Scan(&A, &B, &C)
	for i := 0; i < 10010; i++ {
		if i%A == 0 && i%B == C {
			fmt.Println("YES")
			return
		}
	}
	fmt.Println("NO")
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n; cin >> n;
  vector<int> a(n);
  for(int &c : a) {
    cin >> c;
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  int Alice = 0, Bob = 0;
  for(int i = 0; i < n; i++) {
    if(i %2 == 0) {
      Alice += a.at(i);
    }
    else {
      Bob += a.at(i);
    }
  }
  cout << max(Alice, Bob) - min(Alice, Bob) << endl;
}

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

using namespace std;

map<pair<int, int>, int> mem;

int num_lunluns(int starting_digit, int length) {
    auto p = make_pair(starting_digit, length);
    if (mem.find(p) != mem.end()) {
        return mem[p];
    }
    if (length == 1) {
        return mem[p] = 1;
    }
    int answer = 0;
    for (int next_digit = 0; next_digit <= 9; ++next_digit) {
        if (abs(starting_digit - next_digit) <= 1) {
            answer += num_lunluns(next_digit, length - 1);
        }
    }
    return mem[p] = answer;
}

string get_kth_lunlun_with_condition(int k, int length, int previous_digit) {
    // zero indexed
    if (length == 0) return "";
    for (int next_digit = 0; next_digit <= 9; ++next_digit) {
        if (abs(next_digit - previous_digit) <= 1) {
            int range = num_lunluns(next_digit, length);
            if (range > k) {
                return ((char) ('0' + next_digit)) + get_kth_lunlun_with_condition(k, length - 1, next_digit);
            }
            k -= range;
        }
    }
    assert (false);
}

string get_kth_lunlun(int k) {
    // zero indexed
    int length = 1;
    while (true) {
        for (int digit = 1; digit <= 9; ++digit) {
            int range = num_lunluns(digit, length);
            if (range > k) {
                return ((char) ('0' + digit))  + get_kth_lunlun_with_condition(k, length - 1, digit);
            }
            k -= range;
        }
        ++length;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k;
    cin >> k;
    cout << get_kth_lunlun(k - 1) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
string a;
cin>>a;
char b=a[0];
char c=a[1];
char d=a[2];
char e=a[3];
if(b==c||c==d||d==e){cout<<"Bad";}
else{cout<<"Good";}
return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<bitset>
#define NMAX 1000001
using namespace std;
int main() {
	vector<char> sosu(NMAX, true);
	for (int i = 2; i < NMAX; ++i) {
		if (sosu[i]) {
			for (int j = i * 2; j < NMAX; j += i) {
				sosu[j] = false;
			}
		}
	}
	
	int num, money;
	while (cin >> num >> money&&num != 0) {
		bitset<NMAX> line;
		line[0] = true;
		for (int i = 0; i < num; ++i) {
			int price;
			cin >> price;
			for (int i = 0, nmax = money - price; i <= nmax; ++i) {
				if (line[i]) {
					line[i + price] = true;
				}
			}
		}
		int ans = -1;
		for (int i = money; i > 0; --i) {
			if (line[i] && sosu[i]) {
				ans = i;
				break;
			}
		}
		if (ans == -1) {
			cout << "NA" << endl;
		}
		else {
			cout << ans << endl;
		}
	}
	return 0;
}

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

#define pi 3.141592654
#define fix(n) cout << fixed << setprecision(n)

#define rep(i,a,b) for(int i=a;i<b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)

#define ll  long long
#define ull unsigned long long

#define mp make_pair
#define pb push_back
#define fi first
#define se second

#define vi      vector<int>
#define pii     pair<int,int>
#define piii    pair<pair<int,int>,int>
#define all(v)  v.begin(), v.end()

int mod = 1000000007;
const int N = 100005;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	vector<piii> v;
	v.pb({{0,0},0});
	for ( int i = 0; i < n; i++)
	{
		int t, x, y;
		cin >> t >> x >> y;
		v.pb({{t,x},y});

	}
	sort(all(v));
	for ( int i = 1; i < v.size(); i++)
	{
		int t = v[i].fi.fi - v[i-1].fi.fi;
		int x = abs(v[i].fi.se - v[i-1].fi.se);
		int y = abs(v[i].se - v[i-1].se);
		int d = x + y;
		if ( d == t)
			continue;
		if ( d > t)
		{
			cout << "No";
			return 0;
		}
		if ( (t-d)%2)
		{
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes";
	return 0;
}


Measured memory_bytes: 1912
#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e5+5;
int a,b,m,ai[MAXN],bj[MAXN],x,y,c,min1=1<<29,min2=1<<29,ans=1<<30;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin>>a>>b>>m;
	for(int i=1;i<=a;i++)
	{
		cin>>ai[i];
		min1=min(min1,ai[i]);
	}
	for(int i=1;i<=b;i++)
	{
		cin>>bj[i];
		min2=min(min2,bj[i]);
	}
	ans=min1+min2;
	for(int i=1;i<=m;i++)
	{
		cin>>x>>y>>c;
		ans=min(ans,ai[x]+bj[y]-c);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) true
#define dump(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int N; cin >> N;
	priority_queue<double,V<double>,greater<double>> q;
	rep(i,N){
		double x; cin >> x;
		q.push(x);
	}
	rep(i,N-1){
		double x = q.top();q.pop();
		double y = q.top();q.pop();
		q.push((x+y)/2);
	}
	cout << q.top() << endl;
}


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

long long l, n, m = 0;
string s;

int main()
{
	cin >> l >> n >> s;

	for (int i = 1; i < l; i++)
		if (s[i - 1] == 'o' && s[i] == 'o')
			m++;

	m *= 3 * ((1ull << n) - 1);

	cout << l + m << endl;

	return 0;
}


Measured memory_bytes: 3172
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
    char x[15],a[6];
    int i,b,k=0,p;
    scanf("%s",&x);
    for(i=0; x[i+2]!='\0'; i++)
    {
        if(k==0)
        {
            k++;
            a[0]=x[i];
            a[1]=x[i+1];
            a[2]=x[i+2];
            p=atoi(a);
        }
        if(k>0)
        {
            a[0]=x[i];
            a[1]=x[i+1];
            a[2]=x[i+2];
            b=atoi(a);
           if(abs(753-p)>abs(753-b))
                p=b;
        }

    }
    int res=abs(753-p);
    printf("%d\n",res);
    return 0;
}


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

using ll = long long;

constexpr ll inf = 1e18;

int main() {
    int n, m;
    cin >> n >> m;
    vector<ll> x(n), y(n), z(n);
    for(int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i] >> z[i];
    }
    ll ans = -inf;
    for(int sgn1 = -1; sgn1 <= 1; sgn1 += 2) {
        for(int sgn2 = -1; sgn2 <= 1; sgn2 += 2) {
            for(int sgn3 = -1; sgn3 <= 1; sgn3 += 2) {
                vector<ll> v(n);
                for(int i = 0; i < n; ++i) {
                    v[i] = sgn1 * x[i] + sgn2 * y[i] + sgn3 * z[i];
                }
                sort(rbegin(v), rend(v));
                ll t = 0;
                for(int i = 0; i < m; ++i) {
                    t += v[i];
                }
                ans = max(t, ans);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
class UFTree
  def initialize(n)
    @parent = (0...n).to_a
    @rank = Array.new(n, 0)
  end

  def find(x)
    return x if @parent[x] == x
    return @parent[x] = find(@parent[x])
  end

  def unite(a, b)
    a = find(a)
    b = find(b)
    return if a == b

    if @rank[a] < @rank[b]
      @parent[a] = b
    else
      @parent[b] = a
      @rank[a] += 1 if @rank[a] == @rank[b]
    end
  end

  def same?(a, b)
    find(a) == find(b)
  end

  # for debug
  def parents
    @parent
  end
end

N = gets.to_i
G = []
G2N = {}
i = 0
N.times do
  x = gets.split.map(&:to_i)
  G << x
  G2N[x] = i
  i += 1
end

Q = []
H = G.sort{|a, b| a[0] <=> b[0]}
H.zip(H.drop(1)).take(N - 1).each do |a, b|
  Q << [G2N[a], G2N[b], [(a[0] - b[0]).abs, (a[1] - b[1]).abs].min]
end

J = G.sort{|a, b| a[1] <=> b[1]}
J.zip(J.drop(1)).take(N - 1).each do |a, b|
  Q << [G2N[a], G2N[b], [(a[0] - b[0]).abs, (a[1] - b[1]).abs].min]
end

tree = UFTree.new(N)
cost = 0
n = 0
Q.sort!{|a, b| a[2] <=> b[2]}.each do |a, b, c|
  break if n == N
  next if tree.same?(a, b)
  cost += c
  tree.unite(a, b)
  n += 1
end

puts cost


Measured memory_bytes: 46552
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

type edge struct {
	a, b int
}

type graph [][]bool

func deleteEdge(G *graph, e edge) {
	(*G)[e.a][e.b], (*G)[e.b][e.a] = false, false
}

func addEdge(G *graph, e edge) {
	(*G)[e.a][e.b], (*G)[e.b][e.a] = true, true
}

func DFS(G *graph, n int, d *[]bool) {
	(*d)[n] = true
	for i, isLinked := range (*G)[n] {
		if isLinked && !(*d)[i] {
			DFS(G, i, d)
		}
	}
}

func isBridge(G *graph, e edge) bool {
	deleteEdge(G, e)

	N := len((*G)[0])
	dist := make([]bool, N)

	DFS(G, 0, &dist)

	addEdge(G, e)

	for _, isVisited := range dist {
		if !isVisited {
			return true
		}
	}
	return false
}

func main() {
	sc.Split(bufio.ScanWords)

	N, M := scanInt(), scanInt()
	G := make(graph, N)
	for i := 0; i < N; i++ {
		G[i] = make([]bool, N)
	}

	L := make([]edge, M)
	for i := 0; i < M; i++ {
		a, b := scanInt()-1, scanInt()-1
		L[i].a, L[i].b = a, b
		addEdge(&G, L[i])
	}

	ans := 0
	for _, ed := range L {
		if isBridge(&G, ed) {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1808
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint X; cin >> X;
    const lint MAX_NUM = 1e5 + 4;
    vec<bool> is_prime(MAX_NUM, true);
    is_prime.at(0) = false;
    is_prime.at(1) = false;
    range(i, 2, MAX_NUM) {
        if (is_prime.at(i)) {
            for (lint j = 2 * i; j < MAX_NUM; j += i) is_prime.at(j) = false;
        }
    }
    range(i, X, MAX_NUM) if (is_prime.at(i)) {
        cout << i << "\n";
        return 0;
    }
}

Measured memory_bytes: 256
def myAnswer(S,T):
   init = S[:]
   while True:
      S.append(S.pop(0))
      if(S == T):
         return "Yes"
      elif(init == S):
         return "No"


def modelAnswer():
   tmp=1
def main():
   S = list(input())
   T = list(input())
   print(myAnswer(S[:],T[:]))

if __name__ == '__main__':
   main()

Measured memory_bytes: 3060
SA = list(input())
SB = list(input())
SC = list(input())

move = 'a'
while(True):
    if move == 'a':
        if len(SA) == 0:
            print('A')
            break
        move = SA.pop(0)
    elif move == 'b':
        if len(SB) == 0:
            print('B')
            break
        move = SB.pop(0)
    elif move == 'c':
        if len(SC) == 0:
            print('C')
            break
        move = SC.pop(0)


Measured memory_bytes: 3064
#include <iostream>

int main(void)
{
    int a, b, c, d;
    std::cin >> a >> b >> c >> d;
    bool left = (a + b) > (c + d);
    bool right = (a + b) < (c + d);
    std::string ret = left ? "Left" : right ? "Right" : "Balanced";
    std::cout << ret << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define modulo 1000000007
#define int int64_t
//#pragma GCC optimize("trapv")
#define float double
#define PI acos(-1);
#define sinDegrees(x) sin((x) * PI / 180.0)
#define tanDegrees(x) tan((x) * PI / 180.0)
#define atanDegrees(x) atan(x)* 180.0 / PI
using namespace std;
int power(int x,int y,int m)
{
int temp;
if(y == 0)
return 1;
temp = (power(x, y/2,m))%m;
if (y%2 == 0)
return ((temp%m)*temp);
else
return ((x*temp%m)*temp%m)%m;
}
int inv(int x)
{
return (power(x,modulo-2,modulo))%modulo;
}
bool comp(int a,int b)
{
return a<b;
}
///Solution created by:Ahmadsm2005
string s;
int Recursion(int ptr,int total,int num,bool before){
if(ptr>=s.size())
return num+total;
if(before)
return Recursion(ptr+1,total,num*10+(s[ptr]-'0'),1)+Recursion(ptr+1,total+num,(s[ptr]-'0'),1);
else
return Recursion(ptr+1,total+num,(s[ptr]-'0'),1);
}
int32_t main()
{
//freopen("output.txt","w", stdout);
//freopen("output.txt","r", stdin);
//iostream::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>s;
cout<<Recursion(0,0,0,0);
return 0;
}


Measured memory_bytes: 256
import numpy as np
n = int(input())

arr = map(int,raw_input().split())

arr.sort()
mx = arr.pop()

def getNearestValue(list, num):
	idx = np.abs(np.asarray(list) - num).argmin()
	return list[idx]

print mx,getNearestValue(arr,mx/2.0)

Measured memory_bytes: 24572
#include<bits/stdc++.h>
using namespace std;
long X,Y,Z,K,i,j,k;
main(){
  cin>>X>>Y>>Z>>K;
  vector<long> A(X),B(Y),C(Z),ABC;
  for(i=0;i<X;i++)cin>>A[i];
  for(i=0;i<Y;i++)cin>>B[i];
  for(i=0;i<Z;i++)cin>>C[i];
  sort(A.rbegin(),A.rend());
  sort(B.rbegin(),B.rend());
  sort(C.rbegin(),C.rend());
  for(i=0;i<X;i++){
    for(j=0;j<Y;j++){
      for(k=0;k<Z;k++){
        if((i+1)*(j+1)*(k+1)>K)break;
        ABC.push_back(A[i]+B[j]+C[k]);
      }
    }
  }
  sort(ABC.rbegin(),ABC.rend());
  for(i=0;i<K;i++)cout<<ABC[i]<<endl;
}


Measured memory_bytes: 1404
N, M, K = map(int,input().split())
uf = [-1 for _ in range(N)]
fc = [0] * N
bc = [0] * N
ans = [0] * N

def find(x):
    # x を引数に取り、xのroot番号を取得するメモ化再帰
    if uf[x] < 0:
        return x
    uf[x] = find(uf[x])
    return uf[x]

def unite(x, y):
    # x, y を引数に取り、x(自分)をy(相手)のrootに接続する関数
    x = find(x)
    y = find(y)
    if x == y:
        return
    if x < y:
        x , y = y, x
    uf[y] += uf[x]
    uf[x] = y

for m in range(M):
    a, b = map(int,input().split())
    fc[a-1] += 1
    fc[b-1] += 1
    unite(a-1, b-1)

for k in range(K):
    c, d = map(int,input().split())
    if find(c-1) == find(d-1):
        bc[c-1] += 1
        bc[d-1] += 1

for i in range(N):
    cnt = -uf[find(i)] - 1 - fc[i] - bc[i]
    ans[i] = cnt

print(*ans)

Measured memory_bytes: 11808
import sys
sys.setrecursionlimit(10**5)

n = int(input())
if n==1:
  print(0)
  exit()
from collections import defaultdict
edge = defaultdict(list)
for i in range(n-1):
  u, v, w = list(map(int, input().split()))
  edge[u].append((v, w))
  edge[v].append((u, w))
graph = [-1 for i in range(n+1)]

def dfs(x, c):
  nexts = edge.get(x)
  if nexts is None:
    return
  if graph[x]!=-1:
    return
  else:
    graph[x] = c
  for y, w in nexts:
    if w%2:
      dfs(y, not c)
    else:
      dfs(y, c)

dfs(1, 0)
for i in range(1, n+1):
  print(int(graph[i]))

Measured memory_bytes: 159632
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
    string n;
    cin >> n;

    vector<vector<int>> dp(n.size() + 1, vector<int>(2));
    dp[0][0] = 0;
    dp[0][1] = 1;
    for (int i = 0; i < static_cast<int>(n.size()); i++) {
        int j = n[i] - '0';
        dp[i + 1][0] = min(dp[i][0] + j, dp[i][1] - j + 10);
        dp[i + 1][1] = min(dp[i][0] + j + 1, dp[i][1] - j + 9);
    }

    cout << dp[n.size()][0] << endl;
}


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

int main(){
    long long n, b=0, i;
    cin >> n;
    long long a[n];
    for (i = 0; i<n; i++){
            cin >> a[i];
        }
    sort(a, a+n, greater<int>());

    b= a[0];
    for (i = 1; i < n / 2; i++)
        b = b + 2 * a[i];
    if(n%2==1)
        b = b + a[i];
    cout << b << endl;
}

Measured memory_bytes: 5164
n,m=list(map(int,input().split()))
lists=[]
for i in range(n):
  lists.append(0)
for i in range(m):
  am,bm=list(map(int,input().split()))
  lists[am-1]+=1
  lists[bm-1]+=1
for i in range(n):
  print(lists[i])

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define fs first
#define sc second
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
int main(){
  int n;
  cin>>n;
  int l[n];
  rep(i,n)cin>>l[i];
  int max=-109;
  rep(i,n){
    if(max<l[i])max=l[i];
  }
  int sum=0;
  rep(i,n)sum+=l[i];
  if(sum-max>max)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

int main(){
	int n, m;
	int a, b, cnt = 0;
	int flag[500];
	vector<int> v[501];
	while (1){
		cin >> n >> m;
		if (!n && !m) return 0;
		for (int i = 0; i < 500; i++) {
			v[i].clear();
			flag[i] = 0;
		}
		flag[0] = 1;
		v[500].clear();
		for (int i = 0; i < m; i++) {
			cin >> a >> b;
			v[a].push_back(b);
			v[b].push_back(a);
		}
		for (int i = 0; i < v[1].size(); i++){
			flag[v[1][i] - 1] = 1;
			for (int j = 0; j < v[v[1][i]].size(); j++){
				flag[v[v[1][i]][j] - 1] = 1;
			}
		}
		for (int i = 0; i < 500; i++) cnt += flag[i];
		cout << --cnt << endl;
		cnt = 0;
	}
	return 0;
}

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

ll get_ll(char* s, int size) {
  char temp = s[size];
  s[size] = '\0';
  ll ret = atoll(s);
  s[size] = temp;
  return ret;
}

main () {
  string s;
  cin >> s;

  ll sum = 0;
  for (int i=0; i<(1<<(s.size()-1)); i++) {
    // iのj番目のbitが立っていたら、そこで数字を分割して足す
    int bit = i | (1<<(s.size()-1));
    int prev = -1;
    for (int j=0; j<s.size(); j++) {
      if ((bit>>j)&1) {
        sum += get_ll(&s[prev+1], j-prev);
        prev = j;
      }
    }
  }

  cout << sum << endl;

  return 0;
}


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

typedef long long ll;

int main() {
int N, M;   cin >> N >> M;
vector<int> X(M);
    for (int i = 0; i < M; i++) {
    cin >> X[i];
}
sort(X.begin(), X.end());

vector<int> D(M - 1);
for (int i = 0; i < M - 1; i++) {
    D[i] = X[i + 1] - X[i];
}
sort(D.begin(), D.end());
int ans = 0;
for (int i = 0; i < M - N; i++) {
    ans += D[i];
}

cout << ans << endl;

}

Measured memory_bytes: 1024
# include <bits/stdc++.h>
using namespace std;
const int D = 105, N = 1e4 + 100, mod = 1e9 + 7;
long long dp[N][D][2], n, m, ans;
string s;
int main(){
    cin >> s >> n;m = s.size();
    dp[0][0][1] = 1;
    s = '0' + s;
    for(int i = 1; i <= m; i++){
        for(int j = 0; j < n; j++){  
            for(int d = 0; d < 10; d++){
                int x = (j - d + 15 * n) % n;
                dp[i][j][0] += dp[i - 1][x][0];
                if(d == s[i] - '0'){
                    dp[i][j][1] += dp[i - 1][x][1];
                }
                if(d < s[i] - '0'){
                    dp[i][j][0] += dp[i - 1][x][1];
                }
                dp[i][j][0] %= mod;
                dp[i][j][1] %= mod;
            }
        }
    }  
    cout << (dp[m][0][0] + dp[m][0][1] - 1 + mod) % mod << endl;
}

Measured memory_bytes: 16640
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx") 
#include <bits/stdc++.h>
#include <ext/pb_ds/priority_queue.hpp>
using namespace std;
using namespace __gnu_pbds;
#define F(i,a,b) for(int i=(a);i<=(b);++i)
#define F2(i,a,b) for(int i=(a);i<(b);++i)
#define dF(i,a,b) for(int i=(a);i>=(b);--i)
#define dF2(i,a,b) for(int i=(a);i>(b);--i)
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define INF 0x3f3f3f3f
#define INFll 0x3f3f3f3f3f3f3f3f
#define y0 _lxybz_
#define y1 _ljmnzyzhhhoscartxdy_
typedef long double ld;
typedef long long ll;
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize
#define lo(x) ((x)&(-(x)))
#define trav(a, x) for (auto &a : x)
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
const ld Pi = 4*atan((ld)1);
template<class T> void chmin(T &a,const T&b) { a = min(a, b); }
template<class T> void chmax(T &a,const T&b) { a = max(a, b); }
namespace IO{
template<class T> inline void read(T&ret)
{
	ret=0; int f=1; char c=getchar();
	while(c<48||c>57){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>=48 && c<=57)ret=ret*10+c-48,c=getchar();
	ret*=f;
}
template<class T> inline void prin(const T&ret)
{
	if(!ret){putchar(48);return;} static T o; o=ret;
	if(o<0){putchar('-');o=-o;}
	static int op[25],tt; tt=0;
	while(o){
		op[++tt]=o%10;
		o/=10;
	}
	for(int i=tt;i;--i)putchar(op[i]+48);
}
template<class T> inline void pri_(const T&ret)
{
	prin(ret);putchar(' ');
}
template<class T> inline void priE(const T&ret)
{
	prin(ret);putchar('\n');
}
}
using namespace IO;

#define N 
#define MO 
ll n,s,ss;
inline void _Sol_()
{
	read(n);s=1;
	while(n){
		ss+=s;
		n/=2;
		s*=2;
	}
	prin(ss);
}

int main()
{
	int T=1; //read(T);
	while(T--)_Sol_();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000LL;
constexpr auto MOD = 1000000007;

int main() {

	int n;
	cin >> n;
	vi p(n);
	rep(i, n)cin >> p[i];
	int ans = 0;
	rep(i, n - 2) {
		if (p[i + 2] > p[i + 1] && p[i] < p[i + 1])ans++;
		if (p[i + 2] < p[i + 1] && p[i] > p[i + 1])ans++;
	}

	cout << ans << endl;

}

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

int t[7][7];
int main(){
	for(int i = 0; i < 7; i++){
		scanf("%d %d", &t[i][0], &t[i][1]);
	}
	for(int i = 0; i < 7; i++){
		printf("%d\n", t[i][0] - t[i][1]);
	}
	return 0;
}

Measured memory_bytes: 1192
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<queue>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;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 llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
typedef pair<ll,ll> LLP;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define INF 1000000007
#define MOD 1000000007
#define ARRAY_MAX 105
#define TICKET 15

int c,n,m,s,d;
vector<P> G[ARRAY_MAX];//to,cost
int cost[TICKET][ARRAY_MAX];//チケットの残り枚数、最短距離
bool used[TICKET][ARRAY_MAX];


void solve(){

    cost[c][s] = 0;//出発点
    priority_queue<pair<int,P>,vector<pair<int,P> >,greater<pair<int,P> > > que;
    que.push(pair<int,P>(0,P(s,c)));//コスト、現在位置、残りのチケット枚数
    while(!que.empty()){

        pair<int,P> tmp = que.top();
        que.pop();
        int now_position = tmp.second.first;//現在位置
        int now_ticket = tmp.second.second;//残りのチケット枚数
        int now_cost = tmp.first;//次の町までのコスト

        if(cost[now_ticket][now_position] < now_cost){
            continue;
        }


        for(int i = 0;i < G[now_position].size();i++){
            //チケットを使わない場合
            if(cost[now_ticket][G[now_position][i].first] > cost[now_ticket][now_position] + G[now_position][i].second){
                cost[now_ticket][G[now_position][i].first] = cost[now_ticket][now_position] + G[now_position][i].second;
                que.push(pair<int,P>(cost[now_ticket][G[now_position][i].first],P(G[now_position][i].first,now_ticket)));
            }
            //チケットをc枚まで使う場合
            if(now_ticket > 0){
                if(cost[now_ticket-1][G[now_position][i].first] > cost[now_ticket][now_position] + G[now_position][i].second/2){
                    cost[now_ticket-1][G[now_position][i].first] = cost[now_ticket][now_position] + G[now_position][i].second/2;
                    que.push(pair<int,P>(cost[now_ticket-1][G[now_position][i].first],P(G[now_position][i].first,now_ticket-1)));
                }
            }
        }
    }
}

int main(){

    while(cin >> c >> n >> m >> s >> d,c|n|m|s|d){

        s--;
        d--;
        //cout << s << " " << d << endl;
        REP(i,ARRAY_MAX){//初期化
            G[i].clear();
        }

        REP(i,TICKET){//最短距離の初期化
            REP(j,ARRAY_MAX){
                cost[i][j] = INF;
                used[i][j] = false;
            }
        }

        REP(i,m){
            int a,b,f;
            cin >> a >> b >> f;
            a--;
            b--;
            G[a].push_back({b,f});
            G[b].push_back({a,f});
            //マップの作成
        }

        solve();

        int mini = INF;
        for(int i = 0;i <= c;i++){
            mini = min(mini,cost[i][d]);
        }
        cout << mini << endl;
    }


    return 0;
}


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

typedef long long                   ll;
typedef long double                 ld;
typedef pair<ll,ll>                 pll;
typedef pair<ld,ld>                 pld;


#define all(x)          (x).begin(),(x).end()
#define Sort(x)         sort(all(x))
#define sep             ' '

#define endl            '\n'
#define tab             '\t'
#define X               first
#define Y               second
#define fast_io         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define set_random      mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll MOD = 1e9 + 7,
         MAXN= 1e6+10,
         INF=1e18;
ll w,h,x,y;
int main()
{
    fast_io;
    cin>>w>>h>>x>>y;
    cout<<ld(w*h)/2<<sep;
    if(x+x==w && y+y==h) cout<<1;
    else cout<<0;

    return 0;
}


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

int main(){
    int n;
    cin >> n;
    
    int A[n];
    for(int i = 0; i < n; i++)  cin >> A[i];

    int l = 0, r = 0;
    int now_sum = 0;
    int now_xor = 0;
    long long ans = 0;

    while(l < n){
        while(r < n && (now_sum+A[r])==(now_xor^A[r])){
            now_sum += A[r];
            now_xor ^= A[r];
            r++;
        }
        
        ans += r-l;

        now_sum -= A[l];
        now_xor ^= A[l];
        l++;
    }

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

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main()
{
    int a , p , x , y;
    cin>> a>>p;
    x = a*3;
    y = x+p;
    if (y > 0) {
        cout<< y/2;
    }
    else {
        cout<< 0;
    }
    return 0;
}


Measured memory_bytes: 3592
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <cassert>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

const long long MOD = 1000000007;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint choose(ll n, ll k) {
  mint x = 1, y = 1;
  for(ll i=0; i<k; i++) {
    x *= n-i;
    y *= i+1;
  }
  return x / y;
}

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

void solve(long long N, long long K, std::vector<long long> A){
  mint ans = 0;
  combination c(100100);
  sort(A.begin(), A.end());
  for(ll ri=0; ri<2; ri++) {
    for(ll i=0; i<N; i++) {
      mint now = c(i, K-1);
      if(ri==1) now = -now;
      ans += now*A[i];
    }
    reverse(A.begin(), A.end());    
  }
  std::cout << ans.x << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  long long K;
  scanf("%lld",&K);
  std::vector<long long> A(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&A[i]);
  }
  solve(N, K, std::move(A));
  return 0;
}



Measured memory_bytes: 2560
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <bitset>
#include <utility>
#include <queue>
#include <deque>

using namespace std;

int main(){

    double L;
    cin >> L;

    printf("%10.10f\n", (L/3.0)*(L/3.0)*(L/3.0));  
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
template<class T = ll> T in(){T x; cin >> x; return (x);}

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


  ll N ; cin >> N;

  FOR(h,1,3501){
    FOR(n,1,3501){
      ll a = N*h*n;
      ll b = 4*h*n-N*n-N*h;

      if(b<=0) continue;
      if(a%b==0) {
	cout << h << " " << n << " " << a/b << endl;
	return 0;
      }
    }
  }
  
  return 0;
}


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

using namespace std;

int main(int argc, char* argv[]) {
  int N;
  cin >> N;

  string s;
  cin >> s;

  int res = 0;
  int x = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == 'I')
      ++x;
    else
      --x;
    res = max(x, res);
  }

  cout << res << endl;

  return 0;
}

Measured memory_bytes: 256