akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

int dp[310][310][310];

int main(){
  int n,m,l,r,x;
  vector<pair<int,int> > query[310];

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

  for(int i=0;i<m;i++){
    scanf("%d%d%d",&l,&r,&x);

    query[r].push_back({l,x});
  }

  dp[0][0][0] = 1;
  
  for(int i=0;i<n;i++){
    for(int a=0;a<max(1,i);a++){
      for(int b=0;b<max(1,i);b++){
        if(a == b && (a != 0 || b != 0)) continue;
        
        bool flag[9] = {1,1,1,1,1,1,1,1,1};
        
        for(int j=0;j<query[i+1].size();j++){
          r = i+1;
          l = query[i+1][j].first;
          x = query[i+1][j].second;

          if(x == 3 && !(l <= a && l <= b)){
            flag[0] = false;
          }
          
          if(x == 2 && !(min(a,b) < l && l <= max(a,b))){
            flag[0] = false;
          }

          if(x == 1 && !(max(a,b) < l)){
            flag[0] = false;
          }

          if(x == 3 && !(l <= a && l <= i)){
            flag[1] = false;
          }
          
          if(x == 2 &&!( min(a,i) < l && l <= max(a,i))){
            flag[1] = false;
          }

          if(x == 1 && !(max(a,i) < l)){
            flag[1] = false;
          }
          
          if(x == 3 && !(l <= i && l <= b)){
            flag[2] = false;
          }
          
          if(x == 2 && !(min(i,b) < l && l <= max(i,b))){
            flag[2] = false;
          }

          if(x == 1 && !(max(i,b) < l)){
            flag[2] = false;
          }

        }
        
        if(flag[0]){
          dp[i+1][a][b] = (dp[i+1][a][b] + dp[i][a][b])%mod;
          dp[a][i+1][b] = (dp[a][i+1][b] + dp[a][i][b])%mod;
          dp[a][b][i+1] = (dp[a][b][i+1] + dp[a][b][i])%mod;
        }
        
        if(flag[1]){
          if(i==0 && a==0) break;
          dp[i][a][i+1] = (dp[i][a][i+1] + dp[i][a][b])%mod;
          dp[a][i][i+1] = (dp[a][i][i+1] + dp[a][i][b])%mod;
          dp[a][i+1][i] = (dp[a][i+1][i] + dp[a][b][i])%mod;
        }

        if(flag[2]){
          if(i==0 && b==0) break;
          dp[i][i+1][b] = (dp[i][i+1][b] + dp[i][a][b])%mod;
          dp[i+1][i][b] = (dp[i+1][i][b] + dp[a][i][b])%mod;
          dp[i+1][b][i] = (dp[i+1][b][i] + dp[a][b][i])%mod;
        }
        
      }
    }
    
  }

  ll ans = 0;
  /*
  for(int i=0;i<=n;i++){
    for(int j=0;j<=n;j++){
      for(int k=0;k<=n;k++){
        cerr << i << " " << j << " " << k << " : " << dp[i][j][k] << endl;
      }
    }
  }
  */
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      
      ans = (ans + dp[i][j][n])%mod;
      ans = (ans + dp[n][i][j])%mod;
      ans = (ans + dp[i][n][j])%mod;
    }
  }
  
  printf("%lld\n",ans);
  
  return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  //freopen("data.in", "r", stdin);
  int l; cin >> l;
  string s; cin >> s;
  int n = 0;
  for (int i = 0; i < l-2; i++) {
    if (s.substr(i, 3) == "ABC") n++;
  }
  cout << n << endl;
  return 0;
}


Measured memory_bytes: 3596
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;
#define int ll
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const int INF = (1 << 30);
const ll INFL = (1LL << 62);
const ll MOD = 1000000007;
template <class T>
bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T>
ll mod_pow(ll a, ll n, T mod) {
    mod = (ll)mod;
    ll res = 1, p = a % mod;
    while (n) {
        if (n & 1) res = res * p % mod;
        p = p * p % mod;
        n >>= 1;
    }
    return res;
}


signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    rep(i, N) cin >> C[i];
    sort(all(A));
    sort(all(B));
    sort(all(C));
    vector<int> less(N), more(N);
    ll ans = 0;
    rep(i, N) {
        int j = C.end() - upper_bound(all(C), B[i]);
        int k = N - (A.end() - lower_bound(all(A), B[i]));
        ans += j*k;
    }
    cout << ans << endl;
    return 0;
}


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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int64_t n, x;
  while(true){
    cin >> n >> x;
    if(n==0&&x==0) break;
    int count = 0;
    for(int i=1;i<=n;i++) {
      if(i>x-5) break;
      for(int j=i+1;j<=n;j++) {
        if(i+j>x-3) break;
        for(int k=j+1;k<=n;k++) {
          if(i+j+k==x) count++;
          if(i+j+k>x) break;
        }
      }
    }
    cout << count << endl;
  }
  return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
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;}
constexpr int INF=1000000000000000000;
constexpr int mod=998244353;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
int n,a[310],ans=1,sum,dp[310][90010],dp2[310][90010];
signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>n;
    rep(i,n){
        cin>>a[i];
        sum+=a[i];
        ans*=3;
        ans%=mod;
    }
    dp[0][0]=3,dp2[0][0]=3;
    rep(i,n){
        rep(j,90000){
            if(j+a[i]<=90000){
                dp[i+1][j+a[i]]+=dp[i][j];
                dp[i+1][j+a[i]]%=mod;
                dp2[i+1][j+a[i]]+=dp2[i][j];
                dp2[i+1][j+a[i]]%=mod;
            }
            dp[i+1][j]+=dp[i][j]*2%mod;
            dp[i+1][j]%=mod;
            dp2[i+1][j]+=dp2[i][j];
            dp2[i+1][j]%=mod;
        }
    }
    for(int i=(sum+1)/2;i<=sum;i++){
        ans-=dp[n][i]%mod;
        ans+=mod;
        ans%=mod;
    }
    if(sum%2==0)ans+=dp2[n][sum/2]%mod;
    ans%=mod;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 425600
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;

static const int INF=1e9;
typedef long long ll;

int main(){
    int N,M; cin >> N >> M;
    int cnt[100000+2]={};
    for(int i=0;i<M;i++){
        int l,r;
        cin >> l >> r;
        //cnt[l-1]--;
        cnt[l]++;
        cnt[r+1]--;
    }
    for(int i=1;i<=100001;i++){
        cnt[i]+=cnt[i-1];
    }
    int ans=0;
    for(int i=1;i<=100001;i++){
        if(cnt[i]>=M){
            ans++;
        }
    }
    cout << ans << endl;
}

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

int main(){
    int N,M;
    cin>>N>>M;
    int L[100000],R[100000];
    for(int i=0;i<M;i++){
        cin >> L[i]>> R[i];
    }
    int a=0,b=0;
    for(int i=0;i<M;i++){
        if(i==0){
            a=L[i];
            b=R[i];
        }
        else{
            if(a<=L[i]){
                if(b<=R[i]){
                    a=L[i];
                }
                else{
                    b=R[i];
                    a=L[i];
                }
            }
            else{
                if(b<=R[i]){
                }
                else{
                    b=R[i];
                }
            }
        }
    }
        cout<<max(0,b-a+1)<<endl;
        return 0;
    }

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;


void solve()
{
	string s;
	cin>>s;
	int n=s.size();
	bool ok=true;
	rep(i,n){
		if(i%2==0){
			if(s.substr(i,2)=="hi"){

			}else{
				ok=false;
			}
		}
	}
	if(ok){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long N,M;cin>>N>>M;
  vector<long>A(N,0);
  for(long i=0;i<M;i++){
    long a,b;cin>>a>>b;A[a-1]++;A[b-1]++;
  }
  bool a=1;
  for(long i=0;i<N;i++)a*=(A[i]%2==0);
  cout<<(a?"YES":"NO");
}


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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

LL modinv(LL a) {
    LL b = MOD, u = 1, v = 0;
    while (b) {
        LL t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return u;
}

LL moddev(LL a, LL b){
	return a * modinv(b) % MOD;
}

void Main()
{
    int a,b;cin>>a>>b;

    int ax = ceil(a/0.08);
    int bx = ceil(b/0.1);

    int result = max(ax,bx);

    if((int)(result*0.08) != a || (int)(result*0.1) != b){
        cout<<-1<<endl;
        return;
    }

    cout<<result<<endl;



	return;
}

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

Measured memory_bytes: 256
#include<stdio.h>

int H;

void maxHeapify(int *A,int i){
  int largest;
  int kari;
  if(2*i<=H&&A[2*i]>A[i])largest=2*i;
  else largest = i;
  if((2*i+1)<=H&&A[2*i+1]>A[largest])largest=2*i+1;
  if(largest!=i){
    kari=A[i];
    A[i]=A[largest];
    A[largest]=kari;
    maxHeapify(A,largest);
  }
}

void buildMaxHeap(int *A){
  for(int i=H/2;i>0;i--){
    maxHeapify(A,i);
  }
}

int main(){
  int i;
  
  scanf("%d",&H);

  int A[H+1];
  
  A[0]=0;
  
  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
  }

  buildMaxHeap(A);

  for(i=1;i<=H;i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 3752
#include <iostream>

using namespace std;

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

    if (n % 10 == 3) {
        cout << "bon" << endl; 
    }
    else if (n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8){
        cout << "pon" << endl;
    }
    else {
        cout << "hon" << endl;
    }
    return 0;
}

Measured memory_bytes: 3596
n = gets.chomp
m = gets.to_i
size = n.size
dp = Array.new(size + 1) { Array.new(2) { Array.new(size + 1) { 0 } } }
dp[0][0][0] = 1

0.upto(size - 1) do |i|
  2.times do |j|
    size.times do |k|
      d = n[i].to_i
      0.upto(j == 0 ? d : 9) do |l|
        dp[i + 1][j == 1 || l < d ? 1 : 0][l != 0 ? k + 1 : k] += dp[i][j][k]
      end
    end
  end
end

puts size < m ? 0 : dp[size][0][m] + dp[size][1][m]


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

using namespace std;

#define vv vector< vector< int > >
#define ll long long
#define ALL(a) (a).begin(), (a).end()
const long long mod = 1000000000 + 7;
const long long INF = 9e18;
const double PI = 3.14159265358979323846;

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

map<int, int> num;

int main(){
    int N, M, X, ans;
    cin >> N >> M >> X;
    vector<int> A(M);
    for(int i = 0; i < M; ++i) cin >> A[i];
    auto itr = lower_bound(A.begin(), A.end(), X);
    ans  = min(abs(itr - A.begin()), abs(A.end() - itr));
    cout << ans << endl;
    return 0;
}


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

using namespace std;

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

  vector<int> x(n);
  for(int idx = 0; idx < n; idx++){
    cin >> x[idx];
  }
  
  int ans = 0;
  for(int idx = 0; idx < n; idx++){
    ans += min(x[idx], abs(k - x[idx]));
  }

  cout << ans * 2 << '\n';

  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

type bufReader struct {
	r   *bufio.Reader
	buf []byte
	i   int
}

var reader = &bufReader{
	bufio.NewReader(os.Stdin),
	make([]byte, 0),
	0,
}

func (r *bufReader) readLine() {
	if r.i < len(r.buf) {
		return
	}
	r.buf = make([]byte, 0)
	r.i = 0
	for {
		line, isPrefix, err := r.r.ReadLine()
		if err != nil {
			panic(err)
		}
		r.buf = append(r.buf, line...)
		if !isPrefix {
			break
		}
	}
}

func (r *bufReader) next() string {
	r.readLine()
	from := r.i
	for ; r.i < len(r.buf); r.i++ {
		if r.buf[r.i] == ' ' {
			break
		}
	}
	s := string(r.buf[from:r.i])
	r.i++
	return s
}

func (r *bufReader) nextLine() string {
	r.readLine()
	s := string(r.buf[r.i:])
	r.i = len(r.buf)
	return s
}

var writer = bufio.NewWriter(os.Stdout)

func next() string {
	return reader.next()
}

func nextInt() int {
	i, err := strconv.Atoi(reader.next())
	if err != nil {
		panic(err)
	}
	return i
}

func nextLine() string {
	return reader.nextLine()
}

func out(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}
func joinInts(a []int, sep string) string {
	b := make([]string, len(a))
	for i, v := range a {
		b[i] = strconv.Itoa(v)
	}
	return strings.Join(b, sep)
}

func main() {
	defer writer.Flush()
	_, A, B := nextInt(), nextInt(), nextInt()
	S := nextLine()
	passed, rankB := 0, 0
	for _, r := range S {
		ans := "No"
		switch r {
		case 'a':
			if passed < A+B {
				ans = "Yes"
				passed++
			}
		case 'b':
			rankB++
			if passed < A+B && rankB <= B {
				ans = "Yes"
				passed++
			}
		}
		out(ans)
	}
}


Measured memory_bytes: 3328
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

MOD = 10**9+7
N = int(input())
A = list(map(int, input().split()))
B = [0]*60
C = [0]*60

for i in range(60):
    for j in range(N):
        if (A[j]>>i)&1 == 0:
            C[i] += 1
        else:
            B[i] += 1

ans = 0
for i in range(60):
    ans += B[i]*C[i]*2**i%MOD
print(ans%MOD)

Measured memory_bytes: 123132
#include<bits/stdc++.h>
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
using namespace std;
bool compare_by_b(pair<string, int> a, pair<string, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second > b.second;
    }
}
int main(){
  int n;
  cin >>n;
  vector<pair<string,int>>s;
  string ss;
  int p[n];
  for(int i=0;i<n;i++){
    cin >>ss >>p[i];
    s.push_back(make_pair(ss,p[i]));
  }
  sort(s.begin(),s.end(),compare_by_b);
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(s[i].second==p[j])cout<<j+1<<endl;
    }
  }
}

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

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

Node *root, *NIL;

void insert(int k)
{
	Node *y=NIL;
	Node *x=root;
	Node *z;
	
	z=(Node *)malloc(sizeof(Node));
	z->key=k;
	z->left=NIL;
	z->right=NIL;
	
	while(x!=NIL)
	{
		y=x;
		if(z->key < x->key) x=x->left;
		else x=x->right;
	}
	z->parent=y;
	if(y==NIL) root=z;
	else
	{
		if(z->key < y->key) y->left=z;
		else y->right=z;
	}
}

void inorder(Node *u)
{
	if(u==NIL) return;
	inorder(u->left);
	printf(" %d", u->key);
	inorder(u->right);
}

void preorder(Node *u)
{
	if(u==NIL) return;
	printf(" %d", u->key);
	preorder(u->left);
	preorder(u->right);
}

int main()
{
	int i,n,x;
	string com;
	
	scanf("%d",&n);
	
	for(i=0;i<=n-1;i++)
	{
		cin >> com;
		if(com=="insert")
		{
			scanf("%d",&x);
			insert(x);
		}
		else if(com=="print")
		{
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 26716
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;

int main(){
	char str[64];
	int i;
	cin >> str;
	for(i=1;i<=strlen(str);i++){
		cout << str[strlen(str)-i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1132
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<math.h>
#include<tuple>
#include<string.h>
#include <numeric> 
#include<unordered_map>
using namespace std; 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define pp(...) "\033[94m [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define pp1(...) "\033[1;47;35m" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define dg(x) debug() << pp1(x)
#define dg1(x) debug() << pp(x)
#define dg2(x,y) debug() << pp(x) pp(y)
#define dg3(x,y,z) debug() << pp(x) pp(y) pp(z)
#define dg4(w,x,y,z) debug() << pp(w) pp(x) pp(y) pp(z)
#define int long long
#define all(x) x.begin() , x.end()
#define clr(x) memset(x , 0 , sizeof x);
#define sz(x) (int)x.size()
template<typename T> void db(T x ){ debug() <<">>> " <<  x; }
template<typename T> void db(T x , T y){ debug() <<">>> " <<  x <<" , "<< y; }
template<typename T> void db(T x , T y , T z){ debug() <<">>> "<< x <<" , "<< y <<" , "<< z; }
template<typename T> void db(T x , T y , T z , T a){ debug() <<">>> "<< x <<" , " << y <<" , "<< z <<" , "<< a; }
const int xx = 2e5;
const int Mod = 1e9 + 7;
const int inf = 1e18;
const int Maxn = 20010;

signed main(){
  ios::sync_with_stdio(false);cin.tie(0);
  int N;
  cin >> N;
  map<string , int>mp;
  for(int i = 0; i < N; i++) {
    string x;
    cin >> x;
    mp[x]++;
  }
  cout << "AC x " << mp["AC"] << '\n';
  cout << "WA x " << mp["WA"] << '\n';
  cout << "TLE x " << mp["TLE"] << '\n';
  cout << "RE x " << mp["RE"] << '\n';
}

Measured memory_bytes: 3236
#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define repi(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
using namespace std;
typedef long long ll;

int main() {
  char b; cin >> b;
  map<char,char> mp;
  mp['A'] = 'T';
  mp['C'] = 'G';
  mp['G'] = 'C';
  mp['T'] = 'A';
  cout << mp[b] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void secondsort(vector<pair<int,int>> &v){
    for(int i=0;i < v.size();i++){
    swap(v.at(i).first,v.at(i).second);
    }
    sort(v.begin(),v.end());
    for(int i=0;i < v.size();i++){
    swap(v.at(i).first,v.at(i).second);
    }
}
    
int main(){
    int n,ans=0;
    cin >> n;
    vector<pair<int,int>> r(n);
    vector<pair<int,int>> b(n);
    for(int i=0;i < n;i++){
        cin >> r.at(i).first >> r.at(i).second;
    }
    for(int i=0;i < n;i++){
        cin >> b.at(i).first >> b.at(i).second;
    }
    sort(r.begin(),r.end());
    secondsort(b);

    for(int i=r.size()-1;-1<i;i--){
        for(int j=0;j < b.size();j++){
            if(r.at(i).first < b.at(j).first && r.at(i).second<b.at(j).second){
                ans++;
                r.erase(r.begin()+i);
                b.erase(b.begin()+j);
                j--;
                break;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
require 'matrix'
require 'bigdecimal'
require 'bigdecimal/util'
require 'bigdecimal/ludcmp'
include LUSolve

def len3d(x, y)
  l2=0.0
  0.upto(3-1){|i|
    l2 += (x[i] - y[i])**2
  }
  return Math.sqrt(l2)
end

def heron(a,b,c)
  s = (a + b + c) / 2.0
  return  Math.sqrt(s*(s-a).abs*(s-b).abs*(s-c).abs)
end

Eps=1e-9
def solve(a,b,c,d,e)   # returns true if beam hits barrier.
  # a, b, c: ????????¢???????§???¢??????????????????????????????
  # d:???????????????????????????
  # e:???????????????????????????
  # a + s*u + t*v = d + x*w ????§£??????(0<x<1) ???P(d+xw)???????§???¢ABC????????¨???????????°??????????????????????????????
  # ??????????????????true?????§???????????°false????????????
  u = c - a
  v = b - a
  w = e - d
  m = Matrix.columns([u, v, -w])
  m1 = m.to_a.flatten
#  m = [[u[0],v[0],-w[0]],[u[1],v[1],-w[1]],[u[2],v[2],-w[2]]].flatten.map{|x| x.to_d}

#  abort("Impssible case") if m.determinant.abs <=Eps
  return false if m.determinant.abs <Eps
  parms = m.inv * (d - a)
  #parms = m.lup.solve(d - a)
=begin
  f = (d-a).to_a
  zero = '0.0'.to_d
  one = '1.0'.to_d
  ps = ludecomp(m1, f.size, zero, one)  # a ?????´?£????????????´?????????
  parms = lusolve(m1, f, ps, zero)
=end

  s = parms[0]
  t = parms[1]
  x = parms[2]
# ???P???????§???¢ABC??????????????¢??¨??´???DE??¨?????????
  return false if x < 0 or x > 1.0
#return true if x.abs<Eps
  p = d + x*w
# ????§???¢ PAC, PAB, PBC?????¢???????????¨????§???¢ABC?????¢????????????????????°???P???ABC???????????????
  pa = len3d(a, p)
  pb = len3d(b, p)
  pc = len3d(c, p)

  ab = len3d(b, a)
  ac = len3d(c, a)
  bc = len3d(c, b)
begin
  s0=heron(ab,ac,bc)
  s1=heron(pa,pc,ac)
  s2=heron(pa,pb,ab)
  s3=heron(pb,pc,bc)
rescue => ex
  puts "MISS"
  exit
end

  return  (s1+s2+s3-s0).abs <Eps
end

def main
  if true then
#  if false then
    fh=STDIN
  else
    #fh=open("in1_0115a.txt")
    #fh=open("in1_0115b.txt")
    fh=open("in1_0115c.txt")
  end
  d1,d2,d3=fh.gets.chomp.split.map{|x| x.to_i}
  e1,e2,e3=fh.gets.chomp.split.map{|x| x.to_i}

  a1,a2,a3=fh.gets.chomp.split.map{|x| x.to_i}
  b1,b2,b3=fh.gets.chomp.split.map{|x| x.to_i}
  c1,c2,c3=fh.gets.chomp.split.map{|x| x.to_i}

  d=Vector[d1,d2,d3]
  e=Vector[e1,e2,e3]
  a=Vector[a1,a2,a3]
  b=Vector[b1,b2,b3]
  c=Vector[c1,c2,c3]

  if solve(a,b,c,d,e) then
    puts "MISS"
  else
    puts "HIT"
  end

end

if $0 == __FILE__ then
  main
end

Measured memory_bytes: 9416
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

/*
k s

k 2 2500
s 3k
 */
int k,s;

int main(){
  cin >> k >> s;
  int ans=0;
  FOR_IN(i, max(0,s-2*k), min(s,k)+1){
    int ss = s-i;
    ans += min(k,ss) - max(0, ss - k) + 1;
  }

  cout << ans << endl;

  return 0;
}


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

int main(){
  int a,b;
  scanf("%d %d",&a,&b);
  int c=b,i=0;;
  while(c>=1){
    c/=10;
    i++;
  }
  int d=a*(int)pow(10,i)+b;
  //printf("%d\n", d);
  //printf("%f\n", sqrt(d));
  if((int)sqrt(d)*(int)sqrt(d)==d)printf("Yes\n");
  else printf("No\n");
}


Measured memory_bytes: 384
N = int(input())
P = list(map(int,input().split()))
#PS = [i for i in range(1,N+1)]
 
cnt = 0
i = 0
idx = []
while i < N:
    if P[i] == i+1:
        if idx:
            if i == idx[0] + 1 :
                idx = []
            else:
                cnt += 1
                idx = [i]
        else:
            idx.append(i)
            cnt += 1
    i += 1   
print(cnt)
    
    


Measured memory_bytes: 14008
M, K = map(int, input().split())

ans = [-1]
if M == 1:
  if K == 0:
    ans = [0, 0, 1, 1]
else:
  if K < 2**M:
    b = [i for i in range(2**M) if i != K]
    ans = b + [K] + b[::-1] + [K]

print(*ans)

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

using namespace std;
using ll = long long;

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((int)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back

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

    bool f = true;
    if(N % 2 == 1) f = false;
    else{ 
        REP(i,0,N/2){
            if(S[i] != S[i + N/2]){
                f = false;
                break;
            }
        }
    }

    if(f) _PR("Yes");
    else _PR("No");

    return 0;
}

/*



*/

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
 
int main()
{
  int N;
  long a[302][302];
  long b[302][302];
  bool v[302][302];
  cin >> N;
 
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      cin >> a[i][j];
      b[i][j] = a[i][j];
      
    }
  }
 
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= N; j++) v[i][j] = 1;
 
  for (int k = 1; k <= N; k++)
    for (int i = 1; i <= N; i++)
      for (int j = 1; j <= N; j++) if (a[i][j]>=a[i][k] + a[k][j]&&i!=k&&j!=k) {
        a[i][j] = a[i][k] + a[k][j];
        v[i][j] = v[j][i] = 0;
      }
 
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= N; j++)if (a[i][j] != b[i][j]) 
    { 
      cout << -1 << endl;
      return 0; 
    }
 
  long long ans = 0;
 
  for (int i = 1; i <= N; i++) 
    for (int j = i+1; j <= N; j++) {
      if (v[i][j]) ans+=a[i][j];
    }
 
  cout << ans <<endl;
 
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define endl '\n';
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;




int main() {
    
    ll x,y;
    cin>>x>>y;

    ll ans=0;
    while(x<=y){
        ans++;
        x*=2;
    }
    fin(ans);

}



Measured memory_bytes: 256
# include <iostream>

int main(){
 int a;
 std::cin >> a;
 int h, m, s;
 h = a /3600;
 m = a % 3600 / 60;
 s = a % 60;
 std::cout << h << ":" << m << ":" << s << std::endl;
 return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;

int N;
vector<vector<int>> bit(26,vector<int>(1000010));

//アルファベットi番目のj番目の値をw加算
void add(int i,int j,int w) {
    while(j <= N) {
        bit[i][j] += w;
        j += j & -j;
    }
}

int sum(int i,int j) {
    int ret = 0;
    while(j > 0) {
        ret += bit[i][j];
        j -= j & -j;
    }
    return ret;
}

int main() {
    cin >> N;
    string S;
    cin >> S;
    for(int i = 0;i < N;i++) {
        add(S.at(i) - 'a',i + 1,1);
    }
    int Q;
    cin >> Q;
    for(int i = 0;i < Q;i++) {
        int A;
        cin >> A;
        if(A == 1) {
            int B;
            char C;
            cin >> B >> C;
            add(S.at(B - 1) - 'a',B,-1);
            add(C - 'a',B,1);
            S.at(B - 1) = C;
        }
        else {
            int B,C;
            cin >> B >> C;
            int ret = 0;
            for(int j = 0;j < 26;j++) {
                if(sum(j,C) - sum(j,B - 1) > 0) {
                    ret++;
                }
            }
            cout << ret << endl;
        }
    }
}

Measured memory_bytes: 105856
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <queue>
#include <algorithm>
#include <utility>
#include <vector>
#include <tuple>
#include <numeric>
using namespace std;


int main(int argc, char* argv[]){
	char N[200001];
	scanf("%s", N);
	string N_str = N;
	long long sum = 0;
	for(int i=0; i<(int)N_str.length(); i++){
//		printf("%c", N_str[i]);
		string str = N_str.substr(i, 1);
		int n = atoi(str.c_str());
		sum += (long long)n;
	}
//	printf("%lld", sum);
	if(sum%9==0){
		printf("Yes\n");
	}else{
		printf("No\n");
	}

}


Measured memory_bytes: 3868
#55 C - Cat Snuke and a Voyage
from collections import deque
N,M = map(int,input().split())
G = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1; b -= 1
    G[a].append(b)
    G[b].append(a)

# BFS のためのデータ構造
dist = [-1]*N
que = deque([])

# 初期条件 (島 1 を初期ノードとする)
dist[0] = 0
que.append(0)

while (len(que) != 0):
    v = que.popleft()# キューから先頭頂点を取り出す
    for next_v in G[v]:
        if (dist[next_v] != -1):# next_v が探索済みならスルー
            continue
        #新たな頂点 next_v について情報を更新してキューに追加
        dist[next_v] = dist[v] + 1
        que.append(next_v)
        
if dist[N-1] == 2:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 113068
#include<stdio.h>
int main(){
int n=0;
int k=0;
int d=0;
int A[100]={0};
int c=0;
int sum=0;
int ss=0;
scanf("%d %d",&n,&k);
// printf("%d%d\n",n,k);
for(int i=0;i<k;i++){
    // printf("%droop\n",i);
    scanf("%d",&ss);
    d=ss;
    // printf("d=%d\n",d);
    for(int j=0;j<n;j++){
        scanf("%d",&c);
        // printf("j=%d\n",j);
        A[c-1]=1;
        if(j==d-1){break;}
    }
    if(i==n-1){break;}
}
for(int i=0;i<n;i++){
    if(A[i]==0){
        sum++;
        // printf("A[]\n");
    }

}

printf("%d",sum);
return 0;

}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define mp make_pair
#define st first
#define nd second

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

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}
// End of template code!
int main() 
{
    buff();
    constexpr ll lim = 3900;
    ll x;
    vector<ll> val;
    vector<ll> root;
    for(ll i = 0; i < lim; ++i) {
        ll v = (i * i * i * i * i);
        val.emplace_back(v);
        root.emplace_back(i);
    }
    pair<ll, ll> ans;
    cin >> x;
    int len = sz(val);
    for(int i = 0; i < len; ++i) {
        ll diff = (x - val[i]);
        if(diff == 0) {
            ans = {root[i], 0};
            break;
        }
        if( diff > 0 ) {
            auto it = lower_bound(all(val), diff);
            if(it != val.end()) {
                if(*it == diff) {
                    int dist = (int) (it - val.begin());
                    ans = {root[i], -root[dist]};
                    break; 
                }
            }
        }
        if( diff < 0 ) {
            diff = (-diff);
            auto it = lower_bound(all(val), diff);
            if(it != val.end()) {
                if(*it == diff) {
                    int dist = (int) (it - val.begin());
                    ans = {root[i], root[dist]};
                    break;
                }
            }
        }
    }
    cout << ans.first << " " << ans.second << '\n';
    return 0;
}



Measured memory_bytes: 3740
import std.stdio;
import std.ascii;
import std.conv;
import std.string;
import std.algorithm;
import std.range;
import std.functional;
import std.math;
import core.bitop;

void main()
{
    auto i = readln.chomp;
    if (i[0] != 'A')
    {
        "WA".writeln;
        return;
    }
    if (i[1].isUpper || i[$ - 1].isUpper)
    {
        "WA".writeln;
        return;
    }
    long cntc;
    foreach (c; i[2 .. $ - 1])
    {
        if (c == 'C')
        {
            cntc++;
        }
        if (c.isUpper && c != 'C')
        {
            "WA".writeln;
            return;
        }
    }
    if (cntc != 1)
    {
        "WA".writeln;
        return;
    }
    "AC".writeln;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
ll p[5005];
ll c[5005];
vector<ll>v[5005];
ll k1=0,n,k;
bool vis[5005];
ll func(ll x)
{
    ll p1=0,m1=-6e18,i,j;
    ll l=v[x].size();
    ll ara[2*l+5];
    ara[0]=0;
    for(i=0;i<l;i++)
    {
        ara[i+1]=c[v[x][i]];
        m1=max(m1,ara[i+1]);
    }
    for(i=1;i<=l;i++)ara[i+l]=ara[i];
    for(i=2;i<=2*l;i++)ara[i]+=ara[i-1];
    if(ara[l]>=0)
    {
        ll v=k/l;
        p1=p1+v*ara[l];
    }
    ll h=k%l,mx=0;
    for(i=1;i<=2*l;i++)
    {
        for(j=i;j<=2*l;j++)
        {
            if((j-i+1)>h)continue;
            mx=max(mx,ara[j]-ara[i-1]);
        }
    }
    p1+=mx;
    for(i=1;i<=2*l;i++)
    {
        for(j=i;j<=2*l;j++)
        {
            ll sz=j-i+1;
            if(sz>k)continue;
            ll v=(k-sz)/l;
            p1=max(p1,ara[j]-ara[i-1]+v*ara[l]);
            p1=max(p1,ara[j]-ara[i-1]);
        }
    }
    if(p1>0)return p1;
    return m1;
}
main()
{
     ll i,ans=-5e18;
     cin>>n>>k;
     for(i=1;i<=n;i++)cin>>p[i];
     for(i=1;i<=n;i++)cin>>c[i];
     for(i=1;i<=n;i++)
     {
         if(vis[i]==1)continue;
         ll a=i;
         while(vis[a]==0)
         {
             v[k1].push_back(a);
             vis[a]=1;
             a=p[a];
         }
         k1++;
     }
     //cout<<k1<<endl;
     for(i=0;i<k1;i++)
     {
         ans=max(ans,func(i));
     }
     cout<<ans<<endl;
}


Measured memory_bytes: 4012
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
#define vl vector<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++)


int main() {
  ll N,Y;
  cin>>N>>Y;
  rep(i,N+1){
    rep(j,N+1){
      if(N<i+j){
        break;
      }
      ll sum=i*10000+j*5000+(N-i-j)*1000;
      if(sum==Y){
        cout<<i<<' '<<j<<' '<<N-i-j<<endl;
        return 0;
      }else if(sum>Y){
        break;
      }
    }
    if(i==N){
      cout<<"-1 -1 -1"<<endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
from collections import Counter
from operator import itemgetter

n = int(input())
v = tuple(map(int, input().split()))

evens = Counter(v[::2])
odds = Counter(v[1::2])

evens = list(sorted(evens.items(), key=itemgetter(1), reverse=True))
odds = list(sorted(odds.items(), key=itemgetter(1), reverse=True))
# 出現数降順ソート

ans = n
for even_num, even_cnt in evens[:2] + [(-1, 0)]:
    for odd_num, odd_cnt in odds[:2] + [(-1, 0)]:
        if even_num == odd_num: continue
        ans = min(ans, n - even_cnt - odd_cnt)
# evensとoddsの書き換え先候補として、出現率上位2数を調べる
# 同じ数は使用できない
# 1111のようにevensとoddsがともに同じ数字しかない場合に備え、
# vの要素に含まれない値-1が0個あると考える(片方の-1をすべて書き換えると考える）

print(ans)


Measured memory_bytes: 18660
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define M 1000040
char c[20],a[20]; /* Hash Table */
int dic[1000040][20];

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  return 4;
}
int h1(int b){return b%M;}
int h2(int b){return 1+b%(M-1);}
int find(int x,int y,int sum,int ch){
  int i=1,h,j=0;
  if(x==strlen(a)){
    h=(h1(sum)+h2(sum))%M;
    if(!ch){
      if(dic[h][0]!=NULL){
	while(dic[h][i]!=NULL){
	  i++;
	}
	dic[h][i]=sum;
	return 0;
      }else{
	dic[h][0]=sum;
	return 0;
      }
    }
    while(dic[h][j]!=NULL && dic[h][j]!=sum){
      j++;
    }
    if(dic[h][j]==NULL) return 0;
    else return dic[h][j];
  }
  return find(x+1,y*4,sum+y*getChar(a[x]),ch);
}

int main(){
    int i,x,t, n, h;
    scanf("%d", &n);
    for ( i = 0; i < n; i++ ){
      scanf("%s %s", c, a);
      if ( c[0] == 'i' ){
	find(0,1,0,0);
      } else {
	if (find(0,1,0,1)>0){
	  printf("yes\n");
	} else {
	  printf("no\n");
	}
      }
    }

    return 0;
}



Measured memory_bytes: 79684
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
const int N = 1e5+9;
const ll INF = 1LL<<60;

int n;
vector<ll> load(N, INF);

int main() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        int a; cin >> a; a = -a;
        *upper_bound(load.begin(), load.end(), a) = a;
    }
    ll nothing = count(load.begin(), load.end(), INF);
    cout << load.size() - nothing << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#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;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N;
  cin >> N;
  vi A(N);
  rep(i,N) {
    cin >> A[i];
  }
  int sign = -1;
  int temp = 0;
  rep(i,N-1) {
    temp += sign * A[i];
    sign *= -1;
  }
  int last = temp + A[N-1];
  vi ans(N);
  ans[0] = last;
  srep(i,1,N) {
    ans[i] = A[N-i-1] * 2 - ans[i-1];
  }
  reverse(rng(ans));
  rep(i,N) {
    cout << ans[i];
    if(i < N-1){
      cout << " ";
    } else {
      cout << endl;
    }
  }
  return 0;
}

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

int N;
const int MAX = 150000;
vector<int> edges[MAX];
int parent[MAX];
double ans[MAX];

double dfs(int i, int prev){
    double ret = 0.0;
    parent[i] = prev;
    for(auto j : edges[i]){
        if(j == prev) continue;
        ret += dfs(j, i) + 1.0;
    }
    if(edges[i].size()>1){
        ret /= edges[i].size() - (i == 0 ? 0 : 1);
    }
    ans[i] = ret;
    return ret;
}

void dfs2(int i){
    if(parent[i] >= 0){
        int p = parent[i];
        int sz = edges[p].size();
        double add;
        if(sz>1){
            add = (ans[p] * sz - ans[i] - 1.0) / (sz-1) + 1.0;
        }else{
            add = 1.0;
        }
        sz = edges[i].size();
        ans[i] = (ans[i] * (sz-1) + add) / sz;
    }
    for(auto j : edges[i]){
        if(j != parent[i]) dfs2(j);
    }
}

int main(){
    int i, j, k;
    cin >> N;
    for(i=0; i<N-1; i++){
        int u, v;
        cin >> u >> v;
        edges[u-1].push_back(v-1);
        edges[v-1].push_back(u-1);
    }

    dfs(0, -1);
    dfs2(0);
    cout << fixed << setprecision(10);
    for(i=0; i<N; i++) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 16768
from collections import Counter

def submit():
    n = int(input())
    vlist = list(map(int, input().split()))

    odd_count = Counter(vlist[0::2]).most_common()
    even_count = Counter(vlist[1::2]).most_common()

    if odd_count[0][0] == even_count[0][0]:
        if len(odd_count) == len(even_count) == 1:
            print(n // 2)
        elif odd_count[0][1] > even_count[0][1]:
            print(n - odd_count[0][1] - even_count[1][1])
        elif odd_count[0][1] < even_count[0][1]:
            print(n - odd_count[1][1] - even_count[0][1])    
        else:
            if odd_count[1][1] > even_count[1][1]:
                print(n - even_count[0][1] - odd_count[1][1])
            else:
                print(n - odd_count[0][1] - even_count[1][1])
    else:
        print(n - odd_count[0][1] - even_count[0][1])


if __name__ == "__main__":
    submit()

Measured memory_bytes: 20692
#include<bits/stdc++.h>
#define ll long long
#define lld long double
using namespace std;
template<typename tn> void read(tn &a){
	tn x=0,f=1; char c=' ';
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	a=x*f;
}
const lld pi=acosl(-1);
int n,T[5010];
ll L;
lld ansx,ansy;
int main(){
	read(n);read(L);
	for(int i=1;i<=n;i++) read(T[i]);
	for(int i=1;i<n;i++)
		for(int j=i+1;j<=n;j++){
			ansx+=cosl(pi*(T[i]+T[j])/L)*(n-j+i-1)+cosl(pi*(T[i]+T[j]+L)/L)*(j-i-1);
			ansy+=sinl(pi*(T[i]+T[j])/L)*(n-j+i-1)+sinl(pi*(T[i]+T[j]+L)/L)*(j-i-1);
		}
	lld cnt=1.l*n*(n-1)*(n-2)/6;
	printf("%.10Lf %.10Lf\n",ansx/cnt,ansy/cnt);
	return 0;
}


Measured memory_bytes: 256