akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>/*{{{*/
#include<cctype>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<vector>
using namespace std;
typedef long long lld;
typedef long double lf;
typedef unsigned long long uld;
typedef pair<int,int> pii;
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define ROF(i,a,b) for(int i=(a);i>=(b);--i)
namespace RA{
    int r(int p){return 1ll*rand()*rand()%p;}
    int r(int L,int R){return r(R-L+1)+L;}
}/*}}}*/
/******************heading******************/
const int N=52,P=1e9+7;

int n;
int C[N][N],f[N][N];
//f[i,j]表示一共i个点，最后一层有j个点有奇数个儿子的方案数

int main(){
    scanf("%d",&n);
    C[0][0]=1;
    FOR(i,1,n){
        C[i][0]=1;
        FOR(j,1,i){
            C[i][j]=(C[i-1][j-1]+C[i-1][j])%P;
            //printf("C[%d,%d]=%d\n",i,j,C[i][j]);
        }
    }
    f[1][0]=f[1][1]=n;
    FOR(i,1,n){
        FOR(j,0,i){
            FOR(k,max(j,1),n-i){//枚举下一层一共有k个点
                if((k-j)&1)continue;//根据状态定义，k-j必须是偶数
                int t=k-j>>1;
                //假设下一层是叶子结点，那么可以理解为有(k-j)/2个点是-1，(k+j)/2个点是1
                FOR(x,0,k){//枚举下一层实际上有x个点是-1
                    //这样就要求|x-(k-j)/2|个点需要从-1改成1（或者从1改成-1）
                    //相当于下一层有|x-(k-j)/2|个奇数儿子结点
                    f[i+k][abs(x-t)]=(f[i+k][abs(x-t)]+1ll*f[i][j]*C[n-i][k]%P*C[k][x])%P;
                    //printf("(%d,%d) <- (%d,%d)\n",i+k,abs(x-t),i,j);
                }
            }
            //printf("f[%d,%d]=%d\n",i,j,f[i][j]);
        }
    }
    printf("%d\n",f[n][0]);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define MAX_N 100

int selectionSort(int A[], int N);

int main() {
  int N;
  int A[MAX_N];
  int cnt;
  int i;

  scanf("%d", &N);
  for(i = 0; i < N; ++i) scanf("%d", A+i);

  cnt = selectionSort(A, N);
  for(i = 0; i < N; ++i) printf("%d%c", A[i], " \n"[i==N-1]);
  printf("%d\n", cnt);

  return 0;
}

int selectionSort(int A[], int N) {
  int cnt = 0;
  int minj, tmp;
  int i, j;

  for(i = 0; i < N; ++i) {
    minj = i;
    for(j = i; j < N; ++j) {
      if(A[j] < A[minj]) minj = j;
    }
    tmp = A[i];
    A[i] = A[minj];
    A[minj] = tmp;
    cnt += minj != i;
  }
  return cnt;
}



Measured memory_bytes: 2108
import java.io.*;
public class Main {
	public static void main(String[] args)throws IOException {
		BufferedReader a=new BufferedReader(new InputStreamReader(System.in));
		String n=a.readLine();
		String str=a.readLine();
		String[] i=str.split(" ");
		for (int m=Integer.parseInt(n)-1;m>=0;m--){
			if(m!=0){System.out.print(i[m]+" ");}
			else{System.out.println(i[m]);}
		}
	}
}

Measured memory_bytes: 16916
#include <iostream>
#include <string>
#include <stdlib.h>

using namespace std;
 
int ascSort(const void* v1, const void* v2) {
    const int _v1 = *((const int*)v1);
    const int _v2 = *((const int*)v2);
 
    if ( _v1 < _v2 ) {
        return 1;
    } else if ( _v1 > _v2 ) {
        return -1;
    } else {
        return 0;
    }
}
int main() {
	int n,i,sum=0,min=101;
	cin >> n;
	int s[101];
	for(i=0;i<n;i++){
		cin>>s[i];
		sum += s[i];
		if(s[i]%10!=0 && s[i]<min){
			min = s[i];
		}
	}
	if(sum%10!=0){
		cout << sum <<endl;
	}else if(min != 101){
		cout <<sum-min<<endl;
	}else{
		cout << "0" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  string s;
  cin >> s;
  if(s[0] == 'S'){
    cout << "Cloudy\n";
    return 0;
  }
  if(s[0] == 'C'){
    cout << "Rainy\n";
    return 0;
  }
  cout << "Sunny\n";
}
  

Measured memory_bytes: 3476
n, m = map(int, input().split())
abList = sorted([list(map(int, input().split())) for _ in range(n)])
abSum = 0
abNum = m
for i in range(n):
    ab = abList[i]
    a, b = ab[0], ab[1]
    if b >= abNum:
        abSum += abNum * a
        break
    else:
        abSum += b * a
        abNum -= b
print(abSum)


Measured memory_bytes: 28648
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    long long a[200010];
    long long sum=0;
    for(int i=0;i<N;i++){
        cin>>a[i];
    }
    long long temp=a[0];
    for(int i=1;i<N;i++){
        if(a[i]<temp){
            sum+=temp-a[i];
        }
        temp=max(temp,a[i]);
        
    }
      
    
    cout<<sum<<endl;
    
}


Measured memory_bytes: 5156
#include<bits/stdc++.h>
using namespace std;
int main() {
	while (1) {
		int H, W;
		cin >> H >> W;
		if (H == 0 && W == 0)break;
		for (int i = 0; i < H; i++) {

			for (int j = 0; j < W; j++)cout << "#";

			cout << endl;
		}

		cout << endl;
	}
}
	


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


int main() {
	
	vector<int>a(3);
	cin >> a.at(0) >> a.at(1) >> a.at(2);
	sort(a.begin(),a.end());
	int k;
	cin >> k;
	cout << a.at(0) + a.at(1) + a.at(2) * pow(2,k) << endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  int n,k; cin>>n>>k;
  ll a[n];
  for(int i=0;i<n;i++) {
    cin>>a[i];
  }
  vector<ll> v;
  for(int i=0;i<n;i++) {
    ll sm=0;
    for(int j=i;j<n;j++) {
      sm+=a[j];
      v.push_back(sm);
    }
  }
  /*
  for(int i=0;i<v.size();i++) {
    cout<<v[i]<<" ";
  } cout<<endl;*/
  ll an=0;
  for(ll x=(1LL<<60); x>0; x>>=1){
    int ct=0;
    for(int i=0;i<v.size()&&ct<k;i++) {
      if ((an+x & v[i]) == an+x) ct++;
    }
    if (ct == k) an += x;
  }
  cout<<an<<endl;
}

Measured memory_bytes: 6512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int n;
int m;
string s;
int mn = INF;
ll ans ;
ll dp[200005][2][2];

struct RMQ{
	#define ss (1<<19)
	ll seg[ss];
	void update(int k,ll a){
		k+=ss/2-1; seg[k]=a;
		while(k>0){
			k=(k-1)/2;
			seg[k]=(seg[k*2+1]+seg[k*2+2])%mod;
		}
	}
	ll query(int a,int b,int k,int l,int r){
		if(r<a || b<l) return 0;
		if(a<=l && r<=b) return seg[k];
		else{
			ll vl=query(a,b,k*2+1,l,(l+r)/2);
			ll vr=query(a,b,k*2+2,(l+r)/2+1,r);
			return (vl+vr)%mod;
		}
	}
}rmq[2];

int main(){
	cin>>n>>m>>s;
    	if(s[0] == 'B'){
    		rep(i,m){
    			if(s[i] == 'B') s[i] = 'R';
    			else s[i] = 'B';
    		}
    	}
		int cur = 0;
		char ch;
		bool beg = 0;
		int C = 0;
		rep(i,m){
			if(i == 0){
				ch = s[i];
				cur = 1;
			}
			else if(ch != s[i]){
				if(ch == 'R'){
					if(cur%2 == 1) mn = min(mn,cur);
					else if(!beg) mn = min(mn,cur+1);
					beg = 1; 
				}
					ch = s[i];
					cur = 1; C++;
				
			}
			else cur++;
		}
				if(ch == 'R'){
					/*if(cur%2 == 1) mn = min(mn,cur);
					else if(!beg) mn = min(mn,cur+1);
					beg = 1; */
				}
				C++;
				
		if(C == 1){
			//BBが存在しなければOK
			dp[0][0][0] = dp[0][1][1] = 1;
			for(int i=0;i<n-1;i++){
				rep(x,2){
					dp[i+1][0][x] += dp[i][0][x];
					dp[i+1][1][x] += dp[i][0][x];
					dp[i+1][0][x] += dp[i][1][x];
					dp[i+1][0][x] %= mod;
					dp[i+1][1][x] %= mod;
				}
			}
			cout<<((dp[n-1][0][0]+dp[n-1][0][1]+dp[n-1][1][0])%mod+mod)%mod<<endl;
		}
		else{
			dp[0][0][0] = 1;
			rmq[0].update(0,1);
			for(int i=2;i<n;i+=2){
				dp[i][0][0] = rmq[i%2].query(max(0,i-mn-1),i,0,0,(1<<18)-1);
				rmq[i%2].update(i,dp[i][0][0]);
			}
			ll ans = 0;
			for(int m=1;m<=n;m++){
				if(m-1 > mn) continue;
				if((m-1)%2 == 0) continue;
				ans += dp[n-m][0][0] * 1LL * m % mod;
			}
			cout << (ans%mod+mod)%mod << endl;
		
		}
	
}

Measured memory_bytes: 10500
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Cube test = new Cube();
		test.num();

	}
}
	

class Cube{
	public void num(){

		String	i = new Scanner(System.in).nextLine();
		int number = Integer.parseInt(i);
		System.out.println((int)Math.pow(number,3));

	}
}

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



int main(){
  int a,b,c,k,i;
  cin >> a >> b >> c >> k;
  i = 0;
  while(true){
    if(a<b)
      break;
    b *= 2;
    i++;
  }
  while(true){
    if(b<c)
      break;
    c *= 2;
    i++;
  }
  if(i>k)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}

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

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

  string t = "0123456789";

  bool flag = 1;
  for(int i = 0; i < s.size(); i++){
    if(i == a){
      if(s[i] != '-') {
        flag = 0;
        break;
      }
    }
    else{
      bool flag2 = 0;
      for(int j = 0; j < 10; j++){
        if(s[i] == t[j]) flag2 = 1;
      }
      if(!flag2){
        flag = 0;
        break;
      }
    }
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3592
local day = io.read("*n")
local c = {}
for i = 1, 26 do
  c[i] = io.read("*n")
end
local s = {}
for id = 1, day do
  s[id] = {}
  for i = 1, 26 do
    s[id][i] = io.read("*n")
  end
end

local scores = {}
local penalties = {}
for i = 1, 26 do
  scores[i] = 0
  penalties[i] = 0
end
local ld = {}
local function solveAll(t)
  for i = 1, 26 do ld[i] = 0 end
  for id = 1, day do
    local pid = t[id]
    scores[pid] = scores[pid] + s[id][pid]
    ld[pid] = id
    for i = 1, 26 do
      penalties[i] = penalties[i] + c[i] * (id - ld[i])
    end
  end
end
local function solveDiff(t, iday, pto)
  local pfrom = t[iday]
  scores[pfrom] = scores[pfrom] - s[iday][pfrom]
  scores[pto] = scores[pto] + s[iday][pto]
  t[iday] = pto
  penalties[pfrom] = 0
  penalties[pto] = 0
  for i = 1, 26 do ld[i] = 0 end
  for id = 1, day do
    local p = t[id]
    ld[p] = id
    for ip = pfrom, pto, (pto - pfrom) do
      penalties[ip] = penalties[ip] + c[ip] * (id - ld[ip])
    end
  end
end

local function solveSum()
  local z = 0
  for i = 1, 26 do z = z + scores[i] - penalties[i] end
  return z
end

local t = {}
for id = 1, day do
  t[id] = 1 + (id % 26)
end
solveAll(t)
local score = solveSum()
math.randomseed(1)
local iter = 1
local random = math.random

local candidate = {}
for i = 1, 365 do
  candidate[i] = {}
  for j = 1, 26 do
    if 1 + (i % 26) ~= j then
      table.insert(candidate[i], j)
    end
  end
end
local day_candidate = {}
for i = 1, 365 do day_candidate[i] = i end

while os.clock() < 1.85 do
  iter = iter + 1
  if #day_candidate == 0 then
    -- reset
    for i = 1, 365 do
      day_candidate[i] = i
      candidate[i] = {}
      for j = 1, 26 do
        if t[i] ~= j then
          table.insert(candidate[i], j)
        end
      end
    end
  end
  local changeday_idx = 1 + (iter % #day_candidate)--random(1, #day_candidate)
  local changeday = day_candidate[changeday_idx]
  local changeto_idx = random(1, #candidate[changeday])
  local changeto = candidate[changeday][changeto_idx]
  table.remove(candidate[changeday], changeto_idx)
  if #candidate[changeday] == 0 then
    table.remove(day_candidate, changeday_idx)
  end
  local changefrom = t[changeday]
  -- if changefrom <= changeto then
  --   changeto = changeto + 1
  -- end
  local score_before_p1 = scores[changefrom]
  local score_before_p2 = scores[changeto]
  local penalty_before_p1 = penalties[changefrom]
  local penalty_before_p2 = penalties[changeto]
  solveDiff(t, changeday, changeto)
  local tmp = solveSum()
  if score < tmp then
    score = tmp
    iter = iter + 1
  else
    scores[changefrom] = score_before_p1
    scores[changeto] = score_before_p2
    penalties[changefrom] = penalty_before_p1
    penalties[changeto] = penalty_before_p2
    t[changeday] = changefrom
  end
end
-- print(iter)
print(table.concat(t, "\n"))


Measured memory_bytes: 3484
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 4e3 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int x, a, b;
	cin >> x >> a >> b;
	cout << (x - a) % b << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() {
	string A, B, C;
	cin >> A >> B >> C;

	if (A[(int)A.length() - 1] == B[0] && B[(int)B.length() - 1] == C[0]) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
inline int read(){
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    return x*f;
}
int a,b,c;
int main(){
	a=read(),b=read(),c=read();
	cout<<c<<" "<<a<<" "<<b<<endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
s = [0] * n
for i in range(n):
    s[i] = int(input())
    

judge = 0
answer = 0

for i in s:
    answer += i
    if i%10 == 0:
        judge += 1 

#print(answer)

s.sort()
mi = 0
#print(s)

for i in s:
    if i%10 != 0:
        mi = i
        break


#print(mi)

if judge == len(s):
    print(0)
else:
    if answer%10 == 0:
        answer -= mi

    print(answer)




Measured memory_bytes: 9144
S = input()
for i in range(8) :
    a = []
    b = int(S[0])
    c = 0
    for j in range(3) :
        if (i>>j) & 1 :
            b += int(S[j+1])
            a.append('+')
        else :
            b -= int(S[j+1])
            a.append('-')
    if b == 7 :
        print(S[0]+a[0]+S[1]+a[1]+S[2]+a[2]+S[3]+'=7')
        break


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<algorithm>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

int main(void) {
    string str;
    cin>>str;
    int k;
    cin>>k;
    set<string> dp;

    for(int i = 0;i < str.size();i++) {
        for(int j = i;j < i+5 && j < str.size();j++) {
            dp.insert(str.substr(i,j-i+1));
        }
    }

    set<string>::iterator it = dp.begin();
    for(int i = 0;i < k-1;i++)
        it++;

    cout<<*it<<endl;

    return 0;
}


Measured memory_bytes: 1664
N, M = map(int, input().split())
if N > M:
    # always N <= M
    N, M = M, N
if N == 1:
    if M == 1:
        print(1)
    elif M == 2:
        print(0)
    else:
        print(M - 2)
elif N == 2:
    print(0)
else:
    print((N - 2) * (M - 2))


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,p;
    string s;
    cin>>n>>p;
    cin>>s;
    if(10%p==0){
        ll ans=0;
        rep(i,n){
            if((s[i]-'0')%p==0) ans+=i+1;
        }
        cout<<ans<<endl;
        return 0;
    }
    
    vector<int> d(n+1);
    int ten=1;
    for(int i=n-1;i>=0;i--){
        int a=(s[i]-'0')*ten%p;
        d[i]=(d[i+1]+a)%p;
        ten*=10;
        ten%=p;
    }
    vector<int> cnt(p);
    ll ans=0;
    for(int i=n;i>=0;i--){
        ans+=cnt[d[i]];
        cnt[d[i]]++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1428
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }

const int NUM = 2019;

ll choose(ll m) { return m*(m-1)/2;}

int main()
{
    string S;
    cin >> S;
    int N = S.size();
    vector<int> iS(N), pow10Mod(N), Spow10(N+1);
    rep(i,N) iS[i] = S[i] - '0';
    pow10Mod[N-1] = 1;
    for(int i = N-2; i>=0; i--) pow10Mod[i] = (pow10Mod[i+1] * 10) % NUM;
    vector<int> ijMod(NUM);
    Spow10[0] = 0;
    ijMod[Spow10[0]] ++;
    rep(i,N) {
        Spow10[i+1] = (Spow10[i] + iS[i] * pow10Mod[i]) % NUM;
        ijMod[Spow10[i+1]] ++;
    }
    ll ans = 0;
    rep(i,NUM) ans += choose(ijMod[i]);
    cout << ans << "\n";
    return 0;
}


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

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define pmod 1000000007
#define maxn 100005
#define IN freopen("input.txt","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(int i=a ; i<=b ; i++)
#define INF 1000000000
#define ll long long int
#define eps (1e-8)
#define sq(x) ( (x)*(x) )

using namespace std;

typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
int a[1000],b[1000],c[1000],p[1000],r[1000];
int N,m;
int  swap1 (int x[1000], int y[1000]){
int    res=0; int st=1;
    while (st<=N){
        if (x[st]==y[st]) {}//st++;
        else{
            FOR (i,st+1,N){
                if (y[i]==x[st]) {
                    swap(y[i],y[st]);
                    //st++;
                    res+=i-st;
                    break;
                }
            }
        }
        //cout<<x[st]<<y[st]<<endl;
        st++;
    }
    return res;
}
int s1,s0,ss1,ss0;
int main()
{
cin>>N>>m;
FOR (i,1,N){
    cin>>a[i];
    if (a[i]==1) s1++;
else s0++;

}
FOR (i,1,m){
cin>>p[i];
r[i]=r[i-1]+p[i];
}
FOR (i,1,m){
    FOR (j,r[i-1]+1,r[i]){
        b[j]=i%2;c[j]=(i+1)%2;
        if (b[j]==1) ss1++;
        else ss0++;
    }

}
//cout<<s0<<s1<<ss1<<ss0<<endl;
//FOR (i,1,N) cout<<c[i];
int r1=INF; int r2=INF;
if (ss1==s1) r1=swap1(a,b);
if (ss0==s1) r2=swap1(a,c);
//cout<<r1<<endl;
cout<<min (r1,r2)<<endl;
         return 0;
}

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

#define mp make_pair
#define fst first
#define snd second

using namespace std;

typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int,int> pii;
typedef pair<i64,int> pli;
typedef pair<int,i64> pil;
typedef pair<i64,i64> pll;
typedef vector<int> vi;
typedef vector<i64> vl;

template <typename T>
T id(T b) {return b;};
template <class It>
bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It>
bool any(It f,It l){return std::any_of(f,l,id<bool>);}

struct union_find {
  typedef vector<int> vi;
  vi parent,rank,cnt;
  vl w;
  int n;

  union_find(int n) : n(n) {
    parent = vi(n); rank = vi(n,0); cnt = vi(n,1);
    w = vl(n,0);
    for (int i = 0; i < n; i++) parent[i] = i;
  }

  int find(int a) {
    if (parent[a] == a) return a;
    return parent[a] = find(parent[a]);
  }

  void unite(int a, int b) {
    a = find(a); b = find(b);

    if (a == b) return;
    if (rank[a] < rank[b]) {
      parent[a] = b; cnt[b] += cnt[a];
      w[b] += w[a];
    } else {
      parent[b] = a; cnt[a] += cnt[b];
      w[a] += w[b];
      if (rank[a] == rank[b])
        rank[a]++;
    }
  }

  int count(int a) { return cnt[find(a)]; }

  i64 weight(int a) { return w[find(a)]; }

  bool same(int a, int b) { return find(a) == find(b); }
};

struct edge { int to, idx, cost; };
const int MAX_N = 100000, MAX_M = 100000;
int n,m;
//int xs[MAX_N];
pii ys[MAX_M];
pii ab[MAX_M];
vector<edge> g[MAX_N];
bool vis[MAX_N] = {};
bool cand[MAX_M] = {};
bool use[MAX_M] = {};

void dfs(int u, int c) {
  if (vis[u]) return;

  vis[u] = true;

  for (edge e : g[u]) {
    if (e.cost > c) continue;
    use[e.idx] = true;
    dfs(e.to, c);
  }
}

int main()
{
  cin >> n >> m;
  union_find uf(n);
  for (int i = 0; i < n; i++) {
    cin >> uf.w[i];
  }

  int a,b,y;
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> y;
    a--,b--;
    ys[i] = mp(y,i);
    ab[i] = mp(a,b);
    g[a].push_back({b,i,y});
    g[b].push_back({a,i,y});
  }

  sort(ys, ys+m);

  int i = 0;
  while (i < m) {
    int s = i;
    while (ys[s].fst == ys[i].fst) {
      uf.unite(ab[ys[i].snd].fst, ab[ys[i].snd].snd);
      i++;
    }
    for (int j = s; j < i; j++) {
      //printf("y=%d %d <= %ld?\n", ys[j].snd, ys[j].fst, uf.weight(ab[ys[j].snd].fst));
      if (ys[j].fst <= uf.weight(ab[ys[j].snd].fst))
        cand[ys[j].snd] = true;
    }
  }
  /*
  for (int i = 0; i < m; i++)
    printf("cand[%d]=%d\n",i,cand[i]);
  */
  int res = 0;
  for (int i = m-1; i >= 0; i--) {
    int j = ys[i].snd;
    if (use[j]) continue;
    if (!cand[j]) { res++; continue;}
    dfs(ab[j].fst, ys[i].fst);
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 12672
H,W=map(int,input().split())
import numpy as np
C=np.array([list(map(int,input().split())) for _ in range(10)])

A=[]
for i in range(H):
  for a in map(int,input().split()):
    if a!=-1:A+=a,

dp=np.array([[None]*10 for _ in range(10)])
for i in range(10):
  for j in range(10):
    dp[i][j]=C[i][j]
    
for _ in range(10): #更新回数最大10 -> 10回までは毎回良くなるかもしれない
  for i in range(10):
    for j in range(10):
      for k in range(0,9+1):
        dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j])
            
ans=0
for a in A:ans+=dp[a][1]
print(ans)

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

using namespace std;

long long a, b, c, k;

int main()
{
    cin>>a>>b>>c;
    cin>>k;
    if (c>=a && c>=b)
    {
        for (int i=1;i <=k; i++)
            c*=2;
    }
    else if (b>=a && b>=c)
    {
        for (int i=1;i <=k; i++)
            b*=2;
    }
    else if (a>=c && a>=b)
    {
        for (int i=1;i <=k; i++)
            a*=2;
    }
    cout<<a+b+c;
    return 0;
}


Measured memory_bytes: 256
import sys
input=sys.stdin.buffer.readline
A,B,C = map(int,input().split())

def F(A,B,C):
    if any(x&1 for x in [A,B,C]):
        return 0
    if A == B == C:
        return -1
    return 1 + F((A+B)//2,(B+C)//2,(C+A)//2)

answer = F(A,B,C)
print(answer)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
#include<algorithm>
#include<string>
#include<vector>
#include<tuple>
using namespace std;

int main(){
  int z;
  cin >> z;
  int v[51],c[51];
  for(int i=0; i<z; i++){
    cin >> v[i];
  }

  for(int i=0; i<z; i++){
    cin >> c[i];
  }
  int sumx=0,sumy=0;

  for(int i=0; i<z; i++){
    if(v[i]>c[i]){
      sumx += v[i];
      sumy += c[i];
    }
  }
    int dif = sumx- sumy;
    cout << dif << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	int m = sc.nextInt();
    	sc.close();
    	if(n == m){
    		System.out.println("Yes");
    	}else{
    		System.out.println("No");
    	}

    }
}

Measured memory_bytes: 21716
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		String s = scan.next();
		int count = 0;
		
		for (int i = 0; i < n - 2; i++) {
			if (s.substring(i, i + 3).equals("ABC")) {
				count++;
			}
		}
		System.out.println(count);
		scan.close();
 	}
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i,k,n) for(int i=k;i<n;i++)
//#define sum(start, end) accumulate(start, end, 0)
#define mmax(start, end) *max_element(start, end)
#define mmin(start, end) *min_element(start, end)
#define pb push_back
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef string str;

using namespace std;
template <class T = ll> T in() { T _in; cin >> _in; return (_in); }


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

    ll N = in(), A[100002];
    REP(i, 1, N+1) A[i] = in();
    A[0] = A[N+1] = 0;   // 処理しやすいように追加

    // rep(i, N) {
    //     ll pos = 0, cost = 0;
    //     rep(j, N+1) {
    //         if (j != i) {
    //             cost += abs(pos - A[j]);
    //             pos = A[j];
    //         }
    //     }
    //     cout << cost << endl;
    // }

    // 答え
    ll pos = 0, D = A[0];
    rep(i, N+1) {
        D += abs(A[i+1] - A[i]);
    }

    REP(i, 1, N+1) {
        cout << D - abs(A[i-1] - A[i]) - abs(A[i] - A[i+1]) + abs(A[i-1] - A[i+1])
            << endl;
    }

    return 0;
}


Measured memory_bytes: 2048
#include <iostream>

using namespace std;

int main() {
  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  cout << (h2 * 60 + m2 - h1 * 60 - m1 - k) << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include<vector>
#include<set>
#include<queue>
#include<string>
using namespace std;

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



Measured memory_bytes: 3560
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    String s = scan.next();
    if (s.equals("RRR")){
      System.out.println(3);
    }else if (s.equals("RRS")){
      System.out.println(2);
    }else if (s.equals("SRR")){
      System.out.println(2);
    }else if (s.equals("RSR")){
      System.out.println(1);
    }else if (s.equals("RSS")){
      System.out.println(1);
    }else if (s.equals("SRS")){
      System.out.println(1);
    }else if (s.equals("SSR")){
      System.out.println(1);
    }else{
      System.out.println(0);
    }
  }
}


Measured memory_bytes: 35452
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
ll N;
ll a[100000], b[100000],d[100000];
vector<ll> c(200001,0);
const int MAX_N=100000;
struct UF{
    int par[MAX_N];
    int sizes[MAX_N];
    bool used[MAX_N];
    void init (int n){
        for (int i=0;i<n;i++){
            par[i]=i;
            sizes[i]=1;
        }
    }
    int find (int x){
        if (par[x]==x){
            return x;
        }
        else{
            return par[x] = find(par[x]);
        }
    }
    void unite (int x, int y){
        x=find(x);
        y=find(y);
        if (x==y) return;
        if (sizes[x] < sizes[y]) swap(x,y);
        par[y]=x;
        sizes[x]+=sizes[y];
    }
    bool same (int x, int y){
        return find(x) == find(y);
    }
    int size(int x){
        return sizes[find(x)];
    }
};
UF uf;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N;
    rep(i,0,N) cin>>a[i];
    rep(i,0,N) cin>>b[i];
    ll res=0;
    rep(i,0,N){
        d[i]=b[i];
        c[i]=a[i];
        res^=a[i];
    }
    c[N]=res;
    sort(c.begin(),c.begin()+N+1);
    sort(d,d+N);
    ll left=0,right=N-1;
    while(left<N&&d[left]==c[left]){
        left++;
    }
    while(right>=0&&d[right]==c[right+1]){
        right--;
    }
    if(left<=right) cout <<-1<<"\n";
    else{
        rep(i,0,N) c[N+1+i]=d[i];
        sor(c);
        uniq(c);
        map<ll,ll> m;
        rep(i,0,sz(c)) m[c[i]]=i;
        uf.init(N);
        rep(i,0,N){
            uf.unite(m[a[i]], m[b[i]]);
        }
        ll ans=0;
        ll ret=0;
        rep(i,0,N){
            if(a[i]==b[i]) ret++;
            if(a[i]!=b[i]&&uf.used[uf.find(m[a[i]])]==0){
                uf.used[uf.find(m[a[i]])]=1;
                if(uf.find(m[a[i]])!=uf.find(m[res])) ans+=1;
            }
        }
        cout <<ans+N-ret<<"\n";
    }
}

Measured memory_bytes: 11264
/*
$Description$
给定一张图（可能存在自环），每个点上有0或1。求是否存在一条路径，使得在上面不断走，能够得到所有01串组合（可以重复经过点）。
$n\leq2\times10^5,m\leq2\times10^5$。
$Solution$
对于一个点，如果它的后继只有0或1，显然它不能在这条路径上。
$Sol 1$
我们把这样的点删掉。然后再判断连向它的点是否要被删掉...这样一直删，判断最后是否存在未被删掉的点。和拓扑排序差不多。
$Sol 2$
由上面的结论也可以看出，路径只能是AABB这样的环（或者AABBAABB...）（这样每个点就存在两种转移）。
AA,AB,BB,BA，这样的环我们可以通过二分图找，即对于相同字符连一条S->T的边，不同字符连一条T->S的边，最后判环。
*/
#include <cstdio>
#include <cctype>
#include <algorithm>
#define gc() getchar()
const int N=2e5+5;

int Enum,H[N],nxt[N<<1],to[N<<1],t,q[N],cnt[N][2];
char s[N];
bool del[N];

inline int read()
{
	int now=0;register char c=gc();
	for(;!isdigit(c);c=gc());
	for(;isdigit(c);now=now*10+c-'0',c=gc());
	return now;
}
inline void AE(int u,int v)
{
	++cnt[u][s[v]-'A'], to[++Enum]=v, nxt[Enum]=H[u], H[u]=Enum;
	++cnt[v][s[u]-'A'], to[++Enum]=u, nxt[Enum]=H[v], H[v]=Enum;
}
void Del(int x)
{
	if(del[x]||(cnt[x][0]&&cnt[x][1])) return;
	q[++t]=x, del[x]=1;
}

int main()
{
	int n=read(),m=read(); scanf("%s",s+1);
	while(m--) AE(read(),read());
	for(int i=1; i<=n; ++i) Del(i);
	for(int h=1; h<=t; ++h)
	{
		int x=q[h];
		for(int i=H[x]; i; i=nxt[i]) --cnt[to[i]][s[x]-'A'],Del(to[i]);
	}
	puts(t==n?"No":"Yes");

	return 0;
}

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

int main() {
int A, B, C, X;
int count = 0;
cin >> A >> B >> C >> X;
for(int i = 0; i <= A; i++){
for(int j = 0; j <= B; j++){
for(int k = 0; k <= C; k++){
if(500*i + 100*j + 50*k == X){
count++;}}}}
cout << count << endl;}


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

int main(){
  int ans;
  string s;
  cin >> s;
  int cnt = 0;
  for(auto a : s){
    if (a == 'A' || a == 'T' || a == 'G' || a == 'C'){
      cnt++;
    }
    else{
      if (ans<cnt) ans = cnt;
      cnt = 0;
    }
  }
  if (ans<cnt) ans = cnt;
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>

int main() {
	int n, k; std::cin >> n >> k;
	std::vector<int> heights(n); for (auto& h : heights) std::cin >> h;
	std::vector<long long int> memo(n, LLONG_MAX);
	memo[0] = 0;
	for (auto i = 0; i < n; ++i) {
		for (auto j = 1; j <= k && i + j < n; ++j) {
			memo[i + j] = std::min(memo[i + j], memo[i] + std::abs(heights[i] - heights[i + j]));
		}
	}
	std::cout << memo.back() << std::endl;
}

Measured memory_bytes: 1408
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
int n,m,c[55][55],cnt[55],ans;
int main()
{
	cin>>n>>m;
	for(int i=0;i<10;i++)
	{
		for(int j=0;j<10;j++)
		{
			cin>>c[i][j];
		}
	}
	for(int k=0;k<10;k++)
	{
		for(int i=0;i<10;i++)
		{
			for(int j=0;j<10;j++)
			{
				c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
			}
		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			int a;
			cin>>a;
			if(a!=-1)
			{
				cnt[a]++;
			}
		}
	}
	for(int i=0;i<10;i++)
	{
		ans+=cnt[i]*c[i][1];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
S = str(input())

S_1 = int(S[:2])
S_2 = int(S[2:])

if (S_1 <=12) and (S_2 <= 12) and (S_1 != 0) and (S_2 != 0):
    print('AMBIGUOUS')

elif (S_1 <= 12) and (S_2 > 12) and (S_1 != 0) and (S_2 != 0):
    print('MMYY')
elif (0 < S_1 <= 12) and (S_2 == 0):
    print('MMYY')

elif (S_1 > 12) and (S_2 <= 12) and (S_1 != 0) and (S_2 != 0):
    print('YYMM')
elif (S_1 == 0) and (0 < S_2 <= 12):
    print('YYMM')

elif (S_1 > 12) and (S_2 > 12) and (S_1 != 0) and (S_2 != 0):
    print('NA')
elif (S_1 == 0) or (S_2 == 0):
    print('NA')


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

using namespace std;

void solve() {
    string S;
    cin >> S;
    int ans = 0;
    for (int i = 0; i < (int)S.length(); i++)
    {
        if (S[i] == '0')
        {
            ans++;
        }
    }
    ans = min(ans, (int)S.length()-ans) * 2;
    cout << ans << endl;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
#define ms(x, n) memset(x,n,sizeof(x));
#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 pb push_back
#define PI acos(-1.0)
#define LONG_LONG_MAX 9223372036854775807
#define LONG_LONG_MIN -9223372036854775808
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;

int n;
ll ans;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ans = 0;
    cin >> n;
    vector<string> a(n);
    rep(i, n) {
        cin >> a[i];
        sort(a[i].begin(), a[i].end());
    }
    sort(a.begin(), a.end());
    ll temp = 1;
    for (int i = 1; i < n; ++i) {
        if (a[i] == a[i-1]) {
            ans += temp;
            ++temp;
        } else {
            temp = 1;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5760
let k, css, h, w, a_s = Scanf.scanf "%d %d %d" @@ fun h w n -> Array.(ref 0, make_matrix h w 0, h, w, init n @@ fun _ -> Scanf.scanf " %d" (+) 0)
let _ = for i = 0 to h - 1 do for j = 0 to w - 1 do if a_s.(!k) = 0 then incr k; css.(i).(if i mod 2 = 0 then j else w - 1 - j) <- !k + 1; a_s.(!k) <- a_s.(!k) - 1 done done; Array.(iter (fun ns -> to_list ns |> List.map string_of_int |> String.concat " " |> print_endline) css)

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

const int A = 100005, B = 100005, M = 100005;
const long long inf = 1000000000000ll;

template <class T>
void read (T &x) {
	int sgn = 1;
	char ch;
	x = 0;
	for (ch = getchar(); (ch < '0' || ch > '9') && ch != '-'; ch = getchar()) ;
	if (ch == '-') ch = getchar(), sgn = -1;
	for (; '0' <= ch && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
	x *= sgn;
}
template <class T>
void write (T x) {
	if (x < 0) putchar('-'), write(-x);
	else if (x < 10) putchar(x + '0');
	else write(x / 10), putchar(x % 10 + '0');
}

int a, b, m;
long long p[A], q[B], mn1 = inf, mn2 = inf, ans = inf;
int main () {
	read(a), read(b), read(m);
	for (int i = 1; i <= a; i++) {
		read(p[i]);
		mn1 = min(mn1, p[i]);
	}
	for (int i = 1; i <= b; i++) {
		read(q[i]);
		mn2 = min(mn2, q[i]);
	}
	ans = mn1 + mn2;
	for (int i = 1; i <= m; i++) {
		int x, y;
		long long c;
		read(x), read(y), read(c);
		ans = min(ans, p[x] + q[y] - c);
	}
	write(ans), putchar('\n');
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int result[100][100];

int main()
{
		int h, w, n;
		cin >> h >> w >> n;
		vector<pair<int, int>> a(n);
		for(int i = 0; i < n; i++)
		{
				int temp;
				cin >> temp;
				a[i] = make_pair(i + 1, temp);
		}
		auto compare = [] (pair<int, int>a, pair<int, int> b){
				return a.second > b.second;
		};
		sort(a.begin(), a.end(), compare);
		pair<int, int> lasti = make_pair(0,0);
		bool isright = true;
		for(auto color : a)
		{
				pair<int, int> index = lasti;
				for(int num = color.second; num > 0; num--)
				{
						if(isright)
						{
								if(index.second < w)
								{
										result[index.first][index.second++] = color.first;
								}else{
										isright = false;
										result[++index.first][--index.second] = color.first;
								}
						}else{
								if(index.second > 0)
								{
										result[index.first][--index.second] = color.first;
								}else{
										isright = true;
										result[++index.first][index.second++] = color.first;
								}
						}
				}
				lasti = index;
		}
		for(int i = 0; i < h; i++)
		{
				for(int j = 0; j < w; j++)
				{
						cout << result[i][j] << " ";
				}
				cout << endl;
		}
		return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getint(_T& a) {
	std::cin >> a;
}
template<class _T> static void getint(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}
template <class _T> static _T tp_abs(_T a) {
	if (a < (_T)0) {
		a *= (_T)-1;
	}
	return a;
}

static void exec();

int main()
{
	exec();
	fflush(stdout);
	return 0;
}

static void exec()
{
	int X, Y, A, B, C;
	getint(X, Y);
	getint(A, B, C);

	std::vector<LLONG> pi(A);
	for (int i = 0; i < A; i++) {
		getint(pi[i]);
	}
	std::vector<LLONG> qi(B);
	for (int i = 0; i < B; i++) {
		getint(qi[i]);
	}
	std::vector<LLONG> ri(C);
	for (int i = 0; i < C; i++) {
		getint(ri[i]);
	}

	std::sort(pi.begin(), pi.end(), std::greater<LLONG>());
	std::sort(qi.begin(), qi.end(), std::greater<LLONG>());
	std::sort(ri.begin(), ri.end(), std::greater<LLONG>());

	std::priority_queue<LLONG, std::vector<LLONG>, std::greater<LLONG>> rque, gque;
	for (int i = 0; i < X; i++) {
		rque.push(pi[i]);
	}
	for (int i = 0; i < Y; i++) {
		gque.push(qi[i]);
	}

	LLONG red, green;
	for (int i = 0; i < C; i++) {
		red = rque.top();
		green = gque.top();
		if (red > green) {
			if (green < ri[i]) {
				gque.pop();
				gque.push(ri[i]);
			}
		}
		else {
			if (red < ri[i]) {
				rque.pop();
				rque.push(ri[i]);
			}
		}
	}

	LLONG sum = 0;
	while (!rque.empty()) {
		sum += rque.top();
		rque.pop();
	}
	while (!gque.empty()) {
		sum += gque.top();
		gque.pop();
	}
	printf("%lld\n", sum);
}


Measured memory_bytes: 7964
import heapq
N=int(input())
A=list(map(int, input().split()))
A_rev = [-x for x in A[::-1]] #逆順にして各要素を-1倍する
left, right = A[:N], A_rev[:N]
sum_left_list, sum_right_list = [0]*(N+1), [0]*(N+1)
sum_left, sum_right = sum(left), sum(right)
sum_left_list[0], sum_right_list[0]=sum_left, sum_right
heapq.heapify(left)
heapq.heapify(right)
#left: k=N, N+1,..., 2N-1まで動かして大きい方からN個の和を求める
for k in range(N, 2*N):
	val=A[k]
	heapq.heappush(left, val)
	min_val = heapq.heappop(left)
	sum_left += val
	sum_left -= min_val
	sum_left_list[k-N+1] = sum_left

#right: k=N, N+1,..., 2N-1まで動かして大きい方からN個の和を求める
for k in range(N, 2*N):
	val = A_rev[k]
	heapq.heappush(right, val)
	min_val = heapq.heappop(right)
	sum_right += val
	sum_right -= min_val
	sum_right_list[k-N+1] = sum_right
sum_right_list=sum_right_list[::-1]

ans=-float("inf")
for i in range(N+1):
	ans=max(ans, sum_left_list[i]+sum_right_list[i])
print(ans)

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

int main(){  
  int m,n,A[100][100],B[100],C[100];
  cin >> n >> m;
  for(int i = 0; i < n; i++)
    for(int j = 0; j < m; j++)
      cin >> A[i][j];
  for(int p = 0; p < m; p++)
    cin >> B[p];

  for (int i = 0; i < n; i++){
    C[i] =0;
    for (int w = 0; w < m; w++){
      C[i] += A[i][w] * B[w];
    }
  }
  for (int i = 0; i < n; i++) cout << C[i] << endl;
  return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int ans[112345];

int query(int p) {
  cout << p << endl;
  string s;
  cin >> s;
  if (s == "Male") ans[p] = 1;
  if (s == "Female") ans[p] = 2;
  if (s == "Vacant") { ans[p] = 3; exit(0); }
  return ans[p];
}

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

  if (N <= 20) {
    REP(i, N) query(i);
    return 0;
  }
  int L = 0, R = N;
  query(0);
  query(N/2);
  if (((N/2) % 2 == 0 && ans[0] != ans[N/2]) || 
      ((N/2) % 2 != 0 && ans[0] == ans[N/2])) {
    L = 0;
    R = N/2;
  } else {
    L = N/2;
    R = N;
  }
  while (R - L > 1) {
    int mid = (L + R) / 2;
    query(mid);
    if (((mid - L) % 2 == 0 && ans[L] != ans[mid]) || 
        ((mid - L) % 2 != 0 && ans[L] == ans[mid])) {
      R = mid;
    } else {
      L = mid;
    }
  }
  query(R);

  return 0;
}


Measured memory_bytes: 852
#include <iostream>
#include <vector>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iomanip>
using namespace std;

int main() {
    string s, t; cin >> s >> t;
    string sub=s[s.size()-1]+s.substr(0, s.size()-1);
    bool ok = false;
    while(1){
        if(sub==s) break;
        if(sub==t) ok = true;
        sub=sub[s.size()-1]+sub.substr(0, sub.size()-1);
    }
    if(ok||s==t) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}
        

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,ss;
  cin >> s >> ss;
  bool t=true;
  for(int i=0;i<s.size();i++){
    if(s[i]!=ss[i]){
      t=false;
      break;
    }
  }
  if(t)cout << "Yes" << endl;
  else cout << "No" << endl;
}
    


Measured memory_bytes: 3592
#include <cstdio>

char c[15][15],d[15],e[15];
int i,m,n;

inline bool dfs2(int x)
{
	if (x>m)
		return true;
	if (e[x])
		return dfs2(x+1);
	else
	{
		int t=0,r=0;
		for (int i=x;i<=m;i++)
			if (! e[i])
				t++;
		for (int i=x;i<=m;i++)
			if (! e[i])
			{
				e[x]=i,e[i]=x,r=1;
				for (int j=1;j<=n;j++)
					if ((c[j][x]!=c[d[j]][i]) || (c[d[j]][x]!=c[j][i]))
					{
						r=0;
						break;
					}
				if ((r) && ((t&1) || (i!=x)) && (dfs2(x+1)))
					return true;
				e[x]=0,e[i]=0;
			}
	}
	return false;
}

inline bool dfs1(int x)
{
	if (x>n)
		return dfs2(1);
	if (d[x])
		return dfs1(x+1);
	else
	{
		int t=0;
		for (int i=x;i<=n;i++)
			if (! d[i])
				t++;
		for (int i=x;i<=n;i++)
			if (! d[i])
			{
				d[x]=i,d[i]=x;
				if (((t&1) || (i!=x)) && (dfs1(x+1)))
					return true;
				d[x]=0,d[i]=0;
			}
	}
	return false;
}

int main()
{
	scanf("%d%d",&n,&m);
	for (i=1;i<=n;i++)
		scanf("%s",c[i]+1);
	if (dfs1(1))
		puts("YES");
	else
		puts("NO");
	return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        long a[] = new long[n];
        for(int i =0 ; i < n;i++){
            a[i] = sc.nextLong();
        }
        long[] wk = Arrays.stream(a).sorted().toArray();
        long sum = (long)0;
        int x = 0;
        int wksize = wk.length - m;
        //Arrays.stream(wk).forEach(System.out::print);      
        for(long num : wk){
            x++;
            if(x > wksize){
                break;
            }
            sum = sum + num;
          //System.out.println(sum);
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 67260
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}




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

int r,d,x;
cin >> r >> d >> x;

int now = x;

for(int i = 1;i <= 10;i++){
    now = r*now- d;
    cout << now << endl;
}

return 0;
}

Measured memory_bytes: 256
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


# --------------------------------------------

dp = None


def main():
    N = int(input())
    A = li_input()
    A.insert(0, 0)
    A.append(0)

    total = 0

    for i in range(1, len(A)):
        total += abs(A[i] - A[i - 1])

    for i in range(1, len(A) - 1):
        ans = total
        ans -= abs(A[i] - A[i - 1])
        ans -= abs(A[i + 1] - A[i])
        ans += abs(A[i + 1] - A[i - 1])
        print(ans)


main()


Measured memory_bytes: 15360
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <map>
using namespace std;
typedef long long int ll;

template<typename T>
map<T,ll> factorize(T x){
	map<T,ll> res;
	for(ll i=2;i*i<=x;i++){
		while(x%i==0){
			x/=i;
			res[i]++;
		}
	}
	if(x!=1) res[x]++;
	return res;
}

int main(){
	ll n,p; cin >> n >> p;
	auto m=factorize(p);
	ll ans=1;
	for(auto x:m){
		ll k=x.second/n;
		ans*=(ll)pow(x.first,k);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>

using namespace std;

// int ball_counter[100];
// int ball_selection[100];


long long ball_counter[200100];
long long ball_selection[200100];


int main(){
    long long N;
    cin >> N;
    vector<long long> a(N);
    for(long long i=0; i<N; ++i) cin >> a[i];

    for(long long i=0; i<N; ++i){
        ball_counter[a[i]]++;
    }

    for(long long i=0; i<200100; ++i){
        if(ball_counter[i] > 1){
            // if(ball_counter[i] %2 == 0){
            //     ball_selection[i] = ball_counter[i]/2 ;
            //     ball_selection[i] *= (ball_counter[i] - 1);
            // }else{
            //     ball_selection[i] = (ball_counter[i] - 1)/2;
            //     ball_selection[i] *= ball_counter[i] ;
            // }
            ball_selection[i] = ball_counter[i] * (ball_counter[i] - 1 )/2;
        }
    }

    long long total = 0;
    for(long long i=0; i<200100; ++i){
        total += ball_selection[i];
    }


    for(int i=0; i<N; ++i){
        long long ans;

        // if( ball_counter[a[i]] - 1 < 2 ){
        //     ans = total;
        // }else{
        ans = total - (ball_counter[a[i]] - 1);
//         }

        cout << ans << endl;
    }
}

Measured memory_bytes: 7920