akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include<iomanip>

using namespace std;
typedef long long ll;


int main() {
	int N, K, S;
	cin >> N >> K >> S;
	vector<int> A(N, 1e9);
	for (int i = 0; i < K; i++) A[i] = S;
	if (S == 1e9) {
		for (int i = K; i < N; i++) A[i] = 1;
	}
	for (int i = 0; i < N; i++) {
		cout << A[i] << " ";
	}
}


Measured memory_bytes: 3784
L=lambda:list(map(int,input().split()))
def main():
    a,b=L()
    ans=0
    if a>b:
        ans+=a
        a-=1
    else:
        ans+=b
        b-=1
    if a>b:
        ans+=a
        a-=1
    else:
        ans+=b
        b-=1
    print(ans)

if __name__ == '__main__':
    main()

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

#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#endif


const int MAXN = 100;
//#define int long long
const int INF = 1e9;

void solve(){
  string s;
  cin >> s;
  int n = s.size();

  for (int i = 0; i < n-1; i++){
    if (s[i] == s[i + 1]) {
      cout << i + 1 << ' ' << i + 2 << '\n';
      return;
    }
  }

  for (int i = 0; i < n-2; i++){
    if (s[i] == s[i + 1] || s[i] == s[i + 2] || s[i + 1] == s[i + 2]) {
      cout << i + 1 << ' ' << i + 3 << '\n';
      return;
    }
  }

  cout << "-1 -1\n";
}

signed main()
{
    #ifdef FILEIO
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    solve();

    return 0;
}


Measured memory_bytes: 3796
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>
#include <iomanip>

typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[20][20];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}
ll dp[20500];
int main() {
	ll bingo[3][3];
	bool p[3][3];
	rep(i, 3) {
		rep(j, 3) {
			cin >> bingo[i][j];
			p[i][j] = false;
		}
	}
	cin >> n;
	ll b;
	rep(i, n) {
		cin >> b;
		rep(i, 3) {
			rep(j, 3) {
				if (bingo[i][j] == b) {
					p[i][j] = true;
				}
			}
		}
	}
	ll res = 0;
	rep(i, 3) {
		if (p[i][0] && p[i][1] && p[i][2]) {
			res++;
		}
	}
	rep(i, 3) {
		if (p[0][i] && p[1][i] && p[2][i]) {
			res++;
		}
	}
	if (p[0][0] && p[1][1] && p[2][2]) {
		res++;
	}
	if (p[0][2] && p[1][1] && p[2][0]) {
		res++;
	}
	if (res != 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}



Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>

void printInt(long long value);
void br();
void scanInt(long long* value);
void scanIntArray(long long* array, long long count);
void scanIntVector(std::vector<long long>* v, long long count);

long long gcd(long long C, long long D) {
	long long r = C % D;
	while (r != 0) {
		C = D;
		D = r;
		r = C % D;
	}
	return D;
}

long long lcm(long long C, long long D) {
	return C * D / gcd(C, D);
}

long long count(long long max, long long C, long long D) {
	return max - (max / C) - (max / D) + (max / lcm(C, D));
}

int main() {
	long long A, B, C, D;
	scanInt(&A);
	scanInt(&B);
	scanInt(&C);
	scanInt(&D);
	printInt(count(B, C, D) - count(A - 1, C, D));
}

void printInt(long long value) {
	printf("%lld", value);
}

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

void scanIntArray(long long* array, long long count) {
	for (long long i = 0; i < count; ++i) {
		scanInt(array + i);
	}
}

void scanIntVector(std::vector<long long>* v, long long count) {
	for (long long i = 0; i < count; ++i) {
		long long value;
		scanInt(&value);
		v->push_back(value);
	}
}

void scanInt(long long* value) {
	scanf("%lld", value);
}

Measured memory_bytes: 256
/*
首先二分单次操作中所获得的最小幸福值，记作𝑚𝑖𝑑 ，然后计算，以此值作为幸福值的边界，
可以握多少次手，如果握手次数大于𝑀则扩大这个𝑚𝑖𝑑 ，否则缩小。
对于每次二分得到的𝑚𝑖𝑑 ，针对每一个𝑎[𝑖]计算另一个值𝑚𝑖𝑑−𝑎[𝑖]的下标𝑝𝑜𝑠。
所以目前就获得了 𝑛−𝑝𝑜𝑠+1 对握手，然后把这些握手得到的幸福值加到𝑟𝑒𝑠 中
𝑠𝑢𝑚 是前缀和数组，𝑠𝑢𝑚[𝑛]−𝑠𝑢𝑚[𝑝𝑜𝑠−1] 得到 𝑛−𝑝𝑜𝑠 这些值的和再加上𝑛−𝑝𝑜𝑠+1个𝑎[𝑖]
因为𝑐𝑛𝑡 最后不一定刚等于𝑚 ，𝑐𝑛𝑡 只是第一次二分的𝑐ℎ𝑒𝑐𝑘 函数 ，有可能大于 𝑚
所以最后在减去多余的即可
*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
const int N = 1e5 + 10;
#define endl '\n'
typedef long long LL;
LL sum[N],a[N],m,n;
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin >> n >> m;
    for(int i = 1;i <= n; ++i) cin >> a[i];
    sort(a+1,a+1+n);
    for(int i = 1;i <= n; ++i) sum[i] = sum[i - 1] + a[i];
    LL l = 0,r = 2*N,ans,res,cnt;
    while(l < r) {
        LL mid = (l + r + 1) >> 1;
        res = cnt = 0;
        for(int i = 1;i <= n; ++i) {
            LL pos = lower_bound(a+1,a+1+n,mid-a[i]) - a;
            cnt += n - pos + 1;
            res += sum[n] - sum[pos - 1] + a[i] * (n - pos + 1);
        }
        if(cnt >= m) l = mid;
        else r = mid - 1;
    }
    cout << res - (cnt - m) * l << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#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 all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
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 string dir = "DRUL";
*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    string S, T;
    cin >> S >> T;
    int N = S.size();
    ll ans = 0;
    rep(i,N){
        ans += S[i] != T[i];
    }
    cout << ans << endl;
}


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

int main(){
  int a,b,c,k;
  cin >>a >>b >>c;
  cin >> k;
  while(k>0){
    k--;
    if(max({a,b,c}) == a){
      a *= 2; 
    }
    else if(max({a,b,c}) == b){
      b *= 2; 
    }
    else{
      c *= 2; 
    }
  }
  cout << a+b+c << endl;
  return 0; 
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef struct{
  int p,l,r,s;
}Node;
Node t[100000];
 
int depth(int x){
  int cnt=0;
  if(t[x].p>=0) cnt=depth(t[x].p)+1;
  return cnt;
}
 
int height(int x){
  int cntl=0,cntr=0;
  if(t[x].l>=0)cntl=height(t[x].l)+1;
  if(t[x].r>=0) cntr=height(t[x].r)+1;
  if(cntl<cntr)return cntr;
  else  return cntl;
}
 
int degree(int x){
  int cnt=0;
  if(t[x].l>=0)cnt++;
  if(t[x].r>=0)cnt++;
  return cnt;
}
 
int main(){
  int n,id,right,left;
  cin>>n;
  for(int i=0;i<n;i++){t[i].l=-1;t[i].p=-1;t[i].r=-1;t[i].s=-1;}
 
  for(int i=0;i<n;i++){
    cin>>id>>left>>right;
    t[left].p=t[right].p=id;
    t[left].s=right;
    t[right].s=left;
    t[id].l=left;
    t[id].r=right;
  }
 
  for(int i=0;i<n;i++){
    cout<<"node "<<i<<": parent = "<<t[i].p<<", sibling = "<<t[i].s<<", degree = "<<degree(i) <<", depth = "<<depth(i)<<", "<<"height = "<<height(i)<<", ";
    if(t[i].p==-1) cout<<"root"<<endl;
    else if(t[i].l>=0 || t[i].r>=0) cout<<"internal node"<<endl;
    else cout<<"leaf"<<endl;
  }
  return 0;
}



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

int main(){
    int n, m;
    cin >> n >> m;
    pair<int, int> p[n];
    rep(i, n){
        p[i] = P(0,0);
    }
    rep(i, m){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        if(a==0){
            p[b].first= 1;
        }
        if(b==n-1){
            p[a].second=1;
        }
    }
    rep(i, n){
        if(p[i]==P(1,1)){
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 1792
// Problem : A - Remaining Time
// Contest : AtCoder - AtCoder Beginner Contest 057
// URL : https://atcoder.jp/contests/abc057/tasks/abc057_a
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

double pi=acos(-1.0);
const int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}

void solve()
{
int a,b;cin>>a>>b;
cout<<(a+b)%24;
}

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


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  while (cin >> N) {
    int res = 180 * (N - 2);
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
	//4ab<(c-a-b)
	long double a=0;
	long double b=0;
	long double c=0;
	cin>>a>>b>>c;
	if(4*a*b<(c-a-b)*(c-a-b)&&c-a-b>0)
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
	return 0;
}

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

int main()
{
  int N;
  cin >>N;
  vector<int> a(N);
  for(int i =0;i<N;i++){
    cin >>a.at(i);
  }
  int cnt = 0;
  for(int i =0;i<N;i++){
    if(a.at(i)==cnt+1){
      cnt++;
    }
  }
  if(cnt ==0){
    cout <<-1<<endl;
  }else{
    cout <<N-cnt<<endl;
  }
}





Measured memory_bytes: 1024
N = int(input())
T = [int(n) for n in input().split()]
M = int(input())
P=[]
X=[]
for i in range(M):
    a,b=[int(n) for n in input().split()]
    P.append(a)
    X.append(b)

s=0
for i in range(N):
    s += T[i]

for i in range(M):
    print ( s - (T[P[i]-1] - X[i] ) )


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define L long
#define endl "\n"
#define ___ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

const int N = (int)1e5;

int main()
{   
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ___
    
    ll int n = 0, k, x = 0;
    cin >> k;
    if (k % 2 == 0)
    {
        cout<< -1;
        return 0;
    }
    while (1)
    {
        n = ((n * 10) + 7) % k;
        x++;
        if (n == 0)
            break;
        else if (x == (int)1e8+(int)1e7)
        {
            cout<< -1;
            return 0;
        }
    }
    cout<< x;
    
    return 0;
}

Measured memory_bytes: 3648
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author kessido
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        CWhenIHitMyPocket solver = new CWhenIHitMyPocket();
        solver.solve(1, in, out);
        out.close();
    }

    static class CWhenIHitMyPocket {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int k = in.NextInt(), a = in.NextInt(), b = in.NextInt();
            long gainPerOperation = b - a;
            if (gainPerOperation <= 2) {
                out.println(k + 1);
            } else if (k <= (a - 1) + 1) {
                out.println(k + 1);
            } else {
                k -= a - 1;
                long startBisc = a;
                int numberOfOperation = k / 2;
                long biscAtTheEnd = startBisc + gainPerOperation * numberOfOperation;
                k -= numberOfOperation * 2;
                while (k != 0) {
                    k--;
                    biscAtTheEnd++;
                }
                out.println(biscAtTheEnd);

            }
        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine(), " \t\n\r\f,");
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int NextInt() {
            return Integer.parseInt(next());
        }

    }

    static class OutputWriter extends PrintWriter {
        public OutputWriter(Writer out) {
            super(out);
        }

        public OutputWriter(File file) throws FileNotFoundException {
            super(file);
        }

        public OutputWriter(OutputStream out) {
            super(out);
        }

    }
}



Measured memory_bytes: 21460
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,x[110],ans = 1e18;
int main() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> x[i];
    for (ll i = 1; i <= 100; i++) {
        ll tmp = 0;
        for (int j = 0; j < n; j++) {
            tmp += abs(x[j] - i) * abs(x[j] - i);
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

struct q{
    int idx,b;
};

struct tree{
    size_t n,r,md;
    vector<vector<int>> e;
    vector<int> l,d,ans;
    stack<q> Q;
    explicit tree(int n):n(n),e(n),l(n+1,INT_MAX),d(n),ans(n),Q(){}
    void built(bool f=true){
        static int a,b;
        for(auto&i:d) cin>>i;
        fr(i,n-1){
            cin>>a>>b;
            if(f) --a,--b;
            add(a,b);
        }
    }
    void add(int a,int b,bool f=true){
        e[a].emplace_back(b);
        if(f) e[b].emplace_back(a);
    }
    void r_dfs(int i=0,int p=-1){
        int idx=lower_bound(l.begin(),l.end(),d[i])-l.begin();
        Q.push(q{idx,l[idx]});
        l[idx]=d[i];
        ans[i]=lower_bound(l.begin(),l.end(),INT_MAX)-l.begin();
        for(auto j:e[i]) if(j!=p) r_dfs(j,i);
        auto [id,b]=Q.top();Q.pop();
        l[id]=b;
    }
};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    tree t(n);
    t.built();
    t.r_dfs();
    for(auto&i:t.ans) cout<<i<<'\n';
}

Measured memory_bytes: 32464
import java.util.*;
import static java.lang.System.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		while (sc.hasNext()) {
			
			int n = sc.nextInt();
			int x = sc.nextInt();
			if (n == 0) {break;}
			int num = 0;
			for (int i=1; i<=n; i++) {
				for (int j=i+1; j<=n; j++) {
					for (int k=j+1; k<=n; k++) {
						if (i!=j && j!=k && i!=k) {
							if (i+j+k == x) {num++;}
						}
					}
				}
			}
			out.println(num);
			
			
		}
	}
}


Measured memory_bytes: 26696
package main

import (
	"fmt"
)

func main() {
	var N, W int
	fmt.Scan(&N, &W)

	weight := make([]int, N)
	value := make([]int64, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&weight[i], &value[i])
	}

	dp := make([][]int64, 1+N)
	for i := 0; i <= N; i++ {
		dp[i] = make([]int64, 1+W)
	}

	for i := 0; i < N; i++ {
		for w := 0; w <= W; w++ {
			if dp[i+1][w] < dp[i][w] {
				dp[i+1][w] = dp[i][w]
			}
			if w+weight[i] <= W && dp[i+1][w+weight[i]] < dp[i][w]+value[i] {
				dp[i+1][w+weight[i]] = dp[i][w] + value[i]
			}
		}
	}

	fmt.Println(dp[N][W])
}


Measured memory_bytes: 81792
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 13 17:57:26 2018


A以上B以下の回文数が何個あるか計算する
例) １１２１１

入力
11009 11332

出力
4


@author: Yuya
"""

A, B = map(int,input().split())

count = 0

for a in range(1, 10):
    for b in range(10):
        for c in range(10):
            N = 10000*a + 1000*b + 100*c + 10*b + a
            if N >= A and N <= B:
                count = count + 1

print(count)

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

using namespace std;

int main() {

	string s;
	cin >> s;

	vector<int> ss;

	int c = 1;

	for (int i = 1; i < s.size(); i++) {
		if (s[i] == s[i - 1]) {
			c++;
		}
		else {
			ss.push_back(c);
			c = 1;
		}
	}
	ss.push_back(c);

	int szs = s.size();

	int mid = s.size();
	mid /= 2;
	if (szs % 2 != 0) {
		mid++;
	}
	int a1 = 0;

	for (int i = 0; i < ss.size(); i++) {
		if (a1 < mid) {
			a1 += ss[i];
		}
		else {
			break;
		}
	}

	int a2 = 0;
	int sz = ss.size();
	for (int i = sz - 1; i >= 0; i--) {
		if (a2 < mid) {
			a2 += ss[i];
		}
		else {
			break;
		}
	}

	cout << min(a1, a2) << endl;

	return 0;
}

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

#define BUF_SIZE 25

int calc_digit_sum(int num) {
  int ans = 0;
  while(num) {
    ans += (num%10);
    num /= 10;
  }
  return ans;
}

int main(void) {
  FILE* fp = stdin;
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, fp)) return 0;

  int num, lower, upper;
  sscanf(line, "%d %d %d", &num, &lower, &upper);

  int i;
  int res = 0;
  for(i = 1; i <= num; i++) {
    int d = calc_digit_sum(i);
    if(lower <= d && upper >= d) res += i;
  }
  printf("%d\n", res);

  return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
  string s; cin >> s;
  int pA = 0, pZmax = 0, flag = 0;
  for(int i=0;i<s.size();i++){
    if(flag == 0 && s[i] == 'A'){
      pA = i;
      flag++;
    }
    if(s[i] == 'Z') pZmax = i;
  }
  cout << pZmax - pA + 1 << endl;
  return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>


typedef long long ll;
const double Eps = 1e-6;

using namespace std;

pair<int, int> p[10000];
struct Sorter
{
	bool operator()(const pair<int, int>& a, const pair<int, int>& b)
	{
		return a.first > b.first || a.first == b.first && a.second < b.second;
	}
};
int main()
{
	int n;
	while (scanf("%d", &n), n)
	{
		for (int i = 0; i < n; ++i)
		{
			int no;
			scanf("%d", &no);

			int total = 0;
			int W = 0;
			int a, b;
			for (int f = 1; f <= 10; ++f)
			{
				scanf("%d", &a);
				total += a;
				if (W)
				{
					total += a * (W % 10);
					W /= 10;
				}
				if (a == 10 && f != 10)
				{
					W += 11;
					continue;
				}

				scanf("%d", &b);
				total += b;
				if (W)
				{
					total += b;
					W /= 10;
				}
				if (a + b == 10)
					++W;
			}
			if (a == 10 || a + b == 10)
			{
				int c;
				scanf("%d", &c);
				total += c;
			}
			p[i] = make_pair(total, no);
		}
		sort(p, p+n, Sorter());
		for (int i = 0; i < n; ++i)
			printf("%d %d\n", p[i].second, p[i].first);
	}

	return 0;
}

Measured memory_bytes: 0
a, b, c, d = map(int,input().split())

x = c - a
y = d - b

z = []
z += y * 'U'
z += x * 'R'
z += y * 'D'
z += (x + 1) * 'L'
z += (y + 1) * 'U'
z += (1 + x) * 'R'
z += 'D'
z += 'R'
z += (y + 1) * 'D'
z += (1 + x) *'L'
z += 'U'

print(''.join(z))

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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
    ll N;
    cin >> N;
    ll ans = N*(N-1)/2;
    print(ans);
}

signed main() {
    solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int answer = 1e9;
int c[40];
vector<int> g[40];
int n,m;

void dfs(int x,long long bit,int cost){
	long long before = bit;
	// self
	if( !(bit >> x&1) ){
		cost += c[x];
		bit |= (1ll<<x);
	}
	// other
	for( auto i : g[x] ){
		if( !(bit >> i & 1) ){
			bit |= (1ll<<i);
			cost += c[i];
		}
	}
	// branch-cut
	if( cost >= answer ) return;
	if( x == n - 1 ){
		answer = cost;
		return;
	}

	for( auto i : g[x] ){
		if( (before >> i & 1) == 0 ) dfs(i,bit,cost);
	}
}

int main(){
	cin >> n >> m;
	for(int i = 0 ; i < n ; i++){
		cin >> c[i];
	}
	for(int i = 0 ; i < m ; i++){
		int a,b;
		cin >> a >> b;
		--a,--b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(0,0,0);
	cout << answer << endl;


}

Measured memory_bytes: 3152
#include<iostream>
using namespace std;
int main(){
  int h,w;
  while(cin >> h >> w && h||w){
    for(int j=0;j<w;j++) cout << "#";
    cout << endl;
    for(int i=1;i<h-1;i++){
      cout << "#";
      for(int j=1;j<w-1;j++) cout << ".";
      cout << "#" << endl;
    }
    for(int j=0;j<w;j++) cout << "#";
    cout << endl << endl;
  }
}


Measured memory_bytes: 3100
a,b,m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [list(map(int, input().split())) for _ in range(m)]
ans = min(a) + min(b)
for i in range(m):
    ans = min(ans, a[c[i][0]-1]+b[c[i][1]-1]-c[i][2])
print(ans)

Measured memory_bytes: 38484
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

signed main() {
	int N, D; ll A;
	cin >> N >> D >> A;
	vector<pair<int, ll>> xh(N);
	for (int i = 0; i < N; ++i)
		cin >> xh[i].first >> xh[i].second;
	sort(xh.begin(), xh.end());
	vector<int> x(N); vector<ll> h(N);
	for (int i = 0; i < N; ++i) {
		x[i] = xh[i].first;
		h[i] = xh[i].second;
	}
	vector<ll> imos(N + 1, 0); // 何回攻撃したかをimosで管理
	int left = 0;
	ll res = 0;
	ll att = 0;
	while (true) {
		// 攻撃する最も右端のモンスターの一個右
		int right = upper_bound(x.begin(), x.end(), x[left] + 2 * D) - x.begin();
		// 攻撃する
		ll dam = h[left] - att * A;
		ll att_add = dam / A + (dam % A ? 1 : 0);
		att += att_add;
		res += att_add;
		imos[right] -= att_add;
		while (left < N && h[left] <= att * A)
			att += imos[++left];
		if (left == N) break;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef char chr;
typedef double  dbl;
typedef long long int lld;
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main (){
    FastIO
    string s;
    cin >> s;
    lld q, i;
    lld f, T;
    cin >> q;
    f = 0;
    lld c;
    c = 0;
    vector <chr> A,B;
    for(i = 0; i<q;){
    	cin >> T;
    	if (T ==  1){
    		if (f == 0)
    			f =  1;
    		else
    			f =  0;
    		c+= 1;
    	}
    	else{
    		lld F;
    		chr r;
    		cin  >>  F;
    		cin  >>  r;
    		if (F == 1){
    			if (f == 0){
    				A.push_back(r);
    			}
    			else{
    				B.push_back(r);
    			}
    		}
    		else{
    			if (f == 0){
    				B.push_back(r);
    			}
    			else{
    				A.push_back(r);
    			}
    		}
    	}
    	i+= 1;
    }
	if (c % 2 == 0){
		for(i = A.size()-1; i>=0;i-=1){
    		cout << A[i];
    	}
    	cout << s;
		for(i = 0; i<B.size(); i += 1){
			cout << B[i];
		}
	}
	else{
		for(i = B.size()-1; i>=0;i-=1){
			cout << B[i];
		}
		lld n =s.length();
		for(i = n - 1; i >= 0; i -= 1){
			cout <<  s[i];
		}
		for(i = 0; i<A.size(); i += 1){
    		cout << A[i];
    	}
	}
    return 0;
}

Measured memory_bytes: 976
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int H1 = in.Int();
            int M1 = in.Int();
            int H2 = in.Int();
            int M2 = in.Int();
            int K = in.Int();

            if (H1 > H2 || H1 == H2 && M1 > M2) {
                H2 += 24;
            }
            int KH = H2 - H1;
            int KM = M2 - M1;
            KH -= K / 60;
            KM -= K % 60;
            while (KM < 0) {
                KH--;
                KM += 60;
            }
            out.println(KH * 60 + KM);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    return null;
                }
            }
            return st.nextToken();
        }

        public int Int() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 32656
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define DEBUG
#ifdef DEBUG
#define debug_printf printf
#else
#define debug_printf 1 ? 0 : printf
#endif

using namespace std;
typedef long long int ll;
typedef vector<ll> Vl;
typedef vector<int> Vi;
typedef pair<int, int> Pi;

#define INF   (1e9 + 7)
#define MAX_N (100000)

int N;
char S[MAX_N + 1];

char guess(char x, char y, char a) {
  return (y == 'S') ^ (a == 'o') ^ (x == 'S') ? 'S': 'W';
}

void solve() {
  char prefs[4][3] = {"SS", "SW", "WS", "WW"};
  char ans[N + 1];
  for (int i = 0; i < 4; i++) {
    ans[0] = prefs[i][0]; ans[1] = prefs[i][1];
    for (int j = 2; j < N; j++) {
      ans[j] = guess(ans[j - 2], ans[j - 1], S[j - 1]);
    }
    bool valid = (ans[0] == guess(ans[N - 2], ans[N - 1], S[N - 1])) && (ans[1] == guess(ans[N - 1], ans[0], S[0]));
    if (valid) {
      ans[N] = '\0';
      printf("%s\n", ans);
      return;
    }
  }
  printf("-1\n");
}

int main() {
  scanf("%d", &N);
  scanf("%s", S);

  solve();

  return 0;
}


Measured memory_bytes: 512
// https://atcoder.jp/contests/abc063/tasks/abc063_a
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

#define FOR(i, n) for (int i = 0; i < n; i++)
#define EACH(i, n) for (auto &i: n)

int main() {
  int a, b;
  cin >> a >> b;
  if (a + b >= 10) {
    cout << "error" << endl;
  } else {
    cout << a + b << endl;
  }

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            StringBuilder sb = new StringBuilder();
            sb.Append(n + ":");

            if (n < 2) sb.Append(" " + n);

            while (n % 2 == 0)
            {
                n /= 2;
                sb.Append(" " + 2);
            }

            for (int i = 3; i <= n; i += 2)
            {
                while (n % i == 0)
                {
                    n /= i;
                    sb.Append(" " + i);
                }
            }

            Console.WriteLine(sb);
        }
    }
}

Measured memory_bytes: 9232
from itertools import accumulate
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
mod = 10**9+7
dp = [0]*(N+1)
dp[0] = 1
for i, t in enumerate(T, 1):
    dp2 = dp[:]
    for i in range(1, N+1):
        dp2[i] = (dp2[i-1] + dp2[i]) % mod
    for j, s in enumerate(S, 1):
        if s == t:
            dp[j] += dp2[j-1]
ans = 0
for d in dp:
    ans = (ans + d) % mod
print(ans)

Measured memory_bytes: 42716
// by batr (TBhero.17)                      
// This will be Accepted!
 
#include <bits/stdc++.h>
 
#define jyldam ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
 
#define pb push_back
#define mp make_pair
 
#define B begin()
#define E end()
#define sz size()
#define skip continue
#define all(x) (x).begin(), (x).end()
 
#define F first
#define S second          
 
#define st(x) st+=x
#define pli pair<long long, int>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;     
 
const int N = 2e5 + 17, M = N * 4, D = 2e3 + 17, mod = 1e9 + 7;
const ll INF = 1e17 + 17;
 
int tt = 1;
map <char, ll> u;           
string s;
int n;
   
void solve () {
			cin >> n >> s;
			for (int i = 0; i < n; i++) {
					u[s[i]]++;		
			}
			ll ans = 1;
			string alph = "abcdefghijklmnopqrstuvwxyz";	
			for (int i = 0; i < alph.sz; i++) {
					ans *= (u[alph[i]] + 1);
					ans %= mod;
			}
			cout << ans - 1;
}   
		    
int main() {
		jyldam;
						                  
		while (tt--) {   
			solve();
		}
   	
		return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main() {
    
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    
    if(abs(a-c)<=d){
        printf("Yes\n");
    }else{
        if((abs(a-b)<=d)&&(abs(b-c)<=d)){
            printf("Yes\n");
        }else{
            printf("No\n");
        }
        
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//






int main(void) {

    int n; cin >> n;
    vector <int> D(n);
    rep(i,n) cin >> D[i];
    Sort(D);
    int m; cin >> m;
    vector <int> T(m);
    rep(i,m) cin >> T[i];
    Sort(T);

    int d_idx = 0;    int t_idx = 0;
    while (1) {
        if (d_idx >= n || t_idx >= m) break;
        else if (D[d_idx] == T[t_idx]) {
            ++d_idx;
            ++t_idx;
        }
        else ++d_idx;
    }

    if (t_idx == m) {
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;




    return 0;
}









Measured memory_bytes: 1792
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
# import statistics
import bisect
import copy
import fractions
import math
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers):
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))
def unite(x, y):
    # それぞれのノードの根を求める
    x = root(x)
    y = root(y)
    if x == y:
        return
    # node[x]の根をyに変更する
    node[x] = y
def same(x,y): return bool(root(x) == root(y))
def root(x):
    if node[x] == x:  # xが根の場合
        return x
    else:
        node[x] = root(node[x])  # 経路圧縮
        return node[x]
def dfs(v):
    # ノードに訪れた
    visited[v] = True
    for v2 in range(n):
        if graph[v][v2] == False:  # そもそもvとv2が辺でつながっていない
            continue
        if visited[v2] == True:  # もう見た
            continue
        dfs(v2)

print(LCM(2, II()))


Measured memory_bytes: 64492
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 1000009 /// leave to tomorrow anything that can be done today
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e17 + 9;
int cont[maxn];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    memset(cont,0,sizeof cont);
    ll n;
    cin>>n;
    int vet[200009];
    rep(i,0,n){
        cin>>vet[i];
        cont[vet[i]]++;
    }
    int ans=0;
    rep(i,0,n){
        cont[vet[i]]--;
        bool can=true;
        rep(j,1,sqrt(vet[i])+1){
            if(vet[i]%j==0){
                if(cont[j]>0 || cont[vet[i]/j]>0)can=false;
            }
        }
        if(can)ans++;
        cont[vet[i]]++; 
    }
    cout<<ans<<'\n';
    return 0;   
}   

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

int solve(int N, vector<int>& T, vector<int>& L) {
  constexpr int R = 1 << 16;
  int res = L[0];
  vector<vector<int>> dp(N, vector<int>(R, 0));
  for(int S = 0; S < R; S++) {
    if((S & T[0]) == T[0]) {
      dp[0][T[0]] = L[0];
    }
  }
  for(int i = 1; i < N; i++) {
    for(int S = 0; S < R; S++) {
      dp[i][S] = dp[i - 1][S];
      if((S & T[i]) == T[i]) {
	dp[i][S] = max(dp[i][S], L[i] + dp[i - 1][S & (~T[i])]);
	res = max(res, dp[i][S]);
      }
    } 
  }
  return res;
}

int main() {
  int N;
  while(cin >> N, N != 0) {
    vector<int> L(N);
    vector<int> T(N);
    for (int i = 0; i < N; i++) {
      int M;
      cin >> M >> L[i];
      int t = 0;
      for(int j = 0; j < M; j++) {
	int s, e;
	cin >> s >> e;
	for (int k = s; k < e; k++) t |= 1 << k-6;
      } 
      T[i] = t;
    }
    cout << solve(N, T, L) << endl;
  }
}


Measured memory_bytes: 28632
#include<bits/stdc++.h>
#define endl "\n"
#define ll long long 
#define F first
#define end 1000000000
#define S second
#define pb push_back
#define mp make_pair
using namespace std;

int main()
{
  string a,b;
  cin >> a >> b;
 
  for(ll i=0;i<b.length();i++)
  {
      cout << b[i];
  }
  for(ll i=0;i<a.length();i++)
  {
      cout << a[i];
  }
  
  
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int K; cin >> K;
    int X, Y; cin >> X >> Y;
    int d = abs(X) + abs(Y);
    if (K % 2 == 0 && d % 2 == 1){
        cout << -1 << endl;
        return 0;
    }
    if (d % K == 0) {
        int cnt = d / K;
        cout << cnt << endl;
        int x = 0, y = 0;
        rep(i, cnt - 1) {
            int prevx = x;
            if (X >= 0)
                x += abs(x - X)/(cnt - i);
            else
                x -= abs(x - X)/(cnt - i);
            if (Y >= 0)
                y += K - abs(x - prevx);
            else
                y -= K - abs(x - prevx);
            cout << x << " " << y << endl;

        }
        cout << X << " " << Y << endl;
        return 0;
    }
    int move_c = (d + K - 1)/K;
    if (move_c == 1) move_c++;
    if (d % 2 != move_c * K % 2) move_c++;
    int move_d = move_c * K;
    int loss = (move_d - d)/2;
    int lossX, lossY;
    if (abs(X) < abs(Y)) {
        lossX = min(K, min(loss, (move_d - abs(X))));
        lossY = loss - lossX;
    } else {
        lossY = min(K, min(loss, (move_d - abs(Y))/2));
        lossX = loss - lossY; 
    }
    
    cout << move_c << endl;
    // cout << move_d << " " << loss << endl;
    // cout << lossX << " " << lossY << endl;
    int x = 0, y = 0;
    rep(i, move_c - 1) {
        if (lossX > lossY && lossX > 0) {
            if (X > x)
                x -= min(K, lossX);
            else
                x += min(K, lossX);
            if (Y > y)
                y += K - min(K, lossX);
            else 
                y -= K - min(K, lossX);
            lossX -= min(K, lossX);
        }
        else if (lossY >= lossX && lossY > 0 ) {
            if (Y > y)
                y -= min(K, lossY);
            else 
                y += min(K, lossY);
            if (X > x) 
                x += K - min(K, lossY);
            else 
                x -= K - min(K, lossY);
            lossY -= min(K, lossY);
        } else {
            int prevx = x;
            if (X >= 0)
                x += min(K, abs(x - X));
            else
                x -= min(K, abs(x - X));
            if (Y >= 0)
                y += K - abs(x - prevx);
            else
                y -= K - abs(x - prevx);
        }
        cout << x << " " << y << endl;
    }
    cout << X << " " << Y << endl;


    


    return 0;
}


Measured memory_bytes: 2304
#include <stdio.h>

int main(){

  int A, B, C, D, P, X, Y;

  scanf("%d %d %d %d %d", &A, &B, &C, &D, &P);

  X = A * P;

  if(P <= C)

    Y = B;

  else if(P > C)

    Y = B + (P - C) * D;

  if(X < Y)

    printf("%d\n", X);

  else

    printf("%d\n", Y);

  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define INF (int)1e9+1
#define INFLL (int)1e18+1
#define sz(bb) (int)bb.size()
#define all(qq) qq.begin(), qq.end() 
#define Max(a, b, c) max(a, max(b, c))
#define Min(a, b, c) min(a, min(b, c))
const double PI=acos(-1);
// #define int unsigned long long int//used when x<2^64-1 && x>0
#define int long long//used when x<2^63-1
//bool cmp if returns true it keeps 1st as first else swaps
typedef long long  ll;

const int N=1000001;
void solve()
{
    int n, k;
    cin>>n>>k;
    int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    sort(arr, arr+n);
    int ans=0;
    int cnt=0;
    for(int i=0;i<n;i++)
    {
        if(cnt==k)
            break;
        ans+=arr[i];
        cnt++;
    }
    cout<<ans<<"\n";
}
int32_t main()
{
    IOS;
    int t;
    // cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}

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

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> a(H, vector<char>(W));
    rep(i,H) rep(j,W) cin >> a.at(i).at(j);
    rep(i,H+2) rep(j,W+2) {
        if (i == 0 || i == H + 1 || j == 0 || j == W + 1) {
            cout << '#';
        } else cout << a.at(i-1).at(j-1);
        if (j == W + 1) cout << endl;
    }
}


Measured memory_bytes: 3568