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

using namespace std;
using vi = vector<int>;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<"\n"

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

  vi A(N), B(N), C(M), D(M);
  REP(i, N)
    cin >> A[i] >> B[i];
  REP(i, M)
    cin >> C[i] >> D[i];

  REP(i, N) {
    int min_idx = 0;
    REP(j, M) {
      if (abs(A[i] - C[j]) + abs(B[i] - D[j]) < abs(A[i] - C[min_idx]) + abs(B[i] - D[min_idx])) {
        min_idx = j;
      }
    }
    OUT(min_idx+1);
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数


int main()
{
  int k, t ;
  cin >> k >> t ;
  int sum = 0 ;
  vector<int> vec(t) ;
  REP(i,t){
    cin >> vec.at(i) ;
  }
  sort(ALL(vec)) ;
  int ans = vec.at(t-1) ;
  REP(i,t-1){
    sum += vec.at(i) ;
  }
  cout << max(ans-sum-1,0) <<endl ;
    
  
  return 0 ;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <math.h>
#include <set>
  
#define REP(i,n)for (int i=0;i<(n);i++)
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ll long long
using namespace std;

int main(){
    string s;
    int w;
    cin>>s>>w;
    for(int i=0;i<s.size();i+=w){
        cout<<s[i];
    }
    cout<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n;
    std::cin >> n;
    std::vector<i64> a(n), b(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i] >> b[i];
    }

    std::set<std::pair<i64, int>, std::greater<>> ss;
    for (int i = 0; i < n; i++) {
        ss.emplace(a[i] + b[i], i);
    }

    i64 ret = 0;
    bool turn = true;
    for (auto it = ss.begin(); it != ss.end(); it++) {
        if (turn) {
            ret += a[it->second];
        } else {
            ret -= b[it->second];
        }
        turn = !turn;
    }

    std::cout << ret << std::endl;

    return 0;
}


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

#define mod ((int)1e9+7)

void test(vector<int> &arr, int k){
	int dp[arr.size()][k+1], p_sum[k+1];
	memset(dp, 0, sizeof(dp));
	memset(p_sum, 0, sizeof(p_sum));
	for(int i = 0; i < arr.size(); i++){
		dp[i][0] = 1;
	}
	for(int i = 1; i <= arr[0]; i++){
		dp[0][i] = 1;
	}
	for(int i = 1; i < arr.size(); i++){ 
		p_sum[0] = dp[i-1][0];
		for(int j = 1; j < k+1; j++){
			p_sum[j] = (((p_sum[j-1])%mod)+(dp[i-1][j]))%mod;
		}
		for(int j = 1; j < k+1; j++){ 
			if(j-arr[i]>=1){
				dp[i][j] = ((p_sum[j]%mod) - (p_sum[j-arr[i]-1]%mod))%mod;
				if(dp[i][j]<0){
					dp[i][j] = (dp[i][j]+mod)%mod;
				}
			}
			else{
				dp[i][j] = p_sum[j]; 
			}
		}
	}
	cout << dp[arr.size()-1][k] << endl;
}

int main(){
	#ifndef ONLINE_JUDGE
	freopen("/home/afzalrao/Desktop/Academics/2nd Year/3rd Sem/ESO207/CP/Text Files/input.txt", "r", stdin);
	freopen("/home/afzalrao/Desktop/Academics/2nd Year/3rd Sem/ESO207/CP/Text Files/output.txt", "w", stdout);
	#endif
	int n, k;
	cin >> n >> k;
	vector<int> arr(n);
	for(int i = 0; i < n; i++){
		cin >> arr[i];
	}
	test(arr, k);
	return 0;
}

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

int main() {
  int a,i,b=0,c=0;
  cin>>a;
  vector<int> vec(a);
  for(i=0;i<a;i++){
    cin>>vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());

  for (int i = 0; i < a; i++) {
      if(i%2==0)
        c+=vec.at(i);
      else
        b+=vec.at(i);
  }
  cout<<c-b;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=1;i<=n;++i)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  cout << (a+b)%24 << endl;
  return 0;
}


Measured memory_bytes: 256
program OE1H
    implicit none
    integer(8)::N,i
    integer(8)::result
    integer(8)::A_sum=0
    integer(8)::snuke=0
    integer(8),allocatable,dimension(:)::A

    read(5,*)N
    allocate(A(N))
    read(5,*)(A(i),i=1,N)

    do i=1,N
        A_sum=A_sum+A(i)
    end do

    do i=1,N-1
        snuke=snuke+A(i)
        A_sum=A_sum-A(i)
        if(i==1)then
            result=abs(snuke-A_sum)
        else if(abs(snuke-A_sum)<result)then
            result=abs(snuke-A_sum)
        end if
    end do
    print'(i0)',result
end program OE1H

Measured memory_bytes: 2304
#include<iostream>

using namespace std;
int main()
{
  int s,hh,mm,ss;
  cin>>s;
  hh = s / 3600;
  mm =s % 3600 / 60;
  ss = s % 3600 % 60;
 
  cout << hh << ':' << mm << ':' << ss << endl;
}

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

using namespace std;

#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define f first
#define s second

typedef long long ll;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

int main(){ _

	int n; cin >> n;
	vector<ll> v(n);
	for(ll& i : v) cin >> i;

	vector<ll> memo(n+1);

	for(int sz=1; sz<=n; sz++) {
		for(int i=0; i<=n-sz; i++) {
			if(sz%2 == n%2) memo[i] = max(memo[i]+v[i+sz-1], memo[i+1]+v[i]);
			else memo[i] = min(memo[i]-v[i+sz-1], memo[i+1]-v[i]);
		}
	}

	cout << memo[0] << endl;

	return 0;
}


Measured memory_bytes: 3652
import sys
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

S = LS2()
s = len(S)

# 2文字か3文字だけ考えれば良い

for i in range(s-1):
    if S[i] == S[i+1]:
        print(i+1,i+2)
        exit()
for i in range(s-2):
    if S[i] == S[i+2]:
        print(i+1,i+3)
        exit()
print(-1,-1)

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

int n, k;
int memo[1010][1010];

int dp(int i, int j){
  if(i == n) return 1;
  if(memo[i][j] != -1) return memo[i][j];

  int ans = 0;
  for(int x = 0;x < k;x++){
    if(x != j){
      ans += dp(i+1, x);
    }
  }

  return memo[i][j] = ans;
}

int main(){
  cin >> n >> k;
  memset(memo,-1,sizeof(memo));

  int ans = 0;
  for(int i = 0;i < k;i++){
    ans += dp(1, i);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4224
//
//  main.cpp
//  atcoder
//
//  Created by cfhaiteeh on 11/03/2018.
//  Copyright © 2018 cfhaiteeh. All rights reserved.
//

#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#define LL long long
using namespace std;
LL n,m;
LL ans;
int main() {
    while(scanf("%lld%lld",&n,&m)!=EOF){
        ans=0;
        if(m==0){
            ans=n;
            for(int i=2;i<=n;i++){
                LL p=n/i;
                ans+=p;
            }
            m=1;
        }
       
        
            for(LL i=m+1;i<=n;i++){
                LL p=n/i;
                LL q=(n%i)-m+1;
                if(q<0)q=0;
                LL z=i-m;
                ans=ans+z*(p)+q;
                
            }
            printf("%lld\n",ans);
        
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define takeline cin.ignore();
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
int main(){
	
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll a,b,c,d;
	cin>>a>>b>>c>>d;

	ll t=(b-a+1);
	ll c1=(b/c)-((a-1)/c);
	ll c2=(b/d)-((a-1)/d);
	ll g=(c*d)/__gcd(c,d);
	ll c3=(b/g)-((a-1)/g);
	//cout<<c1<<" "<<c2<<" "<<c3<<endl;
	cout<<(t-c1-c2+c3);
	return 0;
}


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

ll inf=1ll<<60;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n;
	cin>>n;
	if (n>=64){
		cout<<"64";
	}
	else if (n>=32){
		cout<<"32";
	}
	else if (n>=16){
		cout<<"16";
	}
	else if (n>=8){
		cout<<"8";
	}
	else if (n>=4){
		cout<<"4";
	}
	else if (n>=2){
		cout<<"2";
	}
	else{
		cout<<"1";
	}
	return 0;
}

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

const int maxn =1e5+5;
vector<pair<ll,ll>> v;
ll ksm(ll a,ll b)
{
    ll ans=1;
    for(; b; b>>=1,a*=a) if(b&1) ans*=a;
    return ans;
}
int main()
{
    ios::sync_with_stdio(false);
    //cout<<ksm(2,5);
    ll x;
    cin>>x;
    v.push_back({0,0});
    for(ll i=1; i<=1000; i++)
    {
        v.push_back(pair<ll,ll>(i,ksm(i,5)));
        v.push_back(pair<ll,ll>(-1ll*i,-1ll*ksm(i,5)));
    }
    for(int i=0; i<v.size(); i++)
        for(int j=0; j<v.size(); j++)

        {
            ll t1=v[i].second,t2=v[j].second;
            if(t1-t2==x)
        {
            cout<<v[i].first<<" "<<v[j].first<<endl;return 0;
        }

        }


    return 0;
}


Measured memory_bytes: 3708
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;
const ll LINF=(ll)1e18;

struct LazySegmentTree{
private:
    int n;
    vector<ll> node,assign,add;
public:
    LazySegmentTree(int sz){
        n=1;
        while(n<sz)n*=2;
        node.resize(2*n-1);
        assign.resize(2*n-1,LINF);
        add.resize(2*n-1);
    }
    void eval(int k,int l,int r){
        if(assign[k]!=LINF){
            node[k]=assign[k];
            if(r-l>1){
                assign[2*k+1]=assign[2*k+2]=assign[k];
                add[2*k+1]=add[2*k+2]=0;
            }
            assign[k]=LINF;
        }
        if(add[k]!=0){
            node[k]+=add[k];
            if(r-l>1){
                if(assign[2*k+1]!=LINF){
                    assign[2*k+1]+=add[k];
                }
                else{
                    add[2*k+1]+=add[k];
                }
                if(assign[2*k+2]!=LINF){
                    assign[2*k+2]+=add[k];
                }
                else{
                    add[2*k+2]+=add[k];
                }
            }
            add[k]=0;
        }
    }
    void update(int a,int b,int q,ll x,int k=0,int l=0,int r=-1){
        if(r==-1)r=n;
        eval(k,l,r);
        if(b<=l||r<=a)return;
        if(a<=l&&r<=b){
            if(q==0){
                assign[k]=x;
            }
            else{
                add[k]=x;
            }
            eval(k,l,r);
        }
        else{
            update(a,b,q,x,2*k+1,l,(l+r)/2);
            update(a,b,q,x,2*k+2,(l+r)/2,r);
            node[k]=max(node[2*k+1],node[2*k+2]);
        }
    }
    ll get(int a,int b,int k=0,int l=0,int r=-1){
        if(r==-1)r=n;
        eval(k,l,r);
        if(b<=l||r<=a)return 0LL;
        if(a<=l&&r<=b){
            return node[k];
        }
        else{
            return max(get(a,b,2*k+1,l,(l+r)/2),get(a,b,2*k+2,(l+r)/2,r));
        }
    }
};

int main(){
    int n,m;
    cin>>n>>m;
    pair<int,pair<int,ll>> p[m];
    for(int i=0;i<m;i++){
        int l,r;
        ll a;
        cin>>l>>r>>a;
        p[i]={r,{l-1,a}};
    }
    sort(p,p+m);
    LazySegmentTree dp(n);
    for(int i=0;i<m;i++){
        int l=p[i].second.first;
        int r=p[i].first;
        ll a=p[i].second.second;
        dp.update(l,r,1,a);
        ll mx=max(dp.get(0,r),0LL);
        if(r!=n)dp.update(r,n,0,mx);
    }
    cout<<max(dp.get(0,n),0LL)<<endl;
}

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

#define ll long long
#define sd(x) scanf("%d", &(x))
#define pii pair<int, int>
#define F first
#define S second
#define all(c) ((c).begin()), ((c).end())
#define sz(x) ((int)(x).size())
#define ld long double

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<", "<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	for(int i = 0;i < (int)v.size(); i++){
		if(i)os<<", ";
		os<<v[i];
	}
	os<<"}";
	return os;
}

#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

int getNext(int x, int n, string s){
	for(int i = x; i + 1 <= n; i++) if(s[i] == '#' && s[i + 1] == '#') return i;
	return n + 1;
}

int getPrev(int x, int n, string s){
	for(int i = x - 1; i >= 1; i--) if(s[i] == '#' && s[i + 1] == '#') return i;
	return -1;
}

int main(){
	cin.tie(0);
	int n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	string s; cin >> s;
	s = "!" + s;

	int p = getNext(a, n, s), q = getNext(b, n, s);
	int u = getPrev(c, n, s), v = getPrev(d, n, s);

	if(u >= a || v >= b){
		cout << "No\n"; return 0;
	}

	if(d > c){
		cout << "Yes\n";
		return 0;
	}

	for(int r = b; r <= d; r++){
		if(s[r] == '.' && s[r - 1] == '.' && s[r + 1] == '.'){
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";
	return 0;
}

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

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define EACH(begin, end) for(auto itr = (begin); itr != (end); itr++)

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;



ll N = 0;
vector<pair<ll, ll>> jobs;
ll ret = 0;

bool my_compare(pair<ll, ll> x, pair<ll, ll> y) {
  return x.second < y.second;
}

void input() {
  IN(N);
  ll a, b;
  REP(i, N) {
    IN(a);
    IN(b);
    jobs.pb(mp(a,b));
  }
}

void solve() {
  sort(ALL(jobs), my_compare);
  ll t = 0;
  bool ok = true;
  REP(i, N) {
    t += jobs[i].first;
    if (t > jobs[i].second) {
      ok = false;
      break;
    }
  }
  PRINT(ok?"Yes":"No");
}

int main(void){
  input();
  solve();
}


Measured memory_bytes: 6128
# Sort II - Quick Sort
class Card():
    def __init__(self,suit,num):
        """suit and num are str"""
        self.s = suit
        self.n = int(num)
    def __str__(self):
        return self.s + ' ' + str(self.n)

def partition(A,p,r):
    x = A[r].n
    i = p - 1
    for j in range(p,r,1):
        if A[j].n <= x:
            i += 1
            tmp = A[i]
            A[i] = A[j]
            A[j] = tmp
    tmp = A[i+1]
    A[i+1] = A[r]
    A[r] = tmp
    return i + 1
def quick_sort(A,p,r):
    if p < r:
        q = partition(A,p,r)
        quick_sort(A,p,q-1)
        quick_sort(A,q+1,r)
def is_stable(Org,A):
    cop = A[:]
    for org in Org:
        i = cop.index(org)
        if i > 0:
            if A[i - 1].n == org.n:
                return False
        del cop[i]
    return True
n = int(input())
A = [Card(*input().split()) for _ in range(n)]
Or = A[:]
quick_sort(A,0,len(A)-1)
if is_stable(Or,A): print('Stable')
else: print('Not stable')
for a in A: print(a)


Measured memory_bytes: 29728
P = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(P[K-1])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    string s;
    cin >> s;
    int n = s.length();
    int ans = 0;
    rep(i,n){
        if(s[i] == '1') ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3660
#1  insertionSort(A, n, g)
#2      for i = g to n-1
#3          v = A[i]
#4          j = i - g
#5          while j >= 0 && A[j] > v
#6              A[j+g] = A[j]
#7              j = j - g
#8              cnt++
#9          A[j+g] = v
#10
#11 shellSort(A, n)
#12     cnt = 0
#13     m = ?
#14     G[] = {?, ?,..., ?}
#15     for i = 0 to m-1
#16         insertionSort(A, n, G[i])
cnt = 0
def insertion_sort(a, n, g):
    global cnt
    for i in range(g, n):
        v = a[i]
        j = i - g
        while j >= 0 and a[j] > v:
            a[j+g] = a[j]
            j = j -g
            cnt += 1
        a[j+g] = v

n = int(input())
a = [int(input()) for i in range(n) ]


def shell_sort(a, n):

    g = [1]
    for i in range(99):
        if n < 1 + 3*g[-1]:
            break
        g.append(1 + 3*g[-1])
    m = len(g)
    print(m)
    
    g.reverse()
    print(*g)
    for i in range(0, m):
        insertion_sort(a, n, g[i])
    
    print(cnt)
    return a


shell_sort(a, n)
print(*a, sep="\n")


Measured memory_bytes: 53308
# unionfind木構造
# unionfindについてはここhttps://www.slideshare.net/chokudai/union-find-49066733
# グループに属するかの判定(find)や、グループ結合(union)に強い

from collections import defaultdict
class UnionFind:
    def __init__(self, n):
        class KeyDict(dict):
            # 辞書にないときの対応
            def __missing__(self,key):
                self[key] = key
                return key
        self.parent = KeyDict()
        self.rank = defaultdict(int)
        self.weight = defaultdict(int)

    # 根を探す
    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            # 経路圧縮
            # 自分自身じゃない場合は、上にさかのぼって検索(再帰的に)
            y = self.find(self.parent[x])           
            self.weight[x] += self.weight[self.parent[x]]   #圧縮時にweightを更新(和)
            self.parent[x] = y      #親の置き換え(圧縮)
            return self.parent[x]

    # 結合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        # 低い方を高い方につなげる(親のランクによる)
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
        
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1

    ### 重み付き
    def weighted_union(self, x, y, w):
        # print("unite",x,y,w,self.weight)
        px = self.find(x)
        py = self.find(y)
        # 低い方を高い方につなげる(親のランクによる)
        # if px == py: return 0
        if self.rank[px] < self.rank[py]:
            self.parent[px] = py
            self.weight[px] = - w - self.weight[x] + self.weight[y]
        else:
            self.parent[py] = px
            self.weight[py] =  w + self.weight[x] - self.weight[y]
        if self.rank[px] == self.rank[py]:
            self.rank[px] += 1
        return 0

    # 判定
    def judge(self, x, y):
        return self.find(x) == self.find(y)

N = int(input())
As  = list(map(int, input().split()))
Bs  = list(map(int, input().split()))
As_ind = [(a,i) for i,a in enumerate(As)]
Bs_ind = [(b,i) for i,b in enumerate(Bs)]
As_ind.sort()
Bs_ind.sort()



uf = UnionFind(N)
cnt = 0
for A,B in zip(As_ind,Bs_ind):
    # print(A,B)
    if A[0] > B[0]:
        print("No")
        exit()
    uf.union(A[1],B[1])


d_ans = defaultdict(int)

for i in range(N):
    root = uf.find(i)
    d_ans[root] += 1
if len(d_ans) >= 2:
    print("Yes")
else:
    # サイクルが1つの場合
    # 巡回置換は、どこかをswapするとそこでcycleが分解されるので、swapしても結果に影響がないかを判断する
    # 具体的には A_p(i+1) <= B_i になっているならば、A_pi, A_p(i+1)をswapしても結果は変わらない。それを比べる。
    for i in range(1,N):
        if As_ind[i][0] <= Bs_ind[i-1][0]:
            print("Yes")
            exit()
    print("No")

Measured memory_bytes: 123312
//Author: Pakhomovee 
#include <iostream> 
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <chrono>

using namespace std;
using namespace std::chrono;

#define int long long

void solve()
{
    int n, m, x;
    cin >> n >> m >> x;
    vector<vector<int>> a(n, vector<int> (m, 0));
    vector<int> c(n);
    for(int i = 0; i < n; ++i)
    {
        cin >> c[i];
        for(int j = 0; j < m; ++j)
        {
            cin >> a[i][j];
        }
    }
    int mins = 1e9;
    for(int mask = 0; mask < (1 << n); ++mask)
    {
        int curr = 0;
        vector<int> gg(m, 0);
        for(int j = 0; j < n; ++j)
        {
            if (mask & (1 << j))
            {
                for(int i = 0; i < m; ++i)
                {
                    gg[i] += a[j][i];
                }
                curr += c[j];
            }
        }
        bool ok = true;
        for(int w : gg)
        {
            if (w < x)
            {
                ok = false;
            }
        }
        if (ok)
        {
            mins = min(mins, curr);
        }
    }
    if (mins != 1e9)
    {
        cout << mins << endl;
    }
    else
    {
        cout << -1 << endl;
    }
    
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	auto start = system_clock::now();

    solve();

	auto end = system_clock::now();
	cerr << "Time: " << duration_cast<milliseconds> (end - start).count() << "ms" << endl;
}

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

#define ll long long

int main() {
    int Q, H, S, D;
    cin >> Q >> H >> S >> D;
    Q *= 4;
    H *= 2;
    int N;
    cin >> N;
    int min1L = min(min(Q, H), S);
    ll sum = 0;
    if (N == 1) {
        sum = min1L;
    } else if (N % 2 == 0) {
        int min2L = min( (min1L * 2) , D );
        N /= 2;
        sum = (ll)min2L * N;
    } else {
        N--;
        int min2L = min( (min1L * 2) , D );
        N /= 2;
        sum = (ll)min2L * N;
        sum += min1L;
    }
    printf("%lld\n", sum);
}

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

int main(void){
  int a, b, t;
  cin >> a >> b >> t;

  int c = 0;
  for(int i = 1; i*a <= t; i ++){
    c += b;
  }

  cout << c << endl;

  return 0;
}


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

#define ll long long
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

// n ^ r % m
template <typename T> T mod_pow(T n, T r, T m)
{
	T ret = 1;
	T tmp = n;
	
	while(r != 0) {
		if(r % 2) {
			ret *= tmp;
		}
		tmp *= tmp;
		tmp %= m;
		ret %= m;
		r /= 2;
	}
	return ret;
}

// フェルマーの小定理より X / Y %(1e9+7) == X * Y^(1e9+7-2) % (1e9+7)
template <typename T> T mod_inv (T a, T m)
{
	return mod_pow(a, m - 2, m);
}

// a / b / m (m == 1e9+7とか)
template <typename T> T mod_div (T a, T b, T m)
{
	return a * mod_inv(b, m) % m;
}

// (a - b)%(1e9+7)
template <typename T> T mod_sub (T a, T b, T m)
{
	return (a < b) ? m + a - b : (a - b) % m;
}

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

int main()
{
	ll n, a, b;
	cin >> n >> a >> b;
	
    chmin(a,n-a);
    chmin(b,n-b);

	ll A = 1;
	ll B = 1;
	ll cmb = 1;
	
	for(ll i=1; i<=max(a, b); i++)
    {
		cmb = cmb * (n - i + 1) % MOD;
		cmb = mod_div(cmb, i, MOD); 
		
		if(i == a) A = cmb;
		if(i == b) B = cmb;
	}
	
	ll ans = mod_pow((ll)2, n, MOD) - 1;
	ans = mod_sub(ans, A, MOD);
	ans = mod_sub(ans, B, MOD);
	cout << ans << endl;
}


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

typedef long long ll;
typedef long double ld;
//#define int ll
//#define endl '\n'

// use unique(x) - removec consecutive items, returns vec.begin() + number of items
// for vector: sort(all(vec)); vec.erase(unique(all(vec)), vec.end());
// use iota(all(vec), 0) for filling a vector with 0,1,2...
// use fill(all(vec), 1) for filling a vector with 1,1,1...
// use rotate(vec.begin(), vec.begin() + 1, vec.end()) to rotate a vector | middle arg becomes first
// print number in binary -> cout << bitset<20>(n);

const int N=100100;
int n,m;
int res[N],got[N];
set<int>in[N]; // is, building
vector<int>out[N],pref[N],suf[N];

main(){
	cin.tie(0);cin.sync_with_stdio(0);
	cin>>n>>m;
	if(n==1){
		cout<<1<<endl;
		return 0;
	}
	for(int i=0;i<n-1;++i){
		int u,v;cin>>u>>v;--u;--v;
		in[u].insert(v);
		in[v].insert(u);
	}
	queue<int>q;
	for(int i=1;i<n;++i)if(in[i].size()<=1)q.push(i);
	while(!q.empty()){
		int u=q.front();q.pop();
		if(!u&&q.size()){
			q.push(u);continue;
		}else if(!u)break;
		int v=*in[u].begin();
		ll res=1;
		for(auto val:pref[u])res=res*val%m;
		res=(res+1)%m;
		out[v].push_back(u);
		pref[v].push_back(res);
		suf[v].push_back(res);
		in[v].erase(u);
		if((v&&in[v].size()==1)||(!v&&in[v].empty()))q.push(v);
	}
	q.push(0);
	while(!q.empty()){
		int u=q.front();q.pop();
		int n=out[u].size();
		for(int i=1;i<n;++i){
			pref[u][i]=(ll)pref[u][i]*pref[u][i-1]%m;
			suf[u][n-i-1]=(ll)suf[u][n-i-1]*suf[u][n-i]%m;
		}
		res[u]=suf[u][0];
		for(int i=0;i<n-!!u;++i){
			ll last=1;
			if(i)last*=pref[u][i-1];
			if(i!=n-1)last=last*suf[u][i+1]%m;
			last=(last+1)%m;
			int v=out[u][i];
			out[v].push_back(u);
			pref[v].push_back(last);
			suf[v].push_back(last);
			q.push(v);
		}
	}
	for(int i=0;i<n;++i)cout<<res[i]<<" ";cout<<endl;	
}


Measured memory_bytes: 32544
<?php
error_reporting(0);
$stdin = file_get_contents('php://stdin');
$line = explode("\n",$stdin);
$fi = 0;
$cnt = 0;
$list = array();
$key = new stdclass();
foreach($line as $l) {
  if (empty($l)) continue;
  if ($fi == 0) {
    $a = explode(" ",$l);
    $key->N = $a[0];
    $fi++;
    continue;
  }
  if ($fi > 0) {
    $a = explode(" ",$l);
    $key->A=$a;
  }
}
$m = max($key->A);
$n = min($key->A);
if ($m == $n) {
  printf("0\n");
  exit;
}
$cost = 99999999;
for($i=$n;$i<=$m;$i++) {
  $cost = min(getcost($i,$key->A),$cost);
}
printf("%d\n",$cost);
function getcost($i,$a) {
  $res = 0;
  foreach($a as $n) {
    $res += pow(($n-$i),2);
  }
  return $res;
}


Measured memory_bytes: 3832
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main(int argc, char const *argv[]) {
  int N;
  cin >> N;
  vector<long double> x(N);
  vector<string> u(N);
  long double sum = 0;
  for (size_t i = 0; i < u.size(); i++) {
    cin >> x[i] >> u[i];
    if (u[i] == "JPY") {
      sum += x[i];
    } else {
      sum += x[i] * 380000.0;
    }
  }
  cout << sum << endl;
  return 0;
}


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


#define mx 1005
#define ll long long 
#define inf 10000000

void IO()
{
  #ifndef ONLINE_JUDGE
  freopen("in.txt","r",stdin);
  freopen("out.txt","w",stdout);
  #endif
}


int ar[mx];
char ch[mx][mx],ch1[mx][mx];
int dis[mx][mx];
int m,n,k,ii;

int xx[]={1,-1,0,0};
int yy[]={0,0,1,-1};
int xxx[]={1,-1,2,-2,0,0,0,0,1,2,-1,-2,1,2,-1,-2,-1,-2,1,2,-1,-2,1,2};
int yyy[]={0,0,0,0,1,-1,2,-2,1,2,-1,-2,-1,-2,1,2,-2,-1,2,1,2,1,-2,-1};


bool chk(int x,int y)
{
  if(x>0 && x<=n && y>0 && y<=m && ch[x][y]=='.')return true;
  return false;
}

void bfs(int x,int y)
{

  dis[x][y]=0;
  priority_queue<pair<int,pair<int,int>>>q;
  q.push({0,{x,y}});
  while(!q.empty())
  {
    //  k++;
      int val=q.top().first;
      val*=-1;
      x=q.top().second.first;
      y=q.top().second.second;
      q.pop();
      if(dis[x][y]<val)continue;
      for(int i=0;i<4;i++)
      {
         int temx=x+xx[i];
         int temy=y+yy[i];
         if(chk(temx,temy)==false)continue;
         if(dis[temx][temy]>dis[x][y])
         {
           dis[temx][temy]=dis[x][y];
           q.push({-dis[x][y],{temx,temy}});
         }
      }
      for(int i=0;i<24;i++)
      {
        int temx=x+xxx[i];
        int temy=y+yyy[i];
        if(chk(temx,temy)==false)continue;
        if(dis[temx][temy]>dis[x][y]+1)
        {
           dis[temx][temy]=dis[x][y]+1;
           q.push({-dis[x][y],{temx,temy}});
        }
      }
  }
}


void solve()
{
    scanf("%d%d",&n,&m);
    int x,y,st,en;
    scanf("%d%d%d%d",&x,&y,&st,&en);
    for(int i=0;i<n;i++)scanf("%s",ch1[i]);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
          {
            ch[i][j]=ch1[i-1][j-1];
            dis[i][j]=inf;
         // cout<<ch[i][j];
        }
        //cout<<endl;
    }

    if(ch[x][y]=='.')bfs(x,y);
    if(dis[st][en]==inf)printf("-1\n");
    else printf("%d\n",dis[st][en] );
    //for(int i=0;i<24;i++)printf("%d %d\n",xxx[i],yyy[i]);
   // cout<<k<<endl;
}

int main()
{
  IO();
  int t=1;
  while(t--)
  {
      solve();

   
  }
  return 0;
}

Measured memory_bytes: 9628
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    int N;
    cin >> N;
    int L, R;
    string s;
    auto func = [](const string& str) -> int {
        if(str == "Vacant") exit(0);
        if(str == "Male")   return 0;
        else    return 1;
    };
    cout << 0 << '\n' << flush;
    cin >> s;
    L = func(s);
    cout << N - 1 << '\n' << flush;
    cin >> s;
    R = func(s);
    int lb = 0, ub = N - 1;
    while(ub - lb > 1){
        int mid = (lb + ub) / 2;
        int M;
        cout << mid << '\n' << flush;
        cin >> s;
        M = func(s);
        if((mid - lb) & 1){
            if(L == M){
                ub = mid;
                R = M;
            }
            else{
                lb = mid;
                L = M;
            }
        }
        else{
            if(L != M){
                ub = mid;
                R = M;
            }
            else{
                lb = mid;
                L = M;
            }
        }
    }
    cout << lb << '\n' << flush;
    cin >> s;
    L = func(s);
    cout << ub << '\n' << flush;
    cin >> s;
    L = func(s);
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
static const int INF (1<<30);

int main() {
  int N;
  cin >> N;
  vector<pair<int, int> > job(N);

  rep(i, N) cin >> job[i].second >> job[i].first;

  sort(all(job));

  long long time = 0;
  rep(i, N) {
    time += job[i].second;
    if (time > job[i].first) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;


  return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int Y[]={0,1,0,-1};
int X[]={1,0,-1,0};
int main(){
  int h,w,i,j,k,y[410*410],x[410*410],ny,nx,t,r,f[410][410]={};
  long long a,b,c=0;
  char s[410][410]={};
  scanf("%d %d",&h,&w);
  for(i=0;i<h;i++)scanf(" %s",s[i+1]+1);
  for(i=1;i<=h;i++){
    for(j=1;j<=w;j++){
      if(f[i][j])continue;
      a=b=0;
      f[y[t=0]=i][x[0]=j]=1;
      for(r=1;r-t;t++){
	if(s[y[t]][x[t]]=='.')a++;
	else                  b++;
	for(k=0;k<4;k++){
	  ny=y[t]+Y[k];
	  nx=x[t]+X[k];
	  if(f[ny][nx]==1)continue;
	  if(s[ny][nx]+s[y[t]][x[t]]-'#'-'.')continue;
	  f[y[r]=ny][x[r]=nx]=1;
	  r++;
	}
      }//printf("%d %d\n",a,b);
      c+=a*b;
    }
  }
  printf("%lld\n",c);
  return 0;
}


Measured memory_bytes: 2304
#include <stdio.h>

int main(void) {
	int w,h,x,y,r;
	scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
	if(x-r>=0&&y-r>=0&&x+r<=w&&y+r<=h){
		printf("Yes\n");
	}else {
		printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 1712
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }

void main() {
  auto N = readln.chomp.to!int;
  auto A = readln.chomp.map!(c => cast(int)(c - '1')).array;

  int solve() {

    bool isOddTriangle(T)(long N, T arr) {
      bool isOdd;
      foreach(i, a; arr) {
        if (a != 1) continue;

        auto k = i;
        if ((N & k) == k) isOdd ^= true;
        debug [N, k, N&k, isOdd].writeln;
      }
      return isOdd;
    }
    
    if (isOddTriangle(N-1, A)) return 1;
    if (A.any!(a => a == 1)) return 0;
    
    return isOddTriangle(N-1, A.map!"a/2".array) ? 2 : 0;
  }

  solve().writeln();
}


Measured memory_bytes: 15784
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
const int MAXN=1e5+10;
ll a[MAXN],n,ans;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)  scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	ans=a[n]-a[1];
	for (int i=2;i<=n/2;i++) ans+=a[n-i+2]-a[i]+a[n-i+1]-a[i-1];
	if (n&1) ans+=max(a[n/2+1]-a[n/2],a[n/2+2]-a[n/2+1]);
	printf("%lld\n",ans);
}

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


int main() {
  int n, m, a;
  int sum = 0;
  int ans;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a;
    sum += a;
  }
  ans = n - sum;
  if (ans < 0) ans = -1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3592
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] array= new int[N];
    for(int i = 0; i < N; i++){
      array[i] = sc.nextInt();
    }
    int sum = 0;
    double ave = 0L;
    for(int i : array){
      sum += i;
    }
    ave = (double)sum / N;
    double min = 10000;
    int minIndex = -1;
    for(int i = 0; i < N; i++){
      double tmp = Math.abs(ave - array[i]);
      if(min > tmp){
        min = tmp;
        minIndex = i;
      }
    }
    System.out.println(minIndex);
  }
}

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

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

  int n;
  cin>>n;
  string s = to_string(n);
  bool ans = false;
  for(int i=0; i<(int)s.size(); i++){
    if(s[i]=='7'){ans =true;break;}
  }

  if(ans)cout<<"Yes\n";
  else cout<<"No\n";

  return 0;
}


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

int main() {
    int K, S;
    cin >> K >> S;
    int pattern = 0;

    for (int x=0; x<=K; ++x) {
        for (int y=0; y<=K; ++y) {
            int z = S - (x + y);
            if ((z >= 0) && (z <= K)) {
                ++pattern;
            }
        }
    }
    cout << pattern << endl;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
using namespace std;

#define M 1000000

int odd[M + 10], all[M + 10];

void update(int *a, int x){
    for(int i = x; i <= M; ++i){
        a[i] = min(a[i], a[i - x] + 1);
    }
}

int main(){
    for(int i = 1; i <= M; ++i){
        odd[i] = all[i] = 10000000;
    }

    for(int i = 1; ; ++i){
        int x = i * (i + 1) * (i + 2) / 6;
        if(x > M){ break; }
        update(all, x);
        if(x % 2){ update(odd, x); }
    }

    int n;
    while(cin>>n, n){
        printf("%d %d\n", all[n], odd[n]);
    }
}

Measured memory_bytes: 10932
x, y = map(int, input().split())

diff = abs(y) - abs(x)

if y == 0:
    if x <= 0:
        print(-x)
        exit()
    if x >= 0:
        print(x + 1)
        exit()

result = 0
if (x >= 0) == (y >= 0):
    if x < 0 and diff > 0:
        result = 2
    if x >= 0 and diff < 0:
        result = 2
else:
    result = 1
if diff < 0:
    diff *= -1
print(result + diff)



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

    typedef long long ll;
    typedef long double ld;
    ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
    ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
    #define endl '\n'
    #define max3(a,b,c) max(a,max(b,c))

    const int q = 1e9+9;




    int main()
    {
        int a,b;
        cin>>a>>b;
        if(a>12) cout<<b<<endl;
        else if(a>=6) cout<<b/2<<endl;
        else cout<<0<<endl;



        return 0;
    }
        // gotcha;


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

using namespace std;

int main(void)
{
  string s;
  string tmp;
  string bef,aft;
  int res=0;

  cin>>s;

  if(s.size()%2==0)
  {
    s.pop_back();
    s.pop_back();
  }
  else
  {
    s.pop_back();
  }

  for(int i=s.size();i>0;i-=2)
  {
    for(int j=0;j<i;j++)
    {
      tmp+=s[j];
    }

    bef = tmp.substr(0,tmp.size()/2);
    aft = tmp.substr(tmp.size()/2);

    if(bef==aft)
    {
      cout<<i<<endl;
      break;
    }
    tmp="";
    bef="";
    aft="";
  }
}

Measured memory_bytes: 256
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define fi first
#define se second
#define pii pair<int, int>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

signed main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == 0) {
      cout << "0\n";
      return 0;
    }
  }
  int res = 1;
  for (int i = 0; i < n; i++) {
    if (res <= 1e18 / a[i] && res * a[i] <= (int) pow(10, 18)) {
      res *= a[i];
    } else {
      cout << "-1\n";
      return 0;
    }
  }
  cout << res << "\n";
}



Measured memory_bytes: 4436
#include <bits/stdc++.h>
using namespace std;
#define QOEINDIEDIS freesteed
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int N, M, K, p[20][1010],res=1010;
char s[15][1005];
inline int sum(int L1,int R1,int L2,int R2){
    return  p[L2][R2] + p[L1 - 1][R1 - 1] - p[L1 - 1][R2] - p[L2][R1 - 1] ;
}
inline void solve(){
	scanf("%d%d%d",&N,&M,&K);
	rep(i,0,N){
		scanf("%s",&s[i]);
		rep(j,0,M)if(s[i][j]=='1')p[i+1][j+1] = 1;
	}
	for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) p[i][j] += p[i][j - 1]; }
    for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) p[i][j] += p[i - 1][j]; }
	for(int bits = 0 ;bits<(1<<(N-1));bits++){
		if(__builtin_popcount(bits)>=res)continue;//剪枝 7ms ~ 3ms 
		VI cut;for(int i=0;i<N-1;i++)if((bits>>i)&1)cut.pb(i+1);cut.pb(N);	
		int  pcol = 1,ans=sz(cut)-1,ok = 1;
		for(int i=1;i<=M;i++){
			int f=1,prow=1;
			for(int j=0;j<sz(cut);j++){
				if(sum(prow,pcol,cut[j],i)>K){
					f = 0;
					break;
				}
				prow = cut[j]+1;
			}
			if(!f){
				ans++;
				if(ans>=res||pcol==i){//剪枝 3ms ~ 2ms 
					ok = 0;
					break;
				}
				pcol = i;
			}
		}
		if(ok)res = min(res,ans);
	}
	printf("%d\n",res);
}
int main() {
	solve();
  	return 0;
}

Measured memory_bytes: 256
N = int(input())
D = list(map(int, input().split()))
D.sort()
M = int(input())
T = list(map(int, input().split()))
T.sort()

while len(T) > 0:
    t = T.pop()
    flag = True
    while flag:
        if len(D) <= 0:
            print("NO")
            exit()
        d = D.pop()
        if d == t:
            flag = False
        elif d < t:
            print("NO")
            exit()
        else:
            continue

print("YES")

Measured memory_bytes: 35420
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  // ll n;
  // cin >> n;
  // ll n, m;
  // cin >> n >> m;
  ll r, g, b, n;
  cin >> r >> g >> b >> n;
  fi(0, (n / r) + 1)
    fj(0, (n / g) + 1)
      if(n - i * r - j * g >= 0 && (n - i * r - j * g) % b == 0)
        ans++;
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int te,i,a=0,w=0,t=0,r=0;
   string str;
   cin>>te;
   for(i=1;i<=te;i++)
   {
       cin>>str;
       if(str=="AC") a++;
       if(str=="WA") w++;
       if(str=="TLE") t++;
       if(str=="RE") r++;
}
cout<<"AC x "<<a<<endl;
cout<<"WA x "<<w<<endl;
cout<<"TLE x "<<t<<endl;
cout<<"RE x "<<r<<endl;
}


Measured memory_bytes: 3628
import java.util.*;


public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();

    boolean result = false;

    if(Math.abs(a - c) <= d){
      result = true;
    }
    if(Math.abs(a - b) <= d && Math.abs(b - c) <= d ){
      result = true;
    }

    System.out.println(result ? "Yes" : "No");

  }
}


Measured memory_bytes: 21844
//package solution;

import java.io.*;
import java.util.*;
import java.math.*;
import java.awt.Point;

public final class Main {
    BufferedReader br;
    StringTokenizer stk;

    public static void main(String[] args) throws Exception {
        new Main().run();
    }
    
    {
        stk = null;
        br = new BufferedReader(new InputStreamReader(System.in));
    }
    
    void run() throws Exception {
        int n = ni(), k = ni();
        long[] a = new long[n];
        for(int i=0; i<n; i++) a[i] = nl();
        
        long[] dp = new long[n];
        dp[0] = 0;
        for(int i=1; i<n; i++) {
            long min = Integer.MAX_VALUE;
            for(int j=Math.max(0, i-k); j<i; j++) {
                min = Math.min(dp[j] + Math.abs(a[i] - a[j]), min);
            }
            dp[i] = min;
        }
        
        pl(dp[n - 1]);
    }
    
    //Reader & Writer
    String nextToken() throws Exception {
        if (stk == null || !stk.hasMoreTokens()) {
            stk = new StringTokenizer(br.readLine(), " ");
        }
        return stk.nextToken();
    }

    String nt() throws Exception {
        return nextToken();
    }

    String ns() throws Exception {
        return br.readLine();
    }

    int ni() throws Exception {
        return Integer.parseInt(nextToken());
    }

    long nl() throws Exception {
        return Long.parseLong(nextToken());
    }

    double nd() throws Exception {
        return Double.parseDouble(nextToken());
    }

    void p(Object o) {
        System.out.print(o);
    }

    void pl(Object o) {
        System.out.println(o);
    }
    
    void selector() {
        Random rd = new Random();
        String[] s = new String[] {"Strings", "Sorting", "Search"
                , "Graph theory", "Greedy", "Dynamic programming"
                , "Constructive algos", "Bit manipulation", "Recursion"};
        pl(s[rd.nextInt(s.length)] + " " + (rd.nextInt(5)+1));
    }
}

Measured memory_bytes: 36756
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int K=scan.nextInt();
        String N=scan.next();
        String append="...";
        if(N.length()<=K){
            System.out.println(N);
        }
        else if(N.length()>K){
            for(int i=0; i<K;i++){
                System.out.print(N.charAt(i));
            }
            System.out.print(append);
        }
    }
}


Measured memory_bytes: 27032
#include <stdio.h>
#define MAX 1000000

int main(void){
  int prime[MAX];
  int i,j,n;

  prime[0]=prime[1]=0;
  for(i=2;i<MAX;i++)
    prime[i]=1;
  for(i=2;i*i<=MAX;i++){
    for(j=2;;j++){
      if(i*j > 999999)
	break;
      prime[i*j]=0;
    }
  }
  while(scanf("%d",&n) != EOF){
    int sum=0;
    for(i=2;i<=n;i++)
      sum+=prime[i];

    printf("%d\n",sum);
  }
  return 0;
}

Measured memory_bytes: 4500
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
 
int main(){
  int i,j,cnt;
  int n,m;
  cin>>n>>m;
  int a[n],b[n];
  for(i=0;i<n;i++)cin>>a[i]>>b[i];
  vector<pair<ll,ll>> v;
  for(i=0;i<n;i++)v.push_back({a[i],b[i]});
  sort(v.begin(),v.end());
  ll sum=0;
  for(i=0;i<n;i++){
    if(m>v[i].second){
      sum+=v[i].first*v[i].second;
      m-=v[i].second;
    }else{
      sum+=v[i].first*m;
      break;
    }
  }
  cout<<sum;
}

Measured memory_bytes: 3188