akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.rbegin(), cont.rend()
#define unique(a)        (a).erase(unique((a).begin(), (a).end()),(a).end())
#define fastio          ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define PB push_back
#define endl "\n"
#define mod 1000000007 
typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
inline LL moduloMultiplication(LL x, LL y) { return (x%mod * 1LL * y%mod) % mod; }
inline LL power(LL a, LL b) {
	LL x = 1 % mod;
	while (b) {
		if (b & 1) x = moduloMultiplication(x, a);
		a = moduloMultiplication(a, a);
		b >>= 1;
	}
	return x % mod;
}
LL gcd(LL a, LL b)
{
	if (!a)
		return b;
	return gcd(b%a, a);
}
inline LL add(LL x, LL y) { x += y; if (x >= mod) x -= mod; return x; }
int main()
{
	int n;
	cin >> n;
	VI v(n);
	rep(i, n)cin >> v[i];
	vector<int>dp(n);
	dp[0] = 0;
	dp[1] = abs(v[1]-v[0]);
	for (int i = 2; i < n; i++) {
		dp[i] = min(dp[i-1]+abs(v[i - 1]-v[i]), dp[i-2] +abs(v[i - 2]-v[i]));
	}

	cout << dp[n - 1] << endl;





}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <tuple>
#include <iomanip>
#include <algorithm>
#include <iterator>
#define PB push_back
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(c) c.begin(),c.end()
#define SHOWVEC(v) for (auto e : v) cerr << e << ' '; cerr << endl;
#define SHOWP(p) cerr << "[" << p.first << "," << p.second << "]" << endl;
#define Decimal fixed << setprecision(20)
#define FI first
#define SE second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
constexpr int INF = 1100000000;
constexpr ll LLINF = 1100000000000000000;

bool hasDifferentChar(string &s, string &t) {
  string a(s), b(t);
  sort(ALL(a));
  a.erase(unique(ALL(a)), a.end());
  sort(ALL(b));
  b.erase(unique(ALL(b)), b.end());
  for (auto be : b) {
    if (a.find(be) == string::npos) return true;
  }
  return false;
}

int main()
{
  string s, t;
  cin >> s >> t;
  if (hasDifferentChar(s, t)) {
    cout << -1 << endl;
    return 0;
  }
  map<char, vector<ll>> mp;
  REP(i, s.size()) {
    mp[s[i]].PB(i);
  }

  ll idx = -1, ans = 0;
  auto dist = [](ll i, ll j, ll len) {
    if (i == j) return len;
    else if (i < j) return j - i;
    else return len - (i - j);
  };
  REP(i, t.size()) {
    auto itr = upper_bound(ALL(mp[t[i]]), idx);
    ll next;
    if (itr == mp[t[i]].end()) next = mp[t[i]][0];
    else next = *itr;
    ans += dist(idx, next, s.size());
    idx = next;
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 1656
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL fun(LL n, LL m){
    if((m / 2) < n) return  m / 2;
    LL ans = n;m=m-n*2;
    ans = ans + m / 4;
    return ans;
}
int main(){
    LL n, m;
    scanf("%lld%lld", &n, &m);
    LL ans = fun(n, m);
    printf("%lld\n", ans); return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
long long h,n,arr[1001],brr[1001];
long long dp[20001];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>h>>n;
    for (int i=0;i<n;i++){
        cin>>arr[i]>>brr[i];
    }
    for (int i=1;i<20001;i++){
        dp[i]=1e9;
    }
    long long ans=1e9;
    for (int i=0;i<n;i++){
        for (int j=arr[i];j<20001;j++){
            dp[j]=min(dp[j],dp[j-arr[i]]+brr[i]);
            if (j>=h) ans=min(ans,dp[j]);
        }
    }
    cout<<ans;
}

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

#define int long long
#define MAX_N (200005)
#define debug(x) cout << #x <<":"<< x << endl;
#define debugArray(x) for(auto p:(x)) cerr << p <<" "; cerr << endl;
#define debugIdx(i, x) cerr << #i <<" : "<< i <<" "<< #x <<" : "<< x << endl;
const int MOD = (int)1e9+7;

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

    bool f1=true;
    string t1, t0;
    for(int i=0; i<S.length(); i++){
        if(f1){
            t1.push_back('1');
            t0.push_back('0');
            f1=false;
        } else {
            t1.push_back('0');
            t0.push_back('1');
            f1=true;
        }
    }

    int cnt1=0, cnt2=0;
    for(int i=0; i<S.length(); i++){
        if(S[i]!=t1[i]) cnt1++;
        if(S[i]!=t0[i]) cnt2++;
    }

    cout << min(cnt1, cnt2) << endl;

}

Measured memory_bytes: 768
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <set>
#include <cmath>
#include <algorithm>
#include <numeric>
using namespace std;

int stoi(char c){
	return c-'0';
}

char itos(int a){
	return a+'0';
}

int main(){
	int n;
	string s1,s2,ans;
	int lmin , lmax , sum , tmp , tmp2;
	cin >> n;
	for(int i=0; i<n ; ++i){
		bool bs1=true;
		cin >> s1 >> s2;
		reverse(s1.begin(),s1.end());
		reverse(s2.begin(),s2.end());
		lmin=min(s1.length(),s2.length());
		lmax=max(s1.length(),s2.length());
		if(s1.length()<s2.length()) bs1=false;
		for(int j=0;j<lmin;++j){
			ans.resize(j+2 , '0');
			sum=stoi(s1[j])+stoi(s2[j]);
			if(sum>=10){
				ans[j+1]=itos(1);
				tmp=stoi(ans[j]);
				tmp+=sum%10;
				ans[j]=itos(tmp);
			} else {
				int tmp=stoi(ans[j]);
				tmp+=sum;
				if(tmp>=10){
					ans[j+1]=itos(1);
					tmp2=stoi(ans[j]);
					tmp2=tmp%10;
					ans[j]=itos(tmp2);
				} else {
					ans[j]=itos(tmp);
				}
			}
			
		}
		for(int k=lmin; k<lmax ; ++k){
			ans.resize(k+2, '0');
			if(bs1){
				sum=stoi(ans[k])+stoi(s1[k]);
				if(sum>=10){
				ans[k+1]=itos(1); 
				tmp=sum%10;
				ans[k]=itos(tmp);
				} else {
					ans[k]=itos(sum);
				}
			} else {
				sum=stoi(s2[k]);
				sum+=stoi(ans[k]);
				if(sum>=10){
				ans[k+1]=itos(1);
				tmp=sum%10;
				ans[k]=itos(tmp);
				} else {
				ans[k]=itos(sum);
				}
			}
		}
		reverse(ans.begin(),ans.end());
		if(ans[0]=='0') ans.erase(0,1);
		if(ans.length()>80 || s1.length()>80 || s2.length()>80) {cout << "overflow" << endl; ans.clear();}
		else {
			cout << ans << endl;
			ans.clear();
		}
	}
	return 0; 
}

Measured memory_bytes: 1224
package main

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

const N = 200005

var in = NewScanner(os.Stdin, 0)
var f, g [N]int

/* this is port of top c++ answer to test go performance */
func main() {
	n, d := in.Int(), in.Int()
	a := in.Array1Int(n)
	ans := 0
	for i := 1; i <= n; i++ {
		ans += a[i]
	}
	ans += d * (n - 1)
	f[1] = a[1]
	for i := 2; i <= n; i++ {
		Eln(i, n)
		f[i] = Min2(a[i], f[i-1]+d)
	}
	g[n] = a[n]
	for i := n - 1; i >= 1; i-- {
		g[i] = Min2(a[i], g[i+1]+d)
	}
	for i := 2; i <= n-1; i++ {
		ans += Min2(f[i], g[i])
	}
	Pln(ans)
}

const M7 = 1000000007

type Scanner struct {
	*bufio.Scanner
}

func NewScanner(r io.Reader, max int) *Scanner {
	s := bufio.NewScanner(r)
	s.Split(scanWords)
	if max <= 0 {
		max = 1048576
	}
	s.Buffer([]byte{}, max)
	return &Scanner{s}
}
func (s *Scanner) Int() int {
	s.Scan()
	i, e := strconv.ParseInt(s.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return int(i)
}
func (s *Scanner) Array1Int(n int) []int {
	r := make([]int, n+1)
	for i := 1; i <= n; i++ {
		r[i] = s.Int()
	}
	return r
}
func isSpace(b byte) bool {
	return b == ' ' || b == '\n' || b == '\r' || b == '\t'
}
func scanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	start := 0
	for start < len(data) && isSpace(data[start]) {
		start++
	}
	for i := start; i < len(data); i++ {
		if isSpace(data[i]) {
			return i + 1, data[start:i], nil
		}
	}
	if atEOF && len(data) > start {
		return len(data), data[start:], nil
	}
	return start, nil, nil
}
func Min2(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func Eln(s ...interface{}) {
	fmt.Fprintln(os.Stderr, s...)
}
func Pln(s ...interface{}) {
	fmt.Println(s...)
}

type ByteSlice []byte
type IntSlice []byte


Measured memory_bytes: 9216
n, m = map(int, input().split())
mod = 10**9+7
if abs(n-m)>1:
    print(0)
else:
    ans = 1
    for i in range(2, max(n, m)):
        ans *= i
        ans %= mod
    ans = pow(ans, 2, mod)
    ans *= 2*max(n, m)**2 if n==m else max(n, m)
    print(ans%mod)

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <string>
#include <typeinfo>
#include <climits>
#include <algorithm>
#include <cctype>
#include <stdio.h>
#include <cstdlib>
using namespace std;

int main(){
    char a[4];
    cin >> a;
    cout << count(a,a+4,'1');
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#define NIL -1
#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;
int root;
int *p = new int[4000000];    //    p---|  Unit
int *left2 = new  int[4000000]; // left2 --|--------> T
int *right2 = new int[4000000];//right2---|
int *key = new int[4000000];  // key----|

void Init(){
  rep(i,4000000){
    p[i]=left2[i]=right2[i]=key[i]=NIL;
  }
}


int FindRoot(){
  rep(i,n){
    if(p[i] == NIL){
      return i;
    }
  }
}



void TREE_INSERT(int z){
  int y = NIL;  
  int x = root;

  while(x != NIL){
    y = x;
    if(key[z] < key[x]){
      x = left2[x];
    }
    else x = right2[x];
  }
  p[z]=y;
  if(y == NIL){
    root = z;
  }
  else if(key[z] < key[y]){
    left2[y] = z;
  }else{
    right2[y] = z;
  }

}

void InorderTreeWalk(int x){
  if(x != NIL){
    InorderTreeWalk(left2[x]);
    printf(" %d",key[x]);
    InorderTreeWalk(right2[x]);
  }
}

void PreorderTreeWalk(int x){
  if(x != NIL){
    printf(" %d",key[x]);
    PreorderTreeWalk(left2[x]);
    PreorderTreeWalk(right2[x]);
  }
}


int main(){
  int val;
  string op;
  int zr;                     


  scanf("%d",&n);
  Init();  
  root = -1;
  zr=0;
  while(n-- > 0){
    cin >> op;
    if(op == "insert"){
      scanf("%d",&val);
      key[zr]=val;         
      TREE_INSERT(zr);
      zr++;
    }else if(op == "print"){
      InorderTreeWalk(root);
      printf("\n");
      PreorderTreeWalk(root);
      printf("\n");
    }
  }

  delete [] p;
  delete [] left2;
  delete [] right2;
  delete [] key;

  return 0;
}

Measured memory_bytes: 61000
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
#define F first
#define S second
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
using priority_queue_small = priority_queue<int, vector<int>, greater<int> >;
template<class T>using vv = vector<T>;
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; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
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; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};

int n, m, k;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n >> m >> k;
    rep(i, 0, n+1) {
      rep(j, 0, m+1) {
        if (i * (m-j) + (n-i) * j == k) {
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
    cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC127A
{
	class Program
	{
		static void Main(string[] args)
		{
			string[] n = Console.ReadLine().Split(' ');
			int a = int.Parse(n[0]);
			int b = int.Parse(n[1]);

			if (a <= 5)
				Console.WriteLine(0);

			else if (a >= 13)
				Console.WriteLine(b);

			else
				Console.WriteLine(b / 2);

			Console.ReadKey();
		}
	}
}


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

int dp[100];

//最大公約数
int gcd(int x, int y){
  if(x % y == 0) return 1;
  return gcd(y, x % y);
}

//最小公倍数
int lcm(int x, int y){
  return x * y / gcd(x, y);
}

//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}

//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}



int main(){
  string s;
  ll k;
  cin >> s >> k;
  rep(i, min(k, (ll)s.size())){
    if(s[i] != '1'){
      cout << s[i] << endl;
      return 0;
    }
  }
  cout << 1 << endl;
}


Measured memory_bytes: 256
using System;
using System.Text;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] vlist = Console.ReadLine().Split(' ');
            string[] clist = Console.ReadLine().Split(' ');

            int[] vclist = new int[n];

            for (int i = 0; i < n; i++)
            {
                vclist[i] = int.Parse(vlist[i]) - int.Parse(clist[i]);
            }
            
            Array.Sort(vclist);
            Array.Reverse(vclist);

            int count = 0;
            for (int i = 0; i < n; i++)
            {
                if (vclist[i] <= 0)
                {
                    break;
                }
                else
                {
                    count += vclist[i];
                }
            }
            Console.WriteLine(count);

            return;
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <queue>
#include <vector>
#define ll long long
const int N=1e6+10;
using namespace std;
int ifprime(int n){
    int flag=1;
    for(int i=2;i<=sqrt(n);i++){
        if(n%i==0)
            flag=0;
    }
    if(flag==1)  return true;
    else  return false;
}
int n;
int main() {
     cin>>n;
     for(int i=n;i>0;i++){
         if(ifprime(i)){
             cout<<i<<endl;
             return 0;
         }
     }
    return 0;
}

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

string ll = "qwertasdfgzxcvb";

bool is_ll(char c){
  for(int i=0;i<ll.size();i++){
    if(ll[i]==c)return true;
  }
  return false;
}

int solve(string s){
  bool j = is_ll(s[0]);
  int ans = 0;
  for(int i=1;i<s.size();i++){
    bool jj = is_ll(s[i]);
    if(j!=jj){
      j = jj;
      ans ++;
    }
  }
  return ans;
}

int main(){
  string s;
  while(cin>>s,s!="#"){
    cout<<solve(s)<<endl;
  }
}

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

#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ll long long
#define tp top()
#define fr front()
#define pii pair<int,int>
#define pip pair<int,pii>
#define ppi pair<pii,int>
#define ppp pair<pii,pii>
#define sz size()
using namespace std;

int main()
{

	int n,m;
	scanf("%d %d",&n,&m);
	if (n >= 10 || m >= 10)
		printf("-1\n");
	else 
		printf("%d\n",n*m);
	

	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define until(x) while(!(x))
#define unless(x) if(!(x))
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pc __builtin_popcount

int ar[5][5];
set<int> b;
int n;

int32_t main(){
	int t;
	for(int i=1;i<=3;i++){
		for(int j=1;j<=3;j++){
			cin>>ar[i][j];
		}
	}
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>t;
		b.insert(t);
	}
	for(int i=1;i<=3;i++){
		if(b.count(ar[i][1]) && b.count(ar[i][2]) && b.count(ar[i][3])){
			cout<<"Yes\n";
			return 0;
		}
		if(b.count(ar[1][i]) && b.count(ar[2][i]) && b.count(ar[3][i])){
			cout<<"Yes\n";
			return 0;
		}
	}
	if(b.count(ar[1][1]) && b.count(ar[2][2]) && b.count(ar[3][3])){
		cout<<"Yes\n";
		return 0;
	}
	if(b.count(ar[1][3]) && b.count(ar[2][2]) && b.count(ar[3][1])){
		cout<<"Yes\n";
		return 0;
	}
	cout<<"No\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define MODB 998244353
#define INF 9223372036854775807
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}
signed main()
{
  int x=0,y=0,z=0,w=0,n=0,m=0;
string s;
std::cin >> s;
rep(i,s.size()){
  if(i!=3){
    std::cout << s[i];
  }else{
    std::cout << s[i]<<' ';
  }
}
std::cout << '\n';
}


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

int main() {
    string S;
    cin >> S;
    int N = S.size();
    long long res = 0;
    for (int bit = 0; bit < (1<<(N-1)); ++bit) {
        long long tmp = 0;
        for (int i = 0; i < N-1; ++i) {
            tmp *= 10;
            //cout << "tmp *= 10 " << tmp << '\n';
            tmp += S[i] - '0';
            //cout << "tmp += S[i] - '0' " << tmp << '\n';
            if (bit & (1<<i)) res += tmp, tmp = 0;
        }
        tmp *= 10;
        tmp += S.back() - '0';
        res += tmp;
    }
    cout << res << endl;
}

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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str = br.readLine().split(" ");
        int n = Integer.parseInt(str[0]);
        long k = Long.parseLong(str[1]);
        str = br.readLine().split(" ");

        int[] arr = new int[n+1];
        for(int i=1; i<=n; ++i)
            arr[i] = Integer.parseInt(str[i-1]);

        int[] next = new int[n+1];
        Arrays.fill(next, -1);

        int i = 1;
        List<Integer> steps = new ArrayList<>();
        while(next[i] == -1){
            next[i] = arr[i];
            i = next[i];
            steps.add(i);
        }
        if(k <= steps.size()){
            System.out.println(steps.get((int)k-1));
            return;
        }
        int start = i;
        i = arr[i];
        int len = 1;
        while(i != start){
            len++;
            i = arr[i];
        }
        int stepsTakenBeforeCycle = steps.size() - len;
        k -= stepsTakenBeforeCycle;
        k %= len;
        i = start;
        while(k-- != 0){
            i = arr[i];
        }
        System.out.println(i);
    }
}


Measured memory_bytes: 60764
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import itertools
import math
import sys

INF = float('inf')


def solve(K: int, S: str):
    return S[:K] + ['...', ''][len(S) <= K]


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    print(solve(K, S))


if __name__ == '__main__':
    main()


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

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) h[i] = sc.nextInt();
        int cnt = 0;
        for (;!end(h); cnt++) {
            int l = 0, r = n;
            for (int j = 0; j < n; j++) if (h[j] > 0) {
                l = j;
                break;
            }
            for (int j = l + 1; j < n; j++) if (h[j] == 0) {
                r = j;
                break;
            }
            for (int j = l; j < r; j++) h[j]--;
//            debug(h);
        }

        System.out.println(cnt);
    }

    boolean end(int[] h) {
        return Arrays.stream(h).sum() == 0;
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }


    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 28748
#include <iostream>
#include <stdio.h>

using namespace std;

int main(){
    int n , x ,y;
    cin >> n ;
    cin >> x ;
    cin >> y ;
    int k[n-1] ;

    for(int i =0 ; i < n-1; i++){
        k[i] = 0;
    } 

    for(int i = 0 ; i<n ; i++){
        for(int j = i+1; j < n ; j++){
            int cost = min(j-i , ( abs(x-1-i) + 1 + abs(y-1-j) ) );
            // printf("(i,j) : (%d,%d)  %d\n",i,j,cost);
            // cout << x << endl;
            k[cost-1] ++;
        }
    }

    for(int i = 0 ; i< n-1 ;i++){
        cout << k[i] << endl;
    }

}

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

int main()
{
    int a, b;
    cin >> a >> b;
    if(a % 3 == 0 || b % 3 == 0 || (a+b) % 3 == 0){
        cout << "Possible" << endl;
    }
    else{
        cout << "Impossible" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n, res;
multiset<int>Set;
int main() {
	int i, a;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &a);
		Set.insert(a);
	}
	while (!Set.empty()) {
		auto it = Set.end();
		it--;
		int x = *it;
		Set.erase(it);
		for (i = 1; i <= x; i *= 2);
		if (Set.find(i-x) != Set.end()) {
			Set.erase(Set.find(i - x));
			res++;
		}
	}
	printf("%d\n", res);
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define mp make_pair
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;

bool check(int a[],int n,int x){
    for(int i=0;i<n;i++){
        if(a[i]<x) return false;
    }
    return true;
}

int32_t main(){
    IOS;
    int n,m,k;
    cin>>n>>m>>k;
    int a[n][m];
    int cost[n];
    int sum[m]={0};
    for(int i=0;i<n;i++){
        cin>>cost[i];
        for(int j=0;j<m;j++){cin>>a[i][j];sum[j]+=a[i][j];}
    }
    for(int i=0;i<m;i++){
        if(sum[i]<k){cout<<-1;return 0;}
    }
    int ans=M;
    for(int i=1;i<(1<<n);i++){
        int res=0;
        int s[m]={0};
        for(int j=0;j<n;j++){
            if(i&(1<<j)){
                for(int k=0;k<m;k++){
                    s[k]+=a[j][k];
                }
                res+=cost[j];
            }
        }
        if(check(s,m,k)){
            ans=min(res,ans);
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3628
import sys
sys.setrecursionlimit(10 ** 7)


def resolve():
    def dfs1(r_topo, par):
        for i in reversed(r_topo):
            stack = [i]
            while stack:
                idx = stack.pop()
                for to in G[idx]:
                    if to == par[i]:
                        continue
                    dist[idx] = max(dist[idx], dist[to] + 1)


    def dfs2(idx, d_par, par):
        stack = [(idx,d_par, par)]
        while stack:
            idx, d_par, par = stack.pop()
            d_child = []
            d_child.append((0, -1))
            for to in G[idx]:
                if to == par:
                    d_child.append((d_par + 1, to))
                else:
                    d_child.append((dist[to] + 1, to))
            d_child.sort(reverse=True)
            ans[idx] = d_child[0][0]
            for to in G[idx]:
                if to == par:
                    continue
                nx_d_par = d_child[d_child[0][1] == to][0]
                stack.append((to, nx_d_par, idx))
                #dfs2(to, nx_d_par, idx)

    N = int(input())
    if N == 1:
        return print(0)

    G = [[] for _ in range(N)]
    for i in range(N - 1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        G[a].append(b)
        G[b].append(a)

    topo = []
    P = [-1] * N
    node = [0]
    while node:
        s = node.pop()
        topo.append(s)
        for to in G[s]:
            if to == P[s]:
                continue
            P[to] = s
            node.append(to)

    dist = [0]*N
    ans = [0] * N
    dfs1(topo,P)
    dfs2(0, 0, -1)
    for i in range(N):
        print((N - 1) * 2 - ans[i])


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 37916
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

double f(int a, int b){ return sqrt(a*a + b*b) / 2.0; }

int main(){
  int x,y,z;
  while(cin>>x>>y>>z, x+y+z){
    double m = 1e10;
    m = min(m, f(x,y));
    m = min(m, f(y,z));
    m = min(m, f(x,z));
    //printf("m = %f\n",m);
    int n; cin>>n;
    while(n --> 0){
      double r; cin >> r;
      puts(r > m ? "OK" : "NA");
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <stdlib.h>
#include <string.h>

using namespace std;

int cmp( const void *p, const void *q ) {
    return *(int*)p - *(int*)q;
}

int main()
{
    int n,k;
    int flag = 0;
    cin >> n >> k;
    int total = 0;
    int a[n];
    int list[n+1] = {0};
    for (int i=0;i<n;i++) {
        cin >> a[i];
        list[a[i]]++;
    }
    for (int i=0;i<=n;i++) {
        if (list[i] == 0) {
            for (int j=i+1;j<=n;j++) {
                if (list[j] > 0) {
                    list[i] = list[j];
                    list[j] = 0;
                    break;
                }
                if (j == n) {
                    flag = i;
                }
            }
        }
        if (flag != 0) {
            break;
        }
    }
    qsort(list, flag, sizeof(int), cmp);
    int len;
    for (len=0;list[len] != 0;len++);
    if (len > k) {
        for (int i=len-k;i>0;i--) {
            total += list[i-1];
        }
    }
    cout << total << endl;
    return 0;
}


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

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

Measured memory_bytes: 3712
<?php
define('MOD', 998244353);
list($n) = ints();
$d = ints();
if ($d[0] !== 0) exit('0');
for ($i = 0; $i < $n; ++$i) {
    if (isset($cnt[$d[$i]])) ++$cnt[$d[$i]];
    else $cnt[$d[$i]] = 1;
}
if ($cnt[0] !== 1) exit('0');
$ans = 1;
for ($i = 1; $i < count($cnt); ++$i) {
    if (!isset($cnt[$i])) exit('0');
    $ans = modMul($ans, modPow($cnt[$i - 1], $cnt[$i]));
}
echo $ans;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}
// 足し算
function modAdd($x, $y)
{
    return ($x + $y) % MOD;
}

// 引き算
function modSub($x, $y)
{
    return ($x + MOD - $y) % MOD;
}

// 掛け算
function modMul($x, $y)
{
    return ($x * $y) % MOD;
}

// 割り算
function modDiv($x, $y)
{
    return modMul($x, modPow($y, MOD - 2));
}

// 累乗（繰り返し二乗法）
function modPow($n, $x)
{
    if ($x === 0) return 1;
    $res = (modPow($n, $x >> 1) ** 2) % MOD;
    if ($x % 2 === 1) $res = modMul($res, $n);
    return $res;
}

// 階乗
function modFac($n)
{
    if ($n === 0) return 1;
    return modMul($n, modFac($n - 1));
}

// 順列
function nPr($n, $r)
{
    if ($r === 0) return 1;
    return modMul(nPr($n, $r - 1), $n - $r + 1);
}

// 組み合わせ
function nCr($n, $r)
{
    $r = min($r, $n - $r);
    if ($r === 0) return 1;
    return modDiv(nPr($n, $r), modFac($r));
}

// 階乗、逆元を前処理
function init($n)
{
    global $fact, $ifact;
    $fact[0] = 1;
    for ($i = 1; $i <= $n; ++$i) $fact[$i] = modMul($fact[$i - 1], $i);
    $ifact[$n] = modDiv(1, $fact[$n]);
    for ($i = $n; $i >= 1; --$i)
        $ifact[$i - 1] = modMul($ifact[$i], $i);
}

// 順列（前処理）
function nPr2($n, $r)
{
    global $fact, $ifact;
    return modMul($fact[$n], $ifact[$n - $r]);
}

// 組み合わせ（前処理）
function nCr2($n, $r)
{
    global $fact, $ifact;
    return modMul(modMul($fact[$n], $ifact[$r]), $ifact[$n - $r]);
}


Measured memory_bytes: 28316
n=gets.to_i
XS=n.times.map { gets.to_i }

def isprime(x)
  if x==2
    return true
  end
  if x<2 || x%2==0
    return false
  end
  i=3
  while i <= Math.sqrt(x) do
    if x%i==0
      return false
    end
    i+=2
  end
  return true
end

cnt=0
XS.each do |x|
  cnt+=1 if isprime(x)
end

p cnt



Measured memory_bytes: 6952
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod(ll n){return n%=MOD1;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{ ll aa , bb;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->aa - ((fr*)q)->aa;}
int cmp2( const void *p, const void *q ) { return ((fr*)q) ->aa - ((fr*)p)->aa;}
void strsortup(fr*a,int n){qsort(a,n,sizeof(fr),cmp1);}
void strsortdown(fr*a,int n){qsort(a,n,sizeof(fr),cmp2);}


int main(void){
    // char ;
    ll n,h,ans=0;
    scanf("%lld%lld",&n,&h);
    fr dam[2*n];
    rep(i,0,n){
        scanf("%lld%lld",&dam[i*2].aa,&dam[i*2+1].aa);
        dam[i*2+1].bb=1;
        dam[i*2].bb=0;
    }
    // qsort(dam,2*n,sizeof(fr),cmp1);
    strsortdown(dam,2*n);
    rep(i,0,2*n){
        if(dam[i].bb){
            h-=dam[i].aa;
            ans++;
            if(h<=0) break;
        }else{
            ans+=h/dam[i].aa;
            h-=dam[i].aa*(h/dam[i].aa);
            while(h>0){
                h-=dam[i].aa;
                ans++;
            }
            break;
        }
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 6396
N, K = map(lambda x:int(x), input().split())
s = input()

S = []
score = 0
for i in range(len(s)-1):
  if i == 0:
    _s = s[i]
  else:
    _s += s[i]
  if s[i] != s[i+1]:
    S.append(_s)
    _s = ''
  else:
    score += 1

ans = min(score+2*K, N-1)

print(ans)

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

int main(void) {
    string n;
    cin >> n;
    if(n == "A"){
        cout << "T" << endl;
    }else if(n == "C"){
        cout << "G" << endl;
    }else if(n == "T"){
        cout << "A" << endl;
    }else if(n == "G"){
        cout << "C" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
dict = {1:"a", 2:"b", 3:"c", 4:"d", 5:"e", 6:"f", 7:"g", 8:"h", 9:"i", 10:"j"}
ans = [["a", 1]]
for i in range(n-1):
    newans = []
    for lis in ans:
        now = lis[0]
        count = lis[1]
        for j in range(1, count + 2):
            newans.append([now + dict[j], max(j, count)])
    ans = newans
for lis in ans:
    print(lis[0])

Measured memory_bytes: 29500
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        int H = ni();
        int W = ni();
        int[][] grid = new int[H][W];
        int numw = 0;
        for (int i = 0; i < H; i++) {
            String s = ns();
            for (int j = 0; j < W; j++) {
                if(s.charAt(j) == '.') {
                    grid[i][j] = Integer.MAX_VALUE;
                    numw++;
                }
                else grid[i][j] = -1;
            }
        }
        ArrayDeque<Integer> que = new ArrayDeque<>();
        que.add(0);
        que.add(0);
        grid[0][0] = 0;
        while(que.size()>0){
            int i = que.poll();
            int j = que.poll();
            if(i+1<H && grid[i+1][j]>grid[i][j]+1){
                grid[i+1][j] = grid[i][j] +1;
                que.addLast(i+1);
                que.addLast(j);
            }
            if(j+1<W && grid[i][j+1]>grid[i][j]+1){
                grid[i][j+1] = grid[i][j] +1;
                que.addLast(i);
                que.addLast(j+1);
            }
            if(i-1>=0 && grid[i-1][j]>grid[i][j]+1){
                grid[i-1][j] = grid[i][j] +1;
                que.addLast(i-1);
                que.addLast(j);
            }
            if(j-1>=0 && grid[i][j-1]>grid[i][j]+1){
                grid[i][j-1] = grid[i][j] +1;
                que.addLast(i);
                que.addLast(j-1);
            }
        }
        if(grid[H-1][W-1] == Integer.MAX_VALUE){
            out.println(-1);
        }else{
            out.println(numw - grid[H-1][W-1]-1);
        }
    }

 
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 32992
using System;
class Program
{
    static void Main(string[] args)
    {
        bool i = false;
        int n, k, q, j;
        int[] m, x = new int[4], y = new int[4], p = new int[] { 10, 50, 100, 500 };

        while (true)
        {
            n = int.Parse(Console.ReadLine());
            if (n==0) { break; }
            if (!i) { i = !i; } else { Console.WriteLine(); }
            k = 0;
            m = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            for (j = 3; j >= 0; j--)
            {
                k += m[j] * p[j];
            }
            q = k - n;
            for (j = 3; j >= 0; j--)
            {
                x[j] = q / p[j];
		q -= x[j] * p[j];
                y[j] = Math.Max(0, m[j] - x[j]);
            }

            for (j = 0; j < 4; j++)
            {
                if (y[j]!=0) { Console.WriteLine("{0} {1}", p[j], y[j]); }
            }
        }
    }
}


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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

ll INF = 1ll << 60;

int main(){
  bool a;
  cin >> a;
  
  if(a)
    cout << 0 << endl;
  else
    cout << 1 << endl;
  
  return 0;
  
}

Measured memory_bytes: 3592
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int n;
	bool first=true;
	while(cin>>n,n){
		if(!first) cout<<endl;
		first=false;
		vector<pair<pii, string>> v(n);
		rep(i,n){
			string s;
			cin>>s;
			int a,b,c;
			cin>>a>>b>>c;
			v[i] = mkp(pii(-a*3-c,i),s);
		}
		sort(ALL(v));
		rep(i,n){
			cout<<v[i].S<<","<<-v[i].F.F<<endl;
		}
	}
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 3100
#include <iostream>

typedef long long ll;

#define FOR(i,a,b) for(ll i = (a);i < (b);++i)
#define REP(i,n) FOR(i,0,n)

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

using namespace std;

int main(void){

    int n,m,k;
    cin >> n >> m >> k;

    int num;
    
    REP(i,n+1){
        REP(j,m+1){
            num = i*(m-j)+(n-i)*j;
            if(num == k){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
vector<int> ret(101);
int main(void){
    cin.tie(NULL);
    ios::sync_with_stdio(false);
    int a,b,k;
    cin>>a>>b>>k;
    int result=0;
    
    for(int i=1;i<=a && i<=b;i++){
        if((a%i==0 && b%i==0)){
            ret.push_back(i);
        }
    }
    result = ret[ret.size()-k];
    

    cout<<result;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int cn; cin>>cn;map<int,pair<int,int>> rbtA;int subt = 0;
    while(cn--){
        int x;int l; cin>>x>>l;
        rbtA[x] = {x-l,x+l};
    }
    int curr1 = 0,curr2 = 0;
    for(auto a: rbtA){
        if(curr1 == 0&&curr2 == 0){curr2 = a.second.second; curr1 = a.second.first;}
        else{
            if(a.second.first < curr2){
                if(a.second.second<curr2){
                    curr1 = a.second.first;
                    curr2 = a.second.second;
                }
                subt+=1;
            }
            else {
                curr1 = a.second.first;
                curr2 = a.second.second;
            }
        }
    }
    cout<<(rbtA.size()-subt);
    return 0;
}


Measured memory_bytes: 6528
#include<stdio.h>
#define it register int
#define ct const int
#define il inline
const int N=100005,B=512;
typedef long long ll;
ll f[B+5][N];
int v[N<<4],w[N<<4],n,Q;
il ll Max(const ll p,const ll q){return p>q?p:q;}
il ll solve(ct x,ct V){
	if(V<=0) return 0;
	if(x<=B) return f[x][V];
	return Max(solve(x>>1,V),V>=w[x]?solve(x>>1,V-w[x])+v[x]:0);
}
int main(){
	scanf("%d",&n);it i,j,fa;
	for(i=1;i<=n;++i) scanf("%d%d",&v[i],&w[i]);
	for(i=1;i<=B;++i){
		fa=i>>1;
		for(j=100000;~j;--j) f[i][j]=f[fa][j];
		for(j=100000;j>=w[i];--j)
			f[i][j]=Max(f[i][j],f[i][j-w[i]]+v[i]);
	}
	scanf("%d",&Q);
	while(Q--) scanf("%d%d",&i,&j),printf("%lld\n",solve(i,j));
	return 0;
}


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

int main() {
  int k;
  cin>>k;
  if(k==1){
    cout<<"1"<<endl;
  }
  else if(k==2){
    cout<<"1"<<endl;
  }
  else if(k==3){
    cout<<"1"<<endl;
  }
  else if(k==4){
    cout<<"2"<<endl;
  }
  else if(k==5){
    cout<<"1"<<endl;
  }
  else if(k==6){
    cout<<"2"<<endl;
  }
  else if(k==7){
    cout<<"1"<<endl;
  }
  else if(k==8){
    cout<<"5"<<endl;
  }
  else if(k==9){
    cout<<"2"<<endl;
  }
  else if(k==10){
    cout<<"2"<<endl;
  }
  else if(k==11){
    cout<<"1"<<endl;
  }
  else if(k==12){
    cout<<"5"<<endl;
  }
  else if(k==13){
    cout<<"1"<<endl;
  }
  else if(k==14){
    cout<<"2"<<endl;
  }
  else if(k==15){
    cout<<"1"<<endl;
  }
  else if(k==16){
    cout<<"14"<<endl;
  }
  else if(k==17){
    cout<<"1"<<endl;
  }
  else if(k==18){
    cout<<"5"<<endl;
  }
  else if(k==19){
    cout<<"1"<<endl;
  }
  else if(k==20){
    cout<<"5"<<endl;
  }
  else if(k==21){
    cout<<"2"<<endl;
  }
  else if(k==22){
    cout<<"2"<<endl;
  }
  else if(k==23){
    cout<<"1"<<endl;
  }
  else if(k==24){
    cout<<"15"<<endl;
  }
  else if(k==25){
    cout<<"2"<<endl;
  }
  else if(k==26){
    cout<<"2"<<endl;
  }
  else if(k==27){
    cout<<"5"<<endl;
  }
  else if(k==28){
    cout<<"4"<<endl;
  }
  else if(k==29){
    cout<<"1"<<endl;
  }
  else if(k==30){
    cout<<"4"<<endl;
  }
  else if(k==31){
    cout<<"1"<<endl;
  }
  else if(k==32){
    cout<<"51"<<endl;
  }
  
}

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

public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] v = new int[n];
		int[] c = new int[n];
		for (int i = 0; i < n; i++)
			v[i] = scan.nextInt();
		for (int i = 0; i < n; i++)
			c[i] = scan.nextInt();

		int ans = 0;
		for (int i = 0; i < n; i++)
			if (v[i] - c[i] > 0)
				ans += v[i] - c[i];
		System.out.println(ans);
	}
    public static void main(String[] args) {
    	new Main().run();
    }
}


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

class Program
{
	static void Main()
	{
		var numbers = Array.ConvertAll(Console.ReadLine().Split(new[] { ' ' }), number => int.Parse(number));
		var count = numbers[0];
		var targetAmount = numbers[1];

		if (targetAmount % 1000 != 0) {
			Console.WriteLine("-1 -1 -1");
			return;
		}

		if (targetAmount > 10000 * count) {
			Console.WriteLine("-1 -1 -1");
			return;
		}

		if (targetAmount == 10000 * count) {
			Console.WriteLine($"{count} 0 0");
			return;
		}

		var anser = string.Empty;

		var max10000 = targetAmount / 10000;
		for (var i = max10000; i >= 0 && !anser.Any(); --i) {
			var rest10000 = targetAmount - 10000 * i;
			if (rest10000 < 5000 * (count - i)) {
				var max5000 = rest10000 / 5000;
				for (var j = max5000; j >= 0 && !anser.Any(); --j) {
					var rest5000 = rest10000 - (5000 * j);
					if ((rest10000 - 5000 * j) / 1000 == count - i - j) {
						anser = $"{i} {j} {count - i - j}";
					}
				}
			} else if (rest10000 == 5000 * (count - i)) {
				anser = $"{i} {count - i} 0";
			} else {
				anser = "-1 -1 -1";
			}
		}

		if (anser.Any()) {
			Console.WriteLine(anser);
		} else {
			Console.WriteLine("-1 -1 -1");
		}
	}
}


Measured memory_bytes: 13268
//hinagata.cpp
//作成日
//更新日
//目的
//手段
/*includes*/
#include <bits/stdc++.h>
/*namespace*/
using namespace std;
using ll= long long;
/*define macro*/
#define REP(i,n) for(ll i=0;i<(n);i++)
#define REPi(i,a,b) for(ll i=(a);i<(b);i++)
#define REPRi(i,a,b) for(ll i=(a);i>(b);i--)
#define ALL(x) (x).begin(),(x).end()

int main(){
    string S,T;
    cin>>S>>T;
    int A,B;
    cin>>A>>B;
    string U;
    cin>>U;
    if(S==U){
        cout<<A-1<<" "<<B<<endl;
    }else if(T==U){
        cout<<A<<" "<<B-1<<endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
using namespace std;


int main() {
	long long int n,t[234567], a[234567], s[200005] = {},two=1,memo=0,taka=0,ao=0,in=12345678123456;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >>a[i];
		
	}
	for (int j = -100; j <=100; j++) {
		memo = 0;
		for (int i = 0; i < n; i++) {
			memo += (a[i] - j)*(a[i] - j);

		}
		if (in > memo) { in = memo; }
	}
	
	cout << in;
}


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

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

#define MAX 100005
#define INF INT_MAX

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

P a[MAX];
map<P, int> memo;

int minMultTime(int s, int e)
{
    if (s >= e) return 0;
    if (memo[P(s,e)]) return memo[P(s,e)];

    int ans = INF;
    rep(i,e-s) {
        int m1 = minMultTime(s,s+i);
        int m2 = minMultTime(s+i+1,e);
        int m3 = a[s].first * a[s+i].second * a[e].second;
        ans = min(ans, m1+m2+m3);
    }
    memo[P(s,e)] = ans;

    return ans;
}

int main(int, char**)
{
    int n;
    cin >> n;

    rep(i,n) {
        cin >> a[i].first;
        cin >> a[i].second;
    }

    cout << minMultTime(0, n-1) << endl;

    return 0;
}



Measured memory_bytes: 3380
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
	double a, s = 0.0;
	while (cin >> a)
	{
		if (cin.eof()) return 0;
		s = a;
		for (int i = 2; i <= 10; i++)
		{
			if (i % 2)	a /= 3.0;
			else		a *= 2.0;
			s += a;
		}
		printf("%.8lf\n", s);
	}
	return 0;
}

Measured memory_bytes: 0