akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 25050
#define K 450
#define Mod 1000000007
int n,k,m,i,j,a[N],cnt[K],f[N][K][2],g[N][K][2],sf[N][K][2],sg[N][K][2],ni[K];
bool vis[K];
int main()
{
	scanf("%d%d%d",&n,&k,&m);
	for (i=1;i<=m;i++) scanf("%d",&a[i]);
	int l,r;
	for (i=1;i<=m;i++) if (vis[a[i]]) break;else vis[a[i]]=true;
	if (i==m+1){
		if (k==1) g[1][1][1]=k;else g[1][1][0]=k;
		if (m==1) f[1][1][(k==1)]=k;
		for (i=2;i<=n+1;i++){
		for (j=k;j>=1;j--) sf[i-1][j][0]=(f[i-1][j][0]+sf[i-1][j+1][0])%Mod,sf[i-1][j][1]=(f[i-1][j][1]+sf[i-1][j+1][1])%Mod,sg[i-1][j][0]=(g[i-1][j][0]+sg[i-1][j+1][0])%Mod,sg[i-1][j][1]=(g[i-1][j][1]+sg[i-1][j+1][1])%Mod;
		for (j=1;j<=k;j++){
			f[i][j][0]=(1LL*(k-j+1)*f[i-1][j-1][0]+sf[i-1][j][0])%Mod;f[i][j][1]=(1LL*(k-j+1)*f[i-1][j-1][1]+sf[i-1][j][1])%Mod;g[i][j][0]=(1LL*(k-j+1)*g[i-1][j-1][0]+sg[i-1][j][0])%Mod;g[i][j][1]=(1LL*(k-j+1)*g[i-1][j-1][1]+sg[i-1][j][1])%Mod;
			if (j==k) f[i][j][1]=(f[i][j][1]+f[i][j][0])%Mod,f[i][j][0]=0,g[i][j][1]=(g[i][j][1]+g[i][j][0])%Mod,g[i][j][0]=0;
			if (j>=m) f[i][j][0]=(f[i][j][0]+g[i][j][0])%Mod,f[i][j][1]=(f[i][j][1]+g[i][j][1])%Mod;
		}
		}int ans=sf[n][1][1];
		ni[1]=1;
		for (i=2;i<=k;i++) ni[i]=-1LL*(Mod/i)*ni[Mod%i]%Mod;
		for (i=k-m+1;i<=k;i++) ans=1LL*ans*ni[i]%Mod;
		printf("%d\n",(ans+Mod)%Mod);
		return 0;
	}
	l=i-1;
	memset(vis,false,sizeof(vis));
	for (i=m;i>=1;i--) if (vis[a[i]]) break;else vis[a[i]]=true;
	r=m-i;
	int tot=0,wtf=0;
	if (k<=m){
	for (i=1;i<=k;i++){
		if (!cnt[a[i]]) tot++;
		cnt[a[i]]++;
	}wtf=tot;
	for (i=k+1;i<=m;i++){
		if (!cnt[a[i]]) tot++;
		cnt[a[i]]++;
		if (--cnt[a[i-k]]==0) tot--;
		wtf=max(wtf,tot);
	}
	}
	if (wtf==k) f[0][l][1]=1,g[0][r][1]=1;else f[0][l][0]=1,g[0][r][0]=1;
	for (i=1;i<=n-m+1;i++){
		for (j=k;j>=1;j--) sf[i-1][j][0]=(f[i-1][j][0]+sf[i-1][j+1][0])%Mod,sf[i-1][j][1]=(f[i-1][j][1]+sf[i-1][j+1][1])%Mod,sg[i-1][j][0]=(g[i-1][j][0]+sg[i-1][j+1][0])%Mod,sg[i-1][j][1]=(g[i-1][j][1]+sg[i-1][j+1][1])%Mod;
		for (j=1;j<=k;j++){
			f[i][j][0]=(1LL*(k-j+1)*f[i-1][j-1][0]+sf[i-1][j][0])%Mod;f[i][j][1]=(1LL*(k-j+1)*f[i-1][j-1][1]+sf[i-1][j][1])%Mod;g[i][j][0]=(1LL*(k-j+1)*g[i-1][j-1][0]+sg[i-1][j][0])%Mod;g[i][j][1]=(1LL*(k-j+1)*g[i-1][j-1][1]+sg[i-1][j][1])%Mod;
			if (j==k) f[i][j][1]=(f[i][j][1]+f[i][j][0])%Mod,f[i][j][0]=0,g[i][j][1]=(g[i][j][1]+g[i][j][0])%Mod,g[i][j][0]=0;
		}
	}int ans=0,gh=1;
	for (i=1;i<=n-m;i++) gh=1LL*gh*k%Mod;
	for (i=0;i<=n-m;i++) ans=(-1LL*sf[i][1][0]*sg[n-m-i][1][0]+ans+gh)%Mod;
	printf("%d\n",(ans+Mod)%Mod);
	return 0;
}

Measured memory_bytes: 352384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll modpow(ll a, ll n, ll mod_) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod_;
        a = a * a % mod_;
        n >>= 1;
    }
    return res;
}

const ll MAX_SIZE = 200005;
array<ll, MAX_SIZE> fac, inv, finv;
void fac_init() {
    // combination init
    fac[0] = 1;
    for (ll i = 1; i < MAX_SIZE; i++) fac[i] = fac[i - 1] * i % MOD;
    finv[0] = modpow(fac[MAX_SIZE - 1], MOD - 2, MOD);
    repe(i, 1, MAX_SIZE) finv[i] = finv[i - 1] * (MAX_SIZE - i) % MOD;
    reverse(all(finv));

    //inv init
    repe(i, 1, MAX_SIZE) inv[i] = modpow(i, MOD - 2, MOD);
}

ll perm(ll a, ll b) { return fac[a] * finv[a - b] % MOD; }

ll comb(ll a, ll b) { return fac[a] * finv[b] % MOD * finv[a - b] % MOD; }

ll A[100005];
int main() {
    init();
    fac_init();

    ll N, K;
    cin >> N >> K;
    ll ans = 0;
    repe(i,K,N+2){
        (ans += i * (N - i + 1) % MOD + 1) %= MOD;
    }

    cout << ans << endl;

}

Measured memory_bytes: 8348
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll> ;
#define all(v) v.begin(),v.end()

int main(){
  ll N,D;cin>>N>>D;
  vll X(N),Y(N);rep(i,N)cin>>X[i]>>Y[i];
  ll ans=0;
  rep(i,N){
    if(X[i]*X[i]+Y[i]*Y[i]<=D*D) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 6428
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

int main()
{
	ios_init();
	int n,c,k;
	while(cin >> n >> c >> k) {
		vector<int> t(n);
		REP(i,n) cin >> t[i];
		map<int,P> mp;
		REP(i,n){
			mp[t[i]].F += 1;
			mp[t[i]+k].S += 1;
		}
		multiset<int> s;
		int ans =0 ;
		for(auto&& e : mp) {
			P p = e.S;
			DEBUG(p);
			REP(i,p.F) s.insert(e.F);
			int pre = e.F-k;
			int co = s.count(pre);
			int x = (co+c-1)/c;	
			DEBUG(x);
			ans += x;
			int num = x*c;
			while(SZ(s) != 0 and num != 0){
				s.erase(s.begin());
				num--;
			}
		}
		ans += (SZ(s)+c-1)/c;
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 13184
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (LLONG_MAX - 1e5)
#define fcout cout << fixed << setprecision(10)

using namespace std;

int mod = 1e9 + 7;


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

    int N, M;
    cin >> N >> M;
    set<int> A, B;
    REP(i, N) {
        int a;
        cin >> a;
        A.insert(a);
    }
    REP(i, M) {
        int b;
        cin >> b;
        B.insert(b);
    }

    if (N != A.size()) {
        cout << 0 << endl;
        return 0;
    }
    if (M != B.size()) {
        cout << 0 << endl;
        return 0;
    }

    int ans = 1;
    int empty = 0;
    int anum = 0;
    int bnum = 0;
    REV(i, N * M, 1) {
        if (A.count(i) > 0 && B.count(i) > 0) {
            anum++;
            bnum++;
            empty += (anum - 1) + (bnum - 1);
        } else if (A.count(i) > 0 && B.count(i) == 0) {
            anum++;
            empty += bnum;
            ans = (ans * bnum) % mod;
            empty--;
        } else if (B.count(i) > 0 && A.count(i) == 0) {
            bnum++;
            empty += anum;
            ans = (ans * anum) % mod;
            empty--;
        } else {
            ans = (ans * empty) % mod;
            empty--;
        }

        if (empty < 0) {
            break;
        }
    }

    if (empty !=  0 || ans <= 0) {
        cout << 0 << endl;
    } else {
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
//#pragma GCC optimize(2)

using namespace std;
#define LL long long
#define Rint register int
#define U unsigned
#define forn(i,a,b) for(int i = a;i <= b;++i)
#define nfor(i,a,b) for(int i = a;i >= b;--i)
#define pii pair<int ,int>
#define MS0(X) memset(X,0,sizeof(X))
#define MSf(X) memset(X,false,sizeof(X))
#define MS1(X) memset(X,-1,sizeof(X))
#define BR printf("--------------------\n")
#define pb push_back
#define rep(i,a,b) for(Rint i=a;i<=b;++i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const double PI=atan(1.)*4.;
const int maxn=1e6+5;
const int inf = 0x3f3f3f3f;
const int mod=1e9+7;
const double e=2.71828182845904523536;
int dirx[8]={1,0,-1,0,1,-1,-1,1};
int diry[8]={0,1,0,-1,1,1,-1,-1};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    int ok=0;
    for(int i=1;i<=9;i++){
        if(n%i==0&&n/i>=1&&n/i<=9)
            ok=1;
    }
    if(ok)cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}

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

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] a = new int[n];
		int[] col = new int[n];
		for (int i = 0; i < n; ++i) {
			a[i] = sc.nextInt();
			--a[i];
			col[a[i]]++;
		}
		PriorityQueue<Integer> pq = new PriorityQueue();
		for (int i = 0; i < n; ++i) {
			if (col[i] != 0) {
				pq.add(col[i]);
			}
		}
		int ans = 0;
		while (pq.size() > k) {
			ans += pq.poll();
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 79076
import math

Five_Dishes1 = []
Five_Dishes2 = []
for i in range(5):
    time = input()
    time_last = time[-1]
    Five_Dishes1.append(time)
    Five_Dishes2.append(time_last)
    
Five_Dishes_int = [int(n) for n in Five_Dishes1]
Five_Dishes2 = [x if x is not '0' else 'a' for x in Five_Dishes2]
Five_Dishes_last2 = sorted(Five_Dishes2)

last_dish = Five_Dishes2.index(min(Five_Dishes2))
res_time = 0
n = 0
while n < 5:
    if Five_Dishes_int[n] % 10 == 0:
        res_time += Five_Dishes_int[n]
    elif Five_Dishes_int[n] % 10 != 0 and n == last_dish:
        res_time += Five_Dishes_int[n]
    else:
        res_time += math.ceil(Five_Dishes_int[n] / 10 ) * 10    
    n += 1    
        
print(res_time)


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

int main()
{
	int n, res;
	while (cin >> n, n) {
		vector<int> v;
		v.reserve(n);
		for (int i = 0, tmp; i < n; i++) {
			cin >> tmp;
			v.push_back(tmp);
		}
		bool flag = true;
		res = 0;
		while (flag) {
			flag = false;
			for (int i = 0, tmp;i < v.size() - 1;i++) {
				if (v[i] > v[i + 1]) {
					tmp = v[i];
					v[i] = v[i + 1];
					v[i + 1] = tmp;
					flag = true;
					res++;
				}
			}
		}
		cout << res << endl;
	}
	return 0;
}

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

string text,in;
int cur,len;

int main()
{
  int CS,n; cin>>CS; cin.ignore();
  for (int cs = 0; cs < CS; cs++) {
    getline(cin,text);
    cin>>n; cin.ignore();
    len=text.size();
    cur=0;
    for (int i = 0; i < n; i++) {
      getline(cin,in);
      if(in=="forward char")cur=min(cur+1,len);
      else if(in=="backward char")cur=max(cur-1,0);
      else if(in=="delete char"){
	if(cur>=text.size())continue;
	text.erase(text.begin()+cur); len--;
      }
      else if(in.find("insert")!=in.npos){
	int s=in.find('"'),t=in.find('"',s+1);
	text=text.substr(0,cur)+in.substr(s+1,t-s-1)+text.substr(cur);
	cur+=t-s-1; len+=t-s-1;
      }
      else if(in=="forward word"){
	for(;cur<len&&text[cur]==' ';cur++);
	for(;cur<len&&text[cur]!=' ';cur++);
      }
      else if(in=="backward word"){
	for(;cur>0&&text[cur-1]==' ';cur--);
	for(;cur>0&&text[cur-1]!=' ';cur--);
      }
      else if(in=="delete word"){
	int s=cur,t;
	for(;text[s]==' ';s++);
	if(s>=len)continue;
	for(t=s;text[t]!=' '&&t<len;t++);
	text=text.substr(0,cur)+text.substr(t); len-=t-cur;
      }
    }
    cout<<text.substr(0,cur)<<"^"<<text.substr(cur)<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int w,h,n,i,s=0;
	cin>>h>>w>>n;
	for(i=1;;i++)
	{
		int a;
		h>=w? a=h:a=w;
		s+=a;
		if(s>=n) break;
	}
	cout<<i<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.*;
public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;
		String[] strs;
		int a;
		String op;
		int b;
		int ans = 0;//解答
		while(true){
			str = br.readLine();
			strs = str.split(" ");
			a = Integer.parseInt(strs[0]);
			op = strs[1];
			b = Integer.parseInt(strs[2]);
			if(op.equals("?")){
				break;
			}else if(op.equals("+")){
				ans = a + b;
			}else if(op.equals("-")){
				ans = a - b;
			}else if(op.equals("*")){
				ans = a * b;
			}else if(op.equals("/")){
				ans = a / b;
			}//if
			System.out.println(ans);
		}//while
	}
}

Measured memory_bytes: 16920
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
#include<vector>
#include<stack>
#include<queue>
#include<iostream>
using namespace std;
int main(void)
{
	int mx,once,i,j,n,a,b,c;
	while(1) {
		cin >>n;
		if(n==0) break;
		mx=-1;
		for(i=0;i<n;i++) {
			cin >>a>>b>>c;
			if(mx<b+c){
				mx=b+c;
				once=a;
			}
		}
		cout <<once<< " "<<mx<<endl;
	}
	exit(0);
}

Measured memory_bytes: 1160
def main():
    M, N, X, Y = map(int, input().split())

    xs = list(map(int,input().split()))
    ys = list(map(int,input().split()))
    zs = []

    for n in range(X+1,Y+1):
        zs.append(n)

    xMax = max(xs)
    yMin = min(ys)
    tmp = []
    for z in zs:
        if z > xMax:
            tmp.append(z)
        if z <= yMin:
            tmp.append(z)

    flag = False
    for z in zs:
        if tmp.count(z) > 1:
            flag = True


    if len(zs) == 0:
        print("War")
        return 0

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


if __name__ == "__main__":
    main()



Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		sc.close();

		int maxLength = 0;
		int counter = 0;

		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == 'A' || s.charAt(i) == 'C' || s.charAt(i) == 'T' || s.charAt(i) == 'G') {
				counter++;
				maxLength=Math.max(maxLength, counter);
			} else {
				counter = 0;
			}
		}

		System.out.println(maxLength);

	}

}


Measured memory_bytes: 35628
#include <iostream>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;

int count = 0;

vector<bool> seen;
void dfs(const Graph &G, int v) {
    seen[v] = true;
    count++;
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue;
        dfs(G, next_v);
    }
}

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

    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b; 
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    int result = -1;
    seen.assign(N, false);
    for (int v = 0; v < N; ++v) {
        if (seen[v]) continue;
        count = 0;
        dfs(G, v);
        result = result > count ? result : count;
    }
    cout << result << endl;
}

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

#define REP(i,m,n) for(int i=(int)m; i < (int) n; ++i)
#define rep(i,n) REP(i,0,n)
typedef long long ll;

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

  int n, p; cin >> n >> p;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  int odd = 0, even = 0;
  rep(i, n) {
    if(a[i]&1) odd++;
    else even++;
  }

  ll ans;
  if(odd == 0) {
    if(p == 0) ans = 1LL << n;
    else ans = 0;
  } else {
    ans = 1LL << (n-1);
  }

  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < n; ++i)
#define FORR(i, m, n) for (ll i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
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; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;cin >> n >> m;
    vector<vector<int>> c(m+1);
    REP(i,n){
      int a,b;cin >> a >> b;
      if(a>m){
        continue;
      }
      c[m-a].push_back(b);
    }
    priority_queue<int> pq;
    ll ans=0;
    REPR(i,m+1){
      REP(j,c[i].size()){
        pq.push(c[i][j]);
      }
      if(pq.empty()){
        continue;
      }
      ans+=pq.top();
      pq.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 8468
#include <cassert>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <iostream>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

typedef long long ll;

template<typename T>
struct BITM {
  vector<T> data;
  BITM() {}
  BITM(int n) : data(n+1, 0) {}
  void init(int n) { data.assign(n+1, 0); }
  T maxOf(int ed) const {
    for(T res(0); ; ed &= ed-1) if(ed) res = max(res, data[ed]); else return res;
  }
  void set(int i, const T& x) {
    for(++i; i < (int)data.size(); i += i&-i) data[i] = max(data[i], x);
  }
};

struct K {
  int h;
  int i;
  ll v;
};
K ks[200000+10];
bool operator<(const K& k1, const K& k2) {
  return k1.h < k2.h;
}

int main(void) {
  int N;
  scanf("%d", &N);
  REP(i, N) {
    scanf("%d", &ks[i].h);
  }
  REP(i, N) {
    scanf("%lld", &ks[i].v);
    ks[i].i = i;
  }
  sort(ks, ks + N);
  ll res = 0;
  BITM<ll> bit(N);
  REP(i, N) {
    K cur = ks[i];
    ll v = bit.maxOf(cur.i);
    bit.set(cur.i, v + cur.v);
    res = max(res, v + cur.v);
  }
  cout << res << endl;
  
  return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<string>
using namespace std;
int main(){
  int h,w;
  while(cin >>h>>w,h||w){
    int field[100][100] = {0};
    bool f[100][100] = {false};
    string s;
    for(int i=0; i<h; i++){
      cin >>s;
      for(int j=0; j<s.size(); j++){
	if(s[j] == '>'){field[i][j] = 1;}
	if(s[j] == 'v'){field[i][j] = 2;}
	if(s[j] == '<'){field[i][j] = 3;}
	if(s[j] == '^'){field[i][j] = 4;}
      }
    }
    int px, py;
    px = py = 0;
    for(;;){
      if(f[py][px]){cout <<"LOOP"<<endl;break;}
      f[py][px] = true;
      if(!field[py][px]){cout <<px<<" "<<py<<endl;break;}
      if(field[py][px] == 1){px++;}
      if(field[py][px] == 2){py++;}
      if(field[py][px] == 3){px--;}
      if(field[py][px] == 4){py--;}
    }
  }
  return 0;
}

Measured memory_bytes: 1268
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <stdlib.h>
using namespace std;

#define INF 1e18
#define PI 3.141592653589793238
typedef long long ll;
#define N 200010

int main() {
    int d,t,s;cin>>d>>t>>s;
    if(t*s<d) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;



    return 0;
}

Measured memory_bytes: 3580
N = int(input())
p = 10 ** 9 + 7
primes = []
for i in range(1, N + 1):
  for j, prime in enumerate(primes):
    while i % prime[0] == 0:
      primes[j][1] += 1
      i //= prime[0]
    if i < prime[0]:
      break
  if i > 1:
    primes.append([i, 2])
ans = 1
for k, v in primes:
  ans *= v
  ans %= p
print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cstring>

struct Node {
  int key;
  Node *prev, *next;
};

Node *nil;

void init() {
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void insert(int key) {
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

Node* listSearch(int key) {
  Node *cur = nil->next;
  while (cur != nil && cur->key != key)
    cur = cur->next;
  return cur;
}

void deleteNode(Node* t) {
  if (t == nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst() {
  deleteNode(nil->next);
}

void deleteLast() {
  deleteNode(nil->prev);
}

void deleteKey(int key) {
  deleteNode(listSearch(key));
}

void printList() {
  Node *cur = nil->next;
  int isf = 0;
  while (1) {
    if (cur == nil) break;
    if (isf++ > 0) printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
  }
  printf("\n");
}

int main() {
  int key, n;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for (int i = 0; i < n; ++i) {
    scanf("%s%d", com, &key);
    if (com[0] == 'i') {
      insert(key);
      ++np;
      ++size;
    } else if (com[0] == 'd') {
      if (strlen(com) > 6) {
        if (com[6] == 'F') deleteFirst();
        else if (com[6] == 'L') deleteLast();
      } else {
        deleteKey(key);
        ++nd;
      }
      --size;
    }
  }
  printList();
  return 0;
}

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

int main( void )
{
    int a, b, c;
    cin >> a >> b >> c;
    if ( a == b )
    {
        cout << c << endl;
    }
    else if ( a == c )
    {
        cout << b << endl;
    }
    else
    {
        cout << a << endl;
    }
    return 0;
}


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

vector<int> st;
vector<int> top;

vector<int> calc(int a, int b, int n) {
    if (n == 1) return {a, b};
    int s = __builtin_ffs(a^b);
    int t = 0;
    if ((a & (1 << (s-1))) != 0) t = (1 << (s-1));
    int aa = a % (1 << (s-1)) + ((a >> s) << (s-1));
    int bb = b % (1 << (s-1)) + ((b >> s) << (s-1));
    int d = aa ^ 1;
    //cout << a << b << " " << aa << " " << bb << " " << d <<  endl;
    vector<int> e = calc(aa, d, n-1), f = calc(d, bb, n-1);
    for (int i = 0; i < (int)e.size(); i++) e[i] = ((e[i] >> (s-1)) << s) + t + e[i] % (1 << (s-1));
    for (int q : f) e.push_back(((q >> (s-1)) << s) + (1 << (s-1)) - t + q % (1 << (s-1)));
    return e;
}

int main(){
    int N, A, B;
    cin >> N >> A >> B;
    B ^= A;
    if (__builtin_parity(B) == 0) {
        cout << "NO" << endl;
        return 0;
    }
    vector<int> base;
    base.push_back(0);
    for (int i = 0; i < N; i++) {
        int t = 1 << i;
        if ((B & t) == 0) {
            for (int j = (int)base.size()-1; j >= 0; j--) {
                base.push_back(base[j]+t);
            }
        }
    }
    
    for (int i = 0; i < N; i++) {
        if (((B>>i) & 1) != 0) st.push_back(i);
    }
    
    top = calc(0, (1<<(int)st.size()) - 1, (int)st.size());
    
    for (int i = 0; i < (int)top.size(); i++) {
        int nt = 0;
        for (int j = 0; j < (int)st.size(); j++) {
            if ((top[i] >> j)&1) nt += (1 << (st[j]));
        }
        top[i] = nt;
    }
    
    //for (int x : top) cout << x << endl;
    vector<int> ans;
    for (int i = 0; i < (int)top.size(); i++) {
        if (i%2 == 0) {
            for (int j = 0; j < (int)base.size(); j++) {
                ans.push_back(A^top[i]^base[j]);
            }
        }else {
            for (int j = (int)base.size()-1; j >= 0; j--) {
                ans.push_back(A^top[i]^base[j]);
            }
        }
    }
    cout << "YES\n";
    for (int i = 0; i < (1<<N); i++) {
        if (i < (1<<N)-1) printf("%d ", ans[i]);
        else printf("%d\n", ans[i]);
    }
    return 0;
}


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

int main(){
  int N, K;
  cin >> N >> K;
  vector<bool> C(N+1,false);
  for(int i=0; i<K; i++){
    int d; cin >> d;
    for(int j=0; j<d; j++){
      int A; cin >> A;
      C[A]=true;
    }
  }
  int ans =0;
  for(int i=1; i<=N; i++){
    if(!C[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

const ll INF = 1LL << 50;

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

  for (ll n = 1; n <= 3500; n++)
    for (ll w = 1; w <= 3500; w++) {
      ll x = n * w * N;
      ll y = 4 * n * w - N * w - N * n;
      if (y == 0) continue;
      ll h = x / y;
      bool cond = x % y == 0 && h <= 3500 && h >= 1;
      if (cond) {
        printf("%lld %lld %lld\n", h, w, n);
        return 0;
      }
    }

  return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <bitset>
#include <limits>

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;
#define REP(i,a,n) for(int i = (a); i < (int)(n); ++i)
#define REPM(i,n,a) for(int i = ((n) - 1); i >= (a); --i)
#define FLOAT setprecision(16)
const int INF = 0x3FFFFFFF;
const LL INFLL = 0x3FFFFFFF3FFFFFFF;
const double INFD = 1.0e+308;
const double EPS = 1.0e-9;

template <class T, class U>
istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(begin(dest), end(dest), val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }
// all_of

#if 1234567891
#include <array>
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
#endif

#if _DEBUG
#include "IntMod.h"
#include "Union_Find.h"
#include "Graph.h"
#endif

int N, M,K;
int main() {
	cin >> N >> M >> K;
	bool ok = false;
	REP(i, 0, N + 1) {
		REP(j, 0, M + 1) {
			if (i * j + (N - i) * (M - j) == K)ok = true;
		}
	}
	cout << (ok ? "Yes" : "No") << endl;
	return 0;
}



Measured memory_bytes: 256
const input = require('fs').readFileSync('/dev/stdin', 'utf8').split(" ").map(str => parseInt(str, 10));
const X = input[0];
const Y = input[1];
for (let i = 0; i <= X; i++) {
    if (Y === 2 * i + 4 * (X - i)) {
        console.log("Yes");
        return;
    };
}
console.log("No");

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

int main() {
    string n;
    int k;
    long r = 0;
    cin >> n >> k;
    if(k == 1) {
        int c = 0;
        for(int j = 0; j < n.length(); j++) {
            int z = c ? 9 : n[j] - '0';
            if(z)
                r += z;
            if(n[j] != '0')
                c = 1;
        }
    }
    if(k == 2) {
        int b = 0;
        for(int i = 0; i < n.length(); i++) {
            int y = b ? 9 : n[i] - '0', c = 0;
            for(int j = i + 1; j < n.length(); j++) {
                int z = b + c ? 9 : n[j] - '0';
                if(y)
                    r += (y - 1) * 9;
                if(y && z)
                    r += z;
                if(n[j] != '0')
                    c = 1;
            }
            if(n[i] != '0')
                b = 1;
        }
    }
    if(k == 3) {
        int a = 0;
        for(int l = 0; l < n.length(); l++) {
            int x = a ? 9 : n[l] - '0', b = 0;
            for(int i = l + 1; i < n.length(); i++) {
                int y = a + b ? 9 : n[i] - '0', c = 0;
                for(int j = i + 1; j < n.length(); j++) {
                    int z = a + b + c ? 9 : n[j] - '0';
                    if(x)
                        r += (x - 1) * 81;
                    if(x && y)
                        r += (y - 1) * 9;
                    if(x && y && z)
                        r += z;
                    if(n[j] != '0')
                        c = 1;
                }
                if(n[i] != '0')
                    b = 1;
            }
            if(n[l] != '0')
                a = 1;
        }
    }
    cout << r << endl;
    return 0;
}


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

int run(int A[], int n, int k, int P) {
    int w = 0, i = 0;
    while (k > 0) {
       if (w + A[i] > P) {
            k--;
            w = 0;
        } else {
            w += A[i]; 
            if (++i >= n) break;
        }
        // cout << k << " " << w << endl;
    }
    return i;
}

int search(int A[], int n, int k) {
    int left = 0, right = MAXLEN * 10000, P;
    while (left < right) {
        P = (left + right) / 2;
        if (run(A, n, k, P) < n) left = P + 1;
        else right = P;
        // cout << P << " " << run(A, n, k, P) << endl;
    }
    return left;
}

int main(){
    int n, k, A[MAXLEN];
    cin >> n >> k;
    for (int i=0; i < n; i++) scanf("%d", &A[i]);
    cout << search(A, n, k) << endl;
    return 0;
} 


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

#define ll long long
#define pb push_back
#define F first
#define S second

using namespace std;

const int N = 100005;
const int MOD = 1e9 + 7;

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
	int a, p;
	cin >> a >> p;
	cout << (3 * a + p) / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("badhair.gir","r",stdin);freopen ("badhair.cik","w",stdout);
#define mod 1000000007
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
using namespace std;

ll n,m,ar[N],sum,t;



int main()
{
	fast;
	cin>>n;
	for(ll i=1;i*i<=n;i++)
	{
		if(n%i!=0)
			continue;
		t=i;
	}
	cout<<t+n/t-2;

}



/*     cd onedrive\desktop\kod
cls

Sinav:21-22 aralik
Aciklama: Muhtemelen 25 aralik
*/

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

using namespace std;

typedef long long ll;

const ll mod=998244353;

ll n;
ll jc[10000010];

ll power(ll a,ll b)
{
	ll res=1ll;
	while(b)
	{
		if(b&1)
		{
			res*=a;
			res%=mod;
		}
		a*=a;
		a%=mod;
		b>>=1;
	}
	return res;
}

void init()
{
	jc[0]=1ll;
	for(ll i=1;i<=n;i++)
	{
		jc[i]=jc[i-1]*i%mod;
	}
}

ll C(ll x,ll y)
{
	return jc[x]*power(jc[x-y],mod-2)%mod*power(jc[y],mod-2)%mod;
}

int main()
{
	scanf("%lld",&n);
	init();
	ll ans=power(3ll,n);
	ll tot=0;
	for(ll i=n/2+1;i<=n;i++)
	{
//		cout<<"qaq"<<endl;
		tot=(tot+C(n,i)*power(2ll,n-i)%mod+mod)%mod;
	}
	printf("%lld",((ans-2*tot)%mod+mod)%mod);
	return 0;
}











Measured memory_bytes: 78336
#include<iostream>
#include<cstring>
using namespace std;
int main(){
	int h,box[2];
	char s[100];
	while(1){
		box[0]=0;
		box[1]=0;
		cin>>s;
		if(s[0]=='0')
			break;
		h=strlen(s);
		for(int i=0;i<h-1;i++)
		box[s[i+1]-'A']++;
		if(box[0]>box[1])
		box[0]++;
		else box[1]++;
		cout<<box[0]<<' '<<box[1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.sql.SQLOutput;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;
import javax.swing.plaf.IconUIResource;


 class Main {

   public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

   static class FastReader {

     BufferedReader br;
     StringTokenizer st;

     public FastReader() {
       br = new BufferedReader(new
           InputStreamReader(System.in));
     }

     String next() {
       while (st == null || !st.hasMoreElements()) {
         try {
           st = new StringTokenizer(br.readLine());
         } catch (IOException e) {
           e.printStackTrace();
         }
       }
       return st.nextToken();
     }

     int nextInt() {
       return Integer.parseInt(next());
     }

     long nextLong() {
       return Long.parseLong(next());
     }

     double nextDouble() {
       return Double.parseDouble(next());
     }

     String[] nextSArray() {
       String sr[] = null;
       try {
         sr = br.readLine().trim().split(" ");
       } catch (IOException e) {
         e.printStackTrace();
       }
       return sr;
     }

     String nextLine() {
       String str = "";
       try {
         str = br.readLine();
       } catch (IOException e) {
         e.printStackTrace();
       }

       return str;
     }
   }

   //  static int MOD=1000000000+7;
//  public static void sortbyCol(int arr[][],int col)
//  {
//    Arrays.sort(arr,new Comparator<int[]>(){
//      @Override
//      public int compare(int[] o1, int[] o2) {
//        // To sort in descending order revert
//        // the '>' Operator
//        if(o1[col]>o2[col])
//          return 1;
//        else
//          return -1;
//      }
//    });
//  }
   static int countbits(int a) {
     if (a == 0)
       return 0;
     return (int) (Math.log(a) / Math.log(2) + 1);
   }

   static int reversebits(int n, int pos) {
     while (pos > 0) {
       if ((n & pos) > 0) {
         n -= pos;
       } else
         n += pos;
       pos = pos >> 1;
     }
     return n;
   }

   public static void main(String[] args) throws java.lang.Exception {
     FastReader sc = new FastReader();
//   int t1=sc.nextInt();
//
//   for(int t=0;t<t1;++t)
//   {
//
//   }
      int n=sc.nextInt();
      int k=sc.nextInt();
      ArrayList<Integer>al=new ArrayList<>();
      for(int i=0;i<n;++i)
      {
        al.add(sc.nextInt());
      }
     Collections.sort(al);
      int sum=0;
     for(int i=0;i<k;++i)
     {
       sum+=al.get(i);
     }
     System.out.println(sum);


   }
 }



// out.println(al.toString().replaceAll("[\\[|\\]|,]",""));


Measured memory_bytes: 26064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

int n;
double calc(vector<int> &cnt){
	double res = 0;
	for (double x : cnt){
		if(x) res -= x / n*log(x / n);
	}
	return res;
}

tuple<int, int, int> bf(vector<int> &v){
	double opt = 1e9;
	auto ans = MT(-1, -1, -1);
	rep(s, 16) rep(a, 16) rep(c, 16){
		vector<int> cnt(256);
		int r = s;
		rep(i, v.size()){
			r = (a*r + c)&255;
			++cnt[(v[i] + r)&255];
		}
		double tmp = calc(cnt);
		if (tmp + 1e-9 < opt){
			ans = MT(s, a, c);
			opt = tmp;
		}
	}
	return ans;
}

int main(){
	while (cin >> n, n){
		vector<int> v(n);
		rep(i, n) cin >> v[i];
		int s, a, c;
		tie(s, a, c) = bf(v);
		cout << s << ' ' << a << ' ' << c << '\n';
	}

	return 0;
}

Measured memory_bytes: 1228
S = input()

c_max = 0
cnt = 0

for i in S:
    if i == "A" or i == "C" or i ==  "G" or i == "T":
        cnt +=1
        c_max = max(c_max, cnt)
    else:
        c_max = max(c_max, cnt)
        cnt = 0

print(c_max)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int64_t n,m,q;
vector<int64_t> a;
vector<int64_t> b;
vector<int64_t> c;
vector<int64_t> d;
int64_t ans=0;
void dfs(vector<int64_t>Q){
  if(Q.size()==n){
    int64_t score=0;
    for(int64_t i=0;i<q;i++){
      if(Q[b[i]-1]-Q[a[i]-1]==c[i])score+=d[i];
    }
    ans=max(ans,score);
    return;
  }
  Q.push_back(Q.back());
  while(Q.back()<=m){
    dfs(Q);
    Q.back()++;
  }
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m >> q;
  a=b=c=d=vector<int64_t>(q);
  for(int64_t i=0;i<q;i++)cin >> a[i] >> b[i] >> c[i] >> d[i];
  dfs({1});
  cout << ans << endl;
}


Measured memory_bytes: 3608
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n; readV(n);
  int[] v; readA(n, v);
  int[] c; readA(n, c);

  auto r = 0;
  foreach (vi, ci; lockstep(v, c))
    if (vi > ci) r += vi-ci;

  writeln(r);
}


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

int main(){
    
    map<string, ll>cnt;
    ll N;
    cin >> N;
    string lst;
    cin >> lst;
    cnt[lst] = 1;
    ll flg = 1;
    for(ll i = 1; i < N; i++){
        string s;
        cin >> s;
        if(lst[lst.size() - 1] != s[0])flg = 0;
        if(cnt[s])flg = 0;
        cnt[s] = 1;
        lst = s;
    }
    if(flg)cout<<"Yes"<<endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
//Littleboy123 Template 1.1

#include <bits/stdc++.h>
using namespace std;

//pragmas
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target ("avx2")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
*/

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#define FOR(a,b,c) for(ll (a)=(b);(a)<(c);++(a))
#define FORE(a,b,c) for(ll (a)=(b);(a)<=(c);++(a))
#define FORN(a,b,c) for(ll (a)=(b);(a)>(c);--(a))
#define FORNE(a,b,c) for(ll (a)=(b);(a)>=(c);--(a))
#define COUT(a) cout << (a) << '\n'
#define MEM(a,b) memset((a), (b), sizeof((a)))
#define MAX(a,b) (a) = max((a), (b))
#define MIN(a,b) (a) = min((a), (b))
#define nl '\n'
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)

void init(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

//End of template

int main(){  
	//init();

	//debug
	/*
	ifstream in("input.in");
	streambuf *cinbuf = std::cin.rdbuf();
	cin.rdbuf(in.rdbuf());
	
	ofstream out("out.txt");
	streambuf *coutbuf = std::cout.rdbuf();
	cout.rdbuf(out.rdbuf());
	*/
	//end debug

	int n;
	cin >> n;
	int arr[n];
	FOR(i, 0, n){
		cin >> arr[i];
	}
	sort(arr, arr+n);
	ld now = arr[0];
	FOR(i, 1, n){
		now = (now+arr[i])/2;
	}
	cout << fixed << setprecision(9) << now << nl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> //ABC 122_a
using namespace std;
int main(){
	char b;
	cin>>b;
	if(b=='A')
		cout<<"T";
	else if(b=='T')
		cout<<"A";
	else if(b=='C')
		cout<<"G";
	else if(b=='G')
		cout<<"C";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[5];
int main(){
    cin>>a[1]>>a[2]>>a[3];
    sort(a+1,a+4);
    if(a[2]-a[1]==a[3]-a[2]) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
N, *A = map(int, open(0).read().split())

C = {}
for a in A:
    if a in C.keys():
        C[a] += 1
    else:
        C[a] = 1
B = list(C.items())
B.sort(key=lambda x: x[0])

M = len(B)
ans = 0
for i in range(M):
    count = B[i][1]
    if i-1 >= 0 and B[i-1][0] == B[i][0]-1:
        count += B[i-1][1]
    if i+1 < M and B[i+1][0] == B[i][0]+1:
        count += B[i+1][1]
    ans = max(ans, count)
print(ans)

Measured memory_bytes: 20848
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
   int X,Y;
   cin >> X >> Y;
   if(Y%2 != 0){
       cout << "No" << endl;
   }else if(Y > 4*X){
       cout << "No" << endl;
   }else if(Y/2 < X){
       cout << "No" << endl;
       
   }else{
       cout << "Yes" << endl;
   }
}


Measured memory_bytes: 3628
import org.w3c.dom.ls.LSOutput;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.nio.Buffer;
import java.util.*;

public class Main {
    public static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
    public static int n;
    public static final int N=305;
    public static double [][][]dp=new double[N][N][N];
    public static boolean [][][] used=new boolean[N][N][N];
    public static double solve(int a,int b,int c){
        if(a<0||b<0||c<0) return 0;
        if(a+b+c==0) return 0;
        double res=dp[a][b][c];
        if(used[a][b][c]) return res;
        used[a][b][c]=true;
        res=0;
        int rem=n-a-b-c;
        res=(double)rem/n+(double)a/n*(solve(a-1,b,c)+1)+(double)b/n*(solve(a+1,b-1,c)+1)+(double)c/n*(solve(a,b+1,c-1)+1);
        res/=1-(double)rem/n;
        return dp[a][b][c]=res;
    }

    public static FastReader r=new FastReader();
    public static void main(String[] args){
        n=r.nextInt();
        int []cnt=new int[4];
        for(int i=0;i<n;++i) {
            int x=r.nextInt();
            ++cnt[x];
        }
        System.out.println(solve(cnt[1],cnt[2],cnt[3]));
    }
}


Measured memory_bytes: 360276
#include<stdio.h>

int count=0;

void selectionSort(int *,int);

int main(){
  int i,n,data[100];

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&data[i]);

  selectionSort(data,n);

  for(i=0;i<n-1;i++) printf("%d ",data[i]);
  printf("%d\n",data[i]);
  printf("%d\n",count);

  return 0;

}

void selectionSort(int *data,int n){
  int i,j,min,tmp;
  
  for(i=0;i<n;i++){
    min=i;
    for(j=i;j<n;j++){
      if(data[j]<data[min]) min=j;      
    }

    if(i!=min) count++;
    tmp=data[i];
    data[i]=data[min];
    data[min]=tmp;
  }

}



Measured memory_bytes: 2108
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int N;
ll A[200005];
vector<vector<int> > edge(200005);
vector<ll> arr(200005, big);
ll ans[200005];

void solve(int u, int v) {
  int index;
  ll pre;
  index = lower_bound(arr.begin(), arr.end(), A[u]) - arr.begin();
  pre = arr[index];
  arr[index] = A[u];
  ans[u] = lower_bound(arr.begin(), arr.end(), big) - arr.begin();
  for(int i=0;i<edge[u].size();++i) {
    if(edge[u][i]==v) continue;
    solve(edge[u][i], u);
  }
  arr[index] = pre;
  return;
}

int main() {
  cin>>N;
  for(int i=0;i<N;++i) cin>>A[i];
  int u, v;
  for(int i=0;i<N-1;++i) {
    cin>>u>>v;
    u--;
    v--;
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  solve(0, -1);
  for(int i=0;i<N;++i) cout<<ans[i]<<endl;
}



Measured memory_bytes: 33236
#include <cstdio>
#include <vector>

int n,m;
int a[100010];
std::vector<int> b[100010];

int main(void)
{
    int i,j;
    long long answer,result;
    int x;

    //freopen("x.in","r",stdin);

    scanf("%d %d",&n,&m);
    for(i = 1;i <= n;++i)
    {
        scanf("%d",&a[i]);
        if(a[i] == a[i - 1])
            --i,--n;
        else
            b[a[i]].push_back(i);
    }

    answer = 0;
    x = 0;
    for(i = 2;i <= n;++i)
        if(a[i - 1] <= a[i])
            answer += a[i] - a[i - 1];
        else
            answer += a[i],++x;
    result = answer;

    for(i = 1;i <= m - 1;++i)
    {
        for(j = 0;j < b[i].size();++j)
        {
            if(b[i][j] == 1)
                ++x,++answer;
            else
                answer += a[b[i][j]] - a[b[i][j] - 1];
            if(a[b[i][j] - 1] > a[b[i][j]])
                answer += m;
            if(b[i][j] == n)
                --x,--answer;
        }
        answer -= x;
        if(answer < result)
            result = answer;
    }
    printf("%lld\n",result);

    return 0;
}

Measured memory_bytes: 5376