akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;

const int N = 2e5 + 5, MOD = 1e9 + 7;

ll A[N], B[N];

int main() {
	fastIO;
#ifdef LOCAL
	freopen("input.in", "rw", stdin);
#endif
	ll n, m, k;
	cin >> n >> m >> k;
	ll tempK = k, aTotal = 0, bTotal = 0;
	vector<ll> vecA, vecB;
	for (int i = 0; i < n; ++i) {
		cin >> A[i];
		tempK -= A[i];
		if(tempK >= 0) {
			aTotal += A[i];
			vecA.push_back(aTotal);
		}
	}
	tempK = k;
	for (int i = 0; i < m; ++i) {
		cin >> B[i];
		tempK -= B[i];
		if(tempK >= 0) {
			bTotal += B[i];
			vecB.push_back(bTotal);
		}
	}
	int ans = 0;
	for (int i = 0; i < (int)vecA.size(); ++i) {
		int kk = (upper_bound(vecB.begin(), vecB.end(), k - vecA[i]) - vecB.begin());
		ans = max(ans, (int)i + 1 + kk);
	}
	for (int i = 0; i < (int)vecB.size(); ++i) {
		int kk = (upper_bound(vecA.begin(), vecA.end(), k - vecB[i]) - vecA.begin());
		ans = max(ans, (int)i + 1 + kk);
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 10524
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <cmath>
 
using namespace std;
 
// typedef
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<string> vs;
 
// container util
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for (typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
// repetition
#define FOR(i,m,n) for (ll (i) = ((ll) m); (i) < ((ll) n); ++(i))
#define RFOR(i,m,n) for (ll (i) = ((ll) (m)-1); (i) >= ((ll) n); --(i))
#define REP(i,n) FOR(i,0,n)
 
// i/o
#define TFOUT(b,t,f) cout << ((b)? (t) : (f)) << endl
 
//constant
const double    EPS     = 1e-10;
const double    PI      = acos(-1.0);
const int       INFTY   = (1<<21);
const ll        INFTY_LL = (1LL<<60);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl


int main() {
    int n, m, r; cin >> n >> m >> r;
    vector<int> v;
    REP(i, r) {
        int e; cin >> e;
        e--;
        v.push_back(e);
    }
    vector< vector<ll> > wf(n, vector<ll>(n, INFTY_LL));
    REP(i, n) {
        wf[i][i] = 0;
    }
    REP(i, m) {
        int a, b; ll c; cin >> a >> b >> c;
        a--; b--;
        wf[a][b] = c;
        wf[b][a] = c;
    }
    REP(k, n) {
        REP(i, n) {
            REP(j, n) {
                ll x = wf[i][k] + wf[k][j];
                if (wf[i][j] > x) wf[i][j] = x;
            }
        }
    }

    ll ans = INFTY_LL;
    SORT(v);
    do {
        ll score = 0;
        REP(i, r-1) score += wf[v[i+1]][v[i]];
        if (ans > score) ans = score;
    } while(next_permutation(ALL(v)));
    cout << ans << endl;
}


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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
typedef pair<ll,ll> pll;

#define reps(i,f,n) for(int i = int(f); i <= int(n); i++)
#define rep(i,n) reps(i,0,int(n)-1)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)

#define all(x) (x).begin(),(x).end()
#define X first
#define Y second

#define sz size()
#define eb emplace_back
#define pb push_back

vector<int> a[26];

int main(void){
  string s;
  int k;
  cin >> s;
  cin >> k;
  rep(i,s.sz){
    //cout << (26-(s[i]-'a')) << endl;

    if(s[i] != 'a' && k >= (26-(s[i]-'a'))){
      k = k - (26-(s[i]-'a'));
      s[i] = 'a';
    }

    //cout << k << " : " << s << endl; 
  }

  if( k > 0){
    s[s.sz-1] = ((s[s.sz-1] - 'a' + k)%26) + 'a';
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 512
//$g++ -std=c++11 Template.cpp 

//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

const int MAX = 25;
int dp[MAX][(1<<MAX)];
int a[MAX][MAX];

//解説AC
//https://atcoder.jp/contests/dp/submissions/4182721

int
main(void){  
  ios_base::sync_with_stdio(false);

  int n;  
  cin >> n;
  REP(i, n) REP(j, n) cin >> a[i][j];

  dp[0][(1<<n)-1] = 1;
  REP(i, n){
    REP(bit, (1<<n)){
      //bit数 != n-i
      if(__builtin_popcount(bit) != n-i) continue;
      REP(j, n){
	//好意 かつ j-bit立ってる
	if(a[i][j] && (bit&(1<<j))) (dp[i+1][bit&(~(1<<j))] += dp[i][bit])%=MOD;
      }
    }
  }

  cout << dp[n][0] << endl;
  
  return 0;
}


Measured memory_bytes: 182528
#include <iostream>
#include <string>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

int main() {
	string s; cin >> s;
	rep(i, 0, s.size()) {
		if ((i != s.size() - 1) && s[i] == s[i + 1]) {
			cout << i + 1 << " " << i + 2 << endl;
			return 0;
		}
		else if ((i != s.size() - 2) && s[i] == s[i + 2]) {
			cout << i + 1 << " " << i + 3 << endl;
			return 0;
		}
	}
	cout << -1 << " " << -1 << endl;
	return 0;
}

Measured memory_bytes: 512
n=int(input())
s=[]
for i in range(n):
    s.append(input())
m=int(input())
t=[]
for i in range(m):
    t.append(input())
ans=float('-inf')
for i in range (n):
    sa=s.count(s[i])-t.count(s[i])
    ans=max(ans,sa)
if ans<0:
    print(0)
else:
    print(ans)

Measured memory_bytes: 3064
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;
#define forl(V, S, E) for(int V = S; V < E; V++)
#define ford(V, S, E) for(int V = S; V >= E; V--)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
typedef unordered_map<int, unordered_set<int>> graph;
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; cin >> n; n--;
	deque<ll> d = {1, 2, 3, 4, 5, 6, 7, 8, 9};
	while(n--) {
		ll num = d.front(); d.pop_front();
		if(num%10) d.push_back(num*10+(num%10)-1);
		d.push_back(num*10+(num%10));
		if(num%10 != 9) d.push_back(num*10+(num%10)+1);
	}
	println(d.front());
}


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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

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;
}

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(){
    int n; cin >> n;
    string s; cin >> s;
    int ans = 0;
    vector<vector<int>> dp(n+1, vector<int>(n+1, 0));
    for(int i = n-1; i >= 0; i--){
        for(int l = n-1; l >= 0; l--){
            if(s[i] != s[l]){
                dp[i][l] = 0;
            }else{
                dp[i][l] = dp[i+1][l+1] + 1;
            }
        }
    }
    REP(i, 0, n){
        REP(l, 0, n){
            if(l <= i){
                continue;
            }else{
                chmax(ans, min(dp[i][l], l - i)); //かぶり消す
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 101208
//SkGeN
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstring>
#include<climits>
#include<deque>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<chrono>
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> p64;
typedef vector<ll> v64;
const int N = 2 * 1e5 + 10;
const ll inf = 1e18 + 100;
const ll mod = 1e9 + 7;
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,s,e) for(long long i=s;i<=e;i++)
#define brep(i,s,e) for(long long i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define DANGER std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
 
void solve() {
    ll n, k;
    cin>>n>>k;

    ll sum = 0;
    for(int i = k ; i <= n + 1 ; i++) {
        ll k = i * (n - i + 1) + 1;
        sum = sum % mod + k % mod;
        sum %= mod;
    }

    cout<<sum<<"\n";
}
int main()
{
    DANGER;
    ll t = 1;
    //cin>>t;
    while(t--) {
        solve();
    }
return 0;
}
//---->O ,,

Measured memory_bytes: 3668
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)
#define Yes(condition) if(condition){ cout << "Yes" << '\n'; }else{ cout << "No" << '\n'; }
#define YES(condition) if(condition){ cout << "YES" << '\n'; }else{ cout << "NO" << '\n'; }
#define yes(condition) if(condition){ cout << "yes" << '\n'; }else{ cout << "no" << '\n'; }




int main() {
    ll x, y;
    cin >> x >> y;
    cout << x + y / 2 << endl;
}

Measured memory_bytes: 256
using System;

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            const decimal rate = 1.08m;
            var p0 = decimal.Parse(Console.ReadLine());

            var c1 = Math.Ceiling(p0 / rate);
            var p1 = Math.Floor(c1 * rate);

            if (p0 == p1) {
                Console.WriteLine(c1);
            }
            else {
                var c2 = Math.Ceiling((p0 - 1) / rate);
                var p2 = Math.Floor(c2 * rate);

                if (p0 == p2) {
                    Console.WriteLine(c2);
                }
                else {
                    Console.WriteLine(":(");
                }
            }
        }
    }
}


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

struct node{
	int key;
	node *p,*l,*r;
};

node *root,*nil;

int n;

void insert(int k){
	node *y,*x,*z;
	y=nil;
	x=root;
	z=(node*)malloc(sizeof(node));
	z->key=k;
	z->l=nil;
	z->r=nil;
	while(x!=nil){
		y=x;
		if(k < x->key){
			x=x->l;
		}
		else{
			x=x->r;
		}
	}
	z->p=y;
	if(y==nil){
		root=z;
	}
	else{
		if( z->key  < y->key){
			y->l=z;
		}
		else{
			y->r=z;
		}
	}
}

void ino(node *x){
	if(x==nil){
		return;
	}
	ino(x->l);
	printf(" %d",x->key);
	ino(x->r);
}

void pre(node *x){
	if(x==nil){
		return;
	}
	printf(" %d",x->key);
	pre(x->l);
	pre(x->r);
}

node *find(node *x,int k){
	while(x!=nil&&k!=x->key){
		if(k <x->key){
			x=x->l;
		}
		else{
			x=x->r;
		}
	}
	return x;
}

int main() {
	cin>>n;
	int key;
	char c[20];
	for(int i=0;i<n;i++){
		cin>>c;
		if( c[0]=='i'){
			cin>>key;
			insert(key);
		}
		else if(c[0]=='f'){
			cin>>key;
			node *x=find(root,key);
			if(x==nil){
				printf("no\n");
			}
			else{
				printf("yes\n");
			}
		}
		else{
			ino(root);cout<<endl;
			pre(root);cout<<endl;
		}
	}

	return 0;
}


Measured memory_bytes: 21960
#include <stdio.h>

int merge(int, int, int);
int mergeSort(int, int);

int S[500000], L[250001], R[250001];
int count=0;

int main()
{
  int n, i;
  scanf("%d%",&n);
  for( i=0 ; i<n ; i++ )
    scanf("%d",&S[i]);

  mergeSort(0,i);

  for( i=0 ; i<n-1 ; i++ )
    printf("%d ",S[i]);
  printf("%d\n",S[i]);
  printf("%d\n",count);

  return 0;
}

int merge(int left, int mid, int right)
{
  int n1, n2, i, j, k;
  n1 = mid-left;
  n2 = right - mid;
  for( i=0 ; i<n1 ; i++ )
    L[i] = S[left+i];
  for( i=0 ; i<n2 ; i++ )
    R[i] = S[mid+i];
  L[n1]=1000000100;
  R[n2]=1000000100;
  i=0;
  j=0;
  for( k=left ; k<right ; k++ ){
    if(L[i]<=R[j]){
      S[k]=L[i];
      i++;
    }
    else{
      S[k]=R[j];
      j++;
    }
    count++;
  }
}
int mergeSort(int left, int right)
{
  int mid;
  if((left+1)<right){
    mid=(left+right)/2;
    mergeSort(left,mid);
    mergeSort(mid,right);
    merge(left,mid,right);
  }
}

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

int main(void) {
	int N, cnt, c_l, c_r;
	string S;

	cin >> N >> S;
	cnt = c_l = c_r = 0;
	for (int i = 0; i < N; ++i) {
		if (S[i] == '(')
			++cnt;
		else
			--cnt;
		if (cnt < 0) {
			cnt = 0;
			++c_l;
		}
	}
	c_r = cnt;

	string s_l = string(c_l, '(');
	string s_r = string(c_r, ')');
	S = s_l + S + s_r;

	cout << S << '\n';
	return 0;
}


Measured memory_bytes: 256
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_macros)]
#![allow(unused_variables)]
#![allow(unused_imports)]
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::max($x, max!($($y),+))
    };
}

macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::min($x, max!($($y),+))
    };
}

use std::cmp;
use std::collections::{HashSet, BinaryHeap, VecDeque};
use std::iter::FromIterator;
fn main() {
    input!{
        N: usize,
        K: usize,
        S: chars
    }
    let c = S[K-1];
    match c {
        'A' => S[K-1] = 'a',
        'B' => S[K-1] = 'b',
        'C' => S[K-1] = 'c',
         _  => panic!(),
    }
    println!("{}", S.into_iter().collect::<String>());
}

Measured memory_bytes: 4352
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i;
  int len,a1,b1,a2,b2,a3,b3;
  string s;
  for(;;){
    s="";
    cin>>s;
    if(s=="0")
      break;
    len=s.length();
    a1=b1=a2=b2=a3=b3=0;
    for(i=1;i<len;i++){
      if(s[i]=='A')
	a1++;
      else
	b1++;
    }
    if(a1>b1)
      a1++;
    else
      b1++;
    cin>>s;
    len=s.length();
    for(i=1;i<len;i++){
      if(s[i]=='A')
	a2++;
      else
	b2++;
    }
    if(a2>b2)
      a2++;
    else
      b2++;
    cin>>s;
    len=s.length();
    for(i=1;i<len;i++){
      if(s[i]=='A')
	a3++;
      else
	b3++;
    }
    if(a3>b3)
      a3++;
    else
      b3++;
    cout<<a1<<" "<<b1<<endl;
    cout<<a2<<" "<<b2<<endl;
    cout<<a3<<" "<<b3<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ms(x,y) memset(x,y,sizeof(x))
using namespace std;
int n,w,d,huan;
const int N=2005;
struct edge{
	int l,r;
}e[N];
int en;
bool cmp(const edge &A,const edge& B){
	return A.r<B.r;
}
bool exi[N];


bool in(int i,int pos){
	if(e[i].l<=e[i].r){
		if(pos>=e[i].l && pos<=e[i].r)return true;
	}
	else if(pos>=e[i].l || pos<=e[i].r)return true;
	return false;
}

int gao(int now,int pos){
	int ans=1;
	for(int i=0;i<en;i++)
		if(in(i,pos))exi[i]=false;
	for(int i=(now+1)%en,j;i!=now;) {
		if(exi[i]) {
			exi[i]=false;
			ans++;
			for(j=(i+1)%en;j!=now;j=(j+1)%en)
				if((!exi[j]) || in(j,e[i].r)) exi[j]=false;
				else break;
			i=j;
		}
		else i++;
	}
	return ans;
}


void add(int l,int r){
	if(l<0)l+=huan;
	if(r<0)r+=huan;
	if(l>=huan)l-=huan;
	if(r>=huan)r-=huan;
	e[en].l=l;
	e[en++].r=r;
}
		
int main(){
	cin>>n>>w>>d;
	huan=2*d+2*w;
	int x,y;
	char ch;
	en=0;
	for(int i=1;i<=n;i++){
		scanf("%d %d %c",&x,&y,&ch);
		if(ch=='W')
			add(y-x,y+x);
		else if (ch == 'N'){
			y=d-y;
			add(x-y+d,x+y+d);
		}
		else if(ch == 'E'){
			x=w-x;y=d-y;
			add(d+w+y-x,d+w+y+x);
		}
		else if(ch == 'S'){
			x=w-x;
			add(d+w+d+x-y,d+w+d+x+y);
		}
	}
	sort(e,e+en,cmp);
	int ans=1000000;
	for(int i=0;i<en;i++){
		ms(exi,1);
		ans=min(ans,gao(i,e[i].l));
		ms(exi,1);
		ans=min(ans,gao(i,e[i].r));
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a[6];
    for(int i=1;i<=5;i++)
       {   cin>>a[i];

        }

        for(int i=1;i<=5;i++)
        {if(a[i]==0)
            cout<<i<<endl;
        }
        return 0;
}


Measured memory_bytes: 3596
#include <stdio.h>

int main(void) {
  int x[5];
  for (int i=0;i<5;++i) {
    scanf("%d\n",&x[i]);
    if (x[i]==0) {
      printf("%d\n",i+1);
      break;
    }
  }
  return 0;
}


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

#define LL long long int
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int N = 2e5 + 5;
const int oo = 1e9 + 5;
const LL ooll = 1e18 + 5;

void solve() {
	int n;
	cin >> n;
	vector<array<int, 2>> v, w;
	LL ans = 0;
	for (int i=0;i<n;++i) {
		int k, l, r;
		cin >> k >> l >> r;
		if (l >= r) {
			v.push_back({k, l-r});
			ans += r;
		} else {
			w.push_back({n-k, r-l});
			ans += l;
		}
	}
	int vsz = v.size(), wsz = w.size(), vit = 0, wit = 0;
	sort(v.begin(), v.end()); sort(w.begin(), w.end());

	multiset<int> st;
	for (int i=1;i<=n;++i) {
		while(vit<vsz && v[vit][0] == i) {
			st.insert(v[vit][1]);
			++vit;
		}
		while(st.size() > i) st.erase(st.begin());
	}
	for (auto it : st) {
		ans += it;
	}

	st.clear();
	while(wit < wsz && w[wit][0] < 1) wit++;
	for (int i=1;i<=n;++i) {
		while(wit < wsz && w[wit][0] == i) {
			st.insert(w[wit][1]);
			++wit;
		}
		while(st.size() > i) st.erase(st.begin());
	}
	for (auto it : st) ans += it;
	cout << ans << '\n';
}

int main() {
	FASTIO;
	int T;
	cin >> T;
	while(T--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 9512
#include <bits/stdc++.h>
using namespace std;
const int MAXn = 1e5 + 10;
typedef pair<int, int> pii;
vector<pii> g[MAXn];
long long n, m, dis[MAXn];
bool flag[MAXn];

void dfs(int v,  long long dist) {
	flag[v] = true;
	dis[v] = dist;
	for (pii u : g[v]) {
		if (flag[u.first])
			continue;
		dfs(u.first, dist + u.second);
	}
}

int  main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int u, v, d;
		cin >> u >> v >> d;
		g[u].push_back(pii(v, d));
		g[v].push_back(pii(u, -d));
	}
	for (int i = 1; i <= n; i++) {
		if (!flag[i]) {
			dfs(i, 0);
		}
	}
	for (int i = 1; i <= n; i++)
		for (pii u : g[i])
			if (dis[i] + u.second != dis[u.first])
				return cout << "No",0;
	cout << "Yes";
}


Measured memory_bytes: 11520
N, M = [ int(x) for x in input().split() ]
As = [ input() for _ in range(N) ]
Bs = [ input() for _ in range(M) ]

def contain(i, j):
    for p in range(M):
        if As[i + p][j:j+M] != Bs[p]:
            return False
    return True
ans = False
for i in range(N - M + 1):
    for j in range(N - M + 1):
        if contain(i, j):
            ans = True

print("Yes" if ans else "No")


Measured memory_bytes: 3060
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

int main()
{
	LL x,y;
	cin>>x>>y;
	int ans=0;while(x<=y){x*=2;ans++;}
	printendl(ans);
	return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  set<int> st;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (i % 2 == 0) st.insert(A[i]);
  }
  vector<int> B = A;
  sort(B.begin(), B.end());
  int res = 0;
  for (int i = 1; i < N; i += 2) {
    if (st.find(B[i]) != st.end()) res++;
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 3328
N=int(input())
h=list(map(int,input().split()))

dp=[0]*100100
#dp[i]はi番目の足場に辿り着くまでのコストの最小値

dp[1]=0
for i in range(1,N):
    if i==1:dp[2]=abs(h[1]-h[0])
    else:dp[i+1]=min(dp[i]+abs(h[i]-h[i-1]),dp[i-1]+abs(h[i]-h[i-2]))


print(dp[N])


Measured memory_bytes: 13924
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int numVals = in.nextInt();
		int[] curVals = new int[numVals];
		for(int i = 0; i < numVals; i++) {
			curVals[i] = in.nextInt();
		}
		in.close();
		
		System.out.println(computeMax(numVals, curVals));
	}
	
	private static int computeMax(int n, int[] R) {
		int maxProfit = Integer.MIN_VALUE;
		int minCurrVal = Integer.MAX_VALUE;
	      for(int i = 0; i < n; i ++) {
	    	  	if(i > 0)maxProfit = Math.max(maxProfit, R[i]-minCurrVal);
	    	  	if(R[i] < minCurrVal)minCurrVal = R[i];
	    	  	//System.out.println("Max Profit: " + maxProfit);
	    	  	//System.out.println("Min Value: " + minCurrVal);
	         }
	     return maxProfit;
	}
}


Measured memory_bytes: 99440
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

int n;
int a[300010];

signed main(){
    cin >> n;
    rep(i, 0, 3 * n){
        cin >> a[i];
    }
    int ans = -1e18, pre = 0;
    priority_queue<int, vector<int> > rt;//降順
    priority_queue<int, vector<int>, greater<int> > lt;//昇順  
    rep(i, 0, n){
        lt.push(a[i]);
        pre += a[i];
    }
    rep(i, 2 * n, 3 * n){
        rt.push(a[i]);
        pre -= a[i];
    }
    vector<int> sl(n, 0), sr(n, 0);
    rep(i, n, 2 * n){
        int MIN = lt.top();
        if(MIN < a[i]){
            lt.pop();
            lt.push(a[i]);
            sl[i - n] += a[i] - MIN;
        }
    }
    repb(i, 2 * n - 1, n){
        int MAX = rt.top();
        // cout << MAX << " " << a[i] <<  endl;
        if(MAX > a[i]){
            rt.pop();
            rt.push(a[i]);
            sr[i - n] += MAX - a[i];
        }
    }
    // rep(i, 0, n){
    //     cout << sr[i] << " ";
    // }
    // cout << endl;
    // rep(i, 0, n){
    //     cout << sl[i] << " ";
    // }
    // cout << endl;
    vector<int> suml(n + 10, 0), sumr(n + 10, 0);
    rep(i, 1, n + 1) suml[i] += suml[i - 1] + sl[i - 1];
    repb(i, n, 1) sumr[i] += sumr[i + 1] + sr[i - 1];
    rep(i, 0, n + 1){
        ans = max(ans, suml[i] + sumr[i + 1]);
    }
    cout << pre + ans << endl;
}

Measured memory_bytes: 7412
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for(i=0;i<n;i++)
int main() {
	int a[]={1,6,9,36,81,216,729,1296,6561,7776,46656,59049},i;
	set<int> s;
	for(i=0;i<12;i++) {
		s.insert(a[i]);
	}
	int n;
	cin>>n; //to be calculated
	int dp[n+1],temp,t,j; //dp[i]=min transactions needed to withdraw amount i
	dp[0]=0;
	dp[1]=1;
	for(i=2;i<=n;i++) {
		if(s.count(i)) {
			dp[i]=1;
			continue;
		}
		temp=dp[i-a[0]];
		for(j=1;j<12;j++) {
			if(i-a[j]>=1) {
				temp=min(temp,dp[i-a[j]]);
			}
		}
		dp[i]=1+temp;
	}
	cout<<dp[n]<<"\n";
	return 0;
}

Measured memory_bytes: 640
n, m = gets.strip.split.map(&:to_i)
a = readlines.map {|line| line.strip.to_i }.sort

MOD = 10**9+7
#p n
#p a
dp=[0]*(n+1)

a.each do |hall|
  dp[hall] = -1
end

dp[0]=1
n.times do |index|
  next if dp[index]==-1

  if (0..n)===(index+1) && dp[index+1]>=0
    dp[index+1]=(dp[index]+dp[index+1])%MOD
  end
  if (0..n)===(index+2) && dp[index+2]>=0
    dp[index+2]=(dp[index]+dp[index+2])%MOD
  end
end

 p dp[n]%MOD

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

pll A[10];
ll B[4] = {0, 10, 100, 1000};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    REP(i, M) {
        cin >> A[i].first >> A[i].second;
    }

    FOR(n, B[N], B[N - 1]) {
        bool e = true;
        vector<ll> v(N);
        ll m = n;
        REP(i, N) {
            v[N - 1 - i] = m % 10;
            m /= 10;
        }
        REP(i, M) {
            if (v[A[i].first - 1] != A[i].second)
                e = false;
        }
        if (e) {
            cout << n << endl;
            return 0;
        }
    }
    cout << -1 << endl;

    return 0;
}

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

using namespace std;

typedef pair<int,int> pi;

const int maxn = 310;

int n, D1, D2, c1 = 0, c2 = 0;
vector<pi> vec[4];
int __s[4];

int getbit(int x, int k) {
	return (x >> k) & 1;
}

int main() {
	scanf("%d%d%d", &n, &D1, &D2);
	while (D1 % 2 == 0) {
		D1 /= 2;
		++ c1;
	}
	while (D2 % 2 == 0) {
		D2 /= 2;
		++ c2;
	}
	if (c1 == c2) {
		for (int x = 0; x < 2 * n; x++) {
			for (int y = 0; y < 2 * n; y++) {
				int v = 0;
				for (int i = 0; i < 10; i++) {
					v ^= (getbit(x, i) << (2 * i));
					v ^= (getbit(x, i) << (2 * i + 1));
					v ^= (getbit(y, i) << (2 * i));
				}
				vec[getbit(v, c1)].push_back(pi(x, y));
			}
		}
	} else {
		if (c1 > c2) {
			swap(c1, c2);
		}
		for (int x = 0; x < 2 * n; x++) {
			for (int y = 0; y < 2 * n; y++) {
				int v = 0;
				for (int i = 0; i < 10; i++) {
					v ^= (getbit(x, i) << (2 * i));
					v ^= (getbit(x, i) << (2 * i + 1));
					v ^= (getbit(y, i) << (2 * i));
				}
				vec[getbit(v, c1)*2+getbit(v, c2)].push_back(pi(x, y));
			}
		}
	}
	for (int i = 0; i < 4; i++) {
		__s[i] = int (vec[i].size());
	}
	int r = int (max_element(__s, __s + 4) - __s);
	for (int i = 0; i < n * n; i++) {
		printf("%d %d\n", vec[r][i].first, vec[r][i].second);
	}
	return 0;
}

Measured memory_bytes: 4712
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    ll n, x, t;
    cin >> n >> x >> t;
    ll cnt = 1+(n-1)/x;
    cout << cnt*t << endl;
    return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

constexpr ll mod=1e9+7;
vector<pair<int,int>> v[301];
ll dp[303][303]={1};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m; cin >> n >> m;
    while(m--){
        int l,r,x; cin >> l >> r >> x;
        v[r-1].push_back({l,x});
    }
    // dp[i][j]:最後に使ったindexのうち後ろを持っておく(i>j)
    // 例外1色しか使わない時, i=j=0
    // 1色使う時選び方3通り　それ以外3!=6通り
    for(int i=0;i<n;i++){ // 今i(1-indexed)番目まで埋め終わってる
        // i番目に使った奴と同じものをi+1番目で使った場合遷移なし
        // i+1番目に使わない方のindex jを固定
        // 並び順はk>i>jとなる　そのDP更新を以下で行う
        for(int j=0;j<i;j++){ 
            for(int k=0;k<i;k++){
                (dp[i][j]+=dp[max(j,k)][min(j,k)])%=mod;
            }
        }
        // 条件を満たしてるかの判定
        for(auto p:v[i]){
            for(int j=0;j<=i;j++){
                for(int k=0;k<=j;k++){
                    if(p.second+(j<p.first)+(k<p.first)-3){
                        dp[j][k]=0;
                    }
                }
            }
        }
    }
    ll res=dp[0][0]*3;
    for(int i=0;i<n;i++){
        for(int j=0;j<i;j++){
            (res+=6*dp[i][j])%=mod;
        }
    }
    printf("%lld\n",res);
}

Measured memory_bytes: 4484
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <numeric>

using namespace std;

typedef long long int ll;
typedef long int li;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main(){
    int ans=0;
    char s[10];
    int a[10];
    for(int i=0;i<10;i++)a[i]=0;
    cin >> s;
    for(int i=0;i<10;i++){
    if(s[i]=='A')a[i]++;
    if(s[i]=='T')a[i]++;
    if(s[i]=='G')a[i]++;
    if(s[i]=='C')a[i]++;
    }
    for(int i=0;i<10;i++){
        int x=0;
        int preans=0;
        for(int j=i;j<10;j++){
          if(a[j]==0)x++;
            if(x==0)if(a[j]==1)preans++;
        }
        ans=max(preans,ans);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, t, a, y = 0;
    double z = 100000.0;
    cin >> n >> t >> a;
    double h[n], x[n], req[n];
    for(int i = 0; i < n; i++){
        cin >> h[i];

        x[i] = t - (h[i]* 0.006);
        req[i] = fabs(a - x[i]);
        if(req[i] < z){
            z = req[i];
            y = i+1;
        }
    }
    cout << y << endl;
return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<map>

using namespace std;

int i,j,k,N,a,b,c,d;

char S[10];

int main()
{
  cin>>N;
  
  a=b=c=d=0;
  for(i=0;i<N;i++)
  {
    cin>>S;
    if(S[0]=='A') a++;
    else if(S[0]=='W') b++;
    else if(S[0]=='T') c++;
    else d++;
  }
  
  cout<<"AC x "<<a <<endl;
  cout<<"WA x "<<b <<endl;
  cout<<"TLE x "<<c <<endl;
  cout<<"RE x "<<d <<endl;

}

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

int LCS(string p, string q) {
	vector<vector<int> > f(p.size()+1, vector<int>(q.size()+1,0));
	int t;
	for (int i = 1; i <= p.size(); i++) {
		for (int j = 1; j <= q.size(); j++) {
			if (p[i-1] == q[j-1])
				f[i][j] = f[i - 1][j - 1] + 1;
			else if (f[i][j - 1] > f[i - 1][j])
				f[i][j] = f[i][j - 1];
			else
				f[i][j] = f[i - 1][j];
		}
	}
	return f[p.size()][q.size()];
}

int main() {
	int n;
	string p[300];
	cin >> n;
	for (int i = 0; i < n; i ++) {
		cin >> p[2*i] >> p[2*i + 1];
	}
	for (int i = 0; i < n; i++) {
		cout << LCS(p[2*i], p[2 * i + 1])<<endl;
	}
	return 0;
}

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

int main ()
{
    char a, b, c, d;
    cin >> a >> b >> c >> d;
    string ans = "No";
    if (a == b) {
        if (c == d && c != a) {
            ans = "Yes";
        }
    }
    if (a == c) {
        if (b == d && b != a) {
            ans = "Yes";
        }
    }
    if (a == d) {
        if (b == c && a != b) {
            ans = "Yes";
        }
    }
    cout << ans;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<endl
#define                 real signed
#define                 endl '\n'              
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 314159
#define  vi vector<int>
#define  v  vector

signed main() 
{
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
     
    int a,b,c;
    cin>>a>>b>>c;
    cout<<min(c,b/a);



     return 0;

}

//       g++ -g c.cpp ; ./a.exe

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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

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

    Vi a(n+1);
    REP(i,n+1) cin>>a[i];

    Vi b(n+1);
    REP(i,n) cin>>b[i];
    
    LL total = 0;
    REPD(i,n-1){
        int taosu_monster = min(b[i],a[i+1]);
        total += taosu_monster;
        a[i+1] -= taosu_monster;
        b[i] -= taosu_monster;

        taosu_monster = min(b[i],a[i]);
        total += taosu_monster;
        a[i] -= taosu_monster;
        b[i] -= taosu_monster;
    }

    cout<<total<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    cout << (abs(a - b) % 2 == 0 ? "Alice" : "Borys") << endl;
}


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

struct Node {
    int key;
    struct Node *parent,*left,*right;
};

void insert(int);
struct Node *find(struct Node *,int);
struct Node *treeMinimum(struct Node *x);
struct Node *treeSuccessor(struct Node *x);
void treeDelete(struct Node *z);
void inorder(struct Node *);
void preorder(struct Node *u);

struct Node *root,*NIL;

int main(){
  int m,i,k;
  char com[20];

  scanf("%d",&m);

  for(i=0;i<m;i++){
  scanf("%s",com);
 
    if(com[0]=='i'){
        scanf("%d",&k);
        insert(k);
    }
    else if(com[0]=='f'){
        scanf("%d",&k);

        struct Node *u=find(root,k);
    
        if(u==NIL) printf("no\n");
        else printf("yes\n");
    }
    else if (com[0]=='p'){
        inorder(root);
        printf("\n");
        preorder(root);
        printf("\n");
    }
    else if(com[0]=='d'){
        scanf("%d",&k);

        treeDelete(find(root,k));
    }
  }

  return 0;
}

void insert(int k){
  struct Node *y=NIL;
  struct Node *x=root;
  struct Node *z;

  z=(struct Node *)malloc(sizeof(struct Node));

  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;

    if(z->key < x->key)   x=x->left;
    else  x=x->right;
  }
  z->parent=y;
    
  if(y==NIL)  root=z;
  else{
    if(z->key < y->key) y->left=z;
    else y->right=z;
  }
}

struct Node *find(struct Node *u, int k){
  while(u!=NIL && k!=u->key){
    if(k<u->key) u=u->left;
    else u=u->right;
  }
  return u;
}

struct Node *treeMinimum(struct Node *x){
    while(x->left!=NIL) x=x->left;

    return x;
}

struct Node *treeSuccessor(struct Node *x){
    if(x->right!=NIL) return treeMinimum(x->right);

    struct Node *y=x->parent;

    while(y!=NIL && x==y->right){
        x=y;
        y=y->parent;
    }

    return y;
}

void treeDelete(struct Node *z){
    struct Node *y;
    struct Node *x;

    if(z->left==NIL || z->right==NIL) y=z;
    else y=treeSuccessor(z);

    if(y->left!=NIL) x=y->left;
    else x=y->right;

    if(x!=NIL) x->parent=y->parent;

    if(y->parent==NIL) root=x;
    else{
        if(y==y->parent->left) y->parent->left=x;
        else y->parent->right=x;
    }

    if(y!=z) z->key=y->key;

    free(y);
}

void inorder(struct Node *u){
    if(u==NIL)  return;

    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);

}

void preorder(struct Node *u){
    if(u==NIL)  return;

    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}


Measured memory_bytes: 20544
#include<stdio.h>
int aa[110];
main()
{
	int n,m;
	while(~scanf("%d %d",&n,&m))
	{
		int i;
		for(i=0;i<n;i++)
		{
			scanf("%d",&aa[i]);
		}
		int sum=0;
		int num=1;
		for(i=0;i<n;i++)
		{	
			sum=sum+aa[i];
			if(sum>m)
			break;
			else
			num++;
			
		}
		printf("%d\n",num);
	}
}//

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
    string S;
    cin >> S;
    bool flag = true;
    for(int i = 1; i < S.length(); i++){
        if(S[i]  == S[i-1]){
            flag = false;
            break;
        }
    }
    if(flag) cout << "Good" << endl;
    else cout << "Bad" << endl;
}


Measured memory_bytes: 256
#include <cstdio>

int main()
{
  int n;
  scanf("%d", &n);
  puts(n < 105 ? "0" : n < 135 ? "1" : n < 165 ? "2" : n < 189 ? "3" : n < 195 ? "4" : "5");
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<unordered_map>
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep2(i,n) for(int i = (n - 1); i >= 0; i--)
#define PI 3.141592653589793

using namespace std;
using ll = long long;

int to[200000];
const int si[] = { -1,0,1,0 };
const int sj[] = { 0,-1,0,1 };

int main() {

	int h, w;
	cin >> h >> w;
	int ci, cj;
	cin >> ci >> cj;
	int di, dj;
	cin >> di >> dj;
	ci--; cj--; di--; dj--;
	vector<string> s(h);
	rep(i, h) cin >> s[i];
	vector<vector<int>> dist(h, vector<int>(w, 1e9));
	deque<pair<int, int>> q;

	dist[ci][cj] = 0;
	q.emplace_front(ci, cj);
	while (!q.empty()) {
		int i = q.front().first;
		int j = q.front().second;
		q.pop_front();
		int d = dist[i][j];

		rep(v, 4) {
		
			int ni = i + si[v], nj = j + sj[v];
			if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
			if (s[ni][nj] == '#') continue;
			if (dist[ni][nj] <= d) continue;
			dist[ni][nj] = d;
			q.emplace_front(ni, nj);
		}

		for (int ki = -2; ki <= 2; ki++) {
			for (int kj = -2; kj <= 2; kj++) {
				int ni = i + ki, nj = j + kj;
				if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
				if (s[ni][nj] == '#') continue;
				if (dist[ni][nj] <= d + 1) continue;
				dist[ni][nj] = d + 1;
				q.emplace_back(ni, nj);
			}
		}
	}

	int ans = dist[di][dj];
	if (ans == 1e9) ans = -1;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 9512
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef map<ll, ll> mlli;

int main() {FIN
	
	ll i, c = 0, n, m = 1, d = 0, p;
	string num;
	mlli md;
	cin >> n >> p;
	cin >> num;
	
	if (p == 2 or p == 5) {
		for (i = 0; i < n; i++) {
			if ((num[i] - '0') % p == 0)
				c += (i + 1);
		}
	} else {
		mlli::iterator it;
		for (i = n - 1; i >= 0; i--) {
			d = (d + (((num[i] - '0') * m) % p)) % p;
			it = md.find(d);
			if (it != md.end())
				c += it->second;
			md[d]++;
			m = (m * 10) % p;
		}
		it = md.find(0);
		if (it != md.end())
			c += it->second;
	}
	
	cout << c << "\n";
	
	return 0;
}


Measured memory_bytes: 1044
#include <iostream>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;

int main(){
    ll K,X;
    cin >> K >> X;
    for(ll i= X-K+1;i<X+K;i++){
        cout << i << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
typedef long long int ll;
using namespace std;
int main(){
    ll x,y,z;
    cin >> x >> y >> z;
    if (x+y+z>=22){
        cout << "bust";
    }
    else{
        cout << "win";
    }
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
 


public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static         Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static int K,N;
	static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);

	public static void main(String[] args) {
			int N=sc.nextInt();
			int K=sc.nextInt();
			
			long ans=K;
			for(int i=1;i<N;i++) {
				
				ans*=K-1;
				
				
			}p(ans);
	}
	

	
	//N==S
	//E==W
//83 S 
	//69E
	//78N
	//87W
	
	//static ArrayList<Integer> cc = new ArrayList<>(10001);
	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 21844
import bisect
def main():
    N,D,A=map(int,input().split())
    XH=[list(map(int,input().split())) for _ in range(N)]
    XH.sort()
    for i in range(N):
        XH[i][1]=-(-XH[i][1]//A)
    X=[x for x,a in XH]
    far=[0]*N
    for i in range(N):
        far[i]=bisect.bisect_right(X,X[i]+2*D)-1

    ans=0
    carry=0
    outrange=[0]*(N+1)
    for i in range(N):
        x=XH[i][0]
        hp=XH[i][1]
        carry-=outrange[i]
        if carry>=hp:
            continue
        outrange[bisect.bisect_right(X,X[i]+2*D)]+=hp-carry
        ans+=hp-carry
        carry+=hp-carry
    print(ans)

if __name__ == '__main__':
    main()

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

using namespace std;
typedef long long ll;

int n,m;
vector<int> v[100005];
ll dp[100005];

ll dfs(int node){

    if(v[node].size() == 0) return 0;

    if(dp[node] != -1) return dp[node];

    ll ret = 0;
    for(int i=0;i<v[node].size();i++)
        ret = max(ret,dfs(v[node][i])+1);

    return dp[node] = ret;

}


int main()
{
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        v[x].push_back(y);
    }
    memset(dp,-1,sizeof(dp));
    ll ans=-1;
    for(int i=1;i<=n;i++){
        ans = max(ans, dfs(i));
    }
    cout<<ans;

    return 0;
}


Measured memory_bytes: 11680
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <utility>
#include <queue>
#include <map>
using namespace std;

#define TEST 0
#if TEST
FILE *in = freopen("./q.txt", "r", stdin);
FILE *out = freopen("./a.txt", "w", stdout);
#endif

int dx[6] = { 0, 1, 1, 0,-1,-1};
int dy[6] = { 1, 1, 0,-1,-1, 0};

inline void pusuQueue(queue<int>& q, int x, int y, int t){
	q.push(x), q.push(y), q.push(t);
}
inline void popQueue(queue<int>& q, int& x, int& y, int& t){
	x = q.front(); q.pop();
	y = q.front(); q.pop();
	t = q.front(); q.pop();
}

inline bool isRegion(int x, int y){
	return x >= -30 && x <= 30 && y >= -30 && y <= 30;
}

int main(){
	while (1){
		int t, n; cin >> t >> n;
		if (!t && !n) break;

		map<pair<int, int>, bool> isBar;

		for (int i = 0; i < n; i++){
			int x, y; cin >> x >> y;
			isBar[make_pair(x, y)] = true;
		}
		
		int sx, sy; cin >> sx >> sy;
		isBar[make_pair(sx, sy)] = true;

		int cnt = 0;
		queue<int> q;
		pusuQueue(q, sx, sy, 0);
		while (!q.empty()){
			int x, y, turn; popQueue(q, x, y, turn);
			cnt++;

			for (int i = 0; i < 6; i++){
				int nx = x + dx[i], ny = y + dy[i];
				if (turn < t && !isBar[make_pair(nx, ny)]){
					pusuQueue(q, nx, ny, turn+1);
					isBar[make_pair(nx, ny)] = true;
				}
			}
		}
		cout << cnt << endl;

	}


#if TEST
	fclose(in);
	fclose(out);
#endif
}

Measured memory_bytes: 1416
while True:
    H,W=map(int,input().split())
    if H==0 and W==0:
        break
    else:
        for v in range(H):
            if v%2==0:
                if W%2==0:
                    print("#."*(W//2))
                else:
                    print("#."*(W//2)+"#")
            else:
                if W%2==0:
                    print(".#"*(W//2))
                else:
                    print(".#"*(W//2)+".")
        print()        


Measured memory_bytes: 5612