akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector <ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <vector<ll>> vv;
typedef vector <string> vs;
typedef vector <char> vc;


ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;

#define Endl endl


/*--------------------template--------------------*/


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

}

Measured memory_bytes: 764
n = int(input())
in_list = []
for i in range(n):
    in_list.append(list(map(int, input().split())))

matrices = [["0" for _ in range(n)] for _ in range(n)]

for i in range(n):
    inp = in_list[i]
    u = inp[0]
    k = inp[1]
    for j in range(k):
        m = inp[j+2]
        matrices[i][m-1] = "1"

for i in range(n):
    print(" ".join(matrices[i]))


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) (1 + (int)(a - 1)/(int)(b))
//#define int long long

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

Measured memory_bytes: 256
#!/usr/bin/env Python3
import collections
import itertools as it
import math
#import numpy as np

s = input()
#  = int(input())
#  = map(int, input().split())
#  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

print('Yes' if len(set(s)) != 1 else 'No')


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  string s;
  cin >> s;
  vi32 used(26, false);
  rep(i, s.size()) used[s[i] - 'a'] = true;
  if (s.size() < 26) {
    int idx = -1;
    rep(i, 26) if (!used[i]) { idx = i; break; }
    cout << s << (char) (idx + 'a') << endl;
  } else {
    if (s == "zyxwvutsrqponmlkjihgfedcba") {
      cout << -1 << endl;
      return 0;
    }
    string t = s;
    next_permutation(all(t));
    rep(i, 26) {
      cout << t[i];
      if (s[i] != t[i]) break;
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
//Let's join Kaede Takagaki Fan Club !!
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
template<class T>
void dmp(T a){
	rep(i,a.size()) cout << a[i] << " ";
	cout << endl;
}
template<class T>
bool chmax(T&a, T b){
	if(a < b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
bool chmin(T&a, T b){
	if(a > b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 1000000007;//998244353
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}

int main(){
	int a, b, c, d; cin >> a >> b >> c >> d;
	while(1){
		c -= b; if(c <= 0) return !puts("Yes");
		a -= d; if(a <= 0) return !puts("No");
	}
}

Measured memory_bytes: 3632
#include<stdio.h>

int main()
{
  int n, d, x, a[100];

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

  int ans;

  for(int i = 0; i < n; i++){
    int count = 0;
    while(1){
      if(count * a[i] + 1 <= d){
        ans++;
        count++;
      }else{
        break;
      }
    }
  }

  ans = ans + x;

  printf("%d", ans);

  return 0;
}


Measured memory_bytes: 128
n,k=map(int,input().split())
a=list(map(int,input().split())) 
 
x=[0]*(n)
before = 0
now = 0
while x[now] == 0:
    x[now]=1+x[before]
    before=now
    now = a[now]-1
    
y=x[now]-x[0]
z=x[before]-y
if k>y:
    l=(k-y)%z+1
else :
    l=k-y+1
for i in range(n):
    if x[i] == l+y:
        print(1+i)
        break

Measured memory_bytes: 32324
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
typedef long long ll;
struct edge { ll s, t, x; };
typedef pair<ll, ll> P;
typedef pair<double, P> event;
const ll MAX = 510000;
const ll MOD = 1000000007;
#define INF (ll)10000000000000000

int main() {
  ll N;
  cin>>N;
  vector<ll>A(N);
  ll money=1000ll;
  ll num=0ll;
  rep(i,N){
    cin>>A[i];
  }
  int memo[N];
  //-1は売り時(A)、1は買い時(V)
  if(A[0]>A[1]){memo[0]=1;}
  if(A[0]==A[1]){memo[0]=0;}
  if(A[0]<A[1]){memo[0]=-1;}
  for(int i=0;i<N-2;i++){
    if(A[i]>=A[i+1]&&A[i+1]<A[i+2]){memo[i+1]=-1;}
    else if(A[i]<=A[i+1]&&A[i+1]>A[i+2]){memo[i+1]=1;}
    else{memo[i+1]=0;}
  }
  memo[N-1]=1;
  rep(i,N){
    if(memo[i]==-1){
      ll p=money/A[i];
      money-=p*A[i];
      num+=p;
    }
    if(memo[i]==1){
      money+=num*A[i];
      num=0ll;
    }
  }
  cout<<money;
}

Measured memory_bytes: 3624
def main():
    ans = int(input())
    op = input()
    while op != '=':
        b = int(input())
        if op == '+':
            ans += b
        elif op == '-':
            ans -= b
        elif op == '*':
            ans *= b
        elif op == '/':
            ans //= b
        op = input()
    else:
        print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5596
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < int(n); i++)
#define FOR(i,n,m) for(int i = int(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 1e18 + 1;
 
int main() {
    int t1, t2; cin >> t1 >> t2;
    ll a1, a2, b1, b2; cin >> a1 >> a2 >> b1 >> b2;
    if (a1 > b1 && a2 < b2) {
        if (b1 * t1 + b2 * t2 - (a1 * t1 + a2 * t2) < 0) {
            cout << 0 << endl;
            return 0;
        }
        else if (b1 * t1 + b2 * t2 - (a1 * t1 + a2 * t2) == 0) {
            cout << "infinity" << endl;
            return 0;
        }
        double k = 1.0*(a1 - b1)*t1 / ((b2 - a2)*t2 + (b1 - a1)*t1);
        if ((a1 - b1)*t1 % ((b2 - a2)*t2 + (b1 - a1)*t1) != 0) {
            cout << ll(2LL * ll(k)) + 1 << endl;
        }
        else {
            cout << ll(2LL * ll(k)) << endl;
        }
    }
    else if (a1 < b1 && a2 > b2) {
        swap(a1, b1);
        swap(a2, b2);
        if (b1 * t1 + b2 * t2 - (a1 * t1 + a2 * t2) < 0) {
            cout << 0 << endl;
            return 0;
        }
        else if (b1 * t1 + b2 * t2 - (a1 * t1 + a2 * t2) == 0) {
            cout << "infinity" << endl;
            return 0;
        }
        double k = 1.0*(a1 - b1)*t1 / ((b2 - a2)*t2 + (b1 - a1)*t1);
        if ((a1 - b1)*t1 % ((b2 - a2)*t2 + (b1 - a1)*t1) != 0) {
            cout << ll(2LL * ll(k)) + 1 << endl;
        }
        else {
            cout << ll(2LL * ll(k)) << endl;
        }
    }
    else {
        cout << 0 << endl;
    }
    return 0;
}

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b; cin>>a>>b;
	for (int i=1; i<=a; i++)
		if (a>b) cout<<b;	
	for (int i=1; i<=b; i++)
		if (a<=b) cout<<a;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(),(x).end()
#define pushb push_back()
#define popb pop_back()
#define makep make_pair
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
int main(){
    int n,q;cin>>n>>q;
    string s;cin>>s;
    vector<int> count(n,0);
    rep(i,1,n){
        if(s[i]=='C'){
            if(s[i-1]=='A'){
                count[i]=1;
            }
        }
        count[i]+=count[i-1];
    }
    rep(i,q){
        int r,l;cin>>l>>r;
        r--;
        l--;
        int ans=count[r]-count[l];
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 1408
#include <cstdio>

using namespace std;

int main() {
    int W, H, x, y, r;
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

    if (x < 0 || y < 0) {
        printf("No\n");
    }
    else if (x + r <= W && y + r <= H) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}



Measured memory_bytes: 2684
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb push_back;
#define sp " ";
void vout(vector<int> v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    string s,fr,ba;
    int q;
    int count=1;
    cin>>s>>q;
    rep(i,q){
        int t;
        cin>>t;
        if(t==1) count*=-1;
        else{
            int f;
            char c;
            cin>>f>>c;
            if(count>0){
                (f==1?fr=c+fr:ba=ba+c);
            }
            else{
                (f==1?ba=ba+c:fr=c+fr);
            }
        }
    }
    if(count<0){ 
    reverse(s.begin(),s.end());
    reverse(fr.begin(),fr.end());
    reverse(ba.begin(),ba.end());
    cout<<ba<<s<<fr<<endl;
    }
    else{
        cout<<fr<<s<<ba<<endl;
    }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
void solve()
{
    int n;
    cin>>n;
    map<int,string> m;
    m[0]="pon";m[1]="pon";m[2]="hon";
    m[3]="bon";m[4]="hon";m[5]="hon";m[6]="pon";
    m[7]="hon";m[8]="pon";m[9]="hon";
    cout<<m[n%10]<<endl;
    
    
}
int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define MAXN 100001
vector<ll> vec;
int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        ll a;
        cin >> a;
        vec.push_back(a);
    }
    sort(vec.begin(), vec.end());
    ll ret = 0;
    if (n % 2 == 0) {
        for (int i = 0; i <= n / 2 - 2; i++) {
            ret -= vec[i] * 2;
        } 
        for (int i = n / 2 + 1; i <= n - 1; i++) {
            ret += vec[i] * 2;
        }
        ret = ret + vec[n / 2] - vec[n / 2 - 1]; 
    }
    else {
        ll ret1 = 0;
        ll ret2 = 0;
        // 足す方を増やす時
        for (int i = 0; i <= n / 2 - 2; i++) {
            ret1 -= vec[i] * 2;
        }
        for (int i = n / 2 + 1; i <= n - 1; i++) {
            ret1 += vec[i] * 2;
        }
        ret1 = ret1 - vec[n / 2] - vec[n / 2 - 1]; 
        //引く方を増やす時
        for (int i = 0; i <= n / 2 - 1; i++) {
            ret2 -= vec[i] * 2;
        }
        for (int i = n / 2 + 2; i <= n - 1; i++) {
            ret2 += vec[i] * 2;
        }
        ret2 = ret2 + vec[n / 2 + 1] + vec[n / 2]; 
        ret = max(ret1, ret2);
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 4292
N, A, B = map(int, input().split()) 

if N <= A:
    print(N)
elif N <= (A + B):
    print(A)
elif N % (A + B) <= A:
    print((N // (A + B))*A + (N % (A + B)))
else:
    print((N // (A + B))*A + A)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

const int N = 1e5 + 5;
ll x[N], y[N];
ll sum[N], best[N];
int n;
ll C;


ll chk() {
    ll calorie = 0;
    for (int i = 1; i <= n; ++i) {
        calorie += y[i];
        best[i] = max(best[i - 1], calorie - x[i]);
    } 

    memset(sum, 0, sizeof sum);
    ll rv = 0;
    x[n + 1] = C;
    calorie = 0;
    for (int i = n + 1; i >= 1; i--) {
        calorie += y[i];
        rv = max(rv, best[i - 1] + calorie - 2 * (C - x[i]));
    } 
    return rv;
}

int main() {
    cin >> n >> C;
    for (int i = 1; i <= n; ++i) {
        cin >> x[i] >> y[i];
    }

    ll res = chk();
    reverse(x + 1, x + 1 + n);
    for(int i = 1; i <= n; ++i) x[i] = C - x[i];
    reverse(y + 1, y + 1 + n);
    res = max(res, chk());
    cout << res << endl;
}

Measured memory_bytes: 3328
using System;

class A_B_Program
{
	public static void Main()
	{
		Math m = new Math();
		
		string number_str = Console.ReadLine();
		string[] number_tmp = number_str.Split(' ');
		int a = int.Parse(number_tmp[0]);
		int b = int.Parse(number_tmp[1]);
		
		m.quotient1(a,b);
		m.remainder(a,b);
		m.quotient2(a,b);
		
	}
}

class Math
{
	public void quotient1(int a,int b)
	{
		Console.Write(a/b+" ");
	}
	
	public void remainder(int a,int b)
	{
		Console.Write(a%b+" ");
	}
	
	public void quotient2(int a,int b)
	{
        double c = (double)a / b;
        Console.WriteLine("{0:.00000}",c);    
    }
}

Measured memory_bytes: 9292
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define dbg(x) { cerr<<"> "<<#x<<": "<<x<< endl; }
#define dbg2(x,y) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int inf = INT_MAX;
const double eps = 0.0000001;
const double PI = acos(-1.0);
const int MOD = 1e9+7;
const int N  = 1e5+5;

int a[N][3], sum[N][3];

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

    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    	cin >> a[i][0] >> a[i][1] >> a[i][2];
    for (int i = 1; i <= n; i++) {
    	for (int j = 0; j < 3; j++) {
    		sum[i][j] = 0;
    		for (int k = 0; k < 3; k++) {
    			if (k != j) {
    				sum[i][j] = max(sum[i][j], sum[i-1][k]);
    			}
    		}
    		sum[i][j] += a[i][j];
    	}
    }
    cout << max({sum[n][0], sum[n][1], sum[n][2]});
    return 0;
}

Measured memory_bytes: 4992
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        n: usize,
        m: usize,
        v: usize,
        p: usize,
        a: [usize; n],
    }
    let mut a = a;
    a.sort();
    a.reverse();

    let mut acc = vec![0; n];
    for i in p..n {
        acc[i] = acc[i - 1] + a[i - 1];
    }
    // println!("{:?}", acc);

    let mut result = 0;
    for i in 0..n {
        if a[i] >= a[p - 1] {
            result += 1;
        } else if a[i] + m < a[p - 1] {
            break;
        } else {
            let left = p - 1;
            let right = n - i;
            // println!(" {} {} {}", v, left, right);
            if v > left + right {
                let remains = v - left - right;
                let target = a[i] + m;
                let d = (i - p + 1) * target - acc[i];
                // println!(" {} {}", d, remains * m);
                if d >= remains * m {
                    result += 1;
                }
            } else {
                result += 1;
            }
        }
        // println!("{} {}", i, result);
    }
    println!("{}", result);
}


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

typedef long long ll;

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    vector<ll> a(n+1,0);
    for(i = 1;i <= n;++i){
        cin >> a.at(i);
    }
    int m = 0;
    vector<int> box(n+1,0);
    vector<int> b;
    for(i = n;i >= 1;--i){
        int tmp = 0;
        for(j = 2*i;j <= n;j += i){
            tmp += box.at(j);
        }
        if(a.at(i) == tmp%2){
            continue;
        }else{
            box.at(i) = 1;
            ++m;
            b.push_back(i);
        }
    }
    cout << m << endl;
    for(i = 0;i < m;++i){
        cout << b.at(i) << endl;
    }
    return 0;
}

Measured memory_bytes: 3832
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;

const long long INF = 1LL << 60;
const ll MOD = ll(1e9)+7;


int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

ll vector_finder(vector<ll> vec, ll number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  if (itr == vec.end()) {
    return -1;
  }
  size_t index = std::distance( vec.begin(), itr );
  return index;
}

bool has_key_using_find(unordered_map<ll, string> &m, ll n){
    if (m.find(n) == m.end()){
        return false;
    }
    else{
        return true;
    }
}

ll enum_divisors(ll N) {
    ll count = 0;
    for (ll i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            count++;
            if (N/i != i) count++;
        }
    }
    return count;
}


vector<pair<ll, ll> > prime_factorize(ll N) {
    vector<pair<ll, ll> > res;
    for (ll a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        ll ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}

bool IsPrime(int num) {
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }

    return true;
}


int main() {
    ll N;
    cin >> N;
    ll ans = 0;

    string operation = "";
    cin >> operation;


    vector<string> c(N);

    ll wnum = 0;
    ll rnum = 0;

    for (ll i = 0; i < N; i++) {
        c.at(i) = operation.at(i);

        if (c.at(i) == "W") {
            wnum++;
        } else if (c.at(i) == "R") {
            rnum++;
        }
    }

    // cout << wnum << " " << rnum << endl;

    for (ll i = 0; i < N; i++) {

        if (rnum <= 0) break;

        rnum--;
        if (c.at(i) == "W") {
            ans++;
        }
    }
    


    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 9788
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            var nk = ReadLine().Split(' ').Select(int.Parse).ToArray();
            var p = ReadLine().Split(' ').Select(double.Parse).ToArray();
            var expectedValues = GetExpected(p);
            var expectedCumulative = new double[expectedValues.Length + 1];
            expectedCumulative[0] = 0d;
            for (var i = 1; i < expectedCumulative.Length; i++)
            {
                expectedCumulative[i] = expectedValues[i - 1] + expectedCumulative[i - 1];
            }

            var max = 0d;
            for (var i = nk[1]; i < expectedCumulative.Length; i++)
            {
                max = Math.Max(max, expectedCumulative[i] - expectedCumulative[i - nk[1]]);
            }
            WriteLine($"{max:F12}");
        }

        static double[] GetExpected(double[] array)
        {
            var expectedValue = new double[array.Length];
            for (var i = 0; i < array.Length; i++)
            {
                expectedValue[i] = (1d + array[i]) / 2d;
            }

            return expectedValue;
        }
    }
}

Measured memory_bytes: 37980
#include <iostream>
#include <iomanip>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    int n;
    cin >> n;
    int two = 0, four = 0;
    repi(i, n, 0)
    {
        int a;
        cin >> a;
        if (a % 2 == 0)
            two++;
        if (a % 4 == 0)
            four++;
    }
    two -= four;
    if (four > 0)
    {
        if (four * 2 + two / 2 * 2 + 1 >= n)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    else
    {
        if (four * 2 + two / 2 * 2 >= n)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
#define tget(a,b) get<a>(b)
using namespace std;
typedef long long ll;
const ll INF = 1e17;
const int MOD = 1e9 + 7;

map<char, bool> mp;
string a;
int ans;
int main(void) {
	cin >> a;
	FOR(i, 0, a.size()) {
		mp[a[i]]=true;
	}
	if (a.size() != 26) {
		FOR(i, 'a', 'z' + 1) {
			if (mp[i] == false) {
				ct(a + char(i));
				return 0;
			}
		}
	}
	else {
		for (int i = 24; i >= 0; i--) {
			char mi = a[i], cur = 'z'+1;
			FOR(k, i + 1, 27) {
				if (mi<a[k] && cur>a[k])cur = a[k];
			}
			if (cur == 'z' + 1)continue;
			swap(a[i], cur);
			ct(a.substr(0, i+1));
			return 0;
		}
	}
	ct(-1);
	return 0;
}


Measured memory_bytes: 256
H,W=list(map(int,raw_input().strip().split(' ')))
grid=[]
for _ in xrange(H):
    grid+=[raw_input()]

block_h=[]
for i in xrange(H):
    temp=[-1]
    for j in xrange(W):
        if grid[i][j]=="#":
            temp+=[j]
    temp+=[W]
    block_h+=[temp]

block_c=[]
for j in xrange(W):
    temp=[-1]
    for i in xrange(H):
        if grid[i][j]=="#":
            temp+=[i]
    temp+=[H]
    block_c+=[temp]

#print(block_h)
#print(block_c)
import bisect
MAX=0
for i in xrange(H):
    for j in xrange(W):
        #print(i,j)
        ans=0
        if grid[i][j]==".":
            post=bisect.bisect_right(block_c[j],i)
            #print(post)
            a1=block_c[j][post-1]
            a2=block_c[j][post]
            ans+=a2-a1-1

            post=bisect.bisect_right(block_h[i],j)
            #print(post)
            a1=block_h[i][post-1]
            a2=block_h[i][post]
            ans+=a2-a1-1            
            MAX=max(MAX,ans)
print(MAX-1)




Measured memory_bytes: 103452
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

const char ops[] = "+-*";

int op(int a, int o, int b) {
    if (o == 0) return a + b;
    if (o == 1) return a - b;
    if (o == 2) return a * b;
    return -1;
}

bool check1(int n[4], int i, int j, int k) {
    if (op(op(n[0], i, n[1]), j, op(n[2], k, n[3])) == 10) {
        printf("((%d %c %d) %c (%d %c %d))\n",
            n[0], ops[i], n[1], ops[j], n[2], ops[k], n[3]);
        return true;
    }
    return false;
}

bool check2(int n[4], int i, int j, int k) {
    if (op(n[0], i, op(n[1], j, op(n[2], k, n[3]))) == 10) {
        printf("(%d %c (%d %c (%d %c %d)))\n",
            n[0], ops[i], n[1], ops[j], n[2], ops[k], n[3]);
        return true;
    }
    return false;
}

bool check3(int n[4], int i, int j, int k) {
    if (op(n[0], i, op(op(n[1], j, n[2]), k, n[3])) == 10) {
        printf("(%d %c ((%d %c %d) %c %d))\n",
            n[0], ops[i], n[1], ops[j], n[2], ops[k], n[3]);
        return true;
    }
    return false;
}

bool check4(int n[4], int i, int j, int k) {
    if (op(op(n[0], i, op(n[1], j, n[2])), k, n[3]) == 10) {
        printf("((%d %c (%d %c %d)) %c %d)\n",
            n[0], ops[i], n[1], ops[j], n[2], ops[k], n[3]);
        return true;
    }
    return false;
}

bool check5(int n[4], int i, int j, int k) {
    if (op(op(op(n[0], i, n[1]), j, n[2]), k, n[3]) == 10) {
        printf("(((%d %c %d) %c %d) %c %d)\n",
            n[0], ops[i], n[1], ops[j], n[2], ops[k], n[3]);
        return true;
    }
    return false;
}

int main(void) {
    int n[4];
    while (true) {
        bool z = true;
        for (int i = 0; i < 4; i++) {
            cin >> n[i];
            if (n[i] != 0) z = false;
        }
        if (z) break;
        sort(n, n + 4);
        do {
            for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 3; j++) {
                    for (int k = 0; k < 3; k++) {
                        if (check1(n, i, j, k)) goto success;
                        if (check2(n, i, j, k)) goto success;
                        if (check3(n, i, j, k)) goto success;
                        if (check4(n, i, j, k)) goto success;
                        if (check5(n, i, j, k)) goto success;
                    }
                }
            }
        } while (next_permutation(n, n + 4));
        cout << 0 << endl;
        success: continue;
    }
    return 0;
}

Measured memory_bytes: 1212
#include <stdio.h>

void solve(int n, int a);


int main()
{
  int n, a;
  scanf("%d %d", &n, &a);
  solve(n, a);

  return 0;
}

void solve(int n, int a)
{
  int temp;

  temp = n % 500;
  if (temp <= a)
    {
      printf("Yes\n");
    }
  else
    {
      printf("No\n");
    }
}


Measured memory_bytes: 128
using System;
using System.Linq;

namespace AtCoderContest
{
    class Program
    {
        static void Main()
        {
            Console.ReadLine();
            var s = Console.ReadLine();

            var max = 0;
            var current = 0;
            foreach(var c in s)
            {
                current += c == 'I' ? 1 : -1;
                
                if (max < current)
                {
                    max = current;
                }
            }

            Console.WriteLine(max);
        }
    }
}


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

int main()
{
    int N, M, a, b;
    cin >> N >> M;
    vector<int> ans(N);
    for (int i = 0; i < M;i++){
        cin >> a >> b;
        ans.at(a - 1)++;
        ans.at(b - 1)++;
    }
    for (int i = 0; i < N;i++){
        cout << ans.at(i) << endl;
    }
}

Measured memory_bytes: 256
from collections import deque
h,w = map(int,input().split())
maze = []
def mazecal(hs,ws):
    calmaze = [[-1 for _ in range(w)] for _ in range(h)]
    que = deque([[hs,ws,0]])
    smax = 0
    while len(que)!=0:
        cur = que.popleft()
        calmaze[cur[0]][cur[1]] = cur[2]
        smax = max(smax,cur[2])
        if cur[0]>0   and maze[cur[0]-1][cur[1]]==0:
            if calmaze[cur[0]-1][cur[1]] ==-1 or calmaze[cur[0]-1][cur[1]] > cur[2]+1:
                calmaze[cur[0]-1][cur[1]] = cur[2]+1
                que.append([cur[0]-1,cur[1],  cur[2]+1])
        if cur[0]<h-1 and maze[cur[0]+1][cur[1]]==0:
            if calmaze[cur[0]+1][cur[1]] ==-1 or calmaze[cur[0]+1][cur[1]] > cur[2]+1:
                calmaze[cur[0]+1][cur[1]] = cur[2]+1
                que.append([cur[0]+1,cur[1],  cur[2]+1])
        if cur[1]>0   and maze[cur[0]][cur[1]-1]==0:
            if calmaze[cur[0]][cur[1]-1] ==-1 or calmaze[cur[0]][cur[1]-1] > cur[2]+1:
                calmaze[cur[0]][cur[1]-1] = cur[2]+1
                que.append([cur[0]  ,cur[1]-1,cur[2]+1])
        if cur[1]<w-1 and maze[cur[0]][cur[1]+1]==0:
            if calmaze[cur[0]][cur[1]+1] ==-1 or calmaze[cur[0]][cur[1]+1] > cur[2]+1:
                calmaze[cur[0]][cur[1]+1] = cur[2]+1
                que.append([cur[0]  ,cur[1]+1,cur[2]+1])
    return smax

for i in range(h):maze.append([0 if c=='.' else 1 for c in input()])
gmax = 0
for i in range(h):
    for j in range(w):
        if maze[i][j]==0:gmax = max(gmax,mazecal(i,j))
print(gmax)

Measured memory_bytes: 3444
#include<stdio.h>

#define MAX 100000

int partition( int A[] , int p , int r ){
	
	int x;
	int i;
	int temp;
	
	x = A[r];
	i = p - 1;
	
	for( int j = p; j < r; j++ ){
		
		if( A[j] <= x ){
			i++;
			temp = A[i];
			A[i] = A[j];
			A[j] = temp;
		}
		
	}
	
	temp = A[i+1];
	A[i+1] = A[r];
	A[r] = temp;
	
	return i + 1;
	
}

int main( void ){
	
	int n;
	int A[MAX];
	int q;
	
	scanf( "%d" , &n );
	
	for( int i = 0; i < n; i++ ){
		scanf( "%d" , &A[i] );
	}
	
	q = partition( A , 0 , n-1 );
	
	//printf( "%d\n" , A[q] );
	
	for( int i = 0; i < n; i++ ){
		
		if( i >= 1 ){ printf( " " ); }
		
		if( i == q ){
			printf( "[%d]" , A[i] ); 
		}else{ printf( "%d" , A[i] ); }
		
	}
	
	printf( "\n" );
	
}



Measured memory_bytes: 2080
#include <iostream>
#include <string>
using namespace std;
#define rep(a,b) for(int a=0;a<b;a++)
int main() {
	int n;
	cin >> n;
	int ans=0;
	rep(i, n) {
		int a;
		cin >> a;
		ans += a - 1;
	}
	cout << ans << endl;
}



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

int main(){
	int A,B,C;
	cin >> A >> B >> C;
	if(A == B){
      if(B == C){
        cout << "No" << endl;
      }else{
        cout << "Yes" << endl;
      }
    }else{
      if(B == C || A == C){
		cout << "Yes" << endl;
      }else{
        cout << "No" << endl;
      }
    }
  
  return(0);
        
}

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

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

		if (n == 0) {
			break;
		}

		int sum = 0;
		int max = 0;
		int min = 1000;
		for (int i = 0; i < n; i++) {
			int s;
			cin >> s;

			sum += s;
			if (s > max) {
				max = s;
			}
			if (s < min) {
				min = s;
			}
		}

		cout << (sum - max - min) / (n - 2) << endl;
	}

	return 0;
}

Measured memory_bytes: 2980
n,www = map(int,input().split())
v,w=[],[]
for i in range(n):
    vv,ww = map(int,input().split())
    v.append(vv)
    w.append(ww)

dp=[0 for j in range(www+1)]
#dp[i][j] = i-1番目(0-index)までの品物の中から重さがjを超えないように選んだ時の価値の最大値

for i in range(n):
    dpp = dp[:]
    for j in range(www+1):
        if (w[i] > j): continue
        dpp[j] = max(dpp[j],dpp[j-w[i]] + v[i])
    dp = dpp[:]

print(dp[www])


Measured memory_bytes: 6448
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

#C
n,m = LI()
v = LIR(m)
p2 = [1]
for i in range(n):
    p2.append(p2[-1]*2)
dp = [[0 for i in range(p2[n])] for j in range(n)]
dp[0][1] = 1
for i in range(1,p2[n]):
    for k in range(n):
        for a,b in v:
            a -= 1
            b -= 1
            if k==a or k == b:
                c = p2[a]
                d = p2[b]
                if i&c and not i&d:
                    dp[b][i|d] += dp[k][i]
                if (not i&c) and i&d:
                    dp[a][i|c] += dp[k][i]
ans = 0
for i in range(1,n):
    ans += dp[i][-1]
print(ans)
#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 3700
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,N) for(int i = 0;i < (int)(N);i++)
 main(){
ll a,b,k;
  cin>>a>>b>>k;
  ll x=0;
  ll y=0;
  if(k<=a){
    x=a-k;
      y=b;
  }
   if(a<k&&k<=a+b){
      y=a+b-k;
  }
  cout<<x<<" "<<y<<endl;
}
    








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

int main()
{
 int n;
  cin >> n;
  string s;
  cin >> s;
  for (int i = 0;i < s.length(); i++)
    cout << (char)(((s[i] - 'A' + n) % 26) + 'A');
  cout << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
ans = 0
if N == M == 1:
	ans = 1
elif N == 1 and M >= 2:
	ans = M - 2
elif N >= 2 and M == 1:
	ans = N - 2
else:
	ans = (N - 2) * (M - 2)
print(ans)

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


int main(){
	char s[222];
	cin >> s;
	int n = strlen(s);
	for(int i = n-2; i; i-=2){
        if(strncmp(s, s+i/2, i/2) == 0){
            cout << i << endl;
            return 0;
        }
	}
}


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

using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	
	vector<int> x(n);
	for(auto itr = x.begin(); itr != x.end(); itr++)
	{
		cin >> *itr;
	}
	
	int ans = 0;
	for(int i = 0; i < n; i++)
	{
		int distance = (x[i] - k > 0) ? x[i] - k : k - x[i];
		if(x[i] <= distance)
		{
			ans += 2*x[i];
		}
		else
		{
			ans += 2*distance;
		}
	}
	
	cout << ans << endl;
	return 0;
}

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

int main() {
    string S;
    cin >> S;

    string res;
    if(S == "Sunny") res = "Cloudy";
    else if(S == "Cloudy") res = "Rainy";
    else res = "Sunny";

    cout << res << endl; 

    return 0;
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
prev = -100
for i in range(n):
    now = A[i] - 1
    ans += B[now]
    if (now - prev) == 1:
        ans += C[prev]
    
    prev = now

print(ans)


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

const ll mod = 1000000007;
const double eps = 1e-8;

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

int main() {
    ll N, A, B;
    cin >> N >> A >> B;

    ll res = (N / (A+B)) * A;
    res += min(N % (A+B), A);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
const int MAX = 2e5+1;

int main(){
  ll n, k;
  cin >> n >> k;
  int a[n];
  rep(i,n) cin >> a[i];
  vector<set<int>> s(MAX);
  rep(i,n) {
    s[a[i]].insert(i);
    s[a[i]].insert(i+n);
  }
  s[a[0]].insert(2*n);
  vector<int> t(2*n+1);
  for(int i = n; i <= 2*n; i++) t[i] = i-n;
  for(int i = n-1; i >= 0; i--) {
    auto itr = s[a[i]].upper_bound(i);
    t[i] = t[*itr+1];
  }
  vector<int> p(n+1), q(n+1);
  rep(i,n+1) p[i] = i;
  ll d = k-1;
  while(d > 0) {
    if(d % 2) {
      rep(i,n+1) p[i] = t[p[i]];
    }
    rep(i,n+1) q[i] = t[t[i]];
    rep(i,n+1) t[i] = q[i];
    d /= 2;
  }
  int pos = p[0];
  vector<int> ans;
  while(pos < n) {
    auto itr = s[a[pos]].upper_bound(pos); 
    if(*itr >= n) {
      ans.push_back(a[pos]);
      pos++;
    } else {
      pos = *itr + 1;
    }
  }
  for(auto k : ans) cout << k << " ";
  cout << endl;
  return 0;
}


Measured memory_bytes: 34424
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	while(1)
	{
		c-=b;
		if(c<=0)
		{
			cout<<"Yes";
			break;
		}
		a-=d;
		if(a<=0)
		{
			cout<<"No";
			break;
		}
	}
}  

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
using namespace std;


int main(){
	int n,m;
	cin >> n >> m;
	
	vector<pair<int,int> > arm(m);
	for(int i=0; i<m; i++){
		int x,y;
		cin >> x >> y;
		arm[i]=make_pair(y,x);
	}
	sort(arm.begin(), arm.end());
	
	vector<int> lb(n+1, 1e9);
	vector<bool> used(m, false);
	for(int i=1; i<=n; i++){
		int lane=i;
		int position=0;
		while(1){
			vector<pair<int,int> >::iterator it;
			it = lower_bound(arm.begin(), arm.end(), make_pair(lane, position));
			if(it == arm.end() || it->first!=lane || used[it-arm.begin()]){
				lb[lane] = min(i, lb[lane]);
				break;
			}
			
			used[it-arm.begin()] = true;
			lb[lane] = min(i, lb[lane]);
			lane++;
			position = it->second;
		}
	}
	
	for(int i=0; i<m; i++){
		arm[i].first = -arm[i].first;
		used[i]=false;
	}
	sort(arm.begin(), arm.end());
	vector<int> ub(n+1, 0);
	for(int i=n; i>0; i--){
		int lane=i;
		int position=0;
		while(1){
			vector<pair<int,int> >::iterator it;
			it = lower_bound(arm.begin(), arm.end(), make_pair(-(lane-1), position));
			if(it == arm.end() || it->first!=-(lane-1)|| used[it-arm.begin()]){
				ub[lane] = max(i, ub[lane]);
				break;
			}
			
			used[it-arm.begin()] = true;
			ub[lane] = max(i, ub[lane]);
			lane--;
			position = it->second;
		}
	}
	
	for(int i=1; i<n; i++){
		cout << ub[i]-lb[i]+1 << " ";
	}
	cout << ub[n]-lb[n]+1 << endl;
	
	return 0;
}

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


int main() {
    string n;
    cin >> n ;
    int s=0;
    for (int i=0; i<n.size(); i++) {
        s += (int) (n[i] - '0');
    }
    if (s%9 == 0) {
        cout << "Yes" << endl;
        return 0;
    } 
    cout << "No" << endl;
    return 0;
}

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

#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define aint(c) begin(c),end(c)
#define mt make_tuple

using ll=long long;
using vi=vector<int>;
using vl=vector<int>;

constexpr int INF=1e9;

struct Edge{
	int u,v,w;
	Edge(){}
	Edge(int u,int v,int w):u(u),v(v),w(w){}
};
using Tree=vector<vector<Edge>>;

vector<tuple<int,int>> dfs(const Tree& t,int x,int p)
{
	if(t[p].empty()) return {mt(0,0)};
	auto e0=t[p][0],e1=t[p][1];
	auto s0=dfs(t,x,e0.v),s1=dfs(t,x,e1.v);

	vector<tuple<int,int>> res;
	rep(_,2){
		for(int i=0,j=0;i<s0.size();i++){
			int a,b; tie(a,b)=s0[i];
			for(;j<s1.size();j++){
				int c,d; tie(c,d)=s1[j];
				if(e0.w+b+c+e1.w>x) break;
			}
			if(j>0){
				int d=get<1>(s1[j-1]);
				res.emplace_back(e0.w+a,d+e1.w);
			}
		}
		swap(e0,e1); swap(s0,s1);
	}

	sort(aint(res),[](auto a,auto b){return a<b;});
	res.erase(unique(aint(res),[](auto a,auto b){return get<1>(a)<=get<1>(b);}),end(res));
	return res;
}

bool ok(const Tree& t,int x)
{
	return dfs(t,x,0).size();
}

int main()
{
	for(int n;cin>>n&&n;){
		Tree t(n);
		rep(i,n-1){
			int u,v=i+1,w; cin>>u>>w; u--;
			t[u].emplace_back(u,v,w);
		}
		int lo=-1,hi=INF;
		while(hi-lo>1){
			int mi=(lo+hi)/2;
			(ok(t,mi)?hi:lo)=mi;
		}
		cout<<hi<<endl;
	}
}


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


int main() {
  
  int N;
  
  cin>>N;
  
  
  vector<char> S(N);
for (int i = 0; i < N; i++) {
  cin >> S.at(i);
}
  
  vector<char> T(N);
for (int i = 0; i < N; i++) {
  cin >> T.at(i);
}
  
  for (int i = 0; i < N*2; i++) {
    if(i%2==0){
      cout<<S.at(i/2);
    }else{
      cout<<T.at(i/2);
    }
  
}
  
  cout<<endl;
  
  
  
  
}




Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int n, i;
    int R[1000000];
    int max, min, maxv;

    scanf("%d", &n);
    for (i = 0; i < n; i++)
        scanf("%d", &R[i]);
    maxv = -999999999;
    min = R[0];

    for (i = 1; i < n; i++)
    {

       if(maxv < R[i]-min)
       {
           maxv = R[i]-min;
       }
    
        if(min > R[i])
        {
            min = R[i];
        }

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


Measured memory_bytes: 2516
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <climits>
#include <bitset>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef unsigned int ui;

typedef vector<ull> vull;
typedef vector<ll> vll;
typedef vector<ui> vui;
typedef vector<long> vl;
typedef vector<int> vi;

typedef pair<ull, ull> pull;
typedef pair<ll, ll> pll;
typedef pair<ui, ui> pui;
typedef pair<long, long> pl;
typedef pair<int, int> pi;

template <class T>
void printv(vector<T> vc) {
    for (auto e: vc) cout << e << " ";
    cout << endl;
}

int main() {
    int a, b, c, d; cin >> a >> b >> c >> d;
    cout << max(a * b, c * d) << endl;
    return 0;
}

Measured memory_bytes: 888
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // 入力
        MyScanner sc = new MyScanner(System.in);
        String S = sc.nextString();

        // 初期化

        // 主処理
        String tmp = S;
        tmp = tmp.replaceAll("eraser", "");
        tmp = tmp.replaceAll("erase", "");
        tmp = tmp.replaceAll("dreamer", "");
        tmp = tmp.replaceAll("dream", "");
        String ans = "".equals(tmp) ? "YES" : "NO";

        // 出力
        System.out.println(ans);
    }

    static class MyScanner {
        BufferedReader br;
        // 標準入力から入力値を取得
        MyScanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
        }
        // 標準入力を文字列で取得
        public String nextString() throws IOException {
            return br.readLine();
        }
        // 標準入力を文字列の配列で取得
        public String[] nextStringArray() throws IOException {
            return nextString().split(" ");
        }
        // 標準入力を数値で取得
        public int nextInt() throws IOException {
            return Integer.parseInt(nextString());
        }
        // 標準入力を数値の配列で取得
        public int[] nextIntArray() throws IOException {
            String[] strArr = nextStringArray();
            int[] intArr = new int[strArr.length];
            for(int i = 0; i < strArr.length; i++) {
                intArr[i] = Integer.parseInt(strArr[i]);
            }
            return intArr;
        }
    }

}


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

int gcd(int x,int y){
	return y==0?x:gcd(y,x%y);
}

const long long mod=1000000000+7;

int main(){

	long long n,m;
	cin>>n>>m;

	long long res1=1,res2=1;
	long long a[2]={n,m};

	for(int i=0;i<n+m;i++){
		res1=(res1*a[i%2])%mod;
		a[i%2]--;
	}

	a[0]=n,a[1]=m;
	for(int i=1;i<=n+m;i++){
		res2=(res2*a[i%2])%mod;
		a[i%2]--;
	}

	cout<<(res1+res2)%mod<<endl;

	return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> b(n+1);
    for(int i = 1; i <= n; i++) cin >> b[i];

    vector<int> a(n+1);
    bool ok = true;
    for(int i = 0; i < n && ok; i++){
        ok = false;
        for(int j = n-i; j > 0; j--){
            if(b[j] == j){
                a[i] = b[j];
                ok = true;
                for(int k = j; k < n; k++){
                    b[k] = b[k+1];
                }
                break;
            }
        }
    }

    if(ok){
        for(int i = n-1; i >= 0; i--) cout << a[i] << endl;
    }else{
        cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int Q = sc.nextInt();
        int[][] abcdz = new int[Q][4];
        for (int q = 0; q < Q; q++) {
            abcdz[q][0] = sc.nextInt();
            abcdz[q][1] = sc.nextInt();
            abcdz[q][2] = sc.nextInt();
            abcdz[q][3] = sc.nextInt();
        }
        int[] nums = new int[M + N - 1];
        for (int i = 0; i < M + N - 1; i++){
            nums[i] = i+1;
        }
        int max = 0;
        for (int i = 0; i < (1<<(M + N - 1)); i++){
            ArrayList<Integer> SequenceA = new ArrayList<Integer>();
            for (int j = 0; j < (M + N + 1); j++){
                if ((1&i>>j) == 1) {
                    SequenceA.add(nums[j]);
                }
            }
            if (SequenceA.size() != N){continue;}
//            System.out.println(SequenceA);
            int[] ArrayA = new int[N];
            for (int n = 0; n < N; n++){
                ArrayA[n] = SequenceA.get(n) - (n + 1);
//                System.out.println(ArrayA[n]);
            }
            int d = 0;
            for (int q = 0; q < Q; q++){
                if ((ArrayA[abcdz[q][1]-1] - ArrayA[abcdz[q][0]-1]) == abcdz[q][2]){
                    d += abcdz[q][3];
                }
            }
            if (d > max){
                max = d;
            }
        }
        System.out.println(max);
    }
}

Measured memory_bytes: 55240
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <map>
#include <cmath>
#include <bitset>
#include <deque>
#include <queue>
#define INF (1LL<<31)
#define fst first
#define snd second
typedef long long ll;
typedef std::pair<int,int> ii;
using namespace std;

int main(){
  int n,ans;
  cin>>n;
  ans=1;
  while(ans<=n){
    ans*=2;
  }
  cout<<ans/2<<endl;
  return 0;
}


Measured memory_bytes: 256