akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
	if(was_output)cout << " ";
	cout << a;
	was_output = true;
}
void outendl(){
	was_output = false;
	cout << endl;
}

int n, m, s, g1, g2;

vvector<pii> edges;
vvector<int> dp;

int cul_cost(int start, int end){
	if(dp[start][end]>=0)return dp[start][end];
	vector<int> fast(n, INF);
	priority_queuer<pii> pq;
	pq.emplace(0, start);
	fast[start] = 0;
	while(pq.size()){
		pii d = pq.top();
		pq.pop();
		if(d.first!=fast[d.second])continue;
		foreach(i, edges[d.second]){
			int next_time = d.first + i.second;
			if(fast[i.first]<next_time)continue;
			fast[i.first]=next_time;
			pq.emplace(next_time, i.first);
		}
	}
	rep(i, n){
		dp[start][i] = fast[i];
	}
	return dp[start][end];
}

int main(){
	while(cin>>n>>m>>s>>g1>>g2&&n){
		edges.assign(n, vector<pii>(0));
		dp.assign(n, vector<int>(n, -1));
		--s;
		--g1;
		--g2;
		rep(i, m){
			int a, b, c;
			cin >> a >> b >> c;
			--a;
			--b;
			edges[a].emplace_back(b, c);
		}
		ll ans = INF;
		rep(i, n){
			chmin(ans, (ll)cul_cost(s, i)+cul_cost(i, g1)+cul_cost(i, g2));
		}
		cout << ans << endl;
	}
	return 0;
}



Measured memory_bytes: 3060
#include<bits/stdc++.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 perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}
const int mod = 1000000007;
using ll=long long;
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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
const int max_n=3000010;
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];
  }
}comb(max_n);
mint box(ll a,ll b){
    mint ans=a+2;
    ans*=comb(a+b+2,b);
    ans-=b+1;
    ans/=b+1;
    return ans;
}
int main(){
    ll a,b,c,d;cin >> a >>b >> c >>d;
    mint ans=box(c,d);
    ans-=box(a-1,d);
    ans-=box(b-1,c);
    ans+=box(a-1,b-1);
    cout <<ans <<endl;
}

Measured memory_bytes: 47232
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// 入力
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();

		// 出力
		if ((x - a) * (x - a) <= (x - b) * (x - b)) {
			System.out.println("A");
		} else {
			System.out.println("B");
		}

		sc.close();
	}
}


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

const double EPS = 1e-8;
const double INF = 1e12;

//point
typedef complex<double> P;
namespace std {
	bool operator < (const P& a, const P& b) {
		return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
	}
	bool cmp_y(const P &a, const P &b){
		return a.imag() != b.imag() ? a.imag() < b.imag() : a.real() < b.real();
	}
}
double cross(const P& a, const P& b) {
	return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
	return real(conj(a)*b);
}
int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;								  // a--c--b on line
}

// line
struct L : public vector<P> {
	L(const P& a, const P& b) {
		push_back(a); push_back(b);
	}
};

// polygon
typedef vector<P> G;

P extreme(const vector<P> &po, const L &l) {
  int k = 0;
  for (int i = 1; i < po.size(); ++i)
    if (dot(po[i], l[1]-l[0]) > dot(po[k], l[1]-l[0])) k = i;
  return po[k];
}

enum { OUT, ON, IN };
int contains(const G& po, const P& p) {
  bool in = false;
  for (int i = 0; i < po.size(); ++i) {
  	P a = po[i] - p, b = po[(i+1)%po.size()] - p;
    if (imag(a) > imag(b)) swap(a, b);
    if (imag(a) <= 0 && 0 < imag(b))
      if (cross(a, b) < 0) in = !in;
    if (cross(a, b) == 0 && dot(a, b) <= 0) return ON;
  }
  return in ? IN : OUT;
}

double area2(const G& po) {
	double A = 0;
  	for (int i = 0; i < po.size(); ++i) 
    	A += cross(po[i], po[(i+1)%po.size()]);
	//????????????????????????????????¨????????????
  	return A/2;
}

bool isconvex(const G &p) {
	int n = p.size();
	if(cross(p[0]-p[n-1],p[n-2]-p[n-1]) < 0) return false;
	for(int i = 1; i < n-1; ++i) {
		if(cross(p[i+1]-p[i],p[i-1]-p[i]) < 0) return false;
	}
	return true;

}

G convex_hull(G ps) {
  int n = ps.size(), k = 0;
  sort(ps.begin(), ps.end(), cmp_y);
  G r(2*n);
  for(int i = 0; i < n; i++){
    while(k>1 && cross(r[k-1]-r[k-2],ps[i]-r[k-2]) < -EPS)k--;
    r[k++] = ps[i];
  }
  for(int i = n-2, t = k; i >= 0; i--){
    while(k>t && cross(r[k-1]-r[k-2],ps[i]-r[k-2]) < -EPS)k--;
    r[k++] = ps[i];
  }
  r.resize(k-1);
  return r;
}

// caliper
double convex_diameter(const G &pt) {
	const int n = pt.size();
	if(n <= 1) return 0;
	if(n == 2) return abs(pt[0]-pt[1]);
	
	int i = 0, j = 0;
	for(int k = 0; k < n; ++k){
		if(!(pt[i] < pt[k])) i = k;
		if(pt[j] < pt[k]) j = k;
	}
   
	double res = 0;
	int si = i, sj = j;
	while(i != sj || j != si) {
		res = max(res, abs(pt[i]-pt[j]));
		if(cross(pt[(i+1)%n]-pt[i],pt[(j+1)%n]-pt[j]) < 0) i = (i+1)%n;
		else j = (j+1)%n;
	}
	return res;
}
	
int main() {
	int n;
	cin >> n;
	G po;
	for(int i=0; i<n; ++i) {
		double x, y;
		cin >> x >> y;
		P p(x, y);
		po.push_back(p);
	}
	cout << fixed << setprecision(15) << convex_diameter(po) << endl;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if ( (A + B) > (C + D) ){
    cout << "Left" << endl;
  }
  else if ( (A + B) < (C + D) ){
    cout << "Right" << endl;
  }
  else{
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char a[100005];
int dp[100005];
int main()
{

 int n,q,num=0;
 cin>>n>>q;
 cin>>a+1;
 for(int i=1;i<=n;i++)
 {
   if (a[i]=='C'&&a[i-1]=='A') num++;
   dp[i]=num;

 }
 int s,e;
 for(int i=1;i<=q;i++)
 {
     cin>>s>>e;
     cout<<dp[e]-dp[s]<<endl;


 }


 return 0;
}


Measured memory_bytes: 1280
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n, k;

int main(){
	cin >> n >> k;
	if(k > (n - 1)*(n - 2)/2){
		cout << -1 << endl;
		return 0;
	}
	cout << n - 1 + ((n - 1) * (n - 2)/2 - k) << endl;
	int num = (n - 1) * (n - 2)/2;
	for(int i = 2;i <= n;i++){
		cout << 1 << " " << i << endl;
	}
	for(int i = 2;i <= n;i++){
		for(int j = i + 1;j <= n;j++){
			if(num == k)return 0;
			cout << i << " " << j << endl;
			num--;
		}
	}
}

Measured memory_bytes: 256
h, w = map(int, input().split())
S = [list(input()) for i in range(h)]

for i in range(h):
    for j in range(w):
        if S[i][j] == '.':
            S[i][j] = 0
            
for i in range(h):
    for j in range(w):
        if S[i][j] == '#':
            for k in range(-1, 2):
                for l in range(-1, 2):
                    ni = i + k
                    nj = j + l
                    if 0 <= ni < h and 0 <= nj < w and S[ni][nj] != '#' and S[ni][nj] != '.':
                        S[ni][nj] += 1
                        
for i in range(h):
    print(''.join(map(str, S[i])))

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

def main():
    N = int(input())
    V = sorted(list(map(int, input().split())))

    x = V[0]

    for v in V[1:]:
        x = (x + v)/2

    print('{:.6f}'.format(x))
    

if __name__ == '__main__':
    main()



Measured memory_bytes: 2940
N, K = map(int, input().split())
S = input()
zeros = []
ones = []
i = 0
if S[0] == '0':
    ones.append(0)
while i < N:
    count = 1
    j = i + 1
    while j < N:
        if S[i] == S[j]:
            count += 1
            j += 1
        else:
            break
    if S[i] == '0':
        zeros.append(count)
    else:
        ones.append(count)
    i = j
if S[-1] == '0':
    ones.append(0)

if len(zeros) <= K:
    print(N)
    exit()

sum_zero = 0
sum_one = 0
for i in range(K):
    sum_zero += zeros[i]
    sum_one += ones[i]
sum_one += ones[K]

ans = sum_zero + sum_one
for i in range(len(zeros) - K):
    sum_zero = sum_zero - zeros[i] + zeros[i+K]
    sum_one = sum_one - ones[i] + ones[i+K+1]
    ans = max(ans, sum_zero + sum_one)
print(ans)


Measured memory_bytes: 4224
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define p pair<int,int>
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
using namespace std;
int POW(int x,int y){return int(pow(double(x),double(y)));}



int main(){
	int a,b,n;
	cin>>a>>b>>n;
	int x;
	FOR(i,a,a+n){
		cout<<i<<endl;
		x=i;
		if(i==b){
			return 0;
		}
	}
	FOR(i,max(b-n+1,x+1),b+1){
		cout<<i<<endl;
		x=i;
		if(i==b){
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223372036854775807
#define INF 2147483647
#define MOD 1000000007
using namespace std;

vector<long> x;
vector<long> y;
vector<pair<long, long> > xx;
vector<pair<long, long> > yy;

long dist( long i, long j ) {
    return MIN(abs(x[i]-x[j]), abs(y[i]-y[j]) );
}

int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);

    x.resize(n);
    y.resize(n);
    xx.resize(n);
    yy.resize(n);
    long i;
    for(i=0; i<n; i++) {
        scanf("%ld%ld", &x[i], &y[i]);
        xx[i]=make_pair(x[i],i);
        yy[i]=make_pair(y[i],i);
    }
    sort(xx.begin(), xx.end());
    sort(yy.begin(), yy.end());

    set<pair<long, long> > sEdge;
#define ADD_EDGE( i, j ) (sEdge.insert(make_pair(MIN((i),(j)), MAX((i),(j)))))
    for(i=0; i<n-1; i++) {
        ADD_EDGE( xx[i].second, xx[i+1].second );
    }
    for(i=0; i<n-1; i++) {
        ADD_EDGE( yy[i].second, yy[i+1].second );
    }

    vector<vector<pair<long,long> > > gra(n);
    auto it=sEdge.begin();
    for(; it!=sEdge.end(); ++it) {
        long dDist = dist(it->first, it->second);
        gra[it->first].push_back( make_pair( it->second, dDist ) );
        gra[it->second].push_back( make_pair( it->first, dDist ) );
    }

    vector<long> used(n,0);
    priority_queue<pair<long,long>, vector<pair<long,long> >, greater<pair<long,long> > > que;   // cst,to
    que.push(make_pair(0,0));

    ll sum=0;
    while( !que.empty()) {
        pair<long,long> curr = que.top(); que.pop();
        if(used[curr.second]) continue;

        sum += curr.first;
        used[curr.second] = 1;

        for(i=0; i<(long)gra[curr.second].size(); i++) {
            if( !used[gra[curr.second][i].first] ) {
                que.push( make_pair( gra[curr.second][i].second, gra[curr.second][i].first ) );                
            }
        }
    }
    printf("%lld\n", sum);

    return 0;
}


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

struct UnionFindPOL {
  vector<int> data;
  vector<int> position;

  UnionFindPOL(int size) : data(size, -1), position(size, 0) { 

  }

  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }

  bool addDist(int l, int r, int d) {
      int rl = root(l);
      int rr = root(r);
      int posl = getAbsolutePosition(l);
      int posr = getAbsolutePosition(r);

      if(rl == rr) {
          if(posr - posl == d) {
              return true;
          } else {
              return false;
          }
      } else {
          if(data[rl] < data[rr]) {
            int offsetr = posl + d - posr;
            position[rr] = offsetr;
            data[rl] += data[rr];
            data[rr] = rl;
          } else {
            int offsetl = posr - d - posl;
            position[rl] = offsetl;
            data[rr] += data[rl];
            data[rl] = rr;
          }
          return true;
      }

  }

  int getAbsolutePosition(int x) {
      int pos = position[x];
      int p = data[x];
      while(p >= 0) {
          pos += position[p];
          p = data[p];
      }
      return pos;
  }

  bool findSet(int x, int y) {
    return root(x) == root(y);
  }

  int root(int x) {
    //return data[x] < 0 ? x : data[x] = root(data[x]);
    if(data[x] < 0) {
        return x;
    } else {
        //position[x] = getPosition(x);
        //return (data[x] = root(data[x]));
        return root(data[x]);
    }
  }

  int size(int x) {
    return -data[root(x)];
  }
};

int main() {
    int N, M;
    cin >> N >> M;
    UnionFindPOL ufpol(N+1);

    for(int i=0; i<M; i++) {
        int l, r, d;
        cin >> l >> r >> d;
        if(ufpol.addDist(l, r, d) == false) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

using namespace std;

int main() {
  vector<int> A = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int N;
  cin >> N;
  cout << A[N - 1] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"

const int N=3005;

int n, m;
string s, t;
int cache[N][N];

int dp(int i, int j)
{
	if(i==n)
		return 0;
	if(j==m)
		return 0;
	int &ans=cache[i][j];
	if(ans!=-1)
		return ans;
	if(s[i]==t[j])
		ans=1+dp(i+1, j+1);
	else
		ans=max(dp(i+1, j), dp(i, j+1));
	return ans;
}

void path(int i, int j)
{
	if(i==n)
		return;
	if(j==m)
		return;
	int ans=dp(i, j);
	if(s[i]==t[j])
	{
		cout<<s[i];
		return path(i+1, j+1);
	}
	else
	{
		if(ans==dp(i+1, j))
			return path(i+1, j);
		return path(i, j+1);
	}
}



int32_t main()
{
	IOS;
	memset(cache, -1, sizeof(cache));
	cin>>s>>t;
	n=s.size();
	m=t.size();
	int len=dp(0, 0);
	path(0, 0);
	return 0;
}


Measured memory_bytes: 35968
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

int sum[200010];
ll num[2020]={};

int main(void){
    string S;
    cin >> S;
    sum[S.size()]=0;
    num[0]=1;
    int now=1;
    for(int i=S.size()-1; i>=0; --i){
        sum[i]=(sum[i+1]+(S[i]-'0')*now)%2019;
        ++num[sum[i]];
        (now *= 10) %= 2019;
    }
    ll ans=0;
    for(int i=0; i<2019; ++i){
        ans += num[i]*(num[i]-1)/2;
    }
    cout << ans << endl;
    return 0;
}


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

int main(void) {
	int D;
	scanf("%d", &D);
	cout << "Christmas";
	for (int i = 0; i < 25 - D; i++) {
		cout << " Eve";
	}
	cout << "\n";
	return 0;
}


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

int main() {
    long long int n,sum;

    cin>>n;
    sum=n-1;
    for(long long int i=1;i*i<=n;i++){
        if(n%i==0){
            long long int minsum=i+n/i-2;
            if(sum>minsum)
                sum=minsum;
        }
    }
    cout<<sum;



    return 0;
}

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

int x[365], y[365], b[365], p[365];

int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> x[i] >> y[i] >> b[i] >> p[i];
	}

	for (int i = 0; i < N; i++) {
		if (b[i] >= 5 && p[i] >= 2) {
			cout << (x[i] * b[i] + y[i] * p[i]) / 10 * 8 << endl;
		} else if (b[i] >= 5) {
			cout << min(x[i] * b[i] + y[i] * p[i], (x[i] * b[i] + y[i] * 2) / 10 * 8) << endl;
		} else if (p[i] >= 2) {
			cout << min(x[i] * b[i] + y[i] * p[i], (x[i] * 5 + y[i] * p[i]) / 10 * 8) << endl;
		} else {
			cout << min(x[i] * b[i] + y[i] * p[i], (x[i] * 5 + y[i] * 2) / 10 * 8) << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
long long n,m,a[300001],b[300001],s[300001];
inline long long read()
{
    long long sum=0,x=1;
    char ch=getchar();
    while (ch<'0'||ch>'9')
	{
        if (ch=='-')
		  x=-1;
        ch=getchar();
    }
    while (ch>='0'&&ch<='9')
	{
        sum=sum*10+ch-'0';
        ch=getchar();
    }
    return sum*x;
}
inline void write(long long x)
{
    if (x<0)
	{
        putchar('-');
        x=-x;
    }
    if (x>9)
      write(x/10);
    putchar(x%10+'0');  
    return;
}
int main()
{
    n=pow(2,read());
    for (register int i=0;i<n;++i)
	  a[i]=read();
    for (register int i=0;i<n;++i)
      for (register int j=i;j<=n;j=(j+1)|i)
      {
    	s[j]=max(s[j],a[i]+b[j]);
		b[j]=max(b[j],a[i]);
	  }
	for (register int i=1;i<n;++i)
	  s[i]=max(s[i],s[i-1]);
    for (register int i=1;i<n;++i)
	{
		write(s[i]);
		putchar('\n');
	}
    return 0;
}

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

int main() {
    int A,B,C;
    cin >> A >> B >> C;
    long long res = 0;
    while(true) {
        if((A&1)^0 || (B&1)^0 || (C&1)^0) { /*どちらかが奇数のとき*/ break; }
        int nA,nB,nC;
        nA = B/2 + C/2;
        nB = A/2 + C/2;
        nC = A/2 + B/2;
        if(A==nA && B==nB && C==nC) { cout << -1 << endl; return 0; }
        A = nA, B = nB, C = nC;
        //cout << A << " " << B << " " << C << endl;
        ++res;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
N, K, S = [int(i) for i in input().split()]
if not (S==10**9):
    l = []
    for i in range(N):
        if i<K:
            l.append(S)
        else:
            l.append(S+1)
    print(*l)
    quit()

l = []
for i in range(N):
    if i<K:
        l.append(S)
    else:
        l.append(1)
print(*l)

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

int main(){
  
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  a += b;
  c += d;
  
  if(a > c){
    cout << "Left" << endl;
  }else if(a < c){
    cout << "Right" << endl;
  }else{
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        if((a+b)<(c+d)){
            System.out.println("Right");

        }else if((a+b)==(c+d)){
            System.out.println("Balanced");
        }else{
            System.out.println("Left");
        }

    }

}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string str;
  cin >> str;
  if(str.find("RRR")+1){
    cout << 3 << endl;
    return 0;
  }else if(str.find("RR")+1){
    cout << 2 << endl;
    return 0;
  }else if(str.find("R")+1){
    cout << 1 << endl;
    return 0;
  }else{
    cout << 0 << endl;
    return 0;
  }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}




int main(){

  string s,t;
  cin >> s >> t;
  ll n = s.size();

  if(s==t.substr(0,n)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

}


Measured memory_bytes: 3548
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define int long long
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1e15
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second
#define pb push_back

using namespace std;
const int N = 100005;
int n, m;
vector<int>v[N];
int vis[N] = {};


int dx[] = { -1, 1, 0, 0};
int dy[] = {0, 0, 1, -1};
int func(int n, int a[])
{
	int l = 0;
	int sum = a[0];
	for (int i = 1; i < n; i++)
	{
		if (a[i] < sum)
		{
			int diff = abs(a[i] - sum);
			l += diff;
			sum = a[i] + diff;
		}
		else {
			sum = a[i];
		}
	}
	return l;
}


int32_t main()
{
	std::ios::sync_with_stdio(false);

// #ifndef ONLINE_JUDGE
// 	freopen("inputf.txt", "r", stdin);
// 	freopen("outputf.txt", "w", stdout);
// #endif

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

	int dp[n] = {};

	dp[0] = 0;
	dp[1] = abs(a[0] - a[1]);
	for (int i = 2; i < n; i++)
	{
		dp[i] += min(abs(a[i] - a[i - 1]) + dp[i - 1], abs(a[i] - a[i - 2]) + dp[i - 2]);
	}
	cout << dp[n - 1] << endl;
	return 0;

}

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

int main()
{
  ll N, M; cin >> N >> M;
  if ((M-2*N) >= 0) {
    cout << N + (M-2*N)/4 << endl;
  } else {
    cout << M/2 << endl;
  }
}

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

using namespace std;
typedef long long ll;

int main() {
    string s,t;
    int n,m;
    cin >> s >> t;
    n = s.length(),m = t.length();

    vector<vector<int>> dp(n+10,vector<int>(m+10));
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(s[i]==t[j]){
                dp[i+1][j+1]=max(dp[i][j]+1,max(dp[i+1][j],dp[i][j+1]));
            }else{
                dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
            }
        }
    }
    string ans="";
    int sx=n,tx=m;
    while(sx>0 && tx>0){
        if(dp[sx][tx]==dp[sx-1][tx]) sx--;
        else if(dp[sx][tx]==dp[sx][tx-1]) tx--;
        else{
            ans=t[tx-1]+ans;
            sx--;
            tx--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 35712
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  int x,y;
  cin>>x>>y;
  bool flag = false;
  if(x == 2) {
    if(y == 2) {
      flag = true;
    }
  } else if(x == 4 || x == 6 || x == 9 || x == 11) {
    if(y == 4 || y == 6 || y == 9 || y == 11) {
      flag = true;
    }
  } else {
    if(y != 2 && y != 4 && y != 6 && y != 9 && y != 11) {
      flag = true;
    }
  }
  if(flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import sys


class Bit:
    def __init__(self, n, arr):
        self.size = n
        self.tree = [0] + arr
        for i in range(1, n+1):
            if i + (i & -i) < n + 1:
                self.tree[i + (i & -i)] += self.tree[i]

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def range_sum(self, l, r):
        return self.sum(r) - self.sum(l)


def main():
    n, q = map(int, sys.stdin.buffer.readline().split())
    bit = Bit(n, list(map(int, sys.stdin.buffer.readline().split())))
    for x in sys.stdin.buffer.readlines():
        q, p, x = map(int, x.split())
        if q:
            print(bit.range_sum(p, x))
        else:
            bit.add(p+1, x)


if __name__ == "__main__":
    main()


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

int main()  
{   
    cin.tie(0); ios::sync_with_stdio(false);  
	
	int n, k;
	string s;
	cin >> n >> k >> s;
	s[k-1] = s[k-1] + 32;
	cout << s << endl;




	return 0;   
}  

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"sort"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

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

func main() {
	defer stdout.Flush()

	a := readInt()
	b := readInt()
	q := readInt()

	s := make([]int64, 0, a+2)
	s = append(s, -10000000000-1000)
	for i := 0; i < a; i++ {
		s = append(s, readInt64())
	}
	s = append(s, 20000000000+1000)

	t := make([]int64, 0, b+2)
	t = append(t, -10000000000-1000)
	for i := 0; i < b; i++ {
		t = append(t, readInt64())
	}
	t = append(t, 20000000000+1000)

	for i := 0; i < q; i++ {
		x := readInt64()
		i := sort.Search(len(s), func(i int) bool {
			return x <= s[i]
		})

		j := sort.Search(len(t), func(i int) bool {
			return x <= t[i]
		})

		var res int64 = math.MaxInt64
		for _, k := range []int{i - 1, i} {
			for _, l := range []int{j - 1, j} {
				res = minInt64(res, absInt64(x-s[k])+absInt64(s[k]-t[l]))
			}
		}
		for _, k := range []int{j - 1, j} {
			for _, l := range []int{i - 1, i} {
				res = minInt64(res, absInt64(x-t[k])+absInt64(t[k]-s[l]))
			}
		}

		println(res)
	}
}

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

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 6528
# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) ((x)%2)
typedef long long ll;
typedef long double ld;
const ll oo=2*1000*1000*1000;
const int _cnt=1000*1000;
const int _p=1000*1000*1000+7;
int o(int x) { return x%_p; }
int gcd(int a,int b) { return (b)?gcd(b,a%b):a; }
int lcm(int a,int b) { return a/gcd(a,b)*b; }
using namespace std;

void file_put(){
	freopen("filename.in","r",stdin);
	freopen("filename.out","w",stdout);
}

int n,a[205],ans[205];
string st; 

int main(){
	//file_put();
	
	scanf("%d",&n);
	cin.ignore();
	for (int i='a'; i<='z'; i++) ans[i]=oo;
	for (int i=1; i<=n; i++){
		cin>>st;
		cin.ignore();
		memset(a,0,sizeof(a));
		for (int j=0; j<st.length(); j++) a[st[j]]++;
		for (int j='a'; j<='z'; j++) ans[j]=min(ans[j],a[j]);
	}
	for (int i='a'; i<='z'; i++)
		for (int j=1; j<=ans[i]; j++)
			printf("%c",(char)i);
	printf("\n");
	
	return 0;
}


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

const int kN = 2e3 + 5;
const int kInf = 0x3f3f3f3f;

bool vis[kN]; std::vector<int> E[kN];
int k, n, ans = kInf;
void Dfs(int cur, int d) {
	if(d > k / 2) return;
	vis[cur] = true;
	for(int x : E[cur])
		if(!vis[x]) Dfs(x, d + 1);
}

int main() {
	scanf("%d%d", &n, &k);
	for(int i = 1; i < n; ++i) {
		int x, y; scanf("%d%d", &x, &y);
		E[x].push_back(y); E[y].push_back(x);
	}
	if(k & 1) {
		for(int i = 1; i <= n; ++i) for(int x : E[i]) if(x < i) {
			memset(vis, false, sizeof(vis));
			int tot = 0;
			vis[x] = true; Dfs(i, 0); Dfs(x, 0);
			for(int j = 1; j <= n; ++j)
				if(!vis[j]) ++tot;
			ans = std::min(ans, tot);
		}
	} else {
		for(int i = 1; i <= n; ++i) {
			memset(vis, false, sizeof(vis));
			int tot = 0;
			Dfs(i, 0);
			for(int j = 1; j <= n; ++j)
				if(!vis[j]) ++tot;
			ans = std::min(ans, tot);
		}
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
int main(void){
    
    int a, b, d, r;
    double f;
    
    scanf("%d %d", &a, &b);
    d = a / b;
    r = a % b;
    f = (double)a / b;
    printf("%d %d %f", d, r, f);
    
    return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int N;
  cin>>N;
  if(N==0){
    cout<<"a"<<endl;
    return 0;
  }
  int M=0;
  for(int i=1;i<=N;i*=26){
    M++;
    N-=i;
  }
  string S="";
  for(int i=0;i<M;i++)
    S+="a";
  for(int i=N;i>0;i/=26){
    S[M-1]='a'+i%26;
    M--;
  }
  cout<<S<<endl;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
 
int main(void){
  int n;
  cin >> n;
  VI s(n);  
  rep(i,n){
    cin >> s.at(i);
  }
  sort(s.begin(),s.end());
  int sum=0;
  rep(i,n){
    sum+=s.at(i);
  }
  bool a=true;
    if(sum%10==0){
    rep(i,n){
		if(s.at(i)%10==0){
          continue;
        }
      else if(s.at(i)%10!=0){
        sum-=s.at(i);
        a=false;
        break;
      }
    }
    }
  else a=false;
  if(a) cout << 0<< endl;
    else cout << sum << endl;

}

Measured memory_bytes: 256
#初期dataの格納
input_number,input_time = map(int, input().split())
input_data = list()
for i in range(input_number):
    input_data.append(list(input().split()))
    input_data[i][-1] = int(input_data[i][-1])

#アルゴリズム実行
temp_list = list()
total_time = 0
result_list = list()
while len(input_data) > 0:
    temp_list = input_data[0]
    if temp_list[-1] > input_time:
        total_time += input_time
        temp_list[-1] -= input_time
        input_data.append(temp_list)
    else:
        total_time += temp_list[-1]
        temp_list[-1] = total_time
        result_list.append(temp_list)
    del input_data[0]

#結果の表示
[print(" ".join(map(str, i))) for i in result_list]



Measured memory_bytes: 15920
#include <iostream>
#include <cmath>

using namespace std;

const int maxn=1e2+10;

const int maxw=1e5+10;

long long int dp[maxn][maxw];


int main()
{
    int n,w1;
    cin>>n>>w1;
    int w[n+1],v[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>w[i]>>v[i];
    }
    for(int i=1;i<=w1;i++)
    {
        if(i>=w[1])
            dp[1][i]=v[1];
        else dp[1][i]=0;
     //   cout<<dp[1][i]<<" ";
    }
 //   cout<<endl;
    for(int i=2;i<=n;i++)
    {
        for(int j=1;j<=w1;j++)
        {
            if(w[i]>j)
            {
                dp[i][j]=dp[i-1][j];
            }
            else dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
        //    cout<<dp[i][j]<<" ";
        }
      //  cout<<endl;
    }
    cout<<dp[n][w1];
	return 0;
}


Measured memory_bytes: 79488
#include <stdio.h>

int prime[10001];
void setprime(void){
    int i,o;
    for(i=4;i<=10000;i+=2)
        prime[i]=1;
    for(i=3;i*i<=10000;i+=2)
        if(!prime[i])
            for(o=i*2;o<=10000;o+=i)
                prime[o]=1;
    prime[1]=1;
}
int main(void){
    int num,sum,c;
    setprime();
    for(;c=1,sum=0,scanf("%d",&num)!=EOF;){
        for(;num;num--,c++)
            if(prime[num]==0&&prime[c]==0)
                sum++;
        printf("%d\n",sum);
    }
    return 0;
}

Measured memory_bytes: 632
import sys
from decimal import Decimal
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


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


def main():
    A, B = readstrs()
    A = Decimal(A)
    B = Decimal(B)
    print(int(Decimal(A * B)))


if __name__ == "__main__":
    main()


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

int digit_sum (int n);

int main () {

    int N, K;

    scanf("%d %d", &N, &K);

    int A[N];

    for (int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }

    int rest = max(N - K, 0);
    int ans = 1 + (rest + (K - 2)) / (K - 1);

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

    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>

int judge(int a, int b, int c){
    if(a < b + c){
        if(b < c + a){
            if(c < b + a){
                return 1;
            }
        }
    }
    return 0;
}

int main(){
    int n, i=0, j, k, ans=0;
    int l[2000];
    
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%d", &l[i]);
    }
    i = 0;
    while(i < n){
        j = i + 1;
        k = j + 1;
        while(j < n){
            while(k < n){
                ans += judge(l[i], l[j], l[k]);
                k += 1;
            }
            j += 1;
            k = j + 1;
        }
        i += 1;
    }
    printf("%d", ans);
    
    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define EPS 1e-10
#define INF 1000000005
#define mp make_pair
#define pb push_back

typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pii;
typedef long long ll;

ll parseInt(string str) {
  ll rep;
  bool isNegative = false;
  if (str[0] == '-') {
    isNegative = true;
    str = str.substr(1);
  }
  rep = str[0] - '0';
  for (int i = 1; i < str.size(); i++) {
    int num = str[i] - '0';
    rep = rep * 10 + num;
  }
  if (isNegative) {
    rep *= -1;
  }
  return rep;
}

void solve(vector<string> signals) {
  ll floor = -1 * INF, ceiling = INF;
  for (int i = 1; i < signals.size(); i++) {
    string signal = signals[i], prev = signals[i-1];
    if (signal == "x") {
      if (prev == "x") { // xx
        cout << "none" << endl;
        return;
      } else { // ?x
        ll ll_prev = parseInt(prev);
        if (i % 2 == 0) { // even
          floor = max(floor, ll_prev + 1);
        } else { // odd
          ceiling = min(ceiling, ll_prev - 1);
        }
      }
    } else {
      if (prev == "x") { // x?
        ll ll_signal = parseInt(signal);
        if (i % 2 == 0) { // even
          ceiling = min(ceiling, ll_signal - 1);
        } else { // odd
          floor = max(floor, ll_signal + 1);
        }
      } else { // ??
        ll ll_signal = parseInt(signal),
           ll_prev   = parseInt(prev);
        if ((i % 2 == 0 && ll_prev >= ll_signal) || (i % 2 == 1 && ll_prev <= ll_signal)) {
          cout << "none" << endl;
          return;
        }
        continue;
      }
    }
  }

  if (floor == ceiling) {
    cout << floor << endl;
  } else if (floor < ceiling) {
    cout << "ambiguous" << endl;
  } else {
    cout << "none" << endl;
  }
}

int main() {
  while (1) {
    int N;
    cin >> N;
    if (N == 0) {
      break;
    }
    vector<string> signals(N+1);
    signals[0] = "1000000005";
    for (int i = 1; i <= N; i++) {
      cin >> signals[i];
    }
    solve(signals);
  }
}

Measured memory_bytes: 1284
import java.util.*;
import static java.lang.System.*;

public class Main{
  public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
	  
	  int N = sc.nextInt();
	  int[] d = new int[N];
	  for(int i=0; i<N; i++)
		  d[i] = sc.nextInt();
	 
	  Arrays.sort(d);
	  
	  int a = d[N/2 - 1];
	  int b = d[N/2];
	  int ans = b-a;
	  
	  out.print(ans);
  	}
  }	 

Measured memory_bytes: 48676
n=int(input())

a=[0]*n
b=[0]*n
c=[0]*n
dp=[ [0]*n for _ in range(3)]

for i in range(n):
    a[i], b[i], c[i] = map(int, input().split())

dp[0]=[a[0], b[0], c[0]]
for i in range(1,n):
    a[i]=a[i]+max(b[i-1], c[i-1])
    b[i]=b[i]+max(a[i-1], c[i-1])
    c[i]=c[i]+max(a[i-1], b[i-1])

n=n-1

print(max(a[n], b[n], c[n]))

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

int main () {
  int N, A, B;
  cin >> N >> A >> B;
  
  cout << min(A,B) << " ";
  if (A + B <= N) {
    cout << 0 << endl;
  }
  else {
    cout << A + B - N << endl;
  }
}

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

int main(){
    int N, L;
    cin >> N >> L;
    vector<string> S;
    for (int i = 0; i < N; ++i){
        string s;
        cin >> s;
        S.push_back(s);
    }
    sort(S.begin(), S.end());
    string ans = "";
    for (int i = 0; i < N; ++i) ans += S[i];
    cout << ans << endl;
}

Measured memory_bytes: 256
# DPをとく
inf=10**10
N=int(input())
H=list(map(int,input().split()))
dp = [inf for _ in range(N)] # 足場Nまでにたどり着くときの最小コストとする
dp[0]=0
for i in range(N):
    if i+1<N:
        dp[i+1] = min(dp[i+1],dp[i]+abs(H[i+1]-H[i]))
    if i+2<N:
        dp[i+2] = min(dp[i+2],dp[i]+abs(H[i+2]-H[i]))
print(dp[N-1])


Measured memory_bytes: 13924
#include<stdio.h>

int main()
{
int N;
int K;
int x;
int i;
int distance=0;
int dista;
int distb;

scanf("%d %d",&N,&K);
for(i=0;i<N;i++)
{
 scanf("%d",&x);
 dista=2*x;
 if((K-x)>=0)
 { 
   distb=2*(K-x);
 }else{
   distb=2*(x-K);
 }
 if(dista>distb)
 {
  distance+=distb;
 }else{
  distance+=dista;
 }
}

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


return 0;
}


Measured memory_bytes: 128
a,b,c,d = list(map(int,input().split()))
ans = 0
if b % c == 0:
    ans += b//c
else:
    ans += (b- (b%c)) //c

if (a-1) % c == 0:
    ans -= (a-1)//c
else:
    ans -= ((a-1)- ((a-1)%c)) //c

ans = int(ans)
if b % d == 0:
    ans += b//d
else:
    ans += (b- (b%d)) //d

if (a-1) % d == 0:
    ans -= (a-1)//d
else:
    ans -= ((a-1)- ((a-1)%d)) //d
ans = int(ans)
e = c*d

c_2 = c
d_2 = d
if (c_2< d_2):
    tmp = c_2
    c_2 = d_2
    d_2 = tmp
r = c_2 % d_2
while r != 0:
    c_2 = d_2
    d_2 = r
    r = c_2 % d_2
e = int(e //d_2)

ans2 = 0


if b % e == 0:
    ans2 += b//e
else:
    ans2 += (b- (b%e)) //e
if (a-1) % e == 0:
    ans2 -= (a-1)//e
else:
    ans2 -= ((a-1)- ((a-1)%e)) //e

sa = ans - ans2
print(int(b-a+1-sa))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000],arr1[1000000],arr2[1000000],arr3[1000000],arr4[1000000];
int main()
{
	long long t,i,j,x,y,a,b,c,ans,p,q,r,rr,gg,z;
	ans=0;
	cin>>x>>y>>a>>b>>c;
	for (i=0;i<a;i++)
	{
		cin>>arr[i];
	}
	for (i=0;i<b;i++)
	{
		cin>>arr1[i];
	}
	for (i=0;i<c;i++)
	{
		cin>>arr2[i];
	}
	sort(arr,arr+a);
	sort(arr1,arr1+b);
	sort(arr2,arr2+c);
	rr=0;
	for (i=a-1;i>a-1-x;i--)
	{
		ans+=arr[i];
		arr3[rr]=arr[i];
		rr++;
	}
	//cout<<ans<<endl;
	for (j=b-1;j>b-1-y;j--)
	{
		ans+=arr1[j];
		arr3[rr]=arr1[j];
		rr++;
	}	
	//cout<<ans<<endl;
	sort (arr3,arr3+rr);
	gg=0;
	z=c-x-y;
	z=fmax(z,0);
	for (i=c-1;i>=z;i--)
	{
		arr4[gg]=arr2[i];
		gg++;
	}
	gg=0;
	for (i=0;i<rr;i++)
	{
		if (arr4[gg]>arr3[i])
		{
			ans=ans-arr3[i]+arr4[gg];
			gg++;
		}
	}
	cout<<ans<<endl;
}

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

int main(){
    int N,X;
    cin >> N >> X;
    vector<int> x(N+1);
    rep(i,N) cin >> x[i];
    x[N]=X;
    sort(x.begin(),x.end());
    // 差分の最大公約数
    int ans = x[1]-x[0];
    for(int i=1;i<=N;i++){
        ans = __gcd(x[i]-x[i-1],ans);
    }
    
    cout << ans << endl;
    return 0;
}

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

namespace aaaa
{
	class Program
	{
		public static void Main(string[] args)
		{
			var s = "";
			var l = new List<int>();
			while((s = Console.ReadLine()) != null)
			{
				l.Add(int.Parse(s));
			}
			var arr = l.ToArray();
			Array.Sort(arr, (x, y) => y - x);
			for(var i = 0; i < 3; i++)
			{
				Console.WriteLine(arr[i]);
			}
		}
	}
}

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

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<double, double> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

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

    auto f = [](int i) {
        if (i == 3) return 100000;
        if (i == 2) return 200000;
        if (i == 1) return 300000;
        return 0;
    };

    int ans = [&] {
        if (x == 1 && y == 1) return 1000000;
        return f(x) + f(y);
    }();
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int main(){
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    int n = div_ceil(c, b), m = div_ceil(a, d);
    puts(m >= n ? "Yes" : "No");
}

Measured memory_bytes: 3656