akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

int main()
{
    const int INF = 1000000000;

    int N, M;
    cin >> N >> M;

    vector<int> a(M);
    vector<int> c(M);

    rep(i, M) {
        int b;
        cin >> a[i] >> b;
        rep(j, b) {
            int cj;
            cin >> cj;
            c[i] |= (1 << (cj-1));
        }
    }

    int allOpened = (1 << N) - 1;
    vector<int> dp(allOpened + 1);

    set<int> curr;
    curr.insert(0);
    dp[0] = 0;
    curr.insert(c[0]);
    dp[c[0]] = a[0];

    // rep(x, dp.size()-1) if (dp[x]) cout  << "dp[" << x << "] = " << dp[x] << "   "; cout << endl;

    for (int i = 1; i < M; ++i) {
        set<int> next;
        for (auto s : curr) {
            // cout << "i = " << i << ", s = " << s << endl;
            next.insert(s);
            int combined = s | c[i];
            if (curr.find(combined) == curr.end() && next.find(combined) == next.end()) {
                dp[combined] = dp[s] + a[i];
                next.insert(combined);
            } else {
                dp[combined] = min(dp[combined], dp[s] + a[i]);        
            }
            // rep(x, dp.size()-1) if (dp[x]) cout  << "dp[" << x << "] = " << dp[x] << "   "; cout << endl;
        }
        curr.swap(next);
    }

    int ans = -1;
    if (curr.find(allOpened) != curr.end()) {
        ans = dp[allOpened];
    }

    cout << ans << endl;

    return 0;
}


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

#ifdef PRINTERS
#include "printers.hpp"
using namespace printers;
#define tr(a)		cerr<<#a<<" : "<<a<<endl
#else
#define tr(a)    
#endif

#define ll          long long
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define partial_sum  	fuck
using namespace std;

int partial_sum[2005][2005];
int N,K;

void add(int fromx,int tox,int fromy,int toy){
	if(fromx>=0 and tox>=0 and fromy>=0 and toy>=0 and fromx<K and tox<K and fromy<2*K and toy<2*K){
		// cerr<<fromx<<" "<<tox<<" "<<fromy<<" "<<toy<<endl;
		partial_sum[fromx][fromy]++;
		partial_sum[tox+1][fromy]--;
		partial_sum[fromx][toy+1]--;
		partial_sum[tox+1][toy+1]++;
	}
	else if(fromx<0 and fromy>=0 and toy>=0 and fromy<2*K and toy<2*K){
		add(0,tox,fromy,toy);
		add(fromx+K,K-1,fromy+K,toy+K);
	}
	else if(tox>=K and fromy>=0 and toy>=0 and fromy<2*K and toy<2*K){
		add(fromx,K-1,fromy,toy);
		add(0,tox-K,fromy+K,toy+K);
	}
	else if(fromy<0 and fromx>=0 and tox>=0 and fromx<K and tox<K){
		add(fromx,tox,0,toy);
		add(fromx,tox,fromy+2*K,2*K-1);
	}
	else if(toy>=2*K and fromx>=0 and tox>=0 and fromx<K and tox<K){
		add(fromx,tox,fromy-2*K,toy-2*K);
	}
	else if(fromx<0 and fromy<0){
		add(0,tox,0,toy);
		add(fromx+K,K-1,fromy+K,K-1);
		add(0+K,tox+K,fromy+K,K-1);
		add(fromx+K,K-1,0+K,toy+K);
	}
	else if(fromx<0 and toy>=2*K){
		add(fromx,tox,fromy,toy-2*K);
	}
	else if(tox>=K and fromy<0){
		add(fromx,tox,fromy+2*K,toy+2*K);
	}
	else if(tox>=K and toy>=K){
		add(fromx-K,tox-K,fromy-K,toy-K);
	}
}
void solve(){
	cin>>N>>K;
	rep(i,0,N){
		int x,y;
		cin>>x>>y;
		char ch;
		cin>>ch;
		bool white=(ch=='W');
		x%=(2*K);
		y%=(2*K);
		if(x>=K){
			x-=K;
			white=!white;
		}
		if(y>=K){
			y-=K;
			white=!white;
		}
		if(!white){
			y+=K;
			white=!white;
		}
		int fromx=x-K+1;
		int tox=x;
		int fromy=y-K+1;
		int toy=y;
		add(fromx,tox,fromy,toy);
	}
	int ans=0;
	rep(i,0,2*K){
		rep(j,0,2*K){
			if(j)partial_sum[i][j]+=partial_sum[i][j-1];
		}
		rep(j,0,2*K){
			if(i)partial_sum[i][j]+=partial_sum[i-1][j];
			ans=max(ans,partial_sum[i][j]);
		}
	}
	cout<<ans;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
//	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 15872
#include"bits/stdc++.h"
using ll=long long; 
using ld=long double; 
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int mod1=1e9+7; 
#define MAX 100000
ll fact[MAX+7];
ll powerm1(ll a,ll b){ ll res=1; while(b) { if(b&1) res=(res*a)%mod1; a=(a*a)%mod1; b>>=1; } return res; }
void fac(){ fact[0]=1; fact[1]=1; rep(i,2,MAX-1) fact[i]=(fact[i-1]*i)%mod1; }
ll modInv(int n){ return powerm1(n,mod1-2); }
int ncr(int n,int r){ if (r==0) return 1; return (fact[n]*modInv(fact[r])%mod1*modInv(fact[n-r])%mod1)%mod1; }
int main()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout); 
  #endif
  int n; cin>>n; ll x,y; ll m=-1e13,mi=1e13; ll m1=-1e13,mi1=1e13; 
  for(int i=1;i<=n;i++)
  {
    cin>>x>>y; 
    m=max(x+y,m); mi=min(mi,x+y); 
    m1=max(m1,x-y); mi1=min(mi1,x-y); 
  }
  
  cout<<max(abs(m-mi),abs(m1-mi1))<<"\n"; 
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
int binpow(int a, int b) {
    if(b==0) return 1;
    int x=binpow(a,b/2);
    x=(x*x)%mod;
    if(b%2==0) return x;
    else return (x*a)%mod;
}
signed main() {
    int n;
    cin>>n;
    // run l from 1 to 1e7
    int l=1;
    int r=1;
    int cur=1;
    int ans=0;
    while(l<1e7) {
        if(cur==n) {
            //cout<<l<<" "<<r<<endl;
            ans=(ans+1)%mod;
        }
        if(cur<=n) {
            r++;
            cur+=(int)log10(r)+1; // digit of r
        }
        if(cur>n) {
            l++;
            cur-=((int)log10(l-1)+1);
        }
    }
    //cout<<"ans = "<<ans<<endl;
    for(int dig=8 ; dig<=n ; dig++) {
        if(n%dig==0) {
            // can use all dig-digit numbers
            int cnt=n/dig;
            int up=binpow(10,dig);
            int down=binpow(10,dig-1);
            int add=(up-cnt+1)-down;
            //cout<<"digit = "<<dig<<endl;
            //cout<<"add = "<<add<<endl;
            ans=(ans+add+mod)%mod;
        }
        // dig*a+(dig+1)*b=n
        // => (dig)(a+b)=n-b
        // b%(dig)==(n)%(dig)
        int rem=(n%dig);
        if(!rem) rem=dig;
        int low=rem*(dig+1);
        int hi=dig*(dig+1); // n>dig*a because b must >0
        if(low<n) ans=(ans+(n-low-1)/hi+1)%mod;
    }
    cout<<ans;
}
/*
123
ans = 910
digit = 41
add = 216089998
digit = 123
add = 244100763
460191684
*/


Measured memory_bytes: 4000
#include <iostream>
using namespace std;
int main(){
    int r,c,A;
    cin >> r >> c;
    int hyo[100][100]={};
    int newer[r+c]={};
    for(int i=0;i<r;i++){
    	for(int j=0;j<c;j++){
    		cin >> A;
    		hyo[i][j]=A;
    	}
    }
    for(int i=0;i<r;i++){
    	for(int j=0;j<c;j++){
    		newer[i]+=hyo[i][j];
    	}
    }
    for(int i=0;i<c;i++){
    	for(int j=0;j<r;j++){
    		newer[r+i]+=hyo[j][i];
    	}
    }
    for(int i=0;i<r;i++){
    	for(int j=0;j<c+1;j++){
    		if(j<c){
    			cout << hyo[i][j] << " " ;
    		}
    		else if(j==c){
    			cout << newer[i] << endl;
    		}
    	}
    }
    int x=0;
    for(int i=0;i<c+1;i++){
    	if(i<c){
              cout << newer[i+r] << " ";
    	}
    	else if(i==c){
              cout << x;
    	}
    	x+=newer[i+r];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3140
from collections import defaultdict, deque, Counter
import sys
import heapq
import math

# input = sys.stdin.readline

sys.setrecursionlimit(1000000000)

MIN = -10 ** 9
MOD = 10 ** 9 + 7


def main():
    s = input()
    t = input()
    # N = int(input())
    # A, B = [int(a) for a in input().split()]
    # B = [int(a) for a in input().split()]
    # A = [
    #     [int(a) for a in input().split()]
    #     for _ in range(N)
    # ]
    # print(A + B)
    print(sum(1 for a,b in zip(s,t) if a==b))


if __name__ == '__main__':
    main()


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

int main () {
  int n;
  cin >> n;
  vector<long>h (n);
  rep (i, n) {
    cin >> h[i];
  }
  long tmp = h[0];
  for (int i = 1; i < n; i++) {
    if (tmp > h[i]) {
      cout << "No" << endl;
      return 0;
    }else if(tmp < h[i]){
      h[i] --;
    }
    tmp = h[i];
  }
  cout << "Yes" << endl; 
}


Measured memory_bytes: 1024
#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>;

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

int main(){
  ll n; cin >> n;
  vll p(n);
  for (ll i=0; i<n; i++) cin >> p.at(i);
  vll pn(n);
  for (ll i=0; i<n; i++) pn.at(p.at(i)-1) = i+1;
  ll k=1, tmpk=1;
  for (ll i=1; i<n; i++) {
    if (pn.at(i-1) < pn.at(i)) tmpk++;
    else {
      k = max(tmpk, k);
      tmpk = 1;
    }
  }
  cout << n - max(tmpk, k) << endl;
  return 0;
}

Measured memory_bytes: 3328
#ifdef loc
    #include "loc_debug.h"
#else
    #include <bits/stdc++.h>
    #define pr(...)
    #define pra(a,n)
    #define praa(a,n,m)
    #define prl()
#endif

typedef long long ll;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define sz(a) int(a.size())
const int N = 100005;
ll a[105], f[105][N], w[105], v[105];

int main() {
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.tie(0);
    int n, W;
    std::cin >> n >> W;
    rep(i, 1, n + 1) {
        std::cin >> w[i] >> v[i];
    }
    rep(i, 1, n + 1) {
        rep(j, 0, W + 1) {
            f[i][j] = f[i - 1][j];
        }
        rep(j, w[i], W + 1) {
            f[i][j] = std::max(f[i][j], f[i - 1][j - w[i]] + v[i]);
        }
    }
    std::cout << f[n][W] << std::endl;
}


Measured memory_bytes: 79360
#include <stdio.h>
#define N 100

int main(void){
    int n;
    int a[N];
    int i;
    double res = 0.0;
    
    scanf("%d", &n);
    
    for(i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    
    for(i = 0; i < n; i++){
        res += ((double)1/a[i]);
    }
    
    printf("%.14f\n", (double)1/res);
    
    return 0;
}

Measured memory_bytes: 128
//
// Created by Chisec Coin on 17/7/15.
//

#include <iostream>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <sstream>
#include <map>
const int NIL = -1;
typedef long long ll;
using std::cin;using std::cout;using std::endl;using std::max;using std::min;

int n, k;
ll w[100005];

int check(ll p) {
    int i = 0;
    for (int j = 0; j < k; ++j) {
        ll s = 0;
        while (s + w[i] <= p) {
            s += w[i++];
            if (i == n) {
                return n;
            }
        }
    }
    return i;
}

int solve() {
    ll left = 0;
    ll right = 100000 * 10000;
    ll mid;
    while (right - left > 1) {
        mid = (left + right) / 2;
        int v = check(mid);
        if (v >= n) {
            right = mid;
        } else {
            left = mid;
        }
    }
    return right;
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> w[i];
    }
    ll ans = solve();
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3848
/**
 * Author RDP
 * 
**/
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <bitset>
#include <iomanip>
#define endl '\n'
#define bp(x) __builtin_popcount(x)
#define zf(x) __builtin_clz(x)
#define zl(x) __builtin_ctz(x)
#define par(x) __bultin_parity(x)
#define FAST_IO ios::sync_with_stdio(0); std::cin.tie(0);
typedef long long ll;
using namespace std;

void test_case()
{
    FAST_IO
    int r;
    cin >> r;
    cout <<(3.141 * 2 * r )<<endl;
    return ;
}
int main()
{
    FAST_IO
    test_case();
    return 0;
}

Measured memory_bytes: 3800
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pb  push_back
#define  F   first
#define  S   second
const ll N=2e5+3;
ll a[105];
int main()
{
    ft
    ll t,i,j,n,m,l,r,s=0,x=0,y=0,z=0;
    cin>>n;
    for(l=2; l<=n; l++)
    {
        r=l;
        for(i=2; i<=(r/i); i++)
        {
            while(r%i==0)
            {
                r/=i;
                a[i]++;
            }
        }
        if(r>1)
        {
            a[r]++;
        }
    }
    l=0,r=0;
    for(i=2; i<=n; i++)
    {
        if(a[i]>=74)
        {
            z++;
        }
        if(a[i]>=24)
        {
            x++;
        }
        if(a[i]>=14)
        {
            y++;
        }
        if(a[i]>3)
        {
            r++;
        }
        if(a[i]>1)
        {
            l++;
        }
    }
    s=z+x*(l-1)+y*(r-1)+(r*(r-1)*(l-2))/2;
    cout<<s<<"\n";
    return 0;
}

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

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

typedef long long ll;

using namespace std;

int main() {
  long H;
  cin >> H;

  ll result = 0;
  ll count = 0;

  while (H >= 1) {
    result += pow(2, count);
    H /= 2;
    count++;
  }

  cout << result << endl;

  return 0;
}


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

cnt = 0
for i in range(N):
    if A[i] >= B[i]:
      cnt += B[i]
      A[i] -= B[i]
    elif A[i+1] >= (B[i]-A[i]):
      A[i+1] = A[i+1]-(B[i]-A[i])
      cnt += B[i]
    else:
      cnt += A[i] + A[i+1]
      A[i+1] = 0
print(cnt)

Measured memory_bytes: 82020
import heapq
n,m=map(int,input().split())
a=list(map(lambda x:-int(x),input().split()))
heapq.heapify(a)
for i in range(m):
    x=-heapq.heappop(a)
    heapq.heappush(a,-(x//2))
print(-sum(a))

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

using namespace std;

#define Rep(i,a,b)  for (int i=(a);i<(b);i++)
#define rep(i,n)    for (int i=0;i<(n);i++)
#define all(x)      (x).begin(), (x).end()

#define ll long long

int main()
{
	int d[5] = {}, n;

	rep (i, 6) {
		cin >> n;
		d[n]++;
	}

	Rep (i, 1, 5) {
		if (d[i] > 2) {
			cout << "NO" << endl;
			return 0;
		}
	}

	cout << "YES" << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 5e5+200;
#define ll long long
#define rep(i,n) for(int i = 0; i < n; i++)
const int INF = 0x3f3f3f;
int main(){
	int w,h,x,y;
	cin>>w>>h>>x>>y;
	double sum = w/2.0*h;
	printf("%.6lf ",sum);
	if( w % 2 == 0 && h % 2 == 0){
		if(x == w/2 && y == h/2){
			cout<<1<<endl;
			return 0;
		}
	}
	cout<<0<<endl;
}


Measured memory_bytes: 256
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>


#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) // [l, r)
#define rep(i,n) REP(i,0,n)           // [0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#ifdef LOCAL
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define showlr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl // [l, r)
#else
#define show(...)
#define showlr(n,l,r)
#endif

#define YN(condition) puts((condition)?"YES":"NO")
#define Yn(condition) puts((condition)?"Yes":"No")
#define yn(condition) puts((condition)?"yes":"no")
#define YES puts("YES")
#define Yes puts("Yes")
#define yes puts("yes")
#define NO  puts("NO")
#define No  puts("No")
#define no  puts("no")

#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

struct io{io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}}io;

template<class T> istream& operator >>(istream &is, vector<T> &v){for(T &e:v)is>>e;return is;}
template<class T> ostream& operator <<(ostream &os, vector<T> v){os<<"{";for(T &e:v)os<<e<<(v.size()-(int)(&e-&v[0])>1?", ":"");os<<"}";return os;}

void _DEBUG(){}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<(sizeof...(b)?",":"\n");_DEBUG(b...);}

inline void in(){}
template<typename H,typename... T>void in(H &a, T&... b){cin>>a;in(b...);}
inline void out(){}
template<typename H,typename... T> void out(H a, T... b){cout<<a<<(sizeof...(b)?" ":"\n");out(b...);}

template<class T> void resz(int n,T& v){v.resize(n);}
template<class H,class... T> void resz(int n,H& a,T&... b){a.resize(n);resz(n,b...);}

template<typename V,typename H> void resize(vector<V>& v,const H a){v.resize(a);}
template<typename V,typename H,typename... T> void resize(vector<V>& v,const H& a,const T... b){v.resize(a);for(auto &v:v) resize(v,b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;
/*------------end of definitions------------*/

vi v(2);
int ans;

signed main(){

    in(v);
    rep(i,2){
        sort(rall(v));
        ans+=v[0];
        v[0]--;
    }
    out(ans);

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    char[] A = scanner.next().toCharArray();
    char[] B = scanner.next().toCharArray();
    int result = compare(A, B);
    if (result < 0) System.out.println("LESS");
    else if (result > 0) System.out.println("GREATER");
    else System.out.println("EQUAL");
  }

  private static int compare(char[] A, char[] B) {
    if (A.length != B.length) {
      if (A.length < B.length) return -1;
      else return 1;
    }
    for (int i = 0; i < A.length; i++) {
      if (A[i] < B[i]) return -1;
      else if (A[i] > B[i]) return 1;
    }
    return 0;
  }
}


Measured memory_bytes: 22868
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

vector<int>g[100111];
int n,a[100111],k,ans;
int dfs(int x,int f=0)
{
	int mx=0;
	for(auto v:g[x])if(v!=x)
	{
		int tmp=dfs(v,x);
		if(tmp==k-(x!=1))ans++;
		else mx=max(mx,tmp+1);
	}
	return mx;
}
int main()
{
	get2(n,k);for(int i=1;i<=n;i++)get1(a[i]);
	if(a[1]!=1){ans++;a[1]=1;}
	for(int i=2;i<=n;i++)g[a[i]].pb(i);
	dfs(1);
	printendl(ans);
	return 0;
}

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

#define N 20
#define K 10
#define S 155

static int c[1 << N];
static int d[1 << N];

static void
init()
{
  int i, j;
  
  for (i = 0; i < (1 << N); ++i) {
    c[i] = d[i] = 0;
    for (j = 1; j <= N; ++j) {
      if (i & (1 << (j - 1))) {
        ++c[i];
        d[i] += j;
      }
    }
  }
}

main()
{
  int n, k, s;
  int i;

  init();
  for (;;) {
    int rval = 0;
    
    scanf("%d%d%d", &n, &k, &s);
    if (n == 0 && k == 0 && s == 0) break ;
    
    for (i = 0; i < (1 << n); ++i) {
      rval += !!(c[i] == k && d[i] == s);
    }
    printf("%d\n", rval);
  }

  return EXIT_SUCCESS;
}

Measured memory_bytes: 8792
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var n, a, b, sum int
	fmt.Scan(&n, &a, &b)
	for i := 1; i <= n; i++ {
		s := strconv.Itoa(i)
		_sum := 0
		for _, v := range s {
			_sum += int(v - '0')
		}
		if a <= _sum && _sum <= b {
			sum += i
		}
	}
	fmt.Println(sum)

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    ll L[11];
    cin >> N;
    rep(i,0,N) cin >> L[i];
    sort(L,L+N);
    ll sum = 0;
    rep(i,0,N-1) sum += L[i];
    if(L[N-1] < sum){
        print("Yes");
    }else{
        print("No");
    }
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

ll A, B, C, D;
ll DP[3005][3005];

int main(){
  scanf("%lld%lld%lld%lld", &A, &B, &C, &D);

  DP[A][B] = 1;
  for (ll i = A + 1; i <= C; i++){
    DP[i][B] = DP[i-1][B] * B;
    DP[i][B] %= MOD2;
  }
  for (ll j = B + 1; j <= D; j++){
    DP[A][j] = DP[A][j-1] * A;
    DP[A][j] %= MOD2;
  }

  for (ll i = A + 1; i <= C; i++){
    for (ll j = B + 1; j <= D; j++){
      ll now = DP[i][j-1] * i; now %= MOD2;
      now += DP[i-1][j] * j; now %= MOD2;
      now -= DP[i-1][j-1] * (i-1) * (j-1); now %= MOD2;
      if (now < 0) now += MOD2;
      DP[i][j] = now;
    }
  }

  cout << DP[C][D] << endl;

  return 0;
}


Measured memory_bytes: 74088
#include <iostream>
#include <vector>
#include <algorithm>	// require sort next_permutation etc.
//#include <fstream>	// require freopen

using namespace std;

int main()
{
//	cut here before submit 
//	freopen ("testcase.bb", "r", stdin );
	int n, m;

	while (cin >> n && n ){
		vector <int> a(n);
		int res = 0;
		int i,j;

		for (i = 0; i < n; ++i ) {
			cin >> a[i];
		} // /end for
		for (i = 0; i < n; ++i ) {
			for (j = 0; j < n - i - 1; ++j ) {
				if (a[j] > a[j+1] ) {
					swap (a[j], a[j+1] );
					++res;
				} // end for
 			} // end for
		} // end for
		cout << res << endl;
	} // end loop

	return 0;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		

		int taro = 0;
		int hanako = 0;
		
		for(int i = 0; i < n; i++){
			String[] tmpArray = br.readLine().split(" ");
			
			if(tmpArray[0].compareTo(tmpArray[1]) > 0){
				taro += 3;
			}
			
			else if(tmpArray[0].compareTo(tmpArray[1]) < 0){
				hanako += 3;
			}
			else {
				taro++;
				hanako++;
			}
		}
		
		System.out.println(taro+" "+hanako);
//		System.out.println(count);

//
//			if(Character.isLowerCase(c)){
//				System.out.print(Character.toUpperCase(c));
//			}
//
//			else if(Character.isUpperCase(c)){
//				System.out.print(Character.toLowerCase(c));
//			}
//			else {
//				System.out.print(c);
//			}
//		}
//		System.out.println();

//		String[] tmpArray = br.readLine().split(" ");
//		int n = Integer.parseInt(tmpArray[0]);
//		int m = Integer.parseInt(tmpArray[1]);
//		int l = Integer.parseInt(tmpArray[2]);
//
//		long[][] a = new long[n][m];
//		long[][] b = new long[m][l];
//		long[][] c = new long[n][l];
//
//		for(int i = 0; i < n; i ++){
//			tmpArray = br.readLine().split(" ");
//			for(int j = 0; j < m; j++){
//				a[i][j] = Long.parseLong(tmpArray[j]);
//			}
//		}
//
//		for(int i = 0; i < m; i ++){
//			tmpArray = br.readLine().split(" ");
//			for(int j = 0; j < l; j++){
//				b[i][j] = Integer.parseInt(tmpArray[j]);
//			}
//		}
//
//		for(int i = 0; i < n; i++){
//			for(int j = 0; j < l; j++){
//				for(int k = 0; k < m; k++){
//					c[i][j] += a[i][k]*b[k][j];
//				}
//
//				if(j != 0 ){
//					System.out.print(" ");
//				}
//				System.out.print(c[i][j]);
//			}
//			System.out.println();
//		}


	}

}

Measured memory_bytes: 25364
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007
int main()
{
       fast;
       ll n,k;
       cin>>n>>k;
       ll arr[2005][2005];
       memset(arr,0,sizeof(arr));
       arr[0][0]=1;
       for(int i=0;i<=n;i++)
    	arr[i][0]=1;
       for(int i=1;i<=n;i++)
    		for(int j=1;j<=n;j++)
    			arr[i][j]=(arr[i-1][j-1]%MOD+arr[i-1][j]%MOD)%MOD;
    	for(int i=1;i<=k;i++)
    		cout<<(arr[n-k+1][i]%MOD*arr[k-1][i-1]%MOD)%MOD<<endl;
       return 0;
}

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

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

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(make_pair(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
const int mod = 1000000007;

int main() {
    int r;
    cin >> r;
    cout << r * r << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin >> N;

    vector<int> A(N);
    vector<int> B(N);
    vector<int> C(N-1);

    for (int i = 0; i < N; i++){
        cin >> A[i];
    }
    for (int i = 0; i < N; i++){
        cin >> B[i];
    }
    for (int i = 0; i < N-1; i++){
        cin >> C[i];
    }

    int ans = 0;
    for (int i = 0; i < N; i++){
        ans += B[A[i]-1];
        if (i >= 1 && A[i-1]+1 == A[i] ){
            ans += C[A[i-1]-1];
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
 
#define MAX_LEN (80)
 
int main(void)
{
    int no;
     
    scanf("%d", &no);
     
    while (no--){
        char num_str[MAX_LEN + 2];
        char add_str[MAX_LEN + 2];
        int num_len, add_len;
        int i;
        int tmp;
         
        scanf("%81s", num_str);
        scanf("%81s", add_str);
        num_len = strlen(num_str);
        add_len = strlen(add_str);
         
        memmove(&num_str[MAX_LEN - num_len + 1], num_str, num_len);
        for (i = 0; i < MAX_LEN - num_len + 1; i++) num_str[i] = '0';
        num_str[MAX_LEN + 1] = '\0';
         
        memmove(&add_str[MAX_LEN - add_len + 1], add_str, add_len);
        for (i = 0; i < MAX_LEN - add_len + 1; i++) add_str[i] = '0';
        add_str[MAX_LEN + 1] = '\0';
         
        tmp = 0;
        for (i = MAX_LEN; i + 1; i--){
            num_str[i] = num_str[i] + (add_str[i] - '0') + tmp;
            if (num_str[i] > '9'){
                num_str[i] = num_str[i] - 10;
                tmp = 1;
            }
            else tmp = 0;
        }
         
        if (num_str[0] != '0') puts("overflow");
        else {
            for (i = 1; num_str[i] == '0'; i++);
            if (i == MAX_LEN + 1) puts("0");
            else puts(&num_str[i]);
        }
    }
     
    return (0);
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
static const int INF = (1 << 21);

int n;
int A, B, C;

int dfs(vector<int> &l, int cur, int a, int b, int c) {
  if (cur == n) {
    if (min(a, min(b, c)) > 0) {
      return abs(a - A) + abs(b - B) + abs(c - C) - 30;
    } else {
      return INF;
    }
  }
  int ret0 = dfs(l, cur + 1, a, b, c);
  int ret1 = dfs(l, cur + 1, a + l[cur], b, c) + 10;
  int ret2 = dfs(l, cur + 1, a, b + l[cur], c) + 10;
  int ret3 = dfs(l, cur + 1, a, b, c + l[cur]) + 10;

  return min(ret0, min(ret1, min(ret2, ret3)));
}

int main() {
  cin >> n >> A >> B >> C;

  vector<int> l(n);
  for (int i = 0; i < n; i++) {
    cin >> l[i];
  }

  cout << dfs(l, 0, 0, 0, 0) << endl;
}

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

using namespace std;

typedef long long ll;

#define endl '\n';

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout);

    string s;

    cin>>s;

    if (s[2]==s[3] && s[4]==s[5])
        cout<<"Yes";
    else
        cout<<"No";

    return 0;
}







Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

const int MAX_M=10000,MAX_N=500;

int M,N;
int P[MAX_M];
int C[MAX_N],E[MAX_N];

int sum[MAX_M];	//sum[i]=(iまでのまんじゅうを選んだ最大の価値)
int memo[MAX_N][MAX_M];
int dfs(int,int);

int main(){
	int i;
	scanf("%d %d",&M,&N);
	for (i=0;i<M;i++){
		scanf("%d",P+i);
	}
	for (i=0;i<N;i++){
		scanf("%d %d",C+i,E+i);
	}
	sort(P,P+M);
	sum[0]=P[M-1];
	for (i=1;i<M;i++){
		sum[i]=sum[i-1]+P[M-1-i];
	}
	memset(memo,-1,sizeof(memo));
	printf("%d\n",dfs(0,0));
	return 0;
}

int dfs(int i,int j){
	//iの箱を使うかどうか選択
	//j以下のまんじゅうを使う
	if (i==N || j==M){
		return 0;
	}
	if (memo[i][j]!=-1){
		return memo[i][j];
	}
	int res=dfs(i+1,j);	//箱を使わない場合
	//箱を使う場合
	//まんじゅうの個数
	int c=min(C[i],M-j);	//箱の限界orまんじゅうの限界
	int e=sum[j+c-1]-(j>0 ? sum[j-1] : 0);	//まんじゅうの価値
	res=max(res,e-E[i]+dfs(i+1,j+c));
	return memo[i][j]=res;
}

Measured memory_bytes: 20676
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+10;
int n;
int color_count[N],color[N],total[N],sz[N],tmp_count[N];
vector<int> vi[N],group[N];
 
void start(int u, int parent) 
{
    sz[u]=1;
    for(auto v: vi[u]) 
	if(v!=parent) 
	{
        start(v,u);
        sz[u]+=sz[v];
    }
} 
void dfs(int u, int parent) 
{
    int before=tmp_count[color[u]];
    int cur=tmp_count[color[u]];
    for(auto v: vi[u]) 
	{
		if(v!=parent) 
		{
        	dfs(v,u);
        	int inc=tmp_count[color[u]]-cur;
        	group[color[u]].push_back(sz[v]-inc);
        	total[color[u]]+=sz[v]-inc;
        	cur=tmp_count[color[u]];
    	}
	}
    tmp_count[color[u]]=before+sz[u];
} 
signed main()  
{
    ios_base::sync_with_stdio(false); 
	cin.tie(0); 
	cout.tie(0);
    cin >> n;
    for(int i=1;i<=n;i++)
	{
		cin>>color[i];
		color_count[color[i]]++;
	}
    for(int i=1;i<n;i++)
	{
        int u,v; 
		cin>>u>>v;
        vi[u].push_back(v); 
		vi[v].push_back(u);
    }
    start(1,1);
    dfs(1,1);
    for(int i=1;i<=n;i++) 
	{
		if(total[i]+color_count[i]<n)
        	group[i].push_back(n-total[i]-color_count[i]);
	}
    for(int i=1;i<=n;i++)
	{
        int ans=n*(n-1)/2+n;
        for(auto num: group[i]) 
		{
            ans-=(num*(num-1)/2);
            ans-=num;
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 59124
#include <bits/stdc++.h>
using namespace std;
char s[2050][2050];
int p[2050][2050];
int r[2050][2050];
int u[2050], d[2050];
int h, w;
int main(){
	memset(p, 0, sizeof(p));
	scanf("%d%d", &h, &w);
	for(int i=1;i<=h;i++){
		scanf("%s", s[i]+1);
	}
	for(int i=1;i<h;i++){
		for(int j=1;j<w;j++){
			int cnt=0;
			cnt+=(s[i][j]=='.');
			cnt+=(s[i+1][j]=='.');
			cnt+=(s[i][j+1]=='.');
			cnt+=(s[i+1][j+1]=='.');
			if(cnt%2==0)p[i][j]=1;
		}
	}
	for(int i=1;i<h;i++){
		for(int j=w-1;j>=1;j--){
			if(p[i][j]){
				r[i][j]=r[i][j+1]+1;
			}
			else r[i][j]=0;
		}
	}
	int M=max(h, w);
	for(int j=1;j<w;j++){
		for(int i=1;i<h;i++){
			int id=i-1;
			while(id&&r[id][j]>=r[i][j])id=u[id];
			u[i]=id;
		}
		for(int i=h-1;i>=1;i--){
			int id=i+1;
			while(id<h&&r[id][j]>=r[i][j])id=d[id];
			d[i]=id;
		}
		for(int i=1;i<h;i++){
			if(r[i][j]==0)continue;
			M=max(M, (d[i]-u[i])*(r[i][j]+1));
		}
	}
	printf("%d\n", M);
}



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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string S; cin >> S;
    int acc = 0;
    rep(i, S.length()){
        acc += S[i]-'0';
    }
    if(acc%9) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3768
/*input
1600
*/

#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>




#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vpll vector < pair<long long,long long> >
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define fill(a)  memset(a, 0, sizeof (a))
#define mp make_pair
#define pb push_back
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second
#define pdd pair<double, double>
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define forstl(i,v) for(auto &i: v)
#define dbg(x) cout << #x << " = " << x << '\n'
#define dbg2(x,y) cout<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl;
#define dbgstl(v) cout<<#v<<" = \n"; { int c=0; forstl(it,v) \
cout<<"    "<<#v<<"["<< ++c <<"] = "<<it<<endl;} cerr<<endl
#define dbgstlp(v) cout<<#v<<" = \n"; { int c=0; forstl(it,v) \
cout<<"    "<<#v<<"["<< ++c <<"] = "<<it.f<<" , "<<it.s<<endl;} cerr<<endl
#define PI           3.14159265358979323846

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define pdd pair<double, double>
#define in(v,n) vll v(n);rep(i,n) cin>>v[i]


using namespace std;


int main(){
	std::ios::sync_with_stdio(false);
    cin.tie(0);
    cin.exceptions(cin.failbit);
    int T;
	// cout<<std::fixed<<std::setprecision(35);
	// cin>>T;while(T--)
	{
		ll t,n,i,j,x,y,m,l,d,k;
		cin>>x;
		if(x<600) cout<<8<<endl;
		else if(x<800) cout<<7<<endl;
		else if(x<1000) cout<<6<<endl;
		else if(x<1200) cout<<5<<endl;
		else if(x<1400) cout<<4<<endl;
		else if(x<1600) cout<<3<<endl;
		else if(x<1800) cout<<2<<endl;
		else cout<<1<<endl;
	}
}

Measured memory_bytes: 3648
N = int(input())
A = list(map(int, input().split(" ")))
A.sort()
counter = {}

for a in A:
    if a in counter:
        counter[a] += 1
    else:
        counter[a] = 1

one, two = 0, 0
for c in counter:
    if counter[c] % 2 == 0:
        two += 1
    else:
        one += 1

print(one + two - (two % 2))

Measured memory_bytes: 18272
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

typedef string::const_iterator State;
ll expression(State &begin);
ll number(State &begin);

string str;

ll number(State &begin){
	ll ret=0;
	while(isdigit(*begin)){
		ret*=10LL;
		ret%=MOD;
		ret+=*begin-'0';
		begin++;
	}
	return ret;
}

ll calc(ll a,ll b){
	if(b>35LL){
		return 0;
	}else{
		ll v=1;
		for(int i=0;i<b;i++){
			v*=2LL;
		}
		return a/v;
	}
}

ll term(State &begin){
	ll ret=number(begin);
	while(1){
		if(*begin=='S'){
			begin++;
			while(*begin==' ')begin++;
			begin++;
			while(*begin==' ')begin++;
			ret=expression(begin);
			ret=ret*ret%MOD;
			while(*begin==' ')begin++;
			begin++;
		}else{
			return ret;
		}
	}
}

ll expression(State &begin){
	ll ret=term(begin);
	while(1){
		//cout << ret << *begin << endl;
		if(*begin=='S'){
			begin++;
			while(*begin==' ')begin++;
			begin++;
			while(*begin==' ')begin++;
			ret=expression(begin);
			ret=ret*ret%MOD;
			while(*begin==' ')begin++;
			begin++;
		}else if(*begin=='b'){
			begin++;
			begin++;
			while(*begin==' ')begin++;
			ret=calc(ret,term(begin));
		}else if(*begin==' '){
			begin++;
		}else{
			return ret;
		}
	}
}


int main(void){
	while(1){
		getline(cin,str);
		if(str=="#")break;
		for(int i=0;i<str.size();i++){
			if(isdigit(str[i]) || str[i]=='S'){
				int v=i-1;
				while(v>=0){
					if(isdigit(str[v]) || str[v]=='S')break;
					if(str[v]=='<')break;
					if(str[v]=='>'){
						str[v]='b';
						str[v-1]='b';
						break;
					}
					v--;
				}
			}
		}
		State begin=str.begin();
		printf("%lld\n",expression(begin));
	}
	return 0;
}

Measured memory_bytes: 4896
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < 5; i++) {
            int x = sc.nextInt();
            if (x == 0) {
                System.out.println(i + 1);
            }
        }
        sc.close();

    }
}


Measured memory_bytes: 35672
#include <bits/stdc++.h>
#define maxn 100086

using namespace std;

int n;
map<int, int> mp;
int a[maxn], ans;

int main(){
	scanf("%d", &n);
	for(int i = 1;i <= n;i++){
		scanf("%d", &a[i]);
		mp[a[i]]++;
	}
	sort(a + 1, a + 1 + n);
	n = unique(a + 1, a + 1 + n) - (a + 1);
	for(int i = 1;i <= n;i++){
		for(int j = 1;j < i;j++){
			for(int k = 1;k < j;k++){
				if(a[j] + a[k] > a[i]) ans += mp[a[i]] * mp[a[j]] * mp[a[k]];
			}
		}
	}
	printf("%d", ans);
}

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

#define ll  long long
#define PII pair<ll,ll>
#define VI  vector<ll>
#define VB  vector<bool>
#define VC  vector<char>
#define VVI vector<vector<ll>>
#define VVC vector<vector<char>>
#define VS  vector<string>
#define VP  vector<PII>
#define lf(i,a,b) for(ll i=a;i<=b;i++)
#define lr(i,a,b) for(ll i=a;i>=b;i--)
#define lfl(i,v) for(ll i=0;i<v.size();i++)
#define lrl(i,v) for(ll i=(ll)(v.size())-1;i>=0;i--)
#define chk2(a,b) cout<<"check :  "<<a<<" "<<b<<endl
#define chk3(a,b,c) cout<<"check :  "<<a<<" "<<b<<" "<<c<<endl
#define chk4(a,b,c,d) cout<<"check :  "<<a<<" "<<b<<" "<<c<<" "<<d<<endl
#define chk5(a,b,c,d,e) cout<<"check :  "<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl
#define l_b(v,k)  lower_bound(v.begin(),v.end(),k)-v.begin()
#define u_b(v,k)  upper_bound(v.begin(),v.end(),k)-v.begin()
#define mod 1000000007
#define sort(v) sort(v.begin(),v.end())
#define p_b push_back
#define p_f push_front
#define m_p make_pair
#define fir first
#define sec second
#define sz size()


int main() 
{	ll T;
	T=1;
	while(T--)
	{	string s,t;cin>>s>>t;
		ll ns=s.length();
		ll nt=t.length();
		ll mini=INT_MAX;
		lf(i,0,ns-nt)
		{	ll cnt=0;
			lf(j,0,nt-1)
			{	if(s[i+j]!=t[j])
					cnt++;
			}
			mini=min(mini,cnt);
		}
		cout<<mini<<endl;
	}  		
}      


Measured memory_bytes: 3628
N, *D = map(int, open(0).read().split())
D.append(0)
used = [0]*(N+1)
cnt = N
while True:
  ls = []
  for i in range(N+1):
    for j in range(N+1):
      if i==j:
        continue
      a,b = min(D[i],D[j]),max(D[i],D[j])
      d = b-a
      ls.append((min(d,24-d),i,j))
  ls.sort(key=lambda x:x[0])
  d,a,b = ls[0]
  if used[a]==0 and used[b]==0:
    da = (24-D[a])%24
    ma = 100
    for i in range(N+1):
      if i==a:
        continue
      x = abs(da-D[i])
      ma = min(ma,x,24-x)
    db = (24-D[b])%24
    mb = 100
    for i in range(N+1):
      if i==b:
        continue
      x = abs(db-D[i])
      mb = min(mb,x,24-x)
    if ma<mb:
      if d>=mb:
        print(d)
        break
      D[b] = db
      used[b] = 1
    else:
      if d>=ma:
        print(d)
        break
      D[a] = da
      used[a] = 1
  elif used[a]==0:
    used[a] = 1
    da = (24-D[a])%24
    ma = 100
    for i in range(N+1):
      if i==a:
        continue
      x = abs(da-D[i])
      ma = min(ma,x,24-x)
    if d>=ma:
      print(d)
      break
    D[a] = da
  elif used[b]==0:
    used[b] = 1
    db = (24-D[b])%24
    mb = 100
    for i in range(N+1):
      if i==b:
        continue
      x = abs(db-D[i])
      mb = min(mb,x,24-x)
    if d>=mb:
      print(d)
      break
    D[b] = mb
  else:
    print(d)
    break

Measured memory_bytes: 3320
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

#define mp make_pair
#define FOR(i, a, b) for (int(i) = a; (i) <= (b); ++(i))
#define rep(i, n) FOR(i, 0, n-1 )
#define FFOR(i, a, b) for (int(i) = a; (i) > (b); --(i))
#define rrep(i, n) FFOR(i, 0, n)
#define vsort(v) sort((v).begin(), (v).end());           //小さい順
#define rvsort(v) sort(v.begin(), v.end(), greater<>()); //大きい順
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define all(c) (c).begin(), (c).end()
#define ll long long
#define lb long double
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout << (p) << endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 123456789012345
#define int ll
typedef pair<int, int> P;
typedef pair<int, P> PP;

const int maxn = 1e5 + 10;
int a[maxn];
map<int,int> mp;

signed main() {

  int n;cin>>n;
  
  int ue = 1,shita = 0,keta =0,value = 1;
  while(!(ue >= n && n >= shita))
  {
    keta++;
    value *= -2;
    if(value > 0) ue += value;
    else shita += value;
  }
  
  string ans = "";

  while(keta>-1)
  {
    if(value>0)ue-=value;
    else shita -= value;

    if(!(ue>=n&&n>=shita))
    {
      ans += "1";
      n -= value;
    }
    else ans +="0";

    value /= -2;
    keta--;
  }

  cout << ans << endl;
 
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;
#define MOD 1000000007
#define EPS 10e-8

ll p[3];  //kazu
ll g[3];  //p[i]no kazu

int main(){
    ll n;
    int c=0;
    int l,r,A,B,C,D,q,a,b; 
    cin >> n >> A >> B >> C >> D ; 
    a=b=l=q=0;    //l:#ren ,q:suretigai
    char S[200007];
    cin >> S;
    if(B>A){
        int t=A;
        A=B;
        B=t;
        t=C;
        C=D;
        D=t;
    }

    if(A>C){
        int t=A;
        A=C;
        C=t;
    }
    if(B>D){
        int t=B;
        B=D;
        D=t;
    }


    for(int i=A;i<=C-1;i++){
        if(S[i]=='#' && S[i-1]=='#'){
            l++;
        }
    }
    for(int i=B;i<=D-1;i++){
        if(S[i]=='#' && S[i-1]=='#'){
            l++;
        }
    }

    if(C<D){
        for(int i=A;i<=C;i++){
            if(S[i]=='.' && S[i-1]=='.' && S[i-2]=='.'){
                q++;
                break;
            }
        }
    }
    else{
        q++;
    }



    if(l==0 && q>0){
        cout << "Yes" << endl;
    }
    else{
        cout <<  "No" << endl;
    }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int inf=1<<30;

int n,q;
vi l,r,a;

void f(int& x){
	x=lower_bound(a.begin(),a.end(),x)-a.begin();
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	l=r=vi(n);
	a=vi(n+1);
	for(int i=0;i<n;i++){
		cin>>r[i]>>l[i];
		l[i]=min(l[i],r[i]);
	}
	for(int i=0;i<=n;i++) cin>>a[i];
	sort(a.begin(),a.end());
	vvi g(n+2),G(n+2);
	vi b(n+2,1),c(n+2,-1),d(n+2);
	priority_queue<P> pq;
	int res=0;
	b[n]=-n;c[0]=0;
	for(int i=0;i<n;i++){
		f(l[i]);f(r[i]);
		int L=l[i],R=r[i];
		g[R].push_back(L);
		if(R<=n){
			b[n]++;
			if(R) b[R-1]--;
		}
		c[R]++;
	}
	for(int i=n;i>=0;i--){
		if(i<n) b[i]+=b[i+1];
		for(auto j:g[i+1]) pq.push({-j,i+1});
		while(pq.size()&&b[i]<0){
			P p=pq.top();
			pq.pop();
			int L=-p.first,R=p.second;
			if(i<L) G[L].push_back(R);
			else{
				b[i]++;
				if(L) b[L-1]--;
				c[L]++;c[R]--;
				res++;
			}
		}
		if(b[i]<0) res=inf;
	}
	while(pq.size()){
		P p=pq.top();
		pq.pop();
		int L=-p.first,R=p.second;
		G[L].push_back(R);
	}
	d[0]=res;
	for(int i=0;i<=n;i++){
		if(i) c[i]+=c[i-1];
		for(auto j:G[i]) pq.push({j,-i});
		while(pq.size()&&c[i]<1){
			P p=pq.top();
			pq.pop();
			int L=-p.second,R=p.first;
			if(i<=R){
				c[i]++;c[R]--;
				res++;
			}
		}
		if(c[i]<1) res=inf;
		d[i+1]=res;
	}
	cin>>q;
	for(int i=0;i<q;i++){
		int x,y;
		cin>>x>>y;
		f(x);f(y);
		int t=min(d[x],d[y]+1);
		cout<<(t<inf?n-t+1:-1)<<endl;
	}
}

Measured memory_bytes: 14964
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
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; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class CSwaps {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      vector<int> a(n), b(n);
      rep(i, n) {
        cin >> a[i];
      }
      rep(i, n) {
        cin >> b[i];
      }
      auto sa = a;
      auto sb = b;
      sort(all(sa));
      sort(all(sb));

      rep(i, n) {
        if (sa[i] > sb[i]) {
          cout << "No" << endl;
          return;
        }
      }
      for(int i=1; i<n-1; i++) {
        if (sa[i+1] <= sb[i]) {
          cout << "Yes" << endl;
          return;
        }
        if (sa[i] == sa[i+1] || sb[i] == sb[i+1]) {
          cout << "Yes" << endl;
          return;
        }
      }

      map<int, int> ma, mb;
      rep(i, n) {
        ma[a[i]] = i;
        mb[b[i]] = i;
      }

      for(int i=0; i<n-2; i++) {
        auto apos = ma[sa[i]];
        auto bpos = mb[sb[i]];
        if (apos == bpos) {
          cout << "Yes" << endl;
          return;
        }
        swap(a[apos], a[bpos]);
        ma[a[apos]] = apos;
        ma[a[bpos]] = bpos;
      }

      rep(i, n) {
        if (a[i] > b[i]) {
          cout << "No" << endl;
          return;
        }
      }

      cout << "Yes" << endl;
    }
};

signed main() {
  CSwaps solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 11136