akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
const int MAX_V=100000;

int par[MAX_V];				//unionfind??¨ ????´????????£????????????????
int m[MAX_V];				//unionfind??¨ ????´??£?????????£???????????£???????????????????????????????????? ?????????????????????blog?????????
							//?????????????°??????????????????§?????????,semi???????°?????????????????????????????????£?????????(???????????????????????????)

int I;			//dfs?????¨??????id???????????¨
int parent[MAX_V];			//parent[v] = dfs??¨T??§???v??????
int vertex[MAX_V];			//vertex[i] = dfs??????i???????????????
int semi[MAX_V];			//semi[v] = v			if v?????????step2??????????????????
							//			sdom(v)???number		otherwise
int U[MAX_V];				//U[w] = w????????????,step3??§?±???????Cor1???u
int idom[MAX_V];			//idom[v] = idom(v) ???????????????
vector<int> bucket[MAX_V];		//bucket[v] = ???????????§??????sdom(x)=v?????????x?????????(?????????step3???????????£???????????????)
vector<int> G[MAX_V],rG[MAX_V];		//?????¨?????°????????¨,?????????????????????????????????

//unionfind????????????
void init(int N){
	rep(i,N) par[i]=i,m[i]=i;
}
int find(int v){
	if(par[v]==v) return v;
	int r=find(par[v]);
	if(semi[m[v]]>semi[m[par[v]]]) m[v]=m[par[v]];
	return par[v]=r;
}
int EVAL(int v){
	find(v);
	return m[v];
}
void LINK(int x,int y){
	par[y]=x;
}
//unionfind???????????§

void dfs(int v){			//dfs??¨
	semi[v]=I;
	vertex[I++]=v;
	for(int u:G[v]) if(semi[u]<0){
		parent[u]=v;
		dfs(u);
	}
}
void makedomtree(int N,int r){
	init(N);
	rep(i,N) semi[i]=-1;
	dfs(r);									//step1
	for(int i=N-1;i>0;i--){
		//step2
		int w=vertex[i];
		for(int v:rG[w]){
			int u=EVAL(v);
			chmin(semi[w],semi[u]);
		}
		bucket[vertex[semi[w]]].pb(w);		//bucket?????´??°
		//????????????step3
		for(int v:bucket[parent[w]]) U[v]=EVAL(v);
		bucket[parent[w]].clear();			//step3???????????£??????bucket???????¶????
		LINK(parent[w],w);					//????????????
	}
//	semi[0]=-1;
	//step4
	for(int i=1;i<N;i++){
		int w=vertex[i];
		int u=U[w];
//		show(w);
//		show(u);
		if(semi[w]==semi[u]) idom[w]=semi[w];
		else idom[w]=idom[u];
	}

	for(int i=1;i<N;i++){				//idom[w]????????????vertex id????????????????????????
		int w=vertex[i];
		idom[w]=vertex[idom[w]];
	}
	idom[r]=-1;
}
int main(){
	int N,M;
	cin>>N>>M;
	rep(i,M){
		int a,b;
		cin>>a>>b;
		a--,b--;
		G[a].pb(b);
		rG[b].pb(a);
	}
	makedomtree(N,0);
//	rep(v,N) printf("sdom[%d]=%d\n",v,semi[v]);
//	rep(v,N) printf("idom[%d]=%d\n",v,idom[v]);
	int Q;
	cin>>Q;
	rep(tt,Q){
		int v;
		cin>>v;v--;
		int ans=idom[v];
		if(ans==0) ans=v;
		cout<<ans+1<<endl;
	}
}

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

int main() {
	string s;
	cin >> s;
	if (s[2] == s[3] && s[4] == s[5]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

int main() {
    string a, b;

    cin >> a >> b;

    int n = atoi((a + b).c_str());

    int i = 1;

    while (i * i < n) {
        i++;
    }

    if (i * i == n) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define L(i, m, n) for(int i(m);i < n;i++)
#define pb push_back
#define D(X) cout<<"  "<<#X": "<<X<<endl;
#define in(x) cin >> x
#define SZ(X) int(X.size())
#define ff first
#define ss second
#define RF(X) freopen(X, "r", stdin)
#define WF(X) freopen(X, "w", stdout)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<int, string> pis;
typedef vector<string> vs;
typedef pair<pair<int, int>, pair<int, int > > piiii;
const int MOD=1000000007;
ll n,m,ans1,ans2;
ll fact[100005];
int main(){
	fact[0]=fact[1]=1;
	L(i,2,100001) fact[i] = (fact[i-1] * i)%MOD;
	scanf("%lld%lld",&n,&m);
	int evenpos=(n+m)/2;
	int oddpos=(n+m)-evenpos;
	//~ D(n);D(m);D(evenpos);D(oddpos);
	if(evenpos==n && oddpos==m){
		ans1=((fact[n]%MOD)*(fact[m]%MOD))%MOD;
	}
	if(evenpos==m && oddpos==n){
		ans2=((fact[m]%MOD)*(fact[n]%MOD))%MOD;
		
	}
	ll ans= ((ans1%MOD) + (ans2%MOD))%MOD;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1024
N,K = gets.split.map(&:to_i)
ss = []
maxd = {}
N.times{
  t,d = gets.split.map(&:to_i)
  ss << [d,t]
  maxd[t] = [maxd[t] || 0, d].max
}
#p tc
ss.sort!.reverse!
score = 0
used = {}
ss[0...K].each{ |d,t| score += d; used[t] = (used[t] || 0) + 1 }
x = used.keys.size
unused = maxd.keys.reject{ |t| used[t] }.map{ |t| maxd[t] }.sort

fs = { x => score }
#p tc.keys, ss
(0...K).reverse_each{ |i|
  break if unused.size == 0
  d,t = ss[i]
  next if used[t] <= 1
  a = unused.pop
  x += 1
  score = score - d + a
  fs[x] = score
  used[t] -= 1
}
p fs.map{ |x,s| x**2 + s }.max


Measured memory_bytes: 22272
#include <bits/stdc++.h>
#define rep(n) for(int I = 0; (I) < (n); ++(I) )
#define repeat(i, n) for( int i = 0; (i) < (n); ++(i) )
#define repeat_to(i, n) for( int i = 0; (i) <= (n); ++(i) )
#define repeat_from(i, m, n) for( int i = (m); (i) < (n); ++(i) )
#define repeat_from_to(i, m, n) for( int i = (m); (i) <= (n); ++(i) )
#define el cout << endl
#define dump(x) cout << " " << #x << "=" << x
#define vdump(v) for(size_t T=0; T<v.size(); ++T){cout << " " << #v << "[" << T << "]=" << v[T];} cout << endl
using namespace std;
using lint = long long;
using ld = long double;

// バイナリーインデクスドツリー
template <class T>
struct binary_indexed_tree {
    int n;
    vector<T> x;
    binary_indexed_tree(int n_ = 0) : n(n_), x(n + 1, 0) {}
    int size() const { return n; }
    T sum(int r) const {
        T S = 0;
        for (r = r - 1; r >= 0; r = (r & (r + 1)) - 1) S += x[r];
        return S;
    }
    T sum(int l, int r) const { return sum(r) - sum(l); }
    void add(int k, const T &a) {
        for (; k < n; k |= k + 1) x[k] += a;
    }
    void set(int k, const T &a) { add(k, a - sum(k, k + 1)); }
};

int main(void) {
    lint n, k; cin >> n >> k;
    vector<lint> a(n); repeat(i, n) cin >> a[i];
    repeat(i, n) a[i] -= k;
    
    vector<lint> s(n+1);
    s[0] = 0;
    repeat(i, n) s[i+1] = s[i] + a[i];
    
    // 座標圧縮 ソート → 一意要素を前に → 後半に残る重複要素を削除 → 二分探索で元の数字のindexを調べる
    auto t = s;
    sort(t.begin(), t.end());
    auto it = unique(t.begin(), t.end());
    t.erase(it, t.end());
    for(auto &e: s) {
        e = lower_bound(t.begin(), t.end(), e) - t.begin();
    }
    
    // 転倒数カウント
    lint ans = 0;
    lint N = *max_element(s.begin(), s.end());
    binary_indexed_tree<lint> bit(N+1);
    
    repeat(i, n+1) {
        ans += bit.sum(s[i]+1);
        bit.add(s[i], 1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6528
import functools
from collections import*
@functools.lru_cache(maxsize=None)
def Knapsack(N,W):
    for i in range(N):
        w,v=map(int,input().split())
        for k,b in d.copy().items():
            if k+w<=W:
                d[k+w]=max(d[k+w],b+v)
    return max(d.values())
N,W=map(int,input().split())   #pypyで実行！
d=defaultdict(int)
d[0]=0
print(Knapsack(N,W))

Measured memory_bytes: 4116
#include <iostream>
#include <string>

int main()
{
	std::string s1, s2, s3;
	std::cin >> s1 >> s2 >> s3;
	std::cout << static_cast<char>(toupper(s1[0])) << static_cast<char>(toupper(s2[0])) << static_cast<char>(toupper(s3[0]));
	return 0;
}

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

int main(void){
    string s;
    cin >> s;
    for(int bit=0; bit<(1<<3); bit++){
        int svn = s[0]-'0';
        for(int i=0; i<3; i++){
            if(bit & (1<<i)) svn += s[i+1]-'0';
            else svn -= s[i+1]-'0';
        }
        if(svn == 7){
            for(int i=0; i<3; i++){
                if(bit & (1<<i)) s.insert(2*i+1, "+");
                else s.insert(2*i+1, "-");
            }
            s += "=7";
            goto SKIP;
        }
    }
SKIP:
    cout << s << '\n';
    return 0;
}

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

using namespace std;

#define ll long long
ll input(){
	ll x=0,f=0;char ch=getchar();
	while(ch<'0'||ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return f? -x:x;
}

const int N=1e5+7;
int a[107];
int dp[N];

int main(){
	int n=input(),k=input();
	for(int i=1;i<=n;i++){
		a[i]=input();
	}

	for(int i=1;i<=k;i++){
		for(int j=1;j<=n;j++){
			if(i-a[j]>=0)
				dp[i]|=!(dp[i-a[j]]);
		}
	}

	if(dp[k]) printf("First\n");
	else printf("Second\n");
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <float.h>
#include <random>

#define repeat(i,n) for (int i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
#define debugArrayP(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge].first<< " " << x[hoge].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1e9+7;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A,B;cin>>A>>B;
  cout<<(A>=13? B:A>=6? B/2:0)<<endl;
  return 0;
}


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

int main() {
	long long L, C;
	bool used[110] = {};
	stack<long long> ST;
	cin >> L;
	for (int i = 1; i <= L; i++) {
		cin >> C;
		if (C > 0) {
			if (used[C]) {
				cout << i << endl;
				return 0;
			}
			ST.push(C);
			used[C] = true;
		}
		else {
			if (ST.empty()) {
				cout << i << endl;
				return 0;
			}
			if (ST.top() != -C) {
				cout << i << endl;
				return 0;
			}
			ST.pop();
			used[-C] = false;
		}
	}
	cout << "OK" << endl;
}


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

int N,M,ans=0;
bool check(vector<vector<int>> &data,int x,int y){
  for(int i=0;i<data.at(x).size();i++){
    if(data.at(x).at(i)==y)return true;
  }
  return false;
}

int main(){
  cin>>N>>M;
  vector<vector<int>> data(N+1);
  for(int i=0;i<M;i++){
    int a,b;cin>>a>>b;
    data.at(a).push_back(b);data.at(b).push_back(a);
  }
  vector<int> nd(N-1);
  for(int i=0;i<N-1;i++)nd.at(i)=i+2;
  sort(nd.begin(),nd.end());
  do{
    int p=0;
    if(!check(data,1,nd.at(p)))continue;
    if(nd.size()==1)goto trip;
    while(p+1){
      if(!check(data,nd.at(p),nd.at(p+1))){p=-1;break;}
      p++;
      if(p>N-3)break;
    }
    if(p==-1)continue;
    trip:
    ans++;
  }while(next_permutation(nd.begin(),nd.end()));
  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main(){
	int n, l;
	string s[100];
	cin >> n >> l;
	for(int i = 0; i < n; i++) cin >> s[i];
	sort(s, s + n);
	for(int i = 0; i < n; i++) cout << s[i];
	cout << endl;
	return 0;
}

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

using ll = long long;
using namespace std;

int main(void) {
	string s;
	cin >> s;
	
	set<char> st;
	for(int i = 0; i < s.size(); ++i) {
		st.insert(s[i]);
	}
	
	if( st.size() == 2 ) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説を参考に作成したソースコード
 */
public class Main {

	/** 大きい値の定義 */
	private static final int INF = Integer.MAX_VALUE >> 1;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int ma = scanner.nextInt();
			int mb = scanner.nextInt();
			int[] a = new int[n], b = new int[n], c = new int[n];
			IntStream.range(0, n).forEach(i -> {
				a[i] = scanner.nextInt();
				b[i] = scanner.nextInt();
				c[i] = scanner.nextInt();
			});
			int result = getResult(n, ma, mb, 0, 0, 0, a, b, c, new HashMap<>());
			System.out.println((result < INF) ? result : -1);
		}
	}

	/**
	 * @param n
	 * @param ma
	 * @param mb
	 * @param now  現在計算しているindex
	 * @param nowA いままで使ったAの合計
	 * @param nowB いままで使ったBの合計
	 * @param a
	 * @param b
	 * @param c
	 * @param map  既に計算した結果を保存するマップ
	 * @return 計算結果
	 */
	private static int getResult(final int n, final int ma, final int mb, int now, int nowA, int nowB, final int[] a,
			final int[] b, final int[] c, final Map<List<Integer>, Integer> map) {
		if (now >= n) {
			return ((nowA > 0) && (nowB > 0) && (nowA * mb == nowB * ma)) ? 0 : INF;
		}
		List<Integer> key = Arrays.asList(now, nowA, nowB);
		Integer result = map.get(key);
		if (null == result) {
			result = Math.min(getResult(n, ma, mb, now + 1, nowA, nowB, a, b, c, map),
					getResult(n, ma, mb, now + 1, nowA + a[now], nowB + b[now], a, b, c, map) + c[now]);
			map.put(key, result);
		}
		return result;
	}
}


Measured memory_bytes: 170332
import sys
input = sys.stdin.readline

MAX = 2*10**5+100
MOD = 998244353
fact = [0]*MAX #fact[i]: i!
inv = [0]*MAX #inv[i]: iの逆元
finv = [0]*MAX #finv[i]: i!の逆元
fact[0] = 1
fact[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
    
for i in range(2, MAX):
    fact[i] = fact[i-1]*i%MOD
    inv[i] = MOD-inv[MOD%i]*(MOD//i)%MOD
    finv[i] = finv[i-1]*inv[i]%MOD

def C(n, r):
    if n<r:
        return 0
    if n<0 or r<0:
        return 0
    return fact[n]*(finv[r]*finv[n-r]%MOD)%MOD

N, M, K = map(int, input().split())
ans = 0

for i in range(N):
    if N-1-i<=K:
        ans += C(N-1, i)*M*pow(M-1, i, MOD)
        ans %= MOD

print(ans)

Measured memory_bytes: 75856
#include<bits/stdc++.h>
using namespace std;
int n,k,dist[100005],way[100005],fa[100005];
vector<int> g[100005];
bool vis[100005];
void dfs(int x)
{
	vis[x]=1;
	int cnt=-1;
	for(int i=0;i<g[x].size();i++)
		if(!vis[g[x][i]])
		{
			if(g[x][i]!=fa[x])
				cnt++;
			way[g[x][i]]=max(k+1-dist[g[x][i]],k-2)-cnt;
			dfs(g[x][i]);
		}
}
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n-1;i++)
	{
		int a,b;
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	queue<int> q;
	q.push(1);
	dist[1]=1;
	while(!q.empty())
	{
		int p=q.front();
		q.pop();
		for(int i=0;i<g[p].size();i++)
			if(!dist[g[p][i]])
			{
				dist[g[p][i]]=dist[p]+1;
				fa[g[p][i]]=p;
				q.push(g[p][i]);
			}
	}
	way[1]=k;
	dfs(1);
	long long ans=1;
	for(int i=1;i<=n;i++)
	{
		ans*=way[i];
		ans%=1000000007;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 10496
#include<iostream>
using namespace std;
int main(){
  int m,f,r;
  cin >> m >> f >> r;
  while(m!=-1||f!=-1||r!=-1){
    if(m==-1||f==-1) cout << "F" << endl;
    else if(m+f>=80) cout << "A" << endl;
    else if(m+f>=65) cout << "B" << endl;
    else if(m+f>=50) cout << "C" << endl;
    else if(m+f>=30)
      if(r>=50) cout << "C" << endl;
      else cout << "D" << endl;
    else cout << "F" << endl;

    cin >> m >> f >> r;
  }
  return 0;
}


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

int64_t MOD = 1000000007;
int64_t MAX = 9223372036854775807;
double PI = 3.141592653589793;

int64_t gcd(int64_t p, int64_t q)
{
    if (p < q)
        swap(p, q);

    if (p % q == 0)
        return q;
    else
        return gcd(q, p % q);
}

map<int64_t, int64_t> bunkai(int64_t N)
{
    map<int64_t, int64_t> hist;

    int64_t a = 2;
    while (N >= a * a)
    {
        if (N % a == 0)
        {
            hist[a]++;
            N /= a;
        }
        else
            a++;
    }
    hist[N]++;
    return hist;
}

int main()
{
    int64_t A, B, ans = 0;
    cin >> A >> B;
    int64_t g = gcd(A, B);
    if (g > 1)
        ans++;
    auto x = bunkai(g);
    cout << ans + x.size();
}

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

int main() {
	// your code goes here
	int n;
	cin >> n;
	int a[n] = {0};
	int b[n] = {0};
	int c[n-1] = {0};
	int ans = 0;
	for(int i=0; i<n; i++)
	{
		cin >> a[i];
	}
	for(int i=0; i<n; i++)
	{
		cin >> b[i];
		ans += b[i];
	}
	for(int i=0; i<n-1; i++)
	{
		cin >> c[i];
	}
	for(int j=0; j<n; j++)
	{
		if((a[(j+1)] - a[j]) == 1)
		{
			ans += c[a[j]-1];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())

m_cake = N // 4
a = 0

for i in range(m_cake + 1):
    m_donuts = (N - 4 * i) % 7
    if m_donuts == 0:
        a = 1

if a == 1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

const int MAX = 1e5 + 10;
int N, M;
int A[MAX];

int main(void) {
    cin >> N >> M;
    REP(i, N) {
        cin >> A[i];
    }
    
    priority_queue<int> pq;
    REP(i, N) pq.emplace(A[i]);
    while (!pq.empty() && M) {
        auto cur = pq.top();
        pq.pop();

        cur /= 2;
        M--;
        if (cur) pq.emplace(cur);
    }

    LL sum = 0;
    while (!pq.empty()) {
        sum += pq.top();
        pq.pop();
    }

    cout << sum << endl;
}


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

int main() {
    int A, B, C;

    cin >> A >> B >> C;

    if ( (A == 5 && B == 5 && C ==7) || (A == 5 && B == 7 && C == 5) || (A == 7 && B == 5 && C == 5) ){
        cout << "YES" << endl;
    } else {
        cout << "NO"   << endl;
    }

    return 0;

}


Measured memory_bytes: 256
n,m=gets.split.map(&:to_i).sort
f=[1]
mod=1000000007
100000.times do |i|
  f << f[-1] * (i+1) % mod
end
if n==m
  puts f[n] ** 2 * 2 % mod
elsif n+1==m
  puts f[n] * f[m] % mod
else
  puts 0
end

Measured memory_bytes: 2684
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define srt(i) sort(i.begin(), i.end())
#define rvt(i) sort(i.begin(), i.end(), greater<int>())

char itoc(int i){
  string s = "zabcdefghijklmnopqrstuvwxy";
  return s.at(i);
}

int main()
{
    int h,w,k;
    cin >> h >> w >>k;

    vector<vector<char> > table(h+1, vector<char>(w+1, '-'));
    rep(i,h){
      string cline;
      cin >> cline;
      rep(j,w){
        table.at(i).at(j) = cline.at(j);
      }
    }

    int ans=0;
    for (int tmp = 0; tmp < (1 << h); tmp++) {
      bitset<6> s(tmp);
       for (int tmp2 = 0; tmp2 < (1 << w); tmp2++) {
        bitset<6> s2(tmp2);

        vector<vector<char> > ttable(h+1, vector<char>(w+1, '-'));
        rep(i,h) copy(table.at(i).begin(), table.at(i).end(), ttable.at(i).begin());
        rep(i,h){
          if(s.test(i)) rep(j,w) ttable.at(i).at(j) = '.';
        }
        rep(j,w){
          if(s2.test(j)) rep(i,h) ttable.at(i).at(j) = '.';
        }

        int cnt=0;
        rep(i,h)rep(j,w) if(ttable.at(i).at(j)=='#') cnt++;
        if(cnt==k) {
          ans++;
        }
       }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3628
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define fi first
#define se second
#define pb(i) push_back(i)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define mes(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 200005;
const int INF = 0x3f3f3f3f;
const int inf = - INF;
const int mod = 1e9+7;
const double pi = acos(-1.0);

int a[N];
int main(){
    int n;
    scanf("%d",&n);
    rep(i,0,n-1)
        scanf("%d",&a[i]);
    sort(a,a+n);
    int flag=1;
    rep(i,0,n-2){
        if(a[i]==a[i+1]){
            flag=0;
            break;
        }
    }
    printf(flag?"YES\n":"NO\n");
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int n,count=0,i,h,sum=0,zum=0;
cin>>n;
long long int a[n],b[n];
for(i=0;i<n;i++)
{
    cin>>a[i];
}
for(i=0;i<n;i++)
{
    cin>>b[i];
}
for(i=0;i<n;i++)
{
    if(b[i]<a[i])
{
    sum=sum+a[i];
    zum=zum+b[i];
}
}
h=sum-zum;
cout<<h;
}


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

int main()
{
    ll w, n;
    cin>>n>>w;
    vector <ll> wt(n + 1), val(n + 1);
    for(ll i = 1; i <= n; i++)
    cin>>wt[i]>>val[i];
    vector <vector <ll> > dp(n + 1, vector <ll> (w + 1, 0));
    for(ll i = 1; i <= n; i++)
    {
        for(ll j = 1; j <= w; j++)
        {
            if(j >= wt[i])
            dp[i][j] = max(val[i] + dp[i - 1][j - wt[i]], dp[i - 1][j]);
            else
            dp[i][j] = dp[i - 1][j];
        }
    }
    cout<<dp[n][w]<<"\n";
    return 0;
}

Measured memory_bytes: 80256
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
static const int MAX = 10000;
static const int INFTY = (1 << 20);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector<pair<int, int> > adj[MAX];

void dijkstra() {
	priority_queue<pair<int, int> > PQ;
	int color[MAX];
	int d[MAX];
	for (int i = 0; i < n; i++) {
		d[i] = INFTY;
		color[i] = WHITE;
	}

	d[0] = 0;
	PQ.push(make_pair(0, 0));
	color[0] = GRAY;

	while (!PQ.empty()) {
		pair<int, int> f = PQ.top(); PQ.pop();
		int u = f.second;
		color[u] = BLACK;

		if (d[u] < f.first*(-1)) continue;

		for (unsigned int j = 0; j < adj[u].size(); j++) {
			int v = adj[u][j].first;
			if (color[v] == BLACK) continue;
			if (d[v] > d[u] + adj[u][j].second) {
				d[v] = d[u] + adj[u][j].second;
				PQ.push(make_pair(d[v] * (-1), v));
				color[v] = GRAY;
			}
		}
	}

	for (int i = 0; i < n; i++) {
		cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
	}
}

int main() {
	int k, u, v, c;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> v >> c;
			adj[u].push_back(make_pair(v, c));
		}
	}

	dijkstra();

	return 0;
}

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

int main(){
    ll n,s=0;
    cin >> n;
    vector<ll> a(n),d(n);
    string ans = "YES";
    for(int i = 0;i < n;i ++){
        cin >> a[i];
        if(i) d[i] = a[i]-a[i-1];
        s += a[i];
    }
    d[0] = a[0]-a[n-1];
    if((2*s)%(n*(n+1))) {cout << "NO" << endl;return 0;}
    ll k = (2*s)/(n*(n+1)),sm=0;
    for(int i = 0;i < n;i ++){
        d[i] -= k;
    }
    for(int i = 0;i < n;i ++){
        if(d[i]>0) {ans="NO";break;}
        else {
            ll m;
            if(d[i]%n) {ans="NO";break;}
            else {m=abs(d[i]/n);sm += m;}
        }
    }
    if(sm!=k) ans = "NO";
    cout << ans << endl;
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    ll sum = 0;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
        sum ^= a[i];
    }

    rep(i, n) {
        ll tmp = sum ^ a[i];
        if (i != 0)
            cout << " ";
        cout << tmp;
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3968
#include<cstdio>
#include<cstring>
#define LL long long
using namespace std;
LL len;
LL num[3000],ans;
char s[2000001];
int main()
{
	LL i;
	scanf("%s",s+1);
	len=strlen(s+1);
	ans=(len*(len-1))/2;
	for (i=1;i<=len;i++)
	  num[s[i]-'a']++;
	for (i=0;i<=27;i++)
	  ans-=(num[i]*(num[i]-1))/2;
	printf("%lld",ans+1);
}

Measured memory_bytes: 384
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep4(i, a, b, c) for (int i = int(a), i##__b = int(b), i##__c = int(c); i < i##__b; i += i##__c)
#define rep1(n) rep4(i, 0, n, 1)
#define rep2(i, n) rep4(i, 0, n, 1)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define REP(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep3(i, a, b) for (int i = int(b) - 1, i##__a = int(a); i >= i##__a; i--)
#define rrep1(n) rrep3(i, 0, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep4(i, a, b, c) for (int i = int(a + (b - a - 1) / c * c), i##__a = int(a), i##__c = int(c); i >= i##__a; i -= i##__c)
#define RREP(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define FOREACH(i, x) for (auto &i : x)
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define mt make_tuple
#define print(x) cout << x << endl;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 9;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vbool = vector<bool>;
using vvbool = vector<vector<bool>>;
using vstring = vector<string>;
template <class T> using vv = vector<vector<T>>;
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;}

struct Point {int x, y; Point(int x, int y):x(x), y(y){}};
int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1};
pii dvs[] = {mp(1, 0), mp(0, 1), mp(-1, 0), mp(0, -1)};
// clang-format on


int main() {
    int n, x;
    for (cin >> n >> x; !(n == 0 && x == 0); cin >> n >> x) {
        int ans = 0;
        REP(a, 1, n + 1) {
            REP(b, 1, a) {
                REP(c, 1, b) {
                    if (a + b + c == x) {
                        ans += 1;
                    }
                }
            }
        }
        print(ans);
    }
}



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

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

    int N, K;  cin >> N >> K;
    vector<int> D(K);
    for (int i = 0; i < K; i++) cin >> D[i];

    for (int i = N; i <= 10*N; i++) {
        int tmp = i;
        bool flag;
        while (tmp != 0) {
            flag = false;
            int d = tmp % 10;
            for (int j = 0; j < D.size(); j++) {
                if (D[j] == d) {
                    flag = true;
                    break;
                }
            }
            if (flag) break;
            tmp /= 10;
        }
        if (!flag) {
            cout << i << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, init, n) for(int i = init; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
 
using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};
 
const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);
 
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int t, n;
    
    while(cin >> t, t)
    {
        cin >> n;
        int sum = 0;

        REP(i, n)
        {
            int s, f;
            cin >> s >> f;

            sum += f - s;
        }

        cout << (t <= sum ? "OK" : to_string(t - sum)) << endl;
    }
    return 0;
}
 


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
#define mp            make_pair
template<class T, class S> inline bool minup(T& m, const S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, const S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-10;

template<typename T> ostream& operator <<(ostream& r, const vector<T> t){vrep(v,t)r<<*v<<(v+1==t.end()?"":" ");return r;}
template<typename T> ostream& operator <<(ostream& r, const pair<vector<T>, int> p){int n=p.second;minup(n,p.first.size());rep(i,n-1)r<<p.first[i]<<' ';r<<p.first[n-1];return r;}
template<typename T> ostream& operator <<(ostream& r, const pair<T*, int> p){int n=p.second-1;rep(i,n)r<<p.first[i]<<' ';return r<<p.first[n];}
template<typename T, size_t S> ostream& operator <<(ostream& r, const T (&a)[S]){rep(i,S-1)r<<a[i]<<' ';return r<<a[S-1];}


int N;
map<vi, int> d[2];
queue<pair<vi, int> > que[2];

int main(int argc, char *argv[])
{
  cin >> N;
  vi A(N), S(N);
  rep(i, N) cin >> A[i];
  S = A;
  sort(ALL(S));

  d[0][A] = 0;
  que[0].push(mp(A, 0));
  while(!que[0].empty()){
    vi top = que[0].front().first;
    int cost = que[0].front().second;
    que[0].pop();
    if(top == S){
      cout << cost << endl;
      return 0;
    }
    if(cost >= 4) break;
    rep(j, N) rep(i, j){
      vi t = top;
      reverse(t.begin() + i, t.begin() + j + 1);
      if(t != A && !d[0][t]){
        d[0][t] = cost + 1;
        que[0].push(mp(t, cost + 1));
      }
    }
  }
  
  d[1][S] = 0;
  que[1].push(mp(S, 0));
  while(!que[1].empty()){
    vi top = que[1].front().first;
    int cost = que[1].front().second;
    que[1].pop();
    if(d[0][top]){
      cout << cost + d[0][top] << endl;
      return 0;
    }
    if(cost >= 4) break;
    rep(j, N) rep(i, j){
      vi t = top;
      reverse(t.begin() + i, t.begin() + j + 1);
      if(!d[1][t]){
        d[1][t] = cost + 1;
        que[1].push(mp(t, cost + 1));
      }
    }
  }

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

Measured memory_bytes: 104464
$D = []
$inf = 2147483647
$n=1
def init(n_)
  $n=1
  while($n<n_) do $n*=2 end
  0.upto(2*$n-2){
    $D<<$inf
  }
end
def update(a,b,k,l,r,x)
  if(r<=a||b<=l)
    return
  end
  if(a<=l&&r<=b)
    $D[k]=x
  else
    if $D[k]
      $D[k*2+1]=$D[k]
      $D[k*2+2]=$D[k]
      $D[k]=nil
    end
    update(a,b,k*2+1,l,(l+r)/2,x)
    update(a,b,k*2+2,(l+r)/2,r,x)
  end
end
def find(a,b,k,l,r)
  if(r<=a||b<=l)
    return $inf
  end
  if $D[k]
    return $D[k]
 else
    return [find(a,b,k*2+1,l,(l+r)/2),find(a,b,k*2+2,(l+r)/2,r)].min
  end
end
n, q = gets.split.map(&:to_i)
init(n)
q.times{
  u,s,t,x = gets.split.map(&:to_i)
  if(u == 0)
    update(s,t+1,0,0,$n,x)
  else
    puts find(s,t+1,0,0,$n) if $n!=1
    puts $D[0] if $n==1
  end
}



Measured memory_bytes: 9148
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  int N;
  cin >> N;
  vector<long long> A(N);
  rep(i, N)
  {
    cin >> A[i];
  }
  SORT(A);
  rep(i, N - 1)
  {
    A[i + 1] += A[i];
  }
  REVERSE(A);
  int ans = 1;
  rep(i, N - 1)
  {
    if (2 * A[i + 1] >= (A[i] - A[i + 1]))
      ans++;
    else
      break;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func rScan() []rune {
	return []rune(Scan())
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}
func fSum(a []float64) float64 {
	x := 0.
	for _, v := range a {
		x += v
	}
	return x
}
func bOut(f bool, x string, y string) {
	if f {
		fmt.Println(x)
	} else {
		fmt.Println(y)
	}
}
func mod(x, d int) int {
	x %= d
	if x < 0 {
		x += d
	}
	return x
}
func iSSPrint(x []int) {
	fmt.Println(strings.Trim(fmt.Sprint(x), "[]"))
}

var lp int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, lp)
	sc.Split(bufio.ScanWords)
	n := iScan()
	c := iScan()
	d := make([][]int, c)
	for i := 0; i < c; i++ {
		d[i] = iSScan(c)
	}
	x := make([][]int, 3)
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			x[(i+j)%3] = append(x[(i+j)%3], iScan()-1)
		}
	}
	cs := make([][]int, 0, c)
	for i := 0; i < c; i++ {
		p, q, r := 0, 0, 0
		for _, v := range x[0] {
			p += d[v][i]
		}
		for _, v := range x[1] {
			q += d[v][i]
		}
		for _, v := range x[2] {
			r += d[v][i]
		}
		cs = append(cs, []int{p, q, r})
	}
	ans := lp * lp
	for i := 0; i < c; i++ {
		for j := 0; j < c; j++ {
			for k := 0; k < c; k++ {
				if i != j && j != k && k != i {
					ans = smaller(ans, cs[i][0]+cs[j][1]+cs[k][2])
				}
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 8392
import java.awt.Point;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static long startTime = System.currentTimeMillis();
	static final int[] DR = { 1, 0, -1, 0 };
	static final int[] DC = { 0, 1, 0, -1 };
	static int H, W, gr, gc;
	static char[][] F;

	public static void main(String[] args) {
		H = sc.nextInt();
		W = sc.nextInt();
		F = new char[H][];
		int stone = 0;
		for (int i = 0; i < H; ++i) {
			F[i] = sc.next().toCharArray();
			for (int j = 0; j < W; ++j) {
				if (F[i][j] == 'o') {
					++stone;
				} else if (F[i][j] == '@') {
					gr = i;
					gc = j;
				}
			}
		}
		boolean ans;
		if (stone >= 3) {
			if (H > 1 && W > 1) {
				ans = true;
			} else {
				ans = search();
			}
		} else if (stone == 2) {
			if (H > 1 && W > 1 && (gr == 0 || gr == H - 1 || gc == 0 || gc == W - 1)) {
				ans = true;
			} else {
				ans = search();
			}
		} else {
			ans = search();
		}
		System.out.println(ans ? "yes" : "no");
	}

	static boolean search() {
		HashSet<ArrayList<Point>> cur = new HashSet<>();
		ArrayList<Point> init = new ArrayList<>();
		for (int i = 0; i < H; ++i) {
			for (int j = 0; j < W; ++j) {
				if (F[i][j] == 'o') init.add(new Point(j, i));
			}
		}
		cur.add(init);
		OUT: for (int i = 0;; ++i) {
			HashSet<ArrayList<Point>> next = new HashSet<>();
			for (ArrayList<Point> st : cur) {
				if (System.currentTimeMillis() - startTime > 900) {
					break OUT;
				}
				for (Point p : st) {
					for (int dir = 0; dir < 4; ++dir) {
						ArrayList<Point> moved = new ArrayList<>();
						Point mp = null;
						for (Point np : st) {
							moved.add(new Point(np.x, np.y));
							if (np.equals(p)) mp = moved.get(moved.size() - 1);
						}
						while (true) {
							int nx = mp.x + DC[dir];
							int ny = mp.y + DR[dir];
							if (nx < 0 || nx >= W || ny < 0 || ny >= H) {
								if (mp.x == gc && mp.y == gr) return true;
								break;
							}
							for (Point np : moved) {
								if (np == mp) continue;
								if (np.x == nx && np.y == ny) {
									if (mp.x == gc && mp.y == gr) return true;
									mp = np;
									break;
								}
							}
							mp.x = nx;
							mp.y = ny;
						}
						//						System.out.println(moved);
						Collections.sort(moved, (Point p1, Point p2) -> {
							if (p1.x != p2.x) return Integer.compare(p1.x, p2.x);
							return Integer.compare(p1.y, p2.y);
						});
						next.add(moved);
					}
				}
			}
			cur = next;
		}
		return false;
	}

}

Measured memory_bytes: 545412
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i < (n);i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define SCANF(i) int i;scanf("%d",&i)
typedef long long ll;
using namespace std;
using P = pair<int,int>;
const long long INF = 1LL << 60;
const int IINF=100000000;
const int MOD = (int)1e9 + 7;
//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    //sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
vector<int> dx={1,0,-1,0};vector<int> dy={0,-1,0,1};

signed main () {
    vector<string> signlist={"AC","WA","TLE","RE"};
    map<string,int> cntlist;
    cntlist["AC"]=0;
    cntlist["WA"]=0;
    cntlist["TLE"]=0;
    cntlist["RE"]=0;
    ll n;cin >> n;
    REP(i,n){
        string tmp;cin >> tmp;
        cntlist[tmp]++;
    }
    for(string s : signlist){
        cout << s << " x " << cntlist[s] << endl;
    }
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    ll P, Q, R;
    cin >> P >> Q >> R;
    cout << P + Q + R - std::max(P, std::max(Q, R)) << endl;
    return 0;
}

Measured memory_bytes: 256
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
if !a.include?(1)
    puts -1
    exit
end
count = 1
ans = 0

a.each do |i|
    if i == count
        count += 1
    else
        ans += 1
    end
end

puts ans

Measured memory_bytes: 16772
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { let mut $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { let $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
fn main() {
    input! {
        n: u64,
        a: u64,
        b: u64
    }
    let space = b - a - 1;
    if space % 2 == 0 {
        println!("Borys");
    } else {
        println!("Alice");
    }

}


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

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
*/

using namespace std;

#if DEBUG && !ONLINE_JUDGE
    #include "debug.h"
#else
    #define debug(...)
#endif

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<vector<int> > vvi;
typedef vector<vector<ii> > vvii;

#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define fill(a,x) memset(a,x,sizeof(a))
#define ff first
#define ss second
#define trav(a, x) for(auto& a : x) 
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
const ll INF = 1e18;
const int mod = 1e9 + 7;
ll gcd(ll a,ll b){if (a==0) return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return a*(b/gcd(a,b));}
ll Abs(ll a){if(a>0)return a;return -a;}
ll Ceil(ll a,ll b){if(a%b==0)return a/b;else return a/b+1;}
double Abs(double a){if(a>0)return a;return -a;}

//*X.find_by_order(2) element at index=2
//X.order_of_key(1) how many elements strictly less than 1

//#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_NOde_update> 

inline int pow_(ll x, ll y,ll p){
  int r = 1; while(y){if(y & 1) r = r * x % p; y >>= 1; x = x * x % p;} return r;
}
inline int inv_(int x){return pow_(x, mod - 2, mod);}
inline int add(int a, int b){a += b; if(a >= mod) a -= mod; return a;}
inline int mul(int a, int b){return a * 1LL * b % mod;}
inline int sub(int a, int b){a -= b; if(a < 0) a += mod; return a;}

int main()
{
    #ifdef LOCAL_TEST
    freopen("in.txt","r",stdin);
    //freopen("out.txt", "w", stdout);
    #else
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    #endif
    ll n;
    cin>>n;
    map<string,int> m;
    for(int i=1;i<=n;i++){
        string s;
        cin>>s;
        sort(all(s));
        m[s]++;
    }
    ll ans = 0;
    for(auto it: m){
        ll val = it.second;
        ans += (val)*(val-1)/2;
    }

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

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

int main(){
  string S;
cin>>S;
  int N,count,nocount;
  N=S.size();
count=0,nocount=0;
  for(int i=0;i<N;i++){
if(S[i]=='0'){
  count++;
}
    else{
      nocount++;
    }
  }

    cout<<N-(max(count,nocount)-min(count,nocount))<<endl;


}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cstdlib>
#define rep for(int i = 0; i<n; i++)

using namespace std;

int main()
{	
	int n,t=0,z=0;
	int l[10];

	cin >> n;
	if (n >= 3)
	{
		rep
		{
			cin >> l[i];
			if (l[i] >= l[t] && i > 0) t = i;
		}

		rep
		{
			if (i != t)
			{
				z += l[i];
			}
		}

		if (z > l[t])
		{
			cout << "Yes" << endl;
		}
		else
		{
			cout << "No" << endl;
		}
	}

    return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
c_4=0
c_2=0
for i in range(n):
    if a[i]%4==0:
        c_4+=1
    elif a[i]%2==0:
        c_2+=1
if n%2==0:
    if c_4>=n//2:
        print("Yes")
    else:
        if c_2>=(n-c_4*2):
            print("Yes")
        else:
            print("No")
else:
    if c_4>=n//2:
        print("Yes")
    else:
        if c_2>=(n-c_4*2):
            print("Yes")
        else:
            print("No")

Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
typedef signed long long ll;
 
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

ll lu[100];

int main(){
	int i,j,k,n,m,l,f,x,y,z; string s;
	cin >> n;
	lu[0] = 2;
	lu[1] = 1;
	REP(i, 2, n+1){
		lu[i] = lu[i-1] + lu[i-2];
	}
	cout << lu[n] << endl;
}	

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int prev;
    int now = 1;
    for (int i = 2; i < 1000; i++) {
      prev = now;
      now += i;
      if (b - a == now - prev) {
        System.out.println(now - b);
        return;
      }
    }
  }
}

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

int main() {
  int A, B;
  cin >> A >> B;
  int N = 0;
  for (int i = A; i <= B; i++) {
    if ((i / 10000) % 10 == i % 10) {
      if((i /1000) % 10 == (i / 10) % 10) {
        N++;
      }
    }
  }
  cout << N;
}

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

struct ModCombi
{
    int64_t sup, mod;
    vector<int64_t> fact_vec, inv_vec, if_vec;
    ModCombi(int64_t sup, int64_t mod): sup(sup), mod(mod)
    {
        assert(1 <= sup && sup <= static_cast<int64_t>(1e+7));
        if (sup < 1) sup = 1;
        fact_vec.resize(sup + 1);
        inv_vec.resize(sup + 1);
        if_vec.resize(sup + 1);
        fact_vec.at(0) = fact_vec.at(1) = 1;
        inv_vec.at(1) = 1;
        if_vec.at(0) = if_vec.at(1) = 1;
        for (int64_t i = 2; i <= sup; ++i) {
            fact_vec.at(i) = fact_vec.at(i - 1) * i % mod;
            inv_vec.at(i) = mod - mod / i * inv_vec.at(mod % i) % mod;
            if_vec.at(i) = if_vec.at(i - 1) * inv_vec.at(i) % mod;
        }
    }
    int64_t calc(int64_t n, int64_t k)
    {
        if (n < 0 || sup < n) return 0;
        if (k < 0 || n < k) return 0;
        return fact_vec.at(n) * if_vec.at(k) % mod * if_vec.at(n - k) % mod;
    }
};

int main()
{
    const static int64_t mod = 1e+9 + 7;
    int S;
    cin >> S;
    ModCombi modcombi(S, mod);
    int cnt = 0;

    for (int i = 1; i <= (S + 2) / 3; ++i) {
        cnt += modcombi.calc(S - 2 * i - 1, i - 1);
        cnt %= mod;
    }
    cout << cnt << endl;
}



Measured memory_bytes: 3556
from sys import stdin

n = stdin.readline().strip()

l = 0
r = 0
for i in range(len(n)):
    l += int(n[i]) // 2
    r += int(n[i]) - (int(n[i])//2)

if l==0:
    l = 0
    r = 0
    ls = str(int(n) // 2)
    rs = str(int(n) - (int(n)//2))
    for i in range(len(ls)):
        l += int(ls[i])
    for i in range(len(rs)):
        r += int(rs[i])

print(l+r)


Measured memory_bytes: 3064