akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007

void solve()
{
	double r,g;
	cin>>r>>g;
	cout<<(g*2)-r;
    return;
}

int main()
{
        fast;
        ll q;
        q=1;
        // cin>>q;
        while(q--)
        	solve();
        
        return 0;
}

Measured memory_bytes: 3760
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;


int main(void){
	int n,m,q;
	cin>>n>>m>>q;
	int work[n+1][n+1];

	rep(i,n+1)rep(j,n+1)work[i][j]=0;

	rep(i,m){
		int l,r;
		cin>>l>>r;
		work[l][r]++;
	}

	rep(i,n){
		rep(j,n){
			work[i+1][j+1]+=work[i][j+1]+work[i+1][j]-work[i][j];
		}
	}

	/*rep(i,n){
		rep(j,n){
			cout<<work[i+1][j+1]<<" ";
		}
		cout<<endl;
	}*/
	
	rep(i,q){
		int l,r;
		cin>>l>>r;
		cout<<work[r][r]-work[r][l-1]-work[l-1][r]+work[l-1][l-1]<<endl;
	}



	return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios_base::sync_with_stdio(0);
    int n; cin >> n;
    int cnt = 0;
    for (int i=0;i<n;i++) {
        int x; cin >> x;
        if (x%2&&i%2==0) cnt++;
    }

    cout << cnt << endl;
}


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

int main() {
  int N;
  cin >> N;
  int thousand = N / 1000;
  int hundred = (N % 1000) / 100;
  int ten = (N % 100) / 10;
  int one = N % 10;
  if (thousand == hundred || hundred == ten || ten == one) {
    cout << "Bad" << endl;
  }
  else {
    cout << "Good" << endl;
  }
}

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

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

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

#define MAX_N 200000
vector<ll>g[MAX_N];

vector<int> group[2];
void dfs(ll pre, ll now, ll d){
  group[d].push_back(now);
  for(auto to: g[now]){
    if(pre!=to) dfs(now, to, d^1);
  }
}

int main(){
  ll n;cin>>n;
  rep(i, n-1){
    ll a,b;cin>>a>>b;
    a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  dfs(-1, 0, 0);

  vector<int> num[3];
  rep1(i, n)num[i%3].push_back(i);

  vector<int> result(n);

  if(group[0].size() <= n/3){
    for(auto tmp: group[0]){
      result[tmp] = num[0].back();
      num[0].pop_back();
    }
    for(auto tmp: group[1]){
      rep(i, 3){
        if(num[i].empty())continue;
        result[tmp] = num[i].back();
        num[i].pop_back();
        break;
      }
    }
    rep(i, n)cout<<result[i]<<' ';
    return 0;
  }

  swap(group[0], group[1]);

  if(group[0].size() <= n/3){
    for(auto tmp: group[0]){
      result[tmp] = num[0].back();
      num[0].pop_back();
    }
    for(auto tmp: group[1]){
      rep(i, 3){
        if(num[i].empty())continue;
        result[tmp] = num[i].back();
        num[i].pop_back();
        break;
      }
    }
    rep(i, n)cout<<result[i]<<' ';
    return 0;
  }

  rep1(i, 2){
    for(auto tmp:group[i-1]){
      if( !num[i].empty() ){
        result[tmp] = num[i].back();
        num[i].pop_back();
      }else{
        result[tmp] = num[0].back();
        num[0].pop_back();
      }
    }
  }
  rep(i, n)cout<<result[i]<<' ';

  return 0;
}

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

int main(){
  int N;
  cin >> N;
  int flo[N+1];
  for(int i=1;i<=N;i++){
    cin >> flo[i];
  }
  
  int sum=flo[1];
  for(int i=2;i<=N;i++){
  	if(flo[i]>flo[i-1]){
		sum += (flo[i]-flo[i-1]);
    }
  }
  
  cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<limits>
#include<string.h>
#include<vector>
#include<stack>
#include<queue>
using namespace std;

int main()
{
    int n;
    cin>>n;
    vector<int> l(n);
    for (int i = 0; i < n; i++)
    {
        cin>>l[i];
    }
    sort(l.begin(), l.end());
    int count=0;
    for (int i = 0; i < n-2; i++)
    {
        for (int j = i+1; j < n-1; j++)
        {
            for (int k = j+1; k < n; k++)
            {
                if (l[k]<(l[i]+l[j]))
                {
                    count++;
                }
                
            }
            
        }
        
    }
    cout<<count<<endl;
    
    

    return 0;
}

Measured memory_bytes: 3164
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
int main() {
	int n;
	std::cin >> n;
	
	int ans = 0, tmph = 0, p;
	
	for (int i = 0; i < n; i++) {
	    std::cin >> p;
	    if(tmph < p) tmph = p;
	    ans += p;
	}
	
	std::cout << ans - tmph / 2 << std::endl;
	
}

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

int main(void)
{
    int n,v;
    cin >> n;
    set<int> st;
    multiset<int> mul;
    for (int i = 0; i < n; i++) {
	int u;
	cin >> u;
	st.insert(u);
	mul.insert(u);
    }
    int cou = 0;
   set<int>::iterator  it = st.begin();

    for (int i = 0; i < st.size(); i++) {
	    v=*it;
	if (v <= mul.count( v)) {
	    cou += mul.count( v);
	    cou-=v;
	}
	else {
	    cou +=mul.count(v);
	}
	++it;
    }
    cout << cou << endl;
    return 0;
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){std::fill( (T*)array, (T*)(array+N), val );};
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;};



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

  string s;
  cin >> s;
  bool f = 1;
  rep(i, s.size()) {
    if(i % 2 == 0) {
      if(s[i] == 'L') f = 0;
    } else {
      if(s[i] == 'R') f = 0;
    }
  }
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

int main(){

int n;
cin >> n;

vector<int> x(n);
rep(i, n) {
    cin >> x.at(i);
}

int ma,mi;
long long sum;
ma = -1000001, mi =1000001; sum =0;

rep(i, n){
    if(ma < x.at(i)) ma = x.at(i);
    if (mi> x.at(i)) mi = x.at(i);
    sum += x.at(i);
}

cout << mi << ' ' << ma << ' ' << sum <<endl;

}


Measured memory_bytes: 3128
#include<stdio.h>
#include<string.h>
#include<algorithm>
const int MAXL = 1e4 + 10;
using namespace std;
char str[MAXL];
char substr[5 * MAXL][10];
int id[5 * MAXL];
int m;
bool cmp(int a, int b) {
	return strcmp(substr[a], substr[b]) < 0;
}
int main() {
	while (scanf("%s", str) != EOF) {
		int L = strlen(str);
		scanf("%d", &m);
		int cnt = 0;
		for (int j = 0; j < m; j++) {
			for (int i = 0; i < L - j; i++) {
				for (int k = 0; k <= j; k++) {
					substr[cnt][k] = str[i + k];
				}
				substr[cnt++][j + 1] = 0;
			}
		}

		for (int i = 0; i < cnt; i++) {
			id[i] = i;
		}

		sort(id, id + cnt, cmp);

		int t = 0;
		while (m  > 1 && t < cnt) {
			while (t + 1 < cnt && strcmp(substr[id[t]], substr[id[t + 1]]) == 0)
				t++;
			m--;
			t++;
		}
		printf("%s\n", substr[id[t]]);
	}
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=55;
bool mark[N];
bool g[N][N];
VI e1[N],e2[N],e[N];
int q[N],deg[N],skip,n,u,v,ans,_;
void dfs1(int u,int f) {
	mark[u]=1;
	skip++;
	for (auto v:e1[u]) if (v!=f) {
		if (g[u][v]) {
			dfs1(v,u);
		}
	}
}
void dfs2(int u,int f) {
	for (auto v:e1[u]) if (v!=f) {
		dfs2(v,u);
		if (!mark[u]) e[v].pb(u);
	}
}
void dfs3(int u,int f) {
	for (auto v:e2[u]) if (v!=f) {
		dfs3(v,u);
		if (!mark[u]) e[u].pb(v);
	}
}
bool check() {
//	puts("chk");
	rep(u,1,n+1) for (auto v:e[u]) {
		deg[v]++;
//		printf("%d %d\n",u,v);
	}
	int t=0;
	rep(u,1,n+1) if (deg[u]==0) q[t++]=u;
	rep(i,0,t) {
		int u=q[i];
		for (auto v:e[u]) {
			--deg[v];
			if (deg[v]==0) q[t++]=v;
		}
	}
	return t==n;
}
void solve() {
	scanf("%d",&n);
	rep(i,1,n+1) {
		e1[i].clear(),e2[i].clear();
		rep(j,1,n+1) g[i][j]=0;
	}
	rep(i,1,n) {
		scanf("%d%d",&u,&v);
		e1[u].pb(v); e1[v].pb(u);
	}
	rep(i,1,n) {
		scanf("%d%d",&u,&v);
		e2[u].pb(v); e2[v].pb(u);
		g[u][v]=g[v][u]=1;
	}
	ans=n+1;
	rep(i,1,n+1) {
		rep(j,1,n+1) mark[j]=0;
		skip=0;
		dfs1(i,0);
		rep(j,1,n+1) e[j].clear(),deg[j]=0;
		dfs2(i,0);
		dfs3(i,0);
		if (check()) ans=min(ans,n-skip);
	}
	rep(i,1,n+1) if (SZ(e1[i])==1) rep(i2,1,n+1) {
		rep(j,1,n+1) e[j].clear(),deg[j]=0,mark[j]=0;
		dfs2(i2,0);
		dfs3(i,0);
		if (check()) {
			ans=min(ans,n);
		}
	}
	if (ans==n+1) ans=-1;
	printf("%d\n",ans);
}
int main() {
	for (scanf("%d",&_);_;_--) {
		solve();
	}
}


Measured memory_bytes: 256
fn main() {
    let a: usize = read();
    let b: usize = read();

    if b == 1 {
        println!("0");
        return
    }

    let mut n: usize = a;
    let mut cnt = 1;
    while n < b {
        n += a - 1;
        cnt += 1;
    }
    println!("{}", cnt);
}

use std::io::stdin;
use std::io::Read;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let token: String = cin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


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

map<string, int> memo;

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

	int n;
	cin >> n;
	for(int i=0; i<n; i++) {
		string s;
		cin >> s;
		memo[s]++;
	}
		
	int maxn=0;
	for(auto &x:memo) {
		int v=x.second;
		maxn=max(v, maxn);
	}

	for(auto it=memo.begin(); it != memo.end(); it++) {
		if(it->second==maxn)
			cout << it->first << endl;
	}

		
    return 0;
}


Measured memory_bytes: 23808
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
#define P pair<ll, ll>

string s[10] = {"pon", "pon", "hon", "bon", "hon", "hon", "pon", "hon", "pon", "hon"};
int main(){
    ll n;
    cin >> n;
    n %= 10;
    cout << s[n] << endl;
}



Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <functional>

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define fst first
#define snd second
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cout << #x << ": " << x << endl
const int MOD = 1000000007;
const int INF = 100100100;
const double EPS = 0.000000001;

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  if(N & 1){
    cout << (N-1) * (N-3) / 2 + (N-1) << endl;
    FOR(i, 1, N){
      FOR(j, i+1, N+1){
        if(j != (N - i)) cout << i << ' ' << j << endl;
      }
    }
  }
  else{
    cout << N * (N-2) / 2 << endl;
    FOR(i, 1, N){
      FOR(j, i+1, N+1){
        if(j != (N + 1 - i)) cout << i << ' ' << j << endl;
      }
    }
  }
  return 0;
}


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


#define all(v)           ((v).begin()), ((v).end())
#define sz size()
#define clr(v,d)         memset(v,d,sizeof(v))
#define lp(i, n)         for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)     for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)     for(int i=(j);i>=(int)(n);--i)
#define sci(a)	scanf("%d",&a)
#define scll(a)	scanf("%lld",&a)
#define scii(a, b)	scanf("%d%d",&a, &b)
#define pri(a)	printf("%d\n",a)
#define prll(a)	printf("%lld\n",a)
	

const int maxn = 300500;

typedef long long ll;

typedef pair<int, int> pii;

int h[maxn], dp[maxn];


int main() {
	//freopen("in.in", "r", stdin);	
	int n; sci(n);
	lp(i, n) sci(h[i + 1]);
	memset(dp, 63, sizeof dp);
	dp[1] = 0;
	lpi(i, 1, n + 1){
		dp[i + 1] = min(dp[i + 1], abs(h[i + 1] - h[i]) + dp[i]);
		dp[i + 2] = min(dp[i + 2], abs(h[i + 2] - h[i]) + dp[i]);
	}
	pri(dp[n]);
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#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 fio(s) freopen(s".inp","r",stdin)
#define foo(s) freopen(s".out","w",stdout)
#define task "test"
using namespace std;
typedef long long LL;
const int N=100009;
int n,f[N],h[N];
int main(){
    //fio(task); foo(task);
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n; For(i,1,n) cin>>h[i];h[0]=h[1];
    For(i,2,n)
        f[i]=min(f[i-1]+abs(h[i]-h[i-1]),f[i-2]+abs(h[i]-h[i-2]));
    cout<<f[n];
    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<set>
#include<map>
#include<vector>
#include<queue>
#define fi first
#define se second
#define L(i,u) for (int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (int i=a; i<=b; i++)
#define per(i,a,b) for (int i=a; i>=b; i--)
#define read(x) scanf("%d",&x)
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
const int N = 233333;
int n;
ll qz[N];
map<ll,int> Map;
int main() { int x;
	read(n); rep(i,1,n) {read(x); qz[i]=qz[i-1]+x;}
	Map[0]++; ll res=0;
	rep(i,1,n) {
		res+=Map[qz[i]]; Map[qz[i]]++;
	}
	cout<<res;
	return 0;
}



Measured memory_bytes: 14336
#!/usr/bin/env python3

def main():
    n = int(input())
    cs = []
    ss = []
    fs = []
    for i in range(n - 1):
        c, s, f = map(int, input().split())
        cs.append(c)
        ss.append(s)
        fs.append(f)

    for i in range(n):
        t = 0
        for j in range(i, n - 1):
            t = cs[j] + next_depart(ss[j], fs[j], t)
        print(t)

def next_depart(s, f, now):
    mi = max(s, now)
    for t in range(mi, mi + f):
        if t % f == 0:
            return t
    raise Exception

main()


Measured memory_bytes: 3064
N = int(input())
A = list(map(int, input().split()))
abs_A = list(map(abs, A))

cnt = 0
for v in A:
    if v < 0:
        cnt += 1

if 0 in A or cnt%2 == 0:
    print(sum(abs_A))
else:
    print(sum(abs_A)-2*min(abs_A))


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	while(true){
		string S=in<string>();
		if(S=="0") break;
		ll sum = 0;
		REP(i,S.size()){
			sum += (ll)(S[i]-'0');
		}
		out(sum);
	}

	return 0;
}



Measured memory_bytes: 3164
//B - Iroha Loves Strings: 2Min;
//Assunto: Sort;
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100050
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int a, b, c;
    vector<int> show(8, 0);
    cin >> a >> b >> c;
    show[a]++; show[b]++; show[c]++;
    if(show[5] == 2 and show[7] == 1) cout << "YES\n";
    else cout << "NO\n";
}

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

int main(){
    int a, b;
    scanf("%d %d", &a, &b);
    if(a < b) printf("%s\n", "a < b");
    else if(a == b) printf("%s\n", "a == b");
    else printf("%s\n", "a > b"); 
    return 0;
}

Measured memory_bytes: 1008
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n, k;
    cin >> n >> k;

    vector<ll> num(k, 0);
    for (int i = 1; i <= n; i++) num[i % k]++;
    ll res = 0;
    for (int a = 0; a < k; a++) {
        int b = (k - a) % k;
        int c = (k - a) % k;
        if ((b + c) % k != 0) continue;
        res += num[a] * num[b] * num[c];
    }
    cout << res << endl;

    return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
vpint G[222222];

int L;
vpint ei[222222];

void dfs(int v){
    ei[v].clear();
    if(G[v].size()==0){
        ei[v].pb({0,0});
        return;
    }

    int u=G[v][0].fi;
    int w=G[v][1].fi;

    int c=G[v][0].se;
    int d=G[v][1].se;

    dfs(u);
    dfs(w);
    if(ei[u].size()==0||ei[w].size()==0)return;

    if(ei[u].size()<ei[w].size()){
        swap(u,w);
        swap(c,d);
    }

    vpint vec;
    int cur=0;
    rep(i,ei[w].size()){
        while(cur<ei[u].size()&&ei[u][cur].se+c+ei[w][i].fi+d>L)cur++;
        if(cur==ei[u].size())break;
        pint p(ei[u][cur].fi+c,ei[w][i].se+d);
        if(vec.size()&&vec.back()>=p)vec.pop_back();
        vec.pb(p);
    }

    vpint vec2=vec;
    reverse(all(vec2));
    rep(i,vec2.size())swap(vec2[i].fi,vec2[i].se);

    int cur2;
    cur=cur2=0;

    while(cur!=vec.size()||cur2!=vec2.size()){
        pint p;
        if(cur2==vec2.size()||(cur!=vec.size()&&vec[cur]<=vec2[cur2]))p=vec[cur++];
        else p=vec2[cur2++];

        if(ei[v].size()&&ei[v].back().se<=p.se)continue;
        ei[v].pb(p);
    }
}

bool C(int l){
    L=l;
    dfs(0);
    if(ei[0].size())return true;
    return false;
}

signed main(){
    scanf("%lld",&N);
    for(int i=1;i<N;i++){
        int a,v;
        scanf("%lld%lld",&a,&v);
        a--;
        G[a].pb({i,v});
    }

    int lb=-1,ub=1ll<<40;
    while(ub-lb>1){
        int mid=(ub+lb)/2;
        if(C(mid))ub=mid;
        else lb=mid;
    }

    cout<<ub<<endl;
    return 0;
}


Measured memory_bytes: 38332
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1125

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

int main() 
{
	int N, W, H, S, T;
		
	while(cin >> N && N)
	{
		cin >> W >> H;
		int field[H][W];
		fill_n((int *)field, sizeof(field) / sizeof(int), 0);
		
		rep(i,N)
		{
			int x,y;
			cin >> x >> y;
			field[y-1][x-1] = 1;
		}

		cin >> S >> T;
		
		int count=0, ans=0;
		rep(t,H-T+1)
		{
			rep(s,W-S+1)
			{
				count=0;
				rep(y,T)
				{
					rep(x,S)
					{
						if(field[y+t][x+s] == 1){count++;}	
					}
				}
				ans = max(ans,count);
			}
		}
		cout << ans << endl;

	}
	return 0;
}

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

int main(){
	string s, t;
	cin >> s >> t;
	if(s[0] == t[2] && s[1] == t[1] && s[2] == t[0]) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
n,gw=map(int,input().split())

V=[]
W=[]

for i in range(n):
	v,w=map(int,input().split())
	V.append(v)
	W.append(w)

DP=[[0]*(gw+1) for i in range(n+1)]

for i in range(n):
	for j in range(gw+1):
		if j-W[i]<0:
			DP[i+1][j]=DP[i][j]
		else:
			DP[i+1][j]=max(DP[i][j],DP[i][j-W[i]]+V[i])

print(DP[n][gw])


Measured memory_bytes: 25492
#include <iostream>
#include <cmath>

#define ll long long
#define MAX 3010

using namespace std;
ll mod,dp[3010][3010],f[3010]={0},cnk[3010][3010];
ll pw(ll a, ll b) {
	ll ans = 1; 
	while (b) {
		while (b%2==0){
			b /= 2;
			a = (a * a) % mod;
		}
		ans = (ans * a) % mod;
		--b;
	}
	return ans;
}

long long inv[MAX],fact[MAX],fi[MAX];
void inverse(){
	int i;
	inv[1] = 1;
	for(i=2;i<MAX;i++){
		inv[i] = mod - (mod/i)*inv[mod%i]%mod;
	}
}

void factinv(){
	int i;
	fact[0] = fi[0] = 1;
	for(i=1;i<MAX;i++){
		fact[i] = fact[i-1]*i%mod;
		fi[i] = (fi[i-1]*inv[i])%mod;
	}
}

long long comb(int n,int k){
	if(n<0 || k<0 || n<k){
		return 0;
	}else{
		return fact[n]%mod*fi[k]%mod*fi[n-k]%mod;
	}
}

int main(){
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	ll i,j,n;
	cin >> n >> mod;
	for(i=0;i<=n;i++){
		for(j=0;j<=n;j++){
			dp[i][j] = 0;
		}
	}

	dp[0][0] = 1;
	for(i=1;i<=n;i++){
		for(j=0;j<=i;j++){
			if(j==0){
				dp[i][j] = 1;
			}else{
				dp[i][j] = (dp[i-1][j-1] + (j+1)*dp[i-1][j]%mod)%mod;
			}
		}
	}

	for(i=0;i<=n;i++){
		mod--;
		ll x = pw(2,(n-i));
		mod++;
		ll y = pw(2,x);
		ll z = pw(2,(n-i));
		for(j=0;j<=i;j++){
			f[i] += y*pw(z,j)%mod*dp[i][j]%mod;
			f[i] = f[i]%mod;
		}
	}

	ll ans = 0,u = -1;
	inverse();
	factinv();
	for(i=0;i<=n;i++){
		cnk[n][i] = comb(n,i);
	}
	
	for(i=0;i<=n;i++){
		ll k = cnk[n][i]*f[i]%mod;
		u *= -1;
		ans += u*k;
		ans = (ans+mod)%mod;
	}
	
	cout << ans << endl;
}


Measured memory_bytes: 74112
#include<bits/stdc++.h>
#define int long long int
using namespace std;
int32_t main(){
	int n;
	cin>>n; 
	vector<int> v(n); 
	unordered_map<int,int> hash; 
	for(auto &it:v){
		cin>>it; 
		hash[it]++;
	} 
	int ans = 0; 
	for(auto &it:hash){
		ans = ans + (it.second)*(it.second-1)/2;
	} 
	for(int i=0;i<n;i++){
		int flag = ans ; 
		flag = flag - hash[v[i]]*(hash[v[i]]-1)/2; 
		flag = flag + (hash[v[i]]-1)*(hash[v[i]]-2)/2;
		cout<<flag<<endl;
	}
}

Measured memory_bytes: 9160
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    def check(i,j):
        if(i>=j): return False
        d=sum((X[i][k]-X[j][k])**2 for k in range(D))**.5
        return d==int(d)

    n,D=map(int,input().split())
    X=[list(map(int,input().split())) for _ in range(n)]
    from itertools import product
    print(sum(check(i,j) for i,j in product(range(n),repeat=2)))
resolve()

Measured memory_bytes: 38384
n, m, x = map(int, input().split())
a = list(map(int, input().split()))

a.append(x)
a.sort()
x_index = a.index(x)


leftCost = len(a[0:x_index])
rightCost = len(a[x_index + 1:m+1])

print(min(rightCost, leftCost))


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll X;
    cin >> X;
    ll ans = 1;
    rep2(i, 2, X + 1) {
        for (ll x = i * i; x <= X; x*=i) {
            ans = max(ans, x);
        }
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,x;
    cin >> a >> b >> x;
    if(a + b >= x && a <= x)
    {
        cout << "YES";
    }
    else
    {
        cout << "NO";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int infty = 1e9;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<pair<int, pair<int, int>>> cmngrh;
  vector<pair<char, pair<int, pair<int, int>>>> addgrh;
  for (int i = 1; i < n; i++) {
    cmngrh.push_back({0, {i, 0}});
  }
  int ans = -1;
  for (int i = 0; i < m; i++) {
    string qtx;
    cin >> qtx;
    int a(0), b(0), d(0);
    char ord('$'), inq('$');
    int phase = 0;
    for (int j = 0; j < qtx.length(); j++) {
      if (qtx[j] - '0' < 0 || 10 <= qtx[j] - '0') {
        if (!(phase & 1)) {
          phase++;
        }
        char* it;
        switch (phase) {
          case 1:
            it = &ord;
            break;
          case 3:
            it = &inq;
            break;
          default:
            break;
        }
        if (*it == '$') {
          *it = qtx[j];
        }
      } else {
        if (phase & 1) {
          phase++;
        }
        int* it;
        switch (phase) {
          case 0:
            it = &a;
            break;
          case 2:
            it = &b;
            break;
          case 4:
            it = &d;
            break;
          default:
            break;
        }
        *it *= 10;
        *it += qtx[j] - '0';
      }
    }
    a--;
    b--;
    if (ord == '*') {
      addgrh.push_back({inq, {d, {a, b}}});
      continue;
    }
    if (ord == '>') {
      swap(a, b);
    }
    if (ord != '*') {
      cmngrh.push_back({0, {b, a}});
    }
    if (inq == '+') {
      swap(a, b);
      d *= -1;
    }
    cmngrh.push_back({d, {a, b}});
  }
  for (int bs = 0; bs < 1 << addgrh.size(); bs++) {
    vector<pair<int, pair<int, int>>> grh = cmngrh;
    for (int i = 0; i < addgrh.size(); i++) {
      auto crr = addgrh[i];
      char inq = crr.first;
      int d = crr.second.first;
      int s = crr.second.second.first;
      int t = crr.second.second.second;
      if (bs & (1 << i)) {
        swap(s, t);
      }
      grh.push_back({0, {t, s}});
      if (inq == '+') {
        swap(s, t);
        d *= -1;
      }
      grh.push_back({d, {s, t}});
    }
    int diam = 0;
    vector<int> dst(n, infty);
    dst[0] = 0;
    for (int i = 0; i < n; i++) {
      for (auto e : grh) {
        int d = e.first;
        int s = e.second.first;
        int t = e.second.second;
        if (dst[s] != infty) {
          dst[t] = min(dst[t], dst[s] + d);
        }
      }
    }
    for (int i = 0; i < n; i++) {
      diam = max(diam, dst[i]);
    }
    for (int i = 0; i < n; i++) {
      for (auto e : grh) {
        int d = e.first;
        int s = e.second.first;
        int t = e.second.second;
        if (dst[s] != infty && dst[t] > dst[s] + d) {
          diam = -1;
        }
      }
    }
    ans = max(ans, diam);
  }
  if (ans == infty) {
    cout << "inf" << '\n';
  } else {
    cout << ans << '\n';
  }
  return 0;
}


Measured memory_bytes: 3244
#!/usr/bin/env python3
from itertools import combinations
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
MOD = 10**9 + 7

n = int(input())
cost = []
for i in range(n):
    cost.append([int(item) for item in input().split()])
score = [0] * 2**n
for i in range(1, 2**n):
    lsb = i & -i
    index = lsb.bit_length() - 1
    other = i ^ lsb
    diff = 0
    for j in range(n):
        if other & 1 << j:
            diff += cost[index][j]
    score[i] = score[other] + diff

memo = [-1] * 2**n
memo[0] = 0
for i in range(n):
    memo[1<<i] = 0

def dfs(st):
    if memo[st] != -1:
        return memo[st]
    sst = st
    val = score[st] 
    while True:
        sst = (sst - 1) & st
        if sst == 0:
            break
        val = max(val, dfs(sst) + dfs(sst ^ st))
    memo[st] = val
    return val

ret = dfs(2**n - 1)
print(ret)

Measured memory_bytes: 46172
#include <iostream>
#include <math.h>
#include <algorithm>
#define ll long long int
#define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n)

using namespace std;

int main()
{
    int n;
    cin >> n;
    int p[n];
    REP(i, n)
    {
        cin >> p[i];
    }
    int c = 0;
    FOR(i, 1, n-1)
    {
        if (p[i - 1] < p[i] && p[i] < p[i + 1])
            c++;
        else if (p[i - 1] > p[i] && p[i] > p[i + 1])
            c++;
    }
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i = (x); i < (n); ++i)
const long long mod = 1e9+7;
int main(void)
{
    int n, m;
    cin >> n >> m;
    vector<bool> ok(n+1,true);
    REP(i,0,m){
        int a;
        cin >> a;
        ok[a] = false;
    }
    vector<long long> dp(n+1);
    dp[0]=1;
    REP(now,0,n)REP(next,now+1,min(n,now+2)+1){
        if(ok[next]){
            dp[next] += dp[now];
            dp[next] %= mod;
        }
    }
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 3980
#include<iostream>
#include<string>
#include <cmath>
#include <ctype.h>
#include<vector>
#include<algorithm>
using namespace std;
string s;
vector<int> v;
int main() {
    cin >> s;
    int n=s.size();
    if(n%2!=0) n=n-1;
    for(int i=n-2; i>=0; i-=2){
        if(s.substr(0,i/2)==s.substr(i/2, i/2)){
            cout << i << endl;
            break;
        }
    }
    return 0;
}

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

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int  MOD=1000000007;
const int  INF= int(1e9);

int main()
{
	ios_base::sync_with_stdio(false);
    for(int i=1;i<=9;i++) {
        for(int j=1;j<=9;j++) {
            cout<<i<<"x"<<j<<"="<<i*j<<endl;
        }
    }
	return 0;

}

Measured memory_bytes: 1156
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;
ll n,k;
vector<ll> a;

bool check(ll d){
    vector<ll> dp(k,0);
    if(a[d]>=k) return  true;
    for(ll i=0;i<n;i++){
        if(i!=d){
            vector<ll> dp_sub(k,0);
            for(ll j=0;j<k-1;j++){
                if(j==0 or dp[j]!=0){
                    if(j+a[i]<k){
                        dp_sub[j+a[i]]=1;
                    }else{
                        break;
                    }
                }
            }
            for(ll j=0;j<k;j++){
                if(dp_sub[j]==1){
                    dp[j]=1;
                    if(j+a[d]>=k) return true;
                }
            }
        }
    }
    return false;
}

signed main(){
    cin >> n >> k;
    a.resize(n);
    for(ll i=0;i<n;i++){cin >> a[i];}
    sort(a.begin(),a.end());
    ll l=0;ll r=n-1;
    while(l+1<r){
        ll d=floor(l+r)/2;
        if(check(d)){
            r=d;
        }else{
            l=d;
        }
    }
    if(check(l)){
        cout << l << endl;
    }else if(check(r)){
        cout << r << endl;
    }else{
        cout << r+1 << endl;
    }
}


Measured memory_bytes: 384
///not today

#include<bits/stdc++.h>
using namespace std;

#define SZ(x) (int)(x).size()
#define pb push_back
#define ll long long
#define xmax(x, y) (x) = max((x), (y))
#define xmin(x, y) (x) = min((x), (y))
#define F first
#define S second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define int long long
#define pipii pair<int, pair<int, int> >
#define pf push_front

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

int32_t main(){
    int n, ans = INT_MAX/ 2;
    cin >>n;
    for(int i = 1; i < n; i ++){
        int j = n - i;
        xmin(ans, f(j) + f(i));
    }
    cout <<ans <<endl;
}


Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

map<int, int> memo;
int solve(int n)
{
	if(memo.count(n))
		return memo[n];
	if(n == 1)
		return 0;
	return memo[n] = 1 + (n%2==0 ? solve(n/2) : solve(n*3+1));
}

int main()
{
	int n;
	while(scanf("%d", &n), n){
		printf("%d\n", solve(n));
	}
	
	return 0;
}

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

using namespace std;

int main()
{
	int N, M;
	cin >> N >> M;
	vector<vector<int>> vec(M);
	for (int i = 0; i < M; i++) 
	{
		int k; 
		cin >> k;
		vec[i].resize(k);
		for (int j = 0; j < k; j++)
		{
			cin >> vec[i][j];
			vec[i][j]--;
		}
	}
	vector <int> p(M);
	for (int i = 0; i < M; i++) 
		cin >> p[i];
	int ans = 0;
	for (int i = 0; i < (1 << N); i++) 
	{
		bool on = true;
		for (int j = 0; j < M; j++) 
		{
			int c = 0;
			for (auto x : vec[j]) 
			{
				if ((i >> x) & 1)  
					c++;
			}
			c %= 2;
			if (c != p[j]) 
				on = false;
		}
		if (on)
			ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <cstdio>
using namespace std;
int a[200011];

bool check(long long x, long long y,long long z){
    
    long long sum = x+z;
    
    long long tmp = y^z;
    
    if(sum==tmp) return true;
    return false;

}
int main(int argc, const char * argv[]) {
    
    int n;
    
    scanf("%d",&n);
    
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    
    
    int l = 0;
    int r = 0;
    long long tmp = a[l];
    long long xo = a[l];
    long long ans = 0;
    while(r<n){
        if(l==r){
            tmp = a[l];
            xo = a[l];
            r++;
          
        }
        else if(check(tmp,xo,a[r])){
            ans+= r-l;
            tmp += a[r];
            xo ^= a[r];
            r++;
            
        }else{
            tmp-=a[l];
            xo = tmp;
            l++;
        }
        
    }
    
    printf("%lld\n",ans+n);
    
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
#include <sstream>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
using namespace std;

typedef long long ll;
static const double PI = 4.0 * atan(1.0);
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin();itr!=c.end();itr++)
#define EPS (1e-8)
bool ISINT(double x){return fabs(x-(ll)x)<EPS;}
bool ISEQ(double x,double y){return fabs(x-y)<EPS;}
string itos(ll n){stringstream ss;ss<<n;return ss.str();}

int main() {
  int n;

  while (cin >> n) {
    string t[3];
    for (int i = 0; i < 3; i++) {
      cin >> t[i];
    }
    int ans = 0;
    for (int j = 0; j < n; j++) {
      set<char> st;
      for (int i = 0; i < 3; i++) {
        st.insert(t[i][j]);
      }
      ans += st.size() - 1;
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
using System;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        int N = sc.NextInt();
        int[] P = sc.IntArray();

        int min = int.MaxValue;
        int cnt = 0;
        foreach (int i in P)
        {
            if (i < min)
            {
                min = i;
                cnt++;
            }
        }
        Console.WriteLine(cnt);
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

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

int main(){
    int n; cin >> n;
    string S; cin >> S;
    vector<vector<int> > lis(n, vector<int>(2, 0));
    int e = 0, w = 0;
    for(int i = 0; i < S.size(); i++){
        if(S[i] == 'E'){
            e++;
        }else{
            w++;
        }
        lis[i][0] = e;
        lis[i][1] = w;
    }
    int ans = 1e7; 
    for(int i = 0; i < S.size(); i++){
        int mid = lis[i][1] + e - lis[i][0];
        if(S[i] == 'W'){
            mid--;
        }
        ans = min(ans, mid);
    }
    cout << ans << endl;
}

Measured memory_bytes: 17028
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

from fractions import gcd

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap



@mt
def slv(N, A):
    L = [A[0]]
  
    for a in A[1:]:
        L.append(gcd(L[-1], a))
        
    R = [-1] * N
    R[-1] = A[-1]
    for i in range(N-2, -1, -1):
        R[i] = gcd(R[i+1], A[i])
    
    ans = 0
    for i in range(N):
        if i == 0:
            ans = max(ans, R[i+1])
        elif i == N-1:
            ans = max(ans, L[i-1])
        else:
            ans = max(ans, gcd(L[i-1], R[i+1]))
    return ans
    


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 16492
#include<iostream>
using namespace std;
#define INFTY 1000000001
#define Max 500000

int cnt = 0;

void mergeSort(int a[], int left, int right);
void merge(int a[], int left, int mid, int right);

int main() {
    int n;
    cin >> n;
    int a[Max];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    mergeSort(a, 0, n);
    for (int i = 0; i < n; i++) {
        if (i) cout << " ";
        cout << a[i];
    }
    cout << endl;
    cout << cnt << endl;
    return 0;
}
void mergeSort(int a[], int left, int right) {
    if (left < right-1) { //have more than 2
        int mid = (left + right) / 2;
        mergeSort(a, left , mid); //divide
        mergeSort(a, mid, right);
        merge(a, left, mid, right); //sort
    }
}
void merge(int a[], int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    int L[n1], R[n2];
    for (int i = 0; i < n1; i++) L[i] = a[left+i];
    for (int i = 0; i < n2; i++) R[i] = a[mid+i];
    L[n1] = INFTY; R[n2] = INFTY;
    int i = 0, j = 0;
    for (int k = left; k < right; k++) { //merge sort
        //left = 0   right = n
        cnt++;
        if (L[i] <= R[j]) { //be careful!
            a[k] = L[i++]; //stable
        } else {
            a[k] = R[j++];
        }
    }
}



Measured memory_bytes: 6920
(function () {
   var input = '';

   function main () {
     var a, b, nums,
         TSUBO = 3.305785;
     
     nums = input.split(' ');
     a = parseInt(nums[0], 10);
     b = parseInt(nums[1], 10);
     
     console.log(a * b / TSUBO);
   }

   process.stdin.resume();
   process.stdin.setEncoding('utf8');
   process.stdin.on('data', function (chunk) {
     input += chunk;
   });

   process.stdin.on('end', function () {
     input.split('\n');
     main();
   });
}());

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

int main(){
  string S;
  cin >> S;
  int mind = 0;

  for (int i = 0; i < 4; i++){
    if (S.at(i) == '+'){
      mind += 1;
    }
    else
    {
      mind -= 1;
    }
    
  }

  cout << mind << endl;
}

Measured memory_bytes: 3580
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 1; i <= n; i++)
#define rep0(i,n) for(int i = 0; i < n; i++)
#define rep0n(i,n) for(int i = 0; i <= n; i++)
#define MAX_N 50
#define INF 12345678

int n, ma, mb, a[MAX_N], b[MAX_N], c[MAX_N], dp[MAX_N][MAX_N*12][MAX_N*12] = {}, ans = INF;
signed main(){
	
	cin>>n>>ma>>mb;
	
	rep0n(i,n)rep0(j,n*11)rep0(k,n*11)dp[i][j][k] = INF;
	
	dp[0][0][0] = 0;
	
	rep(i,n){
		cin>>a[i]>>b[i]>>c[i];
		rep0n(j,i*10){
			rep0n(k,i*10){
				dp[i][j][k] = min(dp[i][j][k], dp[i-1][j][k]);
				// rep(l,i){
					int l = i;
					// if(dp[i-1][j][k] ==INF) continue;
					dp[i][j+a[i]][k+b[i]] = min(dp[i][j+a[i]][k+b[i]], dp[i-1][j][k] + c[i]);
				// }
			}
		}
		// rep(j,6){
		// rep(k,6){
			// cout<<i<<" "<<j<<" "<<" "<<k<<" "<<dp[i][j][k]<<endl;
		// }cout<<endl;
	// }cout<<endl;
	}
	
	rep(i,n*10){
		rep(j,n*10){
			if(mb*i == ma*j){
				ans = min(ans, dp[n][i][j]);
			}
		}//cout<<endl;
	}//cout<<endl;
	
	cout<<(ans==INF?-1:ans)<<endl;
	
	return 0;
}


Measured memory_bytes: 57216
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    int n;
    cin >> n;
    multiset<ll> st;
    ll a;
    REP(i,n){
        cin >> a;
        auto itr = st.lower_bound(a);
        if(itr == st.begin()) st.insert(a);
        else{
            itr--;
            st.erase(itr);
            st.insert(a);
        }
    }
    cout << st.size() << endl;
    return 0;
}

Measured memory_bytes: 4992
n,d=[int(x) for x in input().split()]
xy=[]
for _ in range(n):
    xy.append([int(x) for x in input().split()])
ans=0
for xy2 in xy:
    x,y=xy2
    if (x**2+y**2)**0.5<=d:
        ans+=1

print(ans)


Measured memory_bytes: 42652
import sys
for e in sys.stdin:
 p,q,r,s,t,u,x,y=map(float,e.split())
 f=lambda h,i,j,k:(h-p)*(i-q)-(j-q)*(k-p)
 a,b=f(x,u,y,t)/f(r,u,s,t),f(x,s,y,r)/f(t,s,u,r)
 print(['NO','YES'][0<a<1-b and 0<b<1-a])


Measured memory_bytes: 5588
N=int(input())
A=list(map(int,input().split()))
i=N-1
while(i>=0):
    print(A[i],end=" ")
    i-=2
if i==-2:
    i=1
else:
    i=0
while(i<N):
    print(A[i],end=" ")
    i+=2
print()


Measured memory_bytes: 94036
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		
		int height=stdIn.nextInt();
		int width=stdIn.nextInt();
		
		String [] s=new String[height];
		
			for(int i=0;i<height;i++){
				s[i]=stdIn.next();
			}
		
		
		char[][] c=new char[height][width];
		
		for(int i=0;i<height;i++){
			for(int j=0;j<width;j++){
				c[i][j]=s[i].charAt(j);
			}
		}
		for(int i=0;i<height*2;i++){
			for(int j=0;j<width;j++){
				System.out.print(c[i/2][j]);
			}
			System.out.println();
		}

	}

}


Measured memory_bytes: 15772
#include <stdio.h>

long long fact4(int a, int b, int c, int d, int e, int f) {
	long long ans = 1;
	int bunsi[2001];
	int bunbo[2001];
	int i,j,p;
	int prime[14] = { 2,3,5,7,11,13,17,19,23,29,31,37,41,43 };
	for (i = 0; i <= 2000; i++) {
		bunsi[i] = 0;
		bunbo[i] = 0;
	}
	int maxa = -1;
	int sic;
	int boc;
	int val;
	if (a > maxa) maxa = a;
	if (b > maxa) maxa = b;
	for (i = 2; i <= maxa; i++) {
		sic = 0;
		boc = 0;
		if (i <= a) sic++;
		if (i <= b) sic++;
		if (i <= c) boc++;
		if (i <= d) boc++;
		if (i <= e) boc++;
		if (i <= f) boc++;
		val = i;
		for (p = 0; p < 14; p++) {
			while (val % prime[p] == 0) {
				val /= prime[p];
				bunsi[prime[p]] += sic;
				bunbo[prime[p]] += boc;
			}
		}
		bunsi[val] += sic;
		bunbo[val] += boc;
	}
	for (i = 0; i <= 2000; i++) {
		bunsi[i] -= bunbo[i];
		bunbo[i] = 0;
		for (j = 0; j < bunsi[i]; j++) {
			ans = (ans*i) % 1000000007;
		}
	}
	return ans;
}

int main()
{
	int i, n, k, v;
	long long blue, red, ans;
	scanf("%d%d", &n, &k);
	v = n - k;
	for (i = 1; i <= k; i++) {
		if (i>v + 1) {
			printf("0\n");
		}
		else {
			//blue=fact(k-1)/fact(k-i)/fact(i-1);
			//red=fact(v+1)/fact(v+1-i)/fact(i);
			ans = fact4(k - 1, v + 1, k - i, i - 1, v + 1 - i, i);
			printf("%lld\n", ans % 1000000007);
		}
	}
	return 0;
}

Measured memory_bytes: 128