akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#define M 1024
int main() {
  char t[M],*c;
  int i,s,n=0,a[10000];
  while(fgets(t,M,stdin)){
    if(0==atoi(t))break;
    c=t;
    s=0;
    while(*c!='\n'&&*c!='\0')s+=*c++ - '0';
    a[n]=s;
    n++;
  }
  for(i=0;i<n;i++)printf("%d\n",a[i]);
  return 0;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

const ll mod=1e9+7;

int N,X,Y,Z;
int S;

bool nx[1<<16][11];
ll dp[41][1<<16];

ll dfs(int now, int state)
{
    if(dp[now][state]>=0) return dp[now][state];
    if(now==N) return 1;

    ll ret=0;
    //次に選ぶ数
    for(int i=1; i<=10; ++i)
    {
        if(nx[state][i])
        {
            ret+=dfs(now+1, ((state<<i)+(1<<(i-1)))%(1<<S));
            ret%=mod;
        }
    }

    return dp[now][state]=ret;
}

int main()
{
    cin >>N >>X >>Y >>Z;
    S=X+Y+Z-1;

    //状態maskの時に，次の数iが来ていいかチェックしておく
    rep(mask,1<<S)
    {
        //直前の状態を復元
        vector<int> b;
        int st=0;
        rep(i,S)
        {
            if(mask>>i&1)
            {
                b.pb(i-st+1);
                st=i+1;
            }
        }

        int B=b.size();
        //jを次に選んだ時にXYZを含まないかチェック
        for(int i=1; i<=10; ++i)
        {
            bool ok=true;
            //直前から順番に見ていき貪欲に足していく
            int x=0,y=0,z=i;
            int bidx=0;
            while(bidx<B && z<Z) z+=b[bidx++];
            while(bidx<B && y<Y) y+=b[bidx++];
            while(bidx<B && x<X) x+=b[bidx++];
            if(x==X && y==Y && z==Z) ok=false;

            nx[mask][i]=ok;
        }
    }

    //全体は10^N通り
    ll p10=1;
    rep(i,N) p10=(p10*10)%mod;

    memset(dp,-1,sizeof(dp));
    //XYZを含まない数列の個数
    ll r=dfs(0,0);
    //全体から引く
    ll ans=(p10-r+mod)%mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 21888
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	static void solve(){//Here is the main function
		int N = nextInt();
		int count = 0;
		for(int i = 0; i < N; i++){
			ArrayList<Integer> tmp = nextIntArray();
			if(tmp.get(0) == tmp.get(1)){
				count++;
			}else{
				count = 0;
			}
			if(count == 3){
				myout("Yes");
				return;
			}
		}
		myout("No");

	}
	//Method addition frame start



	//Method addition frame end

	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	@SuppressWarnings("unchecked")
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
}


Measured memory_bytes: 32976
#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i+=1)
#define reps(i,a,b) for(int i=a;i>=b;i-=1)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define pi pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define in1(x) int x; cin>>x;
#define in2(x, y) int x, y; cin>>x>>y;
#define in3(x, y, z) int x, y, z; cin>>x>>y>>z;
#define in4(x, y, z, w) int x, y, z, w; cin>>x>>y>>z>>w;
#define mi unordered_map<int,int>
#define mem(x) memset(x, 0, sizeof(x))
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
using namespace std;

//bool primes[1000001];vi prime;
//void seive(){memset(primes, true, sizeof(primes));primes[0] = primes[1] = false;for(int i = 2; i*i<=1000000;i += 1){
//if(primes[i]){for(int j = i*i; j <= 1000000;j += i) primes[j] = false;}}rep(i, 2, 1000001){if(primes[i]) prime.pb(i);}}
//int gcd(int a, int b){return b==0 ? a : gcd(b, a%b);}
//int power(int x, int y){ int res = 1;x = x % mod; if (x == 0) return 0;
//while (y > 0){ if(y & 1) res = (res*x) % mod; y = y>>1; x = (x*x) % mod;} return res;}

int32_t main(void){
	IOS;
	in2(n, k);
	int arr[n];
	rep(i, 0, n) cin>>arr[i];
	sort(arr, arr+n);
	int ans = 0;
	rep(i, 0, k) ans += arr[i];
	cout<<ans<<endl;
}

Measured memory_bytes: 3660
#ABC051
sx,sy,tx,ty = list(map(int,input().split()))
x,y = [tx-sx,ty-sy]
s = "U"*y+"R"*x+"D"*y+"L"*x + "L"+"U"*(y+1)+"R"*(x+1)+"D"+"R"+"D"*(y+1)+"L"*(x+1)+"U"
print(s)



Measured memory_bytes: 3060
import java.util.Scanner;

    public class Main {
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    		String s = sc.next();
    		String tmp ="";
    		int start=0;
    		int end=0;
    		for (int i=0;i<s.length();i++) {
    			tmp=s.substring(i,i+1);
    			if(tmp.equals("A")) {
    				start=i;
    				break;
    			}
    		}
    		for(int j=s.length()-1;j>0;j--) {
    			tmp=s.substring(j,j+1);
    			if(tmp.equals("Z")) {
    				end=j;
    				break;
    			}
    		}
    		System.out.println(end-start+1);
    	}
    }

Measured memory_bytes: 36328
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
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 n, a, b, c, d;
string s;

bool can_reach(int start, int goal) {
    for (int i = start; i < goal; i++) {
        if (s[i] == '#' && s[i+1] == '#') return false;
    }
    return true;
}

int main() {
    cin >> n >> a >> b >> c >> d >> s;
    a--; b--; c--; d--;

    if (!can_reach(a, c) || !can_reach(b, d)) {
        cout << "No" << endl;
        return 0;
    }

    bool ok = false;
    if (c < d) {
        ok = true;
    } else {
        for (int i = b; i <= d; i++) {
            if (s[i-1] == '.' && s[i] == '.' && s[i+1] == '.') ok = true;
        }
    }
    cout << (ok ? "Yes" : "No") << endl;
}


Measured memory_bytes: 644
n, k = map(int, input().split())

a = list(map(int, input().split()))

def IMOS(a):
    imos = [0]*n
    for i, ai in enumerate(a):
        imos[max(i-ai, 0)] += 1
        if i+ai+1 < n:
            imos[i+ai+1] -= 1
    for i in range(1, n):
        imos[i] += imos[i-1]
    return imos

for _ in range(k):
    if sum(a) == n*n:
        break
    a = IMOS(a)

print(*a)

Measured memory_bytes: 151368
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define mp make_pair
#define ll long long
#define pb push_back

void solve()
{
  long long a,b,c,d;
  cin>>a>>b>>c>>d;

  long long ans = a*c;
  ans = max(ans, b*c);
  ans = max(ans, b*d);
  ans = max(ans, a*d);

  cout<<ans<<endl;

}

int main()
{
    int t = 1;
    //cin>>t;

    while(t--)
    {
        solve();
    }
}


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

int main() {
  int n;
  cin>>n;
  vector<int>a(n+1);
  for(int i=1;i<=n;i++) cin>>a[i];
  vector<bool>b(n+1);
  for(int i=1;i<=n;i++) b[i]=true;
  bool c=false;
  int ans=0;
  int i=1;
  while(b[i]){
    ans++;
    b[i]=false;
    if(a[i]==2) {
      c=true;
      break;
    }
    else i=a[i];
  }
  if(c) cout<<ans<<endl;
  else cout<<-1<<endl;
}

Measured memory_bytes: 640
import java.util.*;
import java.io.*;

public class Main
{
	public static void main(String [] Args)
	{
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		if((n/100)*5>=n%100)
			System.out.println(1);
		else
			System.out.println(0);
	}
}
	

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	string S,T;
	int R;
	cin >> S >> T;
	for (int i=0; i<3; i++){
		if (S.at(i) == T.at(i)){
			R++;
		}
	}
	cout << R << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

#define int long long

#if defined(__GNUC__)
#define __int32 __int32_t
#endif // __GNUC__

#define itn __int32
#define REP(i, n) for(itn (i) = 0; (i) < (n); (i)++)
#define REP2(i, x, n) for(itn (i) = x; (i) < (n); (i)++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SORT(x) sort(ALL(x))
#define RSORT(x, T) sort(ALL(x), greater<T>())
#define REVERCE(x) reverce(ALL(x))

#define INT_POW(x, y) [](int a, int b) -> int {int c = a; REP(i, b - 1){c *= a;} return c;}(x, y)
#define INT_POWM(x, y, m) [](int a, int b, int m) -> int {int c = a; REP(i, b - 1){c *= a; c %= m;} return c;}(x, y, m)



itn main() {
	ios::sync_with_stdio(false);

	int h, w, k;

	cin >> h >> w >> k;

	if (k == 1) {
		REP(i, h) {
			REP(j, w) {
				cout << 1 << ' ';
			}
			cout << '\n';
		}
		return 0;
	}

	vector<vector<char>> s(h);

	REP(i, h) {
		s[i].resize(w);
		REP(j, w) {
			cin >> s[i][j];
		}
	}

	int cnt = 0;
	int obj = 0;
	int inner_cnt = 0;
	int tmp_ic;
	int base_num = 1;
	int adnum = 0;

	while (true) {
		if (count(s[cnt].begin(), s[cnt].end(), '#')) {
			break;
		}
		cnt++;
	}

	obj = cnt;
	inner_cnt = count(s[cnt].begin(), s[cnt].end(), '#');
	tmp_ic = inner_cnt;

	int loop_t = obj + 1;

	REP(i, loop_t) {
		REP(j, w) {
			cout << (base_num + adnum) << ' ';
			if (s[obj][j] == '#') {
				inner_cnt--;
				if (inner_cnt) {
					adnum++;
				}
			}
		}
		cout << '\n';
		adnum = 0;
		inner_cnt = tmp_ic;
	}

	REP2(i, loop_t, h) {

		if (count(s[i].begin(), s[i].end(), '#')) {
			base_num += tmp_ic;
			tmp_ic = inner_cnt = count(s[i].begin(), s[i].end(), '#');
			obj = i;
		}

		REP(j, w) {
			cout << (base_num + adnum) << ' ';
			if (s[obj][j] == '#') {
				inner_cnt--;
				if (inner_cnt) {
					adnum++;
				}
			}
		}

		cout << '\n';
		adnum = 0;
		inner_cnt = tmp_ic;
	}

	return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
vector<pair<pair<int,int>,pair<int,int>>>anst;

int main(void){
	int h,w;
	cin>>h>>w;
	int a[h+1][w+1];
	int oddnum=0;
	int isodd[h+5][w+5];
	memset(a,0,sizeof(a));
	memset(isodd,0,sizeof(isodd));
	vector<pair<int,int>>t(h*w+5);
	int k=0;
	memset(isodd,0,sizeof(0));
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>a[i][j];
			if(a[i][j]%2!=0){
				oddnum+=1;
				isodd[i][j]=1;
				//t.push_back(make_pair(make_pair(i,j),1));
				t[k] = make_pair(i,j);
				k++;
			}
		}
	}

	int v[h+2][w+2];
	memset(v,0,sizeof(v));
	bool toggle=true;
	bool flag=false;
	int x=0,y=0;
	int cnt=0;
	int flag2=false;
	for(int i=0;i<h;i++){
		if(!flag){
			x=0;y=0;
		}
		if(toggle){
			if(flag){
				y=i-1;x=0;
				flag2=true;
			}
			for(int j=0;j<w;j++){
				if((isodd[i][j]&1)&&flag==false){
					cnt++;
					y=i;x=j;
					flag=true;continue;
				}
				if(flag){
					if(isodd[i][j]&1){
						cnt++;
						//if(v[y][x]==1)continue;
						flag=false;
						anst.push_back(make_pair(make_pair(y,x),make_pair(i,j)));
						if(flag2){
							y++;flag2=false;x--;
						}
						v[y][x]=1;
						x=0;y=0;
						//continue;
					}else{
						//if(v[y][x]==1)continue;
						anst.push_back(make_pair(make_pair(y,x),make_pair(i,j)));
						if(flag2){
							y++;flag2=false;x--;
						}
						v[y][x]=1;
						x++;
					}
				}
			}
			toggle=false;
		}else{
			if(flag){
				y=i-1;x=w-1;
				flag2=true;
			}
			for(int j=w-1;j>=0;j--){
				if((isodd[i][j]&1)&&flag==false){
					cnt++;
					y=i;x=j;
					flag=true;continue;
				}
				if(flag){
					if(isodd[i][j]&1){
						//if(v[y][x]==1)continue;
						cnt++;
						flag=false;
						anst.push_back(make_pair(make_pair(y,x),make_pair(i,j)));
						if(flag2){
							y++;flag2=false;x++;
						}
						v[y][x]=1;
						x=0;y=0;
						//continue;
					}else{
						//if(v[y][x]==1)continue;
						anst.push_back(make_pair(make_pair(y,x),make_pair(i,j)));
						if(flag2){
							y++;flag2=false;x++;
						}
						v[y][x]=1;
						x--;
					}
				}
			}
			toggle=true;
		}
	}

	//cout<<"a"<<endl;
	cout<<anst.size()<<endl;
	for(auto p:anst){
		cout<<p.first.first+1<<" "<<p.first.second+1<<" "<<p.second.first+1<<" "<<p.second.second+1<<endl;
	}
}


Measured memory_bytes: 9072
N, M = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(M)]
i = 10**(N-1) if N > 1 else 0
while i < 10**N:
  n = [(i//10**j)%10  for j in reversed(list(range(N)))]
  f = True
  for s, c in SC:
    if n[s-1] != c:
      f = False
  if f:
    break
  i += 1
if i >= 10**N:
  print(-1)
else:
  print(i)

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

using namespace std;
 
int main() {
    long long X, K, D;cin >> X >> K >> D;
    if (X<0) X=-X;
    if (X/D-K>=0){
        cout << X-K*D << endl;
    }
    else if((K-X/D)%2==0){
        cout << X%D << endl;
    }
    else {
        cout << D-X%D << endl;
    }
}

Measured memory_bytes: 3656
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef pair<ll,P> PP;
int t[102] = {};
int main() {
	int a, b, c, d; cin >> a >> b >> c >> d;
	Rep(i, a, b)t[i]++;
	Rep(i, c, d)t[i]++;
	int cnt = 0;
	rep(i, 102) {
		if (t[i] == 2)cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <climits>
#include <queue>
using namespace std;
typedef pair<int,pair<int,int> >NODE;
#define name first
#define val second
#define CST first
#define POS second.first
#define BIT second.second
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	int n;
	while(1){
		cin >> n;if(n==0)break;
		int N = n+1;
		vector< vector< pair<string,int> > > info(n);
		
		for(int i=0;i<n;i++){
			int k; cin >> k;
			for(int j=0;j<k;j++){
				string s;int value;
				cin >> s >> value;
				info[i].push_back(make_pair(s,value));
			}
		}
		int q; cin >> q; if(q==0){cout << 0 << endl;continue;}
		vector<string> wantList(q);
		rep(i,q)cin >> wantList[i];
		sort(wantList.begin(),wantList.end());
		
		vector< pair<int,int> > ret;
		
		for(int bit=0;bit<(1<<n);bit++){
			map<string,int> data;
			rep(i,q)data[wantList[i]] = 10001;
			for(int j=0;j<n;j++){
				if(bit & (1<<j) ){
					rep(i,info[j].size()){
						int value = info[j][i].val;
						string name = info[j][i].name;
						if(count(wantList.begin(),wantList.end(),name)){
							data[name] = min(data[name],value);
						}
					}
				}
			}
			bool f = false;
			int sum = 0;
			rep(i,q){
				if(data[wantList[i]] == 10001)f=true;
				sum += data[wantList[i]];
			}
			if(f)continue;
			ret.push_back( make_pair(sum,bit) );
		}
		sort(ret.begin(),ret.end());
		
				
		int m; cin >> m;
		int wf[11][11]; rep(x,11)rep(y,11)wf[x][y] = (1<<21);
		rep(i,11)wf[i][i] = 0;
		
		rep(i,m){
			int a,b,c;
			cin >> a >> b >> c;
			wf[a][b] = wf[b][a] = c;
		}
		
		int homo = INT_MAX;
		
		rep(k,11)rep(i,11)rep(j,11)
			wf[i][j] = min(wf[i][j],wf[i][k]+wf[k][j]);
			
		int mostMin; if(ret.size())mostMin = ret[0].first;
		
		int dp[1<<11][11];
		
		rep(x,1<<11)rep(y,11)dp[x][y]=(1<<21);
		
		dp[1][0] = 0;
		rep(bit,1<<N){
			rep(pos,N){
				if(bit & (1<<pos) == 0)continue;
				rep(next,N){
					if((1<<next) & bit)continue;
					int nextbit = bit | (1<<next);
					dp[nextbit][next] = min(dp[nextbit][next], dp[bit][pos]+wf[pos][next]);
				}
			}
		}
		
		/*rep(i,1<<N){
			rep(j,N)
				cout << dp[i][j] << " ";
			cout << endl;
		}*/
		rep(t,ret.size()){
			if(ret[t].first != mostMin )break;
			int bitch = (ret[t].second<<1)+1;
			for(int i=1;i<n;i++)
				homo = min(homo,dp[bitch][i]+wf[i][0]);
		}
		if(homo == INT_MAX)cout << "impossible" << endl;
		else cout << mostMin << " " << homo << endl;
	}
	
}

Measured memory_bytes: 1040
import java.util.Scanner;
import java.lang.Math;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
			int N =sc.nextInt();	
			int T =sc.nextInt();
			int A =sc.nextInt();
			int []H=new int[N];
			double []J=new double[N];
			double []K=new double[N];
			double min=100000;
			int mini=0;
						
				for(int i=0;i<N;i++){
					H[i]=sc.nextInt();
				}
				for(int i=0;i<N;i++){
					J[i]=T-H[i]*0.006;
				}
				for(int i=0;i<N;i++){
					K[i]=Math.abs(A-J[i]);
				}
				for(int i=0;i<N;i++){
					if(K[i]<min){
						min=K[i];
						mini=i+1;
					}
				}
			System.out.println(mini);
	}
}

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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;

template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }

const int INF = 1L << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = { 0, 1, 0, -1 }, dx4 = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };

using namespace std;


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

	int N;
	cin >> N;

	vector<int> dp(100100, 0);
	FOR(i, 0, N) {
	    int a, b;
	    cin >> a >> b;
	    dp[a] += 1;
	    dp[b + 1] -= 1;
	}

	FOR(i, 0, dp.size() - 1) {
	    dp[i + 1] += dp[i];
	}

	int ans = 0;
	FOR(i, 0, dp.size()) {
	    if (dp[i] >= i - 1) {
            ans = max(ans, i - 1);
        }
	}
	print(ans);

	return 0;
}


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

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

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


int main()
{
	int n;
	cin>>n;
	int *a = new int[n];
	for(int i = 0; i < n; i++){
		cin>>a[i];
	}
	for(int i = n -1; i >= 0 ; i--){
		if(i == 0){
			cout<< a[i];
		}else{
			cout<< a[i] <<" ";
		}
	}
	cout<<endl;
	delete a;
	return 0;
}

Measured memory_bytes: 3048
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <functional>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

int main()
{
    const int vsize = 200010;
    ll n;
    vector<ll> a(vsize, 0);
    ll sum = 0;
    cin >> n;
    rep(i, n)
    {
        cin >> a[i];
        sum = sum ^ a[i];
    }
    rep(i, n)
    {
        if (i + 1 < n)
        {
            cout << (sum ^ a[i]) << " ";
        }
        else
        {
            cout << (sum ^ a[i]) << endl;
        }
    }
}

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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define pll         pair<long,long>
#define vi          vector<int>
#define vll         vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define mod        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rem(i,a,b)  for(int i=a;i>b;i--)
#define mp(a,b)     make_pair(a,b)
#define vvi(a,b,name)    vector<vector<int>> name(a,vector<int>(b,-1))


void solve(){
    int a,b,c;cin>>a>>b>>c;
    rep(i,0,b){
        if((i*a)%b==c){
            cout<<"YES";
            return;
        }
    }
    cout<<"NO";

}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
ll factorial(int i) {       //階乗
    if (i == 0) return 1;
    return (factorial(i - 1)) * i;
}

int main() {
    int n;
    cin >> n;
    set<string> ans;
    string s;
    rep(i, n) {
        cin >> s;
        ans.insert(s);
    }
    cout << ans.size() << endl;
}

Measured memory_bytes: 19264
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int ninzu = sc.nextInt();
    int[] iro = new int[8];
    int ziyu = 0;
    int a;
    int kazu = 0;
    for(int i=0; i<ninzu; i++){
      a = sc.nextInt()/400;
      switch(a){
        case 0:
          iro[0] = 1;
          break;
        case 1:
          iro[1] = 1;
          break;
        case 2:
          iro[2] = 1;
          break;
        case 3:
          iro[3] = 1;
          break;
        case 4:
          iro[4] = 1;
          break;
        case 5:
          iro[5] = 1;
          break;
        case 6:
          iro[6] = 1;
          break;
        case 7:
          iro[7] = 1;
          break;
        default:
          ziyu++;
          break;
      }
    }
    for(int o=0; o<8; o++){
      if(iro[o] == 1)
        kazu++;
    }
    if(kazu > 0){
      System.out.print(kazu + " ");
    }else{
      System.out.print(1 + " ");
    }
    kazu += ziyu;
    System.out.print(kazu);
  }
}

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

using namespace std;
using ll=long long;

int main()
{
   int n;cin >>n;
   int s=0;
   while(n>0){
    s+=n%10;
    n/=10;
   }
   if(s==1)cout << 10 << endl;
   else cout << s << endl;
    return 0;
}


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

void Main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n){
		cin >> a[i];
	}
	reverse(a.begin(), a.end());
	rep(i, n){
		cout <<a[i];
		if(i != n - 1){
			cout << ' ';
		}
	}
	cout << endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 3220
#include <iostream>
using namespace std;
int ba(int a[],int n){
    int sw=0,i,j;
    bool flag=1;
    for ( i = 0;flag; i++) {
        flag=0;
        for ( j = n-1; j >= i+1 ; j--) {
            if(a[j]<a[j-1]){
                swap(a[j],a[j-1]);
                flag=1;
                sw++;
            }
        }
    }
    return sw;
}
int main() {
    int i,j,a;
    int array[100];
    cin >>  a;
    for (i = 0; i <a ; i++) {
        cin >> array[i];}
    j= ba(array, a);
    for ( i = 0; i < a; i++) {
        if(i) cout<<" ";
        cout<<array[i];
    }
    cout<<endl;
    cout<<j<<endl;
    return 0;
}

Measured memory_bytes: 3116
r, g, b, n = gets.split(" ").map(&:to_i)

count = 0

sum = 0

0.upto(3000) do |index|
  0.upto(3000) do |index2|
    sum = r * index + g * index2
    if (n - sum) % b == 0 && n >= sum
      count += 1
    end
  end
end

puts count

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

int n;
int a[1000];
int a1[1000];
int a2[1000];
void dfs(int s,int s1, int s2){
    if(s==10){
        return ;
    }
    if(s1==0 && s2==0){
        a1[s1]=a[s];
        dfs(s+1,s1+1,s2);
    }else{
        if(s1==0){
            if(a2[s2-1]<a[s]){
                a2[s2] = a[s];
                dfs(s+1,s1,s2+1);
            }else{
                a1[s1] = a[s];
                dfs(s+1,s1+1,s2);
            }
        }else if(s2==0){
            if(a1[s1-1]<a[s]){
                a1[s1] = a[s];
                dfs(s+1,s1+1,s2);
            }else{
                a2[s2] = a[s];
                dfs(s+1,s1,s2+1);
            }
        }else{
            if(a1[s1-1]<a[s]){
                a1[s1] = a[s];
                dfs(s+1,s1+1,s2);
            }else if(a2[s2-1]<a[s]){
                a2[s2] = a[s];
                dfs(s+1,s1,s2+1);
            }else{
                return ;
            }
        }
    }
}
int main(){
    while(~scanf("%d",&n)){
        while(n--){
            for(int i=0;i<10;i++){
                scanf("%d",&a[i]);
            }
            memset(a1,-1,sizeof(a1));
            memset(a2,-1,sizeof(a2));
            dfs(0,0,0);
            int i=0,j=0;
            for(;;i++){
                if(a1[i]==-1){
                    break;
                }
            }
            for(;;j++){
                if(a2[j]==-1){
                    break;
                }
            }
            if(i+j==10){
                printf("YES\n");
            }else{
                printf("NO\n");
            }
        }
    }
}


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

using namespace std;

int main()
{
    int n, k, c;    cin >> n >> k >> c;
    string s;       cin >> s;

    c++;
    s = "o" + s + "o";

    vector <int> Dp1(n + 2, 0);
    vector <int> Dp2(n + 2, 0);

    for(int Max = 0, i = 1; i <= n; i++)
    {
        if(i - c >= 0)
            Max = max(Max, Dp1[i - c]);

        if(s[i] == 'o')
            Dp1[i] = 1 + Max;
    }

    for(int Max = 0, i = n; i >= 1; i--)
    {
        if(i + c <= n + 1)
            Max = max(Max, Dp2[i + c]);

        if(s[i] == 'o')
            Dp2[i] = 1 + Max;
    }

    vector <int> PrefixMaxDp1 = Dp1;
    vector <int> SuffixMaxDp2 = Dp2;

    for(int i = 1; i <= n + 1; i++) PrefixMaxDp1[i] = max(PrefixMaxDp1[i], PrefixMaxDp1[i - 1]);
    for(int i = n; i >= 0; i--)     SuffixMaxDp2[i] = max(SuffixMaxDp2[i], SuffixMaxDp2[i + 1]);

    vector <int> Ans;
    multiset <int> Can;

    if(c == 1)  c++;

    for(int i = 1; i <= n; i++)
    {
        if(i + c <= n + 1)  Can.insert(PrefixMaxDp1[i - 1] + SuffixMaxDp2[min(n + 1, i - 1 + c)]);
        if(i - c >= 0)  Can.erase(Can.find(PrefixMaxDp1[i - c] + SuffixMaxDp2[i]));

        if(PrefixMaxDp1[i - 1] < k && SuffixMaxDp2[i + 1] < k && (Can.empty() || *Can.rbegin() < k))    Ans.push_back(i);
    }

    for(int i : Ans)    printf("%d\n", i);
}


Measured memory_bytes: 5816
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

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

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

    string S, T;
    cin >> S >> T;
    ll n_s = S.size(), n_t = T.size();
    vec s_s(n_s+1, 0), s_t(n_t+1, 0);

    Rep (i, n_s) {
        if (S[i] == 'A') {
            s_s[i+1] = s_s[i] + 1;
        } else {
            s_s[i+1] = s_s[i] + 2;
        }
    }

    Rep (i, n_t) {
        if (T[i] == 'A') {
            s_t[i+1] = s_t[i] + 1;
        } else {
            s_t[i+1] = s_t[i] + 2;
        }
    }

    ll q;
    cin >> q;

    while (q--) {
        ll a, b, c, d;
        cin >> a >> b >> c >> d;
        a--; c--;
        if (abs(s_s[b]-s_s[a]-s_t[d]+s_t[c]) % 3 == 0) {
            cout << "YES\n";
        } else {
            cout << "NO\n";
        }
    }

}

Measured memory_bytes: 2640
import sys
from collections import deque

H, W = map(int, input().split())
c = [input() for a in range(H)]

d = [[ sys.maxsize for b in range(W)] for a in range(H)]

dy = [1, 0, -1, 0]
dx = [0, 1, 0, -1]

q = deque()

for y in range(H):
  for x in range(W):
    if c[y][x] == '#':
      q.append([y, x])
      d[y][x] = 0
ans = 0
while len(q) > 0:
  y, x = q.popleft()
  for i in range(4):
    ny = y + dy[i]
    nx = x + dx[i]
    if 0 <= nx and nx <= W-1 and 0 <= ny and ny <= H-1 and c[ny][nx] == '.' and d[ny][nx] == sys.maxsize:
      q.append([ny, nx])
      d[ny][nx] = d[y][x]+1
      ans = max(ans, d[ny][nx])

      
print(ans)


Measured memory_bytes: 142300
import math

a, b, x = [int(x) for x in input().split()]

if a * a * b // 2 <= x:
	y = a * a * b - x
	h = y * 2 / a / a
	t = math.atan2(h, a)
else:
	h = x * 2 / a / b
	t = math.pi / 2 - math.atan2(h, b)

print(math.degrees(t))


Measured memory_bytes: 2940
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    a = int(input())
    s = input()[:-1]

    if a>=3200:
        print(s)
    else:
        print("red")


if __name__ == '__main__':
    main()

Measured memory_bytes: 5828
/*
 Shahadat Hossain
 I.C.T Department
 Comilla University
 Session: 2013-2014
 */

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

#define int long long
#define valid(x,y) x>=0 && y>=0 && x<n && y<n
#define all(x) x.begin(),x.end()
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define ms(a,b) memset(a, b, sizeof(a))
#define eps 1e-5
#define input freopen("/Users/shahadat/Desktop/input.txt", "r", stdin)
#define output freopen("/Users/shahadat/Desktop/output.txt", "w", stdout)
#define d(x) cout << #x << " = " << x << endl
#define dd(x,y) cout << #x << " = " << x << "   " << #y << " = " << y << endl
#define ddd(x,y,z) cout << #x << " = " << x << "   " << #y << " = " << y << "   " << #z << " = " << z << endl
//fprintf(stdout,"\nTIME: %.3lf sec\n", (double)clock()/(CLOCKS_PER_SEC));
//int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
#define bit(n,k) (((n)>>(k))&1)
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define pr(x) {cout << (x) << '\n';  }
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define mask(i) ((1LL<<(i)))
#define endl '\n'
double const PI = acos(-1);
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

struct Item{
    int a, b, c;
    Item(): a(), b(), c() {}
    
    void scan(){
        cin >> a >> b >> c;
    }
};

int const N = 1e5 + 5;

int n;
int ar[N][3];
int dp[N][3];

int32_t main(){
    cin >> n;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            cin >> ar[i][j];
        }
    }
    
    
    dp[0][0] = ar[0][0];
    dp[0][1] = ar[0][1];
    dp[0][2] = ar[0][2];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                if(j == k) continue;
                dp[i + 1][k] = max(dp[i + 1][k], ar[i + 1][k] + dp[i][j]);
            }
        }
    }
    int res = max(dp[n][0], max(dp[n][1], dp[n][2]));
    cout << res << endl;
}




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

using LL = long long;

#define ALL(a) begin((a)), end((a))
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define RFOR(i, a, b) for (int(i) = (a); (i) > (b); (i)--)
#define debug(x) cout << #x << " : " << x << '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const LL LINF = 1e16;

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

  string ans = "No";
  string S;
  cin >> S;

  if (S[0] == S[1]) {
    if (S[2] == S[3] && S[0] != S[2] && S[1] != S[3]) {
      ans = "Yes";
    }
  }
  if (S[0] == S[2]) {
    if (S[1] == S[3] && S[0] != S[1] && S[2] != S[3]) {
      ans = "Yes";
    }
  }
  if (S[0] == S[3]) {
    if (S[1] == S[2] && S[0] != S[1] && S[2] != S[3]) {
      ans = "Yes";
    }
  }

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 256
from itertools import product
N = int(input())
K = int(input())
cmin = 10**4
for x in product((0,1),repeat=N):
    cnt = 1
    for i in range(N):
        if x[i]==0:
            cnt = cnt*2
        else:
            cnt += K
    cmin = min(cmin,cnt)
print(cmin)

Measured memory_bytes: 65732
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Queue;

public class Main implements Runnable{

	public static void main(String[] args) {
		new Thread(null,new Main(), "" ,Runtime.getRuntime().maxMemory()).start();
	}
	
	public void run() {
		FastScanner sc=new FastScanner();
		String str=sc.next();
		boolean ans=str.length()%2==0;
		for(int i=0;i+1<str.length();i+=2) {
			ans&=str.substring(i,i+2).equals("hi");
		}
		System.out.println(ans?"Yes":"No");
	}
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 23252
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#define int long long
template<typename T> inline bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> inline bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }

int main() {
    int H, W, N;
    cin >> H >> W >> N;
    if (H < W) swap(H, W);
    cout << (N + H - 1) / H << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;

  string ans = "No";
  for (int i = 0; i <= n/7; i++) {
    for (int j = 0; j <= n/4; j++ ){
        if (7 * i + 4 * j  == n) ans = "Yes";
    }
  }

  cout << ans << endl;

}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <string.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
#define INF 100000000
using namespace std;

int path[101][101];

int dijkstra(int s,int g,int n){
	long long d[101];
	bool used[101];
	memset(d,0x3f,sizeof(d));
	memset(used,0,sizeof(used));
	d[s]=0;
	while(1){
		int v=-1;
		for(int u=1;u<=n;u++){
			if(!used[u]&&(v==-1||d[u]<d[v])) v=u;
		}
		if(v==-1) break;
		used[v]=true;
		for(int u=1;u<=n;u++){
			d[u]=min(d[u],d[v]+path[v][u]);
		}
	}
	return d[g];
}

int main(){
	int n,k;
	while(1){
		cin>>n>>k;
		if(n==0&&k==0) return 0;
		memset(path,0x3f,sizeof(path));
		for(int i=0;i<k;i++){
			int tmp;
			cin>>tmp;
			if(tmp){
				int c,d,e;
				cin>>c>>d>>e;
				path[c][d]=path[d][c]=min(e,path[c][d]);//c??¨d?????????e
			}
			else{
				int a,b;
				long long res=0;
				cin>>a>>b;
				res=dijkstra(a,b,n);//a??????b?????§?????????????????????
				if(res>INF) cout<<"-1"<<endl;
				else cout<<res<<endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3028
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int a, b; cin >> a >> b;
    cout << (a <= 8 and b <= 8 ? "Yay!" : ":(") << endl;
}

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

#define mem(t, v)   memset ((t) , v, sizeof(t))
#define all(x)      x.begin(),x.end()
#define un(x)       x.erase(unique(all(x)), x.end())
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sl(n)       scanf("%lld", &n)
#define sll(a,b)    scanf("%lld %lld", &a, &b)
#define slll(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
#define D(x)        cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define DD(x,y)     cerr << __LINE__ << ": " << #x << " = " << x << "   " << #y << " = " << y << '\n'
#define DDD(x,y,z)  cerr << __LINE__ << ": " << #x << " = " << x << "   " << #y << " = " << y << "   " << #z << " = " << z << '\n'
#define DBG         cerr << __LINE__ << ": Hi" << '\n'
#define pb          push_back
#define PI          acos(-1.00)
#define xx          first
#define yy          second
#define eps         1e-9

typedef unsigned long long int ULL;
typedef long long int LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;


inline int setBit(int N, int pos) { return N=N | (1<<pos); }
inline int resetBit(int N, int pos) { return N= N & ~(1<<pos); }
inline bool checkBit(int N, int pos) { return (bool)(N & (1<<pos)); }

//int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1};
//int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1}; //Four & Eight Direction
vector<LL>A, B;
LL csum[2][100010];
int main()
{
    //freopen("maxon.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n, k;
    sff(n, k);
    for(int i = 1; i<=n; i++)
    {
        LL a;
        sl(a);
        if(a < 0)
            A.pb(-a);
        else
            B.pb(a);
    }
    sort(all(A));
    sort(all(B));


    LL res = 1e18;
    for(int i = 0; i<=min(k, (int)A.size()); i++)
    {
        int j = k - i;
        if(j > B.size())
            continue;
        LL a = 0, b = 0;
        if(i)
            a = A[i-1];
        if(j)
            b = B[j-1];
        LL tmp = min(a*2 + b, a + b*2);
        res = min(res, tmp);
    }
    cout << res << endl;
    return 0;
}




Measured memory_bytes: 1656
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const [a, b, c] = stdin
  .split('\n')[0]
  .split(' ')
  .map(Number)

const s = [a, b, c].sort((a, b) => b - a)

const max = s[0]

const diff = s[0] - s[1] + s[0] - s[2]

const res = _ => {
  let count = Math.ceil(diff / 2)

  if (diff % 2 !== 0) count++

  return count
}

console.log(res())


Measured memory_bytes: 7372
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
//#define INF (INT_MAX/2)
#define EPS (1.0e-8)
//#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


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

    int N; cin >> N;
    vi A(N); REP(i, N) cin >> A[i];

    map<string, int> mp;
    REP(i,N){
        if (1<=A[i] && A[i]<=399) {
            mp["gray"]++;
        } else if (400 <= A[i] && A[i] <= 799) {
            mp["brown"]++;
        } else if (800 <= A[i] && A[i] <= 1199) {
            mp["green"]++;
        } else if (1200 <= A[i] && A[i] <= 1599) {
            mp["light_blue"]++;
        } else if (1600 <= A[i] && A[i] <= 1999) {
            mp["blue"]++;
        } else if (2000 <= A[i] && A[i] <= 2399) {
            mp["yellow"]++;
        } else if (2400 <= A[i] && A[i] <= 2799) {
            mp["orange"]++;
        } else if (2800 <= A[i] && A[i] <= 3199) {
            mp["red"]++;
        } else if (3200 <= A[i]) {
            mp["super"]++;
        }
    }

    int lo = 0, hi = 0;
    if (mp.count("super") > 0) {
        for(auto p : mp) {
            if (p.first == "super") continue;
            lo++;
        }
        if (lo == 0) {
            lo = 1;
            hi = mp["super"];
        } else {
            hi = lo + mp["super"];
        }
    } else {
        for(auto p : mp) {
            lo++;
        }
        hi = lo;
    }

    cout << lo << " " << hi << endl;

    return 0;
}


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

int main(void){
    int ans ;
    string s ;
    cin >> s ;
    if (s=="SUN"){
        ans=7 ;
    } else if (s=="MON"){
        ans=6 ;
    } else if (s=="TUE"){
        ans=5 ;
    } else if (s=="WED"){
        ans=4 ;
    } else if (s=="THU"){
        ans=3 ;
    } else if (s=="FRI"){
        ans=2 ;
    } else {
        ans=1 ;
    }
    cout << ans << endl ;
}

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

typedef struct directedGraph{
  int *vertex;
  int *next;
  int *start;
  int v,e;
  int pointer;
} graph;

graph* newGraph(const int v,const int e){
  graph *g=(graph *)malloc(sizeof(graph));
  g->vertex=(int *)calloc(e,sizeof(int));
  g->next=(int *)calloc(e,sizeof(int));
  g->start=(int *)calloc(v,sizeof(int));
  for(int i=0;i<v;i++) g->start[i]=-1;
  g->v=v;
  g->e=e;
  g->pointer=0;
  return g;
}

void freeGraph(graph *g){
  free(g->vertex);
  free(g->next);
  free(g->start);
  free(g);
  return;
}

void addEdge(graph *g,const int from,const int to){
  const int p=g->pointer;
  g->vertex[p]=to;
  g->next[p]=g->start[from];
  g->start[from]=p;
  g->pointer++;
  return;
}

void run(void){
  int n;
  scanf("%d",&n);
  if(n==1){
    printf("0\n");
    return;
  }
  graph *g=newGraph(n,2*n);
  int i;
  for(i=0;i<n-1;i++){
    int a,b;
    scanf("%d%d",&a,&b);
    a--;b--;
    addEdge(g,a,b);
    addEdge(g,b,a);
  }
  int *parent=(int *)calloc(n,sizeof(int));
  int *q=(int *)calloc(n,sizeof(int));
  int front=0;
  int last=0;
  q[last++]=0;
  while(last<n){
    int v=q[front++];
    for(int p=g->start[v];p!=-1;p=g->next[p]){
      int u=g->vertex[p];
      if(u==parent[v]) continue;
      parent[u]=v;
      q[last++]=u;
    }
  }
  double *dp1=(double *)calloc(n,sizeof(double));
  for(i=n-1;i>=0;i--){
    int v=q[i];
    double sum=0;
    int cnt=0;
    for(int p=g->start[v];p!=-1;p=g->next[p]){
      int u=g->vertex[p];
      if(u==parent[v]) continue;
      sum+=dp1[u];
      cnt++;
    }
    dp1[v]=cnt==0?0:(1+sum/cnt);
  }
  double *dp2=(double *)calloc(n,sizeof(double));
  double *ans=(double *)calloc(n,sizeof(double));
  for(i=0;i<n;i++){
    int v=q[i];
    double sum=dp2[v];
    int cnt=(i>0?1:0);
    for(int p=g->start[v];p!=-1;p=g->next[p]){
      int u=g->vertex[p];
      if(u==parent[v]) continue;
      sum+=dp1[u]+1;
      cnt++;
    }
    ans[v]=sum/cnt;
    for(int p=g->start[v];p!=-1;p=g->next[p]){
      int u=g->vertex[p];
      if(u==parent[v]) continue;
      dp2[u]=1;
      if(cnt>1) dp2[u]+=(sum-dp1[u]-1)/(cnt-1);
    }
  }
  for(i=0;i<n;i++) printf("%.9f\n",ans[i]);
}

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


Measured memory_bytes: 9600