akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define REP(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define INF 10000000
#define ll long long

using namespace std;

typedef pair<int, int> P;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

char c[3];

int main(){
    scanf("%s", c);

    int t = 0;

    REP(i, 3){
        if(c[i] == 'o') ++t;
    }

    printf("%d\n", 700 + 100 * t);

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int d[10000];
int main()
{
	int n,m,p,q,i,j,temp,r1,r2,c1,c2,min;
	scanf("%d %d %d",&n,&m,&p);
	min=n;
	d[0]=p;
	for(i=1;i<m+1;i++){
		scanf("%d",&d[i]);
	}
	for(i=0;i<m;i++){
		for(j=i+1;j<m+1;j++){
			if(d[i]>d[j]){
				temp=d[i];
				d[i]=d[j];
				d[j]=temp;
			}
		}
	}
	for(i=0;i<m+1;i++){
		q=d[i];
		r1=d[(i-1+m+1)%(m+1)];
		r2=d[(i+1)%(m+1)];
		c1=((q-p+n)%n)*2+(p-r2+n)%n;
		c2=((p-q+n)%n)*2+(r1-p+n)%n;
		if(min>c1){
			min=c1;
		}
		if(min>c2){
			min=c2;
		}
	}
	printf("%d\n",min*100);
	return 0;
}

Measured memory_bytes: 1060
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long N, K;
    cin>>N>>K;
    long long c = 0;
    for(long long i = 0 ; i <= N+1-K; i++) {
        c += (N-(K+i)+1+N)*(K+i)/2  -(0+(0+(K+i)-1))*(K+i)/2 + 1;
        //cout<<(N-(K+i)+1+N)*(K+i)/2<<endl;
        //cout<<(0+(0+K+i-1))*(K+i)/2<<endl;
        //cout<<0<<"~"<<(0+(K+i)-1)<<","<<N-(K+i)+1<<"~"<<N<<endl;
        //cout<<c<<endl;
    }
    cout<<c%(1000000000 +7)<<endl;
    return 0;
}



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

int main(){
  int H, W;
  cin >> H >> W;
  for(int i = 0; i < W + 2; i++){
    cout << "#";
  }
  cout << endl;
  vector<string> A(H);
  for(int o = 0; o < H; o++){
      cin >> A.at(o);
      cout << "#" << A.at(o) << "#" << endl;
    }
  for(int i = 0; i < W + 2; i++){
    cout << "#";
  }
  cout << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include<algorithm>
#include <cstdio>
#include <vector>

using namespace std;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
    string s;
    cin>>s;int flag=0;
    for(int i=0;i<s.size();i+=2)
    {
        if(s[i]=='h'&&s[i+1]=='i')
            continue;
        else flag=1;
    }
    if(flag) cout<<"No";
    else cout<<"Yes";
    return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
A = list(map(int, input().split()))
sumVal = sum(A) / (4 * M)

ansCnt = 0
for i in A:
    if i >= sumVal:
        ansCnt += 1

if ansCnt >= M:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
// PROXY

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        long k = scan.nextLong();
        long a = scan.nextLong();  
        long b = scan.nextLong();
        long biscuit = 1;
        if(b - a < 3){
            for(int i = 1; i <= k; i++){
                biscuit += 1;
            }
        System.out.println(biscuit);
        } else {
            if((k % 2 == 1 && a % 2 == 1)||(k % 2 == 0 && a % 2 == 0)){
                for(long i = 1; i <= a; i++ ) biscuit += 1;
                for(long j = 1; j <= (k - a)/2; j++ ) biscuit +=(b-a);
                System.out.println(biscuit);
            } else if((k % 2 == 1 && a % 2 == 0)||(k % 2 == 0 && a % 2 == 1)){
                for(long i = 1; i <= a - 1; i++ ) biscuit += 1;
                for(long j = 1; j <= (k - a + 1)/2; j++) biscuit +=(b-a);
                System.out.println(biscuit);
            } 
        }
    }
}


Measured memory_bytes: 21588
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

S = s()
print(S[0]+str(len(S)-2)+S[len(S)-1])

Measured memory_bytes: 77468
#include "bits/stdc++.h"
using namespace std;

int main() {
	long long N, X;
	cin >> N >> X;
	vector<long long> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	reverse(A.begin(), A.end());
	vector<long long> SUM(N + 1, 0);
	for (int i = 0; i < N; i++) SUM[i + 1] = SUM[i] + A[i];
	long long ANS = 1000000000000000000;
	for (long long K = N; K >= 1; K--) {
		long long NOW = 0;
		long long COUNT = 0;
		while (1) {
			long long L = NOW * K, R = L + K;
			long long P;
			if (NOW == 0) P = 5;
			else P = NOW * 2 + 3;
			if (R > N) {
				COUNT += (SUM[N] - SUM[L]) * P;
				break;
			}
			COUNT += (SUM[R] - SUM[L]) * P;
			NOW++;
			if (COUNT > ANS) goto NEXT;
		}
		ANS = min(ANS, X * K + X * N + COUNT);
	NEXT:;
	}
	cout << ANS << endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int q,w,e=0,i,j;
	cin>>q;
	for(i=1;i<=q;i++)
	{
		cin>>w;
		if(w!=i)
		e++;
	}
	if(e>2)
	cout<<"NO";
	else
	cout<<"YES";
	
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val argList = Scanner(System.`in`)


    val s = argList.next()

    val executor = FiftyFifty()
    val result = executor.execute(s)
    println(result)
}

class FiftyFifty {
    fun execute(args: String): String {
        val x0 = args[0]
        val x1 = args[1]
        val x2 = args[2]
        val x3 = args[3]

        val isResultX0 = args.filter { it == x0 }.count() == 2
        val isResultX1 = args.filter { it == x1 }.count() == 2
        val isResultX2 = args.filter { it == x2 }.count() == 2
        val isResultX3 = args.filter { it == x3 }.count() == 2

        if (isResultX0 && isResultX1 && isResultX2 && isResultX3) {
            return "Yes"
        }

        return "No"
    }
}

Measured memory_bytes: 29600
#include<iostream>
#include<stdlib.h>
using namespace std;
int exec(int n,int* h){
	int max=0;
	for(int i=0;i<n;i++){
		max=(max<h[i])?h[i]:max;
	}
	if(max==0)
		return 1;
	int flag=0;
	for(int i=0;i<n;i++){
		if(max==h[i]&&flag==0){
			h[i]-=1;
			flag=1;
		}else if(max==h[i]&&flag==1){
			h[i]-=1;
		}else if (max!=h[i]&&flag==1){
			break;
		}
	}
	return 0;
}

int main(){
	int n;
	cin>>n;
	int *h;
	h=(int*)malloc(sizeof(int)*n);
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	int c=0;
	while(exec(n,h)==0)
		c++;
	cout<<c;
		return 0;
}

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

int main() {
	int n, m, a, b, i;
	cin >> n >> m;
	int ans = m;
	for (i = 0; i < n; ++i) {
		cin >> a >> b;
		m += a - b;
		if (0 > m) {
			ans = 0;
			break;
		}
		ans = max(ans, m);
	}
	cout << ans << endl;
}


Measured memory_bytes: 3052
import re
stt = ""
line = input()
for i in range(len(line)):
    if re.compile("[A-Z]").search(line[i]):
        stt += line[i].lower()
    elif re.compile("[a-z]").search(line[i]):
        stt += line[i].upper()
    else:
        stt += line[i]
print(stt)

Measured memory_bytes: 7596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <time.h>
#include <cstdlib>
#include <cmath>
#include <fstream>

int main(void) {

	//test??¨
	//std::ifstream in("test.txt");
	//std::cin.rdbuf(in.rdbuf());

	std::string str;
	std::cin >> str;

	int n;
	std::cin >> n;

	for (int i = 0; i < n; i++) {

		std::string cmd;
		std::cin >> cmd;
		int st, ed;
		std::cin >> st >> ed;

		if (cmd == "print") {
			std::cout << str.substr(st, ed - st + 1) << std::endl;
		}
		else if (cmd == "reverse") {
			std::reverse(str.begin() + st, str.begin() + ed + 1);
		}
		else {
			std::string temp;
			std::cin >> temp;
			str.replace(st, ed - st + 1, temp);
		}

	}

}

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

using namespace std;

#define ll long long
#define ld long double
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short

#define pb push_back

#define fst first
#define snd second
#define mp make_pair

#define MOD 1000000007
#define all(v) (v).begin(),(v).end()
#define frl(i,n) for(long long i=0;i<n;i++)

#define ms(x,i)	memset(x,i,sizeof(x))
#define dbg(x)	cerr << #x << " = " << x << "\n"
#define displayvec(vec) cerr<<#vec<<": "; for(auto vd : vec) cerr<<vd<<" "; cerr<<"\n"

typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for(auto &i : v) cin>>i;
  return is;
}

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
  for(auto &i : v) cout<<i<<" ";
  return os;
}

vector< ll > lis(vector< ll > &v){
    ll n = v.size();
    if(n == 0) return vector< ll > ();
    vector< ll > arr, temp(n + 1, LLONG_MAX);
    vector< ll > mark(n);

    for(ll i = 0; i < n; ++i){
        ll index = lower_bound(temp.begin(), temp.end(), v[i]) - temp.begin();
        mark[i] = index;
        temp[index] = v[i];
    }

    ll findex;
    for(findex = 0; temp[findex + 1] != LLONG_MAX; ++findex);

    for(ll i = n-1; i >= 0; --i){
        if(mark[i] == findex){
            arr.emplace_back(v[i]);
            --findex;
        }
    }
    reverse(arr.begin(), arr.end());
    return arr;
}

string lcs(string s, string t){
    string str;
    ll n = s.length(), m = t.length();
    vector< ll > arr[128];
    vector< ll > find_lis;
    find_lis.reserve(n*m);

    for(ll i = 0; i < m; ++i){
        arr[static_cast< int >(t[i])].emplace_back(i);
    }
    for(auto &i : s){
        for(vector< ll > :: reverse_iterator itr = arr[static_cast< int >(i)].rbegin(); itr != arr[static_cast< int >(i)].rend(); ++itr){
            find_lis.emplace_back(*itr);
        }
    }

    const vector< ll > found_lis = lis(find_lis);
    for(auto i : found_lis){
        str.push_back(t[i]);
    }
    return str;
}

int main()
{
   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s, t;
    cin>>s>>t;
    cout<<lcs(s, t)<<"\n";
    return 0;
}


Measured memory_bytes: 214344
#include <iostream>
#include <vector>
#include <map>
using namespace std;
using ll = long long int;

ll kosuu(ll n)
{

    map<ll, ll> ret;
    for (ll i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i] += 1;
            n /= i;
        }
    }

    if (n != 1)
    {
        ret[n] += 1;
    }

    ll ans = 1;
    for (auto &&d : ret)
    {
        ans *= (d.second + 1);
    }

    return ans;
}

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

    ll ans = 0;
    for (ll i = 1; i <= N; i++)
    {
        if (i % 2 == 0)
        {
            continue;
        }
        ll s = kosuu(i);
        if (s == 8){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#[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")
    };
}

const M : i64 = 1000000007;

fn inv(a: i64) -> i64 {
    let m = M as i64;
    let mut a = a as i64;
    let mut b = m as i64;
    let mut u = 1;
    let mut v = 0;
    let mut tmp;
    while b != 0 {
        let t = a / b;
        a -= t * b;
        tmp = a;
        a = b;
        b = tmp;
        u -= t * v;
        tmp = u;
        u = v;
        v = tmp;
    }
    u %= m;
    if u < 0 {
        u += m;
    }
    return u;
}

fn main() {
    input! {
        n: usize,
        k: usize,
        a: [i64; n],
    }
    let mut a = a;
    a.sort();

    let mut f = vec![0i64; n + 1];
    f[0] = 1;
    for i in 1..n + 1 {
        f[i] = f[i - 1] * i as i64 % M;
    }
    let mut g = vec![0i64; n + 1];
    for i in 0..n + 1 {
        g[i] = inv(f[i]);
    }

    let mut result = 0;
    for i in k - 1..n {
        let c = (f[i] * g[i - k + 1] % M) * g[k - 1] % M;
        let s = a[i] * c % M;
        result = (result + s) % M;
        let s = a[n - i - 1] * c % M;
        result = (result - s + M) % M;
    }

    println!("{}", result);
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=998244353;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};


vector<LL> divi(LL K){
    vector<LL> v;
    for(LL i=1;i*i<=K;i++){
        if(K%i) continue;
        v.pb(i);
        v.pb(K/i);
    }
    sort(ALL(v));
    v.erase(unique(ALL(v)),v.end());
    return v;
}


int main(){
    LL n;cin >> n;
    LL ans = 1;
    auto q = divi(n - 1);
    for (int i = 0; i < q.size(); i++) {
        LL k = (n - 1) / q[i];
        if(k > sqrtl(n) && 0 < q[i] && q[i] < k) ans++;
    }
    for (LL i = 2; i*i <= n; i++) {
        LL t = n;
        while(t){
            if(t % i == 1){
                ans++;
                break;
            }
            else if(t % i == 0){
                t /= i;
            }
            else{
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int i,j,k,n;
    cin >>n;
    int l[n];
	long long sum = 0;
    for (i = 0;i<n;i++){
	cin>>l[i];
	sum +=l[i];
    }
    // output
	long long sum0 = 0;
	long long temp =	1000000000000000;
	for(i= 0;i<n-1;i++){
		sum0 +=l[i];
	if(2*sum0-sum>=0)
		temp= (2*sum0-sum)<temp?(2*sum0-sum):temp;
	else 
		temp= (sum-2*sum0)<temp?(sum-2*sum0):temp;
	}
	cout<<temp<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(int argc, char const *argv[]) {
  int a,b,c,d,e,k;
  cin>>a>>b>>c>>d>>e>>k;
  if(e-a>k){
    cout<<":("<<endl;
  }else{
    cout<<"Yay!"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
inline int in();
typedef long long ll;
inline void wr(ll);
int main(int argc,char**argv){
	register int n=in();
	register ll s=0;
	/*计数器，即所有的符合条件的数字都计算在内*/ 
	for(register int i=1;i<=n;++i)
		/*枚举数字i，计算和值*/
		if(i%3!=0)/*不是3的倍数*/ 
			if(i%5!=0)/*不是5的倍数*/ 
				s+=i;/*累加*/ 
	wr(s),putchar('\n');
}
inline int in(){
	register char c=getchar();
	register int x=0,f=1;
	for(;c<'0'||c>'9';c=getchar())
		if(c=='-')f=-1;
	for(;c>='0'&&c<='9';c=getchar())
		x=(x<<1)+(x<<3)+(c&15);
	return x*f;
}
inline void wr(ll x){
	if(x<0)putchar('-'),x=-x;
	if(x/10)wr(x/10);
	putchar(x%10+'0');
}


Measured memory_bytes: 1532
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B - One Clue
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int k, x;
  scanf("%d%d", &k, &x);

  for (int i = x - k + 1, cont = 0; i <= x + k - 1; i++, cont = 1) {
    if (cont) putchar(' ');
    printf("%d", i);
  }
  putchar('\n');
  return 0;
}


Measured memory_bytes: 256
#include<string>
#include <iostream>
using namespace std;
int main(void){
    string s;
    cin >> s;
    int cont = 0;
    for(int i = 0; i < s.length();i++){
        if(s.substr(i,1)=="x")cont++;
        
    }
    string ans ="YES";
    if(cont > 7)ans ="NO";
    cout << ans <<endl;

    
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#define INF 1<<30
#define FinishFunction return 0
#define MAX 1000000
using namespace std;
     
struct edge {
  int from,to,cost,k;
};
   
edge es[MAX];
   
int main(){
  int n,u,k,E,c,v;
  E = 0;
  scanf("%d",&n);
   
  for(int i=0;i<n;i++){
    scanf("%d %d",&u,&k);
      
    for(int j=0;j<k;j++){
      scanf("%d %d",&v,&c);
      es[E].from = u;
      es[E].to = v;
      es[E++].cost = c;
    }
  }
   
  // Ika berumanfo-do  
  int d[MAX];
  for(int i=0;i<n;i++)d[i] = INF;
  d[0] = 0;
  while(true){
    bool update = false;
    for(int i=0;i<E;i++){
      edge e = es[i];
      if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
    d[e.to] = d[e.from] + e.cost;
    update = true;
      }
    }
    if(!update)break;
  }
  for(int i=0;i<n;i++)cout << i << " " << d[i] << endl;
  FinishFunction;// return 0
}

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

using namespace std;

const int N = 500 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n, k;
string s;

bool read() {
    if (!(cin >> s >> k))
        return false;

    return true;
}

void solve() {
    n = s.size();
    int res = 0;
    vector<int> kek;

    for (int l = 0; l < n; ) {
        int r = l;
        for (; r < n && s[r] == s[l]; ++r) { }
        res += (r - l) / 2;

        if (l == 0 || r == n)
            kek.emplace_back(r - l);

        l = r;
    }

    if (kek.size() == 1) {
        long long l = min(k / 2, k - k / 2);
        long long r = k - l;
        long long a = min(kek[0] / 2, kek[0] - kek[0] / 2);
        long long b = kek[0] - a;
        cout << min(l * a + r * b, l * b + r * a) << endl;
        return ;
    }

    long long ans = 1ll * k * res;

    if (s[0] == s.back() && kek[0] % 2 != 0 && kek.back() % 2 != 0)
        ans += k - 1;

    cout << ans << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 256
def main():
    _ = int(input())
    A = [int(i) for i in input().split()]
    from collections import Counter
    c = Counter(A)
    li = [(k, v) for k, v in c.items() if v >= 2]
    li.sort(reverse=True)
    if li and li[0][1] >= 4:
        print(li[0][0] * li[0][0])
    elif len(li) <= 1:
        print(0)
    else:
        print(li[0][0] * li[1][0])


if __name__ == '__main__':
    main()


Measured memory_bytes: 18216
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
#define yn(x) puts((x ? "Yes" : "No"))
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;

void input() {
  ;
  ;
  int a, b, c;
  cin >> a >> b >> c;
  swap(a, b);
  swap(a, c);
  cout << a << " " << b << " " << c << endl;
}
void solve() {
  ;
  ;
}
signed main() {
  cout << setprecision(12);
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 111116
 
int n,a[N];
 
int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-')  f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}
 
int main(){
	n=read();
	for (int i=1;i<=n;i++) a[i]=read();
	sort(a+1,a+n+1);reverse(a+1,a+n+1);
	int x=0,y=0;
	while (a[x+1]>=x+1) x++;
	while (a[x+y+1]==x) y++;
	printf(((a[x]-x)&1)||(y&1)?"First\n":"Second\n");
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>

#define rep(i, n) for (int i = 0; i < n; i++) 
#define rrep(i, n) for(int i = n-1; i>=0; i--)
#define range(i, n, m) for (int i = n; i < m; i++) 
#define rrange(i, n, m) for (int i = n - 1; i => m; i--) 

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


using namespace std;

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

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

	ll N;
	cin >> N;

	ll arr[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
	vector<ll> prime(begin(arr), end(arr));
	vector<ll> div;

	//Nの約数の数
	ll divisor = 1;
	rep(i, prime.size()) {
		ll p = prime[i];
		ll count = 1;

		while (p <= N){
			count += N / p;
			p = p * prime[i];
		}

		div.push_back(count - 1);
		divisor *= count;
	}

	ll out = 0;

	rep(i, prime.size() - 1) {
		range(k, i+1, prime.size()) {

			rep(l, prime.size()) {
				if (l == i)continue;
				if (l == k)continue;
				if (div[i] >= 4 && div[k] >= 4 && div[l] >= 2)  out++;
			}

			if (div[i] >= 14 && div[k] >= 4)out++;
			if (div[i] >= 24 && div[k] >= 2)out++;

			if (div[k] >= 14 && div[i] >= 4)out++;
			if (div[k] >= 24 && div[i] >= 2)out++;

		}
		if (div[i] >= 74)out++;
	}


	cout << dec << out;

	return 0;
}


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

long long H, W;

long long solve(long long A, long long B) {
	long long minx = 0; if (A % 3 != 0) minx = B;
	for (int i = 1; i <= A - 1; i++) {
		long long G1 = 1LL * i*B;
		long long G2 = 1LL * (A - i)*(B / 2);
		long long G3 = 1LL * (A - i)*(B - (B / 2));
		long long I[3] = { G1,G2,G3 };
		sort(I, I + 3);
		minx = min(minx, I[2] - I[0]);
	}
	return minx;
}

int main() {
	cin >> H >> W;
	long long p1 = solve(H, W);
	long long p2 = solve(W, H);
	cout << min(p1, p2) << endl;
	return 0;
}

Measured memory_bytes: 256
// contest.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

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

int main()
{
	long long a, b, c;
	cin >> a >> b >> c;
	//sa+sb>sc a+b+2sab<c
	if ((c - a - b) * (c - a - b) > 4 * a * b && c - a - b > 0)
	{
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	return 0;
	return 0;
}



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

#define int long long int
#define pb push_back
#define mp make_pair

#define fr(i,a,b) for(i=a;i<=b;i++)

const int N=1e5+5;

int32_t main()
{
     
     string s;
     
     int i,k,idx=-1;
     
     char ch;
     
     cin>>s>>k;
     
     for(i=0;i<s.size();i++)
     {
          if(s[i]!='1')
          {
               idx=i+1;
               ch=s[i];
               break;
          }
     }
     if(idx==-1)
     {
          cout<<"1";
          return 0;
     }
     if(k<idx)
     {
          cout<<"1";
          return 0;
     }
     else
     {
          cout<<ch;
          return 0;
     }
}

Measured memory_bytes: 256
a, b, c = map(int, input().split())
for i in range(c):
  if i % 2 == 0:
    if a % 2 == 1:
      a -= 1
    b += a // 2
    a //= 2
  else:
    if b % 2 == 1:
      b-= 1
    a += b // 2
    b //= 2
print(a, b)


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


int main(void) {
  int l, r, d;
  cin >> l >> r >> d;

  int ans = 0;
  for (int i = l; i <= r; ++i) {
    if (i % d == 0) {
      ans++;
    }
  }

  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3624
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,m;
	cin>>n>>m;
	rep(i,m){
		int a;cin>>a;
		n-=a;
	}
	if(n<0)cout<<-1<<endl;
	else cout<<n<<endl;
}











Measured memory_bytes: 3616
n=int(input())
a=list(map(int,input().split()))
q=int(input())
ans=sum(a)
L=[0]*(10**5+1)
for i in range(n):
    L[a[i]]+=1
for i in range(q):
    b,c=map(int,input().split())
    num=L[b]
    L[b]=0
    L[c]+=num
    ans-=num*b
    ans+=num*c
    print(ans)


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

#define ll long long
#define ld long double
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
//#define int long long

using namespace std;
const int INF = 2e17;
const int MB = 20;
const int MOD = 1e9 + 7;

void solve() {
	int n, m, q;
	cin >> n >> m >> q;
	vector<vector<int>> x(n + 1);
	vector<int> y(m + 1);
	for (int i = 0; i < q; i++) {
		int one, two;
		cin >> one >> two;
		x[one].push_back(two);
		y[two]++;
	}

	map<int, int> mp;
	for (int i : y) mp[i]++;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int j : x[i]) {
			mp[y[j]]--;
			if (!mp[y[j]]) mp.erase(y[j]);
			y[j]--;
			mp[y[j]]++;
		}
		ans = max(ans, (int) x[i].size() + mp.rbegin()->first);
		for (int j : x[i]) {
			mp[y[j]]--;
			if (!mp[y[j]]) mp.erase(y[j]);
			y[j]++;
			mp[y[j]]++;
		}
	}

	cout << ans;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	//srand(time(0));
	int t = 1;
	//int t;
	//cin >> t;
	while (t--) solve();
}

Measured memory_bytes: 20872
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <cmath>
#include <ios>
#include <ctype.h>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>
#include <functional>
#include <bitset>
#include <list>
#include <deque>
#include <time.h>
#include <random>
#include <iomanip>
#include <fstream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define RREP(i,a,b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(),(x).end()
#define YY cout << "Yes" << endl
#define NN cout << "No" << endl
const long long INF = 1000000007;
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
int solve(){
  int n,m;
  cin>>n>>m;
  Graph G(n);
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  rep(i,n)cout<<G[i].size()<<endl;
  return 0; 
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16);
  solve();
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int f[1100][100010];
int d[1100];
int a[1000010],b[1000010];
int da[1000010],db[1000010];
int n,ans,cnt;
int read()
{
	int ans=0;
	char ch=getchar();
	while (ch<'0'||ch>'9') ch=getchar();
	while (ch>='0'&&ch<='9') ans=(ans<<1)+(ans<<3)+ch-'0',ch=getchar();
	return ans; 
}
int main()
{
	n=read();
	for (int i=1;i<=n;i++) a[i]=read(),b[i]=read();
	for (int i=1;i<(1<<9);i++)
		for (int j=100000;j>=0;j--)
			f[i][j]=max(f[i/2][j],j>=b[i]?f[i/2][j-b[i]]+a[i]:0);
	int q=read();
	while (q--)
	{
		int x=read(),y=read();
			cnt=0;
			while (x>=(1<<9)) d[1<<(cnt++)]=x,x/=2;
			ans=f[x][y];
			for (int j=1;j<(1<<cnt);j++){
				int v=(j-1)&j;
				da[j]=da[v]+a[d[j-v]],db[j]=db[v]+b[d[j-v]];
				if (db[j]<=y) ans=max(ans,f[x][y-db[j]]+da[j]);
			} 
			for (int j=0;j<(1<<cnt);j++) da[j]=db[j]=d[j]=0;
			printf("%d\n",ans);
	}
 } 

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


using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 1010;
const ll INF = 1LL << 60;

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



// Main Code
int main()
{
	ll n;
	cin>>n;
	vector<int> v(n);
	rep(i,0,n) cin>>v[i];
	ll r = 0;
	ll x = 0;
	ll ans = 0;
	for(ll l = 0; l<n; l++)
	{
		while(r < n && ((x^v[r]) == (x+v[r])))
		{
			x = x ^v[r];
			r++;
		}
		ans += (r - l);
		// cout<<l<<" "<<r<<endl;
		x ^= v[l];
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  string s;
  cin >> s;
  ll n = s.size();
  ll res = n;
  for (ll i = 2; i <= n; i+=2) {
    bool flag = 1;
    for (ll j = 0; j < (n-i)/2; j++) {
      if (s.at(j) != s.at((n-i)/2+j)) flag = 0;
    }
    if (flag) {
      res -= i;
      break;
    }
  }
  cout << res << endl;
}

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

int main()
{
    ll n, k;
    cin >> n >> k;
    ll m = 0;

    m = n;
    m = min(m, n % k);
    m = min(m, k - n % k);
    cout << m << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main{
    public static void main(String[] args){
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            String[] arr = br.readLine().split("\\s");
            int[] nums = new int[arr.length];
            
            for(int i=0; i<arr.length; i++){
                nums[i] = Integer.parseInt(arr[i]);
            }
            
            System.out.println(String.valueOf(calc(nums[0], nums[1])));
            
        }catch(IOException e) {
            e.printStackTrace();
        }
    }
    
    static int calc(int a, int b){
        if(a<b) {
            int tmp = a;
            a = b;
            b = tmp;
        }
        if(b==0){
            return a;
        }
        return calc(b, a%b);
    }
}



Measured memory_bytes: 24532
import sys
def input(): return sys.stdin.readline().strip()


def main():
    X = int(input())
    if X < 4:
        print(1)
        return
    ans = 1
    for b in range(2, int(X ** 0.5) + 2):
        for p in range(11):
            if b ** p > X: break
            ans = max(ans, b ** p)
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 62524
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(j,n) for(int j = 0; j < (n); ++j)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define drep2(j,n) for(int j = (n)-1; j >= 0; --j)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define srep2(j,s,t) for (int j = s; j < t; ++j)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

int N;
ll X;

ll height(int n) {
  return (ll)pow(2,n+2) - 3; 
}

ll getP(int n) {
  return (ll)pow(2,n+1) -1;
}

ll dfs(int lv, ll nokori) { // return P
  if(nokori == 0) return 0;
  if(lv == 1){
    if(nokori >= 5) {
      return 3;
    } else {
      return nokori - 1;
    }
  }
  ll inferH = height(lv-1);
  nokori--;

  ll ans = 0;
  if( inferH >= nokori){
    ans =  dfs(lv-1,nokori);
  } else if (inferH == nokori - 1){
    ans = dfs(lv - 1,nokori) + 1;
  } else {
    ll p = getP(lv-1);
    ans =  dfs(lv-1,nokori - inferH - 1) + p + 1;
  }
  return ans;
}

int main() {
  cin >> N >> X;
  cout << dfs(N,X) << endl;
  return 0;
}

Measured memory_bytes: 384
// Note that by default C++ creates a max-heap 
// for priority queue 
#include <iostream> 
#include <queue> 
#include <bits/stdc++.h>
using namespace std; 



int main () 
{ 
       int s,w;
       cin>>s>>w;
       if(w>=s)
       cout<<"unsafe"<<endl;
       else
       cout<<"safe"<<endl;
    
} 



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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

int main()
{
  string al = "abcdefghijklmnopqrstuvwxyz";
  string s; cin >> s;
  int K; cin >> K;
  int t[100010];
  for(int i = 0; i < s.size(); i++) {
    t[i] = al.size()-al.find(s[i]);
  }
  for(int i = 0; i < s.size() && K > 0; i++) {
    if(s[i] == 'a') continue;
    if(t[i] <= K) {
      s[i] = 'a';
      K -= t[i];
    }
  }
  K %= al.size();
  s[s.size()-1] = al[(al.find(s[s.size()-1])+K)%al.size()];
  cout << s << endl;
  return 0;
} 


Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cctype>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <memory>
#include <functional>

#define rep(i,n) REP(i,0,n)
#define REP(i,a,n) for(int i = a; i < (int)n; i++)

using namespace std;

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

Node *root;

bool find(int a){
  Node *r = root;
  while(r != NULL){
    if(r->data == a){
      return true;
    }
    else if(a < r->data){
      r = r->left;
    }
    else {
      r = r->right;
    }
  }
  return false;
}

void insert(int a){
  Node *root_tmp = root;
  Node *elem;

  elem = (Node *)malloc(sizeof(Node));
  elem->data = a;
  elem->left = NULL;
  elem->right = NULL;

  Node *prev = NULL;

    while(root_tmp != NULL){
      prev = root_tmp;
      if(elem->data < root_tmp->data){
	root_tmp = root_tmp->left;
      }
      else {
	root_tmp = root_tmp->right;
      }
    }

    elem->parent = prev;

    if(elem->parent == NULL){
      root = elem;
    }
    else{
        if(elem->parent->data < elem->data){
      elem->parent->right = elem;
    }
    else {
      elem->parent->left = elem;
    }
  }
}

void preorder(Node *u){
  if(u == NULL) return;
  cout << " " << u->data;
  preorder(u->left);
  preorder(u->right);
}

void inorder(Node *u){
  if(u == NULL) return;
  inorder(u->left);
  cout << " " << u->data;
  inorder(u->right);
}

 signed main(){
  int n;
  string command;
  int elem;

  cin >> n;
  rep(i,n){
    cin >> command;
    if(command == "insert"){
      cin >> elem;
      insert(elem);
    }
    else if(command == "find"){
      cin >> elem;
      if(find(elem)) cout << "yes" << endl;
      else cout << "no" << endl;
    }
    else{
      inorder(root);
      cout << "\n";
      preorder(root);
      cout << "\n";
    }
  }
}

  



Measured memory_bytes: 21880
#include<bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define pi pair<int, int>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define deb(x) cout << #x << ":" << x << endl;
/* freopen("input.txt", "r", stdin); */
/* freopen("output.txt", "w", stdout); */
const int MOD = 1000000007;


int main() {
	fastio();
	int k;
	cin >> k;
	string s;
	cin >> s;
	if(s.length() <= k)
		cout << s << "\n";
	else {
		for(int i=0;i<k;i++)
			cout << s[i];
		cout << "...\n";
	}
	return 0;
}



Measured memory_bytes: 3600
N,M = map(int, raw_input().split())
V,W = [],[]
for i in range(N):
    v,w = map(int, raw_input().split())
    V.append(v)
    W.append(w)

DP = [0]*(M+1)

for w in range(1, M+1):
    for i in range(N):
        if W[i] <= w:
            DP[w] = max(DP[w], DP[w-W[i]] + V[i])

print DP[M]


Measured memory_bytes: 5088
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner seer = new Scanner(System.in);
		int n = seer.nextInt();
		long[] arr = new long[n];
		int countneg = 0; long min = Integer.MAX_VALUE, tot = 0;
		for(int i = 0; i < n; i++){
			arr[i] = seer.nextInt();
			tot += Math.abs(arr[i]);
			min = Long.min(min, Math.abs(arr[i]));
			if(arr[i] < 0) {
				countneg++;
			}
		}
		if(countneg % 2 == 0){
			System.out.println(tot);
		}
		else{
			System.out.println(tot - 2*min);
		}
	}
}


Measured memory_bytes: 50820
#include <bits/stdc++.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string.h>
using namespace std;
#define pb push_back
#define all(v) v. begin(),v. end()
#define  rep(i,n,v) for(i=n;i<v;i++)
#define per(i,n,v) for(i=n;i>v;i--)
#define ff first 
#define ss second 
#define pp pair<ll,ll>
#define ll  long long
#define endl '\n'
void solve()
{
  ll n, a,m=0,b=1, c,k=0, i, j,l=1e9+7;
  string s, r, y;
  cin>>n;
  vector<string>v;
  map<string,int>mp;
  rep(i,0,n) {cin>>s;
  sort(s.begin(),s. end());
  //v.pb(s);
  if(mp.find(s)==mp. end())
  mp[s]=1;
  else mp[s]++;
  }
  sort(all(v));
 /* rep(i,0,v.size())
  {
   /* rep(j,i+1,v.size())
    {
      string r=v[i],y=v[j];
      sort(r.begin(),r. end());
      sort(y.begin(),y. end());
      if(r==y) k++;
    }*/
    /*  rep(j,i+1,v.size())
      {
        if(v[i]==v[j]) k++;
      }
  }*/
    for(auto& it : mp) {m=it.ss;k+=(m*(m-1))/2;}
  cout<<k;
}
int main()
{
 ios_base::sync_with_stdio(false);
  cin. tie(0);cout. tie(0);
    ll t=1;
  // cin>>t;
    while(t--)
    {
      solve();
    }
    return 0;
}

Measured memory_bytes: 11364
#include <stdio.h>

#define MAX(A,B) \
  ( (A) > (B) ? (A) : (B) )

/** Application main entry point. */
int
main (
  int     argc,
  char  * argv[ ]
  )
{
  int res = 0;
  int m, n;
  int i, j;

  scanf ( "%d%d", &m, &n );

  for ( i = 0; i < m; ++i )
  {
    int t = 0;

    for ( j = 0; j < n; ++j )
    {
      int d;

      scanf ( "%d", &d );
      t += d;
    }

    res = MAX( res, t );
  }

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

  return ( 0 );
}

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

using namespace std;

long long prime = 1000000007;

bool all_chars_equal(string s) {
    for (char c : s) {
        if (c != s[0]) {
            return false;
        }
    }
    return true;
}

vector<int> get_runs(string s) {
    vector<int> runs;
    int current_run = 0;
    for (char c : s) {
        if (c == s[0]) {
            ++current_run;
        } else if (current_run > 0) {
            runs.push_back(current_run);
            current_run = 0;
        }
    }
    // We intentionally don't add the last run
    return runs;
}

long long mod(long long x) {
    return (x % prime + prime) % prime;
}

long long f(int n, int k) {
    vector<long long> pow_2(2 * k + 4);
    pow_2[0] = 1LL;
    for (int i = 1; i < 2 * k + 4; ++i) {
        pow_2[i] = pow_2[i - 1] * 2 % prime;
    }

    vector<long long> f1(max(n + 1, 2 * k + 4), 0);
    for (int i = 1; i <= k; ++i) {
        f1[i] = pow_2[i];
    }
    f1[k + 1] = mod(pow_2[k+1] - 1);
    for (int n1 = k + 2; n1 <= 2 * k + 3; ++n1) {
        f1[n1] = mod(pow_2[n1] - 1 - n1 * pow_2[n1 - k - 2]);
    }
    for (int n1 = 2 * k + 4; n1 <= n; ++n1) {
        f1[n1] = mod(2 * f1[n1 - 1] - f1[n1 - k - 2]);
    }
    return f1[n];
}

/*
f(n, k) = antal cirkler af længde n med højst k røde i streg (ingen andre begrænsninger)

f(n, k) = 2^n for n <= k
f(n, k) = 2^n - 1 for n = k+1
f(n, k) = 2^n - 1 - n * 2^{n-k-2} for k+2 <= n <= 2k+3
f(n, k) = 2f(n-1, k) - f(n-k-2, k) for n >= 2k + 4

*/

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    string s;
    cin >> n >> m;
    cin >> s;
    if (all_chars_equal(s)) {
        cout << f(n, 1) << endl;  // OK since n >= 2
        return 0;
    }
    if (n % 2 != 0) {
        cout << 0 << endl;
        return 0;
    }
    vector<int> runs = get_runs(s);
    int bound = runs[0] % 2 == 1 ? runs[0] : runs[0] + 1;
    bound = min(bound, n - 1);
    for (int run : runs) {
        if (run % 2 == 1 && run < bound) {
            bound = run;
        }
    }
    cout << mod(f(n / 2, (bound - 1) / 2) * 2) << endl;
    return 0;
}


Measured memory_bytes: 3792
import Control.Applicative
import Control.Monad
import Data.List
import Data.Array
import Data.Char

main = do
  n <- (read::String -> Int) <$> getLine
  let digitSum = calc n
  putStrLn $ if n `mod` digitSum == 0 then "Yes" else "No"

calc::Int -> Int
calc n = if n == 0 then 0 else (n `mod` 10) + calc (n `div` 10)


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


void solve(long long K, long long N, std::vector<long long> A){

    long long ans;
    std::vector<long long> Ad(N);
    for(long long i = 0; i < N; i++){
        
        Ad[i] = A[(i+1)%N] - A[i];
        if(Ad[i] < 0){
            Ad[i] += K;
        }
        //cout << i << " " << Ad[i] << endl;
    }

    ans = K - *max_element(Ad.begin(), Ad.end());

    cout << ans << endl;

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long K;
    scanf("%lld",&K);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(K, N, std::move(A));
    return 0;
}


Measured memory_bytes: 3328
n, a, b = $stdin.readline.chomp.split.map(&:to_i)
h = Array.new(n) { $stdin.readline.to_i }.sort!

# x回の爆発で倒せるモンスターの最大値
res = (1..10 ** 9).bsearch {|x|
  cnt = h.bsearch_index {|y| y > b * x } || n
  r = x
  while cnt < n && r > 0
    c = [r, (h[cnt] - b * x + a - b - 1) / (a - b)].min
    break if h[cnt] > c * a + (x - c) * b
    cnt += 1
    r -= c
  end
  cnt >= n
}
puts res

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

int main()
{
  string s;
  cin>>s;
  int i,j;
  for(i=0;i<s.length();i++)
    if(s[i]=='A')
      break;
  for(j=s.length()-1;j>=0;j--)
    if(s[j]=='Z') break;
  cout<<j-i+1<<"\n";

  return 0;
}


Measured memory_bytes: 640
import java.lang.Math

fun main(args: Array<String>)
{
    val n = readInt()
    val w = readNInts()

    var ans = 1000000
    for (i in 0 until n) {
        var sum1 = 0
        var sum2 = 0
        for (k in 0..i) {
            sum1 += w[k]
        }
        for (k in i+1 until n) {
            sum2 += w[k]
        }
        val a = Math.abs(sum1 - sum2).toInt()
        ans = if (ans > a) a else ans
    }

    println(ans)
}

// Read an integer
// Usage: val a = readInt()
fun readInt() = readLine()!!.toInt()

// Read N integers separated by " "
// Usage: val (a, b, c) = readNInts()
fun readNInts() = readLine()!!.split(" ").map(String::toInt)

// Read a string
// Usage: val a = readString()
fun readString() = readLine()!!


Measured memory_bytes: 37928