akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <sstream>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repp(i,k,n) for(int i=k;i<(int)n;i++)
#define rei(n) for(int i=0;i<(int)n;i++)
#define rel(n) for(int l=0;l<(int)n;l++)
#define al(s) s.begin(),s.end()
#define INT_MAX 2147483647
#define debug(x) cout<<#x<<": "<<x<<endl;
#define PI 2*acos(0,0)
#define pb push_back
#define inin(x) int x; cin>>x;
#define ll long long

typedef pair<int, int> pii;

struct Calendar
{
	long long year;
	long long month;
	long long day;
	long long dat[2][13];
	Calendar(long long y, long long m, long long d)
	{
		year = y;
		month = m;
		day = d;
		dat[0][0] = dat[1][0] = 0;
		dat[0][1] = dat[1][1] = 31;
		dat[0][2] = dat[1][2] = 28;
		dat[0][3] = dat[1][3] = 31;
		dat[0][4] = dat[1][4] = 30;
		dat[0][5] = dat[1][5] = 31;
		dat[0][6] = dat[1][6] = 30;
		dat[0][7] = dat[1][7] = 31;
		dat[0][8] = dat[1][8] = 31;
		dat[0][9] = dat[1][9] = 30;
		dat[0][10] = dat[1][10] = 31;
		dat[0][11] = dat[1][11] = 30;
		dat[0][12] = dat[1][12] = 31;
		dat[1][2] = 29;
	}
	int uruu()
	{
		if (year % 4 == 0)
		{
			if (year % 400 != 0 && year % 100 == 0)
			{
				return 0;
			}
			else
			{
				return 1;
			}
		}
		return 0;
	}
	int uruu(long long y)
	{
		if (y % 4 == 0)
		{
			if (y % 400 != 0 && y % 100 == 0)
			{
				return 0;
			}
			else
			{
				return 1;
			}
		}
		return 0;
	}
	long long pday(long long d)
	{
		day += d;
		for (;; month++)
		{
			if (month >= 13)
			{
				year++;
				month = 1;
			}

			if (dat[uruu()][month] < day)
			{
				day -= dat[uruu()][month];
			}
			else
			{
				break;
			}
		}
		pmonth(0);
		return d;
	}
	long long pmonth(long long m)
	{
		month += m;
		for (;; year++)
		{
			if (month > 12)
			{
				month -= 12;
			}
			else
			{
				break;
			}
		}
		return m;
	}
	long long pyear(long long y)
	{
		year += y;
		return y;
	}
	long long dif(Calendar c)
	{
		long long ans = 0;
		Calendar a(year, month, day);
		ans -= a.day;
		ans += c.day;
		a.day = 0;
		c.day = 0;
		for (; a.month >= 1; a.month--)
		{
			ans -= dat[a.uruu()][a.month-1];
		}
		for (; c.month >= 1; c.month--)
		{
			ans += dat[c.uruu()][c.month-1];
		}
		for (; a.year != c.year; a.year++)
		{
			ans += 365;
			if (a.uruu())ans++;
		}
		return ans;
	}


};




int main()
{
	int v ;
	while (cin >> v&&v)
	{
		for (int i = 0; i < 9; i++)
		{
			inin(x);
			v -= x;
		}
		cout << v << endl;
	}
}

Measured memory_bytes: 1160
integer M
integer D
integer D10,D1
integer ans
read*,M,D
D10=D/10
D1=mod(D,10)

ans=0
do i=2,D10-1
  do j=2,9
    if(i*j<=M)ans=ans+1
  end do
end do
do j=2,D1
  if(D10*j<=M)ans=ans+1
end do
print"(i0)",ans
end

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

int main() {
  int N;
  cin >> N;
  vector<int> date(N);
  int count = 0;
  int divide = 0;
  for(int i = 0; i < N; i++){
    cin >> date[i];
  }
  for(int i = 0; i < N; i++){
    if(date[i] % 2 == 0){
      date[i] /= 2;
      count++;
      if(count == N){
        i -= N;
        divide++;
        count = 0;
      }
    }
    else if(date[i] % 2 == !0){
      break;
    }
  }
  cout << divide << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,f,n) for(int i=(f); (i) < (n); i++)
#define repe(i,f,n) for(int i=(f); (i) <= (n); i++)
using namespace std;

typedef long long ll;

int
main(void)
{

  int n; cin >> n;
  string s; cin >> s;
  int sarr[n];
  rep(i, 0, n) sarr[i] = s[i] - '0';
  int ans = 0;

  repe(i, 0, 9){
    repe(j, 0, 9){
      repe(k, 0, 9){
        int target[3] = {i, j, k};
        int index = 0;
        rep(l, 0, n){
          if(sarr[l] == target[index]){
            index++;
            if(index >= 3) break;
          }
        }
        if(index >= 3) ans++;
      }
    }
  }

  cout << ans <<endl;

  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
#define int long long 
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define DEBUG(x) cerr << #x << " = " << x<< endl
signed main() {
  ios::sync_with_stdio(false);
  int N, M; cin >> N >> M;
  vector<vector<int>> out(N);
  vector<int> in(N);
  REP(i, M) {
    int a, b; cin >> a >> b;
    --a, --b;
    in[b]++;
    out[a].push_back(b);
  }
  bool mul = false;
  vector<int> ans;
  queue<int> Q;
  int c = 0;
  REP(i, N) {
    if(in[i] == 0) {
      ++c;
      ans.push_back(i);
      Q.push(i);
    }
  }
  if(c > 1) mul = true;
  while(!Q.empty()) {
    c = 0;
    int v = Q.front(); Q.pop();
    for(int i : out[v]) {
      in[i]--;
      if(in[i] == 0) {
        ++c;
        ans.push_back(i);
        Q.push(i);
      }
    }
    if(c > 1) mul = true;
  }
  for(int a : ans) cout << (a + 1) << endl;
  cout << (mul ? 1 : 0) << endl;
}

Measured memory_bytes: 2680
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
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; }


int main() {
    ll x;
    cin >> x;
    ll ans = 8;
    x -= 400;
    while (!(x>=0 & x<200)){
        x-=200;
        ans--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <random>

using namespace std;

struct Pref{
    int ken;
    int nen;
    int id;
    Pref(){ 
    }
    Pref(int a, int b){
        ken = a;
        nen = b;
    }
    bool operator<(const Pref &another) const{
        return nen < another.nen;
    }
};
int main(){
    int n,m, i;
    cin >> n >> m;
    vector<Pref> prefs;
    vector<Pref> origin;
    map<int, int>prefCnts;
    map<int, int>getIdFromNen;
    for(i=0;i<m;i++){
        int a,b;
        cin >> a >> b;
        Pref hoge{a, b};
        prefs.push_back(hoge);
        origin.push_back(hoge);
    }
    sort(prefs.begin(), prefs.end());

    for(i=0;i<(int)prefs.size();i++){
        int id = ++prefCnts[prefs[i].ken];
        getIdFromNen[prefs[i].nen] = id;
    }
    for(i=0;i<(int)origin.size();i++){
        printf("%06d%06d\n", origin[i].ken, (getIdFromNen[origin[i].nen]));
    }
    return 0;
}


Measured memory_bytes: 13228
#include <iostream>
using namespace std;
int main() {
  string s;
  cin >> s;
  int n = s.size(), ans = 0;
  for (int i = 0; i < (n / 2); ++i) {
    if (s.at(i) != s.at(n - i - 1)) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

vpi fst;
vi num;
vl sum;
int N;
map<int,ll> val;
ll ans[MX];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N;
    FOR(i,1,N+1) {
        int x; cin >> x; num.pb(x);
        if (sz(fst) == 0 || x > fst.back().f) fst.pb({x,i});
    }
    sort(all(num));
    ll cur = 0;
    F0R(i,N) {
        cur += num[i];
        sum.pb(cur);
    }
    F0Rd(i,N) {
        val[num[i]] = sum[i]+(ll)(N-1-i)*num[i];
    }
    F0Rd(i,sz(fst)) {
        ll zz = val[fst[i].f];
        if (i) zz -= val[fst[i-1].f];
        ans[fst[i].s] = zz;
    }
    FOR(i,1,N+1) cout << ans[i] << "\n";
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS

Measured memory_bytes: 10096
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
inline int read()
{
	int x;char c;
	while((c=getchar())<'0'||c>'9');
	for(x=c-'0';(c=getchar())>='0'&&c<='9';)x=x*10+c-'0';
	return x;
}
#define MN 200000
#define N 262144
ll t1[N*2+5],t2[N*2+5];int x[MN+5];
void rw(ll*t,int k,ll x){for(k+=N;k;k>>=1)t[k]=min(t[k],x);}
ll query(ll*t,int l,int r)
{
	ll res=t[0];
	for(l+=N-1,r+=N+1;l^r^1;l>>=1,r>>=1)
	{
		if(~l&1)res=min(res,t[l+1]);
		if( r&1)res=min(res,t[r-1]);
	}
	return res;
}
inline int z(int x){return x<0?-x:x;}
int main()
{
	int n,q,a,i;ll s=0,ans;
	n=read();q=read();a=read();x[0]=read();
	memset(t1,40,sizeof(t1));rw(t1,a,-a);
	memset(t2,40,sizeof(t2));rw(t2,a,a);
	for(i=1;i<=q;++i)
	{
		x[i]=read();
		ans=min(x[i]+query(t1,1,x[i]),query(t2,x[i],n)-x[i])+s;
		s+=z(x[i]-x[i-1]);
		rw(t1,x[i-1],ans-s-x[i-1]);rw(t2,x[i-1],ans-s+x[i-1]);
	}
	for(ans=t1[0],i=1;i<=n;++i)ans=min(ans,t1[i+N]+i+s);
	printf("%lld",ans);
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using Pair = pair<int, int>;
using Vec = vector<int>;
using Graph = vector<Vec>;

int		main(void)
{
	int n, m;
	cin >> n >> m;
	Vec height(n + 1);
	for (int i = 1; i <= n; i++)
		cin >> height.at(i);
	Graph g(n + 1);
	for (int i = 0; i < m; i++)
	{
		int a, b;
		cin >> a >> b;
		g.at(a).push_back(b);
		g.at(b).push_back(a);
	}
	int bad_peaks = 0;
	for (int i = 1; i <= n; i++)
	{
		for (auto j = g.at(i).begin(); j != g.at(i).end(); j++)
		{
			if (height.at(i) <=  height.at(*j))
			{
				bad_peaks++;
				break;
			}
		}
	}
	cout << n - bad_peaks << endl;
}



Measured memory_bytes: 8800
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <tuple>

using namespace std;

class Solver {

};

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

		int m0;
		cin >> m0;
		vector<vector<tuple<int, int>>> valids(8, vector <tuple<int, int>>(m0));
		int x0, y0;
		for (int i = 0; i < m0; i++) {
			int tmp_x, tmp_y;
			cin >> tmp_x >> tmp_y;
			if (i == 0) {
				for (int j = 0; j < 4; j++) {
					valids[j][i] = make_tuple(0, 0);
				}
				x0 = tmp_x;
				y0 = tmp_y;
			}
			else {
				int delta_x = tmp_x - x0;
				int delta_y = tmp_y - y0;
				valids[0][i] = make_tuple(delta_x, delta_y);
				valids[1][i] = make_tuple(-delta_y, delta_x);
				valids[2][i] = make_tuple(-delta_x, -delta_y);
				valids[3][i] = make_tuple(delta_y, -delta_x);
			}
		}

		for (int i = 0; i < m0; i++) {
			for (int j = 4; j < 8; j++) {
				int delta_x = get<0>(valids[j - 4][m0 - i - 1])
					- get<0>(valids[j - 4][m0 - 1]);
				int delta_y = get<1>(valids[j - 4][m0 - i - 1])
					- get<1>(valids[j - 4][m0 - 1]);
				valids[j][i] = make_tuple(delta_x, delta_y);
			}
		}

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

			vector<tuple<int, int>> pos(m);
			int x0, y0;
			for (int j = 0; j < m; j++) {
				int tmp_x, tmp_y;
				cin >> tmp_x >> tmp_y;
				if (j == 0) {
					pos[j] = make_pair(0, 0);
					x0 = tmp_x;
					y0 = tmp_y;
				}
				else {
					int delta_x = tmp_x - x0;
					int delta_y = tmp_y - y0;
					pos[j] = make_pair(delta_x, delta_y);
				}
			}

			if (m != m0)continue;

			bool valid = false;
			for (int j = 0; j < 8; j++) {
				for (int k = 0; k < m; k++) {
					int delta_x = get<0>(valids[j][k]) - get<0>(pos[k]);
					int delta_y = get<1>(valids[j][k]) - get<1>(pos[k]);
					if (delta_x == 0 && delta_y == 0) {
						if (k == m - 1)valid = true;
						continue;
					}
					else break;
				}
			}

			if (valid)cout << i << endl;
		}

		cout << "+++++" << endl;
	}
}


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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll A[105];

int main()
{
    int N, M, X;
    cin >> N >> M >> X;
    REP(i, M)
    {
        int a;
        cin >> a;
        A[a]++;
    }

    int l = 0;
    for (int i = 0; i <= X; ++i)
    {
        l += A[i];
    }
    int r = 0;
    for (int i = X; i <= N; ++i)
    {
        r += A[i];
    }
    cout << std::min(l, r) << endl;
    return 0;
}

Measured memory_bytes: 256
// In the name of Allah the Most Merciful.

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

int main(void)
{
    ll a ;string ar;
    cin >> a >> ar;

    ll x = 0 , mx = 0;

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

        if(ar[i]=='I')x++;
        else x--;
        if(x>mx)mx=x;
    }

    cout << mx << endl;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		int[] s=sc.Ia;
		Cb r=new Cb(s[0]+1);
		StringBuilder sb=new StringBuilder();
		for(int i = 1;i<=s[1];i++) {
			long p=s[0]-s[1]+1<i?0:((r.C1(s[0]-s[1]+1,i)*r.C1(s[1]-1,i-1))%mod);
			sb.Append(p+"\n");
		}
		Console.Write(sb);
	}
}
public class Cb{
	private const int mod=(int)1e9+7;
	public long[] r;
	public Cb(int n){
		r=new long[n];
		r[0]=1;
		for(int i=1;i<n;i++){r[i]=(r[i-1]*i)%mod;}
	}
	public long C1(long n,long k){return (r[n]*Mi(r[k]*r[n-k]))%mod;}
	public long C2(long n,long k){
		long l=1;
		n%=mod;
		for(int i=1;i<=k;i++){l=(l*(n-i+1))%mod;l=(l*Mi(i))%mod;}
		return l;
	}
	public long Mi(long a){
		a=(a+mod)%mod;
		long b=mod,u=1,v=0;
		while(b>0){long t=a/b;a-=t*b;a^=b;b^=a;a^=b;u-=t*v;u^=v;v^=u;u^=v;}
		u%=mod;
		if(u<0){u+=mod;}
		return u%mod;
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}


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

int ab(int a)
{
	if(a<0) return -a;
	return a;
}

int main()
{
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n,v=1,mv=0,tmp,x;
	cin >> n;
	for(int i=1;i<=n;i++)
	{
		cin >> tmp;
		if(ab(tmp)>mv) mv=ab(tmp),v=i,x=(tmp<0) ? 1 : 0;
	}
	cout << 2*n-2 << "\n";
	for(int i=1;i<=n;i++)
		if(i!=v) cout << v << " " << i << "\n";
	if(x)
		for(int i=n;i>1;i--)
			cout << i << " " << i-1 << "\n";
	else 
		for(int i=2;i<=n;i++)
			cout << i-1 << " " << i << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll mininf = -922337203685477;
const ll nax = 0;
int n, k;

int main(){
	IOS
	cin >> n >> k;
	for(int i=k-n+1;i<=k+n-1;i++){
		cout << i;
		if(i!=k+n-1){
			cout << ' ';
		}
	}
	cout << '\n';
}


Measured memory_bytes: 3600
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
    int a, b;
    
    scanf("%d %d", &a, &b);
    
    int c = b - a;
    
    b = 0;
    for (int i = 0; i < c; i++) {
        b += i;
    }
    
    printf("%d", b - a);
    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repp(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

 
signed main(){
    int h, w;
    cin >> h >> w;
    string s[50];
    rep(i, 0, h){
        cin >> s[i];
    }
    int MIN = 3000;
    rep(i, 0, h - 2){
        rep(j, 1, h - 1){
            int cnt = 0;
            rep(k, 0, h){
                rep(l, 0, w){
                    if(k <= i && s[k][l] != 'W') cnt++;
                    if(i < k && k <= j && s[k][l] != 'B') cnt++;
                    if(j < k && s[k][l] != 'R') cnt++;
                }
            }
            MIN = min(MIN, cnt);
        }
    }
    cout << MIN << endl;
}

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

static const int MAX = 100;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n,M[MAX][MAX];

void dijkstra(){
  int minv;
  int d[MAX],color[MAX];

  for(int i = 0; i < n; i++){
    d[i] = INFTY;
    color[i] = WHITE;
  }

  d[0] = 0;
  color[0] = GRAY;
  while(1){
    minv = INFTY;
    int u = -1;
    for(int i = 0;i < n;i++){
      if(minv > d[i] && color[i] != BLACK){
        u = i;
        minv = d[i];
      }
    }
    if( u == -1)break;
    color[u] = BLACK;
    for(int v = 0;v < n;v++){
      if(color[v] != BLACK && M[u][v] != INFTY){
        if(d[v] > d[u] + M[u][v] ){
          d[v] = d[u] + M[u][v];
          color[v] = GRAY;
        }
      }
    }
  }
  for(int i = 0; i < n;i++){
    cout << i << " " << ( d[i] == INFTY ? -1 : d[i] ) << endl;
  }
}

int main(){
  cin >> n;
  for(int i = 0; i < n; i++){
    for(int j = 0;j < n;j++){
      M[i][j] = INFTY;
    }
  }

  int k,c,u,v;
  for(int i = 0; i < n; i++){
    cin >> u >> k;
    for(int j = 0; j < k; j++){
      cin >> v >> c;
      M[u][v] = c;
    }
  }

  dijkstra();

  return 0;
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vii vector<int,int>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
const int mod=1e9+7;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int main(){
    fast;
    int z;
    cin>>z;
    string s;
    cin>>s;
    int m=s.length();
    if(m<=z) cout<<s;
    else{
        for(int i=0;i<z;i++){
            cout<<s[i];
        }
        cout<<"...";
    }
}

Measured memory_bytes: 3604
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;

int main(){
  int N; cin >> N;
  vector <ll> A(3 * N);
  for (int i = 0; i < 3 * N; i++) cin >> A[i];
  
  priority_queue <ll, vector<ll>, greater<ll> > que1;
  priority_queue <ll> que2;

  vector <ll> sum1(N + 1), sum2(N + 1);

  ll sum = 0;
  for (int i = 0; i < N; i++){
    sum += A[i]; que1.push(A[i]);
  }
  sum1[0] = sum;
  for (int i = 0; i < N; i++){
    sum += A[N + i];
    que1.push(A[N + i]);
    sum -= que1.top();
    sum1[i + 1] = sum;
    que1.pop();
  }
  
  sum = 0;
  for (int i = 0; i < N; i++){
    sum += A[i + 2 * N]; que2.push(A[i + 2 * N]);
  }
  
  sum2[N] = sum;
  for (int i = N - 1; i >= 0; i--){
    sum += A[N + i]; que2.push(A[N + i]);
    sum -= que2.top(); sum2[i] = sum;
    que2.pop();
  }
  
  ll ans = -1e18;
  for (int i = 0; i < N + 1; i++){
    ans = max(ans, sum1[i] - sum2[i]);
  }
  cout << ans << endl;

  return 0;
}


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

void dfs(int x, int y);
char data[16][16];

int main(void)
{
	char c;
	
	while (1){
		
		for (int i = 0; i < 12; i++){
			cin >> data[i];
		}
		if (cin.eof()) return (0);
		
		int res = 0;
		for (int i = 0; i < 12; i++){
			for (int j = 0; j < 12; j++){
				if (data[i][j] == '1'){
					dfs(i, j);
					res++;
				}
			}
		}
		
		printf("%d\n", res);
		scanf("%c", &c);
	}
	
	return (0);
}

void dfs(int x, int y)
{
	data[x][y] = '0';
	
	if (data[x - 1][y] == '1' && 0 <= (x - 1)){
		dfs(x - 1, y);
	}
	if (data[x + 1][y] == '1'){
		dfs(x + 1, y);
	}
	if (data[x][y - 1] == '1' && 0 <= (y - 1)){
		dfs(x, y - 1);
	}
	if (data[x][y + 1] == '1'){
		dfs(x, y + 1);
	}
	
	return;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <complex>
#include <numeric>
#include <string.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const ll MOD = 998244353;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

int calc_rank(vector<vector<int>> v) {
    int n = v.size(), m = v[0].size();
    int st = 0;
    rep(j,m) {
        int pv = -1;
        for (int i = st; i < n; i++) {
            if (v[i][j]) {
                pv = i;
                break;
            }
        }
        if (pv == -1) continue;
        if (pv != st) {
            swap(v[st], v[pv]);
        }
        for (int i = st+1; i < n; i++) {
            if (!v[i][j]) continue;
            for (int k = j; k < m; k++) {
                v[i][k] ^= v[st][k];
            }
        }
        st++;
    }
    return st;
}

int n, m;

int main() {
    cin >> n >> m;
    vector<vector<int>> a(n, vector<int>(m, 0));
    rep(i,n) rep(j,m) cin >> a[i][j];
    int r = calc_rank(a);
    ll ans = 1;
    rep(i,n+m-1) ans = ans * 2 % MOD;
    ll tmp = 1;
    rep(i,n+m-r-1) tmp = tmp * 2 % MOD;
    cout << (ans-tmp+MOD) % MOD << endl;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<58;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    while(true){
        int n,m;
        cin >> n >> m;
        if(n==0 and m==0) break;
        vector<vector<tuple<int,long double,long double>>> graph(n);
        int s,g;
        cin >> s >> g;
        --s;
        --g;
        rep(i,0,m){
            int x,y;
            long double d,c;
            cin >> x >> y >> d >> c;
            --x;
            --y;
            graph[x].emplace_back(make_tuple(y,d,c));
            graph[y].emplace_back(make_tuple(x,d,c));
        }

        vector<vector<vector<long double>>> dist(n,vector<vector<long double>>(n,vector<long double>(31,inf)));
        priority_queue<tuple<long double,int,int,int>,vector<tuple<long double,int,int,int>>,greater<tuple<long double,int,int,int>>> que;
        dist[s][s][0]=0;
        que.push(make_tuple(0,s,s,0));
        while(!que.empty()){
            const tuple<long double,int,int,int> tup=que.top();
            que.pop();
            const long double d=get<0>(tup);
            const int u=get<1>(tup),v=get<2>(tup),spd=get<3>(tup);
            if(d>dist[u][v][spd]) continue;
            for(const auto& e:graph[v]){
                const auto w=get<0>(e);
                if(w==u) continue;
                rep(i,-1,2){
                    const int next_spd=spd+i;
                    if(next_spd<=0 or next_spd>get<2>(e)) continue;
                    const long double tmp_d=d+get<1>(e)/next_spd;
                    if(tmp_d>=dist[v][w][next_spd]) continue;
                    dist[v][w][next_spd]=tmp_d;
                    que.push(make_tuple(tmp_d,v,w,next_spd));
                }
            }
        }

        long double ans=inf;
        rep(i,0,n) ans=min(ans,dist[i][g][1]);
        if(ans==inf) cout << "unreachable" << endl;
        else cout << ans << endl;
    }
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    cout << fixed << setprecision(8);
    solve();
    return 0;
}

Measured memory_bytes: 4400
s = list(input())
y = int(s[0]+s[1]+s[2]+s[3])
m = int(s[5]+s[6])
d = int(s[8]+s[9])

if y > 2019 or (y <= 2019 and m > 4):
  print("TBD")
else:
  print("Heisei")


Measured memory_bytes: 2940
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const double PI = acos(-1);



int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	string s;
	cin >> s;

	for (int i = 0; i < sz(s) - 1; i++) {
		if (s[i] == 'A' && s[i + 1] == 'C') {
			out("Yes");
			return 0;
		}
	}

	out("No");

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    //int型（整数型）の要素を3個もつ名前がaの配列
   int a[3];
   cin>>a[0]>>a[1]>>a[2];
   //sort（配列の変数名,配列の変数名＋配列の要素数 ) 昇順
   sort(a,a+3);
   if(a[0]==5&&a[1]==5&&a[2]==7)cout<<"YES"<<endl;
   else cout<<"NO"<<endl;
}


Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;
typedef long long ll;
int n;
bool ok[50][31];
ll b[50];

void solve() {

	memset(ok, 0, sizeof ok);
	for(int i = 0; i < n; i++) {
		int m, d;
		cin >> m;
		for(int j = 0; j < m; j++) {
			cin >> d;
			ok[i][d] = true;
		}
	}

	for(int i = 0; i < n; i++) {
		b[i] = 1LL << i;
	}

	for(int d = 1; d <= 30; d++) {
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				if(i == j) continue;
				if(ok[i][d] && ok[j][d]) {
					b[i] = b[j] = b[i] | b[j];
					if(b[i] == (1LL << n) - 1) {
						cout << d << endl;
						return;
					}
				}
			}
		}
	}
	cout << -1 << endl;
}

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

	while(cin >> n, n) {
		solve();
	}

}

Measured memory_bytes: 3124
# /usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math



def get_c(a, b):
  # a,b の営業時間の個数を返す
  return str(bin(a&b)).count("1")



if __name__ == "__main__":
  ## Input
  N = int(input())
  Fn = []
  Pn = []

  for i in range(N):
    f = list(map(int, input().split()))
    ret = 0
    for i in range(10):
      ret *= 2
      ret += f[i]
    Fn.append(ret)

  for i in range(N):
    p = list(map(int, input().split()))
    Pn.append(p)

  ## Solve
  ret = -1 * 10**10
  for i in range(1,2**10):
    ans = 0
    for j in range(N):
      ans += Pn[j][get_c(Fn[j],i)]
    ret = max(ret, ans)
  print(ret)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    int ac = 0,wa=0,tle=0,re=0;
    while(t--){
        string s;
        cin>>s;
        int i = 0;
        if(s == "AC"){
            ac++;
        }
        else if(s == "WA"){
            wa++;
        }
        else if(s == "TLE"){
            tle++;
        }   
        else if(s == "RE"){
            re++;
        }
    }
    cout<<"AC x "<<ac<<endl<<"WA x "<<wa<<endl<<"TLE x "<<tle<<endl<<"RE x "<<re<<endl;
    

}

Measured memory_bytes: 3632
//ITP1_7_D
#include <iostream>
using namespace std;

int n, m, l;
int array_a[110][110], array_b[110][110];
long long array_c[110][110];

long long calc(int i, int j) {
	long long sum = 0;
	for (int k = 0; k < m; k++) {
		sum += array_a[i][k] * array_b[k][j];
	}
	return sum;
}

int main() {
	cin >> n >> m >> l;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> array_a[i][j];
		}
	}
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < l; j++) {
			cin >> array_b[i][j];
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < l; j++) {
			array_c[i][j] = calc(i, j);
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < l; j++) {
			cout << array_c[i][j];
			if (j == l - 1) cout << endl;
			else cout << " ";
		}
	}
	return 0;
}

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

const int	SIZE=200,
			OF=100;
const int	vx[]={1,1,0,-1,-1,0},
			vy[]={1,0,-1,-1,0,1};

int main(){
	int t,n;
	while(cin >> t >> n , t||n){
		vector<vector<bool> > map(SIZE, vector<bool>(SIZE, true));
		while(n--){
			int x,y;
			cin >> x >> y;
			x+=OF; y+=OF;
			map[x][y]=false;
		}
		int sx,sy;
		cin >> sx >> sy;
		sx+=OF; sy+=OF;
		map[sx][sy]=false;

		queue<pair<pair<int,int>,int> > open;
		open.push(make_pair(make_pair(sx,sy),0));
		int ans=1;

		while(!open.empty()){
			pair<pair<int,int>,int > now=open.front();
			open.pop();
			if(now.second >= t)	continue;
			for(int i=0; i<6; ++i){
				int xx=now.first.first+vx[i],
					yy=now.first.second+vy[i];
				if(!map[xx][yy])	continue;
				map[xx][yy]=false;
				open.push(make_pair(make_pair(xx,yy), now.second+1));
				++ans;
			}
		}

		cout << ans << endl;
	}
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define int                     long long int
#define ld                      long double
#define pb                      push_back
#define MOD                     1000000007
#define inf                     3e18
#define vi                      vector<int>
#define vld                     vector<ld>
#define pii                     pair<int,int>
#define mii                     map<int,int>
#define fi                      first
#define se                      second
#define fastIO                  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> pbds; 
		//order_of_key (k) : Number of items strictly smaller than k .
		//find_by_order(k) : K-th element in a set (counting from zero) (returns an iterator)           


void inp_out()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("debug.txt", "w", stderr);
	#endif
}

int bin_exp(int b,int e)
{
	if(e == 0)	
		return 1;

	int a = bin_exp(b, e / 2);
	
	if(e & 1)	
		return a * a * b;
	else 
		return a * a;
}

int powm(int x, int y, int m = MOD) 
{
	x = x % m;
	int res = 1;
	while(y)
	{
		if(y & 1)
			res = res * x;
		res %= m;
		y = y >> 1;
		x = x * x;
		x %= m;
	}
	return res;
}

int modInverse(int a,int m = MOD)
{
	return powm(a, m - 2, m);
}


int32_t main()
{
	fastIO
  	inp_out();
	int n; 
	cin >> n; 
	if(n == 1)
	{
		cout << 0; 
		return 0; 
	}


	int ans; 

	ans = powm(10, n); 

	ans  += powm(8, n); 

	ans  -= 2 * powm(9, n); 
	ans %= MOD; 
	ans += MOD; 
	ans %= MOD; 

	cout << ans; 



	return 0;
}

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

int main(){


  char S[3];

  for(int i = 0;i < 3;i++)cin >> S[i];

  if(S[0] < S[1])cout << (char)(S[0]+1) << (char)(S[0]+1) << (char)(S[0]+1) << endl;

  else if(S[0] > S[1])cout << S[0] << S[0] << S[0] << endl;

  else{//S[0] = S[1]
    if(S[1] < S[2])cout << (char)(S[0]+1) << (char)(S[0]+1) << (char)(S[0]+1) << endl;
    else cout << S[0] << S[0] << S[0] << endl;
  }


}

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

struct NODE{
	int id = -1;
	int parent = -1;
	int left = -1;
	int right = -1;
	int sibling = -1;
	int degree = 0;
	int depth;
	int height;
};

int depth_height(NODE *nodes, int id, int d, int h){
	nodes[id].depth = d;

	// depth
	int h1 = 0;
	int h2 = 0;

	if(nodes[id].left != -1){
		nodes[id].degree += 1;
		h1 = depth_height(nodes, nodes[id].left, d+1, h);
	}
	if(nodes[id].right != -1){
		nodes[id].degree += 1;
		h2 = depth_height(nodes, nodes[id].right, d+1, h);
	}

	h1 >= h2 ? h=h1 : h=h2;
	nodes[id].height = h;
	return h+1;

}

void show(NODE *nodes, const int &n){
	for(int i=0; i<n; ++i){
		cout << "node " << nodes[i].id << ": ";
		cout << "parent = " << nodes[i].parent << ", ";
		cout << "sibling = " << nodes[i].sibling << ", ";
		cout << "degree = " << nodes[i].degree << ", ";
		cout << "depth = " << nodes[i].depth << ", ";
		cout << "height = " << nodes[i].height << ", ";

		if(nodes[i].parent == -1){
			cout << "root";
		}else if(nodes[i].degree == 0){
			cout << "leaf";
		}else{
			cout << "internal node";
		}

		cout << endl;
	}
}

int main(){
	int n;
	cin >> n;
	NODE *nodes = new NODE[n]; 

	int id;
	for(int i=0; i<n; ++i){
		cin >> id;
		nodes[id].id = id;
		cin >> nodes[id].left >> nodes[id].right;

		nodes[ nodes[id].left ].sibling = nodes[id].right;
		nodes[ nodes[id].right ].sibling = nodes[id].left;
		if(nodes[id].right != -1)
			nodes[ nodes[id].right ].parent = id;
		if(nodes[id].left != -1)
			nodes[ nodes[id].left ].parent = id;
	}

	// Find root
	int root_id;
	for(int i=0; i<n; ++i){
		if(nodes[i].parent == -1){
			root_id = i;
			break;
		}
	}


	depth_height(nodes, root_id, 0, 0);
	show(nodes, n);

	return 0;
}


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

const int MOD = 1000000007;
const int MAXN = 100005;

long long modpow(long long a, long long p){
	if(p == 0)return 1;
  	if(p % 2 == 1)return a * modpow(a, p - 1) % MOD;
  
  	long long r = modpow(a, p / 2);
  	return r * r % MOD;
}

int n, k;
long long cnt[MAXN];

int main(){
	scanf("%d %d", &n, &k);
  	
  	long long res = 0;
  	for(int g = k; g >= 1; g--){
    	cnt[g] = modpow(k / g, n);
      	for(int z = g + g; z <= k; z += g)
        	cnt[g] = (cnt[g] - cnt[z] + MOD) % MOD;
      	res = (res + cnt[g] * g) % MOD;
    }
  	printf("%lld\n", res);
  	
  	return 0;
}

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

int main(){
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<int> p(a), q(b), r(c);
    for(int i = 0; i < a; i++) cin >> p[i];
    for(int i = 0; i < b; i++) cin >> q[i];
    for(int i = 0; i < c; i++) cin >> r[i];
    sort(p.begin(), p.end());
    sort(q.begin(), q.end());

    vector<int> apples(x+y+c);
    for(int i = 0; i < x; i++) apples[i] = p[a-i-1];
    for(int i = 0; i < y; i++) apples[i+x] = q[b-i-1];
    for(int i = 0; i < c; i++) apples[i+x+y] = r[i];

    sort(apples.begin(), apples.end());
    long long int ans = 0;
    for(int i = 1; i <= x+y; i++) ans += apples[x+y+c-i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 998244353;
const ll INF = 1e16;

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    
    vvl dp(c+10, vl(d+10));  // dp[i][j] : 縦iマス横jマスのときの場合の数
    dp[a][b] = 1;
    exrep(i, a, c) {
        exrep(j, b, d) {
            dp[i+1][j] = (dp[i+1][j] + j*dp[i][j])%mod;
            dp[i][j+1] = (dp[i][j+1] + i*dp[i][j])%mod;
            dp[i+1][j+1] = (dp[i+1][j+1] + mod - i*j*dp[i][j]%mod)%mod;
        }
    }

    out(dp[c][d]);
    re0;
}

Measured memory_bytes: 74060
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;

#define maxn 10000+10
#define maxe maxn*maxn/2+1
int parent[maxn],height[maxn];

// void init(int n){
// 	for(int i=0; i<n; i++){
// 		pa[i] = i;
// 		ran[i] = 0;
// 	}
// }

// int find(int x){
// 	if(pa[x]==x) return x;
// 	else pa[x] = find(pa[x]);
// }

// void unite(int x,int y){
// 	x = find(x); y = find(y);

// 	if(x==y) return ;
// 	if(ran[x] < ran[y]){
// 		pa[x] = y;
// 	}else{
// 		pa[y] = x;
// 		if(ran[x] == ran[y])
// 			++ran[x];
// 	}
// }

// bool same(int x,int y){
// 	return find(x) == find(y);
// }
void init(const int& n)
{
	for (int i = 0; i < n; ++i)
	{
		parent[i] = i;
		height[i] = 0;
	}
}
 
int find(const int& x)
{
	if (parent[x] == x)
	{
		return x;
	}
	else
	{
		return parent[x] = find(parent[x]);
	}
}
 
void unite(int x, int y)
{
	x = find(x);
	y = find(y);
	if (x == y)
	{
		return;
	}
 
	if (height[x] < height[y])
	{
		parent[x] = y;
	}
	else
	{
		parent[y] = x;
		if (height[x] == height[y])
		{
			++height[x];
		}
	}
}
 
bool same(const int& x, const int& y)
{
	return find(x) == find(y);
}
struct edge{
	int u,v;
	double cost;
	edge(int u=0,int v=0,double cost=0) : u(u),v(v),cost(cost){}
	bool operator<(const edge& rhs) const{
		return cost > rhs.cost;
	}
};
edge es[maxe];
int V,E;

pair<int,int> pile[maxn];

// double kruskal(){
// 	sort(es,es+E);
// 	init(V);
// 	double res = 0;
// 	for(int i=0; i<E; i++){
// 		edge e = es[i];
// 		if(!same(e.u,e.v))
// 			unite(e.u,e.v);
// 		else
// 			res += e.cost;
// 	}

// 	return res;
// }
double kruskal()
{
	sort(es, es + E);    // ?????§??????????°???°??§??????
	init(V);
	double res = 0;
	for (int i = 0; i < E; ++i)
	{
		edge e = es[i];
		if (!same(e.u, e.v))
		{
			unite(e.u, e.v);
		}
		else
		{
			res += e.cost;
		}
	}
 
	return res;
}

int main(int argc, char *argv[])
{
	cin >> V >> E;
	
	for (int i = 0; i < V; ++i)
	{
		cin >> pile[i].first >> pile[i].second;
	}
 
	for (int i = 0; i < E; ++i)
	{
		cin >> es[i].u >> es[i].v;
		--es[i].u; --es[i].v;
		int dx = pile[es[i].u].first - pile[es[i].v].first;
		int dy = pile[es[i].u].second - pile[es[i].v].second;
		es[i].cost = sqrt(dx * dx + dy * dy);
	}
 
	cout.setf(ios::showpoint);
	cout.precision(3);
	cout.setf(ios::fixed);
	cout << kruskal() << endl;
	return 0;
}
// int main(){
// 	scanf("%d%d",&V,&E);
// 	for(int i=0; i<V; i++)
// 		scanf("%d%d",&pile[i].first,&pile[i].second);

// 	for(int i=0; i<E; i++){
// 		scanf("%d%d",&es[i].u,&es[i].v);
// 		--es[i].u,--es[i].v;
// 		int dx = pile[es[i].u].first - pile[es[i].v].first;
// 		int dy = pile[es[i].u].second - pile[es[i].v].second;
// 		es[i].cost = sqrt(dx*dx+dy*dy);	
// 	}

// 	printf("%.3lf\n",kruskal());
// }

Measured memory_bytes: 5128
while true
  e = gets.to_i
  break if e==0

  m = e
  for z in 0..100
    z3 = z**3
    break if z3>e
    for y in 0..1000
      x = e - z3 - y**2
      break if x < 0
      m = x+y+z if m > x+y+z
    end
  end
  puts m
end

Measured memory_bytes: 8792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; n>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define endl '\n'
template <class T> bool updmax(T& a, T b) { if (b > a) { a = b; return true;} return false;}
template <class T> bool updmin(T& a, T b) { if (b < a) { a = b; return true;} return false;}

struct price {
    int x;
    ll y=1;
    friend bool operator < (const price& a, const price& b) {
        return a.get() < b.get();
    }
    void discount() {
        if (y > 1LL << 60)
            return;
        y *= 2;
    }
    int get() const {
        return x/y;
    }
};
int main() {
    fastio;
    ll ans=0;
    ll N,M;
    cin >> N >> M;
    multiset<price> s;
    rep(i,N) {
        int a;
        cin >> a;
        s.insert({a});
    }
    while (M--) {
        auto im = --s.end();
        price p = *im;
        s.erase(im);
        p.discount();
        s.insert(p);
    }
    for (auto p : s) {
        ans += p.get();
    }
    cout << ans << endl;
}

Measured memory_bytes: 9732
H, W = map(int, input().split())
S = [input() for _ in range(H)]

# そのマスを含めてLeft, Right, Up, Downにそれぞれ何マス分明かりを照らせるかを配列に記録
L = [[0] * W for _ in range(H)]
R = [[0] * W for _ in range(H)]
D = [[0] * W for _ in range(H)]
U = [[0] * W for _ in range(H)]

for i in range(H):
	for j in range(W):
		if S[i][j] == ".":
			if j == 0:
				L[i][j] = 1
			else:
				L[i][j] = L[i][j - 1] + 1

for i in range(H):
	for j in range(W - 1, -1, -1):
		if S[i][j] == ".":
			if j == W - 1:
				R[i][j] = 1
			else:
				R[i][j] = R[i][j + 1] + 1

for j in range(W):
	for i in range(H - 1, -1, -1):
		if S[i][j] == ".":
			if i == H - 1:
				D[i][j] = 1
			else:
				D[i][j] = D[i + 1][j] + 1

for j in range(W):
	for i in range(H):
		if S[i][j] == ".":
			if i == 0:
				U[i][j] = 1
			else:
				U[i][j] = U[i - 1][j] + 1


ans = 0
X = [[0] * W for _ in range(H)]
for i in range(H):
	for j in range(W):
		X[i][j] = L[i][j] + R[i][j] + D[i][j] + U[i][j] - 3
	ans = max(ans, max(X[i]))

print(ans)

Measured memory_bytes: 211844
// AUTHOR: ROSHAN SRIVASTAVA
// WEBSITE: https://www.youtube.com/channel/UC6uQdd7kLLOdlHSVklhV7Cw

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007

int k, r, g, b; 

int main(){

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	cin>>r>>g>>b;
	cin>>k;

	while(r >= g) {
		g *= 2;
		k--;
	}

	while(g >= b) {
		b *= 2;
		k--;
	}

	if(k < 0) cout<<"No\n";
	else cout<<"Yes\n";

	return 0;
}

Measured memory_bytes: 3628
#include<stdio.h>
int main(void){
	int a[100],n,i;
	
	scanf("%d",&n);
	for(i=1; i<=n; i++){
		scanf("%d",&a[i]);
	}
	for(i=n; i>=1; i--){
		printf("%d",a[i]);
		if(i!=1) 
		printf(" ");
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 600
# すぬけ君がふぬけ君を追い越す必要があるならば
# 追い越すためのスペースが必要になる

def main():
    N,A,B,C,D = map(int,input().split())
    S = input()

    if S[A-1:C].count('##'):
        return 0

    if S[B-1:D].count('##'):
        return 0

    if D < C and not(S[B-2:D+1].count('...')):
        return 0

    return 1

print(['No','Yes'][main()])

Measured memory_bytes: 3572
#include<stdio.h>
#include<string.h>
#define MAX 100005
 
typedef struct pp{
  char name[100];
  int t;
}P;
 
void initialize(void);
int isEmpty(void);
int isFull(void);
void enqueue(P);
P dequeue(void);
 
 
P Q[MAX+1];
int head,tail,n;

int main()
{
  int c,elaps = 0;
  int i,q;
  P u;

  scanf("%d%d",&n,&q);

  initialize();

  tail = n;

  for (i = 0; i < n; i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
  }

  while(!isEmpty()){
    u = dequeue();
 
    if(u.t - q > 0){
      u.t -= q;
      enqueue(u);
      elaps += q;
    }
     else{
      elaps += u.t;
      printf("%s %d\n",u.name,elaps);
      u.t = -1;
    }
  }
   
  return 0;
}

void initialize()
{
  head = tail = 0;
}
 
int isEmpty()
{
  return head == tail;
}
 
int isFull()
{
  return head == ( tail + 1 ) % MAX;
}
 
void enqueue(P x)
{
  if(isFull()) return;

  Q[tail] = x;

  if(tail + 1 == MAX) tail = 0;
  else tail++;
}
 
P dequeue()
{
  P x;

  if(isEmpty()) return;

  x = Q[head];

  if(head + 1 == MAX) head = 0;
  else head++;

  return x;
}
 

Measured memory_bytes: 10756
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef long long lli;
lli n;
vector<lli> r,l;
priority_queue<lli> pqr;
priority_queue<lli,vector<lli>,greater<lli> > pql;
lli ans;
int main(){
    cin >> n;
    r = vector<lli> (n);l = vector<lli> (n);
    for(lli i = 0;i < n;i++) cin >> l[i] >> r[i];
    pqr.push(l[0]);
    pql.push(l[0]);
    lli tr = 0,tl = 0;
    ans = 0;
    for(lli i = 1;i < n;i++){
        tl += r[i-1] - l[i-1];tr -= r[i] - l[i];
        if(pqr.top() > l[i] - tr)       ans += abs(pqr.top() - (l[i] - tr)),pqr.push(l[i] - tr),pqr.push(l[i] - tr),pql.push(pqr.top() + tr - tl),pqr.pop();
        else if(pql.top() < l[i] - tl)  ans += abs(pql.top() - (l[i] - tl)),pql.push(l[i] - tl),pql.push(l[i] - tl),pqr.push(pql.top() + tl - tr),pql.pop();
        else pqr.push(l[i] - tr),pql.push(l[i] - tl);
        //cout << pqr.top() + tr << " " << pql.top() + tl << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3692
class Dice(object):
    def __init__(self, nums):
        self.top, self.front, self.right, self.left, self.back, self.bottom = nums

    def roll(self, directions):
        if directions == 'E':
            self.top, self.right, self.left, self.bottom = self.left, self.top, self.bottom, self.right
            return

        if directions == 'N':
            self.top, self.front, self.back, self.bottom = self.front, self.bottom, self.top, self.back
            return

        if directions == 'S':
            self.top, self.front, self.back, self.bottom = self.back, self.top, self.bottom, self.front
            return

        if directions == 'W':
            self.top, self.right, self.left, self.bottom = self.right, self.bottom, self.top, self.left
            return

        self.roll(directions[0])
        self.roll(directions[1:])

if __name__ == '__main__':
    nums = [int(i) for i in input().split()]
    d = Dice(nums)
    q = int(input())
    for i in range(q):
        top, front = [int(x) for x in input().split()]

        if(top == d.front):
            d.roll('N')
        elif(top == d.right):
            d.roll('W')
        elif(top == d.left):
            d.roll('E')
        elif(top == d.back):
            d.roll('S')
        elif(top == d.bottom):
            d.roll('NN')

        if(front == d.right):
            d.roll('WSE')
        elif(front == d.left):
            d.roll('ESW')
        elif(front == d.back):
            d.roll('SENWSE')

        print(d.right)

Measured memory_bytes: 6776