akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
#include<vector>

using namespace std;
struct node{
    int parent=-1;
    int lchild=-1;
    int rchild=-1;
};

vector<int> PreOrder,InOrder,PostOrder;

void getPre(node A[],int root){
    if(root==-1) return;
    PreOrder.push_back(root);
    getPre(A,A[root].lchild);
    getPre(A,A[root].rchild);

}
void getIn(node A[],int root){
    if(root==-1) return;
    getIn(A,A[root].lchild);
    InOrder.push_back(root);
    getIn(A,A[root].rchild);
}
void getPost(node A[],int root){
    if(root==-1) return;
    getPost(A,A[root].lchild);
    getPost(A,A[root].rchild);
    PostOrder.push_back(root);

}
void show(vector<int> B){
    for(int i=0;i<B.size();i++){
        cout<<' '<<B[i];
    }
    cout<<endl;
}
int main(){
    int n,k;
    node A[26];
    cin>>n;
    int root=0;
    for(int i=0;i<n;i++){
        cin>>k;
        cin>>A[k].lchild>>A[k].rchild;
        A[A[k].lchild].parent=k;
        A[A[k].rchild].parent=k;
    }
    for(int i=0;i<n;i++){
        if(A[i].parent==-1) {
            root=i;
            break;
        }
    }

    getPre(A,root);
    getIn(A,root);
    getPost(A,root);

    cout<<"Preorder"<<endl;
    show(PreOrder);
    cout<<"Inorder"<<endl;
    show(InOrder);
    cout<<"Postorder"<<endl;
    show(PostOrder);

    return 0;
}



Measured memory_bytes: 3156
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.function.Consumer;

public class Main {
    private static final Scanner scanner = new Scanner(System.in);
    private static final Consumer<List<String>> consumer = solve();

    public static void main(String[] args) {
        consumer.accept(readInput());
    }

    private static List<String> readInput() {
        final List<String> lineList = new ArrayList<>();
        while (scanner.hasNextLine()) {
            lineList.add(scanner.nextLine());
        }
        return lineList;
    }

    private static Consumer<List<String>> solve() {
        return args -> {
            int N = Integer.valueOf(args.get(0).split(" ")[0]);
            int K = Integer.valueOf(args.get(0).split(" ")[1]);
            System.out.println(K == 1 ? 0 : N - K);
        };
    }

}


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

#define int             long long int
#define ff              first
#define ss              second
#define pb              push_back

#define vi              vector <int>
#define pii             pair <int, int>

#define loop(i,s,e)     for(int i=s;i<e;i++)
#define rloop(i,e,s)    for(int i=e;i>=s;i--)
#define mset(a,f)       memset(a,f,sizeof(a))

#define endl            "\n"
#define sz(x)           ((int) x.size())
#define all(p)          p.begin(), p.end()

#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define Print(a,x,y)    for (int i=x; i<y; i++) cout<< a[i]<< " "; cout << endl



template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 3000005;


void solve()
{
	int k; cin >> k;


	int num = 0, cnt = 0;
	while (cnt < N)
	{
		num = (num * 10 + 7) % k;
		cnt++;
		if (num == 0)
		{
			cout << cnt << endl;
			return;
		}
	}
	cout << -1 << endl;

	return;

}

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE
	freopen("input.txt",  "r",  stdin);
	freopen("output.txt", "w", stdout);
#endif

	int t = 1;
	//cin >> t;
	while (t--) solve();

	return 0;
}

Measured memory_bytes: 3592
#include<iostream>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);
int main() {
    int n; cin >> n;
    ll t[n];
    ll ans = 1;
    for (int i = 0; i < n; ++i) {
        cin >> t[i];
        ans = lcm(ans, t[i]);
    }
    cout << ans << endl;
}
ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}


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

public class Main{
	
	//最大公約数・最小公倍数（セットで使う）
	public static long gcm(long a, long b) {
		long result = a;
		long k = 0;
		long n = b;
		do {
			k = result % n;
			result = n;
			n = k;
		} while(k != 0);
		return result;
	}
	
	public static long lcm(long a, long b) {
		long g;
		g = gcm(a, b);
		return a/g*b;
	}
	
	static long gcd (long a, long b) {
		long temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return b;
	}



	//素数判定
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2) if(n%i==0){return false;}
		return true;
	}


	//倍数判定（10進数以外のときに有用）
	static boolean isMultiple (String s, int base, int m) {
		int temp = 0;
		for (int i=0; i<s.length(); i++) {
			temp = (temp*base+Character.getNumericValue(s.charAt(i)))%m;
		}
		if (temp==0) {return true;}
		return false;
	}


	//階乗
	static long factorial (int i) {
		if (i==1) {return 1;}
		else {return i*factorial(i-1);}
	}


	//進数変換
	static String toNbase (String sm, int m, int n) {
		return Long.toString(Long.parseLong(sm,m),n);
	}
	
	public static final long gcd_n(long[] param) {
	    final int len = param.length;
	    long g = gcd(param[0], param[1]);    //gcd(a, b) は以前作ったもの
	    for (int i = 1; i < len - 1; i++) {
	        g = gcd(g, param[i + 1]);       //gcd(a, b) は以前作ったもの
	    }
	    return g;
	}
	
	public static long lcm_n(long[] numbers) {
		long l;
		l = numbers[0];
		for (int i = 1; i < numbers.length; i++) {
			l = lcm(l, numbers[i]);
		}
		return l;
	}
	
	
 public static void main(String[] args) {
	 Scanner sc=new Scanner(System.in);
	 int A=sc.nextInt();//500
	 int B=sc.nextInt();//100
	 int C=sc.nextInt();//50
	 int X=sc.nextInt();
	 int count=0;
	 for(int i=0;i<=A;i++) {
		 for(int j=0;j<=B;j++) {
			 for(int k=0;k<=C;k++) {
				 int res=500*i+100*j+50*k;
				 if(res==X) {
					 count++;
				 }
				
				 
			 }
             
			 
		 }
		 
	 }
	 System.out.println(count);
	 
	 
	 
 }
	


}



Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mkp make_pair
#define f(i,l,h) for(ll i=l;i<h;i++)
#define fr(i,h,l) for(ll i=h;i>=l;i--)

using namespace std;

typedef pair<ll,ll> pll;
const ll INF=(ll)(1e9+7);
typedef vector<ll> vll;

int main()
{
    string s;
    cin>>s;
    if(s.compare("ABC")==0){
        cout<<"ARC"<<endl;
    }else{
        cout<<"ABC"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3596
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-5;
const int inf=1e8;
bool f(int a){
	string s=to_string(a);
	bool h=true;
	rep(i,s.size()-1)if(s[i]+1!=s[i+1])h=false;
	return h;
}
int main(){
	int n;
	cin>>n;
	vi in(n);
	rep(i,n)cin>>in[i];
	int out=-1;
	rep(i,n)loop(j,i+1,n){
		int t=in[i]*in[j];
		if(f(t))out=max(out,t);
	}
	cout<<out<<endl;
}

Measured memory_bytes: 3184
#!/usr/bin/env python3
import sys
import numpy as np

MOD = 1000000007  # type: int

def solve(N: int, A: "List[int]"):
    mLEN = len(format(max(A),'b'))

    A = np.array(A)
    ans = 0
    d = 1
    while d < (1 << mLEN):
        cnt = np.count_nonzero(A & d)
        ans += (N - cnt) * cnt * d
        ans %= MOD
        d <<= 1
    print(ans)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 59128
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
#include <memory>
using namespace std;
typedef long long LL;

int main() {
    int n, a;
    cin >> n >> a;
    cout << (n*n) - a << endl;

    return 0;
}


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

int main()
{
    int n, y;
    cin >> n >> y;
    int a, b, c;
    a = y / 10000;
    b = (y % 10000) / 5000;
    c = (y % 5000) / 1000;
    int count = a + b + c;
    int ato = n - count;

    //cout<<a+b+c<<endl;
    if (ato == 0)
    {
        cout << a << " " << b << " " << c << endl;
    }
    else if (ato < 0)
    {
       // cout<<111;
        cout << -1 << " " << -1 << " " << -1 << endl;
    }
    else
    {
        //cout<<123<<endl;
        for (int i = 0; i < a + b + 1000000; i++)
        {
            if (ato >= 4 && b > 0)
            {
                b = b - 1;
                c = c + 5;
                ato = ato - 4;
            }
            if(ato<4||b==0){
               if (0 < ato&& a > 0)
            {
                a = a - 1;
                b = b + 2;
                ato = ato - 1;
            }
            }

            if (ato == 0)
            {
               // cout<<222;
                break;
            }

            if (a <= 0 && b <= 0)
            {
                break;
               // cout<<333;
            }
        }

        if (ato == 0)
        {
            cout << a << " " << b << " " << c << endl;
        }
        if (ato!=0){
            cout<< -1 << " " << -1 << " " << -1 << endl;
           // cout<<ato;
        }
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>


using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<n;++i)
#define FOR(i, a, b) for(int i=a;i<b;++i)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=b-1;i>=a;--i)

#define all(x) begin(x),end(x)
#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

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

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


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> p) {
    os << p.first << ":" << p.second;
    return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

// edit

string f(string s){
    int ret = 0;
    
    for(int i = 1; i < s.size(); ++i){
        string pre = s.substr(0, i);
        string suf = s.substr(i);
        int p = stoi(pre);
        int q = stoi(suf);
        chmax(ret, p * q);
    }
    
    string r = to_string(ret);
    return r;
}

void solve(string N) {
//    string N;
//    cin >> N;
    
    int ans = 0;
    string T = N;
    while(true){
        if(T.size() <= 1){
            break;
        }
        
        ans++;
        T = f(T);
    }
    
    cout << ans << endl;

}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());
    
//    FOR(i, 1, 1000000){
//        string S = to_string(i);
//        cout << i << " ";
//        solve(S);
//    }

    int Q;
    cin >> Q;
    REP(i,Q){
        string N;
        cin >> N;
        solve(N);
    }


    return 0;
}



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

using namespace std;

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

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int k, n;
	cin >> k >> n;
	vector<int> a(n);
	rep (i, n) cin >> a[i];
	int res = a[n - 1] - a[0];
	rep (i, n) {
	  if (i != n - 1) res = min(res, a[i] + k - a[i + 1]);
	  if (i != 0) res = min(res, k - a[i] + a[i - 1]);
	}
	cout << res << endl;
    
    return 0;
}


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

int main() {

  string S;
  cin >> S;
  sort(S.begin(),S.end());
  if(S[0]==S[1] && S[1]!=S[2] && S[2]==S[3]){
      cout << "Yes" << endl;
  }else{
      cout << "No" << endl;
  }
}

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

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

const ll INF = 1LL << 62;
#define atcoder(int)1e9+7
#define Endl endl
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pb push_back

ll gcd(ll a, ll b) {//最大公約数
	if (a%b == 0)return b;
	else gcd(b, a%b);
}

ll lcm(ll a,ll b){//最小公倍数
	return (a / gcd(a, b))*b;
}

int main() {

	int r, g;

	cin >> r >> g;

	cout << g * 2 - r << endl;
	
	return 0;
}

Measured memory_bytes: 256
extern crate core;

use core::cmp::min;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

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

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

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

fn main() {
    input!{
        n: i32,
        data: [i32; n],
    }
    let mut sum = 0;
    let mut left = 0;
    let mut ans = 1000000000;
    for i in &data {
        sum = sum + i;
    }
    for i in &data {
        left = left + i;
        let right = sum - left;
        ans = min(ans, (left - right).abs());
    }
    println!("{}", ans);
}

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

const int MAXN = 300005, mod = 1e9+7;

char str[MAXN];
int n;

int dp[MAXN][3];
int sum[MAXN], power[MAXN];

int main()
{
	scanf("%s", str+1), n = strlen(str+1);
	power[0] = 1;
	for (int i = 1; i <= n; i++) power[i] = power[i-1]*2%mod;
	for (int i = 1; i <= n; i++) sum[i] = sum[i-1]+(str[i]=='?');
	dp[1][2] = dp[1][0] = (str[1] != '0');
	dp[1][1] = 0;
	for (int i = 3; i <= n; i += 2) {
		if (str[i] == '?' && str[i-1] == '?') {
			dp[i][0] = (power[sum[i-2]] + 1ll*dp[i-2][0] + dp[i-2][2] + dp[i-2][1]) % mod;
			dp[i][2] = (power[sum[i-2]] + 3ll*dp[i-2][2]) % mod;
			dp[i][1] = 2ll*(dp[i-2][1] + dp[i-2][0])%mod;
		} else if (str[i] == '?') {
			if (str[i-1] == '1') {
				dp[i][0] = (power[sum[i-2]] + dp[i-2][0]) % mod;
				dp[i][1] = 2*dp[i-2][0] % mod;
				dp[i][2] = (power[sum[i-2]] + dp[i-2][2]) % mod;
			} else {
				dp[i][0] = (dp[i-2][1] + dp[i-2][2]) % mod;
				dp[i][1] = 2*dp[i-2][1] % mod;
				dp[i][2] = 2*dp[i-2][2] % mod;
			}
		} else if (str[i-1] == '?') {
			dp[i][1] = (dp[i-2][0] + dp[i-2][1]) % mod;
			if (str[i] == '1') {
				dp[i][2] = dp[i][0] = (dp[i-2][2] + power[sum[i-2]]) % mod;
			} else {
				dp[i][0] = (dp[i-2][0] + dp[i-2][1]) % mod;
				dp[i][2] = (dp[i-2][2] + dp[i-2][2]) % mod;
			}
		} else if (str[i] == '1' && str[i-1] == '1') {
			dp[i][2] = dp[i][0] = power[sum[i-2]];
			dp[i][1] = dp[i-2][0];
		} else if (str[i] == '0' && str[i-1] == '0') {
			dp[i][0] = dp[i][1] = dp[i-2][1];
			dp[i][2] = dp[i-2][2];
		} else {
			if (str[i] == '1') {
				dp[i][1] = dp[i-2][1];
				dp[i][0] = dp[i][2] = dp[i-2][2];
			} else {
				dp[i][1] = dp[i-2][0];
				dp[i][0] = dp[i-2][0];
				dp[i][2] = dp[i-2][2];
			}
		}
		// cerr << dp[i][0] << " " << dp[i][1]  << " " << dp[i][2] << endl;
	}
	cout << dp[n][0] << endl;
	return 0;
}


Measured memory_bytes: 6400
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  if (a > k) {
    cout << k << endl;
  } else if (a < k) {
    if (a + b >= k) {
      cout << a << endl;
    } else {
      ll s = k - (a + b);
      cout << a - s << endl;
    }
  } else {
    cout << a << endl;
  }
} 


Measured memory_bytes: 3628
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)

signed main(){

	vector<lli> v(3);
	REP(i,0,3)cin>>v[i];
	sort(v.begin(),v.end());

	cout<<v[0]+v[1]<<endl;

	return 0;
}

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

const long long mod = 1000000007;

int main(void) {
  int H, W, K;
  cin >> H >> W >> K;
  if (W == 1) {
    cout << 1 << endl;
    return 0;
  }

  long long amida[101][16];
  memset(amida, 0, sizeof(amida));
  amida[0][0] = 1;
  for (int h = 0; h < H; h++) {
    for (int ptn = 0; ptn < (1 << (W-1)); ptn++) {
      bool check = true;
      for (int i = 0; i < W - 2; i++) {
        if (((ptn >> i) & 1) && ((ptn >> (i+1)) & 1)) check = false;
      }
      if (!check) continue;
      
      int p = (ptn << 1);
      for (int i = 0; i < W; i++) {
        if ((p >> i) & 1) {
          amida[h + 1][i - 1] += amida[h][i];
          amida[h + 1][i - 1] %= mod;
        }
        else if ((p >> (i+1)) & 1) {
          amida[h + 1][i + 1] += amida[h][i];
          amida[h + 1][i + 1] %= mod;
        }
        else if (!((p >> i) & 1) && !((p >> (i+1)) & 1)) {
          amida[h + 1][i] += amida[h][i];
          amida[h + 1][i] %= mod;
        }
      }
    }
  }
  for (int i = 0; i < W; i++) {
    cerr << amida[H][i] << " ";
  }cerr << endl;

  cout << amida[H][K - 1] << endl;
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

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

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 45;
const int mod = 1000000007;

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  vector<int> q(n+1);
  rep(i, n) q[p[i]] = i+1;
  int k = 0;
  int r = 1;
  for(int l = 1; l <= n; ++l) {
    while(r <= n && q[r] <= q[r+1]) ++r;
    chmax(k, r-l+1);
    if(r==l)++r;
  }
  cout << n-k << endl;
}

Measured memory_bytes: 1920
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <random>
#include <complex>
#include <assert.h>

using namespace std;
typedef long long ll;

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

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

int main() {
	int H, W, K; cin >> H >> W >> K;
	int s[10][1000], t[10][1000];
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			char c; cin >> c;
			s[i][j] = c - '0';
		}
	}

	const int INF = 100000000;
	int ans = INF;
	for (int q = 0; q < (1 << (H - 1)); q++) {
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				t[i][j] = 0;
			}
		}
		int a = 0;
		int Y = 0;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				t[Y][j] += s[i][j];
				if (t[Y][j] > K) { a = -1;}
			}
			if (q & (1 << i)) { Y++; }
		}
		if (a == -1) { continue; }
		
		vector<int> b(H, 0);
		a = Y;

		for (int j = 0; j < W; j++) {
			bool f = false;
			for (int i = 0; i <= Y; i++) {
				b[i] += t[i][j];
				if (b[i] > K) { f = true; }
			}
			if (f) {
				a++;
				for (int i = 0; i <= Y; i++) {
					b[i] = t[i][j];
				}
			}
		}
		chmin(ans, a);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 384
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int c[][] = new int[n - 1][3];
        for (int i = 0; i < n - 1; i++) {
            c[i][0] = Integer.parseInt(sc.next());
            c[i][1] = Integer.parseInt(sc.next());
            c[i][2] = Integer.parseInt(sc.next());
        }
        sc.close();
        for (int i = 0; i < n - 1; i++) {
            long a = 0;
            for (int j = i; j < n - 1; j++) {
                if (a <= c[j][1]) {
                    a = c[j][1];
                } else {
                    long b = a - c[j][1];
                    if (b % c[j][2] > 0) {
                        a -= b;
                        a += (b / c[j][2]) * c[j][2];
                        a += c[j][2];
                    }
                }
                a += c[j][0];
            }
            System.out.println(a);
        }
        System.out.println(0);
    }
}

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

int main() {
    string s;
    cin >> s;
    vector<string> t = {"maerd", "remaerd", "esare", "resare"};
    string ans = "YES";

    reverse(s.begin(), s.end());

    int i;
    while(s.size() > 0) {
        int tmp = s.size();
        for(i = 0; i < 4; i++) {
            if (s.substr(0, t[i].size()) == t[i]) {
                s.erase(s.begin(), s.begin() + t[i].size());
            }
        }
        if (tmp == (int)s.size()) {
            ans = "NO";
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
n = int(input())

edge = []
X,Y = map(int,input().split())
x = [X]
y = [Y]

for j in range(n-1):
    a,b = map(int,input().split())
    for ex,ey in zip(x,y):
        edge.append(((a-ex)**2+(b-ey)**2)**0.5)
    x.append(a)
    y.append(b)

me = sum(edge)/len(edge)
print(me*(n-1))

Measured memory_bytes: 38384
#include <iostream>
#include <functional>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <vector>
#include <array>
#include <memory>
#include <set>
#include <map>

using namespace std;

#define Get(ty,...) ty __VA_ARGS__;cins(__VA_ARGS__);
#define GetArray(ty,v,n) vector<ty> v(n);cin_arr(v,n);
#define ci cin
#define co cout
#define en endl;
#define Arr(f, arr,pred) f(arr.begin(),arr.end(),pred)
#define Arr2(f, arr) f(arr.begin(),arr.end())
#define ArrExpr(f, arr,expr) f(arr.begin(),arr.end(),[](auto x){return expr;})
#define Acc(init,arr,pred) accumulate(arr.begin(),arr.end(),init,pred)

void cins(){}

template<class Head,class... Tail>
void cins(Head& head,Tail&... tail) {
	cin >> head;
	cins(tail...);
}

template<class Arr>
void cin_arr(Arr& v,int n) {
	for (int i = 0; i < n; i++)
		cin >> v[i];
}



int main() {
	Get(int, n);
	multimap<int, int> m;
	while (n--!=0)
	{
		Get(int, a, b);
		m.insert(make_pair(b, a));
	}

	int timeTotal = 0;
	for (auto i = m.begin(); i != m.end(); ++i) {
		timeTotal += i->second;
		if (timeTotal > i->first) {
			co << "No" << en;
			return 0;
		}
	}
	co << "Yes" << en;

}




Measured memory_bytes: 9600
#include <iostream>
#include <vector>
#include <stack>
#include <sstream>
#include <ctype.h>
#include <cstdlib>
#include <cstdio>
using namespace std;

int main(){
	long double a,b;
	
	string s,t;
	while(getline(cin,s) && s != ""){
		stringstream ss(s);
		stack<long double> S;
		while(ss >> t){
			if( isdigit(t[0]) || t.size() >= 2){
				S.push(atof(t.c_str()));
			}else{
				switch(t[0]){
				case '+':
					b = S.top();S.pop();
					a = S.top();S.pop();
					S.push(a+b);
					break;
				case '-':
					b = S.top();S.pop();
					a = S.top();S.pop();
					S.push(a-b);
					break;
				case '*':
					b = S.top();S.pop();
					a = S.top();S.pop();
					S.push(a*b);
					break;
				case '/':
					b = S.top();S.pop();
					a = S.top();S.pop();
					if(a==0)continue;
					S.push(a/b);
					break;
				default:
					exit(0);
				}
			}
		}
		printf("%.6Lf\n",S.top());
	}
}

Measured memory_bytes: 0
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム（標準入力変更用）
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define in(x1) cin >> x1
#define in2(x1, x2) cin >> x1 >> x2
#define in3(x1, x2, x3) cin >> x1 >> x2 >> x3
#define inN(x, N) rep(i, N) in(x[i])
#define outl(x) cout << x << endl
#define out2l(x, y) cout << x << " " << y << endl 

//よく使う関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

    //標準入力をファイルに変更
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());

    int N, X, T;
    in3(N, X, T);

    int count = N / X;
    if (N % X != 0) count++;

    outl(T * count);
    return 0;
}

Measured memory_bytes: 3576
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int n;
int a[505][505];
ll s1[505][505], s2[505][505];
ll dp[2][505][505];
int main()
{
    cin>>n;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(i==j) continue;
            cin>>a[i][j];
        }
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++) s1[i][j+1]=s1[i][j]+a[i][j];
        for(int j=0; j<n; j++) s2[i][j+1]=s2[i][j]+a[j][i];
    }
    const ll INF=1e18;
    dp[0][0][1]=0;
    for(int i=1; i<n; i++){
        for(int j=0; j<=i+1; j++) for(int k=1; j+k<=i+1; k++) dp[i&1][j][k]=INF;
        for(int j=0; j<=i; j++){
            for(int k=1; j+k<=i; k++){
                if(dp[(i&1)^1][j][k]==INF) continue;
                dp[i&1][j][k+1]=min(dp[i&1][j][k+1], dp[(i&1)^1][j][k]+s2[i][i]-s2[i][i-k]+s1[i][i-j-k]);
                dp[i&1][k][1]=min(dp[i&1][k][1], dp[(i&1)^1][j][k]+s1[i][i-k]);
                dp[i&1][0][1]=min(dp[i&1][0][1], dp[(i&1)^1][j][k]+s1[i][i]);
            }
        }
    }
    ll ans=INF;
    for(int i=0; i<=n; i++){
        for(int j=1; i+j<=n; j++) ans=min(ans, dp[(n-1)&1][i][j]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 9216
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
using namespace std;

int a[100];
int main(){
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }

    int ans = 0;
    int count = N + 1;
    for(int i = 0; i < N - 1; i++){
        if(a[i] == a[i + 1]){
            ans ++;
            a[i + 1] = count;
            count ++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
s = input()
t = input()
a = []
b = []
for i in s:
    a.append(i)
for j in t:
    b.append(j)


flag = False
for i in range(len(a) + 1):
    if a == b:
        flag = True
        break
    else:
        p =  b[0]
        b.pop(0)
        b.append(p)

if flag:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)

const ll MOD = (ll)1e9 + 7;
const ll HIGHINF = (ll)1e18;

vvll f(100, vll(10, 0));
vvll p(100, vll(11, 0));
ll n;

ll calc(ll o) {
  if (!o) return -HIGHINF;  // 営業時間が0はダメなので
  ll c, ans=0, tmp;
  REP(i, n) {
    c = 0; tmp = o;
    REP(j, 10) {
      if (tmp&1 && f.at(i).at(j)) c++;
      tmp >>= 1;
    }
    ans += p.at(i).at(c);
  }
  return ans;
}

ll dps(ll i, ll o) {
  if (i == 10) return calc(o);  // すべての時間帯について決めたら利益計算
  // 営業する場合((o<<1)+1)としない場合(o<<1)で探索
  else return max(dps(i+1, (o<<1)+1), dps(i+1, o<<1));
}

int main() {
  cin >> n;
  REP(i, n) REP(j, 10) cin >> f.at(i).at(j);
  REP(i, n) REP(j, 11) cin >> p.at(i).at(j);
  ll ans = dps(0, 0);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
// abc129d.cpp : Lamp
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,n) for(int i=0;i<(n);i++)
#define irp(i,n) for(int i=(n);i>=0;i--)

int main(){
	int h,w; cin>>h>>w;

	vector<string> s(h);
	vector<vi> Y(h,vi(w)), X(h,vi(w));

	rp(y,h){
		cin>>s[y];
		rp(x,w){
			if(y>0 && s[y][x]=='.' && s[y-1][x]=='.') Y[y][x] = Y[y-1][x] + 1;
			if(x>0 && s[y][x]=='.' && s[y][x-1]=='.') X[y][x] = X[y][x-1] + 1;
		}
	}

	irp(y,h-1)
		irp(x,w-1){
			if(y<h-1 && s[y][x]=='.' && s[y+1][x]=='.') Y[y][x] = Y[y+1][x];
			if(x<w-1 && s[y][x]=='.' && s[y][x+1]=='.') X[y][x] = X[y][x+1];
		}

	int ans = 1; rp(y,h) rp(x,w) ans = max(ans, X[y][x] + Y[y][x] + 1);
	cout<< ans <<endl;
}


Measured memory_bytes: 35712
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int N;
	cin >> N;
	vector<int> A(3*N);
	for(int i=0;i<3*N;++i){
		cin >> A[i];
	}
	priority_queue<int, vector<int>, greater<int> > que;//小さい順
	LL Lsum=0;
	for(int i=0;i<N;++i){
		Lsum += A[i];
		que.push( A[i] );
	}
	vector<LL> L(N+1),R(N+1);
	L[0] = Lsum;
	for(int i=0;i<N;++i){
		LL temp = que.top();
		if( temp < A[N+i] ){
			Lsum = Lsum-temp + A[N+i];
			que.pop();
			que.push(A[N+i]);
		}
		L[i+1] = Lsum;
	}
	//逆から
	LL Rsum = 0;
	priority_queue<int> que2;
	for(int i=0;i<N;++i){
		Rsum += A[2*N+i];
		que2.push( A[2*N+i] );
	}
	R[N] = Rsum;
	for(int i=N-1;i>=0;--i){
		LL temp = que2.top();
		if( A[N+i] < temp ){
			Rsum = Rsum -temp + A[N+i];
			que2.pop();
			que2.push(A[N+i]);
		}
		R[i] = Rsum;
	}
	LL ans = -LINF;
	for(int i=0;i<=N;++i){
		ans = max(ans,L[i]-R[i]);
	}
	cout << ans << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(3);//小数点以下の桁数を指定//coutとcerrで別	
	
	solve();
}
#pragma endregion //main()


Measured memory_bytes: 4216
///
// File:  cgl_1_a.cpp
// Author: ymiyamoto
//
// Created on Sun Oct 22 19:02:33 2017
//

#include <cstdint>
#include <iomanip>
#include <iostream>

using namespace std;

struct vector_t;

struct point_t {
  double x;
  double y;

  point_t operator+(const point_t a)
  {
    return point_t({x + a.x, y + a.y});
  }

  void print()
  {
    cout << fixed << setprecision(10) << x << " " << y << endl;
  }
};

struct vector_t {
  double x;
  double y;

  vector_t(double a, double b) : x(a), y(b)
  {
  }
  vector_t(point_t a, point_t b) : x(a.x - b.x), y(a.y - b.y)
  {
  }

  double norm2()
  {
    return x * x + y * y;
  }

  double cross(vector_t a)
  {
    return x * a.x + y * a.y;
  }

  vector_t operator*(double a)
  {
    return vector_t(a * x, a * y);
  }

  point_t operator+(point_t p)
  {
    return point_t({x + p.x, y + p.y});
  }
};

int32_t main()
{
  double x, y;
  cin >> x >> y;
  point_t p1 = point_t({x, y});

  cin >> x >> y;
  point_t p2 = point_t({x, y});

  vector_t vec(p1, p2);

  uint32_t q;
  cin >> q;
  for (uint32_t i = 0; i < q; i++) {
    double x, y;
    cin >> x >> y;
    vector_t v(point_t({x, y}), p1);
    (vec * (vec.cross(v) / vec.norm2()) + p1).print();
  }
  return 0;
}

Measured memory_bytes: 3296
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define ld long double
#define endl '\n'
#define TIME 1.0*clock()/CLOCKS_PER_SEC
#define pii pair < int , int >
#define Endl '\n'

#pragma GCC optimize("Ofast")

using namespace std;
using namespace __gnu_pbds;

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

mt19937 gen(chrono::system_clock::now().time_since_epoch().count());

const int mod = 1e9 + 7;
const int FFTM = 998244353;

const int SX[4] = {0 , 1 , -1 , 0};
const int SY[4] = {1 , 0 , 0 , -1};
const int rx[8] = {1, -1, 0, 0, 1, 1, -1, -1};
const int ry[8] = {0, 0, 1, -1, 1, -1, 1, -1};
const int kx[8] = {1, 1, -1, -1, 2, 2, -2, -2};
const int ky[8] = {2, -2, 2, -2, 1, -1, 1, -1};

typedef cc_hash_table< int, int, hash<int>, equal_to<int>, direct_mask_range_hashing<int>, hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>, true>> ht;

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//    freopen("gotham.in", "r", stdin);
//    freopen("gotham.out", "w", stdout);
#endif
    int n;
    cin >> n;
    for (int i = 1;i <= n; ++i){
        int kol = 0;
        for (int j = 1;j <= 10000; ++j){
            if (j * j > i)break;
            for (int x = 1;x <= 10000; ++x){
                if (j * j + x * x + x * j > i)break;

                int l = 1, r = 10000;
                bool ok = 0;
                while(l <= r){
                    int mid = (l + r) >> 1;
                    if (mid * mid + mid * j + mid * x + (j * j + x * x + x * j) <= i){
                        l = mid + 1;
                        if (mid * mid + mid * j + mid * x + (j * j + x * x + x * j) == i){
                            ok = 1;
                            break;
                        }
                    }else{
                        r = mid - 1;
                    }
                }
                if (ok)kol++;
            }
        }
        cout << kol << endl;
    }
    return 0;
}


Measured memory_bytes: 3612
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define fio                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define ld long double
#define endl "\n"
#define ff first
#define ss second
#define pi pair<ll, ll>
#define PI 3.141592653589793238462643383279502884L
#define mp make_pair
#define pb push_back
#define fall(i, a, b) for (int i = a; i < b; i++)
#define sz(x) (ll) x.size()
#define all(x) x.begin(), x.end()
#define ed cout << "ed";
#define time_passed 1.0 * clock() / CLOCKS_PER_SEC
ll MOD = 1e9 + 7;
ll MOD1 = 1e9 + 123;
ll MOD2 = 1e9 + 321;
ll fun(int n)
{
    int c = 0, i = 1;
    for (i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            if (i == n / i)
                c++;
            else
                c += 2;
        }
    }
    return c;
}
int main()
{
    fio;
    ll t, c, p, a, n, q, k, i, l, m, u, f, j, x, y, b, d;
    cin >> n;
    c = 0;

    for (i = 1; n - i >= 1; i++)
    {
        //  cout<<n-i<<endl;

        c += fun(n - i);
    }
    cout << c << endl;
    // cout << time_passed << endl;
    return 0;
}


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

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

    if (a >= b)
        cout << "delicious" << endl;
    else if (b - a <= x)
        cout << "safe" << endl;
    else
        cout << "dangerous" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<iomanip>
#include<iterator>
#include<vector>
#include<map>
#include<utility>
#include<set>
#include<stack>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);


    int s,w;
    cin>>s>>w;
    if (w>=s)cout<<"unsafe\n";
    else cout<<"safe\n";

    return 0;
}


Measured memory_bytes: 3660
import java.util.Scanner;

class Main{
  
   public static void main(String[] args) {
     
     Scanner sc = new Scanner(System.in);
     
     int a = sc.nextInt();
     int b = sc.nextInt();
     int c = sc.nextInt();
     
     System.out.println((a * b) / 2);
     
     sc.close();
   }
}

Measured memory_bytes: 21844
#include <stdio.h>

int main(){
	int n;
	scanf("%d", &n);
	long long int total = 0;
	
	for (int i = 1; i <= n; i++){
		if (i % 3 != 0 && i % 5 != 0){
			total += i;
		}
	}
	printf("%lld", total);
	return 0;
}

Measured memory_bytes: 1728
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(); 
		int A = sc.nextInt(); 
		int B = sc.nextInt();
		String s; int sum; int ans=0;
		
		for(int i=1;i<=N;i++) 
		{
			s 	= String.valueOf(i);
			sum	= 0;
			for(int k=0; k < s.length() ; k++) 
				sum += Integer.parseInt( s.substring(k,k+1) );
			if(A <= sum &&sum <= B)	ans += Integer.parseInt(s);
		}
		System.out.println(ans);
	}
	
		
}


Measured memory_bytes: 24148
#include <stdio.h>

int main(void){
	int i , a[11] = {0} , buf , a_count = 0;
	while(scanf("%d" , &buf)!=EOF){
		if(buf != 0){
			a[a_count] = buf;
			a_count++;
		}else{
			printf("%d\n" , a[a_count-1]);
			a_count--;
		}
	}

	return 0;
}

Measured memory_bytes: 0
import java.util.*;

public class Main {
	
	public static int maxYen(int arr[], int size) {
		int profit = Integer.MIN_VALUE;
		int min = arr[0];
		for(int i = 1; i < size; i++) {
			if(profit < arr[i] - min) profit = arr[i] - min;
			if(min >  arr[i]) min = arr[i];
		}
		return profit;
	}
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int time = in.nextInt();
		int[] arr = new int[time];
		for(int i = 0; i < time; i++) {
			arr[i] = in.nextInt();
		}
		System.out.println(maxYen(arr, time));
	}
}



Measured memory_bytes: 100740
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;

inline char gc()
{
		static const int L = 1000;
		static char sxd[L], *sss = sxd, *ttt = sxd;
		if(sss == ttt)
		{
				ttt = (sss = sxd) + fread(sxd, 1, L, stdin);
				if(sss == ttt)
						return EOF;
		}
		return *sss++;
}

#define dd c = getchar()
inline int read(int& x)
{
		x = 0;
		char dd;
		bool f = false;
		for(; !isdigit(c); dd)
		{
				if(c == EOF)
						return -1;
				if(c == '-')
						f = true;
		}
		for(; isdigit(c); dd)
				x = (x << 1) + (x << 3) + (c ^ 48);
		if(f)
				x = -x;
		return 1;
}
#undef dd

string a,b;
int i,j,n,z,k,t;
int d(int k)
{
	t=0;
	for(int i=k;i<n;i++)
	{
		if(a[i]!=b[t])break;
		t++;
	}
	return t;
}

int main()
{
	read(n);
	cin>>a>>b;
	z=n*2;
	for(i=0;i<n;i++)
	{
		k=d(i);
		z=min(z,n*2-k);
	}
	cout<<z;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define found(m,x) ((m).find(x)!=(m).end())
#define uset unordered_set
#define umap unordered_map
#define db(x) cerr << #x << " == " << x << ";\n";
#define a(x) x.begin(),x.end()
#define input(v,n) for(int i=0;i<n;i++)cin>>v[i]
typedef vector<int> vi;
typedef pair<int,int> pi;

const int nax = 1e5+7;
const int mod = 1e9+7; //1e9+2667
const int inf = numeric_limits<int> :: max();
// ===================== MANASH =================== //

int n,m;

long long power(int a, int b ) {
    if ( b == 0) return 1;
    long long t = power(a,b/2);
    if (b&1) return a*t*t;
    else return t*t;
}


void test() {

    cin >> n;
    cout << power(n,3);
    
}

signed main() {

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

    #ifdef LOCAL
    freopen("input.txt","r",stdin);
    cout<<"Time Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec.\n";
    #endif

    int T = 1;
    //cin >> T;
    while(T--) {
        test();
        cout << "\n";
    }
    return 0;

}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
 int H[3000],W[3000];
 int i,j,k,m,n;

 for(i=0;i<3000;i++){
  scanf("%d %d",&H[i],&W[i]);
  
  if(H[i]==0 && W[i]==0){
   j=i;
   break;
  }
  }

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

  for(k=0;k<H[i];k++){
 
  if(k==0){
   for(m=0;m<W[i]-1;m++){
        printf("#");
       }
       printf("#\n");
  }
   else if(k==H[i]-1){
    for(m=0;m<W[i]-1;m++){
        printf("#");
       }
       printf("#\n");
  } else{
    printf("#");
     for(n=1;n<=W[i]-2;n++){
      printf(".");
     }
     printf("#\n");
  }
 }
 printf("\n");

 }

return 0;
}

  

Measured memory_bytes: 596
n=int(input())
inf=10**15
a=[[0]*n for _ in range(n)]
dist=[[0]*n for _ in range(n)]

for u in range(n):
    for v,c in enumerate(list(map(int,input().split()))):
        a[u][v]=c
        dist[u][v]=c

def calc(n,a,dist):

    for k in range(n):
        for i in range(n):
            for j in range(n):
                if k==i or k==j or i==j or dist[i][k]==inf or dist[k][j]==inf:
                    continue
                
                if dist[i][k]+dist[k][j]==a[i][j]:
                    dist[i][j]=inf
                elif dist[i][k]+dist[k][j]<a[i][j]:
                    return -1
    
    ret=0
    for i in range(n):
        for j in range(n):
            if dist[i][j]==inf:
                continue
            ret+=dist[i][j]
    
    return ret//2


print(calc(n,a,dist))

Measured memory_bytes: 75928
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;
int main() {
    ll n;
    cin >> n;
    vector<ll> p(n);
    for(int i=0;i<n;i++) cin >> p[i];
    ll c = 0;
    bool isSecond=false;
    for(int i=0;i<n;i++) {
        if(i+1 == p[i]) {
            c++;
            if(isSecond) {
                isSecond = false;
                c--;
            } else {
                isSecond = true;
            }
        } else {
            isSecond = false;
        }
    }
    cout << c << endl;

}


Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>
#include <deque>
#include <iomanip>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

//cout << fixed << setprecision(10);

int main() {
    ll N;
    cin >> N;
    vector<ll> B(N);
    for(int i=0;i<N-1;i++) cin >> B[i];

    ll ans=B[0]+B[N-2];
    for(int i=1;i<N-1;i++){
        ans+=min(B[i-1],B[i]);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256