akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;

struct UnionFind{
    vector<int> parent;
    vector<int> rank;
    UnionFind(int n):parent(n),rank(n){
        for (int i=0;i<n;i++){
            parent[i]=i;
            rank[i]=0;
        }
    }
    int root(int x){
        if (parent[x]==x)return x;
        return parent[x]=root(parent[x]);
    }
    void unite(int x, int y){
        int rx=root(x);
        int ry=root(y);
        if (rx==ry)return;
        if (rank[rx]<rank[ry]) parent[rx]=ry;
        else{
            parent[ry]=rx;
            if (rank[rx]==rank[ry]) rank[rx]++;
        }
    }
    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<pair<int,int>> X(n),Y(n); 
    vector<pair<int,pair<int,int>>> edge;
    UnionFind uf(d5);
    for(int i=0;i<n;i++){
        cin>>X[i].first>>Y[i].first;
        X[i].second=Y[i].second=i;
    }
    sort(All(X));
    sort(All(Y));
    for(int i=0;i<n-1;i++){
        edge.push_back(make_pair(abs(X[i].first-X[i+1].first),make_pair(X[i].second,X[i+1].second)));
        edge.push_back(make_pair(abs(Y[i].first-Y[i+1].first),make_pair(Y[i].second,Y[i+1].second)));
    }
    sort(All(edge));
    int res = 0;
    for (auto e : edge) {
        int u = e.second.first;
        int v = e.second.second;
        int cost = e.first;
        if (uf.same(u,v))continue;
        uf.unite(u,v);
        res += cost;
    }
    cout << res << endl;
}

Measured memory_bytes: 13168
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define Rep(i,n) for(int i=1; i<(n); i++)
using namespace std;
using ll = long long;
const ll INF = 1e9 + 7;

int dp[10010];
int main(){
    int h,n; cin >> h >> n;
    int a[1010],b[1010];
    rep(i,n) cin >> a[i] >> b[i];
    rep(i,10010) dp[i]=INF;
    dp[h]=0;//体力がｈある時のMP消費量
    
    for(int i=h; i>=0; i--){
        for (int j=0; j<n; j++){ //n個の呪文を全部試す
            if (i-a[j]<=0) dp[0]=min(dp[0],dp[i]+b[j]);
            else dp[i-a[j]]=min(dp[i-a[j]],dp[i]+b[j]);
        }
    }
    cout << dp[0] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
bool solve(void){
	int i,j,k,n,m;cin>>n>>m;
	if(n==0){return false;}
	vector<vector<llint>>land(n,vector<llint>(n,big));
	vector<vector<llint>>ship(n,vector<llint>(n,big));
	for(i=0;i<n;i++){land[i][i]=0;ship[i][i]=0;}
	for(i=0;i<m;i++){
		int x,y,t;char c;
		cin>>x>>y>>t>>c;x--;y--;
		if(c=='L'){mineq(land[x][y],t);mineq(land[y][x],t);}
			  else{mineq(ship[x][y],t);mineq(ship[y][x],t);}
	}
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			for(k=0;k<n;k++){
				mineq(land[j][k],land[j][i]+land[i][k]);
				mineq(ship[j][k],ship[j][i]+ship[i][k]);
			}
		}
	}
	int R,mae;cin>>R>>mae;R--;mae--;
	vector<llint>dco(n,big);dco[mae]=0;
	while(R--){
		int bas;cin>>bas;bas--;
		vector<llint>dp=dco;
		for(i=0;i<n;i++){dp[i]+=land[mae][bas];}//陸
		//海
		vector<llint>aaa(n,big);
		for(i=0;i<n;i++){dco[i]+=land[mae][i];}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				mineq(aaa[j],dco[i]+ship[i][j]);
			}
		}
		for(i=0;i<n;i++){mineq(dp[i],aaa[i]+land[i][bas]);}
		dco=dp;mae=bas;
	}
	llint ans=big;
	for(i=0;i<n;i++){mineq(ans,dco[i]);}
	cout<<ans<<endl;
	return true;
}
int main(void){
	cout<<fixed<<setprecision(20);
	cin.tie(0);ios::sync_with_stdio(false);
	while(solve()){}
	return 0;
}



Measured memory_bytes: 3460
#include <stdio.h>

int main(){

    int w, h, x, y, r; //入力値
    
    scanf ("%d%d%d%d%d", &w, &h, &x, &y, &r);

    if ( (x-r)>=0 && (y-r)>=0 && (x+r)<=w && (y+r)<=h ){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }

    return 0;
}



Measured memory_bytes: 2112
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import qualified Data.Set as S

main :: IO ()
main = do
  n <- unsafeTextToInt <$> T.getLine :: IO Int
  ss <- sequence . replicate n $ T.getLine :: IO [T.Text]
  print . count $ ss

count :: [T.Text] -> Int
count = S.size . foldl (flip S.insert) S.empty

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 81396
print_endline @@
  Scanf.scanf "%d" @@ fun n ->
  let a = Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0)) in
  Array.sort (-) a;
  let l, r = a.(0), a.(n-1) in
  if r-l >= 2 then "No" else
  if l = r then
    if n = l + 1 || n >= 2 * l then "Yes" else "No"
  else
  (* l+1 = r *)
  let lc = Array.fold_left (fun s x -> s + a.(n-1) - x) 0 a in
  let rc = n - lc in
  if lc <= l && rc >= 2 * (r-lc) then "Yes" else "No"

Measured memory_bytes: 5248
while ((n,x = gets.split(" ").map(&:to_i)).inject(:+) != 0) do
  max = 3*(n-1)
  if !((6..max).include?(x))
    puts 0
    next
  end
  count = 0
  catch(:stop) do
    n.downto(1) do |n1|
      (n1-1).downto(1) do |n2|
        n3 = x - n1 - n2
        count += 1 if (n3 < n2) && (n3 > 0)
        throw :stop if (n3 > n1)
        break if (n3 > n2)
      end
    end
  end
  puts count
end

Measured memory_bytes: 8604
#include <stdio.h>

int main(void)
{
	int a,b,c,d[10]={0,0,0,0,0,0,0,0,0,0};
	for(a=0;a<10;a++)
		scanf("%d",&d[a]);
	for(a=0;a<10;a++)
		for(b=0;b<10;b++){
			if(d[a]>d[b]){
				c=d[b];
				d[b]=d[a];
				d[a]=c;
			}
		}
	for(a=0;a<3;a++)
		printf("%d\n",d[a]);
	return 0;
}


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

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "
#define cout(n) cout<<fixed<<setprecision(n)
int main(){
  ll N;
  cin>>N;
  N--;
  VEC2(v,N,3);
  FOR(i,0,N){
    cin>>v[i][0]>>v[i][1]>>v[i][2];
  }

  ll res=0;
  FOR(i,0,N){
    res=0;
    FOR(j,i,N){
      if(res<=v[j][1]) res=v[j][1];
      else if(res%v[j][2]==0) ;
      else res=(v[j][2]-res%v[j][2]) + res;
      res+=v[j][0];
    }
    cout<<res<<endl;
  }
  cout<<0<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const double pi=acos(-1);
const double eps=1e-10;
const vi emp;

int sum;

int main(){
	while(1){
		cin>>sum;
		if(!sum) break;
		int a;
		for(int i=0;i<9;i++){
			cin>>a;
			sum-=a;
		}
		cout<<sum<<endl;
	}
}

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

N = int(input())
W = [int(i) for i in input().split()]

sub_S = []

for n in range(N):
    S1 = sum(W[:n])
    S2 = sum(W[n:])
    sub_S.append(abs(S1 - S2))

print(min(sub_S))


Measured memory_bytes: 3064
import math 
a, b ,c = map(int, input().split())
k = int(input())

num_a = 0
for i in range(8):
    if a >= b:
        num_a += 1
        b *= 2
    else:
        break

num_b = 0
for i in range(8):
    if b >= c:
        num_b += 1
        c *= 2
    else:
        break
if num_a + num_b <= k:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9188
import bisect

n = int(input())
a = list(map(int,input().split()))
a.sort()
amax = a[-1]

if amax//2 in set(a):
  print(amax,amax//2)
else:
  ind = bisect.bisect_left(a,amax//2)
  MIN = min(abs(a[ind]-(amax//2)),abs(a[ind-1]-(amax//2)))
  if amax == 100 and a[ind] == 100:
    print(100,0)
    exit()
  
  if MIN == abs(a[ind]-(amax//2)):
    print(amax,a[ind])
  else:
    print(amax,a[ind-1])

Measured memory_bytes: 21880
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>
#include<functional>
#include<numeric>
#include <tuple>

using namespace std;
using ll = long long;
using ld = long double;
#define int long long
#define all(a) (a).begin(),(a).end()
#define EPS (1e-7)
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define H pair<int, int>
#define P pair<int, pair<int, int>>
#define Q(i,j,k) mkp(i,mkp(j,k))
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define reo(i,n) for(int (i) = 1 ; (i) <= (n) ; (i)++)
#define rng(i,s,n) for(int (i) = (s) ; (i) < (n) ; (i)++)
#define req(n,i) for(int (i) = (n) - 1 ; (i) >= 0 ; (i)--)
#define mkp make_pair
#define mem0(x) memset(x,0,sizeof(x))
#define vec vector
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
#define ssp(i,n) (i==n-1?"\n":" ")
#define ctoi(c) (int)(c-'a')
#define itoc(c) (char)(c+'a')
#define itn int
#define pri_que priority_queue
#define pp(x,y) pb(H{x,y})
#define ppp(x,y,z) pb(Q(x,y,z))
#define cyes cout<<"Yes\n"
#define cno cout<<"No\n"
const int mod = 1e9 + 7;
const int Mod = 998244353;
const ll inf = 3 * 1e18;
const int Inf = 15 * 1e8;
const vec<int>dx{ 0,0,-1,1 }, dy{ 1,-1,0,0 };
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
ll read() { ll u, k = scanf("%lld", &u); return u; }
string reads() { string s; cin >> s; return s; }
ll gcd(ll i, ll j) { return j ? gcd(j, i % j) : i; }
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
ll bitcount(ll x) {
	int sum = 0; for (int i = 0; i < 60; i++)if ((1ll << i) & x) sum++;
	return sum;
}
const int fn_ = 600000;
ll fact_[fn_], comp_[fn_];
ll comb(ll x, ll y, ll Mod = mod) {
	if (!fact_[0]) {
		fact_[0] = 1; comp_[0] = 1;
		for (int i = 1; i < fn_; i++) {
			fact_[i] = fact_[i - 1] * i % Mod;
			comp_[i] = mod_pow(fact_[i], Mod - 2, Mod);
		}
	}
	if (x < y) return 0;
	return fact_[x] * comp_[x - y] % Mod * comp_[y] % Mod;
}
//---------------------------------------------------------------
int h, n;
vec<H>a(2000);
int dp[20000];
signed main() {
	cin >> h >> n;
	rep(i, n) {
		int u, v;
		cin >> u >> v;
		a[i] = H{ u,v };
		//valie, cost
	}
	rep(i, 20000) dp[i] = inf;
	dp[0] = 0;
	rep(i, n) {
		for (int j = 0; j <= h; j++) {
			dp[min(h, j + a[i].fs)] = min(dp[min(h, j + a[i].fs)], dp[j] + a[i].sc);
		}
	}
	cout << dp[h] << endl;
}

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

int main() {
  vector<int> v{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin >> k;
  cout << v[k - 1] << endl;
}


Measured memory_bytes: 256
#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 each(it,v) for(auto &it : v)
#define all(v) (v).begin(),(v).end()
#define mod 1e9+7

using namespace std;
using vi = vector<int>;
using vl = vector<long>;
using P = pair<int,int>;

main()
{
        int n; cin>>n;
        vector<P> v;
        rep(i,n)
        {
                int a; cin>>a;
                v.push_back(make_pair(a,i+1));
        }
        sort(all(v));
        each(it,v)cout<<it.second<<endl;
}

Measured memory_bytes: 1780
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

#define lpsbd(i, s, b, d) for(size_t i = s; i < b; i+=d)
#define lpsb(i, s, b) for(size_t i = s; i < b; i++)
#define lpn(i, n) for(size_t i = 0; i < n; i++)
#define fa(i, x) for(auto &i: x)
#define vcd(t, n, d) vector<t>(n, d)
#define vc(t, n) vector<t>(n)

using namespace std;
using ull = unsigned long long;

const ull MOD = 1000000007;

int main(void)
{
    int r;
    cin >> r;
    cout << 3*r*r << endl;
    return 0;
}

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

using namespace std;

int main() {
    
    int N, max=0, count=0;
    cin >> N;

    vector<int> H(N);
    for (int i = 0; i < N; i++) {
        cin >> H[i];
    }

    for (int i = 0; i < N; i++) {
        if (max <= H[i]) {
            max = H[i];
            count++;
        }
    }

    cout << count;

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int h = Integer.parseInt(sa[0]);
		int w = Integer.parseInt(sa[1]);
		char[][] a = new char[h][w];
		for (int i = 0; i < h; i++) {
			a[i] = br.readLine().toCharArray();
		}
		br.close();

		int c1 = 0;
		int c2 = 0;
		int c4 = (h / 2) * (w / 2);
		if (h % 2 == 1) {
			if (w % 2 == 1) {
				c1 = 1;
				c2 = (h / 2) + (w / 2);
			} else {
				c2 = w / 2;
			}
		} else {
			if (w % 2 == 1) {
				c2 = h / 2;
			}
		}

		int[] cnt = new int[26];
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cnt[a[i][j] - 'a']++;
			}
		}

		int x = 0;
		while (x < 26) {
			if (cnt[x] >= 4 && c4 > 0) {
				cnt[x] -= 4;
				c4--;
			} else if (cnt[x] >= 2 && c2 > 0) {
				cnt[x] -= 2;
				c2--;
			} else if (cnt[x] >= 1 && c1 > 0) {
				cnt[x]--;
				c1--;
			} else {
				x++;
			}
		}

		for (int i = 0; i < 26; i++) {
			if (cnt[i] != 0) {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}
}


Measured memory_bytes: 22356
#include<bits/stdc++.h>
            #include<ext/pb_ds/assoc_container.hpp>
            #include<ext/pb_ds/tree_policy.hpp>
            using namespace __gnu_pbds;
            using namespace std;
            # define ll long long
            # define int long long  //comment it out when MLE
           // # define endl "\n"
            template <typename T>
            using ordered_set = tree<T, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;

            #define gok ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
            //# define m 163577857
            # define mo 1000000007
            # define pi acos(-1)
            # define fi first
            # define se second
            #define REP(i,n) for (int i = 1; i <= n; i++)
            const ll mod =  1e9+7;
            //const int K = 2;
            //typedef vector<vector<int> > matrix;
/*
          int add(int a, int b,int mod) {
                a%=mod;
                b%=mod;
                a += b;
                if (a >= mod) a -= mod;
                if(a<0)
                {
                    a += mod;
                    a %= mod;
                }
                return a;
            }

            int mul(ll a, int b,int mod) {
                a%=mod;
                b%=mod;
                a *= b;
                a += mod;
                return a % mod;
            }
            int po(int a,int b,int mod)
            {
                if(b==0)
                    return 1;
                if(b%2==0)
                    return po(mul(a,a,mod),b/2,mod);
                return mul(a,po(mul(a,a,mod),(b-1)/2,mod),mod);
            }


            ll fact[200003];
            ll inv[200003];

            void fact0()
            {
                int i,j;
                fact[0]=1;
                for(i=1;i<=200000;i++)
                {
                    fact[i]=i*fact[i-1]%mod;
                }
                inv[0]=1;
                inv[1]=1;
                ll p=mod;
                for (i=2; i<=200000; i++)
                    inv[i] = (p - (p/i) * inv[p%i] % p) % p;

                for(i=2;i<=200000;i++)
                {
                    inv[i]*=inv[i-1];
                    inv[i]%=mod;
                }
            }
            int help(int a,int b)
            {
               // cout<<a<<" "<<b<<endl;
                int an = fact[a];
                //cout<<an<<endl;
                an *= inv[b];
                an %= mod;
                an *= inv[a-b];
                an %= mod;
                return an;
            }
/*
          void random()
            {
              srand(time(0));
            for (int i = 0; i < n; i ++)
                perm[i] = i + 1;
            random_shuffle(perm, perm + n);
            }
int ncr(int a,int b)
{
    int tt = fact[a];
    tt %= mod;
    tt *= inv[a-b];
    tt %= mod;
    tt *= inv[b];
    tt %= mod;
    return tt;
}
*/

signed main() {
	gok

	int l,r,d;
	cin>>l>>r>>d;
	int st = (l-1)/d,en=r/d;
	cout<<en-st;





















  return 0;
}


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

#define F first 
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 1010, M = 1 << 12;

int n, m;
int a[N], b[N], c[M];
int f[N][M];

int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i ++ )
	{
		scanf("%d%d", &a[i], &b[i]);
		for (int j = 0; j < b[i]; j ++ )
		{
			int t;
			scanf("%d", &t);
			c[i] += 1 << (t - 1);
		}
	}
	
	memset(f, 0x3f, sizeof f);
	f[0][0] = 0;
	
	for (int i = 1; i <= m; i ++ )
	{
		memcpy(f[i], f[i - 1], sizeof f[i]);
		for (int j = 0; j < 1 << n; j ++ )
		{
			int t = min(f[i - 1][j | c[i]], f[i - 1][j] + a[i]);
			f[i][j | c[i]] = min(f[i][j | c[i]], t);
		}
	}
	
	int res = f[m][(1 << n) - 1];
	if (res == 0x3f3f3f3f) puts("-1");
	else printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 19960
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int a, b, t; cin >> a >> b >> t;
  int res = 0;
  for (int i = a; i <= t; i += a) res += b;
  cout << res << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}


int main(){
    double n,m,d;cin >> n >> m >>d;
    CST(12);
    double ans=(n-d)*(m-1)*2/n/n;
    if(d)cout << ans <<endl;
    else cout << ans/2 <<endl;
}

Measured memory_bytes: 3764
import java.util.Scanner;

public class Main {
	static Scanner scan = new Scanner(System.in);
	
	public static void main(String[] args) {
		int a = scan.nextInt();
		int b = scan.nextInt();
		
		int n1 = a-b;
		int n2 = a+b;
		int n3 = a*b;
		
		int m = Math.max(n1, n2);
		m = Math.max(m, n3);
		
		System.out.println(m);
	}

}


Measured memory_bytes: 23764
/*
				C++
				encoding: UTF-8
				Modified: <07/Sep/2019 05:31:08 PM>

				✪ H4WK3yE乡
				Mohd. Farhan Tahir
				Indian Institute Of Information Technology (IIIT), Gwalior
*/

#include <bits/stdc++.h>
#ifdef LOCAL_PROJECT
#	include <prettypr.hpp>
#endif

using namespace std;

// clang-format off

#define         ll                     long long
#define         ve                     vector
#define         pb                     push_back
#define         endl                   "\n";
#define         ff                     first
#define         ss                     second
#define         pii                    pair<int, int>
#define         len(v)                 int(v.size())
#define         all(v)                 v.begin(), v.end()
#define         reset(a, b)            memset(a, b, sizeof(a));
#define         fr(i, s, n)            for (int i = s ; i < n ; ++i)
#define         dfr(i, s, n)           for (int i = s ; i > n ; --i)

void pr () {
    cout << "\n";
}

template < typename T, typename... ARGS > void pr (const T& t, ARGS... args) {
    cout << t << " ";
    pr (args...);
}

// clang-format on

signed main () {
	ios_base::sync_with_stdio (false), cin.tie (nullptr);
	int n;
	cin >> n;
	int ans = pow (n, 3);
	pr (ans);

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	string s;
	cin >> s;
	int forw=0,backw=((int)s.size())-1;
	while(s[forw]!='A'){
		forw++;
	}
	while(s[backw]!='Z'){
		backw--;
	}
	cout << backw-forw+1 << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define fo(int, i, a, b)        for (int i=a; i<(b); i++)
#define forev(int, i, b, a)     for (int i = (b)-1; i >= a; i--)
#define uns                     unsigned
#define lli                     long long int
#define ld                      long double
#define all(x)                  x.begin(), x.end()
#define sortall(x)              sort(all(x))
#define enl                     "\n"
#define dbg(x)                  cout << #x << ": " << x << enl;
// #define PI 3.1415926535897932384626
// const int MOD = 1000000007; const lli INF = 1e18; const int MX = 100001;

void solve() {
    int x; cin >> x;
    cout << (x ? 0 : 1) << enl;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    // int testcase; cin >> testcase; for (int i = 1; i <= testcase; ++i)
    solve();
    return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>
int main(void){
    int s,m,h;
    scanf("%d",&s);
    h=s/60/60;
    m=(s-h*60*60)/60;
    s=s-h*60*60-m*60;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
    
}



Measured memory_bytes: 2048
import sys
import os

def is_same(a, b):
    for i in range(len(a)):
        if a[i] != b[i]:
            return False
    return True

N, M = list(map(lambda x: int(x), sys.stdin.readline().strip().split(" ")))

A = []
B = []

for _ in range(N):
    A.append(sys.stdin.readline().strip())

for _ in range(M):
    B.append(sys.stdin.readline().strip())

it = N - M + 1

for i in range(it):
    for j in range(it):
        a = list(map(lambda x: x[j:j+M], A[i:i+M]))
        if is_same(a, B):
            print("Yes")
            sys.exit(0)
print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <math.h>
#include <stdio.h>
#define INF 1000000000
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long int ll;
using namespace std;

int main() {

	int h,a; cin >> h >> a;
	if (h % a != 0) { cout << h / a + 1 << endl; }
	else { cout << h / a << endl; }



	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <sstream>
#include <fstream>
#include <climits>
#include <map>
#include <numeric>
#include <functional>

typedef signed char        int8;
typedef short              int16;
typedef int                int32;
typedef long long          int64;
typedef unsigned char      uint8;
typedef unsigned short     uint16;
typedef unsigned int       uint32;
typedef unsigned long long uint64;

int main(void) {
  int n;
  std::cin >> n;
  int64 sum = 0;
  for (int64 i = 1; i <= n; i++) {
    if (i % 3 != 0 && i % 5 != 0) {
      sum += i;
    }
  }
  std::cout << sum << std::endl;
  return 0;
}


Measured memory_bytes: 3648
///mAAria...
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(),v.end()
#define allr(v) v.begin(),v.end()
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pii pair<int,int>
#define pi 3.1415926535897932384626433832
#define mod 1000000007
//#define mod 998244353
#define inf 1000000000
#define pr1(a) cout << a << endl
#define pr2(a,b)cout << a <<  " " <<b<< endl
#define pr3(a,b,c) cout << a <<" " << b << " " << c << endl

const long double PI = acos(-1);

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

int gcd(int a, int b){
    if(b==0)return a;
    return gcd(b,a%b);
}

bool p(int n){
    return ((n&(n-1))==0);

}
void solve(){
    
    int n,m,k;
    cin >> n>> m >>k;

    vector<int> a,b;

    for(int i = 0; i<n;i++){
        int x;
        cin >> x;
        if(a.size()){
            a.pb(a.back()+x);
        }
        else a.pb(x);
        // cout << a[i] << endl;
     }

    for(int i = 0; i<m;i++){
        int x;
        cin >> x;
        if(b.size()){
            b.pb(b.back()+x);
        }
        else b.pb(x);
        // cout << b[i] << endl;
    }
    // cout << *upper_bound(all(a), k) << endl;
    int ans = upper_bound(a.begin(), a.end(), k) - a.begin();
    ans+=(upper_bound(b.begin(), b.end(), k-a[n-1]) - b.begin());
    // cout << ans << endl;
    // cout << *upper_bound(all(b), k) << endl;
    int tmp = (upper_bound(b.begin(), b.end(), k) - b.begin());
    tmp+=upper_bound(a.begin(), a.end(), k-b[m-1]) - a.begin();
    ans = max(ans, tmp);
    // cout << tmp << endl;

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

        int tmp;
        if(k-a[i]<=0)break;
        tmp = i + 1 + (upper_bound(b.begin(), b.end(), k-a[i])-b.begin());

        ans = max(ans, tmp);
    }
    for(int i = 0; i<m;i++){

        int tmp;
        if(k-b[i]<=0)break;
        tmp = i + 1 + (upper_bound(a.begin(), a.end(), k-b[i])-a.begin());

        ans = max(ans, tmp);
    }

    cout <<ans << endl;
   
} 

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

    for(int i = 1;i<=t;i++){
        solve();
    }
    return 0;
} 

 


Measured memory_bytes: 7952
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
using namespace std;
typedef long long ll;
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int dp[3050][3050];
char a[maxn];
char b[maxn];
int n,m;
int c[maxn];
int pre[maxn];
int lis[maxn];
int main()
{
    scanf("%s",a);
    scanf("%s",b);
    n=strlen(a);
    m=strlen(b);
    for(int i=n-1;i>=0;i--)
    {
        for(int j=m-1;j>=0;j--)
        {
            if(a[i]==b[j])
            {
                dp[i][j]=dp[i+1][j+1]+1;
            }else
            {
                dp[i][j]=max(dp[i+1][j],dp[i][j+1]);
            }
        }
    }
//    cout<<dp[n-1][m-1]<<endl;
    int i=0;
    int j=0;
    while(i<n&&j<m)
    {
        if(a[i]==b[j])
        {
            putchar(a[i]);
            i++;
            j++;
        }else if(dp[i][j]==dp[i+1][j])
        {
            i++;
        }else
        {
            j++;
        }
    }
//    int i=n-1;
//    int j=m-1;
//    int cnt=dp[n-1][m-1];
//    char ans[cnt+50];
//    while(i>=0&&j>=0)
//    {
//        if(a[i]==b[j])
//        {
////            putchar(a[i]);
//            ans[cnt--]=a[i];
//            j--;
//            i--;
//
//        }else if(dp[i][j]==dp[i-1][j])
//        {
//            i--;
//
//        }else
//        {
//            j--;
//        }
//
//    }
//    cnt=dp[n-1][m-1];
//    repd(i,1,cnt)
//    {
//        putchar(ans[i]);
//    }
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}


Measured memory_bytes: 39424
#include<bits/stdc++.h>
#define mz 998244353
#define pq priority_queue
using namespace std;

struct Node
{
    int no,v;
}a[200005];
struct Nodes
{
    int l,r,mid,maxx;
}tre[800005];
vector <int> vec[200005];
int ans[200005];

bool cmp1(Node x1,Node x2)
{
    return x1.v<x2.v;
}
bool cmp2(Node x1,Node x2)
{
    return x1.no<x2.no;
}
void build(int x,int l,int r)
{
    tre[x].l=l;
    tre[x].r=r;
    tre[x].mid=(l+r)/2;
    if(l!=r)
    {
        build(x*2,tre[x].l,tre[x].mid);
        build(x*2+1,tre[x].mid+1,tre[x].r);
    }
}
int ask(int x,int l,int r)
{
    if(l>r)
        return 0;
    if(l==tre[x].l && r==tre[x].r)
        return tre[x].maxx;
    if(l<=tre[x].mid && r>tre[x].mid)
        return max(ask(x*2,l,tre[x].mid),ask(x*2+1,tre[x].mid+1,r));
    else
    {
        if(r<=tre[x].mid)
            return ask(x*2,l,r);
        else
            return ask(x*2+1,l,r);
    }
}
void add(int x,int p,int y)
{
    if(tre[x].l==tre[x].r)
        tre[x].maxx=y;
    else
    {
        if(p<=tre[x].mid)
            add(x*2,p,y);
        else
            add(x*2+1,p,y);
        tre[x].maxx=max(tre[x*2].maxx,tre[x*2+1].maxx);
    }
}
void dfs(int x,int fa)
{
    ans[x]=ask(1,1,a[x].v-1)+1;
    int temp=ask(1,a[x].v,a[x].v);
    if(ans[x]>temp)
        add(1,a[x].v,ans[x]);
    ans[x]=max(ans[fa],ans[x]);
    for(int i=0;i<vec[x].size();i++)
    {
        if(vec[x][i]!=fa)
            dfs(vec[x][i],x);
    }
    add(1,a[x].v,temp);
}

int main()
{
    int now=0,u,v,n,cnt=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        a[i].no=i;
        scanf("%d",&a[i].v);
    }
    sort(a+1,a+1+n,cmp1);
    for(int i=1;i<=n;i++)
    {
        if(a[i].v!=now)
        {
            now=a[i].v;
            cnt++;
        }
        a[i].v=cnt;
    }
    sort(a+1,a+1+n,cmp2);
    build(1,1,cnt);
    for(int i=1;i<n;i++)
    {
        scanf("%d%d",&u,&v);
        vec[u].push_back(v);
        vec[v].push_back(u);
    }
    dfs(1,0);
    for(int i=1;i<=n;i++)
        printf("%d\n",ans[i]);
    return 0;
}

Measured memory_bytes: 32916
#include <iostream>
#include <string>
#include <cmath>
#include <sstream>

using namespace std;

long long int keisan(string a, string b) {
	long long int aa, bb;
	stringstream ss;
	ss << a;
	ss >> aa;
	ss.clear();
	ss << b;
	ss >> bb;
	//cout << aa << ' ' << bb << ' ' << aa*bb << endl;
	return aa*bb;
}

string kaiseki(string a) {
	long long int count = 0;
	for (int i = 1; i < a.size(); i++) {
		count = max(count, keisan(a.substr(0, i), a.substr(i)));
	}
	//cout << count << endl;
	string b;
	stringstream ss;
	ss << count;
	ss >> b;
	return b;
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string a;
		cin >> a;
		int count = 0;
		while (a.size() != 1) {
			a = kaiseki(a);
			//cout << a << endl;
			count++;
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 1240
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#include <set>
#define PI 3.14159265359
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF=1e9+7;

int main(void) {
	int h, w;
	cin >> h >> w;
	vector<vector<char>> table(h, vector<char>(w));
	vector<vector<char>> ans;
	ans.emplace_back();
	REP(i, h)REP1(j, w)cin >> table[i][j];
	REP(i, h) {
		REP1(j, w) {
			if (table[i][j] == '#') {
				ans[i].push_back(table[i][j]);
			}
			else {
				bool can1, can2;can1 = can2 = false;
				for (int k = 0;k < h;k++) {
					if (table[k][j] == '#') {
						can1 = true;
						break;
					}
				}
				for (int k = 0;k < w;++k) {
					if (table[i][k] == '#') {
						can2 = true;
						break;
					}
				}
				if (can1 && can2)ans[i].push_back(table[i][j]);
			}
		}
		ans.emplace_back();
	}
	REP(i, ans.size()) {
		if (ans[i].size() == 0)continue;
		REP(j, ans[i].size()) {
			cout << ans[i][j];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use nalgebra::{min, max};
use std::mem::swap;

#[fastout]
fn main() {
    input! {
    n: usize,
    t: usize,
    mut ab: [(usize, usize); n]
    }
    ab.sort();
    let mut dp = vec![0; t + 1];
    for i in 0..n {
        let mut prev = vec![0; t + 1];
        swap(&mut dp, &mut prev);
        let (a, b) = ab[i];
        for j in 0..t {
            let k = min(j + a, t);
            if j < a {dp[j] = prev[j]}
            dp[k] = max(prev[k], prev[j] + b);
        }
    }
    println!("{}", dp[t]);
}

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

typedef long long int ll;

ll digitSum(int n){
    ll sum=0;
    while(n){
        sum+=(n%10);
        n/=10;
    }
    return sum;
}

int main(){
    int n;
    scanf("%d",&n);
    if(n%digitSum(n)==0) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
const int ddx[4] = {1,1,-1, -1};
const int ddy[4] = {1,-1,-1,1};
//////////////////////////////////

vector<pair<char, int>> func(string s) {
    s += " ";
    int n = s.size();
    vector<pair<char, int>> r;
    char c = s[0]; int cnt = 1;
    for(int i=1; i<n; i++) {
        if(c != s[i]) {
            r.push_back({c, cnt});
            c = s[i];
            cnt = 1;
        }else{
            cnt++;
        }
    }

    return r;
}

string funcr(vector<pair<char, int>> r) {
    string s = "";
    for(int i=0; i<r.size(); i++) {
        s += string(r[i].second, r[i].first);
    }
    return s;
}

int count(string s) {
    int cnt = 0;
    for(int i=0; i<s.size()-1; i++) {
        if(s[i] == s[i+1]) cnt++;
    }
    // cerr << s << " " << cnt << endl;
    return cnt;
}

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

    auto r = func(s);
    for(int i=1; i<r.size(); i+=2) {
        if(k == 0) break;
        if(r[i].first == 'R') r[i].first = 'L';
        else r[i].first = 'R';
        k--;
    }

    string t = funcr(r);
    cout << count(t) << endl;

    return 0;
}

// EOF


Measured memory_bytes: 2164
#include<bits/stdc++.h>
using namespace std;
int main(){int n,i,c=0;
cin>>n;
if(n%10==7)c++;
n/=10;
if(n%10==7)c++;
n/=10;
if(n==7)c++;
if(c){cout<<"Yes";}
else{cout<<"No";}
    return 0;}

Measured memory_bytes: 3636
#include "bits/stdc++.h"

#define rep(i,n) for(int i = 0;i<n;i++)
#define vv(Type, n,m,d)vector<vector<Type>> vv(n, vector<Type>(m, d));

using namespace std;
using ll = long long;

const ll mod = 1e9 + 7;




int main(void) {

	ios::sync_with_stdio(false);
	cin.tie(0);

	string s, t, u;
	int a, b;
	cin >> s >> t >> a >> b >> u;
	if (s == u) a--;
	else b--;

	cout << a << " " << b << endl;





	return 0;
}


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

int main() {
    char x1, x2, ball = 'A';
    while ((x1 = getchar()) != EOF) {
        getchar();
        x2 = getchar();
        getchar();
        if (ball == x1) {
            ball = x2;
        } else if (ball == x2) {
            ball = x1;
        }
    }
    cout << ball << endl;
}

Measured memory_bytes: 0
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]

N, K = ri_()
A = ri_()
for i in range(K, N):
    if A[i] > A[i - K]:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 31568
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

int main() {
#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	ll n; cin >> n;

	vvl path(n);
	REP(i, n - 1) {
		ll a, b; cin >> a >> b;
		a--; b--;
		path[a].push_back(b);
		path[b].push_back(a);
	}

	ll k; cin >> k;
	vl p(n, -1);

	ll start = -1;
	vl low(n, -1), high(n, -1);
	REP(i, k) {
		ll v, pp; cin >> v >> pp;
		v--;
		start = v;
		low[v] = high[v] = p[v] = pp;
	}
	
	function<bool(ll, ll)> dfs1 = [&](ll cur, ll prev) {
		if (p[cur] == -1) {
			low[cur] = low[prev] - 1;
			high[cur] = high[prev] + 1;
		}
		for (ll next : path[cur]) if (next != prev) {
			if (!dfs1(next, cur)) return false;
			// nextの要求範囲を満たすか判定＆更新
			if (low[next]  - 1 > high[cur]) return false;
			if (high[next] + 1 < low[cur])  return false;
			if ((low[next] + low[cur]) % 2 == 0) return false;
			low[cur]  = max(low[cur],  low[next]  - 1);
			high[cur] = min(high[cur], high[next] + 1);
		}
		return true;
	};

	if (!dfs1(start, -1)) {
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
		function<void(ll, ll)> dfs2 = [&](ll cur, ll prev) {
			if (p[cur] == -1) {
				p[cur] = (p[prev] + 1 <= high[cur] ? p[prev] + 1 : p[prev] - 1);
			}
			for (ll next : path[cur]) if (next != prev) dfs2(next, cur);
		};
		dfs2(start, -1);
		REP(i, n) cout << p[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 18176
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;

signed main(){
    int A,B;cin>>A>>B;
    if(A==1)A=14;if(B==1)B=14;
    cout<<(A>B?"Alice":A<B?"Bob":"Draw")<<endl;
}

Measured memory_bytes: 256
/*
Á·Ï°Ìâ£ºProperty Distribution_AOJ 0118

²»Ö»ÓÐÈý¸ö×Ö·û£¬Òª×÷Îª²ÎÊý´«Èëdfs 
*/
#include <cstdio>

char maze[105][105];
int W, H;
int sx, sy;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int count;

void dfs(int x, int y, char c)
{
	for(int i=0; i<4; i++)
	{
		int nx=x+dx[i];
		int ny=y+dy[i];
		if(nx>=0&&nx<H&&ny>=0&&ny<W&&maze[nx][ny]==c)
		{
			maze[nx][ny]='.';
			dfs(nx,ny,c);
		}
	}
	return ;
}


int main()
{
	while(scanf("%d%d", &H, &W)!=EOF)
	{
		count=0;
		if(W==0&&H==0)
			break;
		getchar();
		for(int i=0; i<H; i++)
		{
			scanf("%s", maze[i]);
		}
		for(int i=0; i<H; i++)
			for(int j=0; j<W; j++)
				if(maze[i][j]!='.')
				{
					sx=i;
					sy=j;
					count++;
					dfs(sx, sy, maze[i][j]);
				}
		
		
		
		printf("%d\n", count);
		
	}
	
	return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define LL long long

using namespace std;

const int maxn = 100005;

int main(){
    int a, b;
    cin>>a>>b;
    cout<<a+b/2<<endl;
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  bool can = false;
  for (int bit=0; bit<(1<<S.size()-1); bit++) {//全列挙
    int sum = S.at(0) - '0';
    for (int i=0; i<S.size()-1; i++) {
        if (bit & (1 << i)) {
            sum += S.at(i+1) - '0';
        } else {
            sum -= S.at(i+1) - '0';
        }
    }
    if (sum == 7) {
        can = true;
        cout << S.at(0);
        if (bit & (1<<0)) cout << "+";
        else cout << "-";
        cout << S.at(1);
        if (bit & (1<<1)) cout << "+";
        else cout << "-";
        cout << S.at(2);
        if (bit & (1<<2)) cout << "+";
        else cout << "-";
        cout << S.at(3) << "=7" << endl;
    }
    if (can) break;
  }
  return 0;
}

Measured memory_bytes: 256
from collections import deque
d=deque()
S=list(input())
Q=int(input())
query=[list(map(str,input().split())) for _ in range(Q)]
flag=0  #反転なし
#print(query)
s=S
s2=""
d.extend(S)
#print(d)
for i in range(Q):
    #print(i,len(d))
    if (len(query[i])==1):
        if len(d)>1:
            flag=(flag+1)%2 #反転フラグをひっくり返す
    else:
        if flag==0:
            if query[i][1]=="1":
                d.appendleft(query[i][2])
            else:
                d.append(query[i][2])
        else:
            if query[i][1]=="2":
                d.appendleft(query[i][2])
            else:
                d.append(query[i][2])
    #print(d)
if flag==0:
    print("".join(list(d)))
else:
    d.reverse()
    print("".join(list(d)))


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

using namespace std;

typedef long long ll;

const int maxn = 100100;

int n,m,a[maxn],b[maxn],p[maxn],id[maxn],vis[maxn],root;
ll f[maxn],s[maxn];
vector<int> g[maxn];

int cmp(int i,int j) {
    return a[i] < a[j];
}

int get(int x) {
    return ((x==p[x]) ? x : p[x] = get(p[x]));
}

int main() {
   // freopen("in.txt","r",stdin);
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>m;
    int ma =0;
    for (int i=1;i<=n;i++) {
        cin>>a[i]>>b[i];
        a[i] = max(a[i]-b[i],0); // all of node always need atleast ai-bi
        if (a[i] > ma) {
            ma = a[i];
            root = i;
        }
        id[i] = i;
        p[i] = i;
        s[i] = b[i]; // amount of money need to donate
        f[i] = a[i]; // amount of money need to add more to donate all
    }
    for (int i=1;i<=m;i++) {
        int x,y;
        cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    sort(id+1,id+n+1,cmp);
    for (int i=1;i<=n;i++) {
        int u = id[i];
        vis[u] = 1;
        for (auto v : g[u]) if (vis[v]) { // alway keep order to DP
            int x = get(u), y= get(v);
           // cout<<u<<" "<<v<<" "<<x<<" "<<y<<endl;
            if (x==y) continue;
            p[y] = x; s[x] += s[y];
            ll need = a[u] - s[y];
            f[x] = min(f[x],max(need,f[y]));
        }
    }
    cout<<f[root] + s[root]<<endl;
}


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

int n;
int A;
const int maxn = 55;
int x[maxn];
long long dp[maxn][maxn * maxn * 2];
const int offset = maxn * maxn;

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);    
    cin >> n >> A;
    for(int i = 1;i <= n;i++){
        cin >> x[i];
        x[i] -= A;
    }
    memset(dp, 0, sizeof(dp));
    dp[0][offset] = 1;
    for(int i = 1;i <= n;i++){
        for(int j = 0;j < maxn * maxn * 2;j++){
            if(dp[i - 1][j] == 0)
                continue;
            int to = j + x[i];
            dp[i][j] += dp[i - 1][j];
            if(to >= 0 and to < maxn * maxn * 2){
                dp[i][to] += dp[i - 1][j];
            }
        }
    }
    cout << dp[n][offset] - 1 << endl;
    return 0;
}


Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
    int no_of_input,capacity;
    int input1,input2,input3;
    int curr = 1;
    vector<pair<int,int> > vect1;//size,value
    cin >> no_of_input >> capacity;
    vector<int> dp(capacity+3100,0);
    for(int i=0;i<no_of_input;i++){
      cin >> input1 >> input2;
      vect1.push_back({input1,input2});
    }
    sort(vect1.begin(),vect1.end());
    for(int i=0;i<vect1.size();i++){
        vector<int> temp(capacity+3100);
        temp = dp;
        for(int j=1;j<temp.size();j++){
          temp[j] = max(temp[j],temp[j-1]);
        }
        for(int j=0;j<=capacity-1;j++){
            temp[j+vect1[i].first] = max(temp[j+vect1[i].first],dp[j]+vect1[i].second);
        }
        dp = temp;
    }
    int ans = 0;
    for(auto k:dp){
        ans = max(ans,k);
    }
    cout << ans;

}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {

  long long N,A,B;
  cin >> N >> A >> B;

  if((B-A)%2 != 0) {
    long long f = A + (B-A-1)/2;
    long long s = N-B+1+(B-A-1)/2;
    // cout << f << " " << s << endl;
    cout << min(f,s) << endl;
  }else cout << (B-A)/2 << endl;

  
}


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

using namespace std;

int main() {
    long long n, a, b;
    cin >> n >> a >> b;

    long long q = n / (a + b);
    long long r = n % (a + b);
    long long ans;
    if (r < a) {
        ans = a * q + r;
    }
    else {
        ans = a * q + a;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256