akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int main() {
    string num;
    long sum;


    while (true) {
        cin >> num;
        if (num == "0") {
            break;
        }
        sum = 0;
        for (int i = 0; i < num.length(); i++) {
            sum += num[i] - '0';
        }
        cout << sum << endl;
    }
}

Measured memory_bytes: 3160
for i in range(5):
    n,k = map(int,input().split())
    if n == 0 and k == 0:
        break
    else:
        ruiseki = [0]*(n+1)
        total = 0
        maximum = -(10**9+7)
        for i in range(n):
            p = int(input())
            total += p
            ruiseki[i+1] = total
        for i in range(n-k+1):
            if ruiseki[i+k]-ruiseki[i]>maximum:
                maximum = ruiseki[i+k]-ruiseki[i]
        print(maximum)


Measured memory_bytes: 9464
#include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7;
int add(int a, int b){
  return (a % mod + b % mod) % mod;
}

int sub(int a, int b){
  return (a % mod - b % mod + mod) % mod;
}

int dp[102][100002];
int main(){
  ios::sync_with_stdio(0);
  int n, k; cin >> n >> k;
  vector<int>a(n);
  for(int i = 0; i < n; i++)
    cin >> a[i];

  // for(int i = 0; i <= k; i++)
    dp[n][0] = 1;

  for(int ind = n - 1; ind >= 0; ind--){
    for(int leftk = 0; leftk <= k; leftk++){
      int low = max(0, leftk - a[ind]);
      dp[ind][leftk] = sub(dp[ind + 1][leftk], low ? dp[ind + 1][low - 1] : 0);
      // cout << ind << ' ' << leftk << ' ' << dp[ind][leftk] << endl;
      if(leftk)
        dp[ind][leftk] = add(dp[ind][leftk], dp[ind][leftk - 1]);
    }
  }

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


Measured memory_bytes: 39296
/**
*    created: 28.06.2020 01:43:33
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pcnt(bit) __builtin_popcountll(bit)
using namespace std;
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const int mod = 1000000007;
const long double pi = acos(-1.0);
const int inf = 1LL << 60;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(all(a));
    cout << a[n-1] - a[0] << endl;
    return 0;
}

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

int main(){
    int a,b,c,x,y;
    cin >> a >> b >>c >>x >>y;
    
    long long sum = 1000000000;
    
    
    for(int i = 0; i <= 100000; i++) {
     long long k = 0;
      k = 2 * c * i + a * max(0, x - i) + b * max(0, y - i);
      sum = min(sum,k);
    }
    cout << sum;
}

Measured memory_bytes: 3604
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define llong long long
#define pb(a) push_back(a)
#define INF 9999999

using namespace std;

typedef pair<int,int> P;

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

int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(abs(b-a)<=d&&abs(c-b)<=d){
		cout<<"Yes"<<endl;
	}
	else if(abs(c-a)<=d){
		cout<<"Yes"<<endl;
	}
	else cout<<"No"<<endl;
}


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

using namespace std;

bool check(int a) {
  return a >= 1 && a <= 9;
}

int main() {
  int a, b;
  cin >> a >> b;
  bool flag = true;
  if (check(a) && check(b)) {
    cout << a * b << '\n';
  } else {
    cout << "-1\n";
  }
  return 0;
}

Measured memory_bytes: 384
while 1:
  c=[0,1,1]+[0]*98
  while 1:
    try: a, b = map(int, raw_input().split())
    except: exit()
    if a==0==b:break
    c[a] = -c[a]+1
    c[b] = -c[b]+1
  print ["NG","OK"][sum(c)==0]

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

int main(int argc, const char * argv[]) {
    string s,ans;
    cin>>s;
    
    for(int i=0;i<s.length();i++){
        if(s[i]=='0')ans.push_back('0');
        else if(s[i]=='1')ans.push_back('1');
        else if(s[i]=='B'){
            if(ans.length()>0)ans.erase(ans.size()-1);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<ctime>
#include<vector>
#include<queue>
#include<map>
#include<deque>
#include<stack>
#include<algorithm>
#define N
using namespace std;
const int INF=0x7fffffff;
const double Pi=acos(-1);
int main()
{
	int i;
	string S;
	cin>>S;
	for(i=0;i<=2;i++)
	{
		if(S[i]=='1')S[i]='9';
		else if(S[i]=='9')S[i]='1';
	}
	cout<<S;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <string> 
using namespace std;
int max(int x, int y) {
	if (x > y)return x;
	return y;
}

int abs(int x) {
	if (x < 0) {
		return -x;
	}
	return x;
}


int N,p[100001],ans,num;
bool match[100001];


int main(){
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> p[i];
		if (p[i] == i) {
			match[i] = true;
		}
	}

	for (int i = 1; i <= N; i++) {
		if (match[i]) {
			match[i] = false;
			if (match[i + 1]) {
				match[i+1] = false;
			}
			num++;
		}
	}
	if (match[N]==true&&match[N-1]==false) {
		num++;
	}

	cout << num << endl;
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define re register
#define F first
#define S second
typedef long long ll;
typedef pair<int, int> P;
const int N = 5005, M = 5e6;
const int INF = 0x3f3f3f3f;
int read() {
	int x = 0, f = 0; char ch = 0;
	while (!isdigit(ch)) f |= ch == '-', ch = getchar();
	while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}
int n, m;
int a[N][N];
bool f;
int dfn[N];
struct edge{
    int to, nxt;
}e[M];
int head[N], tot;
void addedge(int x, int y){
    e[++tot].to = y, e[tot].nxt = head[x], head[x] = tot;
}
void dfs(int x, int idx){
    if(!f) return;
    for(int i = head[x]; i; i = e[i].nxt){
    	int y = e[i].to;
        if (!dfn[y]){
            dfn[y] = idx;
            dfs(y, idx + 1);
        } else if((dfn[e[i].to] + idx) & 1){
            f = 0; return ;
        }
    }
}
int main(){
	n = read(); 
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++){
			char c; scanf(" %c", &c); a[i][j] = c - '0';
			if (a[i][j] == 1) addedge(i, j), addedge(j, i);
			else if (i != j) a[i][j] = INF;
		}
	bool flg = 1;
    for (int i = 1; i <= n; i++){
        memset(dfn, 0, sizeof(dfn));
        f = 1; dfs(i, 1);
        if(!f){
            puts("-1"); return 0;
        }
    }		
	int ans = -INF;
	for (int k = 1; k <= n; k++)
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
                a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			if (i != j && a[i][j] != INF) ans = max(ans, a[i][j]);
	printf("%d\n", ans + 1);
	return 0;
}

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

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

  vector<int> v(N-1);
  for (int i = 0; i < N - 1; i++)
	cin >> v[i];

  int sum = 0;
  vector<int> res(N, 0);

  res[0] = v[0];
  for (int i = 0; i < N - 1; i++) {
	if (res[i] > v[i])
	  res[i] = v[i];

	res[i+1] = v[i];
	sum += res[i];
  }
  sum += res[N-1];


  cout << sum << endl;


  return 0;
}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()
#define fcout cout << setprecision(10)

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

template <typename T>
void debug(vector<T> &vec) {
    for (auto x : vec) {
        cout << x << " ";
    }
    cout << endl;
    return;
}

template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

template <typename T>
int getFormer(const vector<T> &vec, T x) {
    return upper_bound(vec.begin(), vec.end(), x) - vec.begin() - 1;
}

template <typename T>
int getLatter(const vector<T> &vec, T x) {
    return lower_bound(vec.begin(), vec.end(), x) - vec.begin();
}

vector<long long> era(int N) {
    vector<bool> isPrime(N, true);
    vector<long long> res;
    isPrime[0] = isPrime[1] = false;
    for (int i = 2; i < sqrt(N) + 1; i++) {
        if (isPrime[i] == true) {
            for (int j = i + i; j < N + 1; j += i){
                isPrime[j] = false;
            }
        }
    }

    for (int i = 2; i < N + 1; i++) {
        if (isPrime[i] == true) res.push_back(i);
    }

    return res;
}

vector<long long> primes;

int solve(int N, int P) {
    auto s = upper_bound(ALL(primes), N) - primes.begin();
    vector<long long> sums;
    for (int i = s; i < s + P; i++) {
        for (int j = i; j < s + P; j++) {
            sums.push_back(primes[i] + primes[j]);
        }
    }

    sort(ALL(sums));
    cout << sums[P - 1] << endl;
}

int main() {
    int N, P;
    primes = era(3 * 1e5);
    while (cin >> N >> P && N != -1) {
        solve(N, P);
    }
    return 0;
}


Measured memory_bytes: 3228
object Main {
  def main(args:Array[String]){
    try{
      while(true){
        var numAry=io.StdIn.readLine.split(" ").map(_.toInt).sorted
        if(numAry(1)==0) throw new Exception
        println(numAry.mkString(" "))
      }
    }
    catch{
      case _:Exception=>()
    }
  }
}

Measured memory_bytes: 46988
using System;
class Qsort
{
    public static void Main()
    {
        string s = Console.ReadLine();
        bool b = false;
        for(int i = 0; i < 3;i++)
        {
            if (s[i] == s[i + 1])
                b = true;
        }
        if (b)
            Console.WriteLine("Bad");
        else
            Console.WriteLine("Good");
    }


}

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

#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define FORV(a, A) for (auto &a : A)

using namespace std;
using ll = long long;
using P = pair<int, int>;

void Main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a+b+c > 21)
    cout << "bust" << endl;
  else
    cout << "win" << endl;
}

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


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    H,W = map(int,input().split())
    N = int(input())
    a = list(map(int,input().split()))
    cl = []
    for i in range(N):
        cl += [(i+1) for _ in range(a[i])]

    ans = [[] for _ in range(H)]
    for i in range(H):
        ans[i] = cl[(W*i):(W*(i+1))]

    for i in range(H):
        if i%2 == 1:
            ans[i].reverse()
        print(*ans[i])

if __name__ == "__main__":
    main()

Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
void solve()
{
    int n,a,b;
    cin>>n>>a>>b;
    if(b-1+a>n||1LL*a*b<n)
        cout<<"-1\n";
    else{
        //cout<<"YES\n";
        vc<vi> all(a);
        for(int i=1;i<a;i++) all[i].push_back(i);
        vi op;
        int cur=n;
        for(int i=a-1;i>=0;i--)
        {
            while(all[i].size()<b+(i==a-1))
            {
                all[i].push_back(cur);
                cur--;
                if(cur==a-1) break;
            }
            if(cur==a-1) break;
        }
        for(int i=0;i<a;i++) for(auto u:all[i]) op.push_back(u);
        print(op);
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    //cin>>T;
    //while(T--)
    //{
        solve();
    //}
    
}


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

int main() {
	int ans;
	string S;
	cin >> S;
	for(int i = 0; i < 4; i++){
		if(S.at(i) == '+'){
			ans++;
		} else {
			ans--;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] p = new int[n];
		int[] ps = new int[n];

		int i;
		for(i = 0; i < n; i++) {
			p[i] = scan.nextInt();
			ps[i] = i + 1;
		}

		int cnt = 0;
		for(i = 0; i < n; i++) {
			if(p[i] != ps[i])
				cnt++;
		}

		if(cnt == 0 || cnt == 2)
			System.out.println("YES");
		else
			System.out.println("NO");
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(a)      (a).begin(),(a).end()
#define debug_array(a,n) for (ll bccc=(0); bccc<(n); bccc++) cout<<a[bccc]<<" "<<"\n"
#define debug_vector(a) for(ll bccc=(0); bccc<(a.size());bccc++) cout<<a[bccc]<<" "<<"\n"
#define F           first
#define S           second
#define debug_set(s) for(auto p:s) cout<<p<<" "
#define debug_map(m) for(auto p:m) cout<<p.F<<" "<<p.S<<"\n"
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
/* ll t = 0;
ordered_multiset me;
...
me.insert({x, t++});
me.erase(me.lower_bound({x, 0}));
cout << me.order_of_key({x, 0}) << "\n";

///////////   t is insertion time
*/
//#pragma GCC optimize("Ofast")  // works very well
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long double lld;
lld pi=3.14159265358;
ll powr(ll a,ll b)
{
    ll c=1;
    ll kjk;
    for(kjk=0;kjk<b;kjk++)
        c*=a;
    return c;
}
ll hell=1000000007;
//ll hell=998244353   ;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
// to generate random number , use rng() ... eg cout<<rng();
ll fact[100005];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    ll n,i;
    cin>>n;
    ll a[n];
    ll b[n];
    for(i=0;i<n;i++)
        {cin>>a[i];b[i]=a[i];}
    fact[0]=1;
    fact[1]=1;
    for(i=2;i<100005LL;i++)
        fact[i]=(i*fact[i-1])%hell;
    ll s=0;
    ll x=fact[n-1];
    ll aa[n+1];
    for(i=1;i<n;i++)
        aa[i]=(x*power(i,hell-2,hell))%hell;
    for(i=2;i<n;i++)
        aa[i]=(aa[i]+aa[i-1])%hell;
    for(i=1;i<n;i++)
    {   ll gg=a[i]-a[i-1];
        s=s+(gg*aa[i])%hell;
        s%=hell;
    }
    cout<<s;
    return 0;
}


Measured memory_bytes: 3328
#!/usr/bin/ruby
def fizzbuzz(n)
	if n%3==0&&n%5==0 then return 'FizzBuzz' end
	if n%3==0 then return 'Fizz' end
	if n%5==0 then return 'Buzz' end
	return n.to_s
end
while(m,n=gets.split.map(&:to_i))!=[0,0]
	a=1.step(m).map.to_a
	c=0
	1.step(n){|i|
		s=gets.chomp
		if a.length>1
			if s!=fizzbuzz(i) then a.delete_at(c);c%=a.length else c=(c+1)%a.length end
		end
	}
	puts a.join(' ')
end

Measured memory_bytes: 2724
#include<stdio.h>
#include<ctype.h>
#include<string.h>
int main(void)
{
	char c[1200];
	int i;
	fgets(c,1200,stdin);
	
	
	for(i = 0;i < strlen(c);i++){
	if(c[i] >= 'a'&&c[i] <= 'z')
		c[i] = toupper(c[i]);
		
	else if(c[i] >='A'&&c[i] <='Z')
		c[i] = tolower(c[i]);
		
	}
	fputs(c,stdout);
	
	return 0;
}


Measured memory_bytes: 2112
m, n = [int(x) for x in input().split()]

mod = 10**9 + 7


def func(m, n):
    if n == 1:
        return m
    if n % 2 == 0:
        return int(func(m, n//2) ** 2) % mod
    else:
        return int(m * func(m, n-1)) % mod


if __name__ == "__main__":
    print(func(m, n))


Measured memory_bytes: 5604
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	strs := make([]string, k)
	for i := range strs {
		fmt.Scan(&strs[i])
	}
	for i := n; i < 10 * n; i++ {
		ok := true
		for _, s := range strs {
			if strings.Contains(strconv.Itoa(i), s) {
				ok = false
				break
			}
		}
		if ok {
			fmt.Println(i)
			return
		}
	}
}


Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <stdlib.h>
using namespace std;

int main(){
	long long a, b;
	long long x;
	cin >> a >> b >> x;

	long long ans = 0;
	if(a != 0){
		ans = (b / x + 1) - ((a - 1) / x + 1);
	}else{
		ans = (b / x + 1) - 0;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rbf(a, x) for (auto& a : x)
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define drep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define Maxe(x) *max_element(all(x))
#define Mine(x) *min_element(all(x))
#define Size(x) ((ll)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
#define Fi first
#define Se second
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

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

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo
//mint,dijkstra,gyakugen
    signed main(){
        string abc="abcdefghijklmnopqrstuvwxyz";
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        ll n;
        cin>>n;
        ll keta=0;
        ll x=1;
        while(1){
            keta++;
            if(n<=x*26)break;
            x*=26;
            n-=x;
        }
        string s="";
        rep(i,keta)s=s+'a';
        n--;
        vc Ans(0);
        rep(i,keta){
            ll q=n%26;
            n/=26;
            Ans.pb(abc[q]);
        }
        rep(i,keta)cout<<Ans[keta-1-i];
        cout<<endl;
    }

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

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define POS(X,Y) *X.find_by_order(Y)
#define ORD(X,Y) X.order_of_key(Y)

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin >> s;
	long long n = s.size();
	long long cnt[26] = {};
	for(char c : s) {
		cnt[c-'a'] ++;
	}
	long long odd = 0;
	long long sp = -1;
	for(long long i = 0; i < 26; ++i) {
		odd += cnt[i]%2;
		if(cnt[i]&1) sp = i;
		cnt[i] >>= 1;
	}
	if(odd > 1) return cout << -1 << endl, 0;

	vector<long long> t(n);
	vector<long long> ord[3];
	for(long long i = 0; i < n; ++i) {
		long long p = s[i] -'a';
		if(p == sp) {
			if(cnt[p] > 0) {
				t[i] = 0;
				--cnt[p];
				ord[0].push_back(i);
			}
			else if(cnt[p] == 0) {
				t[i] = 1;
				--cnt[p];
				ord[1].push_back(i);

			}
			else if(cnt[p] < 0) {
				t[i] = 2;
				ord[2].push_back(i);
			}
		}
		else {
			if(cnt[p]) {
				t[i] = 0;
				--cnt[p];
				ord[0].push_back(i);
			}
			else {
				t[i] = 2;
				ord[2].push_back(i);
			}

		}
	}

	long long pref[3][n];
	for(long long i = 0; i < n; ++i) {
		for(long long j = 0; j < 3; ++j) {
			pref[j][i] = (i ? pref[j][i-1] : 0);
		}
		pref[t[i]][i]++;
	}
	long long inv = 0;
	for(long long i = 0; i < n; ++i) {
		for(long long j = 2; j > t[i]; --j) {
			inv += pref[j][i];
		}
	}
	ordered_set<long long> lol;
	queue<long long> q[26];
	for(long long i = 1; i <= ord[2].size(); ++i) {
		q[s[ord[2][ord[2].size() - i]] - 'a'].push(i);
	}
	for(long long i = 0; i < ord[0].size(); ++i) {
		int p = q[s[ord[0][i]] - 'a'].front();
		q[s[ord[0][i]] - 'a'].pop();
		inv += lol.size() - lol.order_of_key(p);
		lol.insert(p);
	}
	cout << inv << endl;
}


Measured memory_bytes: 14604
#include <iostream>
#include <cstdlib>
#include <string>
#include <typeinfo>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int INFTY = (1<<21);
int n,M[N][N], d[N];
void bfs(int s){
    queue<int> q;
    q.push(s);
    for(int i = 0; i < n; i++)d[i] = INFTY;
    d[s] = 0;
    int u;
    while(!q.empty()){
        u = q.front();q.pop();
        for(int v = 0; v < n; v++){
            if(M[u][v] == 0)continue;
            if(d[v] != INFTY)continue;
            d[v] = d[u] + 1;
            q.push(v);
        }
    }
    for(int i = 0; i < n; i++)cout << i + 1 << " " << ( (d[i] == INFTY) ? (-1) : d[i] ) << endl;
    }


int main(){
    int u,k,v;
    cin >>n;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++)M[i][j] = 0;
    }
    for(int i = 0; i < n; i++){
        cin >> u >> k;
        u--;
        for(int j = 0; j < k; j++){
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }
    bfs(0);
    return 0;
}





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

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

using namespace std;

int n,d,x,p[11][11],dp[100010];//??


int main() {
  cin >> n >> d >> x;
  rep(i,d) rep(j,n) cin >> p[i][j];
  int maxi = x;
  rep(day,d-1) {
    memset(dp,0,sizeof(dp));
    rep(i,maxi+1) dp[i] = i;
    int tmp = maxi;
    rep(i,n) {
      REP(j,p[day][i],maxi+1) {
        dp[j] = max(dp[j],dp[j-p[day][i]]+p[day+1][i]);
        tmp = max(tmp,dp[j]);
      }
    }
    maxi = tmp;
  }
  cout << maxi << endl;
  return 0;
}

Measured memory_bytes: 1564
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define nl '\n'
#define f(i, n) for (int i = 0; i < n; ++i)
#define INF 1e9 + 5
using namespace std;
void solve() {
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    int mx = -INF;
    f(i, n) {
        int c;
        cin >> c;
        if (c > mx) mx = c;
    }
    int mn = INF;
    bool war = false;
    f(i, m) {
        int c;
        cin >> c;
        if (c < mn) mn = c;
    }
    war = mn > mx && mn <= y && mn > x;
    cout << (war ? "No War" : "War") << nl;
}

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

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

int main(){
    int a,b;
    cin >> a >> b;
    if(a<=5){
        cout << 0 << endl;
        return 0;
    }
    else if(a<=12){
        cout << b/2 << endl;
        return 0;
    }
    else {
        cout << b << endl;
        return 0;
    }
}

Measured memory_bytes: 256
X = int(input())
ls = [2, 2, 2, 3, 3, 5]
a = []
for l in ls:
  if X % l == 0:
    a.append(l)
    X /= l
num = 1
if len(a) != 0:
  for b in a:
    num *= b
print(int(360 / num))

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

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


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

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


int main()
{
    int n;
    cin>>n;
    unordered_set<string> s;
    for (int i = 0; i < n; i++)
    {
        string ss;
        cin>>ss;
        s.emplace(ss);
    }
    cout<<s.size()<<endl;
    
    return 0;
}

Measured memory_bytes: 17616
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

x_minus_y = list(map(lambda xi, yi: xi - yi, x, y))

print(sum(list(map(abs, x_minus_y))))
print(sum(list(map(lambda x: x**2, x_minus_y))) ** .5)
print(sum(list(map(lambda x: abs(x)**3, x_minus_y))) ** (1 / 3))
print(max(list(map(abs, x_minus_y))))



Measured memory_bytes: 5640
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
  cin >> n;
string s;
int c0=0;
int c1=0;
int c2=0;
int c3=0;
for(int i=0;i<n;i++){
cin >>s;
if (s == "AC")c0+=1;
else if(s =="WA")c1+=1;
else if(s =="TLE")c2+=1;
else if(s =="RE")c3+=1;

}
cout << "AC x "<< c0 <<endl;
cout << "WA x "<< c1 <<endl;
cout << "TLE x "<< c2 <<endl;
cout << "RE x "<< c3 <<endl;
     return 0;
}

Measured memory_bytes: 3604
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
   int A,B;
   cin >> A >> B;
   if(A>=13) cout << B<<endl;
   else if(A>=6) cout << B/2<<endl;
   else cout <<0 <<endl;

   return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String[] tokens = in.nextLine().split(" ");
		long n = Long.parseLong(tokens[0]);
		long m = Long.parseLong(tokens[1]);
		long d = Long.parseLong(tokens[2]);

		// scoreカウントに合致する数
		long count = 0;
		if(d == 0) {
			count = n;
		}else {
			count = (n - d) * 2;
		}
		double dcount = (double) count;
		long n2 = n * n;
		double dn2 = (double) n2;
		// System.out.println("count: " + count + ", n2: " + n2);

		double base = dcount / dn2;
		double result = base * (double) (m - 1);
		System.out.println(result);
		in.close();
	}

}

Measured memory_bytes: 23892
#include <iostream>                                                             
using namespace std;                                                            
                                                                                
int main() {                                                                    
  int a, b;                                                                     
  cin >> a >> b;                                                                
  if (a % 2 == 1 && b % 2 == 1) {                                               
    cout << "Yes" << endl;                                                      
  } else {                                                                      
    cout << "No" << endl;                                                       
  }                                                                             
} 

Measured memory_bytes: 256
N = int(raw_input())
A = map(int, raw_input().split())

count = 0
head_swaped = False
tail_swaped = False
if A[0] == 1:
    A[0], A[1] = A[1], A[0]
    count += 1
if A[-1] == N:
    A[-1], A[-2] = A[-2], A[-1]
    count += 1

for i in xrange(1, N-1):
    j = i+1
    if j == A[i]:
        count += 1
        A[i], A[i+1] = A[i+1], A[i]

# for i in xrange(N/2):
#     j = i+1
#     if j == A[i]:
#         count += 1
#         A[i], A[i+1] = A[i+1], A[i]
#         head_swaped = True
#     else:
#         head_swaped = False
#     i = N-1-i
#     j = i+1
#     if j == A[i]:
#         count += 1
#         A[i], A[i-1] = A[i-1], A[i]
#         tail_swaped = True
#     else:
#         tail_swaped = False

print count

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

public class Main {
    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];

        long sum = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            sum += a[i];
        }

        Arrays.sort(a);

        System.out.println(a[0] + " " + a[n - 1] + " " + sum);
    }
}


Measured memory_bytes: 41744
import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines

N = int(readline())
XY = [tuple(int(x) for x in line.split()) for line in readlines()]

graph = [[] for _ in range(N+1)]
for x,y in XY:
    graph[x].append(y)
    graph[y].append(x)

visited = [False] * (N+1)
visited[1] = True
q = [1]
ord = [1]
par = [0] * (N+1)
while q:
    x = q.pop()
    for y in graph[x]:
        if visited[y]:
            continue
        ord.append(y)
        par[y] = x
        visited[y] = True
        q.append(y)

G = [0] * (N+1)
for x in ord[::-1]:
    p = par[x]
    G[p] ^= (G[x]+1)

answer = 'Alice' if G[1] != 0 else 'Bob'
print(answer)

Measured memory_bytes: 35356
use std::cmp;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let mut count: Vec<usize> = vec![0; n];
    for _ in 0..n {
        let a = sc.read::<usize>() - 1;
        count[a] += 1;
    }

    count.sort();
    let mut ans = vec![0; n + 1];
    let mut sum = count.iter().sum::<usize>();
    let mut popped = 0;
    for height in (1..(n + 1)).rev() {
        while let Some(c) = count.pop() {
            if c >= height {
                sum -= c;
                popped += 1;
            } else {
                count.push(c);
                break;
            }
        }

        let columns = sum / height + popped;
        ans[columns] = cmp::max(ans[columns], height);
    }
    for k in (0..n).rev() {
        ans[k] = cmp::max(ans[k], ans[k + 1]);
    }

    for k in 1..(n + 1) {
        println!("{}", ans[k]);
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 13180
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define re register
#define int long long
#define D double
il int read() {
    re int x = 0, f = 1; re char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
#define rep(i , a , b) for(int i = (a) , i##Limit = (b) ; i <= i##Limit ; ++ i)
#define maxn 200005
int n, m, a[maxn], ans, Mi = -1e18, Ma = 1e18, c1, c2, b[maxn], c[maxn], g, d[maxn], c3;
il int check(int x) {
	int tem = 0;
	if(x >= 0) {
		tem = g * (c1 + c2) + g * (g - 1) / 2 + c1 * c2;
		rep(i, 1, c1 - 1) tem += upper_bound(b + i + 1, b + c1 + 1, x / b[i]) - b - 1 - i;
		rep(i, 1, c2 - 1) tem += upper_bound(c + i + 1, c + c2 + 1, x / c[i]) - c - 1 - i;
	}
	else {
		x = -x;
		rep(i, 1, c1){
            int pos = lower_bound(c + 1, c + c2 + 1, (int)ceil((D)x / (D)b[i])) - c;
            if(b[i] * c[pos] < x) pos++;
            if(b[i] * c[pos - 1] >= x) -- pos;
            if(c2 >= pos) tem += c2 - pos + 1;
        } 
	}
	return tem >= m;
}
signed main() {
	n = read(), m = read();
	rep(i, 1, n) a[i] = read();
	rep(i, 1, n) {
		if(a[i] < 0) b[++ c1] = -a[i];
		else if(a[i] > 0) c[++ c2] = a[i];
		else ++ g;
	}
	sort(b + 1, b + c1 + 1), sort(c + 1, c + c2 + 1);
	while(Mi < Ma){
        int Mid = (Mi + Ma) >> 1;
        if(check(Mid)) Ma = Mid;
        else Mi = Mid + 1;
    }
	cout << Ma;
	return 0;
}

Measured memory_bytes: 4992
(w, h, x, y, r) = input().rstrip().split(' ')
w = int(w)
h = int(h)
x = int(x)
y = int(y)
r = int(r)

if 0 + r <= x <= w - r and 0 + r <= y <= h - r:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 6728
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
string S;
int AL[26];
int Num[10];
string s1="abcdefghijklmnopqrstuvwxyz";
string s2="0123456789";
int ans=0;
int main()
{
	cin >> S;
	for(int i=0;i<S.length();i++){
		for(int j=0;j<26;j++){
			if(S[i]==s1[j])AL[j]++;
		}
		for(int j=0;j<10;j++){
			if(S[i]==s2[j])Num[j]++;
		}
	}
	while(true){
		bool F=false;
		for(int i=0;i<26;i++){
			int k=0;
			while(i+k<26&&AL[i+k]>=1)k++;
			if(k>=4){
			F=true;
				ans+=3;
				for(int j=i;j<i+k;j++)AL[j]--;
				break;
			}
		}
		for(int i=0;i<10;i++){
			int k=0;
			while(i+k<10&&Num[i+k]>=1)k++;
			if(k>=4){
				F=true;
				ans+=3;
				for(int j=i;j<i+k;j++)Num[j]--;
				break;
			}
		}
		if(!F)break;
	}
	
	for(int i=0;i<26;i++)ans+=AL[i];
	for(int i=0;i<10;i++)ans+=Num[i];
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1192
///Nahid Hasan Raju
#include <bits/stdc++.h>
#define ll long long
#define MS(ARRAY,VALUE) memset(ARRAY,VALUE,sizeof(ARRAY))
#define Fin freopen("input.txt","r",stdin)
using namespace std;

#define P(XX) cout<<XX<<endl
#define P1(XX) cerr<<"db1: "<<XX<<endl
#define P2(XX,YY) cerr<<"db2: "<<XX<<" "<<YY<<endl
#define P3(XX,YY,ZZ) cerr<<"db3: "<<XX<<" "<<YY<<" "<<ZZ<<endl
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define Fout freopen("output.txt","w",stdout)
#define rep(i,a,b) for(i=a;i<=b;i++)
#define EPS 0.00000001
#define INF INT_MAX
#define PI 2*acos(0.0)
#define set(XX,POS) XX|=(1<<POS)
#define reset(XX,POS) XX&=(~(1<<POS))
#define check(XX,POS) (bool)(XX&(1<<POS))
#define toggle(XX,POS) (XX^(1<<POS))
#define SORT(v) sort(v.begin(),v.end())
#define REVERSE(V) reverse(v.begin(),v.end())
#define VALID(X,Y,R,C) X>=0 && X<R && Y>=0 && Y<C
#define SIZE(ARRAY) sizeof(ARRAY)/sizeof(ARRAY[0])
#define RT printf("Run Time : %0.3lf seconds\n", clock()/(CLOCKS_PER_SEC*1.0))
#define pb push_back
#define pll pair<ll,ll>
#define pii pair<int,int>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
typedef tree< pair<int,int> , null_type, less< pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> odrst;

#define MOD 1000000007ll
#define MX 2000006  ///200005

ll m, n;
ll a[MX], vis[MX];
vector<ll>vt[MX];
string s,s1;
map<pll,int>mp;
ll ans;
ll dfs(ll p)
{
    ll u, v;
    for(int i=1;i<vt[p].size();i++)
    {
        u=vt[p][i];
    }
}
int main()
{
    int test=1, tc=0, i, j;
    #ifndef ONLINE_JUDGE
    //Fin;
    test=2;
    #endif
    ll k, t;
    //scanf("%d", &test);
    ll u, v;
    while(test--)
    {
        ans=0;
        mp.clear();
        char ch;
        cin>>ch;
        if(ch>='a')P('a');
        else P('A');
    }
    return 0;
}

Measured memory_bytes: 50500
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin >> N;
    
    vector<string> A(N);
    
    for(int i=0;i<N;i++) cin >> A[i];
    
    bool can = true;
    for(int i=0;i<N-1;i++){
       // cout << A[i][0] << endl;
        if(A[i][A[i].size()-1]!=A[i+1][0]) can = false;
    }
    sort(A.begin(),A.end());
    
    for(int i=0;i<N-1;i++){
        if(A[i]==A[i+1]) can = false;
    }
    
    if(can) cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	LL s=0;
	cin>>n;
	for(i=1;i<=n;i++){
		if(i%3 && i%5)s+=i;
	}
	cout<<s<<endl;
}

Measured memory_bytes: 3672
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

vector<int> V;

int N;
int L[2050];


int C[1050];

set<int> S;

int main(void) {

	cin >> N;

	for (int i = 1; i <= N; i++){
		cin >> L[i];
		V.push_back(L[i]);
		C[L[i]]++;
		S.insert(L[i]);
}

	long long int ans = 0;
	sort(V.begin(), V.end());

	for (int i = 0; i <= N-1; i++) {
		for (int j = i + 1; j <= N-1; j++) {

			int a = V[i];
			int b = V[j];

			if (a == b) { continue; }
			
			ans+=upper_bound(V.begin(), V.end(), a + b - 1)-lower_bound(V.begin(), V.end(), b+1);
			
		}
	}


	for (auto y : S) {
		if (C[y] <= 1) { continue; }

		int tmp = (C[y] * (C[y] - 1)) / 2;

		int cnt = 0;
		for (int i = 1; i <= N; i++) {
			if (L[i] == y) { continue; }
			if (L[i] < 2 * y) { cnt++; }
		}
		ans += tmp*cnt;
		//cout << tmp*cnt << endl;
	}

	/*for (auto y : S) {
		if (C[y] <= 1) { continue; }

		int tmp = (C[y] * (C[y] - 1)) / 2;

		int cnt = 0;
		for (int i = 1; i <= N; i++) {
			if (L[i] == y) { continue; }
			if (L[i] < 2 * y) { cnt++; }
		}
		ans += tmp*cnt;
	}*/

	for (auto y : S) {
		if (C[y] <= 2) { continue; }
		long long  int tmp = ((long long int) C[y] * (C[y] - 1)*(C[y] - 2)) / 6;
		ans += tmp;
	}


	cout << ans << endl;

	return 0;
}

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

struct BINNODE {
	int key;
	BINNODE *parent;
	BINNODE *left;
	BINNODE *right;

	BINNODE (int k) {
		key=k;
		parent=nullptr;
		left=nullptr;
		right=nullptr;
	}
};

void preorderwalk(BINNODE* root) {
	if(root==nullptr) return;
	printf(" %d",root->key);
	preorderwalk(root->left);
	preorderwalk(root->right);
	return;
}

void inorderwalk(BINNODE* root) {
	if(root==nullptr) return;
	inorderwalk(root->left);
	printf(" %d",root->key);
	inorderwalk(root->right);
	return;
}

int main() {
	int m,v;
	int i;
	string cmd;
	BINNODE* root=nullptr;
	BINNODE* x;
	BINNODE* y;
	BINNODE* z;
	cin >> m;
	for(i=0; i<m; ++i) {
		cin >> cmd;
		if(cmd=="insert") {
			cin >> v;
			z=new BINNODE(v);
			y=nullptr;
			x=root;
			while(x!=nullptr) {
				y=x;
				if (z->key < x->key) {
					x=x->left;
				} else {
					x=x->right;
				}
			}
			z->parent = y;

			if(y==nullptr) {
				root=z;
			} else if(z->key < y->key) {
				y->left = z;
			} else {
				y->right = z;
			}
		} else {
			inorderwalk(root);
			printf("\n");
			preorderwalk(root);
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 26688
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3e5+5;
const ll mod=1e9+7;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
ll n,ans=0,mx=0,a[N],num[100]={0},cnt[64]={0};
void split(ll x){
    ll p=0;
    while(x){
        if(x%2) cnt[p]++;
        p++;
        x/=2;
    }
    mx=max(mx,p);
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i],split(a[i]);
    //cout<<mx<<endl;
    for(int i=1;i<=n;i++){
        for(ll j=0;j<mx;j++){
            //cout<<j<<endl;
            if(a[i]&(1LL<<j)) num[j]+=n-cnt[j];
            else num[j]+=cnt[j];
            //cout<<a[i]<<" "<<num[j]<<endl;
        }
    }
    for(ll i=0;i<100;i++){
        //cout<<cnt[i]<<" "<<num[i]<<endl;
        num[i+1]+=num[i]/2;
        if(num[i]%2) ans=(ans+power(2,i))%mod;
    }
    //cout<<ans<<endl;
    cout<<ans*power(2,mod-2)%mod;
    return 0;
}


Measured memory_bytes: 5920
N = int(input())
X = [0]
A = list(map(int,input().split()))
ans = 0
tlist = X+A+X
for i in range(N+1):
	ans += abs(tlist[i]-tlist[i+1])
for i in range(N):
	print(ans-(abs(tlist[i]-tlist[i+1])+abs(tlist[i+1]-tlist[i+2]))+abs(tlist[i]-tlist[i+2]))

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

int main() {
  int a, b, c, k, cnt = 0;

  cin >> a >> b >> c >> k;

  while (a >= b) {
    cnt++;
    b *= 2;
  }
  while (b >= c) {
    cnt++;
    c *= 2;
  }

  if (cnt <= k)
    cout << "Yes";
  else
    cout << "No";

  return 0;
}

Measured memory_bytes: 3632
#import pysnooper
import os,re,sys,operator,math,heapq,string
from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy

setrecursionlimit(10**6)
input=stdin.readline

s=list(input().rstrip())
ans=10000
for i in set(s):
    tmp=deque(s[:])
    cnt=0
    while len(set(tmp))!=1:
        cnt+=1
        for j in range(len(tmp)-1):
            if tmp[j+1]==i:
                tmp[j]=tmp[j+1]
            else:
                continue
        #print(tmp)
        tmp.pop()
    ans=min(ans,cnt)
print(ans)

Measured memory_bytes: 3828
#include<iostream>
#include<vector>
#include<map>

using namespace std;

int main(){
    int n, ans = 0;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    map<int, int> mp;
    for(auto i : a){
        mp[i]++;
    }
    for(auto i : mp){
        int f = i.first, s = i.second;
        if(s >= f){
            ans += s - f;
        }else{
            ans += s;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5120
//#pragma comment(linker, "/stack:200000000") //  (UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")  // $ (UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define endl "\n"
#define int long long
#define ll long long
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define fi first
#define se second
#define vi vector<int>
#define vii vector< vector<int> >
#define vpi vector< pair<int,int> >
#define pair <int, int> pii

typedef tree< int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>
    ordered_set;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the iterator to kth largest element.(0-based)

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

template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}

int modpow(int x, int n, int mod)
{
	x %= mod ;
	int res = 1;
	while(n > 0) {
		if(n & 1)
			res = res * x % mod ;
		x = x * x % mod ;
		n >>= 1 ;
	}
	return res;
}

const long long inf = 2e18 ;
const int mod = 1e9+7 ;
// const int mod = 998244353 ;
const int N = 1e5 + 10 ;

typedef long double ld;

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

        char c;
        cin>>c;
        c++;
        cout<<c<<endl;

return 0 ;
}


Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)
 
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]

    def Unite(self, x, y):
        x = self.Find_Root(x)
        y = self.Find_Root(y)
 
        if(x == y):
            return 
        elif(self.rnk[x] > self.rnk[y]):
            self.root[y] = x
        else:
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
 
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)
 
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

def main():
  N, M = map(int, input().split())
  p = list(map(int, input().split()))
  xy = [list(map(int, input().split())) for _ in range(M)]
  U = UnionFind(N+1)
  for x, y in xy:
    U.Unite(x, y)
  ans = 0
  for i in range(1, N+1):
    if U.isSameGroup(i, p[i-1]):
      ans += 1
  print(ans)


if __name__ == "__main__":
  main()

Measured memory_bytes: 32876
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define cn first
#define pn second.first
#define tn second.second

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int main(void){
    for(int t, p, r; cin >> t >> p >> r, t;){
        vector<vi> wc = vector<vi>(t, vi(p, 0));

        vector< pair<int, pii> > res(t);
        rep(i, t) res[i].tn = i;

        rep(i, r){
            int tid, pid, tm; string msg; cin >> tid >> pid >> tm >> msg;
            tid--, pid--;

            if(msg == "CORRECT"){
                res[tid].cn--;
                res[tid].pn += wc[tid][pid] * 1200 + tm;
            }
            else{
                wc[tid][pid]++;
            }
        }

        sort(all(res));
        rep(i, t){
            cout << res[i].tn + 1 << " "<< res[i].cn * -1 << " " << res[i].pn << endl;
        }
    }

	return 0;
}

Measured memory_bytes: 1240