akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    string s[n];
    rep(i,n){
      cin >> s[i];
    }

    vector< pair<bool,bool> > barray(n,make_pair( false , false ));
    ll ans = 0;
    rep(i,n){
      if(s[i][0] == 'B') barray[i].first = true;
      rep(j,s[i].size()-1){
        if(s[i][j] == 'A' && s[i][j+1] == 'B'){
          ans++;
        }
      }
      if(s[i].back() == 'A') barray[i].second = true;
    }

    //cout << "mid " << ans << endl;

    ll ab = 0;
    ll b = 0;
    ll a = 0;
    rep(i,n){
      if(barray[i].first && barray[i].second) ab++;
      else if(barray[i].first) b++;
      else if(barray[i].second) a++;
    }
    //cout << a << ' ' << b << ' ' << ab << "\n";

    //3pair
    bool flag = false;
    ll tmp = min(a,min(b,ab));
    ans += 2LL*tmp;
    a-=tmp;
    b-=tmp;
    ab-=tmp;
    if(tmp > 0) flag = true;

    if(a > 0 && ab > 0){
      if(ab > a) ans += a + (ab-a);
      else       ans += ab;
    }
    else if(a > 0 && b > 0) ans += min(a,b);
    else if(ab > 0 && b > 0){
       if(ab > b) ans += b + (ab-b);
       else       ans += ab;
    }
    else if(ab > 0){
      if(flag == true) ans += ab;
      else ans += ab-1;
    }

    cout << ans << endl;
    return 0;
}


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

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
    int X;  cin >> X;
    ll ans = (int)(X / 500) * 1000;
    X %= 500;
    cout << ans + (int)(X / 5) * 5 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e18 + 3)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

const int n_max = 202020;

llong fac[n_max];  /// fac[n] = n!
llong finv[n_max]; /// (fac[n] * finv[n]) % MOD = 1
llong inv[n_max];  /// (n * inv[n]) % MOD = 1

int summ[n_max];
 
void init() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  FOR (i, 2, n_max) {
    fac[i] = fac[i-1]*i % MOD;
    inv[i] = MOD - inv[MOD%i]*(MOD/i) % MOD;
    finv[i] = finv[i-1]*inv[i] % MOD;
  }
}
 
llong nCk (int n, int k) {
  if (n < k || k < 0 || n < 0) return 0;
  return fac[n]*finv[k]%MOD*finv[n-k]%MOD;
}

int solve(int n, int m, int k){
    int res = 0;
    FOR(i,2,m+1){
        FOR(j,1,n+1){
            if(k-j > 0){
                int hoge = nCk((m-1)*n - 1,k-j-1 );
                hoge *= nCk(n,j);
                hoge %= MOD;
                hoge *= j;
                hoge %= MOD;

                hoge *= (n * summ[i-1]) % MOD;
                res += hoge;
                res %= MOD;

            }
        }
    }
    return res;

}

signed main(){
    init();
    int n,m,k;
    cin >> n >> m >> k;
    summ[0] = 0;
    REP(i,max(n,m)){
        summ[i + 1] = summ[i] + i + 1;
        summ[i+1] %= MOD;
    }
    /*
    REP(i,max(n,m)){
        summ[i+1] += summ[i];
        summ[i+1] %= MOD;
    }
    */

    //debug(solve(n,m,k));
    cout << (solve(n,m,k) + solve(m,n,k)) % MOD << endl;

}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

using Graph = vector<vector< pair<int, int> > >;

vector<int> ans, used;
int k = 0;

void dfs(Graph &G, int u){
    used[u] = 1;
    set<int> st;
    repe(i, G[u]){
        if(ans[i.second] != -1){
            st.insert(ans[i.second]);
        }
    }
    int col = 0;
    repe(i, G[u]){
        if(ans[i.second] == -1){
            while(st.count(col)>0) col++;
            ans[i.second] = col;
            col++;
            chmax(k, col);
        }
        if(!used[i.first]) dfs(G, i.first);
    }
}

int main(){
    fastcin();
    int n;
    cin >> n;
    Graph G(n);
    rep(i, n-1){
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].emplace_back(b, i);
        G[b].emplace_back(a, i);
    }

    ans.assign(n-1, -1);
    used.assign(n, 0);
    dfs(G, 0);
    cout << k << endl;
    repe(i, ans){
        cout << i+1 << endl;
    }

}

Measured memory_bytes: 14080
#include<stdio.h>
  
void print(int* A, int N){
  int i;
  for(i = 0; i < N; i++){
    if(i) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
}
  
int bubble_sort(int* A, int N){
  int i,j,minj,cnt = 0;
  for(i = 0; i < N; i++)
  {
      minj = i;
      for(j = i;j < N;j++)
      {
          if(A[j] < A[minj]) minj = j;
      }
      int tmp = A[i];
      A[i] = A[minj];
      A[minj] = tmp;
      if(i!=minj) cnt++;
  }
  print(A,N);
  return cnt;
}
  
int main(){
  int i,N,data[100];
  scanf("%d",&N);
  for(i = 0; i < N; i++) scanf("%d",&data[i]);
  printf("%d\n",bubble_sort(data,N));
  return 0;
}


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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int d, g;
    cin >> d >> g;
    vector<int> il(d), bonus(d);
    for (int i = 0; i < d; ++i)
        cin >> il[i] >> bonus[i];
    int odp = 1000;
    for (int i = 0; i < (1 << d); ++i)
    {
        int ile = 0, s = 0;
        for (int j = 0; j < d; ++j)
        {
            if ((i & (1 << j)) > 0)
            {
                s += il[j] * 100 * (j + 1) + bonus[j];
                ile += il[j];
            }
        }
        vector<int> kop = il;
        for (int j = d - 1; j >= 0; --j)
        {
            if ((i & (1 << j)) == 0)
            {
                while (kop[j] > 0 && s < g)
                {
                    --kop[j];
                    ++ile;
                    s += 100 * (j + 1);
                }
            }
        }
        if (s >= g)
            odp = min(odp, ile);
    }
    cout << odp;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define bug1(x) cout<<#x<<" = "<<x<<endl
#define bug2(x,y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define bug3(x,y,z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define bug4(x,y,z,m) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<" "<<#m<<" = "<<m<<endl

using namespace std;

template<class T> 
ostream& operator<<(ostream &os, vector<T> input) {
    os << "[ ";
    for(auto elem : input) { 
		os << elem << " ";
	}
	return os << "]";
}

template<class T> 
ostream& operator<<(ostream &os, set<T> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << elem << " ";
	}
	return os << "}";
}

template<class T> 
ostream& operator<<(ostream &os, unordered_set<T> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << elem << " ";
	}
	return os << "}";
}

template<class T> 
ostream& operator<<(ostream &os, multiset<T> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << elem << " ";
	}
	return os << "}";
}

template<class T> 
ostream& operator<<(ostream &os, unordered_multiset<T> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << elem << " ";
	}
	return os << "}";
}

template<class L, class R> 
ostream& operator<<(ostream &os, map<L,R> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << "(" << elem.first << "," << elem.second << ") ";
	}
	return os << "}";
}

template<class L, class R> 
ostream& operator<<(ostream &os, unordered_map<L,R> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << "(" << elem.first << "," << elem.second << ") ";
	}
	return os << "}";
}

#define ll long long
const int MAXN = 100005;
const int INF = 1e9;
const int MOD = 1e9 + 7;

class TaskA {
private:

public:
	void solveOne(int it){
		ll x;
		cin >> x;
		cout << 1 - x << endl;
	}

	void solve(){
		int tc = 1;
		for(int it = 1; it <= tc; it++){
			solveOne(it);
		}
	}
};


int main(){
	ios_base::sync_with_stdio(false);
	TaskA solver;
	solver.solve();
	return 0;
}


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

int main() {
  int n;cin >> n;
  vector<int>L(n);
  for(int i = 0; i < n; i++){
    int l;
    cin >> l;
    L.at(i) = l;
  }
  int ans = 0;
  for(int i = 0; i < n-2; i++){
    for(int j = i+1; j < n-1; j++){
      for(int k = j+1; k < n; k++){
        int count = 0;
        if(L.at(i) != L.at(j) && L.at(j) != L.at(k) && L.at(i) != L.at(k)){
          count++;
        }
        if(L.at(i) -L.at(j) < L.at(k) && L.at(k) < L.at(i) + L.at(j) && L.at(j) - L.at(i) < L.at(k)){
          count++;
        }
        if(count == 2)ans++;
      }
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 3588
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
 
using namespace std;
const int MAX_N = 100000;
long long N, M, A[MAX_N];
long long dp[MAX_N + 1];
 
void solve() {
    long long res = 0;
    unordered_map<long long, long long> mp;
 
    for (int i = 0; i < N; i++) {
        dp[i + 1] = (dp[i] + A[i]) % M;
        mp[dp[i + 1]] = mp[dp[i + 1]] + 1;
    }
 
    for (auto const &val: mp) {
        res += val.second * (val.second - 1) / 2;
        if (val.first == 0) {
            res += val.second;
        }
    }
 
    printf("%lld\n", res);
}
 
int main() {
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        A[i] = A[i] % M;
    }
    solve();
    return 0;
}

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

int main()
{
   int n;
   cin >> n;
   int p[n];
   for (int i = 0; i < n; i++) {
        cin >> p[i];
   }
   int cnt = 1;
   int mx = p[0];
   for (int i = 1; i < n; i++) {
        if (p[i] <= mx) {
            mx = p[i];
            cnt++;
        }
   }

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


Measured memory_bytes: 1024
#include<iostream>
#include<cctype>
#include<stdio.h>
using namespace std;

int main(){
    char ch;

    while((ch = getchar()) != EOF){
        if(isalpha(ch) == false){
            printf("%c", ch);
            continue;
        }

        if(islower(ch)){
            printf("%c", toupper(ch));
        }
        else{
            printf("%c", tolower(ch));
        }
    }
    
    return 0;
}


Measured memory_bytes: 3060
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
#include<string>
#include<iostream>

#define maxn 200005
#define INF 0x3f3f3f3f

using namespace std;

inline long long getint()
{
    long long num=0,flag=1;char c;
    while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;
    while(c>='0'&&c<='9')num=num*10+c-48,c=getchar();
    return num*flag;
}

int n,K;
int R,S,P;
char s[maxn];
long long ans;

int main()
{
	n=getint(),K=getint();
	R=getint(),S=getint(),P=getint();
	scanf("%s",s+1);
	for(int i=1;i<=n;i++)
	{
		if(i>K&&s[i]==s[i-K])s[i]=0;
		if(s[i]=='r')ans+=P;
		if(s[i]=='s')ans+=R;
		if(s[i]=='p')ans+=S;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<queue>
#include<deque>
#include<string>
#include<utility>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#include<ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<pli> vpli;
typedef vector<vi> mat;

#define I_Love_Hashimoto_Kanna main
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define filein(s) freopen(s,"r",stdin);
#define fileout(s) freopen(s,"w",stdout);
#define file freopen("I_Love_Hashimoto_Kanna.out","w",stdout);
#define RE cout<<"I_Love_Hashimoto_Kanna"<<endl;
#define Tone(Kanna) cout<<Kanna<<endl;
#define Tall(Hashimoto,Kanna) for(int I_Love=0;I_Love<Kanna;I_Love++)cout<<Hashimoto[I_Love]<<(I_Love==Kanna-1?"\n":" ");
#define FOR(I_Love,Hashimoto,Kanna) for(int I_Love=Hashimoto;I_Love<Kanna;I_Love++)
#define MP(Hashimoto,Kanna) make_pair(Hashimoto,Kanna)
#define REV(Kanna) reverse(Kanna.begin(),Kanna.end());
#define SORT(Kanna) sort(Kanna.begin(),Kanna.end());
#define inf (int)1e9
#define linf (ll)1e18
#define mod (inf+7)

int n;
ll a[222222];
map<ll,int> mp;

int I_Love_Hashimoto_Kanna() {
  fastio;
  cin>>n;
  ll cnt=0;
  mp[0]++;
  FOR(i,0,n){
  	cin>>a[i];
  	cnt+=a[i];
  	mp[cnt]++;
	}
	ll ans=0;
	for(map<ll,int>::iterator itr=mp.begin();itr!=mp.end();itr++){
		ll ha=itr->second;
		ans+=(ha)*(ha-1)/2;
	}
	cout<<ans<<endl;
  
  
  
  
  
  return 0;
}


Measured memory_bytes: 14336
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<utility>
#include <numeric>

using namespace std;
typedef long long ll;

void yes(){
cout<<"Yes"<<endl;
}
void no(){
cout<<"No"<<endl;
}
int main(){
ll a,b,k;
cin>>a>>b>>k;
for(ll i=1;i<=k;i++){
if(i%2==1){
if(a%2==1){
a--;
}
ll a2=a/2;
a-=a2;
b+=a2;
}
else{
if(b%2==1){
b--;
}
ll b2=b/2;
a+=b2;
b-=b2;
}

}
cout<<a<<" "<<b<<endl;
  return 0;
}



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

#define ll long long
#define ull unsigned long long
#define pb push_back
#define pii pair<int, int>
#define sz size()

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>void __f(const char* name, Arg1&& arg1){cout<<name<<" : "<<arg1<<"\n";}
template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args)
{const char* comma=strchr(names+1,',');cout.write(names,comma-names)<<" : "<<arg1<<" , ";__f(comma+1, args...);} 
#define traceloop(x,a) { cerr<<#a<<": "; for(ll ix=0;ix<x;ix++) cerr<<a[ix]<<" "; cerr<<endl; }

int main()
{
	ios::sync_with_stdio(0);

	int n, i, j, m, k;
	cin>>n;
	int a[n];
	for(i=0;i<n;++i)
		cin>>a[i];

	ll dp[n][n];
	memset(dp, 0, sizeof dp);
	for(k=0;k<=n;++k)
	{
		for(i=0;i+k<n;++i)
		{
			j = i + k;
			//trace(i, j);
			if(i==j)
				dp[i][i] = a[i];
			else
				dp[i][j] = max(-dp[i+1][j] + a[i], -dp[i][j-1] + a[j]);
		}
	}

	cout << dp[0][n-1] << "\n";

	return 0;
}

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

int main(){
	int N;
  	string S;
  	cin >> N;
  	string result = "Three";
  	for(int i = 0; i < N ; i ++){
      	cin >> S;
    	if(S == "Y"){
        	result = "Four";
          	break;
        }
    }
  	cout << result << endl;
}

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout.precision(12);
    cout.setf(ios_base::fixed, ios_base::floatfield);
    
    int n;
    string s;
    cin >> n;
    cin >> s;

    int r=0, b=0;
    for(int i=0;i<n;i++){
        if(s[i]=='R') r++;
        else b++;
    }

    if(r > b) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 256
program main
    implicit none
    integer(4):: h, n, i, j
    integer(4), allocatable:: a(:), b(:), dp(:), old_dp(:)
    integer(4), parameter:: inf = 100000001
    logical:: change = .true.

    read*, h,n
    allocate(a(n),b(n),dp(0:h), old_dp(0:h))

    do i = 1,n
        read*, a(i), b(i)
    end do

    dp(1:) = inf
    dp(0) = 0


    do while(change)
        old_dp(:) = dp(:)
        do i = 0, h
            do j = 1, n
                if (i+a(j) < h) then
                    dp(i+a(j)) = min(dp(i+a(j)), dp(i)+b(j))
                else
                    dp(h) = min(dp(h), dp(i)+b(j))
                end if
            end do
        end do

        change = .false.
        do i = 0, h
            if (dp(i) /= old_dp(i))then
                change = .true.
                exit
            end if
        end do       
    end do

    print*, dp(h)

end program main

Measured memory_bytes: 256
//IIT Kanpur FacelessMen India
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define foreach( gg,itit )  for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define mp make_pair
#define pb push_back
#define all(s) s.begin(),s.end()
#define present(c,x) ((c).find(x) != (c).end())
const double EPS = 1e-8;
const int mod = 1e9+7;
const int N = 1e6+10;
const ll INF = 1e18;

//#define DEBUG
ll power(ll x,ll y){
  ll t=1;
  while(y>0){
    if(y%2) y-=1,t=t*x%mod;
    else y/=2,x=x*x%mod;
  }
  return t;
}
#ifdef DEBUG
#define dprintf(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#else
#define dprintf(fmt,...)
#endif

int col[N];
int di[N][11];
vector<int> G[N];
vector<pair<pii,pii> > P;

int main(){
  // freopen("product.in","r",stdin);
  // freopen("product.out","w",stdout);
  int n,m; scanf("%d%d",&n,&m);
  REP(i,m){
    int x,y; scanf("%d%d",&x,&y);
    x--;y--; G[x].pb(y); G[y].pb(x);
  }
  FILL(col,0);
  int q;  scanf("%d",&q);
  REP(i,q){
    int v,d,c; scanf("%d%d%d",&v,&d,&c);
    v--;
    P.pb(mp(mp(i+1,v),mp(d,c)));
    
  }
  reverse(all(P));
  REP(i,P.size()){
    pair<pii,pii> tp;
    queue<pair<pii,pii> > Q;
    Q.push(P[i]);
    while(!Q.empty()){
      pair<pii,pii> tp = Q.front(); Q.pop(); 
      
      if(col[tp.X.Y]==0) col[tp.X.Y]=tp.Y.Y;
      if(tp.Y.X==0) continue;
      int v=tp.X.Y;
      if(di[v][tp.Y.X-1]==0){
        di[v][tp.Y.X-1] = tp.X.X;
        Q.push(mp(mp(tp.X.X,v),mp(tp.Y.X-1,tp.Y.Y))); 
      }
      REP(i,G[v].size())if(di[G[v][i]][tp.Y.X-1]==0){
        di[G[v][i]][tp.Y.X-1] = tp.X.X;
        Q.push(mp(mp(tp.X.X,G[v][i]),mp(tp.Y.X-1,tp.Y.Y)));
      }
    }
  }
  
  REP(i,n) printf("%d\n",col[i]);
  return 0;
}


Measured memory_bytes: 42096
wfwfe=input()
check=0
b=input().split()
if "0" in b:
    print (0)
else:
    
    count=1
    for i in b:
        count=count*int(i)
        
        if count>10**18:
            print (-1)
            check=1
            break
    if check==0:
        print (count)
        


Measured memory_bytes: 19116
import copy
l = []
for i in (range(5)):
    l.append(int(input()))

k = int(input())
f = False
for a in l:
    for b in l:
        if a != b:
            if b - a > k:
                f = True

if f:
    print(":(")
else:
    print("Yay!")


Measured memory_bytes: 3444
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string.h>
#include <queue>
#include <functional>
const int INF =1e5;
const int MOD = 1e9 + 7;
using namespace std;
typedef pair<int,int> P;
typedef long long lint;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fill(x,y) memset(x,y,sizeof(x))
#define all(x) (x).begin(),(x).end()
#define pb push_back

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if((a+b)<c){
        cout<<"No"<<endl;
    }else{
         cout<<"Yes"<<endl;
    }
    return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

using namespace std;

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if (A + B > C + D) {
    printf("Left\n");
  } else if (A + B < C + D) {
    printf("Right\n");
  } else {
    printf("Balanced\n");
  }
}

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

typedef long long LL;

LL X,Y,A,B,C;
vector<int>a,b,c;

int main()
{
	cin>>X>>Y>>A>>B>>C;
	
	for(int i=1;i<=A;i++) {
		int k;
		cin>>k;
		a.push_back(k);
	}
	for(int i=1;i<=B;i++) {
		int k;
		cin>>k;
		b.push_back(k);
	}
	for(int i=1;i<=C;i++) {
		int k;
		cin>>k;
		c.push_back(k);
	}
	sort(a.begin(),a.end(),greater<int>());
	sort(b.begin(),b.end(),greater<int>());
	for(int i=0;i<X;i++) {
		c.push_back(a[i]);
	}
	for(int i=0;i<Y;i++) {
		c.push_back(b[i]);
	}
	
	sort(c.begin(),c.end(),greater<int>());
	
	LL res=0;
	for(int i=0;i<X+Y;i++) res+=c[i]; 
	
	cout<<res<<'\n';
	return 0; 
} 


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main() {
    int A, B, K;
    cin >> A >> B >> K;

    for (int i = 0; i < K; i++) {
        A /= 2;
        B += A;
        swap(A, B); 
    }

    if (K%2 == 1) swap(A, B);
    cout << A << " " << B << endl;
}

Measured memory_bytes: 256
from functools import lru_cache

MOD = 10**9 + 7

@lru_cache(None)
def F(N):
  # (u,v) = (a^b,a+b), (a^b,a+b+1) という組の個数x,y. where v <= N
  if N == 0:
    return 1,1
  x,y = 0,0
  # (0,0) mod 2
  x1,y1 = F(N//2)
  x += x1
  y += x1
  # (0,1) mod 2
  x2,y2 = F((N-1)//2)
  x += x2
  y += y2
  # (1,1) mod 2
  if N > 1:
    x3,y3 = F((N-2)//2)
    x += y3
    y += y3

  return x%MOD,y%MOD
  
answer = F(int(input()))[0]
           
print(answer)
  
  
  

Measured memory_bytes: 3828
using System;

namespace Sample1
{
    class Program
    {
        static void Main(string[] args)
        {
            bool notZero = true;
            while (notZero)
            {
                string input = Console.ReadLine();
                int[] numbers = new int[]
                    {
                int.Parse(input.Split(' ')[0]),
                int.Parse(input.Split(' ')[1]),
                    };
                Array.Sort(numbers);
                if (numbers[0] == 0 &&
                    numbers[1] == 0)
                {
                    notZero = false;
                }
                else
                {
                    Console.WriteLine("{0} {1}", numbers[0], numbers[1]);
                }

            }
        }
    }
}

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

#define ll long long
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define forn(i,n) for(ll i=0; i<(n); i++)
#define fori(i,k,n) for(ll i=k; i<(n); i++) 
#define all(x) (x).begin(),(x).end()
#define en '\n'
#define FILL(x,v) memset(x,v,sizeof(x))
#define pb push_back

template<typename T> void print(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
 
template<typename T> void print(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
 
template<typename T> void print(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

const ll MOD = 1e9+7;

void solve2(){
	ll n, k, ans=0;
	cin >> n >> k;
	// finding the range
	for(int i=k; i<=n+1; i++){
		ans += i*(n-i+1) + 1;
		ans %= MOD;
	}
	cout << ans << en;
}


int main(){
    ios::sync_with_stdio(0);
	cin.tie(0);
    cout.tie(0);
 
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
    int t = 1;
	// cin >> t;
    while(t--)
        solve2();
    return 0;
}

Measured memory_bytes: 3676
import sys
sys.setrecursionlimit(10**7)
from collections import defaultdict

import collections
import itertools
import operator


class UnionFind:
    def __init__(self, elems=None):
        class KeyDict(dict):
            def __missing__(self, key):
                self[key] = key
                return key

        self.parent = KeyDict()
        self.rank = collections.defaultdict(int)

        if elems is not None:
            for elem in elems:
                _, _ = self.parent[elem], self.rank[elem]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1

    def are_same(self, x, y):
        return self.find(x) == self.find(y)

    def grouper(self):
        roots = [(x, self.find(x_par)) for x, x_par in self.parent.items()]
        root = operator.itemgetter(1)
        for _, group in itertools.groupby(sorted(roots, key=root), root):
            yield [x for x, _ in group]


'''
def init(n):
    return list(range(n+1))#
def find(lis, x):
    if lis[x] == x:
        return x
    else:
        lis[x] = find(lis, lis[x])
        return lis[x]

def sameset(lis, x, y):
    return find(lis, x) == find(lis, y)

def union(lis, x, y):
    x = find(lis, x)
    y = find(lis, y)
    if x != y:
        lis[x] = y
'''

N = int(input())
#union_find_tree = init(N)

town = []

for i in range(N):
    x, y = map(int, input().split())
    town.append((i, x, y))

x_sorted_town = sorted(town, key=lambda x: x[1])
y_sorted_town = sorted(town, key=lambda x: x[2])

graph = []

pre_tx = x_sorted_town[0]
pre_ty = y_sorted_town[0]
pre_nx = town[pre_tx[0]]
pre_ny = town[pre_ty[0]]
for tx, ty in zip(x_sorted_town[1:], y_sorted_town[1:]):
    nx = town[tx[0]]
    ny = town[ty[0]]
    wx = min(abs(tx[1] - pre_tx[1]), abs(nx[2] - pre_nx[2]))
    wy = min(abs(ty[2] - pre_ty[2]), abs(ny[1] - pre_ny[1]))
    graph.append((nx[0], pre_nx[0], wx))
    graph.append((ny[0], pre_ny[0], wy))
    pre_tx = tx
    pre_ty = ty
    pre_nx = nx
    pre_ny = ny

uf = UnionFind()

cost = 0
for (s,t,w) in sorted(graph, key=lambda x: x[2]):
    if not uf.are_same(s,t):
        uf.unite(s,t)
        cost += w
print(cost)

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

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, w;
    cin >> n >> w;
    vector<int> weight(n+1), value(n+1);
    const int bound = 1000*100+1;
    vector<vector<int>> memo(n+1, vector<int>(bound, 1e18));
    memo[0][0] = 0;
    for(int i = 1; i <= n; ++i) {
        cin >> weight[i] >> value[i];
        for(int j = 0; j <= bound; ++j) {
            memo[i][j] = min(memo[i][j], memo[i-1][j]);
            if(j-value[i] >= 0)
                memo[i][j] = min(memo[i][j], weight[i]+memo[i-1][j-value[i]]);
        }
    }
    int res = 0;
    for(int j = 0; j < bound; ++j) {
        if(memo[n][j] <= w) res = j;
    }
    cout << res << '\n';
    return 0;
}


























Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define ll unsigned long long int
#define test long int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
#define mm 1000000007

bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int binaryExponentiation(int x, int n) //function to calculate x raise to power n
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x;
		x = x * x;
		n = n / 2;
	}
	return result;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-______________________________________________________________________________

	int n;
	cin >> n;
	int x = n % 10;
	if (n % 10 == 3)
	{
		cout << "bon" << en;
	}
	else if (x == 0 || x == 1 || x == 6 || x == 8)
	{
		cout << "pon" << en;
	}
	else {
		cout << "hon" << en;
	}


	return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <algorithm>
#include <unordered_map>
#define int                long long
#define pb                 push_back
#define pi                 pair<int,int>
#define vi                 vector<int>
#define all(v)             v.begin(),v.end()
#define MOD                1000000007
#define F                  first
#define S                  second
#define FOR(i,r)           for(int i=0;i<r;i++)
#define REP(i,l,r)         for(int i=l;i<r;i++)
#define RER(i,l,r)         for(int i=l;i>=r;i--)
#define print(v)           for(auto i : v)cout << i << ' ';
#define FASTIO             ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mem(arr,k)         memset(arr,k,sizeof(arr));
#define pii                acos(-1.0)
#define PI                 3.1415926535897932385
#define Sin(a)             sin((pi*a)/180)
#define test()             int x;cin >> x;while(x--)
using namespace std;
const int inf = (int)1e11;
const int N = (int)1e5+6;
int32_t main(){

	
	FASTIO;
	int a,b,c;
	cin >> a >> b >> c;
	cout << c << ' ' << a << ' ' << b << endl;
    return 0;

}

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

using namespace std;

#define int long long
bool isprime(int num){
	if(num==1){
		return false;
	}
	if(num==2)
		return true;
	if(num%2==0)
		return false;
	double sqrtNum = sqrt(num);
    for (int  i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}
vector<int> v;
signed main(){
	int n,m;
	cin>>n>>m;
	int temp=min(n,m);
	for(int i=1;i*i<=temp;i++){
		if(temp%i==0){
			v.push_back(i);
			if(i*i!=temp){
				v.push_back(temp/i);
			}
		}
	}
	int ans=0;
	int t=max(n,m);
	for(int i=0;i<v.size();i++){
		if(t%v[i]==0&&isprime(v[i]))
			ans++;
	}
	cout<<ans+1;
	return 0;
}

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

int main() {
  size_t D;
  unsigned long G;
  std::cin >> D;
  std::cin >> G;

  std::vector<size_t> P(D);
  std::vector<unsigned long> C(D);

  size_t ans = 0;

  for (size_t i=0; i<D; i++) {
    std::cin >> P[i];
    std::cin >> C[i];

    ans += P[i];
  }

  for (size_t flags=0; flags<((1<<D)-1); flags++) {
    size_t max_i=0;
    size_t p=0;
    unsigned long score=0;
    for (size_t i=0; i<D; i++) {
      if ((flags>>i)%2==1) {
        p += P[i];
        score += 100*(i+1) * P[i];
        score += C[i];
      } else {
        max_i = i;
      }
    }

    if (score >= G) {
      ans = std::min(ans, p);
    } else {
      for (size_t i=0; i<P[max_i]-1; i++) {
        p++;
        score += 100*(max_i+1);
        if (score >= G) {
          ans = std::min(ans, p);
          break;
        }
      }
    }
  }

  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define INF 1000000007
#define LINF 1000000000000000007
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
typedef long long ll;
typedef long double ld;
long long dx[] = {1,0,-1,0};
long long dy[] = {0,1,0,-1};
long long dx8[] = {1,1,0,-1,-1,-1,0,1};
long long dy8[] = {0,1,1,1,0,-1,-1,-1};
long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};

signed main(){
    int N;
    cin >> N;
    int x;
    FOR(i,0,N){
        cin >> x;
        if(x%2){
            cout << "first" << endl;
            return 0;
        }
    }
    cout << "second" << endl;
}

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

int main() {
    int n, a;
    cin >> n >> a;
    int x[n];
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    int size = n * a + 1;
    long long dp[n + 1][size] = {}, result = 0;
    dp[0][0] = 1;
    for (int k = 0; k < n; k++) {
        for (int i = n; i >= 0; i--) {
            for (int j = size - 1; j >= x[k]; j--) {
                dp[i][j] += dp[i - 1][j - x[k]];
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        result += dp[i][i * a];
    }
    cout << result;
    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <new>

using namespace std;

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
	
int main(){
    ll a=0,b=0;
    string A,ANS;
    cin >> A;

    a = A.size();
    for(ll i = 0;i < a;i++){
        ANS += 'x';
    }
    cout << ANS << endl;

    return 0;

}

Measured memory_bytes: 256
import numpy as np

n=int(input())

def div2(x,y):
    if x>0:
        return (1,y/x)
    elif x<0:
        return (-1,y/x)
    else:
        if y>0:
            return (-1,-float("inf"))
        else:
            return (1,-float("inf"))
    

L=[list(map(int,input().split())) for i in range(n)]

L.sort(key=lambda x:div2(x[0],x[1]))

m=0
for i in range(n):
    for j in range(i,n):
        x0=y0=0
        x1=y1=0
        for k in range(n):
            if i<=k<=j:
                x0+=L[k][0]
                y0+=L[k][1]
            else:
                x1+=L[k][0]
                y1+=L[k][1]
        m=max(m,x0**2+y0**2,x1**2+y1**2)

print('{:.12f}'.format(np.sqrt(m)))

Measured memory_bytes: 12464
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;
const int MOD = 1000000007;

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

  int n; cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];
  int m; cin >> m;
  vi b(m);
  rep(i, m) cin >> b[i];

  for (int i = 0; i < m; ++i) {
    if (!binary_search(all(a), b[i])){
      cout << 0 << '\n'; return 0;
    }
  }
  cout << 1 << '\n';

  return 0;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    int N; cin >> N;
    ll ans1 = 0;
    ll num1 = 0;

    ll ans2 = 0;
    ll num2 = 0;
    REP(i,N){
        ll a; cin >> a;
        num1 += a;
        if(i%2==0 && num1 <= 0){
            ans1 += 1-num1;
            num1 = 1;
        }else if(i%2==1 && num1 >= 0){
            ans1 += num1+1;
            num1 = -1;
        }

        num2 += a;
        if(i%2==1 && num2 <= 0){
            ans2 += 1-num2;
            num2 = 1;
        }else if(i%2==0 && num2 >= 0){
            ans2 += num2+1;
            num2 = -1;
        }
    }
    cout << min(ans1,ans2) << endl;
    return 0;
}

Measured memory_bytes: 3556
A, B, K = map(int, input().split())
if A < K:
    K = K - A
    A = 0
elif A == K:
    A = 0
    K = 0
else:  # K < A
    A = A - K
    K = 0

if B < K:
    K = K - B
    B = 0
elif B == K:
    B = 0
    K = 0
else:  # K < B
    B = B - K
    K = 0

print(A, B)


Measured memory_bytes: 38384
#include <stdio.h>
#include<math.h>
int main()
{
 long int x[26]={0},y,z,sum,i=0,k;
 char a[2];
 gets(a);
 
if(a[0]==a[2])
{
    printf("Yes");
    
}else{
    printf("No");
}
    return 0;
}


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

using namespace std;

int f[3][32], x, c, n, d[32][32], nr, sol;

int main ()
{
  sol = INT_MAX;
  cin >> n >> c;
  for (int i = 1; i <= c; i++)
    for (int j = 1; j <= c; j++)
      cin >> d[i][j];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> x;
      f[(i + j) % 3][x]++;
    }
  }
  for (int i = 1; i <= c; i++)
    for (int j = 1; j <= c; j++)
      if (i != j)
        for (int k = 1; k <= c; k++)
          if (k != i && k != j) {
            nr = 0;
            for (int l = 1; l <= c; l++) {
              nr += d[l][i] * f[0][l];
              nr += d[l][j] * f[1][l];
              nr += d[l][k] * f[2][l];
            }
            if (sol > nr)
              sol = nr;
          }
  cout << sol;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

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

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll X, Y, A,B,C;
    cin >> X >> Y >> A >> B >> C;
    vector<pair<ll, int>> v;
    rep(i,A){
        ll p;
        cin >> p;
        v.push_back({p, 0});
    }
    rep(i,B){
        ll p;
        cin >> p;
        v.push_back({p, 1});
    }
    rep(i,C){
        ll p;
        cin >> p;
        v.push_back({p, 2});
    }
    sort(all(v));
    reverse(all(v));
    //printpair(v);
    ll cnt[] = {0,0,0};
    /*
    ll dp[v.size()+1][2];
    rep(i,v.size()+1)rep(j,2){
        dp[i][j] = -1;
    }*/
    ll ans = 0;
    ll sum = 0;
    rep(i,v.size()){
        int id = v[i].second;
        int cost = v[i].first;
        if(id == 0){
            if(cnt[id] == X)continue;
            if(sum == X + Y)continue;
            cnt[id]++;
            sum++;
            ans += cost;
        }
        if(id == 1){
            if(cnt[id] == Y)continue;
            if(sum == X + Y)continue;
            cnt[id]++;
            sum ++;
            ans += cost;
        }
        if(id == 2){
            if(sum == X + Y)continue;
            cnt[id]++;
            sum++;
            ans += cost;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 10604
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
#define PI (3.141592653589793)
using namespace std;

signed main(){
    int n; cin>>n;
    vector<int> a(n),b(n-n/2);
    rep(i,n){
        cin>>a.at(i);
        if(i%2==0)b.at(i/2)=a.at(i);
    }
    sort(all(a));
    sort(all(b));
    map<int,int> mp;
    rep(i,n){
        if(i%2==0)mp[a.at(i)]++;
    }
    int ans=0;
    rep(i,b.size()){
        if(mp[b.at(i)]==0){
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 7680
#[allow(unused_imports)]
use std::collections::VecDeque;
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::collections::HashMap;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_variables)]
        #[allow(unused_mut)]
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, string).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, string).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("parse error")
    };
}

fn main() {
    input!{
        n: usize,
        k: usize,
        v: [i32; n]
    }
    let mut costs = vec![std::i32::MAX; 100010];
    costs[0] = 0;
    for i in 1..n {
        let max_len = cmp::min(n, i+k);
        for j in i..max_len {
            costs[j] = cmp::min(costs[j], costs[i - 1] + (v[i - 1] - v[j]).abs());
        }
    }
    println!("{}", costs[n - 1]);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main()
{
  int a,b;
  cin>>a>>b;
  bool ok = false;
  for(auto&& i:irange(1,1100)) {
    if (i * 8 / 100 != a) continue;
    if (i / 10 != b) continue;
    cout<<i<<endl;
    ok = true;
    break;
  }
  if (!ok) {
    cout<<-1<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }



int N;

int main() {
    while (cin >> N) {
        int res = 50;
        for (int i = 0; i < N; ++i) {
            int T;
			int tmp = 0;
			cin >> T;
			while (T % 2 == 0) ++tmp, T /= 2;
			chmin(res, tmp);
        }
        cout << res << endl;
    }
}


















Measured memory_bytes: 256