akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    char c;
    for(int i=0;i<a;i++)
    {
        cin>>c;
        if(c=='0'||c=='1'||c=='2'||c=='3'||c=='4'||c=='5'||c=='6'||c=='7'||c=='8'||c=='9'){}
        else
        {
            cout<<"No"<<endl;
            return 0;
        }
            
    }
    cin>>c;
    if(c=='-'){}
    else
    {
        cout<<"No"<<endl;
        return 0;
    }
    for(int i=0;i<b;i++)
    {
        cin>>c;
        if(c=='0'||c=='1'||c=='2'||c=='3'||c=='4'||c=='5'||c=='6'||c=='7'||c=='8'||c=='9'){}
        else
        {
            cout<<"No"<<endl;
            return 0;
        }
        
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////

int main(){
    string s;cin>>s;
    if(s[0]==s[2]){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    
    
    return 0;
}


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

public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String line = br.readLine();

        while(line != null){            
            String[] input = line.split(" ");
            int height = Integer.valueOf(input[0]);
            int width = Integer.valueOf(input[1]);
            
            if(height == 0 && width == 0) break;
            
            for(int i = 0; i < height; i++){
                for(int j = 0; j < width; j++){
                    System.out.print("#");
                }
                System.out.println();
            }
            
            System.out.println();
            line = br.readLine();
        }
    }
}

Measured memory_bytes: 33096
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstring>
#include<string>
using namespace std;
char str[100005],tp[100005];
int n,k,r,s,p;
long long ans=0;
char Oppo(char x){
	if(x=='r')return 'p';
	if(x=='p')return 's';
	return 'r';
}
char Change(char x){
	if(x=='r')return 's';
	if(x=='p')return 'r';
	return 'p';
}
int Val(char x){
	if(x=='r')return r;
	if(x=='p')return p;
	return s;
}
int main(){
	cin>>n>>k>>r>>s>>p>>str;
	for(int i=0;i<n;i++){
		if(i<k){
			tp[i]=Oppo(str[i]);
			ans+=Val(tp[i]);
		}
		else if(tp[i-k]==Oppo(str[i])){
			if(i+k>=n)continue;
			tp[i]=(str[i]==Oppo(str[i+k])?Change(str[i]):str[i]);
		}
		else tp[i]=Oppo(str[i]),ans+=Val(tp[i]);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int A = Integer.parseInt(scn.next());
		int B = Integer.parseInt(scn.next());
		int C = Integer.parseInt(scn.next());
		int D = Integer.parseInt(scn.next());

		int a = A * B;
		int b = C * D;
		if (a > b) {
			System.out.println(a);
		} else {
			System.out.println(b);
		}

	}
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
  int N; cin >> N;
  ll ans=0;
  for(int i=1;i<=N;i++){
    if(i%3!=0 && i%5!=0){
      ans+=i;
    }
  }
  cout << ans << endl;
  return 0;
}

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

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define F first
#define S second
#define MSET(m,v) memset((m),(v),sizeof(m))
#define UB(c,v) (upper_bound((c).begin(),(c).end(),(v)))
#define LB(c,v) (lower_bound((c).begin(),(c).end(),(v)))
#define INREP int TC;cin>>TC;while(TC--)
#define CPPIO ios::sync_with_stdio(false);cin.tie(NULL);
#define PC(x) fixed<<setprecision(x)
#define FBO find_by_order
#define OOK order_of_key
#define PI acos(-1.0)
#define INF 0x7ffffff0
#define INFL 0x7ffffffffffffff0LL
#define si(x) scanInt(&x)
#define sll(x) x = scanLong()
#define nl putc_unlocked('\n', stdout)
#define gc getchar_unlocked
#define RI readint()
#define MOD 1000000007


typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;


void printNcR(int n, int r) 
{ 
  
        long long p = 1, k = 1; 
  
    if (n - r < r) 
        r = n - r; 
  
    if (r != 0) { 
        while (r) { 
            p *= n; 
            k *= r; 
  
            long long m = __gcd(p, k); 
  
            p /= m; 
            k /= m; 
  
            n--; 
            r--; 
        } 
  
    } 
  
    else
        p = 1; 
    cout << p << endl; 
} 


int main(){
 int N;
 cin>>N;
 ll A[N];
 ll dp[N];
 for(int i=0;i<N;i++)
  cin>>A[i];
 dp[N-1] = 0;
 dp[N-2] = llabs(A[N-1] - A[N-2]);
  
 for(int i=N-3;i>=0;i--){
  dp[i] = min(llabs(A[i+1]-A[i]) + dp[i+1],llabs(A[i+2]-A[i])+dp[i+2]);
 } 

 cout<<dp[0]<<"\n";
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n, m;
  cin >> n >> m;
  vi a(m);
  vector<vi> c(m);
  rep(i, m) {
    int b;
    cin >> a[i] >> b;
    rep(j, b) {
      int cc;
      cin >> cc;
      cc--;
      c[i].push_back(cc);
    }
  }
  int dp[1 << n];
  rep(j, 1 << n) dp[j] = 1e9;
  dp[0] = 0;
  rep(i, m) rep(j, 1 << n) {
    int nj = j;
    for(int v : c[i]) nj |= (1 << v);
    dp[nj] = min(dp[nj], dp[j] + a[i]);
  }
  int ans = dp[(1 << n) - 1];
  if(ans >= 1e9) ans = -1;
  cout << ans << endl;
}

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

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

    vector<int> field(1000005,0);

    sort(A.begin(),A.end());
    int ans=0;
    for(int i=0; i<N; ++i){
        if(field[A[i]]==0){
            if(A[i] != A[i+1]) ++ans;
            for(int j=1; A[i]*j<=1000000; ++j){
                field[A[i]*j] = 1;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 7988
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>
#include <cassert>

using namespace std;

#define int long long
#define double long double

typedef pair<int, int> P;
typedef tuple<int, int, int> T;

template<class T> string tostr(T x) { stringstream o; o << x; return o.str(); }
template<class T> T sqr(T x) { return x*x; }
template<class T> T mypow(T x, int n) { T r = 1; while (n > 0) { if (n & 1)r = r*x; x = x*x; n >>= 1; }return r; }

int toint(string s) { int v; stringstream i(s); i >> v; return v; }
bool check(int x, int y, int w, int h) { return x >= 0 && y >= 0 && w > x && h > y; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

#define REP(i,a,b)	for(int (i) = (a);i < (b);(i)++)
#define rep(i,n)	REP(i,0,n)
#define PER(i,a,b)	for(int (i) = (a-1);i >= (b);(i)--)
#define per(i,n)	PER(i,n,0)
#define each(i,n)	for(auto &i : n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define dump(val) 	cerr << #val " = " << val << endl;
#define dum(val)	cerr << #val " = " << val;
#define FILL(a,v)	fill(a,a+sizeof(a)/sizeof(*a),v)

const int dx[8] = { +1,+0,-1,+0,+1,+1,-1,-1 };
const int dy[8] = { +0,-1,+0,+1,-1,+1,-1,+1 };
const int mod = 1e9 + 7;
const int INF = 1e17 + 9;

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

	int n;
	cin >> n;

	map<int, P> mp;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (mp.count(-a) == 0) {
			mp[-a].first = 0;
			mp[-a].second = INF;
		}
		mp[-a].first++;
		mp[-a].second = min(mp[-a].second, i + 1);
	}
	
	vector<T> v;
	each(i, mp) {
		v.push_back(T(-i.first, i.second.first, i.second.second));
	}

	map<int, int> ans;

	int res = 0;
	int tar = INF;

	v.push_back(T(0, 0, INF));

	rep(i, v.size() - 1) {
		int n0 = get<0>(v[i]);
		int n1 = get<0>(v[i + 1]);
		int c = get<1>(v[i]);
		int t = get<2>(v[i]);
		tar = min(t, tar);
		res += c;
		ans[tar] += (n0 - n1) * res;
	}

	REP(i, 1, n + 1) {
		cout << ans[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 16368
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<signed(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 200000000000;
struct edge {int to,cost;};
typedef std::pair<int,int> P;

    double A,B,C,D,E,F;
    std::set<double> W,S;
    double N=0;
    ll X,Y;
    //N= 水 M=もの

int main(){
    ios_base::sync_with_stdio(false);
    cin>>A>>B>>C>>D>>E>>F;
    // A<B
    for(int i=0;;i++){
        if(F<i*A*100)break;
        for(int j=0;;j++){
            if(i==0&&j==0)continue;
            if(F>=(A*i+B*j)*100)W.insert(A*i+B*j);
            else break;
        }
    }
    for(int i=0;;i++){
        if(F<i*C)break;
        for(int j=0;;j++){
            if(F>=C*i+D*j)S.insert(C*i+D*j);
            else break;
        }
    }
    //sort(ALL(W));sort(ALL(S));
    //for(auto x:S)DEB(x)
    for(auto x:W){
        for(auto y:S){
            if(x*100+y>F)break;

            if(x*E>=y){
                if(N<100*y/(x*100+y)){

                    X=x*100+y;
                    Y=y;
                    N=100*y/(x*100+y);

                }
            }else break;
        }
    }

    if(X!=0&&Y!=0)cout<<X<<" "<<Y;
    else cout<<A*100<<" "<<0;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#define rep(v,n) for(int v=0;v<n;v++)
using namespace std;
int main()
{
    int H, W;
    cin >> H >> W;
    vector<string> map(H);
    vector<bool> h(H), w(W);
    rep(i, H) cin >> map[i];
    rep(y, H) {
        bool wall = false;
        rep(x, W) 
            if (map[y][x] == '#')
                wall = true;
        h[y] = wall;
    }
    rep(x, W) {
        bool wall = false;
        rep(y, H)
            if (map[y][x] == '#')
                wall = true;
        w[x] = wall;
    }
    rep(y, H) {
        if (!h[y]) continue;
        rep(x, W) if (w[x]) cout << map[y][x];
        cout << endl;
    }
    return 0;
}


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

using namespace std;

template< typename Monoid >
struct DisjointSparseTable {
  using F = function< Monoid(Monoid, Monoid) >;
  const F &f;
  vector< vector< Monoid > > st;

  DisjointSparseTable(const vector< Monoid > &v, const F &f) : f(f) {

    int b = 0;
    while((1 << b) <= v.size()) ++b;
    st.resize(b, vector< Monoid >(v.size(), Monoid()));
    for(int i = 0; i < v.size(); i++) st[0][i] = v[i];
    for(int i = 1; i < b; i++) {
      int shift = 1 << i;
      for(int j = 0; j < v.size(); j += shift << 1) {
        int t = min(j + shift, (int) v.size());
        st[i][t - 1] = v[t - 1];
        for(int k = t - 2; k >= j; k--) st[i][k] = f(v[k], st[i][k + 1]);
        if(v.size() <= t) break;
        st[i][t] = v[t];
        int r = min(t + shift, (int) v.size());
        for(int k = t + 1; k < r; k++) st[i][k] = f(st[i][k - 1], v[k]);
      }
    }
  }

  Monoid query(int l, int r) {
    if(l >= --r) return st[0][l];
    int p = 31 - __builtin_clz(l ^ r);
    return f(st[p][l], st[p][r]);
  }
};

using Pi = pair< int, int >;

vector< int > g[100000];
vector< Pi > depth;
int rev[100000];

void dfs(int idx, int dep) {
  rev[idx] = (int) depth.size();
  depth.emplace_back(dep, idx);
  for(auto &to : g[idx]) {
    dfs(to, dep + 1);
    depth.emplace_back(dep, idx);
  }
}

int main() {
  int N, Q;
  scanf("%d", &N);
  for(int i = 0; i < N; i++) {
    int k;
    scanf("%d", &k);
    for(int j = 0; j < k; j++) {
      int c;
      scanf("%d", &c);
      g[i].push_back(c);
    }
  }
  dfs(0, -1);
  auto f = [](const Pi &a, const Pi &b) { return min(a, b); };
  DisjointSparseTable< Pi > beet(depth, f);
  scanf("%d", &Q);
  for(int i = 0; i < Q; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    auto p = minmax(rev[a], rev[b]);
    printf("%d\n", beet.query(p.first, p.second).second);
  }
}



Measured memory_bytes: 44652
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  int a,b;
  cin>>a>>b;
  cout<<max(a+b,max(a-b,a*b))<<endl;
}







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

int main() {
  int a, b, c, x, y;
  int xnum, ynum, price, pmin = INT_MAX;
  cin >> a >> b >> c >> x >> y;
  pmin = min(x, y);
  if (c * 2 < a + b)
    price = (c * 2) * pmin;
  else
    price = a * pmin + b * pmin;
  x -= pmin;
  y -= pmin;
  if (x != 0) {
    if (a * x < (c * 2) * x) {
      price += a * x;
    } else {
      price += (c * 2) * x;
    }
  } else {
    if (b * y < (c * 2) * y) {
      price += b * y;
    } else {
      price += (c * 2) * y;
    }
  }
  cout << price << endl;
}

Measured memory_bytes: 3628
import java.util.*;

class Main{
	static int mod=1000000007;

	public static void main(String[] $){
		System.err.println();
		Scanner s=new Scanner(System.in);
		char[]a=s.next().toCharArray();
		char[]t=s.next().toCharArray();
		int n=a.length;
		int[][]next=new int[26][n];

		for(int i=0;i<26;++i)
			Arrays.fill(next[i],Integer.MAX_VALUE/2);
		for(int i=0;i<n;++i)
			next[a[i]-'a'][i]=1;

		for(int k=n*2-2;k>=0;--k) {
			int i=k%n;
			int j=(i+1)%n;
			for(int c=0;c<26;++c)
				next[c][i]=Math.min(next[c][i],next[c][j]+1);
		}

		//Arrays.stream(next).map(Arrays::toString).forEach(System.err::println);

		long r=0;
		int index=0;
		int m=t.length;
		for(int i=0;i<m;++i) {
			int v=next[t[i]-'a'][index];
			if(v>=10000000) {
				System.out.println(-1);
				return;
			}
			r+=v;
			//System.err.println(r+" "+index);
			index+=v;
			index%=n;
		}
		System.out.println(r);
	}
}


Measured memory_bytes: 38900
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
ll a[55], p[55];
ll f(ll N, ll X) {
	if (N == 0) {
		if(X>0) return 1;
		else return 0;
	}
	else if (X <= a[N - 1] + 1) return f(N - 1, X - 1);
	else return p[N - 1] + 1 + f(N - 1, X - a[N - 1] - 2);
}
int main() {
	ll N, X;
	cin >> N >> X;
	a[0] = 1;
	p[0] = 1;
	for (int i = 0; i < N; i++) a[i + 1] = 2 * a[i] + 3;
	for (int i = 0; i < N; i++) p[i + 1] = 2 * p[i] + 1;
	cout << f(N,X) << endl;
}

Measured memory_bytes: 384
import numpy as np

N = int(input())
arr = np.array([int(i) for i in input().split()])

ans = 0

for i in range(60):
    c1 = np.count_nonzero(arr & 1)
    ans += 2 ** i * c1 * (N-c1)
    arr >>= 1


print(ans%1000000007)

Measured memory_bytes: 48832
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int N;
    cin >> N;
    int h[100010];
    for(int i = 1; i <= N; i++){
        cin >> h[i];
    }
    
    int dp[100010];
    dp[0] = 0;
    dp[1] = abs(h[2] - h[1]);
    
    for(int i = 1; i < N; i++){
        dp[i+1] = dp[i] + abs(h[i+2] - h[i+1]);
        dp[i+1] = min(dp[i+1], dp[i-1] + abs(h[i+2] - h[i]));
    }
    
    cout << dp[N-1] << endl;
    


}


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

namespace Algorithm
{
    class Program
    {
        const long Inf = long.MaxValue;
        static int N;
        static long[] h = new long[100010];
        static long[] dp = new long[100010];
        static void Main(string[] args)
        {
            N = int.Parse(Console.ReadLine());
            h = Console.ReadLine().Split().Select(long.Parse).ToArray();
            dp = Enumerable.Repeat(Inf, 100010).ToArray();

            dp[0] = 0;
            for (var i = 1; i < N; i++)
            {
                dp[i] = Math.Min(dp[i], dp[i - 1] + Math.Abs(h[i] - h[i - 1]));
                if (i > 1) dp[i] = Math.Min(dp[i], dp[i - 2] + Math.Abs(h[i] - h[i - 2]));

            }

            Console.WriteLine(dp[N - 1]);
        }
    }
}


Measured memory_bytes: 23136
module IntSet = Set.Make (struct
  type t = int
  let compare = compare
end)

let () = Scanf.scanf "%d" @@ fun s -> 
  let rec solve s an n =
    if IntSet.mem an s then n
    else solve (IntSet.add an s) (if an mod 2 = 0 then an / 2 else 3 * an + 1) (n + 1) in
  Printf.printf "%d\n" @@ solve IntSet.empty s 1


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

string a,b;
int main() {
  cin >> a >> b;
  string c(a.size() + b.size(), ' ');
  for(int i = 0; i < a.size(); ++i) {
    c[i * 2] = a[i];
  }
  for(int i = 0; i < b.size(); ++i) {
    c[i * 2 + 1] = b[i];
  }
 cout << c << endl;
}


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

int main(){
	int n;
	cin>>n;
	int *line = new int[n];
	for(int i=0;i<n;++i){
		cin>>line[i];
	}
	int x = line[n-1];
	int j = -1;
	for(int i=0;i<n-1;++i){
		if(line[i] <= x){
			++j;
			swap(line[i],line[j]);
		}
	}
	++j;
	swap(line[j],line[n-1]);
	for(int i=0;i<n;++i){
		cout<<(i==j?"[":"")<<line[i]<<(i==j?"]":"")<<(i+1==n?"\n":" ");
	}
	return 0;
}



Measured memory_bytes: 3492
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
using graph = vector<vector<int>>;

const double pi = 3.14159265358979323846;
const ll mod = 1000000007;

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n, m; cin >> n >> m;
	graph G(n+1);
	vector<int> ans(n+1);
	for(int i = 0; i < m; i++){
		int a, b; cin >> a >> b;
		G.at(a).push_back(b);
		G.at(b).push_back(a);
		if(a == 1) ans.at(b) = 1;
		if(b == 1) ans.at(a) = 1;
	}
	queue<int> que;
	for(int v: G.at(1)){
		que.push(v);
	}
	while(!que.empty()){
		int v = que.front(); que.pop();
		for(auto nv: G.at(v)){
			if(ans.at(nv) != 0) continue;
			ans.at(nv) = v;
			que.push(nv);
		}
	}
	bool ok = true;
	for(int i = 1; i < n+1; i++){
		if(ans.at(i) == 0){
			ok = false;
			break;
		}
	}
	if(ok){
		cout << "Yes" << endl;
		for(int i = 2; i < n+1; i++){
			cout << ans.at(i) << endl;
		}
	}
	else cout << "No" << endl;
} 

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

n,m = map(int,input().split())
A = list(map(int,input().split()))
BC = [tuple(map(int,input().split())) for i in range(m)]
BC = sorted(BC,key=lambda x:-x[1])
cnt = 0
flag = True
while True:
    for b,c in BC:
        A += [c]*b
        cnt += b
        if cnt > n:
            break
    break
A = sorted(A,reverse=True)
print(sum(A[:n]))

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

int main(){
    int a,b;
    char c;
    scanf("%d",&a);
    scanf(" %c",&c);
    scanf("%d", &b);
    if(c=='+'){
        printf("%d\n",a+b);
    }
    else{
        printf("%d\n",a-b);
    }
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<string>
#include<math.h>
using namespace std;

typedef struct Point{
    double x,y;
}P;

void koch(int n,P a,P b){
    if(n==0)return;
    P s,t,u;
    double th=M_PI*60.0/180.0;

    s.x=(2.0*a.x+1.0*b.x)/3.0;
    s.y=(2.0*a.y+1.0*b.y)/3.0;
    t.x=(1.0*a.x+2.0*b.x)/3.0;
    t.y=(1.0*a.y+2.0*b.y)/3.0;
    u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
    u.y=(t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;           

    koch(n-1,a,s);
    printf("%.8f %.8f\n",s.x,s.y);
    koch(n-1,s,u);
    printf("%.8f %.8f\n",u.x,u.y);
    koch(n-1,u,t);
    printf("%.8f %.8f\n",t.x,t.y);
    koch(n-1,t,b);
}

int main(){
    P a,b;
    int n;

    cin>>n;
    a.x=0;
    a.y=0;
    b.x=100;
    b.y=0;

    printf("%.8f %.8f\n",a.x,a.y);
    koch(n,a,b);
    printf("%.8f %.8f\n",b.x,b.y);
    return 0;
}



Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(x, y) for(int x = 0; x < (y); x++)
#define REP(x, z, y) for(int x = (z); x < (y); x++)
#define all(x) x.begin(), x.end()
#define len(x) (sizeof(x) / sizeof(x[0]))
#define split_str(str, sp_word) istringstream stream(str); string res; for(int cnt = 0; getline(stream,res,sp_word); cnt++)
#define scanln(x) fgets(x, sizeof x, stdin)
#define down_queue(x) priority_queue<x>
#define up_queue(x) priority_queue<x, vector<x>, greater<x>>
#define i_str(x) atoi(x.c_str())
#define digit(x) ((int)log10((double)(x)) + 1)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
using namespace std;
const int MOD = 1000000007; 
typedef long long ll;
typedef string str;
 
int main(){
  int H,W;
  scanf("%d%d",&H,&W);

  str ans[H * 2];
  for(int i = 0; i < (H * 2); i += 2){
    cin >> ans[i];
    ans[i + 1] = ans[i];
  }
  
  for(auto c :ans)
    printf("%s\n",c.c_str());

  return 0;
}

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

int main() {
	string s;
  	cin >> s;
  	bool half = false, other = false;
  	for(int i = 0; i < s.size(); i++) {
    	if(s[i] == 'A') {
        	half = true;
        } else {
        	other = true;
        }
    }
  	if(half && other) {
    	cout << "Yes";
    } else {
    	cout << "No";
    }
}

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

main()
{
        long a,b,k; cin>>a>>b>>k;
        if(a>=k)
        {
                a-=k;
                cout<<a<<" "<<b<<endl;
                return 0;
        }
        k-=a;
        if(b>=k)
        {
                b-=k;
                cout<<0<<" "<<b<<endl;
                return 0;
        }
        cout<<"0 0"<<endl;
}

Measured memory_bytes: 256
// Copyright 2020 yaito3014
#include <algorithm>
#include <iostream>
#include <vector>

int main() {
  int N;
  unsigned int K;
  std::cin >> N >> K;
  std::vector<unsigned int> A(N);
  std::vector<long long> B(N);
  for (int i = 0; i < N; ++i) std::cin >> A[i] >> B[i];
  long long ans = 0;
  for (int r = 0; r <= 30; ++r) {
    unsigned int X = K >> r << r | ((1 << r) - 1) >> 1;
    if (X > K) continue;
    long long sum = 0;
    for (int i = 0; i < N; ++i)
      if (!(A[i] & ~X))
        sum += B[i];
    ans = std::max(ans, sum);
  }
  std::cout << ans << '\n';
}


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

using namespace std;

#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define f first
#define s second
#define pb push_back

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

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

int main(){ _
	int k; cin >> k;
	string s; cin >> s;
	if (s.length() <= k) cout << s << endl;
	else {
		for (int i = 0; i < k; i++) cout << s[i];
		cout << "..." << endl;
	}
	exit(0);
}


Measured memory_bytes: 3560
def func(N, A_i, B_i, C_i):
    stf = 0
    for i in range(N):
        stf += B_i[i]
        if i >= 1 and (A_i[i] == A_i[i-1] + 1):
            stf += C_i[A_i[i-1]-1]
    return stf

N = int(input())
A_i = list(map(int, input().split(" ")))
B_i = list(map(int, input().split(" ")))
C_i = list(map(int, input().split(" ")))
print(func(N, A_i, B_i, C_i))

Measured memory_bytes: 3064
#!/usr/bin/perl -w                                                                                                                                         2 use strict;
   use warnings;
  
   my $s = <>;
   my $flag = 0;
   chomp($s);
   for my $alpha ('a'..'z'){
           my $count = 0;
          while($s =~ m/$alpha/g){$count++;}
          if($count %2 != 0){$flag = 1;}
  }
  if($flag ==0){print"Yes\n";}
  else{print "No\n"}

Measured memory_bytes: 640
#include<iostream>
#include<string>
using namespace std;
int main(){
  string name[5]={"meiji","taisho","showa","heisei"},ss=" ";
  int year[5]={1867,1911,1925,1988};
  int a,b,c,d;
  while(cin>>a>>b>>c){
    d=a*10000+b*100+c;
    if(d<18680908){cout<<"pre-meiji"<<endl;continue;}
    if(d<19120730){cout<<"meiji"<<ss<<a-1867<<ss<<b<<ss<<c<<endl;continue;}
    if(d<19261225){cout<<"taisho"<<ss<<a-1911<<ss<<b<<ss<<c<<endl;continue;}
    if(d<19890108){cout<<"showa"<<ss<<a-1925<<ss<<b<<ss<<c<<endl;continue;}
    cout<<"heisei"<<ss<<a-1988<<ss<<b<<ss<<c<<endl;
  }
  return 0;
}

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

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

    int n, y;
    cin >> n >> y;

    REP(i, n + 1){
        REP(j, n + 1){
            if((n - i - j) >= 0){
                if(i * 10000 + j * 5000 + (n - i - j) * 1000 == y){
                    cout << i << " " << j << " " << n - i - j << endl;
                    return 0;
                }
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = (int)1e9 + 7;
const int INF = (int)100100100;

int main() {
    ll N; cin >> N;
    //ll N,M; cin >> N >> M;文明のりきぽよ（りきぽよをあまり知らない）
    //ll H,W; cin >> H >> W;
  	if(N==10 || N==100 || N==1000 || N==10000 || N==100000)cout << 10;
  	else{
      int sum=0;
      for(int i=0;i<6;i++){
        sum+=N%10;
        N=N/10;
      }
      cout << sum;
    }
}

/*



 */




Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdexcept>
#include<stdio.h>
using namespace std;

int main(){
  string S; cin >> S;  int l=0; int ans=0;
  for(int i=0;i<S.size();i++){
    if(S[i]=='A' || S[i]=='C' || S[i]=='G' || S[i]=='T')
    {l++; if(ans<l) ans=l;}
    else l=0;
  }
  cout << ans <<endl;
}
  
      

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

using namespace std;


int main(){
    double a,b,c,d,e,f,x,y;

    while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=EOF){
        x=(c*e-b*f)/(a*e-d*b);
        y=(c*d-a*f)/(b*d-a*e);
        if(x == 0)x=0;
        if(y == 0)y=0;
        printf("%.3lf %.3lf\n",x,y);
    }

    return 0;
}


Measured memory_bytes: 2596
X, Y = map(int, input().split())
prize = [300000, 200000, 100000]
ans = 0

if X <= 3:
    X -= 1
    ans += prize[X]

if Y <= 3:
    Y -= 1
    ans += prize[Y]

if ans == 600000:
    ans += 400000

print(ans)

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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

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

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

    string S;
    std::cin >> S;

    auto check = [](char& c) {
                     if(c == 'A' || c == 'C' || c == 'G' || c == 'T') {
                         return true;
                     }
                     else {
                         return false;
                     }
                 };

    int ans = 0;
    int cont_cnt = 0;
    REP(i, S.size()) {
        if(check(S[i])) {
            cont_cnt++;
        }
        else {
            ans = max(ans, cont_cnt);
            cont_cnt = 0;
        }
    }

    std::cout << max(ans, cont_cnt) << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
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 (a>b) { a=b; return 1; } return 0; }

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

    string s; cin >> s;
    int ans = 0;
    rep(i,4) if(s[i] == '2') ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  cin >> a >> b;
  
  if( (a + b) % 2 == 0 ) {
	  cout << (a+b)/2 << endl;     
  }else{  	
	  cout << (a+b)/2 + 1 << endl; 
  }
}

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

using ll = long long;
using vi = vector<int>;
#define pb push_back

const ll mod = 1e9+7;
const int lim = 1e5+99;

int N, M;

vi f; // 素因数分解(指数部のみ)

ll fact[lim], inv[lim]; // 階乗, そのmodでの逆数

ll pow(ll a, ll e) { // a^e
    if(e == 0) return 1;
    ll p = pow(a, e/2);
    if(e%2 == 1) return p * p % mod * a % mod;
    else return p * p % mod; 
}

inline ll combine(ll n, ll k) { // n_C_k
    return fact[n] * inv[k] % mod * inv[n-k] % mod;
}

int main() {

    cin >> N >> M;

    for(int p=2; M != 1; ++p) { // 素因数分解
        int e = 0;
        while(M%p == 0) {
            ++e;
            M /= p;
        }
        if(e>0)f.pb(e);
    }

    // fact, inv の計算
    fact[0] = inv[0] = 1;
    for(ll k = 1; k < lim; ++k) {
        fact[k] = fact[k-1] * k % mod;
        inv[k] = pow(fact[k], mod-2);
    }

    ll ans = 1;
    for(int e : f) {
        ans *= combine(e+N-1, e); // N_H_e (重複組合せ)
        ans %= mod;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2424
import numpy as np
import fractions

S = input()
F = int(S[0:2])
E = int(S[2:4])

if(0 < F and F < 13 ):
    if(0 < E and E<13):
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:#F>=13
    if(0 < E and E < 13):
        print("YYMM")
    else:
        print("NA")


Measured memory_bytes: 22276
def main():
    n, m = map(int, input().split())
    A = [[0] * m for i in range(n)]
    B = [0] * m
    C = [0] * n
    for i in range(n):
        A[i] = list(map(int, input().split()))
    for i in range(m):
        B[i] = int(input())
    for i in range(n):
        sum = 0
        for j in range(m):
            sum += A[i][j] * B[j]
        C[i] = sum
    for i in C:
        print(f"{i}")
    return 0


if __name__ == "__main__":
    main()



Measured memory_bytes: 5796
#include <bits/stdc++.h>
using namespace std;
int qtas_pedras, pedras[100009];
long long custo_ate_aqui[100009];
void menor_custo(int pedra){
    long long op1 = custo_ate_aqui[pedra-2] + abs(pedras[pedra-2]-pedras[pedra]);
    long long op2 = custo_ate_aqui[pedra-1]+abs(pedras[pedra-1]-pedras[pedra]);
    custo_ate_aqui[pedra] = min(op1, op2);
}
int main(){
    int temp;
    cin>>qtas_pedras;
    for(int i=0;i<qtas_pedras;i++){
        cin>>temp;
        pedras[i]=temp;
        custo_ate_aqui[i] = 1000000009;
    }
    qtas_pedras--;
    custo_ate_aqui[0] = 0;
    custo_ate_aqui[1] = abs(pedras[0]-pedras[1]);
    //cout<<custo_ate_aqui[qtas_pedras]<<endl;
    /*
    for(int i=0;i<=qtas_pedras;i++){
        cout<<"i"<<i<<"qi"<<custo_ate_aqui[i]<<endl;
    }
    */
   for(int i=2;i<=qtas_pedras;i++){
       menor_custo(i);
       //cout<<"menor c i"<<i<<' '<<custo_ate_aqui[i]<<endl;
   }
   cout<<custo_ate_aqui[qtas_pedras]<<endl;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long 
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)

int main()
{
  ll x,y;
  cin >> x >> y;
  if(y<=4*x && y>=2*x)
  {
      if(y%2==0)
      {
         cout << "Yes" << endl;
      }
      else
      cout << "No" << endl;
  }
  else
  cout << "No" << endl;
  
  return 0;
}

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

int main() {
	int N, Taro = 0, Hanako = 0;
	string T, H;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> T >> H;
		if (T == H) Taro++, Hanako++;
		else {
			bool t = false, h = false;
			for (int j = 0; j < min(T.size(), H.size()); j++) {
				if (T[j] > H[j]) {
					t = true;
					break;
				}
				if (T[j] < H[j]) {
					h = true;
					break;
				}
			}
			if (!t && !h) {
				if (T.size() > H.size()) t = true;
				else h = true;
			}
			if (t) Taro += 3;
			if (h) Hanako += 3;
		}
	}
	cout << Taro << " " << Hanako << endl;
}


Measured memory_bytes: 3212
n, c = map(int, raw_input().split())
A = map(int, raw_input().split())
B = map(int, raw_input().split())

MOD = 10**9+7

memo = [[0]*401 for i in xrange(401)]
for i in xrange(401):
    temp = 0
    for j in xrange(401):
        temp = (temp + pow(j, i, MOD)) % MOD
        memo[j][i] = temp
S = [memo[A[i]-1] for i in xrange(n)]
T = [memo[B[i]] for i in xrange(n)]

dp = [[-1]*(c+1) for i in xrange(n)]
def dfs(i, r):
    if i==-1:
        return r==0
    if dp[i][r] != -1:
        return dp[i][r]
    res = 0
    s = S[i]; t = T[i]
    for j in xrange(0, r+1):
        res = (res + (t[j]-s[j])*dfs(i-1, r-j)) % MOD
    dp[i][r] = res
    return res
print dfs(n-1, c)

Measured memory_bytes: 21356
n,k=map(int,input().split())
h=[int(input()) for _ in range(n)]
h.sort()
#print(h)
m=10000000000
for i in range(n-k+1):
    hs=h[i+k-1]-h[i]
    #print(hs)
    m=min(m,hs)
print(m)


Measured memory_bytes: 50264
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int mx,mn;
	int n;
	while(n=in()){
		int sum;
		int i,j;
		mx=0;mn=1000;
		for(j=0;j<n;j++){
			sum=0;
			for(i=0;i<5;i++){
				sum+=in();
			}
			chmax(mx,sum);
			chmin(mn,sum);
		}
		cout<<mx<<" "<<mn<<endl;
	}
	return 0;
}

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

int main()
{
    ll n,w;
    cin>>n>>w;
    ll x[n],y[n];
    for(ll i=0;i<n;i++)
    {
        cin>>x[i]>>y[i];
    }
    ll dp[n][w+1];
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<=w;j++)
        {
            if(i==0)
            {
                if(j<x[i])
                    dp[i][j]=0;
                else
                    dp[i][j]=y[i];
                continue;
            }
            if(j<x[i])
                dp[i][j]=dp[i-1][j];
            else
                dp[i][j]=max(dp[i-1][j],y[i]+dp[i-1][j-x[i]]);
        }
    }
    cout<<dp[n-1][w]<<endl;
    return 0;
}


Measured memory_bytes: 78336
#define _GLIBCXX_DEBUG
    #include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int a, b, c, d;
      int e;
      int f;
      cin >> a >> b >> c >> d;
      e = a / d;
      if (a % d != 0){
        e++;
      }
      if (c - b * e <= 0){
        cout << "Yes" << endl;
      }
      else{
        cout << "No" << endl;
      }
    }

Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack> 
#include <set>
#include <map>
using namespace std;

#define N 100020
const int INF = 1 << 30;

int a[N];

int main()
{
	//freopen("in.in", "r", stdin);
	//freopen("out.out", "w", stdout);
     
    int n, Min = INF, Max = 0;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) 

    {
    	scanf("%d", &a[i]);
    	Min = min(Min, a[i]);
    	Max = max(Max, a[i]);
    }

	if (Max == Min)
	{
		if (Max == n - 1 || 2 * Max <= n) puts("Yes");
		else puts("No");
	}
	else if (Max - Min == 1)
	{
		int b = 0;
		for (int i = 1; i <= n; ++i) b += (a[i] == Min);
		puts(b < Max && (Max - b) * 2 + b <= n? "Yes":"No");
	}
	else puts("No");
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define bug1( x ) {cerr << (#x) <<"="<< x << endl;}
#define bug2( x , y ) {cerr << (#x) <<"="<< (x) << "    " << (#y) << "="<< (y) << endl;}
#define bug3( x , y , z ) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << endl;}
#define bug4( x , y , z , w) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << endl;}
#define bug5( x , y , z , w ,p) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << endl;}
#define bug6( x , y , z , w ,p , q) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << "    " << (#q) <<"="<< q << endl;}
#define bugn( x , n ) {cerr << (#x) <<":";for(int i=0;i<n;i++)cerr << x[i] <<"  "; cerr << endl;}
#define bugnm( x , n , m ) {cerr << (#x)<<endl;for(int i=0;i<n;i++){cerr << "Row #" << i<< ":";for(int j=0;j<m;j++)cerr << x[i][j] << "   ";cerr << endl;}}
typedef long long ll;
typedef long double ld;
using namespace std;

const int maxn  = 12;
vector<int>dp(1<<maxn,1e18);
int n,m;
int32_t main(){
	IOS
	dp[0]=0;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int cost,k;cin>>cost>>k;
		int mask=0;
		for(int j=0;j<k;j++){
			int x;cin>>x;x--;
			mask|=1<<x;
		}
		auto dp2=dp;
		for(int j=0;j<1<<n;j++){
			dp2[j|mask]=min(dp2[j|mask],dp[j]+cost);
		}
		dp=dp2;
	}
	int ans = dp[(1<<n)-1];
	if( ans >= 1e18 )ans =-1;
	cout << ans;
 }
/*
 * long long or int?
 * index out of bound? 
 * Tested on own test case?corner?
 * Make more general solution.
 * Read Read Read Read ....
 */


Measured memory_bytes: 3684
package main

import "fmt"

func main() {
	var N int
	var S string
	fmt.Scan(&N)
	fmt.Scan(&S)
	var r, g, b int
	for _, c := range S {
		if c == 'R' {
			r++
		}
		if c == 'G' {
			g++
		}
		if c == 'B' {
			b++
		}
	}
	count := 0 // j-i==k-j
	for i := 0; i < N-2; i++ {
		for j := i + 1; j < N-1; j++ {
			k := 2*j - i
			if k >= N {
				continue
			}
			// (i, j, k)
			if S[i] != S[j] && S[j] != S[k] && S[k] != S[i] {
				count++
			}
		}
	}
	fmt.Println(r*g*b - count)
}


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

typedef long long ll;

const int Maxn = 100005;
const int mod = 1000000007;

char s[Maxn];
int slen;
int L[Maxn], LU[Maxn];
int R[Maxn], RU[Maxn];

int toPower(int a, int p)
{
	if (p < 0) return 0;
	int res = 1;
	while (p) {
		if (p & 1) res = ll(res) * a % mod;
		p >>= 1; a = ll(a) * a % mod;
	}
	return res;
}

int Inv(int a) { return toPower(a, mod - 2); }

int getLeft(int ind)
{
	return (ll(L[ind]) * toPower(3, LU[ind]) + ll(LU[ind]) * toPower(3, LU[ind] - 1)) % mod;
}

int getRight(int ind)
{
	return (ll(R[ind]) * toPower(3, RU[ind]) + ll(RU[ind]) * toPower(3, RU[ind] - 1)) % mod;
}

int main()
{
	scanf("%s", s + 1); slen = strlen(s + 1);
	for (int i = 1; i <= slen; i++) {
		L[i] = L[i - 1]; LU[i] = LU[i - 1];
		if (s[i] == '?') LU[i]++;
		else if (s[i] == 'A') L[i]++;
	}
	for (int i = slen; i > 0; i--) {
		R[i] = R[i + 1]; RU[i] = RU[i + 1];
		if (s[i] == '?') RU[i]++;
		else if (s[i] == 'C') R[i]++;
	}
	int res = 0;
	for (int i = 1; i <= slen; i++) if (s[i] == 'B' || s[i] == '?')
		res = (res + ll(getLeft(i - 1)) * getRight(i + 1)) % mod;
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  cout << fixed << setprecision(15);
  int N;
  cin >> N;
  vector<ld> p(N);
  for(int i=0;i<N;i++)  cin >> p.at(i);

  vector<vector<ld>> dp(N+1,vector<ld>(N+1,0));
  dp.at(0).at(0)=1;
  for(int i=1;i<=N;i++){
    for(int j=0;j<=N;j++){
      dp.at(i).at(j)=dp.at(i-1).at(j)*(1.0-p.at(i-1));
      if(j-1>=0)  dp.at(i).at(j)+=dp.at(i-1).at(j-1)*p.at(i-1);
    }
  }
  ld ans=0;
  for(int i=(N+1)/2;i<=N;i++) ans+=dp.at(N).at(i);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 141056
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>

#define MAX_N 100001
using namespace std;
typedef long long ll;
ll A[MAX_N];
ll B[MAX_N];

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

    ll N;
    cin >> N;
    for(ll i = 0; i < N; i++) cin >> A[i];

    fill(B, B + N, 0);
    B[N-1] += A[N-1];
    for(ll i = 0; i < N-1; i++) B[N-1] += pow(-1, (i+1) % 2) * A[i];
    for(ll i = 1; i < N; i++) B[N-1-i] = 2 * A[N-1-i] - B[N-i];

    for(ll i = 0; i < N; i++) cout << B[i] << " ";
    cout << endl;    
    return 0;
}


Measured memory_bytes: 4800
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define ll unsigned long long
using namespace std;
int main(){
    int H,N;
    cin>>H>>N;
    vector<int> A(0,N);
    REP(i,N){
        int k;cin>>k;
        A.push_back(k);
    }
    sort(A.begin(),A.end());
    A.erase(unique(A.begin(),A.end()),A.end());
    for(int i=0;i<N;i++){
        if(H-A[i]<=0){
            cout<<"Yes"<<endl;
            return 0;
        }
        H-=A[i];
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 892
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 line = br.readLine();
		boolean zeroFlag = true;

		while (zeroFlag) {
			String[] hikakuStr = line.split("[\\s]+");
			int x = Integer.parseInt(hikakuStr[0]);
			int y = Integer.parseInt(hikakuStr[1]);

			if (x == 0 && y == 0) {
				zeroFlag = false;
			} else if (x < y) {
				System.out.println(x + " " + y);
				line = br.readLine();
				hikakuStr = line.split("[\\s]+");
			} else {
				System.out.println(y + " " + x);
				line = br.readLine();
				hikakuStr = line.split("[\\s]+");
			}
		}
	}
}

Measured memory_bytes: 33752
#include <bits/stdc++.h>
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")
using namespace std;

typedef unsigned long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;

#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for (int i=(a); i<(b); ++i)
#define FORD(i,a,b) for (int i=(a)-1; i>=(b); --i)

#define pb push_back
#define mp make_pair
#define st first
#define nd second

const int MOD = 1000000007;

int N;
vector<int> adj[105];

int D[105];
void compute_distances(vector<int> r) {
  REP(i,N) D[i] = -1;

  queue<int> Q;
  for (int v: r) {
    Q.push(v);
    D[v] = 0;
  }
  while (!Q.empty()) {
    int v = Q.front();
    Q.pop();
    for (int u: adj[v]) if (D[u] == -1) {
      D[u] = D[v] + 1;
      Q.push(u);
    }
  }
}

pair<LL, LL> go(vector<int> r) {
  compute_distances(r);
  vector<vector<int>> by_distance(N+1);
  REP(i,N) by_distance[D[i]].pb(i);
  LL result = by_distance[0].size();
  int depth = 1;
  REP(i,N+1) {
    int m = 0;
    for (int v: by_distance[i]) {
      m = max(m, (int)adj[v].size() - (i > 0 ? 1 : (int)r.size() - 1));
    }
    if (m == 0) break;
    depth = i + 2;
    result *= m;
  }

  return pair<LL,LL>{depth, result};
}

int main() {
  // ios_base::sync_with_stdio(0);

  scanf("%d", &N);
  REP(i,N-1) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a, --b;
    adj[a].pb(b);
    adj[b].pb(a);
  }

  pair<LL, LL> res(~0ULL, ~0ULL);
  REP(i,N) res = min(res, go({i}));
  REP(u,N) for (auto v: adj[u]) res = min(res, go({u, v}));
  printf("%lld %lld\n", res.st, res.nd);
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int R = sc.nextInt();
    int G = sc.nextInt();
    int B = sc.nextInt();
    int N = sc.nextInt();
    
    int count = 0;
    
    for (int r=0; r<=N; r++){
      for (int g=0; g<=N; g++){
        int x = N-r*R-g*G;
        if (x>=0 && x % B == 0){
          count++;
        }
      }
    }
    
    System.out.println(count);
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
  #include "dbgtoki.hpp"
  #define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
DbgTimer D_t;
  #define TSTART() D_t.start()
  #define TSTOP() D_t.stop()
#else
  #define DUMP(i) 
  #define TSTART()
  #define TSTOP()  
#endif
 
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

const int EPS = 1e-9;



int main (){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b;
  while(cin >> a >> b ){
    TSTART();
    
    string ans;
    if(a == b)ans = "Draw";
    else if(a == 1)ans = "Alice";
    else if(b == 1)ans = "Bob";
    else{
      if(a > b)ans = "Alice";
      else ans = "Bob";
    }
    
    cout << ans << endl;
    TSTOP();
  }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
struct edge { int to, cost; };
typedef pair<int, int>P;
#define PI 3.14159265359
#define MOD 1000000007
const int MAX =510000;

int main(){
	int N;
  	cin >>N;
  	vector<int>L(N);
  	
  	rep(i,N){
    	cin >>L[i];
    }
  	
  	sort(L.begin(),L.end());
  	ll ans=0;
  	for(int i=0;i<=N-3;i++){
    	for(int j=i+1;j<=N-2;j++){
    		int a=L[i],b=L[j];    	
        	auto itr=lower_bound(L.begin(),L.end(),a+b);
            int g=distance(itr,L.end());
          ans+=(N-j-1)-g;
        }
    }
  	cout<<ans<<endl;
}


Measured memory_bytes: 256