akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  cin>>n;
  int a[n][n];
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      cin>>a[i][j];
  int ans=0;
  bool used[n];
  memset(used,0,sizeof(used));
  used[0]=1;
  int cost[n];
  for(int i=0;i<n;i++) cost[i]=a[0][i];
  while(1){
    int v=-1;
    for(int i=0;i<n;i++){
      if(used[i]||cost[i]<0) continue;
      //cout<<i<<":"<<cost[i]<<endl;
      if(v<0||cost[i]<cost[v]) v=i;
    }
    if(v<0) break;
    used[v]=1;
    ans+=cost[v];
    //cout<<v<<endl;
    for(int i=0;i<n;i++){
      if(a[v][i]<0) continue;
      if(cost[i]<0||a[v][i]<cost[i]) cost[i]=a[v][i];
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3092
#include <stdio.h>
#include <iostream>
#include <queue>
#include <cstdio>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string.h>
#include <limits.h>
#include <map>
#include <string>
#include <bitset>
#include <vector>
using namespace std;
int main() {
    long long a,b;
    cin>>a>>b;
    a%=b;
    if(b-a<a) a=b-a;
    printf("%lld\n",a);
    return 0;
}


Measured memory_bytes: 3680
from fractions import gcd
a,b,c,d = map(int, input().split())
x = (c*d) // gcd(c,d)
c1, d1, cd1 = b // c, b // d, b // x
c2, d2, cd2 = (a-1) // c, (a-1) // d, (a-1) // x
ans = (c1+d1-cd1) - (c2+d2-cd2)
print(b-a+1-ans)

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


#define ll long long
#define pll pair <ll,ll>
#define fi first
#define se second
#define endl "\n"
#define sqr(b) (b)*(b)


using namespace std;



int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//    freopen("", "r", stdin);
//    freopen("", "w", stdout);

    ll n, k;
    ll a[111111], f[111111];

    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        f[i] = 2e9;
    }

    f[1] = 0;
    for (int i = 1; i <= n - 1; i++) {
        for (int j = 1; j <= k; j++)
            f[i + j] = min(f[i + j], f[i] + abs(a[i] - a[i + j]));
    }

    cout << f[n] << endl;

    return 0;
}


Measured memory_bytes: 5164
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=(a),_ed=(b);i<=_ed;++i)
#define DREP(i,a,b) for(int i=(a),_ed=(b);i>=_ed;--i)
#define mp(x,y) make_pair((x),(y))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
inline int read(){
    register int x=0,f=1;register char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=0;ch=getchar();}
    while(isdigit(ch)){x=x*10+(ch^'0');ch=getchar();}
    return f?x:-x;
}

const int mod=998244353;
int n,m,fac[8005],ifc[8005],f[8005],g[17000],A[17000];
inline void inc(int& x,int y){x=x+y<mod?x+y:x+y-mod;}
inline int power(int b,int n){int ans=1;for(;n;n>>=1,b=1ll*b*b%mod)if(n&1)ans=1ll*ans*b%mod;return ans;}
inline int C(int n,int m){return (n<0||m<0||n<m)?0:1ll*fac[n]*ifc[m]%mod*ifc[n-m]%mod;}

int trans[17000],w[17000];
void NTT(int* a,int n){
	static ull f[17000];
	REP(i,0,n-1)f[i]=a[i];
	REP(i,0,n-1)if(i<trans[i])swap(f[i],f[trans[i]]);
	for(int len=2,d=1;len<=n;d=len,len<<=1)
		for(int p=0;p<n;p+=len)
			for(int i=p;i<p+d;++i){
				int t=f[i+d]*w[d+i-p]%mod;
				f[i+d]=f[i]+mod-t,f[i]+=t;
			}
	REP(i,0,n-1)a[i]=f[i]%mod;
}
void times(int* f,int* a,int m1,int m2,int lim){
	static int g[17000];
	int n=1;for(;n<m1+m2-1;n<<=1);
	REP(i,0,n-1)trans[i]=(trans[i>>1]>>1)|(i&1?(n>>1):0);
	for(int len=2,d=1;len<=n;d=len,len<<=1){
		int e=power(3,(mod-1)/len);
		REP(i,w[d]=1,d-1)w[d+i]=1ll*w[d+i-1]*e%mod;
	}
	REP(i,m1,n-1)f[i]=0;REP(i,0,m2-1)g[i]=a[i];REP(i,m2,n-1)g[i]=0;
	NTT(f,n),NTT(g,n);
	REP(i,0,n-1)f[i]=1ll*f[i]*g[i]%mod;
	NTT(f,n);int inv=power(n,mod-2);
	reverse(f+1,f+n);
	REP(i,0,lim-1)f[i]=1ll*f[i]*inv%mod;
	REP(i,lim,n-1)f[i]=0;
}

int main(){
	// freopen("matrix.in","r",stdin);
	// freopen("matrix.out","w",stdout);
	REP(i,fac[0]=1,8004)fac[i]=1ll*fac[i-1]*i%mod;
	ifc[8004]=power(fac[8004],mod-2);
	DREP(i,8004,1)ifc[i-1]=1ll*ifc[i]*i%mod;
	n=read(),m=read();
	REP(i,0,n)f[i]=1;
	REP(i,3,n)A[i]=ifc[i];
	REP(t,1,m){
		memcpy(g,f,sizeof f);
		memset(f,0,sizeof f);
		REP(i,0,n){
			inc(f[i],1ll*C(i,0)*g[i]%mod);
			inc(f[i],1ll*C(i,1)*g[i]%mod);
			inc(f[i],1ll*C(i,2)*g[i]%mod);
		}
		g[0]=g[1]=0;
		REP(i,2,n)g[i]=1ll*g[i]*ifc[i-2]%mod;
		times(g,A,n+1,n+1,n+3);
		REP(i,0,n)inc(f[i],1ll*g[i+2]*fac[i]%mod);
	}
	printf("%d\n",f[n]);
	return 0;
}


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

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

#define FOR(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define REP(i,n) FOR(i,0,n)

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)

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; }

using ll = long long;

int main() {
  int n; cin >> n;
  vector<int> a(n);
  REP(i,n) cin >> a[i];
  deque<int> q;
  bool f = false;
  if (n%2) f = true;
  REP(i,n) {
    if (f) q.push_front(a[i]);
    else q.push_back(a[i]);
    f = !f;
  }
  for (int i : q) cout << i << " ";
  cout << endl;
  return 0;
}


Measured memory_bytes: 3840
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int N;
    cin >> N;
    vector<int> d(N);
    rep(i, 0, N) cin >> d[i];
    sort(all(d));
    int ans = 0;
    for (int K = 1; K <= 100000; ++K)
    {
        const auto it = lower_bound(all(d), K);
        if (it - d.begin() == N / 2)
        {
            ++ans;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ll;
const int INF = 1<<30;

int main(){
  int x, a, b;cin>>x>>a>>b;
  string ans;
  if(b-a<=0)ans="delicious";
  else if(b-a<=x)ans="safe";
  else ans="dangerous";
  cout<<ans<<endl;
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

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

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U>
void chmax(T &a, U b) {
  if (a < b) a = b;
}

template <class T, class U>
void chmin(T &a, U b) {
  if (b < a) a = b;
}

template <class T>
T Sq(const T &t) {
  return t * t;
}

signed main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int dx = x2 - x1, dy = y2 - y1;
  int x = x2, y = y2;
  REP(i, 2) {
    swap(dx, dy);
    dx = dx * -1;
    x += dx;
    y += dy;
    print(x, 2);
    print(y, 2);
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n;
  scanf("%d",&n);
  
  int p[n];
  for(int i=0; i<n; i++){
    scanf("%d",&p[i]);
  }
  
  int count = 0;
  for(int j=1; j<n-1; j++){
    if(p[j] != max(p[j-1],p[j],p[j+1]) && p[j] != min(p[j-1],p[j],p[j+1])) count++;
  }
  printf("%d",count);
}

int max(int a, int b, int c){
  int d = a;
  if(d<b) d = b;
  if(d<c) d = c;
  return d;
}

int min(int a, int b, int c){
  int d = a;
  if(d>b) d = b;
  if(d>c) d = c;
  return d;
}

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

int minRemovals(int n, vector<int> &a) {
	if(n==1 && a[0]!=1)
		return 1;
	int ans=0;
	unordered_map<int, int> freq;
	for(int i=0; i<n; i++)
		freq[a[i]]++;
	for(int i=0; i<n; i++) {
		if(freq.find(a[i])!=freq.end()) {
			if(freq[a[i]]==a[i])
			{	// do nothing
			}
			else if(freq[a[i]]<a[i])
				ans+=freq[a[i]];
			else
				ans+=(freq[a[i]]-a[i]);
			freq.erase(a[i]);
		}
	}
	return ans;
}

signed main() {
	// your code goes here
	int n, input;
	cin>>n;
	vector<int> a;
	for(int i=0; i<n; i++) {
		cin>>input;
		a.push_back(input);
	}
	cout<<minRemovals(n, a);
	return 0;
}

Measured memory_bytes: 4980
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;
template<typename T>
struct Edge {
    int u, v;
    T cost;
    Edge(int u, int v, T c) : u(u), v(v), cost(c) {}
    bool operator< (const Edge &e) const {return cost < e.cost;}
};

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

struct UnionFind {
	vector<int> par;
	vector<int> rank;
	vector<long long> Size; //連結成分の総数
 
	UnionFind(int n)  {
	      par.resize(n+1); rank.resize(n+1); Size.resize(n+1);
		for(int i = 0; i <= n; i++) {par[i] = i; rank[i] = 0; Size[i] = 1;}
	}
 
	int find(int x) {if (par[x]==x) return x; else return par[x] = find(par[x]);}
	bool unite(int x, int y) {
        x = find(x); y = find(y);
        if (x==y) return false;
 
        if (rank[x]<rank[y]) swap(x, y);
        if (rank[x]==rank[y]) rank[x]++;
        par[y] = x;
        Size[x] += Size[y];
        return true;
  }
	bool same(int x, int y) {return find(x)==find(y);}
	long long size(int i) {return Size[find(i)];}
};

ll ans = -1;

int main(void) {
    int N, M;
    cin >> N >> M;
    UnionFind uf(N+5);
    rep(i, 0, M) {
        int A, B;
        cin >> A >> B;
        uf.unite(A, B);
    }

    rep(i, 1, N+1) ans = max(ans, uf.size(i));

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





Measured memory_bytes: 6424
#include <bits/stdc++.h>
using namespace std;
#define rc(s) return cout<<s,0
string a[10000];
int n,l;
int main(){
    cin >> n >> l;
    for(int i=1;i<=n;i++) cin >> a[i];
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++) cout<<a[i];
    
    
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )

#define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

string conv( string str )
{
	OSS oss;
	int count;
	char prev = ' ', cur;

	REP( i, 0, str.size() )
	{
		if ( str[i] != prev )
		{
			if ( prev != ' ' )
			{
				oss << count << prev;
			}

			prev = str[i];
			count = 1;
		}
		else
		{
			count++;
		}
	}
	oss << count << prev;
	return oss.str();
}

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

	while ( true )
	{
		int n;
		cin >> n;

		if ( !n )
		{
			break;
		}

		string str;
		cin >> str;

		REP( i, 0, n )
		{
			str = conv( str );
		}
		cout << str << endl;
	}

	return 0;
}

Measured memory_bytes: 1404
#include <iostream>

using namespace std;

int main()
{
    int N = 0 , AC = 0 , WA = 0 , TLE = 0 , RE = 0;
    cin >> N;
    string S ;
    for(int i = 0 ; i < N ; ++i)
    {
        cin >> S ;
        if(S == "AC")
            AC++ ;
        else if (S == "WA")
            WA++;
        else if (S == "TLE")
            TLE ++ ;
        else
            RE++ ;
    }
    cout << "AC x " << AC << "\n"
         << "WA x " << WA << "\n"
         << "TLE x "<< TLE<< "\n"
         << "RE x " << RE << "\n" ;
    return 0;
}


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

int main() {
    int t,x;cin >> t >> x;
    cout << (t*1.0)/(x*1.0) << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public void Solve()
        {
            var inputs = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray();
            var N = inputs[0];
            var K = inputs[1];
            var S = Console.ReadLine();

            var answer = string.Empty;
            for (int i = 0; i < S.Length; i++)
            {
                var c = (i == (K - 1)) ? S[i].ToString().ToLower() : S[i].ToString();
                answer += c;
            }

            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
#define pb emplace_back
#define int long long
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=998244353;

int32_t main(){
	IOS;
	string s;
	cin>>s;
	int a=0;
	for(int i=0;i<(int)s.length()/2;i++){
		if(s[i]!=s[(int)s.length()-1-i]) a++;
	}
	cout<<a<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<double, double> pd;
typedef pair<ll, ll> pl;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;

typedef double D;
typedef complex<D> P;
typedef pair<P, P> L;
typedef vector<P> VP;
const D EPS = 1e-9;
#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)

D dot(P a, P b) {
  return (conj(a)*b).X;
}

P proj(P a1, P a2, P p) {
  return a1 + dot(a2-a1, p-a1)/norm(a2-a1) * (a2-a1);
}

VP crosspointLC(P a1, P a2, P c, D r) {
    VP ps;
    P ft = proj(a1, a2, c);
    if (!GE(r*r, norm(ft-c))) return ps;

    P dir = sqrt(max(r*r - norm(ft-c), 0.0)) / abs(a2-a1) * (a2-a1);
    ps.push_back(ft + dir);
    if (!EQ(r*r, norm(ft-c))) ps.push_back(ft - dir);
    return ps;
}

int n;
double x[50000], r[50000];

void solve() {
    rep(i,n) {
        cin >> x[i] >> r[i];
    }
    double le = 0.0, ri = 200000.0;
    rep(i,100) {
        double mid = (le + ri) / 2.0;
        P ho = P(0.0, mid), ge = P(1.0, mid);
        double nowl = -1000000.0, nowr = -1000000.0;
        bool ok = false;
        vector<pd> vd;
        rep(j,n) {
            VP vp = crosspointLC(ho, ge, P(x[j],0.0), r[j]);
            if (vp.size() != 2) continue;
            if (vp[0].X < vp[1].X) {
                vd.push_back(pd(vp[0].X, vp[1].X));
            } else {
                vd.push_back(pd(vp[1].X, vp[0].X));
            }
        }
        sort(vd.begin(), vd.end());
        rep(j,vd.size()) {
            if (nowr < vd[j].first) {
                nowl = vd[j].first;
                nowr = vd[j].second;
            } else {
                nowr = max(nowr, vd[j].second);
            }
            if (GE(nowr-nowl,2*mid)) {
                ok = true;
                break;
            }
        }
        if (ok) le = mid;
        else ri = mid;
    }
    printf("%.9f\n", le*2);
}

int main() {
    while (cin >> n) {
        if (n == 0) break;
        solve();
    }
}



Measured memory_bytes: 5428
package main

import "fmt"

func main() {
	var n,a,b int64
	fmt.Scan(&n, &a, &b)

	times := n / (a + b)
	n = n - times * (a + b)
	count := times * a
	if n > a {
		count = count + a
	} else {
		count = count + n
	}
	fmt.Println(count)
}

Measured memory_bytes: 512
//--- pE ---//
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
	public static void main (String[] args) throws java.lang.Exception {
		new Solution();
	}
}
class Solution {
	Reader reader;
	public Solution () {
		reader = new Reader();
		while (reader.hasNext()) {
			run_case();
		}
	}

	int inf = (int)1e9+5;
	private void run_case() {
		int X = reader.ni();
		int Y = reader.ni();
		int A = reader.ni();
		int B = reader.ni();
		int C = reader.ni();

		Integer[] arr_a = new Integer[A];
		Integer[] arr_b = new Integer[B];
		Integer[] arr_c = new Integer[C];

		for (int i=0; i<A; i++) arr_a[i] = reader.ni();
		for (int i=0; i<B; i++) arr_b[i] = reader.ni();
		for (int i=0; i<C; i++) arr_c[i] = reader.ni();

		Arrays.sort(arr_a, Collections.reverseOrder());
		Arrays.sort(arr_b, Collections.reverseOrder());
		Arrays.sort(arr_c, Collections.reverseOrder());

		int iter_a = X - 1, iter_b = Y - 1, iter_c = 0;

		while (true) {
			int a = iter_a >= 0 ? arr_a[iter_a] : inf;
			int b = iter_b >= 0 ? arr_b[iter_b] : inf;

			if (iter_c == C || Math.min(a, b) >= arr_c[iter_c]) {
				break;
			}

			if (a < b) {
				iter_a --;
				iter_c ++;
			} else {
				iter_b --;
				iter_c ++;
			}
		}

		long res = 0;
		for (int i=0; i<=iter_a; i++) res += arr_a[i];
		for (int i=0; i<=iter_b; i++) res += arr_b[i];
		for (int i=0; i<iter_c; i++) res += arr_c[i];

		System.out.println(res);

		return;
	}
}


class Reader {
	BufferedReader br;
	StringTokenizer st;
	public Reader(){
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public String next() {
		if (st.hasMoreTokens()) return st.nextToken();
		try {
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return st.nextToken();
	}
	public boolean hasNext() {
		try {
			if (!st.hasMoreTokens() && !br.ready()) return false;
			else return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
	public int ni() {return Integer.parseInt(this.next());}
	public String ns() {return this.next();}
}


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

N = int(input())
B = [int(x) for x in input().split()]

def F(arr):
    # (最後に挿入する数、挿入前のarray) を返す
    L = len(arr)
    x = None
    for i,y in enumerate(arr[::-1]):
        if L - i == y:
            x = y
            break
    if x is None:
        return None,None
    return x, arr[:x-1] + arr[x:]

answer = []
while B:
    x, B = F(B)
    if x is None:
        answer = [-1]
        break
    answer.append(x)
answer = answer[::-1]

print('\n'.join(map(str,answer)))

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

int main(){
    int n;
    cin >> n;
    ll a[n], b[n], c[n];
    ll suma = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        suma += a[i];
    }
    ll sumc = 0;
    for(int i = 0; i < n; i++){
        cin >> b[i];
        // どれだけ足りてないか
        c[i] = a[i] - b[i];
        sumc += c[i];
    }
    if(sumc < 0){
        cout << -1 << endl;
        return 0;
    }
    int f = 1, cnt = 0;
    vector<ll> ma;
    ll mi = 0;
    for(int i = 0; i < n; i++){
        if(c[i] < 0) f = 0, cnt++;
        if(c[i] > 0) ma.push_back(c[i]);
        if(c[i] < 0) mi += c[i];
    }
    if(f){
        cout << 0 << endl;
        return 0;
    }
    sort(ma.begin(), ma.end());
    reverse(ma.begin(), ma.end());
    for(int i = 0; i < ma.size(); i++){
        mi += ma[i];
        if(mi >= 0){
            cout << cnt + i + 1 << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3324
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define ll long long
//#define cccgift
//#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
template<typename T>
inline void read(T &x)
{
    static char ch;bool f=1;
    for(x=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') f=0;
    for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=getchar());x=f?x:-x;
}
template<typename T>
void print(T x)
{
    if (x<0) x=-x,putchar('-');
    if (x>9) print(x/10);
    putchar(x%10+48);
}
template<typename T>
inline void print(T x,char ap) {print(x);if (ap) putchar(ap);}
template<typename T>
inline void chkmax(T &x,const T &y) {x=x<y?y:x;}
template<typename T>
inline void chkmin(T &x,const T &y) {x=x<y?x:y;}
const int mod=1e9+7;
int n,ver[400001],nxt[400001],head[200001],ans,x,y,tot,len[200001];
#define inc(x,y) x+=y,x>=mod?x-=mod:0
#define dec(x,y) x-=y,x<0?x+=mod:0
inline int kuai(int p,int q,int mod) {int tot=1;for(;q;p=(ll)p*p%mod,q>>=1) if(q&1) tot=(ll)tot*p%mod;return tot;}
void dfs(int x,int fa) {
	inc(tot,kuai(2,n-1,mod)-1),len[x]=1;
	for(res i=head[x];i;i=nxt[i]) {
		if(ver[i]==fa) continue;
		dfs(ver[i],x),dec(tot,kuai(2,len[ver[i]],mod)-1),len[x]+=len[ver[i]];
	}
	dec(tot,kuai(2,n-len[x],mod)-1);
}
inline void add(int x,int y) {ver[++ans]=y,nxt[ans]=head[x],head[x]=ans;}
int main()
{
	read(n);
	for(res i=1;i<n;++i) read(x),read(y),add(x,y),add(y,x);
	dfs(1,0),print((ll)tot*kuai(kuai(2,n,mod),mod-2,mod)%mod,'\n');
	return 0;
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do something instead of nothing and stay organized
*/ 

Measured memory_bytes: 11648
#include<stdio.h>
#include<string.h>
int MAX(int a,int b){return a<b?b:a;}
int strint(char* a){
  int n,i;
  for(i=n=0;a[i];i++)n=n*10+a[i]-'0';
  return n;
}
int main(){
  int i,j,l,r,d[100][100]={0};
  char *c,s[1000];
  for(l=0;~scanf("%s",s);l++){
    c=strtok(s,",\0");
    d[l][r=1]=strint(c);
    while(c=strtok(NULL,",\0"))d[l][++r]=strint(c);
  }
  for(i=1;i<l/2;i++){
    for(j=0;j<l;j++)d[i][j]+=MAX(d[i-1][j-1],d[i-1][j]);
  }
  for(;i<l;i++){
    for(j=0;j<l;j++)d[i][j]+=MAX(d[i-1][j],d[i-1][j+1]);
  }
  for(i=j=0;i<l;i++)j=MAX(j,d[l-1][i]);
  printf("%d\n",j);
  return 0;
}

Measured memory_bytes: 592
N, W = map(int, input().split())
w, v = [0] * N, [0] * N

for i in range(N):
    w[i], v[i] = map(int, input().split())

dp = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(N):
    for j in range(W + 1):
        if j >= w[i]:
            dp[i + 1][j] = dp[i][j - w[i]] + v[i]

        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])

print(dp[N][W])


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int N,Q;
vector<int> E[202020];
ll V[202020];

void dfs(int cur,int pre,ll v) {
	V[cur]+=v;
	FORR(e,E[cur]) if(e!=pre) {
		dfs(e,cur,V[cur]);
	}
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>Q;
	FOR(i,N-1) {
		cin>>x>>y;
		E[x-1].push_back(y-1);
		E[y-1].push_back(x-1);
	}
	FOR(i,Q) {
		cin>>x>>y;
		V[x-1]+=y;
	}
	
	dfs(0,-1,0);
	FOR(i,N) cout<<V[i]<<" ";
	cout<<endl;
		
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

int main() {
	float max,min;
	float input;
	
	cin >> input;
	max = input;
	min = input;
	while ( cin >> input ) {
		if ( input < min )
			min = input;
		else if ( input > max )
			max = input;
	}
	cout << max - min << endl;
}

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

#define rep(i, o) for (int i = 0; i < (o); ++i)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)

typedef long long ll;


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

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

  map<string, int> s;
  rep(i, n) {
      string str;
      cin >> str;
      s.insert(make_pair(str, 1));
  }


  cout << s.size() << endl;
  return 0;
}

Measured memory_bytes: 19228
#include<iostream>
using namespace std;
int main()
{
  int a,m1,b,m2,k,x,y,z;
  cin>>a>>m1>>b>>m2>>k;
  a=a*60;
  b=b*60;
  x=a+m1;
  y=b+m2;
  z=y-x-k;
  if(y-x<=k)
    cout<<"0";
  else
    cout<<z;
  
}

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

//macro-----------------------------------------------------------------------------------------
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i=a;i>b;i--)
#define int long long

//constant--------------------------------------------------------------------------------------
const int inf = 100100100100000;
const int mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//general_method--------------------------------------------------------------------------------
vector<int> cs(vector<int> arr){vector<int> ret = arr;rep(i,1,arr.size()){ret[i] += ret[i-1];}return ret;}
int ceil(int a, int b){if(a%b == 0) return a/b;else return a/b + 1;}
int digitlen(int i){int t = i;int count = 0;while(t){count += 1;t /= 10;}return count;}
int gcd(int m, int n){if((0== m)||(0 == n))return 0;while(m != n){if(m > n)m = m - n;else n = n - m;}return m;}
int lcm(int n, int m){return n*m/gcd(n,m);}

//io_method-------------------------------------------------------------------------------------
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
void print(int n){cout << n << endl;}
void print(vector<int> arr){cout << arr[0];rep(i,1,arr.size()) cout << " " << arr[i];cout << endl;}
void print(string s){cout << s << endl;}
void print(pair<int, int> p){cout << p.first << " " << p.second;}
void print(vector<vector<int>> arr){rep(i,0,arr.size()){print(arr[i]);}}

//main------------------------------------------------------------------------------------------


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

    int a,b, c; cin >> a >> b >> c;

    print(max({a,b,c})*10+ (a+b+c)-max({a,b,c}));

}

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

int
main (
  int   argc,
  char *argv[ ]
  )
{
  int *d;
  int r, c;
  int i, j;

  scanf ( "%d%d", &r, &c );
  d = calloc ( c + 1, sizeof ( int ) );
  if ( d == NULL ) return ( 1 );

  for ( i = 0; i < r; ++i )
  {
    int sum = 0;

    for ( j = 0; j < c; ++j )
    {
      int t;

      scanf ( "%d", &t );
      printf ( "%d ", t );
      d[ j ] += t;
      sum    += t;
    }

    printf ( "%d\n", sum );
    d[ c ] += sum;
  }

  for ( i = 0; i <= c; ++i )
  {
    printf ( "%d", d[ i ] );
    putchar ( i == c ? '\n' : ' ' );
  }
  free ( d );

  return ( 0 );
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  string s; cin>>s;
  ll n=s.size();
  
  ll ans=0;
  vll dp(2100);
  
  rep(i,n){
    vll ndp(2100);
    ll num=s[i]-'0';
    ndp[num]=1;
    rep(j,2019){
      ll nj=(j*10+num)%2019;
      ndp[nj]+=dp[j];
    }
    ans+=ndp[0];
    dp=ndp;
  }
  cout<<ans<<endl;
}

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

long long int items[3005][3005];
long long int dp[3005][3005][4];

int main() {
  int r, c, k;
  scanf("%d%d%d", &r, &c, &k);
  for (int l = 0; l < k; l ++) {
    int i, j, v;
    scanf("%d%d%d", &i, &j, &v);
    items[i][j] = v;
  }
  for (int i = 1; i <= r; i++) {
    for (int j = 1; j <= c; j++) {
      for (int m = 0; m < 4; m++) {
        dp[i][j][m] = max(dp[i - 1][j][3], dp[i][j - 1][m]);
      }
      if (items[i][j] > 0) {
        for (int m = 2; m >= 0; m--) {
          dp[i][j][m + 1] = max(dp[i][j][m + 1], dp[i][j][m] + items[i][j]);
        }
      }
    }
  }

  printf("%lld\n", dp[r][c][3]);
  return 0;
}


Measured memory_bytes: 355864
while True:
    H,W=map(int,input().split())
    if H==0 and W==0:
        break
    for i in range(H):
        for j in range(W):
            if (i+j)%2==0:
                print('#',end='')
            else:
                print('.',end='')
        print()
    print()
            
    


Measured memory_bytes: 7004
n=int(input())
l=list(map(int, input().split()))
l.sort()
cnt=0
for i in range(n):
  for j in range(i+1,n):
    for k in range(j+1,n):
      if l[i]<l[j] and l[j]<l[k]:
        if l[i]+l[j]>l[k]:
          cnt+=1
print(cnt)

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

using namespace std;

typedef long long ll;
const ll mod = 1e9+7;

ll factorial(int n) {
  if (n == 1) return 1;
  return n*factorial(n-1)%mod;
}

int main()
{
  int N; cin >> N;
  ll ans = factorial(N);
  cout << ans;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ff              first
#define ss              second
#define int             long long int
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define vv(type)		vector<vector<type>>
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define db(x) 			cout<<x<<" "
#define db1(x) 			cout<<x<<'\n'
#define db2(x,y) 		cout<<x<<" "<<y<<'\n'
#define db3(x,y,z) 		cout<<x<<" "<<y<<" "<<z<<'\n'
#define rep(i,n) 		for(int i=0;i<(n);++i)
#define repA(i,a,n) 	for(int i=a;i<=(n);++i)
#define repD(i,a,n) 	for(int i=a;i>=(n);--i)
#define so(a) 			sort(a.begin(),a.end())
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
// to find all local maximaa and minima in O(n)
//	 for (int i=1;i<=n;i++)
//        {
//            if (i==1 || i==n || (p[i-1]<p[i])!=(p[i]<p[i+1]))
//           ans.push_back(p[i]);
//        }
int dx[] = { -1, 1, -1, 0, 0, -1, 1, 1 };
int dy[] = { -1, -1, 1, -1, 1, 0, 0, 1 };
int gcd(int a, int b)
{
	if (!b)
		return a;
	return gcd(b, a % b);
}
int modular_expo(int x, int y, int m)
{
	int ans = 1;
	while (y)
	{
		if (y & 1)
			ans = (ans % m * x % m) % m;
		x = (x % m * x % m) % m;
		y /= 2;
	}
	return ans % m ;
}
int power(int x, int y)
{
	int ans = 1;
	while (y)
	{
		if (y & 1)
			ans = (ans * x);
		x *= x;
		y /= 2;
	}
	return ans;
}
int dp[101][100001];
void ways(int n, int k, vi &a)
{

	rep(j, k + 1)
	dp[0][j] = (j <= a[0]) ? 1 : 0;
	repA(i, 1, n - 1)
	{
		rep(j, k + 1)
		{
			if (j == 0)
				dp[i][j] = dp[i - 1][j] % mod;
			else
				dp[i][j] = (mod + dp[i - 1][j] + dp[i][j - 1] - ((j - a[i] > 0) ? dp[i - 1][j - a[i] - 1] : 0)) % mod;
		}
	}
}

void solve()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, k;
	cin >> n >> k;
	memset(dp, -1, sizeof(dp));
	vi a(n);
	rep(i, n)
	cin >> a[i];
	ways(n, k, a);
	// rep(i, n)
	// {
	// 	rep(j, k + 1)
	// 	db(dp[i][j]);
	// 	cout << "\n";
	// }
	db1(dp[n - 1][k]);
}
int32_t main()
{
	solve();
	return 0;
}


Measured memory_bytes: 82508
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.Comparator;


public class Main{

	static class Circle {
		double r;
		double x;
		double y;

		public Circle(double r, double x, double y) {
			this.r = r;
			this.x = x;
			this.y = y;
		}

		public double getR() {
			return this.r;
		}

		public void set(double r) {
			this.r = r;
		}

		public double getX() {
			return this.x;
		}

		public void setX(double x) {
			this.x = x;
		}

		public double getY() {
			return this.y;
		}

		public void setY(double y) {
			this.y = y;
		}

		@Override
		public String toString() {
			return this.x + ", " + this.y;
		}
	}

	static Circle[] circles = null;
	static double maxRadius = 0.0;
	public static void main(String[] args) throws Exception{
		//Scanner s = new Scanner(System.in);
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while(true) {
			int N = Integer.parseInt(br.readLine());
			if(N == 0)
				break;
			circles = new Circle[N];
			for(int i=0 ; i<N ; i++) {
				String[] tmp = br.readLine().split(" ");
				circles[i] = new Circle(Double.parseDouble(tmp[0]), Double.parseDouble(tmp[1]), Double.parseDouble(tmp[2]));
				maxRadius = Math.max(maxRadius, Double.parseDouble(tmp[0]));
			}

			Arrays.sort(circles, Comparator.comparing(Circle::getX));
			double res1 = solve(circles, 0, N-1);
			DecimalFormat fmt = new DecimalFormat("0.00000000");

			System.out.println(fmt.format(res1));
		}
	}

	static double solve(Circle[] c, int start, int end) {

		if(start == end || start > end)
			return Integer.MAX_VALUE;
		if(start == (end-1))
			return Math.hypot(c[start].x - c[end].x, c[start].y - c[end].y) - c[start].r - c[end].r;
		int middle = (start + end) / 2;

		double result = Math.sqrt((c[middle].x - c[middle+1].x)*(c[middle].x - c[middle+1].x) + (c[middle].y - c[middle+1].y)*(c[middle].y - c[middle+1].y)) - c[middle].r - c[middle+1].r;
		double result1 = solve(c, start, middle);
		double result2 = solve(c, middle+1, end);

		double distance =  Math.min(Math.min(result1, result2), result);
		int m = (start+end)/2;
		double middleP = (c[m-1].x + c[m].x) / 2;
		Circle[] cc = new Circle[end-start];
		int index = 0;
		for(int i=start ; i<end ;i++) {
			if(Math.abs(c[i].x - middleP) < distance+2*maxRadius) {
				cc[index++] = c[i];
			}
		}

		if(index <= 1)
			return distance;
		Circle[] cY = new Circle[index];
		for(int i=0 ; i<index ; i++) {
			cY[i] = cc[i];
		}
		Arrays.sort(cY, Comparator.comparing(Circle::getY));

		for(int j=0 ; j<index ; j++) {
			for(int k=j+1 ; k<index && (cY[k].y-cY[j].y < distance+2*maxRadius); k++) {
				distance = Math.min(distance, Math.hypot(cY[j].x - cY[k].x, cY[j].y - cY[k].y) - cY[j].r - cY[k].r);
			}
		}
		return distance;
	}

}

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

int M;
int a[7];
int s, g;
int N[301];

bool isChecked[301];
vector<int> milestone[301];  //そのマスで出せばゴールにたどり着ける目を格納する

int iabs(int x){ return x >= 0 ? x : -x; }

bool search(int now){
	if (isChecked[now]) return false;
	else if (now == g)  return true;

	isChecked[now] = true;
	for (int dice = 1; dice <= 6; dice++){
		if (now + a[dice] <= M && search(now + a[dice] + N[now + a[dice]])){
			milestone[now].push_back(a[dice]);
		}
		if (now - a[dice] >= 1 && search(now - a[dice] + N[now - a[dice]])){
			milestone[now].push_back(-a[dice]);
		}
	}

	return milestone[now].size() > 0 ? true : false;
}

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

	cin >> M;
	for (int i = 1; i <= 6; i++){
		cin >> a[i];
	}
	cin >> s >> g;
	for (int i = 1; i <= M; i++){
		cin >> N[i];
	}
	bool canGoal = search(s);

	int now = s; //自分が今いるマスの番号
	for (;;){
		int dice;
		cin >> dice;

		bool found = false;
		for (vector<int>::iterator it = milestone[now].begin(); it != milestone[now].end(); it++){
			if (iabs(*it) == a[dice]){
				if (*it > 0){
					now = now + a[dice] + N[now + a[dice]];
					cout << 1 << endl;
				}
				else{
					now = now - a[dice] + N[now - a[dice]];
					cout << -1 << endl;
				}
				found = true;
				break;
			}
		}
		if(!found) cout << 0 << endl;
		cout.flush();

		if (now == g) return 0;
	}
	
	return 0;
}

Measured memory_bytes: 1304
N=int(input())
uvw= [list(map(int,input().split())) for _ in [0]*(N-1)]
connect=[[] for _ in [0]*N]
for u,v,w in uvw:
    connect[u-1].append((v-1,w))
    connect[v-1].append((u-1,w))
MAX=10**16
dist = [MAX]*N
dist[0]=0
q = [0]
while q:
    i = q.pop()
    for j,w in connect[i]:
        if dist[j] == MAX:
            dist[j] = dist[i]+w
            q.append(j)
for o in dist:
    print(o%2)

Measured memory_bytes: 63044
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(long int I=X;I<Y;I++)
#define REP(I,X,Y) for(long int I=Y-1;I>=X;I--)
#define INF 1000000007
using namespace std;

int main(){
  int a,b,c;
  string S,T;
  cin >> a;
  if(a < 1200)cout << "ABC" << endl;
  else if(a < 2800)cout << "ARC" << endl;
  else cout << "AGC" << endl;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons;
import std.math, std.numeric;
import core.bitop;

alias Pair = Tuple!(int, "val", int, "type");

void main() {
    int w, h; scan(w, h);
    auto p = new Pair[](w + h);
    foreach (i ; 0 .. w + h) {
        int pi; scan(pi);
        if (i < w) {
            p[i] = Pair(pi, 0);
        }
        else {
            p[i] = Pair(pi, 1);
        }
    }
    p.sort!"a.val < b.val"();
    debug {
        writefln("%(%s\n%)", p);
    }

    int[] a = [w + 1, h + 1];
    long ans;
    foreach (i ; 0 .. w + h) {
        ans += 1L * p[i].val * a[p[i].type ^ 1];
        a[p[i].type]--;
        debug {
            writefln("%d * %d = %d", p[i].val, a[p[i].type^1], p[i].val * a[p[i].type^1]);
            writeln(a);
        }
    }
    writeln(ans);
}


void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 4860
import numpy as np

N, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)

digits = len(format(K, "b"))
bits_list = [((A >> shift) & 1).sum() for shift in range(digits)]
bits_list.reverse()

X = 0
half = (N + 1) // 2
digit = 1 << (digits - 1)

for bits in bits_list:
    if bits < half and (X | digit) <= K:
        A ^= digit
        X |= digit
    digit >>= 1

print(A.sum())


Measured memory_bytes: 26016
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


X, Y, Z, K = read_ints()
A = list(map(int,input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

from itertools import product

AB = [a + b for a, b in product(A, B)]
AB.sort(reverse=True)

ABC = [ab + c for ab, c in product(AB[:K], C)]
ABC.sort(reverse=True)

ABC = ABC[:K]

print(*ABC, sep='\n')



Measured memory_bytes: 145184
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))
#define SORT(a,num,cmp) qsort((a),(num),sizeof(*(a)),cmp)

i32 query (i32 u, i32 v) {
  printf ("? %" PRIi32 " %" PRIi32 "\n", u, v);
  fflush (stdout);
  i32 l;
  scanf ("%" SCNi32, &l);
  return l;
}

typedef struct node {
  i32 v, l, r;
} node;

int cmp_node (const void *a, const void *b) {
  i32 d = ((node *)a)->l - ((node *)b)->l;
  return d == 0 ? 0 : d < 0 ? -1 : 1;
}

void run (void) {
  i32 n, s, t;
  scanf ("%" SCNi32 "%" SCNi32 "%" SCNi32, &n, &s, &t);
  i32 distance = query (s, t);
  node *p = ALLOC (n, node);
  i32 len = 0;
  for (i32 i = 1; i <= n; ++i) {
    if (i == s || i == t) continue;
    i32 l = query (s, i);
    i32 r = query (i, t);
    if (l + r > distance) continue;
    p[len++] = (node) {i, l, r};
  }
  if (len == 0) {
    printf ("! %" PRIi32 " %" PRIi32 "\n", s, t);
    return;
  }
  SORT (p, len, cmp_node);
  i32 *ans = ALLOC (n, i32);
  i32 alen = 0;
  ans[alen++] = s;
  ans[alen++] = p[0].v;
  i32 l = p[0].l;
  for (i32 i = 1; i < len; ++i) {
    i32 q = query (ans[alen - 1], p[i].v);
    if (l + q + p[i].r == distance) {
      ans[alen++] = p[i].v;
      l = p[i].l;
    }
  }
  ans[alen++] = t;
  printf ("!");
  for (i32 i = 0; i < alen; ++i) {
    printf (" %" PRIi32, ans[i]);
  }
  puts ("");
}

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



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

int main() {
  
  int N;
  cin >> N;
  
  vector<int> P(N);
  for(int i=0; i<N; i++){
   cin >> P.at(i);  
  }
  
  int count=0;
  int curmin=10e9;
  
  for(int i=0; i<N; i++){
    
    curmin=min(curmin,P.at(i));
    
    if(curmin==P.at(i)) count++;
  }
  
  cout << count << endl;
  
      
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define trep(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
using vi = vector<int>;
using vvi = vector<vi>;
#define N 100000
vi s(N + 1, 1);
vi like(N + 1, 0);
vi sum(N + 1,0);
void eli(int p)
{
    for (int i = p + p; i <= N; i = i + p)
    {
        s[i] = 0;
    }
}
int main()
{
    s[0] = s[1] = 0;
    rep(i, N + 1)
    {
        if (s[i] == 1)
        {
            eli(i);
        }
    }
    rep(i,N + 1)
    {
       if(s[i]==1 && s[(i+1)/2]==1){
           like[i] = 1;
       }
    }
    trep(i, 1, N + 1)
    {
        sum[i] += sum[i - 1]+like[i];
    }
    int q;
    cin >> q;
    rep(i, q)
    {
        int l, r;
        cin >> l >> r;
        cout << sum[r] - sum[l-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int h,w;
  int i,j;
  cin >> h >> w;
  vector<vector<char>> d(h, vector<char>(w));
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      cin >> d[i][j];
    }
  }
  vector<bool> a(h,false);
  vector<bool> b(w,false);
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      if(d[i][j] == '#'){
        a[i]=true;
        b[j]=true;
      }
    }
  }
  for(i=0;i<h;i++){
    if(a[i]==false) continue;
    for(j=0;j<w;j++){
      if(b[j]==false) continue;
      else cout << d[i][j];
    }
    cout << "\n";
  }
  return 0;
}

Measured memory_bytes: 256
A, B, C, X, Y = map(int, input().split())

min = X if X < Y else Y
max = X if X > Y else Y
sub = X - Y

if A+B > 2*C:
    ch = 2*C
else:
    ch = A+B

m = ch * min

if sub > 0:
    m += sub * A
else:
    m += sub * B * (-1)
    
m_ = ch * max

if m_ > m:
    print(m)
else:
    print(m_)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep2(i,m,n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;
template <typename T>
T sq(T x){
  return x * x;
}

signed main (){
 vector<int> a(3);
 rep(i,3){
 cin >> a.at(i);
 }
sort(all(a));
cout << a.at(0) + a.at(1) << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N,X = inpl()
xx = inpl()
xx.append(X)
xx.sort()

dists = set()
for i in range(N):
	dists.add(xx[i+1]-xx[i])

dists = list(dists)
dists.sort()

def gcd(a,b):
	while b:
		a,b = b, a%b
	return a

ans = dists[0]
for d in dists:
	ans = gcd(ans,d)

print(ans)


Measured memory_bytes: 15448