akhauriyash/Code-Regression huggingface dataset:
//
//  main.cpp
//  AC
//
//  Created by makinofuya on 2019/07/08.
//  Copyright © 2019 makinofuya. All rights reserved.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
typedef long long ll;
using namespace std;
#define mod 1000000007
#define rep(i,n) for(int i=1;i<n;i++)
#define out(s) cout << s << endl

int main(){
    string s;cin >> s;
    int cnt=0;
    for(int i=0;i<s.size();i++){
        if(i%2==0){
            if(s[i]!=s[0])cnt++;
        }
        else{
            if(s[i]==s[0])cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
   
}



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

int main()
{
    long long n,k;
    cin>>n>>k;
    if(n%k==0)
    {
        cout<<0;
        return 0;
    }
    if(n<k)
    {
        cout<<min(n,k-n);
        return 0;
    }
    long long q=n/k;
    cout<<min(n-(q*k),((q+1)*k)-n);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INTMAX 2147483647LL
#define PII pair<int,int>
#define MP make_pair
#define fir first
#define sec second
#define pb push_back
#define re register
#define lc c[x][0]
#define rc c[x][1]
using namespace std;
typedef long long ll;
const double Pi=acos(-1.0);
const int Inf=0x3f3f3f3f;
const int MAXN=1e5+10; 
inline int read(){
	re int x=0,f=1,ch=getchar();
	while(!isdigit(ch))f=ch=='-'?-1:1,ch=getchar();
	while(isdigit(ch))x=x*10+ch-48,ch=getchar();
	return x*f;
}
inline ll readll(){
	re ll x=0,f=1,ch=getchar();
	while(!isdigit(ch))f=ch=='-'?-1:1,ch=getchar();
	while(isdigit(ch))x=x*10+ch-48,ch=getchar();
	return x*f;
}

int n,ans;
int a[MAXN],sum[MAXN];
ll tot,BIT[MAXN<<1];

inline int lowbit(int x){return x&(-x);}
inline void Update(int x,int v){for(int i=x;i<=(n<<1)+2;i+=lowbit(i)) BIT[i]+=v;}
inline ll Query(int x){ll res=0;for(int i=x;i;i-=lowbit(i)) res+=BIT[i];return res;}

inline bool Check(int mid){
	memset(BIT,0,sizeof(BIT));
	for(int i=1;i<=n;++i){
		sum[i]=(a[i]>=mid)?1:-1;
		sum[i]+=sum[i-1];
	}
	for(int i=1;i<=n;++i) sum[i]+=n+1;
	
	ll cnt=0;Update(n+1,1);
	for(int i=1;i<=n;++i){
		cnt+=Query(sum[i]);
		Update(sum[i],1);
	}
	return cnt>=tot-tot/2;
}
int main(){
	n=read();tot=1ll*n*(n+1)/2;
	for(int i=1;i<=n;++i) a[i]=read();
	int l=1,r=1e9+10;
	while(l<=r){
		int mid=(l+r)>>1;
		if(Check(mid)){
			ans=mid;l=mid+1;
		}
		else{
			r=mid-1;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main(){
	int n;
	long a[100010], sum = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (i % 2 == 0) {
			sum += a[i];
		}
		else {
			sum -= a[i];
		}
	}
	cout << sum << " ";
	for (int j = 0; j < n - 1; j++) {
		sum = 2 * a[j] - sum;
		cout << sum;
		if (j != n - 2) {
			cout << " ";
		}
	}
	cout << endl;
	return 0;
}

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

int main() {
 int d , n ;
  cin >> d >> n;
  int ans = 1;
  if (n==100)
    n++;
  if(d==0)
    cout << n;
  else{
    for(int i=1;i<d+1;i++){
      ans *=100 ;
    }
    cout << ans *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 PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
    int n;
    string s;
    cin >> n>>s;
    int a = 0;
    int cnt = 0;
    int b = 1;
    while (a < n&&b<n)
    {
        if (s.at(a) == s.at(b))
        {
            cnt++;
        }
        else
        {
            a = b;
        }
        b++;
    }
    cout << n-cnt << endl;
    
}

Measured memory_bytes: 3764
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <sstream>
#include <bitset>
#include <stack>
#include <cstdlib>
#include <utility> //pair

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

typedef long long ll;

using namespace std;

int main() {
    
    int  n;
    cin >> n;
    
    vector<int> a(n);
    FOR(i, 0, n){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    
    int ans;
    ans = a[n-1] - a[0];
    
    cout << ans <<  endl;
    
    return 0;
}


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


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,a,b,c;cin>>n>>a>>b>>c;
    vector<ll> l(n);rep(i,n)cin>>l[i];
    ll ans = 1e9;
    for(ll i=0; i<pow(4,n); i++){
        ll la=0,lb=0,lc=0,nabc=0;        
        rep(j,n){
            ll e=(i/(ll)pow(4,j))%4;
            if(e==0){la+=l[j];nabc++;}
            else if(e==1){lb+=l[j];nabc++;}
            else if(e==2){lc+=l[j];nabc++;}
        }
        if(la*lb*lc==0)continue;
        ans = min(ans,abs(la-a)+abs(lb-b)+abs(lc-c)+10*(nabc-3));
    }
    cout<<ans<<endl;
    return 0;
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int n;
    while(cin >> n)
    {
        int cnt = 0;
        for(int a=0;a<=9;a++)
            for(int b=0;b<=9;b++)
                for(int c=0;c<=9;c++)
                    for(int d=0;d<=9;d++)
                        if(a+b+c+d == n) cnt++;
        
        cout << cnt << "\n";
    }
    return 0 ;
}



Measured memory_bytes: 3124
N, M = map(int, input().split())
LRD = [tuple(int(x) for x in input().split()) for _ in range(M)]
Graph = [[] for _ in range(N)]
for l,r,d in LRD:
    Graph[r-1].append((l-1,d))
    Graph[l-1].append((r-1,-d))

seen = set()
Dfr = [0] * N #dist from Root
for root in range(N):
    if root in seen: continue
    seen.add(root)
    V = [root]
    while len(V) != 0: #bfs
        v = V.pop(0)
        for nv,d in Graph[v]:
            if nv in seen and Dfr[nv] != Dfr[v] + d: #bfsで発見済みの値が異なる⇔矛盾
                print('No')
                exit()
            if nv in seen: continue
            else:
                seen.add(nv)
                Dfr[nv] = Dfr[v] + d
                V.append(nv)
print('Yes')

Measured memory_bytes: 101548
// C - *3 or /2
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N; cin>>N;
	int a, ans = 0;
	while(N--){
		cin>>a;
		while(!(a&1)){
			ans++;
			a >>= 1;
		}
	}
	cout<< ans <<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;


class Program
{
    static void Main(string[] args)
    {
        

        int N = int.Parse(Console.ReadLine());
        string[] line = Console.ReadLine().Split();
        bool okay = true;
        for (int i = 0; i < N; i++)
        {
            int num = int.Parse(line[i]);
            if (num % 2 == 0)
            {
                if (num % 3 != 0 && num % 5 != 0) okay = false;
            }
        }
        string answer = (okay) ? "APPROVED" : "DENIED";
        Console.WriteLine(answer);

        Console.ReadLine();
    }

}

Measured memory_bytes: 11092
def SelectionSort(seq):
    swp_cnt = 0
    
    for i in range(0, len(seq)):
        idx = i

        for j in range(i, len(seq)):
            if seq[idx] > seq[j]:
                idx = j

        if idx != i:
            seq[i], seq[idx] = seq[idx], seq[i]        
            swp_cnt += 1

    print(*seq)
    print(swp_cnt)

def main():
    n = input()
    seq = [int(a) for a in input().split()]
    SelectionSort(seq)

main()


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

using Graph=vector<vector<int>>;

int main(){
    int n;
    cin>>n;
    int sz=n*n;
    Graph g(sz);
    for(int i=0;i<2*n*n-2*n;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        g[a].push_back(b);
        g[b].push_back(a);
    } 

    vector<vector<int>> res(n,vector<int>(n,-1));
    
    if(n==2){
        res[0][0]=0;
        res[0][1]=g[0][0];
        res[1][0]=g[0][1];
        for(int i=1;i<4;i++){
            if(res[0][1]!=i && res[1][0]!=i){
                res[1][1]=i;
                break;
            }
        }
    }
    else{
        int lu=-1;
        for(int i=0;i<sz;i++){
            if(g[i].size()==2){
                lu=i;
                break;
            }
        }
        assert(lu!=-1);

        res[0][0]=lu;
        for(int i=1;i<n;i++){
            int pre=res[0][i-1];
            for(auto to:g[pre]){
                if(g[to].size()<=3 && (i==1 || res[0][i-2]!=to)){
                    res[0][i]=to;
                    break;
                }
            }
        }
        for(int i=1;i<n;i++){
            int pre=res[i-1][0];
            for(auto to:g[pre]){
                if(to!=res[0][i] && g[to].size()<=3 && (i==1 || res[i-2][0]!=to)){
                    res[i][0]=to;
                    break;
                }
            }
        }

        for(int i=1;i<n;i++){
            for(int j=1;j<n;j++){
                int v0=res[i-1][j];
                int v1=res[i][j-1];
                int notV=res[i-1][j-1];
                for(auto to0:g[v0]){
                    for(auto to1:g[v1]){
                        if(to0==to1 && to0!=notV){
                            res[i][j]=to0;
                        }
                    }
                }
            }
        }
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cout<<res[i][j]+1<<(j+1==n ? "\n" : " ");
        }
    }
    return 0;
}


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

const int N = 200005;
int n, a[N], b[N], ans, piv;

int over (vector<int> &A, vector<int> &B) {
	int C = 0, R = 0;
	for(int i=0,j=(int)B.size()-1;i<(int)A.size();i++) {
		while(j >= 0 && A[i] + B[j] >= piv) {
			C ^= 1;
			j--;
		}
		R ^= C;
	}
	return R;
}

void solve (int V) {
	vector<int> A[2], B[2];
	for(int i=1;i<=n;i++) {
		a[i] %= 2*V;
		A[!!(a[i]&V)].push_back(a[i]%V);
	}
	sort(A[0].begin(), A[0].end());
	sort(A[1].begin(), A[1].end());
	for(int i=1;i<=n;i++) {
		b[i] %= 2*V;
		B[!!(b[i]&V)].push_back(b[i]%V);
	}
	sort(B[0].begin(), B[0].end());
	sort(B[1].begin(), B[1].end());
	piv = V;
	ans += (over(A[0], B[0]) + over(A[1], B[1]) + 1ll*A[0].size()*B[1].size() - over(A[0], B[1]) + 1ll*A[1].size()*B[0].size() - over(A[1], B[0]))%2*V;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		scanf("%d",&a[i]);
	}
	for(int i=1;i<=n;i++) {
		scanf("%d",&b[i]);
	}
	for(int i=29;i>=0;i--) {
		solve(1<<i);
	}
	printf("%d\n",ans);
}


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

int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);
	
	int N,M,Tmp;
	vector<int> Pts,Target;
	
	cin >> N >> M;
	
	Pts.resize(N);
	
	for(int t = 0;t < M;t++){
		cin >> Tmp;
		Target.push_back(Tmp);
	}
	
	for(int m = 0;m < M;m++){
		int t = Target.at(m) - 1;
		for(int n = 0;n < N;n++){
			cin >> Tmp;
			if(Tmp == Target.at(m)){
				Pts.at(n) += 1;
			}else{
				Pts.at(t) += 1;
			}
		}
	}
	
	for(auto v : Pts){
		cout << v << "\n";
	}
	
	return 0;
}

Measured memory_bytes: 3136
#include <iostream>
#include <map>
#include <vector>
#include <numeric>

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> a(n);
    map<ll, ll> c;
    for (ll i = 0; i < n; ++i) cin >> a.at(i), ++c[a.at(i)];
    ll k = accumulate(c.begin(), c.end(), 0LL, [](ll v, pair<ll, ll> i) {
        return v += i.second * (i.second - 1);
    }) / 2;
    for (ll i = 0; i < n; ++i) cout << k - (c.at(a.at(i)) - 1) << '\n';
    return 0;
}


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

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))
#define xyrange(x, minX, maxX, y, minY, maxY) (range(x, minX, maxX) && range(y, minY, maxY))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<bool> > VVB;
typedef pair<int,int> PII;
typedef vector<PII> VPII;


const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
const int INF = 0x3f3f3f3f;

string solve_reverse(int sx, int sy, int tx, int ty) {
	int dx = tx - sx;
	int dy = ty - sy;
	string s1, s2;
	rep (i, dy) {
		s1 += 'D';
	}
	rep (i, dx) {
		s2 += 'L';
	}
	return s1 + s2;
}

string solve(int sx, int sy, int tx, int ty) {
	int dx = tx - sx;
	int dy = ty - sy;
	string s1, s2;
	rep (i, dy) {
		s1 += 'U';
	}
	rep (i, dx) {
		s2 += 'R';
	}
	return s1 + s2;
}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	string ans = solve(sx, sy, tx, ty);
	ans += solve_reverse(sx, sy, tx, ty);
	ans += 'L';
	ans += solve(sx - 1, sy, tx, ty + 1);
	ans += 'D';
	ans += 'R';
	ans += solve_reverse(sx, sy - 1, tx + 1, ty);
	ans += 'U';
	cout << ans << endl;
	return 0;
}



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

flag = 1
for i in range(N):
    if A[i] %2 == 1:
        continue
    elif A[i]%3 == 0 :
        continue
    elif A[i]%5== 0:
        continue
    else:
        flag = 0

if flag :
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3060
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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






template<unsigned long long m> class comb_perm{
private:
    int n;
    std::vector<long long> fact, fact_inv;
public:
    comb_perm(): n(0), fact(1), fact_inv(1){
        fact[0] = fact_inv[0] = 1;
    }
    comb_perm(int N): n(N), fact(N+1), fact_inv(N+1){
        fact[0] = fact[1] = fact_inv[0] = fact_inv[1] = 1;
        for(int i(2); i <= n; ++i) fact[i] = fact[i - 1] * i % m;
        for(int i(2); i <= n; ++i) fact_inv[i] = inv(fact[i]);
    }
 
    void resize(int N){
        fact.resize(N+1);
        fact_inv.resize(N+1);
        if(!n && N){
            fact[1] = fact_inv[1] = 1;
        }
        for(int i(std::max(2, n+1)); i <= N; ++i) fact[i] = fact[i - 1] * i % m;
        for(int i(std::max(2, n+1)); i <= N; ++i) fact_inv[i] = inv(fact[i], m);
        n = N;
    }
 
    long long power(long long a, unsigned long long b){
        long long ret(1);
        while(b){
            if(b & 1) ret = (ret * a) % m;
            a = (a * a) % m;
            b /= 2;
            if(ret < 0) ret += m;
            if(a < 0) a += m;
        }
        return ret;
    }
 
    long long inv(long long a){ // GCD(a, m) = 1
        return power(a, m-2);
    }
 
    long long permutation(int n, int r){
        if(n < r) return 0;
        if(n < 0 || r < 0) return 0;
        long long ret(fact[n]);
        ret = ret * fact_inv[n - r] % m;
        return ret;
    }
 
    long long combination(int n, int r){
        if(n < r) return 0;
        if(n < 0 || r < 0) return 0;
        long long ret(permutation(n, r));
        return ret * fact_inv[r] % m;
    }
 
    long long factorial(int a){
        return fact[a];
    }
 
    long long inv_factorial(int a){
        return fact_inv[a];
    }
};

int main(){
    int N; std::cin >> N;
    comb_perm<MOD> cp(N+3);
    long long ans(cp.power(10, N) - cp.power(9, N));
    ans *= 2;
    ans %= MOD;
    if(ans < 0) ans += MOD;
    ans -= cp.power(10, N) - cp.power(8, N);
    ans %= MOD;
    if(ans < 0) ans += MOD;
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 18780
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define pb push_back 
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<10)
#define LLINF (1<<30)
#define MOD 1000000007
using ll = long long;
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    cout << a * b - a - b + 1;
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>
#include <fstream>
#include <cassert>
//#include <bits/stdc++.h>
using namespace std;

//#include<bits/stdc++.h>


	
int main() {
	
	int n;
	cin >> n;
	string ans = "";
	while (n != 0) {
		if (n % 2) {
			n--;
			ans = "1" + ans;
		}
		else ans = "0" + ans;
		n /= -2;
	}
	if (ans.size() == 0)cout << 0 << endl;
	else cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
object Main extends App{
    val n = scala.io.StdIn.readInt
    println(n.toString.last match {
        case '2' => "hon"
        case '4' => "hon" 
        case '5' => "hon" 
        case '7' => "hon" 
        case '9' => "hon"
        
        case '0' => "pon"
        case '1' => "pon" 
        case '6' => "pon"
        case '8' => "pon"
        
        case _   => "bon"
    })
}


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

using namespace std;

const int M=1e6+6;

int co[M];
int n;

int main()
{
	cin >> n;
	for(int i=0;i<n;i++)
	{
		int x;
		cin >> x;
		co[x]++;
	}
	int ans=0;
	for(int i=1;i<M;i++)
	{
		if(co[i]==0) continue;
		for(int j=2*i;j<M;j+=i)
			co[j]=0;
		ans+=co[i]==1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 7544
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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 <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};


signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    int A,B,C; cin >> A >>B>>C;
    int K; cin >> K;
    bool ok = false;
    REP(i,8) REP(j,8) REP(k,8){
        if(i+j+k > K) continue;

        LL ta = A, tb = B, tc = C;
        REP(l,i) ta *= 2;
        REP(l,j) tb *= 2;
        REP(l,k) tc *= 2;
        if(ta < tb and tb < tc){
            ok = true;
        }

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

}

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

int n,q;
string name[1010];
int e_y[1010], w_y[1010];

int main(){
  while(cin >> n >> q, n){
    for(int i=0;i<n;i++){
      cin >> name[i] >> e_y[i] >> w_y[i];
    }
    for(int i=0;i<q;i++){
      int query;
      cin >> query;

      string ans = "Unknown";
      int y = -1;
      for(int j=0;j<n;j++){
	if(w_y[j]-e_y[j]< query && query<=w_y[j]){
	  ans = name[j]; y = e_y[j] - (w_y[j]-query);
	}
      }
      if(y<0)cout << ans << endl;
      else cout << ans << " " << y << endl;
    }
  }
}

Measured memory_bytes: 1312
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? (-(a)) : (a))

typedef long long ll;

using namespace std;

vector<int> R_idx;
vector<int> G_idx;
vector<int>	B_idx;

ll get_ans(vector<int> &first, vector<int> &second, vector<int> &third)
{
	ll ret = 0;

	for (int i = 0; i < first.size(); ++i)
	{
		for (int j = 0; j < second.size(); ++j)
		{
			if (second[j] < first[i]) continue;
			auto it = lower_bound(third.begin(), third.end(), first[i] + (second[j] - first[i]) + 1);
			ret += third.end() - it;
			it = lower_bound(third.begin(), third.end(), first[i] + 2 * (second[j] - first[i]));
			if (it != third.end() && *it == first[i] + 2 * (second[j] - first[i])) ret--;
		}
	}

	return ret;
}

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

	int N;
	char input[4000 + 5];

	scanf("%d", &N);
	scanf("%s", input);

	for (int i = 0; input[i]; ++i)
	{
		if (input[i] == 'R') R_idx.push_back(i);
		else if (input[i] == 'G') G_idx.push_back(i);
		else B_idx.push_back(i);
	}

	ll ans = 0;
	ans += get_ans(R_idx, G_idx, B_idx);
	ans += get_ans(R_idx, B_idx, G_idx);
	ans += get_ans(G_idx, R_idx, B_idx);
	ans += get_ans(G_idx, B_idx, R_idx);
	ans += get_ans(B_idx, R_idx, G_idx);
	ans += get_ans(B_idx, G_idx, R_idx);

	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 3884
from collections import defaultdict
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
snm = lambda: map(str, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
l=[]
d=defaultdict(int)
for i in range(n):
    s=list(si())
    s.sort()
    tmp=''
    for ss in s:
        tmp+=ss
    l.append(tmp)

for ll in l:
    d[ll]+=1

ans=0
for k,v in d.items():
    if v>=2:
        ans+=(v*(v-1))//2

print(ans)

Measured memory_bytes: 19836
//Kaori Miyazono, did I reach you ?
//"I can't die because... I'm the one who will protect you." -Asuna Yuuki
 
#include <bits/stdc++.h>
using namespace std;

const int N = 19;
typedef pair<long long int, long long int> ii;

int n;
long long int nums[1 << N];
ii dp[1 << N];
long long int ans[1 << N];

void up(ii &a, long long int k) {
	if (k > a.first) {
		a.second = max(a.second, a.first);
		a.first = k;
	} else {
		if (k > a.second) {
			a.second = k;
		}
	}
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for(int i = 0; i < (1 << n); i++) {
		cin >> nums[i];
		up(dp[i], nums[i]);
		//cout << i << ' ' << nums[i] << '\n';
	}
	/*for(int i = 0; i < (1 << n); i++) {
		for(int j = 0; j < n; j++) {
			if (!(i & (1 << j))) {
				up(dp[i | (1 << j)], dp[i].first);
				up(dp[i | (1 << j)], dp[i].second); 
			}
		}
	}*/
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < (1 << n); j++) {
			if (!(j & (1 << i))) {
				up(dp[j | (1 << i)], dp[j].first);
				up(dp[j | (1 << i)], dp[j].second);
			}
		}
	}
	for(int i = 1; i < (1 << n); i++) {
		ans[i] = dp[i].first + dp[i].second;
		ans[i] = max(ans[i], ans[i - 1]);
		//cout << i << '\n';
		//cout << dp[i].first << ' ' << dp[i].second << '\n';
		cout << ans[i] << '\n';
	}
	return 0;
}

Measured memory_bytes: 17408
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <climits>

using namespace std;

class Work {
public:
	int a, b;
};

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

	int n;
	cin >> n;
	vector<Work> work(n);
	for (int i = 0; i < n; i++) {
		cin >> work[i].a >> work[i].b;
	}

	sort(work.begin(), work.end(), [](Work& i, Work& j) {return i.b < j.b; });

	long long time = 0;
	for (int i = 0; i < n; i++) {
		time += work[i].a;
		if (time > work[i].b) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
	return 0;

}

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

int main(){
 int a, b;
 char op;

 while(1){
  cin >> a >> op >> b;
  if( op == '+' ){
  cout << a + b << endl;
  }else if( op == '-' ){
  cout << a - b << endl;
  }else if( op == '*' ){
  cout << a * b << endl;
  }else if( op == '/' ){
  cout << a / b << endl;
  }else if( op == '?' )break;
 }
 return 0;
}

Measured memory_bytes: 3076
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

const ll MOD = 1e9 + 7;

bool check(string mask) {
  if (mask.find("AGC") != string::npos) return false;
  for (int i = 0; i + 1 < mask.size(); i++) {
    swap(mask[i], mask[i + 1]);
    if (mask.find("AGC") != string::npos) {
      return false;
    }
    swap(mask[i], mask[i + 1]);
  }
  return true;
}

int main() {
#ifdef DEBUG
  ifstream cin("in.txt");
#endif
  int N;
  while (cin >> N) {
    const int threshold = 3;
    const string alpha = "ATCG";
    map<string, ll> dp;
    dp[""] = 1;
    for (int t = 0; t < N; t++) {
      map<string, ll> ndp;
      for (auto& entry : dp) {
        string mask = entry.fst;
        ll ways = entry.snd;
        for (char c : alpha) {
          string newMask = mask + c;
          if (check(newMask)) {
            (ndp[newMask.size() > threshold ? newMask.substr(newMask.size() - threshold) : newMask] += ways) %= MOD;
          }
        }
      }
      dp = ndp;
    }
    ll res = 0;
    for (auto& entry : dp) res = (res + entry.snd) % MOD;
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <limits>
#include <tuple>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>
#include <iomanip>
#include <set>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = n-1; i >= 0; --i)
#define REP(i, s, n) for (int i = s; i< (int)(n); ++i)
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;
ll inf = ll(1e18);
using ll1d = vector<ll>;
using ll2d = vector<ll1d>;
using ll3d = vector<ll2d>;

void solve(istream &ccin = cin, ostream &ccout = cout) {

  ll n;
  ccin >> n;
//  ll1d a(n), index_a(n);
  map<ll, ll> mpa;
  rep(i, n) {
    ll a;
    ccin >> a;
    mpa[a] = i;
  }
  ll ans = 0;
  set<ll> s;
  s.insert(-1);
  s.insert(n);
  rep(i, n) {
    auto itr = s.lower_bound(mpa[i + 1]);

    ll r = *itr - mpa[i + 1];
    --itr;
    ll l = mpa[i + 1] - *itr;
    s.insert(mpa[i + 1]);

    ans += (i + 1) * r * l;

  }

  ccout << ans << endl;

}

int main() {
  ios::sync_with_stdio(false);
  solve();
  return 0;
}

Measured memory_bytes: 22144
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTG(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using ll = long long;
using ld = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VI = vector<int>;
using VVI = vector<VI>;
using Vll = vector<ll>;
using VVll = vector<Vll>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

void dijkstra(vector<vector<pair<int, ll>>> &G, Vll &dis, auto s)
{
  /*
  ダイクストラ法。任意の始点から各点への最短距離を求める。計算量は O((V+E)logV)。
  引数のグラフは 0-indexed の隣接リストを想定。要素は、PII(to, weight)。
  始点から各点までの距離を格納する配列を用意し、参照渡しする。すべての要素をINFで初期化しておく。
  */
  dis[s] = 0;
  priority_queue< pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>> > q; // 値の小さい要素を優先
  q.push(pair<ll, int>(dis[s], s));
  while(!q.empty())
  {
    pair<ll, int> node = q.top();
    q.pop();
    int u = node.second;
    ll c = node.first;
    REPx(x, G[u])
    {
      int v = x.first;
      ll w = x.second;
      if (c + w < dis[v])
      {
        dis[v] = c + w;
        q.push(pair<ll, int>(dis[v], v));
      }
    }
  }
}

int main()
{
  ll N;
  cin >> N;
  vector<vector<pair<int, ll>>> tree(N, vector<pair<int, ll>>());
  REP(i, N-1)
  {
    int a, b;
    ll c;
    cin >> a >> b >> c;
    a--; b--;
    tree[a].push_back(pair<int, ll>(b, c));
    tree[b].push_back(pair<int, ll>(a, c));
  }
  int Q, K;
  cin >> Q >> K; K--;
  Vll dis(N, INF);
  dijkstra(tree, dis, K);
  REP(i, Q)
  {
    int x, y;
    cin >> x >> y;
    x--; y--;
    ll res = dis[x] + dis[y];
    cout << res << endl;
  }

  return 0;
}


Measured memory_bytes: 11120
N=input()
for i in range(2**(len(N)-1)):
    OP=["-","-","-"]
    for j in range(len(N)-1):
        if ((i>>j)&1):
            OP[3-j-1]="+"
    formula=""
    for n,op in zip(N,OP+[""]):
        formula+=n+op
    if eval(formula)==7:
        print(formula+"=7")
        break

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
int prime[50010],p;
int main(){
	rep(i,3,50005){
		int flag=1;
		for(int j=2;j*j<=i;j++){
			if(i%j==0){
				flag=0;break;
			}
		}
		if(flag&&i%5==1){
			prime[++p]=i;
		}
	}
	int n;cin>>n;
	rep(i,1,n){
		printf("%d%c",prime[i],(i==n)?'\n':' ');
	}
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <math.h>
#include <string>
typedef long long ll;

using namespace std;

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

    if ((a <= c) && (c <= b)){
	cout << "Yes" << endl;
    } else {
	cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n;
  cin >> n;
  vi a(n);
  int tot;
  rep(i, n){
    cin >> a[i];
    if(i){
      tot ^= a[i];
    }else tot = a[i];
  }
  rep(i, n - 1) cout << (tot ^ a[i]) << " ";
  cout << (tot ^ a[n - 1]) << endl;
}

Measured memory_bytes: 3996
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define GET_ARRAY_SIZE(a)   (sizeof(a)/sizeof(a[0]))
#define LL long long
int main(){
    LL n;
    cin >> n;
    if(n < 1000) {
        cout << "ABC" << endl;
    }else cout << "ABD" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

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

const ld pi = 3.141592653589793;

ll x, k, d;
// -10 5 3
int main() {
  cin >> x >> k >> d;

  if (abs(x) / d >= k) {
    cout << abs(x) - d * k << endl;
    return 0;
  }

  ll ek = k - abs(x) / d;  // 2
  ll c = 0;
  if (x >= 0) {
    c = x - d * (abs(x) / d);
  } else {
    c = x + d * (abs(x) / d);  // -1
  }

  if (ek % 2 == 0) {
    cout << abs(x) - d * (k - ek) << endl;
    return 0;
  }

  cout << min(abs(c - d), abs(c + d)) << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define INF 2e9
using namespace std;
typedef long long llong;
typedef long double ldouble;
int main()
{
  int N;
  cin >> N;
  vector<int> W(N);
  for(int i=0; i<N; i++) cin >> W.at(i);
  int ans = 1e5;
  for(int i=0; i<N-1; i++){
    int mi=0;
    int ma=0;
    for(int j=0; j<=i; j++) mi+=W.at(j);
    for(int j=i+1; j<N; j++) ma += W.at(j);
    ans = min(ans, abs(ma-mi));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
using namespace std;

int main()
{
	string a, b;
	cin >> a >> b;
	int x;
	x = stoi(a + b);
	for (int i = 1; i <= 1000; i++) {
		if (i * i == x) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
  val (N, K) = readInts()
  val set = mutableSetOf<Int>()
  repeat(K) {
    val d = readInt()
    readInts().forEach { set.add(it) }
  }
  println(N - set.size)
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readLong() = readString().toLong()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }


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

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

using namespace std;

typedef long double ld;
typedef complex<ld> P;
typedef vector<P> VP;
const ld eps = 1e-8, pi = acos(-1.0);

#define EQ(a,b) (abs((a)-(b))<eps)

ld dot (P a, P b) { return real(conj(a) * b); }
ld cross (P a, P b) { return imag(conj(a) * b); }

namespace std {
  bool operator<(const P &lhs, const P &rhs) {
    return lhs.real() == rhs.real() ? lhs.imag() < rhs.imag() : lhs.real() < rhs.real();
  }
}

// Line
class L{
public:
  P a, b;
  L (P aa, P bb) { a = aa; b = bb; }
  L (ld ax, ld ay, ld bx, ld by) { a = P(ax, ay); b = P(bx, by); }
};

int ccw (P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > eps) return 1;   // counter clockwise
  if (cross(b, c) < -eps) return -1; // clockwise
  if (dot(b, c) < 0) return 2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;  // a--b--c on line
  return 0;                          // a--c--b on line
}

bool isis_ss(L s, L t) {
  return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0 &&
         ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0;
}

bool isis_sp(L s, P p) {
  return abs(s.a - p) + abs(s.b - p) - abs(s.b - s.a) < eps;
}

P proj(L l, P p) {
  ld t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b);
  return l.a + t * (l.a - l.b);
}

ld dist_sp(L s, P p) {
  P r = proj(s, p);
  if (isis_sp(s, r)) return abs(r - p);
  return min(abs(s.a - p), abs(s.b - p));
}

ld dist_ss(L s, L t) {
  if (isis_ss(s, t)) return 0;
  ld a = min(dist_sp(s, t.a), dist_sp(t, s.a));
  ld b = min(dist_sp(s, t.b), dist_sp(t, s.b));
  return min(a, b);
}

int main() {
  while(1) {
    int n;
    cin>>n;
    if(!n) break;
    ld sx,sy,ex,ey;
    cin>>sx>>sy>>ex>>ey;
    L l(sx,sy,ex,ey);
    typedef tuple<ld,ld,ld,ld,ld> box;
    vector<box> bv;
    REP(i,n) {
      int mnx,mny,mxx,mxy,h;
      cin>>mnx>>mny>>mxx>>mxy>>h;
      bv.emplace_back(mnx,mny,mxx,mxy,h);
    }
    ld lb = 0.0, ub = 1000.0;
    REP(i,50) {
      ld mid = (lb + ub) / 2.0;
      bool ok = true;
      REP(j,n) {
        int mnx,mny,mxx,mxy,h;
        tie(mnx,mny,mxx,mxy,h) = bv[j];
        ld r = (h > mid) ? mid : sqrt(mid*mid - (mid-h)*(mid-h));
        vector<L> vl;
        vl.emplace_back(mnx,mny,mxx,mny);
        vl.emplace_back(mnx,mxy,mxx,mxy);
        vl.emplace_back(mnx,mny,mnx,mxy);
        vl.emplace_back(mxx,mny,mxx,mxy);
        REP(k,4)
          if (dist_ss(vl[k], l) < r) ok = false;
        if (max(sx,ex) < mxx && min(sx,ex) > mnx && max(sy,ey) < mxy && min(sy,ey) > mny) ok = false;
      }
      if (ok) lb = mid;
      else ub = mid;
    }
    cout << setprecision(10) << fixed << lb << endl;
  }
  return 0;
}

Measured memory_bytes: 1328
#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
const int MOD = 1000000007;
const int oo = 2e9;
const int N = 200000 + 100;
const int LOGN = 18;

int n,a[N],dp[N],app[N],ans;

int main() {
	cin >> n;
	for (int i = 0; i < n; ++i){
		scanf("%d",&a[i]);
		if(!app[a[i]-1]){
			dp[a[i]] = 1;
		}else{
			dp[a[i]] = 1 + dp[a[i]-1];
		}
		ans = max(ans,dp[a[i]]);
		app[a[i]] = 1;
	}
	cout << n-ans << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,j,n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(), i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;
 
typedef long long i64;
typedef pair<int, int> pi;
 
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;
 
i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcm(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

const int sz = 300;

i64 fac[sz], finv[sz], inv[sz];

void init() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;

  for(i64 i = 2; i < sz; ++i) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    finv[i] = finv[i - 1] * inv[i] % mod;
  }
}

i64 get(int n, int k) {
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

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

  string s;
  int k;
  cin >> s >> k;

  if(k == 2 && s.size() < 2) return cout << 0 << endl, 0;
  if(k == 3 && s.size() < 3) return cout << 0 << endl, 0;

  init();

  i64 ans = 0;
  int n = s.size();
  rep(i, k, n) {
    if(k == 1) ans += 9;
    else if(k == 2) ans += 9 *  9 * (i - 1);
    else if(k == 3) ans += 9 * 9 *  9 * get(i - 1, 2);
  }

  int num = s[0] - '0';
  if(k == 1) {
    ans += num;
  }
  else if(k == 2) {
    ans += (num - 1) * 9 * (n - 1);
    int i = 1;
    while(i < n && s[i] == '0') ++i;
    if(i < n) ans += s[i] - '0';
    if(i + 1 < n) ans += 9 * (n - i - 1);
  }
  else if(k == 3) {
    ans += (num - 1) * 9 * 9 * get(n - 1, 2);
    int i = 1;
    while(i < n && s[i] == '0') ++i;
    if(i + 1 < n) ans += ((s[i] - '0') - 1) * 9 * (n - i - 1);
    int j = i + 1;
    while(j < n && s[j] == '0') ++j;
    if(j < n) ans += s[j] - '0';
    if(j + 1 < n) ans += 9 * (n - j - 1);
    if(n - i - 1 >= 2) ans += 9 * 9 * get(n - i - 1, 2);
  }
  cout << ans << endl;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  if ((a + b) % 2 == 1) cout << "IMPOSSIBLE" << endl;
  else cout << (a + b) / 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (((a)%mod) * ((b)%mod)) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T, typename U, typename V>
ostream &operator<<(ostream &os, const tuple<T, U, V> &t){
  os << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
  }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
string substr(const string &str, int S1, int S2 = -1){
  if(S2 == -1)return str.substr(S1);
  return str.substr(S1, S2-S1);
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef tuple<int, int, int> TT;
typedef pair<int, TT> PT;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;
// int sum = accumulate(a, a+n, 0LL);
// int mx = max_element(a, a+n);
// int mn = min_element(a, a+n);
// int cnt = count(a, a+n, k);


signed main(){
  int w, h, x, y;
  cin >> w >> h >> x >> y;
  double ans = (double)w * h / 2;
  printf("%lf ", ans);
  if(2*x == w and 2*y == h)cout << 1 << endl;
  else cout << 0 << 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)

int main(void){
	int N,d;
	cin>>N>>d;
	vector<int> p(N);
	rep(i,N)cin>>p[i];
	int res=0;
	rep(i,N){
		res+=max(0,p[i]-d);
	}
	if(res==0)cout<<"kusoge"<<endl;
	else cout<<res<<endl;

	return 0;
}

Measured memory_bytes: 3088
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>

#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

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

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

using namespace std;

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}
template<typename T>
T lcm( T m, T n )
{
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;

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

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end

int main() {
    long long N,x;
    long long ans=0;
    vector<long long>a;
    cin >> N >>x;

    a.push_back(0);
    for(long long i=1; i<=N; i++){
        long long y;
        cin >> y;
        a.push_back(y);
        if(a[i]+a[i-1] > x){
            ans+=a[i]+a[i-1]-x;
            a[i]-=a[i]+a[i-1]-x;
        }
    }


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



Measured memory_bytes: 1400
import java.io.*;
import java.util.Arrays;
import java.util.Scanner;

class Main{

	public static void printseq(int[] s){
		for (int i = 0; i<s.length ; i++) {
			if ( i == s.length-1) {
				System.out.println(s[i]);
			}else{
				System.out.print(s[i] + " ");
			}
		}
	}

	
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] num = new int[n];
		for (int i = 0; i<n ; i++ ) {
			num[i] = Integer.parseInt(br.readLine());
		}
		int cnt = 0;
		int m = 1;
		int judge = m*3 + 1;
		while(judge < num.length){
			m++;
			judge = judge*3 + 1;
		}
		int[] g = new int[m];
		for ( int i = 0; i<m ; i++ ) {
			judge = (judge-1)/3;
			g[i] = judge;
		}

		for (int i = 0; i<m ; i++ ) {
			for (int k = g[i]; k<n ; k++ ) {
				int v = num[k];
				int j = k - g[i];
				while(j >= 0 && num[j] > v){
					num[j+g[i]] = num[j];
					j = j-g[i];
					cnt++;
					// System.out.println(Arrays.toString(num));
				}
				num[j+g[i]] = v;
			}
		}




		System.out.println(m);
		printseq(g);
		System.out.println(cnt);
		for (int i = 0 ; i<num.length ; i++ ) {
			System.out.println(num[i]);
		}
	}
}

Measured memory_bytes: 106624