akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  
  int n,m;
  cin>>n>>m;
  long long x[n],y[n],z[n];
  REP(i,n){
    cin>>x[i]>>y[i]>>z[i];
  }
  
  long long ans=0;
  vector<long long> arr(n);
  long long temp;
  for(int k=0;k<(1<<3);k++){
    REP(i,n){
      arr[i] = 0;
      if((k>>2) & 1){
        arr[i] += x[i];
      }else{
        arr[i] -= x[i];
      }
      if((k>>1) & 1){
        arr[i] += y[i];
      }else{
        arr[i] -= y[i];
      }
      if(k & 1){
        arr[i] += z[i];
      }else{
        arr[i] -= z[i];
      }
    }
    sort(arr.begin(),arr.end(),greater<long long>());
    temp = 0;
    REP(i,m){
      temp += arr[i];
    }
    ans = max(ans,temp);
  }
  
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
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() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  string s;
  cin >> s;
  int c = 0, n = s.size();
  rep(i, 1, n) {
    if ((s[i] == 'W' && s[i - 1] == 'B') || (s[i] == 'B' && s[i - 1] == 'W'))
      c++;
  }
  cout << c << endl;
}


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

int main()
{
	int x, n, t ;
	cin >> x >> n ;
	
	const int maxN = 301 ;
	const int off = 100 ;

	vector<bool> mask(maxN, true);
	while(n--)
	{
		cin >> t ;
		mask[t+off] = false ;
	}
	
	for(int i = 0; i <= 100; ++i)
	{
		if(mask[x+off-i])
		{
			cout << x - i << '\n' ;
			break ;
		}
		if(mask[x+off+i])
		{
			cout << x + i << '\n' ;
			break ;
		}
	}
}


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

Measured memory_bytes: 596
#include <stdio.h>

int main() {
    int n, k, x, y;
    int ans = 0;

    scanf("%d", &n);
    scanf("%d", &k);
    scanf("%d", &x);
    scanf("%d", &y);

    if (n > k) {
        ans = k * x + (n - k) * y;
    } else {
        ans = n * x;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

int solve(int A[], int n, int m, int i){
    if(m == 0) return 1;
    else if(n == i) return 0;
    int res = solve(A, n, m, i + 1) || solve(A, n, m - A[i], i + 1);
    return res;
}

int main(){
    int n, i, q, m;
    scanf("%d", &n);
    int A[n];
    for(i = 0; i < n; i++){
        scanf("%d", &A[i]);
    }
    scanf("%d", &q);
    for(i = 0; i < q; i++){
        scanf("%d", &m);
        if(solve(A, n, m, 0)) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}


Measured memory_bytes: 2112
#include <cstdio>
#include <cstring>
const int MaxN = 1e5;
using namespace std;

int ind[MaxN + 5];
int n , m;
int main()
{
	while(~scanf("%d%d" , &n, &m)){
		for(int i = 1;i <= m;i++){
			int u ,  v;
			scanf("%d%d" , &u , &v);
			ind[u]++;
			ind[v]++;
		}
		for(int i = 1;i <= n;i++){
			printf("%d\n" , ind[i]);
		}
	}
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define TRACE
#define M 1000000007
#define oo 1000000000000000007
#define F first
#define S second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
#define pb push_back
#define M6 1000009
#define M5 500009
#define pi 3.14159265
#define epsilon 1e-6

#ifdef TRACE
    #define trace1(x)                cerr << #x << ": " << x << endl;
    #define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
    #define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
    #define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
    #define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
    #define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
 
#else
 
    #define trace1(x)
    #define trace2(x, y)
    #define trace3(x, y, z)
    #define trace4(a, b, c, d)
    #define trace5(a, b, c, d, e)
    #define trace6(a, b, c, d, e, f)
 
#endif
ll power(ll x,ll n,ll m){
    ll res=1;
    while(n>0){
        if(n&1) res=(res*x)%m;
        n/=2;
        x=(x*x)%m;
    }
    return res;
}

ll n,m,A[M5];
int  main()
{   //ios_base::sync_with_stdio (0), cin.tie (0);
    //sieve();
    //init();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll tc=1,t=0,i,j,k,a,b,c,d,l,r;
    //cin>>tc;
    while(t++<tc){
        //cout<<"Case #"<<t<<": ";
        cin>>n;
        string s;
        cin>>s;
        if(n>=3200) cout<<s;
        else cout<<"red";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int h,w;
    cin>>h>>w;
    std::vector<vector<char>> vec(h+2,vector<char>(w+2));
    char c;
    for (int i=0;i<h+2;i++) {
        for (int j=0;j<w+2;j++) {
            if (i==0||j==0||i==h+1||j==w+1) {
                vec.at(i).at(j)='.';
            } else {
                cin>>c;
                vec.at(i).at(j)=c;
            }
        }
    }
    int flag=0;
    /*
    for (int hoge=0;hoge<h+2;hoge++) {
        for (int piyo=0;piyo<w+2;piyo++) {
            cout<<vec.at(hoge).at(piyo);
        }
        cout<<endl;
    }*/
    for (int k=1;k<=h;k++) {
        for (int l=1;l<=w;l++) {
            if (vec.at(k).at(l)=='#') {
                if (vec.at(k-1).at(l)=='.'&&vec.at(k+1).at(l)=='.'&&vec.at(k).at(l-1)=='.'&&vec.at(k).at(l+1)=='.') {
                    flag=1;
                    break;
                }
            }
        }
        if (flag==1) {
            cout<<"No"<<endl;
            break;
        }
    }
    if (flag==0) {
        cout<<"Yes"<<endl;
    }
}

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

#define rep(i, N) for (int i = 0; i < N; ++i)

using namespace std;

int main() {
    int n, q, key;
    scanf("%d", &n);
    vector<int> S(n);
    rep(i, n) scanf("%d", &S[i]);

    int ans = 0;
    scanf("%d", &q);
    for (int i = 0; i < q; ++i) {
        scanf("%d", &key);
        for (int j = 0; j < S.size(); ++j) {
            if (S[j] == key) {
                ++ans;
                break;
            }
        }
    }

    printf("%d\n", ans);
    return 0;
}



Measured memory_bytes: 2736
import java.util.*
fun main(args: Array<String>) {
    val reader = Scanner(System.`in`)
    val N = reader.nextInt()
    var resultMap = mutableMapOf<String, Int>()
    repeat(N){
        val result = reader.next()
        val currentCnt = resultMap.getOrDefault(result, 0)
        resultMap.put(result, currentCnt + 1)
    }
    listOf<String>("AC", "WA", "TLE", "RE").forEach {
        println("${it} x ${resultMap.getOrDefault(it, 0)}")
    }
}

Measured memory_bytes: 59808
#include<iostream>
#include<cmath>
#include<stack>
#include<algorithm>
using namespace std;

int main(){
  int n,m,b[1000],x[1000],y[1000],s,g;
  double dis[1001][1001];
  int route[1001][1001];

  while(1){
    cin >> n;
    if(!n)break;

    for(int i=0;i<n;i++)cin >> b[i] >> x[i] >> y[i];

    for(int i=0;i<n;i++){
      for(int j=i;j<n;j++){
	double d = sqrt( (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]) );
	if(d>50.0)dis[b[i]][b[j]] = 1e+10;
	else dis[b[i]][b[j]] = d;
	dis[b[j]][b[i]] = dis[b[i]][b[j]];
	route[b[i]][b[j]] = b[i];
	route[b[j]][b[i]] = b[j];
      }
    }

    for(int k=1;k<=n;k++){
      for(int i=1;i<=n;i++){
	for(int j=1;j<=n;j++){
	  if(dis[i][j] > dis[i][k] + dis[k][j]){
	    dis[i][j] = dis[i][k] + dis[k][j];
	    route[i][j] = route[k][j];
	  }
	}
      }
    }
 
    cin >> m;
    for(int i=0;i<m;i++){
      cin >> s >> g;
      if(dis[s][g] >= 1e+10)cout << "NA" << endl;
      else{
	stack<int> a;
	while(s!=g){
	  a.push(g);
	  g = route[s][g];
	}
	cout << s;
	while(a.size()){
	  cout << " " << a.top();
	  a.pop();
	}
	cout << endl;
      }
    }
  }
}

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

#define pb emplace_back
#define fi first
#define se second
#define m_p make_pair
#define vi vector<int>
#define pi pair<int, int>
#define mem(a,b) memset(a,b,sizeof(a))
#define el cout<<endl
#define sz(a) (int)a.size()
const int mod = (int)1e9+7;
typedef long long int ll;

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N = (int)1e5+5;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	ll n,d;
	cin>>n>>d;
	int cnt=0;
	for(int i=0;i<n;i++){
		ll x1,y1;
		cin>>x1>>y1;
		if(x1*x1 + y1*y1 <= d*d) cnt++;
	}
	cout<<cnt;el;
}

ll power(ll a,ll b, ll md=mod){
	ll r=1;
	while(b){
		if(b%2) 
			r=(r*a)%md;
		a=(a*a)%md;
		b>>=1;
	}
	return r;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define INF 0x7fffffff
typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<ld> vld;

#define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()

vll make_cycle(vb vis, vll p, vll c, int i)
{
	vll v;
	ll sum = 0;

	while(!vis[i]) 
	{
		vis[i] = true;
		sum += c[p[i]];
		v.pb(sum);
		i = p[i];
	}
	return v;
}

int main()
{
	fastIO;
	ll n, k, ans = -1e18; cin >> n >> k;
	vll p(n), c(n);
	for(int i = 0; i < n; i++) cin >> p[i], p[i]--;
	for(int i = 0; i < n; i++) cin >> c[i];

	vb vis(n,false);
	for(int i = 0; i < n; i++)
	{
		vll cycle = make_cycle(vis,p,c,i);

		if(cycle.back() > 0 && k >= (ll)cycle.size())
		{
			ll cnt = k / (ll)cycle.size();
			ll mod = k % (ll)cycle.size();
			ll temp = -1e18;

			for(int j = 0; j < cycle.size(); j++)
				if(temp < cycle[j])
					temp = cycle[j];

			temp += (cnt - 1)*cycle.back();
			if(ans < temp) ans = temp;

			temp = -1e18;
			for(int j = 0; j < mod; j++)
				if(temp < cycle[j])
					temp = cycle[j];

			temp += cnt*cycle.back();
			if(ans < temp) ans = temp;
		}

		else
		{
			for(int j = 0; j < cycle.size() && j < k; j++)
				if(ans < cycle[j])
					ans = cycle[j];
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3924
import sys
import numpy as np
import numba
from numba import jit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@jit
def main(s):
  ans = 0
  for j, i in enumerate(s):
    if i=='A' or i=='C' or i=='G' or i=='T':
      cnt = 1
      j += 1
      while s[j]=='A' or s[j]=='C' or s[j]=='G' or s[j]=='T':
        j += 1
        cnt += 1
      ans = max(ans, cnt)
  return ans
        
s = str(readline().split())
print(main(s))

Measured memory_bytes: 117196
#include <algorithm>
#include <array>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <vector>
using namespace std;

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

typedef array<int, 2> A;
typedef pair<A, A> E;
typedef unsigned hash_t;

hash_t rolling_hash(const string &s) {
	static constexpr hash_t base = 1000000007;
	hash_t res = 0;
	for(const auto &c : s) {
		res = res * base + c;
	}
	return res;
}
 
string to_str(const vector<string> &state) {
	string res = "";
	for(const auto &s : state) {
		res += s + ":";
	}
	return res;
}
 
unordered_map<hash_t, int> bfs(int limit, const vector<string> &start, const vector<E> &exchanges) {
	unordered_map<hash_t, int> res;
	queue<vector<string>> que;
 
	res.insert({rolling_hash(to_str(start)), 0});
	que.push(start);
 
	while(!que.empty()) {
		vector<string> state = que.front();
		que.pop();
		const int d = res.at(rolling_hash(to_str(state)));
 
		if(d == limit) break;
 
		for(const auto &element : exchanges) {
			const A &pos = element.first;
			const A &dir = element.second;
			const array<string, 2> train{move(state[pos.front()]), move(state[pos.back()])};

			for(int i = 0; i <= 1; ++i) {
				const int from = i;
				const int to = 1 - i;

				const int &p1 = pos[from];
				const int &p2 = pos[to];
				const int &d1 = dir[from];
				const int &d2 = dir[to];
				const string &t1 = train[from];
				const string &t2 = train[to];

				for(int num = 1; num <= t1.size(); ++num) {
					string tmp = (d1 ? t1.substr(0, num) : t1.substr(t1.size() - num));
					if(d1 == d2) reverse(tmp.begin(), tmp.end());
					state[p1] = (d1 ? t1.substr(num) : t1.substr(0, t1.size() - num));
					state[p2] = (d2 ? tmp + t2 : t2 + tmp);
 
					const hash_t h = rolling_hash(to_str(state));
					if(!res.count(h)) {
						res.insert({h, d + 1});
						que.push(state);
					}
				}
			}
 
			state[pos.front()] = move(train.front());
			state[pos.back()] = move(train.back());
		}
	}
 
	return res;
}
 
int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
 
	for(int x, y; cin >> x >> y && x;) {
		vector<E> exchanges;
		exchanges.reserve(y);
 
		for(int i = 0; i < y; ++i) {
			string a, b;
			cin >> a >> b;
 
			const int p1 = a[0] - '0';
			const int d1 = (a[1] == 'W');
			const int p2 = b[0] - '0';
			const int d2 = (b[1] == 'W');
 
			exchanges.emplace_back(A{p1, p2}, A{d1, d2});
		}
 
		vector<string> lines(x), goal(x);
 
		for(auto &e : lines) {
			cin >> e;
			if(e == "-") e = "";
		}
 
		for(auto &e : goal) {
			cin >> e;
			if(e == "-") e = "";
		}
     
		const auto d1 = bfs(3, lines, exchanges);
		const auto d2 = bfs(2, goal, exchanges);
 
		int ans = 6;
		for(const auto &e1 : d2) {
			if(ans <= e1.second) continue;
 
			if(d1.count(e1.first)) {
				chmin(ans, e1.second + d1.at(e1.first));
			}
		}
 
		cout << ans << endl;
	}
 
	return EXIT_SUCCESS;
}

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

int main(){

    int n;
    double sum=0;
    cin>>n;
    for(int i=0;i<n;i++){
        double x; string u;
        cin>>x>>u;
        if(u=="JPY") sum+=x;
        else sum+=x*380000.0;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <limits.h>
#include <utility>
#include <cmath>
#include <string>

using namespace std;

int main()
{
  int N;
  cin >> N;

  double sum = 0;
  
  for (int n=0; n<N; ++n) {
    double x;
    string u;
    cin >> x >> u;

    sum += ((u=="JPY") ? x : x*380000);
  }
  
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
h, w = [int(i) for i in sys.stdin.readline().split()]
a_dict = dict()
for i in range(h):
    a_dict[i] = [int(i) for i in sys.stdin.readline().split()]
start = [0,0]
root = []
flg = True
while True:
    y, x = start
    if flg:
        if x + 1 >= w:
            if y + 1 >= h:
                break
            flg = False
            y += 1
        else:
            x += 1
    else:
        if x - 1 < 0:
            if y + 1 >= h:
                break
            y += 1
            flg = True
        else:
            x -= 1
    _next = [y, x]
    if a_dict[start[0]][start[1]] % 2 == 1:
        root.append([start[0] + 1, start[1] + 1, _next[0] + 1, _next[1] + 1])
        a_dict[start[0]][start[1]] -= 1
        a_dict[y][x] += 1
    start = _next
print(len(root))
for i in root:
    print(" ".join([str(j) for j in i]))

Measured memory_bytes: 69212
def answer(*inp):

    A = int(inp[0])
    B = int(inp[1])
    C = int(inp[2])
    X = int(inp[3])

    cnt = 0

    for a in range(A + 1):
        for b in range(B + 1):
            for c in range(C + 1):
                if ((500 * a) + (100 * b) + (50 * c)) == X:
                    cnt += 1

    print(cnt)

answer(input(), input(), input(), input())

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    vector<int> l;

    vector<int> ABC;

    void input() {

    }

    int sub(int bit) {
        vector<vector<int> > kouho(3);

        int idx = 0;
        while (bit > 0) {
            int tmp = bit % 4;
            if (tmp != 0) {
                kouho[tmp - 1].push_back(l[idx]);
            }
            idx++;

            bit /= 4;
        }

        if (kouho[0].size() * kouho[1].size() * kouho[2].size() == 0) return INF;

        int cost = 0;
        for (int i = 0; i < 3; ++i) {
            int tmp = 0;
            tmp += (kouho[i].size() - 1) * 10;
            int val = accumulate(all(kouho[i]), 0);
            int diff = abs(val - ABC[i]);
            tmp += diff;
            cost += tmp;
        }

        return cost;

    }

    void solve() {
        int N;
        cin >> N;
        ABC.resize(3);
        rep(i, 0, 3) cin >> ABC[i];
        l.resize(N);
        rep(i, 0, N) cin >> l[i];

        int max = (int) round(pow(4, N));

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

        cout << ans << endl;


    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111
	
	int dp[3100][3100];

	
	void solve(){

		ini(n);
		while (n--)
		{
			ins(morty);
			ins(morty1);
			FOR(i,0,morty.size()+1)
			FOR(i1,0,morty1.size()+1)
			dp[i][i1] = 0;

			FOR(i,0,morty.size()+1)
			FOR(i1,0,morty1.size()+1){
				if(morty[i] == morty1[i1]){
					dp[i+1][i1+1] = dp[i][i1]+1;
				}
				else{
					dp[i+1][i1+1] = max(dp[i][i1+1],dp[i+1][i1]);
				}
			}
			out(dp[morty.size()][morty1.size()]);
		}
		
		

		


		
		
	}























int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}



Measured memory_bytes: 15068
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.C
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var (X, K, D) = Read3Longs();
            var xabs = Math.Abs(X);
            var mod = xabs % D;
            var c = (xabs - mod) / D;
            if (c >= K)
            {
                return Math.Abs(X) - K * D;
            }
            if ((K - c) % 2 == 0)
            {
                return mod;
            }
            else
            {
                return Math.Abs(D - mod);
            }
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 28280
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2

using namespace std;

int MOD = 1000000007;

signed main(){
    string k;
    cin >> k;
    int wcnt = 0;
    int ans = 0;
    for(int i = 0;i < k.size();i++){
        if(k[i] == 'B'){
            
        }else{
            ans += i - wcnt;
            wcnt++;
        }
    }


    cout << ans << endl; 
      
   
    
    return 0;
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl 

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    string s,t;
    cin>>t;
    int n=t.size();
    for (int i = 0; i < n; i++)
    {
        if(t[i]=='?')
        {
            s+='D';
        }
        else
        {
            s+=t[i];
        }
    }
    cout<<s<<endl;
    /*
    int ans=0;
    int tmp=0;
    for (int i = 0; i < n; i++)
    {
        if(s[i]=='D')
        {
            tmp++;
        }
        else    //s[i]=='P'
        {
            if(i<n-1 && s[i+1]=='D')
            {
                tmp++;
            }
            else
            {
                ans=max(ans,tmp);
                tmp=0;
            }
        }
    }
    ans=max(ans,tmp);
    
    cout<<ans<<endl;
    */
    return 0;
}

Measured memory_bytes: 3864
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    double l;cin >> l;
    double a = l/3;
    cout << fixed << setprecision(6) << a*a*a << endl;
}


Measured memory_bytes: 256
def p_b():
    N = int(input())
    A = list(map(int, input().split()))
    A = [i - 1 for i in A]
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    ans = 0

    bf = -100
    for i in A:
        ans += B[i]
        if bf == i - 1:
            ans += C[i - 1]
        bf = i

    print(ans)


if __name__ == '__main__':
    p_b()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n,k;cin>>n>>k;
  map<int, int> mp;
  for(int i=0;i<n;i++){
    int a;cin>>a;
    mp[a]++;
  }
  vector<int> v;
  for (auto& kv : mp) {
    v.push_back(kv.second);
  }
  int m = mp.size();
  int left=(m-k);
  sort(v.begin(), v.end());
  int res=0;
  for(int i=0;i<left;i++){
    res += v[i];
  }
  cout<<res<<endl;

  return 0;
}


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

int main() {
  
  int A,B;
  cin >> A >> B;
  
  int i = 1;
  int socket = 1;
  
  while ( socket < B ){
    socket = 1 + A * i - i;
    i ++;
  }
  
  cout << i - 1 << endl;
  
}


Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))
tmp = 0
ans = 0
for i in range(N-1):
    if H[i] >= H[i+1]:
        tmp += 1
    else:
        ans = max(ans, tmp)
        tmp = 0
ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

int main(){
    int N, M;
    cin >> N >> M;
    ll x[N], y[M], dx[N-1], dy[M-1];
    rep(i, N) cin >> x[i];
    rep(i, M) cin >> y[i];
    rep(i, N-1) dx[i] = x[i+1] - x[i];
    rep(i, M-1) dy[i] = y[i+1] - y[i];
    ll sumx = 0, sumy = 0;
    rep(i, N-1){
        ll j = min(i, N-2-i);
        ll tmp = j*(j+1) + (j+1)*(N-1-2*j);
        tmp %= MOD;
        sumx += dx[i]*tmp%MOD, sumx %= MOD;
    }
    rep(i, M-1){
        ll j = min(i, M-2-i);
        ll tmp = j*(j+1) + (j+1)*(M-1-2*j);
        tmp %= MOD;
        sumy += dy[i]*tmp%MOD, sumy %= MOD;
    }
    cout << sumx*sumy%MOD << endl;
}

Measured memory_bytes: 3328
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        boolean[][] s = new boolean[n][m];
        for (int i = 0; i < m; i++) {
            int k = sc.nextInt();
            for (int j = 0; j < k; j++) {
                int a = sc.nextInt()-1;
                s[a][i] = true;
            }
        }
        int[] p = new int[m];
        for (int i = 0; i < m; i++) {
            p[i] = sc.nextInt();
        }
        int ans = 0;
        for (int i = 0; i < 1<<n; i++) {
            int[] b = new int[m];
            for (int j = 0; j < n; j++) {
                if((i>>j & 1) != 1) continue;
                for (int k = 0; k < m; k++) {
                    if(s[j][k]) b[k]++;
                }
            }
            boolean able = true;
            for (int j = 0; j < m; j++) {
                if(b[j]%2 != p[j]){
                    able = false;
                    break;
                }
            }
            if(able) ans++;
        }
        System.out.println(ans);
        sc.close();

    }

}


Measured memory_bytes: 23764
#define _CRT_SECURE_NO_WARNINGS
#define MOD 1000000007
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <bitset>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <functional>
#include <algorithm>
#include <iterator>
#include <cstdio>
#include <utility>
#include <unordered_map>
#include <cmath>
#include <chrono>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

typedef pair<ll, ll> P;
struct edge { ll to, cost; };

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

inline ll madd(ll a, ll b) {
	a %= MOD;b %= MOD;
	return (a + b) % MOD;
}
inline ll msub(ll a, ll b) {
	a %= MOD;b %= MOD;
	a += MOD;
	return (a - b) % MOD;
}
inline ll mmul(ll a, ll b) {
	a %= MOD;b %= MOD;
	return (a*b) % MOD;
}
inline ll mpow(ll a, ll r) {
	long long res = 1;
	while (r > 0) {
		if (r & 1) res = res * a % MOD;
		a = a * a % MOD;
		r >>= 1;
	}
	return res;
}
inline ll minv(ll a) {
	a %= MOD;
	ll b = MOD, u = 0, v = 1;
	while (a) {
		ll t = b / a;
		b -= t * a; swap(a, b);
		u -= t * v; swap(u, v);
	}
	if (u < 0) u += MOD;
	return u;
}
inline ll mdiv(ll a, ll b) {
	a %= MOD;
	a *= minv(b);
	return a%MOD;
}

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unite(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

//ll fact[100001], fact_inv[100001];
/*
ll combi(int a, int b) {
	return mmul(fact[a], mmul(fact_inv[b], fact_inv[a - b]));
}
*/
int main(void) {
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n),f(n);
	REP(i, n) cin >> a[i];
	REP(i, n) cin >> f[i];
	sort(a.begin(), a.end(),greater<ll>());
	sort(f.begin(), f.end());
	ll ok = 1000000000001, ng=-1;
	while (ok - ng > 1) {
		ll test = (ng + ok) / 2;
		ll cost = 0;
		REP(i,n){
			ll x = test/f[i];
			cost += max(0LL, a[i] - x);
		}
		if (cost <= k) ok = test;
		else ng = test;
	}
	cout << ok;
	return 0;
}

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

typedef long long ll;
const ll INF = 1e12;

int main() {
	ll n, ma, mb; cin >> n >> ma >> mb;
	vector<vector<ll>>dp(405, vector<ll>(405, INF));
	dp[0][0] = 0;
	for (ll k = 0, a, b, c; k < n; k++) {
		cin >> a >> b >> c;
		for (ll i = 404; i >= a; i--) {
			for (ll j = 404; j >= b; j--)dp[i][j] = min(dp[i][j], dp[i - a][j - b] + c);
		}
	}
	ll ans = INF;
	for (ll i = 1; i * max(ma, mb) < 405; i++) {
		ans = min(ans, dp[i * ma][i * mb]);
	}
	cout << (ans != INF ? ans : -1) << endl;

	return 0;
}

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

int main(){
	int h,w,l[51][51] = {0};
	char f[51][51] = {0};
	scanf("%d %d",&h,&w);
	for(int i = 0;i < h;i++){
		for(int j = 0;j <= w;j++){
			scanf("%c",&f[i][j]);
			if(f[i][j] == '#'){
				l[i][j] = 9999;
				l[i + 1][j]++;
				l[i + 1][j + 1]++;
				l[i + 1][j - 1]++;
				l[i - 1][j]++;
				l[i - 1][j + 1]++;
				l[i - 1][j - 1]++;
				l[i][j + 1]++;
				l[i][j - 1]++;
			}
//			printf("%c",f[i][j]);
		}
//		printf("\n");
	}
//		
	for(int i = 0;i < h;i++){
		for(int j = 1;j <= w;j++){
//			printf("%c",f[i][j]);
			if(l[i][j] >= 9999)
				printf("#");
			else
				printf("%d",l[i][j]);
		}
		printf("\n");
	}
	return 0;
}

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

int main(){
  char a[3];
  int b[3];
  cin >> a;
  for ( int i = 0 ;  i < 3 ; i++ ){
    b[i] = a[i] - '0';
  }
  int n=0;
  for ( int i = 0 ;  i < 3 ; i++ ){
    n+=b[i];
  }

  cout << n;
  return 0;
}

Measured memory_bytes: 3572
var n,x,i,j,t:Longint;
a:Array[1..100]of Longint;
begin
read(n,x);
for i:=1 to n do begin
read(a[i]);
for j:=i downto 2 do if a[j-1]>a[j]then begin
t:=a[j-1];a[j-1]:=a[j];a[j]:=t;
end;
end;
i:=1;
while(i<=n)and(x-a[i]>=0)do begin dec(x,a[i]);inc(i);end;
if i<=n then writeln(i-1)else if x>0 then writeln(n-1)else writeln(n);
end.

Measured memory_bytes: 128
import java.util.*;
public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		boolean[] arr = new boolean[n + 1];
		for(int i = 0; i < k; i++) {
			int count = sc.nextInt();
			for(int j = 0; j < count; j++) {
				arr[sc.nextInt()] = true;
			}
		}
		int res = 0;
		for(int i = 1; i <= n; i++) {
			if(!arr[i])
				res++;
		}
		System.out.println(res);
    }
}

Measured memory_bytes: 46512
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		int ansA=0;
		int ansB =0;
		for(int i=0;i<N;i++){
			A[i] = sc.nextInt();
		}
		Arrays.sort(A);
		for(int i = 0;i<N;i=i+2){
			ansA=ansA+A[i];
		}
		for(int i =1;i<N;i=i+2){
			ansB =ansB +A[i];
		}
		System.out.println(Math.abs(ansA-ansB));
		sc.close();
	}
}


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

using ll = long long;

int main() {
    ll S, a = 1e9, b, r;
    ll X1, Y1, X2, Y2, X3, Y3;
    cin >> S;
    if (S == 1e18) {
        X1 = a;
        Y1 = a;
        X2 = a;
        Y2 = 0;
        X3 = 0;
        Y3 = a;
    } else {
        b = S / a;
        r = S % a;
        X1 = a;
        Y1 = b + 1;
        X2 = r;
        Y2 = 0;
        X3 = 0;
        Y3 = b;
    }
    cout << X1 << " " << Y1 << " ";
    cout << X2 << " " << Y2 << " ";
    cout << X3 << " " << Y3 << endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  
  long long N,count,l,A[100],B[100],C[100];
  cin >> N;
  rep(i,N){
    cin >> A[i];
  }
  rep(i,N){
    cin >> B[i];
  }
  rep(i,N-1){
    cin >> C[i];
  }
  rep(i,N){
    count += B[i];
  }
  rep(i,N-1){
    if (A[i+1] - A[i] == 1 ){
      l = A[i];
      count += C[l-1];
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n,t;
    cin>>n>>t;
    int a[n];
    rep(i,n)cin>>a[i];
    int ma=0;
    int tmp=0;
    int cnt=0;
    for(int i=n-1;i>=0;--i){
        ma=max(ma,a[i]);
        if(ma-a[i]>tmp){
            tmp=ma-a[i];
            cnt=1;
        }
        else if(ma-a[i]==tmp)++cnt;
    }
    cout<<cnt<<endl;
    return 0;
}

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

int w,h,n,A[11][11],ans,cnt;
bitset<100> B[11][11];

void dfs(int d,bitset<100> s,int sco){
  if(d==n){
    ans=min(ans,sco);
    return;
  }
  cnt++;
  if(cnt>=30000000)return;
  if(ans<=sco)return;
  if(!A[d/w][d%w])dfs(d+1,s,sco);
  else{
    int y=d/w;
    int x=d%w;
    if((B[y][x]&s).any()){
      bitset<100>p;
      p.set(y*10+x);//(y*100+x);
      if(!(s&p).any())dfs(d+1,s,sco);
      dfs(d+1,(B[y][x]|s)^B[y][x],sco+1);
    }
    else dfs(d+1,s,sco);
  }
}

int main(){
  while(cin>>w>>h,w){
    memset(A,0,sizeof(A));
    r(i,11)r(j,11)B[i][j]&=0;
    n=h*w;
    bitset<100> b;
    r(i,h)r(j,w)cin>>A[i][j];
    r(i,h)r(j,w)if(A[i][j]){
      int sum=1;
      for(;;sum++){
        int f=0;
        for(int y=i;y<i+sum;y++){
          for(int x=j;x<j+sum;x++){
            if(A[y][x]==0)f++;
          }
        }
        if(f){
          sum--;
          break;
        }
      }
      bitset<100>tmp;
      for(int y=i,k=0;k<sum;k++,y++){
        for(int x=j,l=0;l<sum;l++,x++){
          tmp.set(y*10+x);
        }
      }
      b.set(i*10+j);
      B[i][j]=tmp;
    }
    ans=100;
    cnt=0;
    dfs(0,b,0);
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 3100
n = int(input())
A = list(map(int,input().split()))
q = int(input())
m = list(map(int,input().split()))

flag = [0]*2000
for j in range(2**n):
    tmp = 0
    for h in range(n):
        if (j>>h)&1:
            tmp += A[h]
    flag[tmp] = 1

for i in m:
    if flag[i]:
        print("yes")
    else:
        print("no")


Measured memory_bytes: 5632
s = gets.chomp
ac = true

ac = false unless s[0] == 'A'
# p ac
ac = false unless s[2..-2].chars.count{|x|x=='C'} == 1
# p ac
cind = s[2..-2].chars.find_index{|x|x=="C"}
ac = false unless s.chars[2..-1].reject.with_index{|x,i|i==cind}.all?{|x|/[a-z]/ === x}
ac = false unless s.chars[1].match(/[a-z]/)
puts ac ? 'AC' : 'WA'


Measured memory_bytes: 1788
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define pb push_back
#define mp make_pair
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<30)
#define LLINF (1<<60)
#define MOD 1000000007
#define rep(i, n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;

int main() {
    int N, M, X, Y, x[105], y[105];
    cin >> N >> M >> X >> Y;
    for (int i = 0; i < N; i++) {
        cin >> x[i];
    }
    x[N] = X;
    for (int i = 0; i < M; i++) {
        cin >> y[i];
    }
    y[M] = Y;
    sort(x, x + N + 1, greater<int>());
    sort(y, y + M + 1);
    if (x[0] < y[0])cout << "No War" << endl;
    else cout << "War" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  if(a == 1){
    a =14;
  }
  if(b == 1){
    b =14;
  }
  if (a > b){
    cout << "Alice" << endl;
  }else if(a < b){
    cout << "Bob" << endl;
  }else{
    cout << "Draw" << endl;
  }
  return 0;
}

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

int main()
{
  int n;
  cin>>n;
  vector<double> v(n);
  for (int i = 0; i < n; ++i)
  {
    cin>>v[i];
  }
  sort(v.begin(), v.end());
  while(v.size()!=1){
    double x=v[0],y=v[1];
    v.erase(v.begin(),v.begin()+2);
    v.emplace_back(x/2+y/2);
    sort(v.begin(), v.end());
  }
  cout<<v[0];
}

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

#define REP(i,n) for(decltype(n) 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);i>=(b);--i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(c) ((int)((c).size()))
#define st first
#define nd second
#define pb push_back

typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<bool> vb;
typedef long long ll;

vector<pii> G[100001];
vector<int> GT[100001];

int SCC[100001];
int rep[100001];
int tim;
int topo[100001];
bool vis[100001];

int x[100001];

void dfs(int v){
    if(vis[v]) return;
    vis[v] = true;
    for(auto const& u : G[v])
        dfs(u.st);
    topo[tim++] = v;
}

void prop(int v, int s){
    if(SCC[v]) return;
    SCC[v] = s;
    rep[s] = v;
    for(int u : GT[v])
        prop(u, s);
}

int scc(int n){
    FOR(i,1,n+1) dfs(i);
    int s = 1;
    FORD(i,n-1,0)
        if(!SCC[topo[i]])
            prop(topo[i], s++);
    return s-1;
}

bool check(int v){
    if(x[v] == INT_MIN)
        x[v] = 0;
    for(auto const& p : G[v]){
        if(x[p.st] == INT_MIN){
            x[p.st] = x[v] + p.nd;
            if(!check(p.st))
                return false;
        } else if(x[p.st] != x[v] + p.nd)
            return false;
    }
    return true;
}

void solve(){
    int N,M;
    int l,r,d;
    cin>>N>>M;
    fill(x,x+N+1,INT_MIN);
    REP(i,M){
        cin>>l>>r>>d;
        G[l].pb({r,d});
        GT[r].pb(l);
    }
    int cnt = scc(N);
    FOR(i,1,cnt+1){
        if(x[rep[i]] == INT_MIN && !check(rep[i])){
            cout<<"No";
            return;
        }
    }
    cout<<"Yes";
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 16000
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
//#define maxi 1e18
#define pll pair<ll,ll>
#define inf 1000000007
map<ll,ll> m;
int main(){
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll i,cnt=0;
    for(i=0;i<n-1;i++){
        if(s[i]!=s[i+1]){
            cnt++;
        }
    }
    cout<<cnt+1;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
	int x;
	cin >> x;
	if (x == 1) {
		cout << "Hello World" << endl;
		return 0;
	}
	else {
		int a, b;
		cin >> a >> b;
		cout << a + b << endl;
	}

}

Measured memory_bytes: 256
from bisect import bisect_right

n,q = map(int,input().split())

v_lay = [(-(n-1),n-2)]
h_lay = [(-(n-1),n-2)]

ans = (n-2)*(n-2)
for _ in range(q):
    case,lay_pos = map(int,input().split())
    
    ref_lay = (v_lay if case==1 else h_lay)
    
    index = bisect_right(ref_lay, (-lay_pos,n))
    _, lay = ref_lay[index-1]
    
    ans -= lay

    if index==len(ref_lay):
        ref_lay = (h_lay if case==1 else v_lay)
        laid_pos, num = ref_lay[-1]
        if laid_pos == -(lay+1):
            ref_lay[-1] = (-(lay+1), min(lay_pos-2,num))
        else:
            ref_lay.append((-(lay+1), lay_pos-2))
            
print(ans)

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

//***********************************************************************

// // hash struct for unordered_map
// struct hash_pair { 
//     template <class T1, class T2> 
//     size_t operator()(const pair<T1, T2>& p) const
//     { 
//         auto hash1 = hash<T1>{}(p.first); 
//         auto hash2 = hash<T2>{}(p.second); 
//         return hash1 ^ hash2; 
//     } 
// };

// int MAXNUM = 5e3+5;
// vector <int>vis(MAXNUM);
// vector<int> pr;
// void sieve() {
// 	pr.push_back(2);
// 	for(ll i=3;i<MAXNUM;i+=2) if(!vis[i]) {
// 		pr.push_back(i);
// 		for(ll j=i*i;j<MAXNUM;j+=2*i) vis[j]=true;
// 	}
// }
// //************************************************************************

void solve()
{
    int a,b,c;
    cin >> a >> b >> c;
    int k;
    cin >> k;
    while(k>0 && b<=a)
    {
        b*=2;
        k--;
    }
    while(k>0 && c<=b)
    {
        c*=2;
        k--;
    }
    if(c>b && b>a)
    cout << "Yes"  << endl;
    else
    cout << "No" << endl;
}


int main()
{ 
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
	ll t;
	//cin >> t;
	t=1;
	while(t--)
	{
		solve();
	}

	return 0;
}

Measured memory_bytes: 3644
#coding:utf-8
#1_8_A
class Node:
    def __init__(self, key):
        self.key = key
        self.parent = None
        self.left = None
        self.right = None

class Tree:
    def __init__(self):
        self.root = None

    def insert(self, node):
        y = None # set parent
        x = self.root
        while x is not None:
            y = x
            if node.key < x.key:
                x = x.left
            else:
                x = x.right
    
        if y is None:
            self.root = node
        elif node.key < y.key:
            y.left = node
        else:
            y.right = node

def inorder(node):
    if node is None:
        return
    inorder(node.left)
    print(" {}".format(node.key), end = "")
    inorder(node.right)

def preorder(node):
    if node is None:
        return
    print(" {}".format(node.key), end = "")
    preorder(node.left)
    preorder(node.right)

m = int(input())
t = Tree()
for i in range(m):
    cmd = input().split()
    if cmd[0] == 'insert':
        t.insert(Node(int(cmd[1])))
    else:
        inorder(t.root)
        print()
        preorder(t.root)
        print()

Measured memory_bytes: 153704
#include<iostream>
#include<string>
#include<algorithm>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define repm(i, m, n) for (int i = (m); i < (n); i++)
#define rep_rev(i, n) for (int i = int (n); i >= 0; i--)
typedef long long ll;
using namespace std;

int a[200000], f[200000];

bool ok(ll m, int n, ll k) {
	ll sum = 0;
	rep(i, n) {
		if (a[i] - m / f[i] > 0)sum += a[i] - m / f[i];
	}
	if (sum <= k) return true;
	else return false;
}

int main() {
	int n;
	ll k;
	cin >> n >> k;
	rep(i, n)cin >> a[i];
	rep(i, n)cin >> f[i];

	sort(a, a + n, greater<int>());
	sort(f, f + n);
	ll l = -1, r = 1e12;
	while (l + 1 < r) {
		ll mid = (l + r) / 2;
		if (ok(mid, n, k)) r = mid;
		else l = mid;
	}
	cout << r << endl;

	return 0;
}

Measured memory_bytes: 1792