akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define Rep(i,n) for(int i=1; i<n; i++)
using namespace std;

int main() {
 int h,w,k;
 int ans=0;
 cin >>h >>w >>k;
 vector<vector<char>> G(h);
 int black_count =0;
 
 rep(i,h){
     rep(j,w){
         char ch;
         cin>>ch;
         if(ch=='#')black_count++;
         G[i].push_back(ch);
     }
 }
 
for(int i=0;i<(1<<h);i++){
    for(int j=0;j<(1<<w);j++){
        vector<vector<char>> tmp=G;
        int cnt=0;
        for(int y=0;y<h;y++){
            if(i&(1<<y)){
                rep(l,w){
                   if(tmp[y][l]=='#'){
                       cnt++;
                       tmp[y][l]='.';
                   }
                }
            }
        }
        
        for(int x=0;x<w;x++){
            if(j&(1<<x)){
                rep(m,h){
                   if(tmp[m][x]=='#'){
                       cnt++;
                       tmp[m][x]='.';
                   }
                }
            }
        }
        if(black_count-cnt==k)ans++;
    }
}
cout<<ans<<endl;
}


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

int main(){
    long long a,b,n;
    long long ans=0;
    cin >> a >> b >> n;
    if(b>=a){
        if(n>=b-1){
            ans = (a*(b-1))/b;
        }else{
            ans = (a*n)/b;
        }
    }else{
        if(n>=b-1){
            ans = (a*(b-1))/b;
        }else{
            ans = (a*n)/b;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;

class Progaram
{
    static void Main(String[] args)
    {
        var l = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
        var n = l[0]; var p = l[1];
        var a = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
        if (a.Length == a.Where(x => x % 2 == 0).ToArray().Length)
        {
            Console.WriteLine((p == 0) ? (Int64)Math.Pow(2, n) : 0);
        }
        else
        {
            Console.WriteLine((Int64)Math.Pow(2, n - 1));
        }
    }
}


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

const static ll MOD = (1e+9)+7;

ll modpow(ll a,ll n){
    if(n==0)return 1;
    if(n%2==1)return a*modpow(a,n-1)%MOD;
    ll t = modpow(a,n/2) % MOD;
    return t*t % MOD;
}

int main(){
    int h,w,k;cin>>h>>w>>k;
    vector<vector<int>> clr(h,vector<int>(w,-1));
    vector<vector<int>> mp(h,vector<int>(w,-1));
    vector<int> exist_cherry(h,-1);//行にイチゴがいるかメモっておく.
    rep(i,h){
        rep(j,w){
            char a;cin>>a;
            if(a=='#'){
                mp[i][j]=1;
                exist_cherry[i] = (exist_cherry[i] == -1 ? 1:exist_cherry[i]+1);
            }
            else mp[i][j]=0;
        }
    }
    int clr_ = 1;
    rep(i,h){
        rep(j,w){
            if(exist_cherry[i] == -1)continue;
            clr[i][j] = clr_;
            if(mp[i][j] == 1){
                if(exist_cherry[i] != 1){
                    //ラスト一個のいちごなら無視。
                    //そうでないならclrを増やす.
                    clr_++;
                    exist_cherry[i]--;
                }
            }
        }
        if(exist_cherry[i]!=-1)clr_++;
    }
    //次に、色のない場所の処理.
    rep(i,h){
        if(clr[i][0] != -1)continue;
        //ここは、色のないやつらの処理.
        if(i == 0){
            //もし一行目に色がないなら...。厄介.
            vector<int> clr_map(w,-1);
            rep(k,h){
                if(clr[k][0] == -1)continue;
                //始めて色のない場所を見つける.
                rep(s,w){
                    clr_map[s] = clr[k][s];
                    //メモメモ.
                }
                break;
            }
            //そして一行目に色塗り.
            rep(s,w){
                clr[i][s] = clr_map[s];
            }
        }else{
            // 1行目以外の処理です
            // あとは一つ上の色をパクるだけでおｋ。
            rep(s,w){
                clr[i][s] = clr[i-1][s];
            }
        }
    }
    rep(i,h){
        rep(j,w){
            cout<<clr[i][j]<<' ';
        }
        cout<<endl;
    }
    return 0;
}

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

int main()
{
    int N;
    cin>>N;
    vector<int> A(N);
    for (int &a: A)
        cin>>a;

    vector<int> T(1000001);
    for (int a: A)
        T[a]++;
    for (int i=1; i<=1000000; i++)
        if (T[i]>0)
            for (int j=i+i; j<=1000000; j+=i)
                T[j] = 0;
    for (int &t: T)
        if (t>=2)
            t = 0;
    int ans = 0;
    for (int t: T)
        ans += t;
    cout<<ans<<endl;
}


Measured memory_bytes: 7524
N, M = gets.split.map(&:to_i)

tp = []
tp2 = []

M.times do
  r = gets.split.map(&:to_i)
  if r[0] == 1
    tp << r[1]
  elsif r[0] == N
    tp2 << r[1]
  elsif r[1] == N
    tp2 << r[0]
  end
end

puts (tp & tp2).empty? ? 'IMPOSSIBLE' : 'POSSIBLE'


Measured memory_bytes: 11916
N,M = map(int,input().split())
ac = (N+1)*[0]
wa = (N+1)*[0]
pt = 0
for i in range(M):
  p,s = input().split()
  p = int(p)
  if ac[p] == 0 and s == "AC":
    ac[p] = 1
    pt += wa[p]
  wa[p] += 1
print(sum(ac),pt)  

Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define LLINF (1e18)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, a, b;
    cin >> x >> a >> b;
    int A = abs(x - a);
    int B = abs(x - b);
    if(A < B){
        cout << "A" << endl;
    }else{
        cout << "B" << endl;
    }
}

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

int main()
{
  int N;
  cin >> N;

  int zorome;
  int digit = N/100;
  zorome = digit*100 + digit*10 + digit;
  if(zorome>=N) {
    cout << zorome << endl;
    return 0;
  }
  digit++;
  zorome = digit*100 + digit*10 + digit;
  cout << zorome << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int H,W;
    cin >> H >> W;
    vector<string> A(H),A_(H+1);
    rep(i,H) {
        cin >> A[i];
        A_[i] = A[i] + '.';
    }
    rep(i,W+1) A_[H][i] = '.';
    int x=0,y=0;
    vector<string> ans;
    ans = A;
    rep(i,H){
        rep(j,W){
            ans[i][j]='.';
        }
    }
    ans[0][0]='#';
    while(1){
        if(A_[y][x+1]=='#'&&A_[y+1][x]=='#'){
            cout << "Impossible" << endl;
            return 0;
        }else{
            if(A_[y][x+1]=='#'){
                x++;
            }else if(A_[y+1][x]=='#'){
                y++;
            }else{
                cout << "Impossible" << endl;
                return 0;
            }
        }
        ans[y][x] = '#';
        if(x==W-1&&y==H-1){
            break;
        }
    }
    bool f = true;
    rep(i,H){
        if(ans[i]!=A[i]) f= false;
    }
    if(f) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#include<stdio.h>
#include<functional>
#include<queue>

using ll = long long;

using namespace std;

ll mod = 1e9 + 7;
//ll mod = 998244353;

ll n_pow(ll a, ll n) {
	if (n == 0)return 1;
	ll t = n_pow(a, n / 2);
	t *= t;
	//t %= mod;
	if (n % 2 == 1)t *= a;
	return t /*% mod*/;
}

//const int INF = 1001001001;
const ll INF = 1e18;

int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };

ll cal_gcd(ll a, ll b) {
	ll m = max(a, b);
	ll n = min(a, b);
	while (m%n != 0) {
		ll b = m % n;
		m = n;
		n = b;
	}
	return n;
}

vector<pair<ll, ll>> prime_factorize(ll N) {
	vector<pair<ll, ll>> res;
	for (long long a = 2; a * a <= N; ++a) {
		if (N % a != 0) continue;
		long long ex = 0;
		while (N % a == 0) {
			++ex;
			N /= a;
		}
		res.push_back({ a, ex });
	}
	if (N != 1) res.push_back({ N, 1 });
	return res;
}


int main() {
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	while (k > 0) {
		if (a >= b) {
			b *= 2;
		}
		else {
			c *= 2;
		}
		k--;
	}
	if (a < b&&b < c)cout << "Yes" << endl;
	else {
		cout << "No" << endl;
	}
	return 0;
}

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

using namespace std;
using VI = vector<int>;
using VPI = vector<pair<int, int>>;
using LL = long long;

#define FOR(a,n) for(int i=a;i<n;i++)
#define rFOR(a,n) for(int i=n-1;i>=a;i--)
#define IN(n,a) for(int i=0;i<n;i++) cin>>a[i]
#define pIN(n,t) for(int i=0;i<n;i++){int a,b; cin>>a>>b; t.emplace_back(a,b);}
#define SORT(a) sort(a.begin(), a.end())
#define ALL(a) a.begin(), a.end()

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

	if ((2 * b) >= a)cout << "0" << endl;
	else cout << a - (2 * b) << endl;
}

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

vector <ll> bam,boo;
ll n;

ll func(ll current,ll a,ll b,ll c){
	if (current == n){
		if (a == 0 || b == 0 || c == 0) return INT_MAX;
		return abs(boo[0]-a)+abs(boo[1]-b)+abs(boo[2]-c)-30;
	}
	ll a1 =func(current+1,a,b,c);
	ll a2 =func(current+1,a+bam[current],b,c)+10;
	ll a3 =func(current+1,a,b+bam[current],c)+10;
	ll a4 =func(current+1,a,b,c+bam[current])+10;
	return min(min(a1,a2),min(a3,a4));
}

int main(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
   	boo.resize(3);
   	cin >> n >> boo[0] >> boo[1] >> boo[2];
   	bam.resize(n);
   	for (int z=0;z<n;z++){
   		cin >> bam[z];
   	}
   	cout << func(0,0,0,0) << endl;
   	cin >> n;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

void solve(){
    int n;
    cin>>n;
    vector<pair<int,int>> pr(n,{0,0});
    int cnt=0;
    for(int i=0,x,y;i<n;i++){
        cin>>pr[i].first>>pr[i].second;
    }
    for(int i=0;i+2<n;i++){
        bool flag=true;
        for(int j=i;j<=i+2;j++) if(pr[j].first!=pr[j].second) flag=false;
        if(flag){
            cout<<"Yes\n";
            return;
        }
    }
    cout<<"No\n";
    return;

}

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

    solve();
    return 0;
}

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

int main() {
  int n;
  long long k;
  cin>>n>>k;
  vector<int> a(n);
  vector<bool> b(n,false);
  for(int &x: a) cin>>x;
  int memo=1,cnt=0;
  b[0]=true;
  vector<int> c;
  c.push_back(1);
  while(true){
    cnt++;
    memo=a[memo-1];
    c.push_back(memo);
    if(cnt==k) {cout<<memo<<endl; return 0;}
    if(b[memo-1]==true)  break;
    b[memo-1]=true;
  }
  int m=c.size(),mem,meme;
  for(int i=0;i<m;i++){
    if(c[i]==memo) {mem=(m-1)-i; meme=i; break;}
  }
   int l=(k-(m-1))%mem;
  cout<<c[meme+l]<<endl;
}
  

Measured memory_bytes: 5128
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds; 
//datatypes
	#define ll 			long long
	#define vi 			vector<int>
	#define vll 		vector<ll>
	#define si 			set<int>
	#define vii 		vector<ii>
	#define ii 			pair<int,int>
	#define vpll		vector<pll>
	#define pii 		pair<int,int>
	#define pll 		pair<ll, ll>
	#define mii 		map<int,int>
	#define ord_set		tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
	#define M 			1000000007
	#define narak 		998244353
	#define pi 			acos(-1)
	#define inf 		2147483647
	#define infl 		9223372036854775807
	#define infd 		1.7e308
	#define invd 		1.7e-308
	#define sz(x) 		(ll)x.size()
	#define fr 			first
	#define sc 			second
	#define pb 			push_back
	#define mkp 		make_pair
	#define rep(i,a,b) 	for(int i=a; i<b; ++i)
	#define rep0(i,a)	for(int i=0; i<a; ++i)
	#define rep1(i,a)	for(int i=1; i<=a; ++i)
	#define trav(a) 	for(auto &x:a)
	#define test 		cout<<"hello\n";
	#define all(x) 		(x).begin(),(x).end()
	#define mem(x,val)	memset(x, val, sizeof(x))
	#define sa(x) 		std::sort(all(x))
	#define endl 		'\n'
	#define __lcm(m,n) 	m*(n/__gcd(m,n))
	#define fill(a,n) 	for(int xxx=0;xxx<n;++xxx) cin>>(a)[xxx]
	#define maxa(v)		*(max_element(all(v)))
	#define mina(v)		*(min_element(all(v))
	#define inputFile 	freopen("input.txt", "r", stdin); 
	#define outputFile	freopen("output.txt", "w", stdout);
	#define disp(a) 	trav(a) cout<<x<<" "; cout<<endl;
  	#define int long long

template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }
template<typename T,typename U> std::ostream& operator<<(std::ostream& out, std::pair<T,U> a) {out<<a.fr<<" "<<a.sc; return out;}
template<typename T,typename U> std::istream& operator>>(std::istream& in, std::pair<T,U> &a) {in>>a.fr>>a.sc; return in;}
template<typename T> static inline void sd(vector<T> &x) {sort(all(x), greater<T>()) ; }

signed solve()
{
    int n, d, cnt=0;
    cin>>n>>d;
    rep(i,0,n){
    	int a,b;
    	cin>>a>>b;
    	if(a*a+b*b<=d*d)
    		cnt++;
    }
    cout<<cnt;
	return 0;
}

signed main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--)
	{
        
		solve();
        
	}
	//cout << "\nTime : " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 3648
import java.util.*;
import static java.lang.Math.*;
public class Main{
	final Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main().init();
	}
	void init(){
		new AOJ1182();
	}
	
	class AOJ1182{
		AOJ1182(){
			while(sc.hasNext()){
				n=sc.nextInt();
				m=sc.nextInt();
				c=sc.nextInt();
				s=sc.nextInt();
				g=sc.nextInt();
				if(n==0)	break;
				--s; --g;
				solve();
			}
		}
		int n,m,c,s,g;
		final int INF = 1<<29;
		int[] p;
		int[][] q,r;
		int[][][] map;
		void solve(){
			map=new int[n][n][c];
			for(int i=0; i<n; ++i)for(int j=0; j<n; ++j)for(int k=0; k<c; ++k)	map[i][j][k]=INF;
			for(int i=0; i<m; ++i){
				int x=sc.nextInt(),y=sc.nextInt(),d=sc.nextInt(),c=sc.nextInt();
				--x; --y; --c;
				map[x][y][c]=min(map[x][y][c], d);
				map[y][x][c]=min(map[y][x][c], d);
			}
			p=new int[c];
			for(int i=0; i<c; ++i)p[i]=sc.nextInt();
			
			q=new int[c][];
			r=new int[c][];
			for(int i=0; i<c; ++i){
				q[i]=new int[p[i]];
				r[i]=new int[p[i]];
				for(int j=0; j<p[i]-1; ++j)	q[i][j]=sc.nextInt();
				q[i][p[i]-1]=INF;
				for(int j=0; j<p[i]; ++j)	r[i][j]=sc.nextInt();
			}
			
			for(int l=0; l<c; ++l)for(int j=0; j<n; ++j)for(int i=0; i<n; ++i)for(int k=0; k<n; ++k)	map[i][k][l]=min(map[i][k][l], map[i][j][l]+map[j][k][l]);
			
			int[][] closed=new int[n][c];
			for(int i=0; i<n; ++i)for(int j=0; j<c; ++j)	closed[i][j]=INF;
			
			PriorityQueue<State> open = new PriorityQueue<State>();
			open.add(new State(s,s,-1,0));
			
			int ans=INF;
			while(!open.isEmpty()){
				State now=open.poll();
				if(now.p==g){
					ans=now.cost;
					break;
				}
				for(int i=0; i<n; ++i)for(int j=0; j<c; ++j){
					if(map[now.p][i][j]>=INF)	continue;
					if(now.c==j)	continue;
					int next = getCost(now.p, i, j);
					if(closed[i][j] <= now.cost+next)	continue;
					
					open.add(new State(i, now.p, j, now.cost+next));
					closed[i][j]=now.cost+next;
					
				}
			}
			System.out.println((ans>=INF? -1: ans));
		}
		int getCost(int from,int to,int c){
			int d=map[from][to][c],
				ret=0,
				idx=0;
			for(int i=1; i<=d; ++i){
				if(q[c][idx]<i)	++idx;
				if(idx>=p[c]-1){
					ret+=r[c][idx]*(idx>0?(d-q[c][idx-1]) :d);
					break;
				}else	ret+=r[c][idx];
			}
			return ret;
		}
		class State implements Comparable<State>{
			int p,b,c,cost;
			State(int p,int b,int c,int cost){
				this.p=p;
				this.b=b;
				this.c=c;
				this.cost=cost;
			}
			@Override public int compareTo(State o){
				return this.cost-o.cost;
			}
		}
	}
}

Measured memory_bytes: 70560
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

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

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

// ---------------------
#define INF 922337203685477580
typedef long long ll;

int main() {
  int N;
  cin >> N;
  int s[N];

  int sum = 0;
  REP(i, N) {
    cin >> s[i];
    sum += s[i];
  }
  sort(s, s + N);

  // dump(sum);

  if (sum % 10 == 0) {
    int i = 0;
    for (i = 0; i < N && s[i] % 10 == 0; i++) {
    }
    // dump(sum);
    // dump(i);
    // dump(N);
    if (i == N) {
      sum = 0;
    } else {
      sum -= s[i];
    }
  }

  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include<string.h>
#include<iomanip>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define ALLOF(c) (c).begin(), (c).end()
const ll mod=10e9+7;
ll ABS(ll a){return max(a,-a);}


int main(void){
    ll N,A,B;
    cin>>N>>A>>B;
    cout<<min(N*A,B)<<endl;
    return 0;
}


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

int main(void) {
    int N, K, sum=0, count=0;
    cin>>N>>K;
    //vector<int> vec_a(D);

    if((N%K)==0) {
        cout<<0<<endl;
        return 0;
    }

    cout<<1<<endl;
     return 0;
}


Measured memory_bytes: 256
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, m, x, y;
    cin >>n >>m;
    int l = INT_MIN, r = INT_MAX;
    while(m--){
        cin >>x >>y;
        l = max(l, x);
        r = min(r, y);
    }
    cout <<max(0, r - l + 1);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  int h,w;
  cin>>h>>w;
  std::map<char, int> map;
  for (int i = 0; i < h; ++i)
  {
    for (int j = 0; j < w; ++j)
    {
      char a;
      cin>>a;
      map[a]++;
    }
  }

  priority_queue<pair<int,char>> que;
  for(auto&& e: map) {
    que.push(make_pair(e.second,e.first));
  }
    


  if(h%2==0 && w%2==0){
    /*
    for(auto&& e: map) {
      if(e.second%4!=0){
        cout<<"No";
        return 0;
      }
    }
    cout<<"Yes";
    return 0;
    */
    for (int i = 0; i < (h*w)/4; ++i)
    {
      pair<int,char> tmp=que.top();
      que.pop();
      tmp.first-=4;
      if(tmp.first>0) que.push(tmp);
      else if(tmp.first<0) {
        cout<<"No";
        return 0;
      }
    }
    if(que.empty()) cout<<"Yes";
    else cout<<"No";
    return 0;
  }

//
  else if(h%2==0 || w%2==0){
    int even=(h%2==0? h:w);
    even/=2;
    for (int i = 0; i < (h*w-even*2)/4; ++i)
    {
      pair<int,char> tmp=que.top();
      que.pop();
      tmp.first-=4;
      if(tmp.first>0) que.push(tmp);
      else if(tmp.first<0){
        cout<<"No";
        return 0;
      }
    }
    for (int i = 0; i < even; ++i)
    {
      pair<int,char> tmp=que.top();
      que.pop();
      tmp.first-=2;
      if(tmp.first>0) que.push(tmp);
      else if(tmp.first<0){
        cout<<"No";
        return 0;
      }
    }
    if(que.empty()) cout<<"Yes";
    else cout<<"No";
    return 0;
  }

  int cnt_2=(w-1+h-1)/2;
  int cnt_1=1;
  int cnt_4=(h*w-cnt_2*2-cnt_1)/4;
  for (int i = 0; i < cnt_4; ++i)
  {
    pair<int,char> tmp=que.top();
    que.pop();
    tmp.first-=4;
    if(tmp.first>0) que.push(tmp);
    else if(tmp.first<0){
      cout<<"No";
      return 0;
    }
  }
  for (int i = 0; i < cnt_2; ++i)
  {
    pair<int,char> tmp=que.top();
    que.pop();
    tmp.first-=2;
    if(tmp.first>0) que.push(tmp);
    else if(tmp.first<0){
      cout<<"No";
      return 0;
    }
  }
  pair<int,char> tmp=que.top();
  que.pop();
  tmp.first-=1;
  if(tmp.first>0) que.push(tmp);
  else if(tmp.first<0) {
    cout<<"No";
    return 0;
  }

  if(que.empty()) cout<<"Yes";
  else cout<<"No";
} 

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

using namespace std;

int main() {
  long long n;
  long long soma = 0;

  cin >> n;
  long long aux = n;

  while(aux > 0) {
    soma += aux % 10;
    aux /= 10;
  }

  if(n % soma == 0) cout << "Yes\n";
  else cout << "No\n";

  return 0;
}

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

int main() {
  string s;
  cin >> s;
  if(s == "zyxwvutsrqponmlkjihgfedcba"){
    cout << -1 << endl;
    return 0;
  }
  vector<bool> used(26, false);
  int n = s.size();
  if(n < 26){
    rep(i,n){
      int a = s[i] - 'a';
      used[a] = true;
    }
    rep(i, 26){
      if(!used[i]){
        char c = i + 'a';
        s += c;
        cout << s << endl;
        return 0;
      }
    } 
  }
  vector<char> ve;
  rep(i,26){
    ve.push_back(s[i]);
  }
  if(next_permutation(ve.begin(), ve.end())){
    string t = "";
    rep(i, ve.size()){
      t += ve[i];
      if(s[i] != ve[i])break;
    }
    cout << t << endl;
    return 0;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-10;
const ll mod=1e9+7;
const vi emp;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,0,1,1,1},DY[8]={1,0,-1,1,-1,1,0,-1};

ll n,k;
vl a;

int main(){
	cin>>n>>k;
	a=vl(n);
	for(int i=0;i<n;i++) cin>>a[i];
	ll ans=0,sum=0,tmp=0;
	for(int i=0;i<k;i++) sum+=a[i];
	for(int i=k;i<n;i++) if(a[i]>0) tmp+=a[i];
	for(int i=0;i<=n-k;i++){
		ans=max(ans,max(sum,(ll)0)+tmp);
		sum+=a[i+k]-a[i];
		if(i==n-k) break;
		if(a[i+k]>0) tmp-=a[i+k];
		if(a[i]>0) tmp+=a[i];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
 
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;i<n;i++)
#define ll long long
 
#define pi pair < ll , ll >
#define pb push_back
#define mp make_pair
#define F first
#define S second
 
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
 
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
using namespace std;

void solve() {
    string s;
    ll n, i, j, k, ans=0;
    cin>>s;n=s.length();
    fo(i,n/2) {
        if(s[i]!=s[n-1-i])ans++;
    }
    cout<<ans;
}

int main()
{
    fastIO;ll t=1;
    // cin>>t;
    while(t--)solve();
}

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

#define INOTFILE freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define IOS std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define mp(x, y) make_pair(x, y)
#define FF first
#define SS second.first
#define TT second.second
#define per(n) setprecision(n)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define LB lower_bound
#define UB upper_bound
#define kill(x) return cout<<x, 0;
#define OT "output is : "
#define debug(x) cout << #x << " : " << (x) << endl
#define qrevint int,vector<int>,greater<int>
#define qrevpii pii, vector<pii>, greater<pii>
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef map<pii, int> mpi;
typedef pair<int, pair<int, int>> piii;
typedef long long ll;
typedef long double ld;
//#define int long long
//const ld PI = 3.14159265359;    
//const ld H = (sqrt(3.00))/2;
const ll INFLL=10000000000000010LL;
const int INF = 2*((1<<30)-1)+1, MOD = (1e9)+7;
const int MAXN = (1e5) + 1000;

int n, h[MAXN], dp[MAXN];

int32_t main(){IOS
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    dp[0] = 0, dp[1] = abs(h[0]-h[1]);
    for(int i = 2; i < n; i++){
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i-2]-h[i]));
    }
    cout << dp[n-1];    
/*	
*/ 
   
//cout << endl;
///*
return 0;   
}   


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

dp = [[0] * 2 for i in range(N+1)]

dp[0][1] = - 10 ** 18

for i in range(N):
    for j in range(2):
        if j == 0:
            dp[i+1][j] = max(dp[i][0] + A[i], dp[i][1] - A[i])
        else:
            dp[i+1][j] = max(dp[i][0] - A[i], dp[i][1] + A[i])

print(dp[N][0])

Measured memory_bytes: 25644
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    bool key[10] = {false};
    int n[4];
    for (int i = 0; i < 4; ++i) {
        cin >> n[i];
        key[n[i]] = true;
    }
    
    if (key[1] && key[9] && key[7] && key[4]) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

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

int main(){
	int N,K;
	cin >> N >> K;

	int count = 0 ;

	// printf("%d\n",N);
	// printf("%d\n",K);
	// cout << endl << N << " " << K;

	for(int i = 0; i < N; i++){
		int h;
		cin >> h;
		if(h >= K){
			count++;
		} 

	}

	cout << count << endl;
	return 0;
}

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

int main()
{
    long n;
    cin >> n;
    long long sum=0;
    long i;
    for(i=1;i<=n;i++){
        if(i%3!=0 && i%5!=0){
            sum+=i;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<utility>
#include<string>
#include<utility>
#include<iomanip>
#include<bitset>
#include<math.h>
using namespace std;

 
int main(){
 
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	
	if((abs(a-c)<=d) || (abs(a-b)<=d && abs(b-c)<=d)){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
  	
}

Measured memory_bytes: 256
//AOJ 0549 A Traveler
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int MAX_N=100001,MAX_M=100001;
int n, m, now, t[MAX_N], p[MAX_M], res = 0;
void solve(int plan){
	if (plan > 0){
const int INF = 100000000, MAX_N = 1000000, MAX_M = 1000000;
		for (int i = 0; i < plan; i++){
			res += t[now + i];
		}
	}
	else{
		for (int i = 0; i > plan; i--){
			res += t[now + i - 1];
		}
	}
	if (res >= 100000)
		res = res % 100000;
}
int main(){
	now = 1;
	res = 0;
	cin >> n >> m;
	for (int i = 1; i < n; i++){
		cin >> t[i];
	}
	for (int i = 1; i <= m; i++){
		cin >> p[i];
		solve(p[i]);
		now += p[i];
	}
	cout << res % 100000 << endl;
	return 0;
}

Measured memory_bytes: 1940
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int n,A,B,C,inf=1e9;
int l[8];

int min(int a,int b){
  if(a>b) return b;
  return a;
}

int func(int cur,int x,int y,int z){
  int r0,r1,r2,r3;
  if(cur==n && (x*y*z>0)) return abs(A-x) + abs(B-y) + abs(C-z) - 30;
  else if(cur==n) return inf;
  else{
    r0 = func(cur+1,x,y,z);
    r1 = func(cur+1,x+l[cur],y,z) + 10;
    r2 = func(cur+1,x,y+l[cur],z) + 10;
    r3 = func(cur+1,x,y,z+l[cur]) + 10;
    return min(r0,min(r1,min(r2,r3)));
  }
}

int main(void){
  int i;
  scanf("%d %d %d %d",&n,&A,&B,&C);
  for(i=0;i<n;i++) scanf("%d",&l[i]);
  printf("%d\n",func(0,0,0,0));
  return 0;
}

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



int main()
{
    int n, m;
    cin >> n >> m;
    ll csum[n + 1];
    csum[0] = 0;
    rep(i,n)
    {
        cin >> csum[i + 1];
        csum[i + 1] += csum[i];
    }

    map<int, int> cnt_map;
    rep(i, n + 1)
        cnt_map[csum[i] % m]++;

    ll ans = 0;
    for (auto mod_cnt: cnt_map)
    {
        int cnt = mod_cnt.second;
        if (cnt <= 1) continue;

        ans += (ll)cnt * (cnt - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3968
// In the name of God

#include <bits/stdc++.h>

using namespace std;

map<string, vector< pair<int,int> > > mp;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int n;
	cin >> n;
	for(int i=0; i<n; i++) {
		string s;
		cin >> s;
		int p;
		cin >> p;
		mp[s].push_back( make_pair(p, i+1) );
	}
	for(auto &v : mp) {
		sort(v.second.rbegin(), v.second.rend());
		for(auto &p : v.second) {
			cout << p.second << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
from functools import *
@lru_cache(maxsize=None) # memoization
def f(x):
  if x==0:return 0
  s=10000000000000000
  for u in [1]+[6**i for i in range(1,11)]+[9**i for i in range(1,11)]:
    if x-u>=0:
      s=min(s,f(x-u)+1)#min coins, coins dp
  return s
for i in range(1,100001):f(i)
print(f(int(input()))) # answer

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

int main(){
int N;
  cin >> N;
  int count = 0;
  vector<int> A(N);
  for(int i =0;i <N;++i)
    cin >> A[i];
  
  for(int i =0;i < N-2;++i){
  if(A[i] < A[i+1] && A[i + 1] < A[i+2])
    count++;
    else if(A[i] > A[i+1] && A[i + 1] > A[i+2])
  count++;
    
  }
cout << count << endl;

}

Measured memory_bytes: 256
a = list(input().split())

stack = []
for v in a:
    if not v.isdigit():
        y = stack.pop(len(stack)-1)
        x = stack.pop(len(stack)-1)
        if v == '+':
            stack.append(x + y)
        elif v == '-':
            stack.append(x - y)
        elif v == '*':
            stack.append(x * y)
        else:
            stack.append(x / y)

    else:
        try:
            stack.append(int(v))
        except ValueError:
            stack.append(float(v))

print('{}'.format(stack.pop(0)))



Measured memory_bytes: 5596
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 100000007
typedef long long ll;
using namespace std;

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


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    String[] S = new String[n];
    int[][] count = new int[n][26];
    int[] min = new int[26]; //各文字の最小出現回数
    for (int i =0; i<n; i++) {
      S[i] = sc.next();
      for (int j =0; j<S[i].length(); j++) {
        char x = S[i].charAt(j);
        count[i][(int)x-97]++;
      }
    }
    for (int i =0; i<26; i++) {
      min[i] = 50;
      for (int j =0; j<n; j++) {
        min[i] = Math.min(count[j][i],min[i]);
      }
      for (int k =0; k<min[i]; k++) {
        System.out.print((char)(97+i));
      }
    }
  }
}

Measured memory_bytes: 22740
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(sc.next());
        }

        // 主処理
        int remain = n - k;
        int result = (int) Math.ceil((double) remain / (k - 1)) + 1;

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 47048
N = int(input())
a = list(map(lambda x: int(x) // 400, input().split()))
s_a = []
over = 0

for i in range(N):
    if a[i] <= 7:
        s_a.append(a[i])
    else:
        over += 1

if len(s_a) == 0:
    min = 1
else:
    min = len(set(s_a))

max = len(set(s_a)) + over

print(min, max)

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


int main(){
    int n, m;
    cin >> n >> m;

    cout << (1900*m + 100*(n-m))*pow(2,m) << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main()
{
    
    
    
    /*int n,m;
    cin>>n>>m;
    if(n==m){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }*/
    
    
    
    
    int a,b;
    cin>>a>>b;
    
    if(a>b){
        for(int i=0;i<a;i++){
            cout<<b;
        }
    }else{
        for(int i=0;i<b;i++){
            cout<<a;
        }
    }
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 256
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0:
        cnt+=1
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

def cmb(n, r, mod):
  if ( r < 0 or r > n ):
    return 0
  r = min(r, n - r)
  return g1[n] * g2[r] * g2[n - r] % mod
 
MOD = 10 ** 9 + 7
SIZE = 10 ** 5 * 2 + 1
g1 = [1, 1]
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
 
for i in range(2, SIZE + 1 ):
  g1.append((g1[-1] * i) % MOD)
  inverse.append((-inverse[MOD % i] * (MOD // i) ) % MOD)
  g2.append((g2[-1] * inverse[-1]) % MOD)

N, M = map(int, input().split())

if M == 1:
  print(1)
  exit()

answer = 1
for p, a in factorization(M):
  answer = (answer * cmb(N - 1 + a, a, MOD)) % MOD

print(answer)

Measured memory_bytes: 80880
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;

struct Point {double x, y; };

void koch(int n, Point p1, Point p2)
{
    Point s, t, u;
    double th = M_PI * 60 / 180;

    s.x = (2.0 * p1.x + 1.0 * p2.x) / 3;
    s.y = (2.0 * p1.y + 1.0 * p2.y) / 3;
    t.x = (1.0 * p1.x + 2.0 * p2.x) / 3;
    t.y = (1.0 * p1.y + 2.0 * p2.y) / 3;
    u.x = s.x + (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th);
    u.y = s.y + (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th);

    if (n == 0)
        return;

    koch(n-1, p1, s);
    printf("%.8f %.8f\n", s.x, s.y);
    koch(n-1, s, u);
    printf("%.8f %.8f\n", u.x, u.y);
    koch(n-1, u, t);
    printf("%.8f %.8f\n", t.x, t.y);
    koch(n-1, t, p2);
}

int main()
{
    int n;
    Point p1, p2;

    scanf("%d", &n);

    p1.x = 0.0;
    p2.x = 100.0;
    p1.y = 0.0;
    p2.y = 0.0;

    printf("%.8f %.8f\n", p1.x, p1.y);
    koch(n, p1, p2);
    printf("%.8f %.8f\n", p2.x, p2.y);

    return 0;
}


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

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll oo = 1e8;
const double pi = 3.1415926535897;


const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}


typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;
typedef pair<int, int>             pii;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

struct edge{
    int from, to, w;

    edge(){}
    edge(int x, int y, int we): from(x), to(y), w(we){}

    bool operator < (const edge &rhs) const{
        return w > rhs.w;
    }

};

const int N = 2e5 + 5;
int A[N];

int main(){
    fIO
//    freopen("", "r", stdin);
//    freopen("", "w", stdout);

    int n;
    cin >> n;

    unordered_map<int, int> cnt;
    for(int i = 0; i < n; i++) {
        cin >> A[i];
        cnt[A[i]]++;
    }

    ll ans = 0;
    for(int i = 0; i < n; i++) {
        int tot = 0;
        for(int j = 1; j * j <= A[i]; j++) {
            if(A[i] % j == 0) {
                int f2 = A[i] / j;

                tot += cnt[j];
                if(f2 != j) tot += cnt[f2];
            }
        }
        tot --;
        if(tot == 0) ans++;
    }

    cout << ans;
}








Measured memory_bytes: 32464
n=int(input())
A=list(map(int,input().split()))
cnt=0
w=1000
for i in range(len(A)):
    if i!=len(A)-1:
        if A[i]<A[i+1]:
            cnt+=w//A[i]
            w=w%A[i]
        if A[i]>A[i+1]:
            w+=cnt*A[i]
            cnt=0
    else:
        w+=cnt*A[i]
print(max(n,w))


Measured memory_bytes: 9196
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define REP(i, a) for (int i(0), _##i(a); i < _##i; ++i)
#define FOR(i, a, b) for (int i(a), _##i(b); i <= _##i; ++i)

#ifdef LOCAL
#define _NTH_ARG(_1, _2, _3, _4, _5, _6, N, ...) N
#define _FE_1(_CALL, x) _CALL(x)
#define _FE_2(_CALL, x, ...) _CALL(x) _FE_1(_CALL, __VA_ARGS__)
#define _FE_3(_CALL, x, ...) _CALL(x) _FE_2(_CALL, __VA_ARGS__)
#define _FE_4(_CALL, x, ...) _CALL(x) _FE_3(_CALL, __VA_ARGS__)
#define _FE_5(_CALL, x, ...) _CALL(x) _FE_4(_CALL, __VA_ARGS__)
#define _FE_6(_CALL, x, ...) _CALL(x) _FE_5(_CALL, __VA_ARGS__)
#define FOR_EACH_MACRO(MACRO, ...)                                             \
  _NTH_ARG(__VA_ARGS__, _FE_6, _FE_5, _FE_4, _FE_3, _FE_2, _FE_1)              \
  (MACRO, __VA_ARGS__)
#define watch(x) cerr << "\033[1;32m" #x " = \033[1;34m" << (x) << "\033[0m; ";
#define debug(...)                                                             \
  cerr << "\033[2;31mLine " << __LINE__ << ": \033[0m";                        \
  FOR_EACH_MACRO(watch, __VA_ARGS__)                                           \
  cerr << endl
#else
#define debug(...)
#endif

using namespace std;

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

template <class T, class = decltype(begin(declval<T>())),
          class = enable_if_t<!is_same<T, string>::value>>
ostream &operator<<(ostream &os, const T &c) {
  os << '[';
  for (auto it = begin(c); it != end(c); ++it)
    os << (it == begin(c) ? "" : ", ") << *it;
  return os << ']';
}
using ll = long long;

const int N = 2e5 + 5;

struct Seg {
  int n = 0;
  array<ll, N << 1> a{};

  Seg(int n) : n(n) {}

  void update(int idx, ll value) {
    idx += n;
    for (a[idx] = max(a[idx], value); idx > 1; idx >>= 1) {
      a[idx >> 1] = max(a[idx], a[idx ^ 1]);
    }
  }

  ll get(int l, int r) {
    ll res = 0;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1)
        res = max(res, a[l++]);
      if (r & 1)
        res = max(res, a[--r]);
    }
    return res;
  }
};

void solve() {
  int n;
  cin >> n;
  vector<pair<int, int>> a(n);
  REP(i, n) cin >> a[i].F;
  REP(i, n) cin >> a[i].S;

  Seg seg(n + 1);

  REP(i, n) {
    ll mx = seg.get(0, a[i].F);
    seg.update(a[i].F, mx + a[i].S);
  }
  ll ans = seg.get(0, n + 1);
  cout << ans << "\n";
}

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

  int T = 1;
  // cin >> T;
  while (T--) {
    solve();
  }
}


Measured memory_bytes: 4992
import java.util.*;

public class Main {
    private static long solve(int N, int W, int[] w, int[] v) {
        long max = 0;
        long[] maxValue = new long[W + 1];

        for (int k = 0; k < N; k++) {
            for (int weight = W - w[k]; weight >= 0; weight--) {
                if (maxValue[weight] == 0 && weight != 0) continue;

                int newWeight = weight + w[k];
                long newValue = maxValue[weight] + v[k];
                long currentValue = maxValue[newWeight];

                if (newValue > currentValue) {
                    maxValue[newWeight] = newValue;
                    max = Math.max(max, newValue);
                }
            }
        }

        return max;
    }

    public static void main(String[] args) {
        int N, W;
        int[] w;
        int[] v;
        try (Scanner scanner = new Scanner(System.in)) {
            N = scanner.nextInt();
            W = scanner.nextInt();

            w = new int[N];
            v = new int[N];
            for (int i = 0; i < N; i++) {
                w[i] = scanner.nextInt();
                v[i] = scanner.nextInt();
            }
        }

        long result = solve(N, W, w, v);
        System.out.println(result);

        //test();
    }

    private static void test() {
        testCase(3, 8, new int[] {3, 4, 5}, new int[] {30, 50, 60}, 90);
        testCase(5, 5, new int[] { 1, 1, 1, 1, 1}, new int[] {1000000000,1000000000,1000000000,1000000000,1000000000}, 5000000000L);
        testCase(6, 15, new int[] {6,5,6,6,3,7}, new int[] {5,6,4,6,5,2}, 17);

        timingTest(100);

        System.out.println("DONE");
    }

    private static void timingTest(int size) {
        int maxWeight = 100000;
        int[] w = new int[size];
        int[] v = new int[size];
        for (int i=0; i < size; i++) {
            w[i] = Math.min(i*i, maxWeight);
            v[i] = i;
        }

        long start = System.currentTimeMillis();
        solve(size, Math.min(100*size*size, maxWeight), w, v);
        long elapsed = System.currentTimeMillis() - start;
        System.out.println("timing size=" + size + " elapsed=" + elapsed);
    }

    private static void testCase(int N, int W, int[] w, int[] v, long expected) {
        long result = solve(N, W, w, v);
        if (result != expected) {
            System.out.println("FAILED N=" + N + " W=" + W + " w=" + Arrays.toString(w) + " v=" + Arrays.toString(v)
                    + ", was " + result + " expected " + expected);
        }
    }
}

Measured memory_bytes: 23252
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()-1;
    int C =B/(A-1);
    int D;
    if(B%(A-1)==0){D=C;}else{D=C+1;}
    System.out.println(D);
  }
}

Measured memory_bytes: 35724
#include <stdio.h>
#include <string.h>

const int MAXN = 22;
const int MOD = (int)1e9 + 7;

int mat[MAXN][MAXN];
int dp[MAXN][(1 << MAXN) + 5];
int n;

int solve(int pos, int mask) {
    if (pos >= n) return 1;
    if (dp[pos][mask] != -1) return dp[pos][mask];

    int& ans = dp[pos][mask];
    ans = 0;
    for (int i = 0; i < n; i++) {
        int bit = (mask >> i) & 1;
        if (!bit && mat[pos][i]) {
            ans += solve(pos + 1, mask | (1 << i));
            ans %= MOD;
        }
    }
    return ans;
}

int main(void) {
    scanf(" %d", &n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            scanf(" %d", &mat[i][j]);
        }
    }
    memset(dp, -1, sizeof(dp));
    int ans = solve(0, 0);
    printf("%d\n", ans);

    return 0;
}


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

int main() {
	int a, b, c, d = 0;
	cin >> a >> b >> c;
	
	std::map<int,int> n{};
	
	n[a] = n[a] + 1;
	n[b] = n[b] + 1;
	n[c] = n[c] + 1;
	cout << n.size() << endl;
	return 0;
	
}

Measured memory_bytes: 256
def main():
    N, *A = map(int, open(0).read().split())
    B = sorted(A)
    S = [set(),set()]
    for i in range(N):
        S[i&1].add(B[i])
    print(sum(a not in S[i&1] for i, a in enumerate(A))//2)


if __name__ == "__main__":
    main()

Measured memory_bytes: 15076
#include<stdio.h>

int main() {
  int x,y,z,tmp;
  
  scanf("%d%d",&x,&y);

  if(x < y) {
    tmp = x;
    x = y;
    y = tmp;
  }

  z = x % y;

  while(z != 0) {
    x = y;
    y = z;
    z = x % y;
  }

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



Measured memory_bytes: 2124
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9
typedef pair<ll,mp> mmp;

int main(){
	int n;
	cin>>n;
	vector<int> a(n,-1);
	vector<vector<mmp> > g(n);
	for(int i=0;i<n-1;i++){
		int u,v,w;
		cin>>u>>v>>w;
		u--,v--;
		g[u].push_back(mmp(u,mp(v,w) ) );
		g[v].push_back(mmp(v,mp(u,w) ) );
	}
	a[0] = 0;
	queue<mmp> q;
	vector<bool> used(n,false);
	used[0] = true;
	for(int i=0;i<g[0].size();i++){
		q.push(g[0][i]);
	}
	while(!q.empty()){
		mmp now = q.front();
		q.pop();
		int nn = now.first;
		int ne = now.second.first;
		int ww = now.second.second;
		if(used[ne])continue;
		used[ne] = true;
		if(ww%2==0){
			a[ne] = a[nn];
		}else{
			a[ne] = (a[nn]+1)%2;
		}
		for(int i=0;i<g[ne].size();i++){
			q.push(g[ne][i]);
		}
	}
	for(int i=0;i<n;i++)cout<<a[i]<<endl;

	return 0;
}


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

int main(void) 
{
    int n,m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    //大きい順
    sort(a.rbegin(),a.rend());

    ll sum = 0;
    rep(i,n) sum += a[i];

    rep(i,m) 
    {
        if( 4*m*a[i] < sum)
        { 
            cout << "No" << endl;
            return 0;
        }
        //選択可
    }
    cout << "Yes" << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x) cout << #x << " = " << (x) << endl;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define P pair<int, int>
#define V vector<int>
#define M map<int, int>
#define itn int
#define tin int
#define tni int
bool dbg = false;
int N, A[200010], B[200010];
int ans;
bool search()
{
    bool flag = true;
    FOR(i, 0, N)
    {
        if (A[i] != B[i]) {
            flag = false;
        }
    }
    return flag;
}

void solve()
{
    priority_queue<P> que;
    //set<P> S;
    FOR(i, 0, N)
    {
        if (A[i] != B[i]) {
            //S.insert(make_pair(B[i], i));
            que.push(make_pair(B[i], i));
        }
    }
    //while (!S.empty()) {
    while (!que.empty()) {
        //auto it = S.end();
        auto x = que.top();
        que.pop();
        //it--;
        //S.erase(it);
        //int t = (*it).second;
        int t = x.second;
        int& b = B[t];
        int& a = B[(t + N - 1) % N];
        int& c = B[(t + 1) % N];
        if (b > a + c) {
            int n = b - A[t];
            n = n / (a + c);
            if (n == 0) {
                cout << -1 << endl;
                return;
            }
            ans += n;
            b -= n * (a + c);
            if (b != A[t]) {
                //S.insert(make_pair(B[t], t));
                que.push(make_pair(B[t], t));
            }
        } else {
            cout << -1 << endl;
            return;
        }
    }
    cout << ans << endl;
}

signed main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N;
    FOR(i, 0, N)
    cin >> A[i];
    FOR(i, 0, N)
    cin >> B[i];
    solve();
    return 0;
}


Measured memory_bytes: 9584