akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
/*
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
*/
#define ull unsigned long long int
#define ll long long int
#define MAX 1000000007
#define MOD 998244353
//1e9+7
#define pll pair<ll,ll>
#define pii pair<int,int>
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FO ifstream fin("a.in");ofstream fout("a.out");
#define TEST ll T;cin>>T;while(T--)
#define all(x) (x).begin(),(x).end()
#define mset0(x) memset((x), 0, sizeof((x)));
#define mset1(x) memset((x), -1, sizeof((x)));
typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

void solve(){
    string s;
    cin>>s;
    int n=s.size();
    for(int i=0;i+2<n;i++){
        if(s[i]-'a'>=0 && s[i+1]-'a'>=0 && s[i+2]-'a'>=0){
            string p="";
            p+=s[i];p+=s[i+1];p+=s[i+2];
            cout<<p;
            return;
        }
    }

    return;
}
int main(){
    IO
    //TEST
    solve();
    return(0);
}


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

const int MOD = 1e9 + 7;

int main(){
	int h,w;
	cin >> h >> w;
	vector<vector<char>> a(h, vector<char>(w));
	rep(i,h){
		string s;
		cin >> s;
		rep(j,w) a[i][j] = s[j];
	}
	
	vector<vector<ll>> dp(h, vector<ll>(w));
	rep(i,h){
		rep(j,w){
			if(a[i][j]=='#') continue;
			
			if(i==0 && j==0){
				dp[i][j] = 1;
			}
			else if(i-1 >= 0 && j-1 >= 0){
				dp[i][j] = ( dp[i-1][j] + dp[i][j-1] ) % MOD;
			}
			else if(i-1 >= 0){
				dp[i][j] = dp[i-1][j];
			}
			else{
				dp[i][j] = dp[i][j-1];
			}
		}
	}
	
	cout << dp[h-1][w-1] << endl;
	return 0;
}

Measured memory_bytes: 9088
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

vector<int> all;
int dp[20][100001];
int solve(int now, int nokori){
	if(nokori < 0) return 10000;
	if(nokori == 0) return 0;
	if(now == all.size()) return 10000;
	if(dp[now][nokori] != -1) return dp[now][nokori];
	return dp[now][nokori] = min(solve(now+1,nokori),solve(now,nokori-all[now])+1);
}

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

	int N;
	cin >> N;
	
	all.push_back(1);
	for(int i=6; i<=N; i*=6) all.push_back(i);
	for(int i=9; i<=N; i*=9) all.push_back(i);
	sort(all.begin(), all.end());
	reverse(all.begin(), all.end());

	for(int i=0; i<all.size(); i++){
		for(int j=0; j<=N; j++){
			dp[i][j] = -1;
		}
	}
	
	cout << solve(0,N) << endl;

	return 0;
}



Measured memory_bytes: 6400
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<sys/time.h>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline ll ri()
{
	register ll x=0;register bool f=0;register char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();};
	return f?-x:x;
}
void wi(ll x)
{
	if(x<0)	x=-x,putchar('-');
	if(x>9)	wi(x/10);
	putchar('0'+x%10);
}
const int N=1005,M=2005,p=1e9+7;
int fa[N],vf[N],dep[N],head[N],nxt[N<<1],to[N<<1],val[N<<1],f[N];
struct edge
{
	int u,v,w,vis;
	bool operator <(const edge &t)const
	{
		return w<t.w;
	}
}e[M];
inline ll mpow(ll a,int x)
{
	ll res=1;
	for(;x;x>>=1,a=a*a%p)
		if(x&1)	res=res*a%p;
	return res;
}
int getf(int x)
{
	return f[x]==x?x:f[x]=getf(f[x]);
}
inline void ade(int x,int y,int z)
{
	nxt[++nxt[0]]=head[x];
	head[x]=nxt[0];
	to[nxt[0]]=y;
	val[nxt[0]]=z;
}
void dfs(int x)
{
	dep[x]=dep[fa[x]]+1;
	for(int now=head[x];now;now=nxt[now])
	{
		if(to[now]==fa[x])	continue;
		fa[to[now]]=x;dfs(to[now]);
		vf[to[now]]=val[now];
	}
}
int getp(int u,int v)
{
	int res=-1;
	while(u!=v)
	{
		if(dep[u]>dep[v])	swap(u,v);
		res=max(res,vf[v]),v=fa[v];
	}
	return res;
}
int main()
{
	int tmp,n=ri(),m=ri(),i,equ=0,upp=0;
	ll res=0,x=ri(),d;
	for(i=1;i<=n;i++)	f[i]=i;
	for(i=1;i<=m;i++)	e[i].u=ri(),e[i].v=ri(),e[i].w=ri();
	sort(e+1,e+1+m);
	for(i=1;i<=m;i++)
	{
		if(getf(e[i].u)==getf(e[i].v))	continue;
		f[getf(e[i].u)]=getf(e[i].v);
		ade(e[i].u,e[i].v,e[i].w);ade(e[i].v,e[i].u,e[i].w);
		res+=e[i].w;e[i].vis=1;
	}
	d=x-res;
	dfs(1);
	if(d<0){puts("0");return 0;}
	for(i=1;i<=m;i++)
	{
		if(e[i].vis)	continue;
		tmp=e[i].w-getp(e[i].u,e[i].v);
		if(tmp==d)	equ++;
		if(tmp>d)	upp++;
	}
	if(d==0)	wi((((mpow(2,n-1)-2)*mpow(2,m-n+1)%p+mpow(2,upp+1)*(mpow(2,equ)-1)%p)%p+p)%p);
	else	wi(mpow(2,upp+1)*(mpow(2,equ)-1)%p);
	putchar('\n');
	return 0;
}


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

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

Measured memory_bytes: 256
from collections import defaultdict
import itertools

def main():
    H,W,K = [int(x) for x in input().split()]

    B = 0
    BH = [0]*H
    BW = [0]*W
    BHW = []
    pBHW = []
    for h in range(H):
        BHW.append([0]*W)
    for i in range(H):
        C = list(input())
        for j in range(W):
            if C[j] == '#':
                B += 1
                BH[i] += 1
                BW[j] += 1
                BHW[i][j] = 1
                pBHW.append((i,j))

    cnt = 0
    for ibit in range(0,1<<H):
        for jbit in range(0,1<<W):
            icost = 0
            jcost = 0
            ijcost = 0
            for i in range(H):
                if (1<<i) & ibit:
                    icost += BH[i]
            for j in range(W):
                if (1<<j) & jbit:
                    jcost += BW[j]
            for i in range(H):
                for j in range(W):
                    if (1<<i) & ibit and (1<<j) & jbit:
                        ijcost += BHW[i][j]
            b = B - icost - jcost + ijcost
            if K == b:
                cnt += 1
            # print(b,B,icost,jcost,ijcost,cnt)
    print(cnt)
                        
    # print(B)
    # print(BH)
    # print(BW)
    # print(BHW)
    # print(pBHW)
    # for k in itertools.combinations(pBHW,2):
    #     print(k)
    # cnt = 0

    # costs_i = []
    # for ibit in range(0,1<<H):
    #     cost = 0
    #     for i in range(H):
    #         if (1<<i) & ibit:
    #             cost += BH[i]
    #     costs_i.append(cost)
    # costs_j = []
    # for jbit in range(0,1<<W):
    #     cost = 0
    #     for j in range(H):
    #         if (1<<j) & jbit:
    #             cost += BW[j]
    #     costs_j.append(cost)
    # print(costs_i)
    # print(costs_j)
    
    # for ci in costs_i:
    #     for cj in costs_j:
    #         b = B - ci - cj + BHW[i][j]
    #         if K == b:
    #             cnt += 1
    #         print(i,j,b,B,BH[i],BW[j],BHW[i][j],cnt)
    # print(cnt)

if __name__ == '__main__':
    main()

Measured memory_bytes: 68836
object Main{
  def main(args: Array[String]){
    val input=io.Source.stdin.getLines().mkString("\n")
    println(solve(input).trim())
  }

  def solve(input:String):String={
    val Array(n,m)=input.split(" ").map(_.toInt)
    ((n-1)*(m-1)).toString
  }
}


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

int main(){
    int n;
    cin>>n;
    char c1,c2;
    cin>>c1;
    char ans;
    for (int i = 1; i < n; ++i) {
        cin>>c2;
        if(c1=='T'&&c2=='T')ans='T';
        else if(c1=='T'&&c2=='F')ans='F';
        else if(c1=='F'&&c2=='T')ans='T';
        else if(c1=='F'&&c2=='F')ans='T';
        c1=ans;
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3076
N,M = (int(x) for x in input().split())
Problem = [False]*N
WACount = [0]*N

for T in range(0,M):
    p,s = input().split()
    p = int(p)
    if (not Problem[p-1]) and s=='AC':
        Problem[p-1] = True
    elif (not Problem[p-1]) and s=='WA':
        WACount[p-1] += 1
WACount = [x*y for (x,y) in zip(Problem,WACount)]
print('{} {}'.format(sum(Problem),sum(WACount)))

Measured memory_bytes: 11424
require 'prime'
require 'set'
require 'tsort'
include Math
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

n,m = gi
mm = darray n,n, 0
rep m do |i|
a,b = gi
mm[a-1][b-1] += 1
mm[b-1][a-1] += 1
end

rep n do |i|
  ans = 0
rep n do |j|
ans += mm[i][j]
end
puts ans
end



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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int p = 0, q = 0;
	string d; cin >> d;
	for (int f = 0; f < a; f++) {
		switch (d[f]) {
		case 'a':if (p + q < b + c) { cout << "Yes" << endl; p++; }
				 else cout << "No" << endl;
				 break;
		case 'b':if (p + q < b + c&&q < c) { cout << "Yes" << endl; q++; }
				 else cout << "No" << endl;
				 break;
		case 'c':cout << "No" << endl;
		}
	}
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define REPS(i,n) for(int i=1;i<=(int)(n);i++)
using namespace std;
using ll = long long;
using ld = long double;

int main(void) {
    int X, Y, Z;
    cin >> X >> Y >> Z;

    cout << Z << " " << X << " " << Y << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define PN cout << endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (n-1); i >= (int)(m); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - (a)) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - (a)) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return


ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }


/*
vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}
*/

/*
ll ncr[100][100];
ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

ll npr[100][100]={};
ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

ll nHr(int n,int r){ret nCr(n+r-1,r);}
*/

///////////////////////////////////////////////////////////////////////////



int main(){

    int n;
    cin >> n;
    int a[n];
    inrep(n,a);

    int c = 1,ans = 0;
    rep(i,0,n){
	if(a[i] == c){
	    c++;
	}else{
	    ans++;
	}
    }

    if(c == 1)P(-1);
    else P(ans);
    return  0;
}


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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

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

int dy[4]={-1,1,0,0};
int dx[4]={0,0,1,-1};
int N, A, B;
int main(){
    ios::sync_with_stdio(false);
    cin >> N >> A >> B;
    if ((B - A) % 2) {
        cout << "Borys" << endl;
    } else {
        cout << "Alice" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int           long long
#define	pb            push_back
#define all(a)        (a).begin(),(a).end()
#define sz(x)         (int)x.size()
#define F             first
#define S             second
#define endl          "\n"
#define inf           1000000007
#define FOR(i, a, b)  for(int i=a; i<b; i++)
#define bigboi        1e18
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); 
#define SHUF(v) shuffle(all(v), RNG);
// Use mt19937_64 for 64 bit random numbers. 


void solve(){
	int n;
	cin>>n;
	cout<<(n+1)/2<<endl;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0); 	
	int t=1;
	//cin>>t;
	FOR(i, 1, t+1){	
	//	cout<<"Case #"<<i<<":"<<endl;
		solve();
	}
	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
	return 0;
 
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(0, min(b,d)-max(a,c)) << "\n";
    return 0;
}


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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

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


int main(void){

	int A, B, C; cin >> A >> B >> C;

	int d = max(A - B, 0);
	int ans = max(C - d, 0);

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, m;
	cin >> n >> m;
	vi s(m), c(m);
	rep(i, m) cin >> s[i] >> c[i];
	rep(i, 1000){
		string num = to_string(i);
		if((int)num.size() == n){
			int f = 1;
			rep(j, m){
				if(num[s[j] - 1] != (char)(c[j] + '0')){
					f = 0;
					break;
				}
			}
			if(f){
				cout << i << endl;
				return 0;
			}
		}
	}
	cout << -1 << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

int main() {
    ll t, a, k;
    cin >> t >> a >> k;
    if (t >= k) {
        cout << t - k << " " << a << endl;
    } else if (t + a >= k) {
        cout << 0 << " " << t + a - k << endl;
    } else {
        cout << 0 << " " << 0 << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long INF = 123456789;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i, r, n) for (ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i, r, n) for (ll i = (ll)(n - 1); i >= r; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/

ll dp[1006][1006] = { 0 };

int main()
{
    cin >> n;
    ll ma = 0;
    REP(i, n)
    {
        string t;
        cin >> s >> t;
        ma = 0;
        s = ' ' + s; //????????????????????????
        t = ' ' + t;
        FOR(i, 1, s.size())
        {
            dp[i][0] = 0;
        }
        FOR(i, 1, t.size())
        {
            dp[0][i] = 0;
        }
        FOR(i, 1, s.size())
        {
            FOR(j, 1, t.size())
            {
                if (s[i] == t[j]) {
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                } else {
                    dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
                }
                ma = max(ma, dp[i][j]);
            }
        }
        cout << ma << Endl;
    }
}

Measured memory_bytes: 11104
from scipy.sparse.csgraph import floyd_warshall

n, m, r = map(int,input().split())
rs = list(map(int, input().split()))
edge = [[0]*n for i in range(n)]
for i in range(m):
    a, b, c = list(map(int, input().split()))
    a, b = a-1, b-1
    edge[a][b] = c
    edge[b][a] = c
dist = floyd_warshall(edge, directed=False)

from itertools import permutations
ans = float("inf")
    
for v in permutations(rs, len(rs)):
    dist_tmp = 0
    for i in range(r-1):
        dist_tmp += dist[v[i]-1][v[i+1]-1]
    ans = min(ans, int(dist_tmp))
print(ans)

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

using namespace std;
typedef pair<int,int> pii;
typedef long long ll;

map<pii, int> vals;
pii all[105];
ll cnt(int n, int w){
    if(n < -1 || w < 0) return -9999999999;
    if(n == -1 || w == 0) return 0;
    if(vals.find(pii(n,w))!=vals.end()){
        return vals[pii(n,w)];
    }
    ll res = 0;

    res = max(cnt(n-1,w), all[n].second + cnt(n-1,w-all[n].first));

    vals[pii(n,w)]=res;
    return res;
}
int main(){
    ll n, w;
    cin >> n >> w;
    for(int i = 0; i < n; i++){
        cin >> all[i].first>> all[i].second;
    }
    cout << cnt(n-1,w);
    return 0;
}


Measured memory_bytes: 6144
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  for(int i = 0;i < n;i++)cin >> a[i];
  ll now = 1000;
  ll mi = pow(10,18);
  for(int j = 0;j < n;j++){
    if(mi < a[j]){
      ll buy = now / mi;
      now = now - buy * mi + a[j] * buy;
      mi = a[j];
    }
    else if(mi > a[j])mi = a[j];
  }
  cout << now << endl;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<functional>
#include<set>
#include<map>
using namespace std;
#define rep(i,l,r) for(register int i=(l);i<=(r);++i)
#define repdo(i,l,r) for(register int i=(l);i>=(r);--i)
#define il inline
typedef double db;
typedef long long ll;

//---------------------------------------
namespace ubospica{

const int nsz=205,vsz=1e5+50;
const ll nmod=1e9+7;
int n;
ll x,li[nsz];
ll ans,dp[vsz];
ll inv[vsz]{0,1};
void init(int bnd){rep(i,2,bnd)inv[i]=inv[nmod%i]*((ll)nmod-nmod/i)%nmod;}//be aware of overflow!

void add(ll &a,ll b){a=(a+b)%nmod;}
void mul(ll &a,ll b){a=a*b%nmod;}
int main(){
	ios::sync_with_stdio(0),cin.tie(0);
	cin>>n>>x;
	rep(i,1,n)cin>>li[i];
	sort(li+1,li+n+1,greater<int>());
	init(1e5+5);
	ll tmp;
	dp[x]=1;
	rep(i,1,n){
		rep(j,0,x){
			tmp=dp[j],dp[j]=0;
			add(dp[j%li[i]],tmp*inv[n-i+1]);
			add(dp[j],tmp*(n-i)%nmod*inv[n-i+1]);
		}
	}
	ans=0;
	rep(i,0,x)
		add(ans,i*dp[i]);
	rep(i,1,n)mul(ans,i);
	cout<<ans<<'\n';
	return 0;
}

}

int main(){return ubospica::main();}









//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);






Measured memory_bytes: 1792
import java.io.*;
class Main{
	public static void main(String[] args){
		int a,b;
		try{
		BufferedReader br = new BufferedReader(new InputStreamReader   (System.in));
			String str = br.readLine();
			String[] strAry = str.split(" ");
			a = Integer.parseInt(strAry[0]);	
			b = Integer.parseInt(strAry[1]);
			System.out.println(a*b +" "+ 2*(a+b));
		} catch(Exception e) {
		}
	 }
}	

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

int main()
{
  int N;
  cin >> N;
  int ans =0;
  vector<int> B(N-1);
  vector<int> A(N);
  rep(i,N-1) {
    cin >> B[i];
  }

  for(int i=1;i<=N-2;i++){
    A[i]=min(B[i-1],B[i]);
  }
  A[0] = B[0];
  A[N-1] = B[N-2];

  rep(i,N){
    ans +=A[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
long long mod=1e9+7;
long long INF=1e7;
double EPS = 1e-12;
const long long lim = 2e5+100;
typedef long long int lld;
typedef long long ll;

#define rep(i,a,n) for(long long int i = (a); i <= (n); ++i)
#define mset(a, v) memset(a, v, sizeof(a))
#define Error(x...) { cout << "(" << #x << ")" << " = ( "; printIt(x); }
template <typename T1> void printIt(T1 t1) { cout << t1 << " )" << endl; }
template <typename T1, typename... T2>
void printIt(T1 t1, T2... t2) { cout << t1 << " , "; printIt(t2...); }
 
 
#define popcount __builtin_popcountll
 
ll powP(ll x, ll y) {
    ll ans = 1, po = x % mod;
    while(y > 0) {
        if(y & 1) ans = ans * po % mod;
        y >>= 1; po = po * po % mod;
    }
    return ans;
}


vector<ll> Ans, Adj[lim];
ll Array[lim], C[lim],dp[600][600];
pair<ll,ll> P[lim];

ll path(ll a,ll b) {
    if(a<0 or b<0) return 0;
    return Array[a+b]* powP(Array[a]*Array[b]%mod,mod-2)%mod;
}

int main(){

    ios::sync_with_stdio(0);
    cin.tie(0);

    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    
    lld T,i,p,j,l,e,r,b,c,k,m,q,a,d,w,x,y,u,v,z,t,curr,prev,sum=0,val,countA=0,indicator=0,pos,h,minA,maxA,type,n,ans=0,left,right;
    string A,B; a=b=0;  
    cin>>h>>w>>a>>b;
    Array[0]=1;
    rep(i,1,2e5) Array[i]=Array[i-1]*i%mod;
    ans = path(h-1,w-1);
    rep(i,1,b) {
        val = path(h-1-a,i-1) * path(a-1,w-i) %mod;
        ans  = (ans-val+mod)%mod;
    }

    cout<<ans<<endl;

    return 0;
}
    


Measured memory_bytes: 9924
if __name__ == "__main__":
    n, m = map(lambda x: int(x), input().split())

    A = [[0] for i in range(n)]
    B = [0 for i in range(m)]

    for i in range(n):
        A[i] = list(map(lambda x: int(x), input().split()))

    for i in range(m):
        B[i] = int(input())

    for row in range(n):
        sum = 0
        for col in range(m):
            sum += A[row][col] * B[col]
        print(f"{sum}")



Measured memory_bytes: 6036
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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








int main(){
    long long a, b, c, d;
    std::cin >> a >> b >> c >> d;
    long long ans(-2 * LINF);
    chmax(ans, a * c);
    chmax(ans, a * d);
    chmax(ans, b * c);
    chmax(ans, b * d);
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   int A, B, C, X, Y;
   cin >> A >> B >> C >> X >> Y;
   int ans = INF;
   for (int i = max(X, Y); i >= 0; i--) {
      int cost = C * i * 2;
      if (X - i > 0) cost += (X - i) * A;

      if (Y - i > 0) cost += (Y - i) * B;
      ans = min(ans, cost);
   }
   cout << ans << endl;
   return 0;
}

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

vector<bool> visited;

void dfs(const Graph &g, int root){
  visited[root]=true;
  for(int nv:g[root]){
    if(!visited[nv])dfs(g,nv);
  }
}

int main() {

  int n,m;
  cin>>n>>m;
  Graph g(n);
  
  rep(i,m){
    int start,goal;
    cin>>start>>goal;
    start-=1;goal-=1;

    g[start].emplace_back(goal);
    g[goal].emplace_back(start);
  }

  visited.assign(n,false);
  int ans=0;

  for(int i=0;i<n;i++){
    if(!visited[i]){
      dfs(g,i);
      ans+=1;
    }
  }

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


Measured memory_bytes: 9484
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define first fi
#define second se
#define MOD 1000000007
#define MAXN 1000006
#define endl "\n"
#define readln(x) getline(cin, x);
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
ll fpow(ll x, ll n, ll mod){if (n==0) return 1%mod; ll u = fpow(x, n/2, mod); u = (u*u)%mod; if (n%2==1)u = (u*x)%mod;return u;}
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

int A, B, m = -1;
int main(){
    //freopen("data.txt","r",stdin);
    cin >> A >> B;
    for (int i = 1; i <= 1000; i++){
        int f_1 = floor((double)i * (double)0.08);
        int f_2 = floor((double)i * (double)0.1);
        if (f_1 == A && f_2 == B){
            m = i;
            cout << i << endl;
            return 0;
        }
    }
    cout << m << endl;
    return 0;
}

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

int main() {
    ll N,M,A,B,C;
    ll ans=0;
    cin>>N>>M;
    vector<ll> Card(N);
    priority_queue<P> que;
    rep(i,N){
      cin>>A;
      que.push(make_pair(A,1));
    }
    rep(i,M){
      cin>>B>>C;
      que.push(make_pair(C,B));
    }  
    rep(i,N){
      P p=que.top();//一番大きい要素を取り出し
      que.pop();//削除
      ans+=p.first;
      if(p.second>1)//入れ替え枠を使った場合、使用回数を減らす。
      {
        p.second--;
        que.push(p);//使用回数がまだ残っているので、queに戻す。
      }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 8228
#include <stdio.h>
int main(){
  int len;
  int num;
  int prev = -1, gl = 0, ans = 0;
  scanf("%d", &len);
  for (int i = 0; i < len; ++i) {
    scanf("%d", &num);
    if (prev != num) 
    {
      ans += gl / 2;
      gl = 0;
    }
    gl++;
    prev = num;
  }  
  
  ans += gl / 2;
  
  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 128
n=int(input())
a=[0]+list(map(int,input().split()))+[0]
x=0
for i in range(n+1):
  x+=abs(a[i+1]-a[i])
for i in range(1,n+1):
  if a[i-1]>a[i]<a[i+1]:
    ans=x-2*(min(a[i-1],a[i+1])-a[i])
  elif a[i-1]<a[i]>a[i+1]:
    ans=x-2*(a[i]-max(a[i-1],a[i+1]))
  else:
    ans=x
  print(ans)

Measured memory_bytes: 14048
while True:
    H,W = map(int,input().split(' '))
    if not(H or W):break
    for h in range(1,H+1):
        for w in range(1,W+1):
            if (h + w) % 2 == 0:
                print('#',end='')
                continue
            print('.',end='')
        print()
    print()


Measured memory_bytes: 7004
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
#include <cstdio>
#include <complex>
#include <cstring>

using namespace std;

typedef long long LL;
const int N = 200000 + 5;
const int C = 26;

int n;
char s[N];
int nxt[N][C];
int dp[N];

void solve()
{
    scanf("%s", s);
    n = strlen(s);
    for(int i = 0; i < C; ++ i) {
        nxt[n][i] = n;
    }
    dp[n + 1] = 0;
    dp[n] = 1;

    for(int i = n - 1; i >= 0; -- i) {
        for(int j = 0; j < C; ++ j) nxt[i][j] = nxt[i + 1][j];
        nxt[i][s[i] - 'a'] = i;
        int d = *max_element(nxt[i], nxt[i] + C);
        dp[i] = dp[d + 1] + 1;
    }

    string ans = "";
    int ptr = 0;

    while(ptr <= n) {
        pair<int, int> best(N, -1);
        for(int j = 0; j < C; ++ j) {
            best = min(best, make_pair(dp[nxt[ptr][j] + 1], j));
        }
        ans += 'a' + best.second;
        ptr = nxt[ptr][best.second] + 1;
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 21504
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
 
#define oper(a,b) max(a,b)
#define NEUT 0
struct STree { // persistent segment tree for min over integers
	vector<int> st, L, R; int n,sz,rt;
	STree(){}
	STree(int n): st(1,NEUT),L(1,0),R(1,0),n(n),rt(0),sz(1){}
	int new_node(int v, int l=0, int r=0){
		int ks=SZ(st);
		st.pb(v);L.pb(l);R.pb(r);
		return ks;
	}
	int init(int s, int e, int *a){ // not necessary in most cases
		if(s+1==e)return new_node(a[s]);
		int m=(s+e)/2,l=init(s,m,a),r=init(m,e,a);
		return new_node(oper(st[l],st[r]),l,r);
	}
	int upd(int k, int s, int e, int p, int v){
		int ks=new_node(st[k],L[k],R[k]);
		if(s+1==e){st[ks]=v;return ks;}
		int m=(s+e)/2,ps;
		if(p<m)ps=upd(L[ks],s,m,p,v),L[ks]=ps;
		else ps=upd(R[ks],m,e,p,v),R[ks]=ps;
		st[ks]=oper(st[L[ks]],st[R[ks]]);
		return ks;
	}
	int query(int k, int s, int e, int a, int b){
		if(e<=a||b<=s)return NEUT;
		if(a<=s&&e<=b)return st[k];
		int m=(s+e)/2;
		return oper(query(L[k],s,m,a,b),query(R[k],m,e,a,b));
	}
	int init(int *a){return init(0,n,a);}
	int upd(int k, int p, int v){return rt=upd(k,0,n,p,v);}
	int upd(int p, int v){return upd(rt,p,v);} // update on last root
	int query(int k,int a, int b){return query(k,0,n,a,b);};
	int query(int a, int b){return query(rt,0,n,a,b);};
}; // usage: STree rmq(n);root=rmq.init(x);new_root=rmq.upd(root,i,v);rmq.query(root,s,e);
 
const int MAXN=2e5+10;
int rt[MAXN],ans[MAXN],a[MAXN],p[MAXN];
STree st;
vector<int> g[MAXN];
int n;

void dfs(int pos, int par){
	p[pos]=par;
	int now=st.query(rt[par],0,a[pos])+1;
	rt[pos]=st.upd(rt[par],a[pos],now);
	ans[pos]=st.query(rt[pos],0,n);
	for(auto x:g[pos]) if(x!=par) dfs(x,pos);
}

int main(){FIN;
	cin>>n;
	set<int> s;
	fore(i,0,n) cin>>a[i],s.insert(a[i]);
	fore(i,1,n){
		int x,y; cin>>x>>y; x--; y--;
		g[x].pb(y); g[y].pb(x);
	}
	int idd=0; map<int,int> mp;
	for(auto x:s) mp[x]=idd,idd++;
	fore(i,0,n) a[i]=mp[a[i]];
	st=STree(n+10);
	dfs(0,n);
	fore(i,0,n) cout<<ans[i]<<"\n";
}

/*
7
4 3 2 7 6 5 1
1 2
2 3
3 4
3 5
5 6
5 7
3 8
*/

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

using namespace std;

void solve()
{
    int n, k;
    string s;
    cin >> n >> k >> s;
    long border = -1, ans = 0, cur = 0;
    char tmp = 'U';
    for (int i = 0; i < n; i++)
    {
        if (s[i] == tmp)
        {
            cur++;
        }
        else
        {
            ans += max(cur - 1, 0L);
            tmp = s[i];
            border++;
            cur = 1;
        }
    }
    ans += max(cur - 1, 0L);
    //cout << ans << ' ' << border << endl;
    while (border && k)
    {
        if (border == 1)
        {
            ans++;
            break;
        }
        else
        {
            ans += 2;
            border -= 2;
        }
        k--;
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long
#define INF             __LONG_LONG_MAX__

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  ll n, h; cin >> n >> h;
  vector<ll> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  sort(a); sort(b);
  ll ans = 0, bi = n-1;
  while (h > 0) {
    if (bi >= 0 && b[bi] > a[n-1]) {
      h -= b[bi];
      bi--;
    } else {
      ans += ceil(h, a[n-1]);
      break;
    }

    ans++;
  }
  outl(ans);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 1792
#include <iostream>
#include <map>
using namespace std;
#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
int main(){
  int N;
  while(cin>>N){
    int wins[101] = {};
    REP(i,N*(N-1)/2){
      int A,B,C,D; cin>>A>>B>>C>>D;
      A--; B--;
      if(C < D) swap(A, B);
      if(C == D){
        wins[A] += 1;
        wins[B] += 1;
      }else{
        wins[A] += 3;
      }
    }
    map<int, int> cnt;
    map<int, int> order;
    REP(i,N)cnt[-wins[i]] ++;
    int t = 1;
    FORIT(it, cnt){
      order[-it->first] = t;
      t += it->second;
    }
    REP(i,N){
      cout<<order[wins[i]]<<endl;
    }
  }
  return 0;
}

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

const long long MOD = 1000000007;
const int INF = 1<<29;
const double EPS = 1e-8;
typedef vector<int> vec;
typedef long long ll;
typedef pair<ll, ll> P;

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

    ll s = 0;
    vector<ll> a(N);
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    list<int> ans;
    for(int i=0;i<N-1;i++){
        if (a[i] + a[i+1] >= L){
            ans.push_front(i+1);
            for(int j=i-1;j>=0;j--){
                ans.push_front(j+1);
            }
            for(int j=i+1;j<N-1;j++){
                ans.push_front(j+1);
            }
            break;
        }
    }
    if(ans.size() == 0){
        cout << "Impossible" << endl;
    }else{
        cout << "Possible" << endl;
        for(int v: ans){
            cout << v << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 4736
// Reads multiple ints in a line, separate by a space.
// It works even if the actual number of ints is smaller than n.
// WARNING: This function does not work for -2^31.
// NOTE: This function does not handle error cases.
fun fastReadInts(n: Int): IntArray {
  val xs = IntArray(n)
  val s = readLine()!!
  var currentValue = 0
  var isNegative = false
  var currentIndex = 0
  for (c in s) {
    if (c == ' ') {
      xs[currentIndex] = currentValue * if (isNegative) -1 else 1
      currentValue = 0
      isNegative = false
      currentIndex++
    } else if (c == '-') {
      isNegative = true
    } else {
      currentValue *= 10
      currentValue += c - '0'
    }
  }
  xs[currentIndex] = currentValue * if (isNegative) -1 else 1
  return xs
}

fun main(args: Array<String>) {
  val (n, c) = fastReadInts(2)
  val dMatrix = Array(c, { fastReadInts(c) })
  val cCount = Array(3, { IntArray(c) })
  for (y in 0 until n) {
    val cs = fastReadInts(n).map { it - 1 }
    for (x in 0 until n) {
      cCount[(x + y) % 3][cs[x]]++
    }
  }
  var ans = Int.MAX_VALUE
  for (c1 in 0 until c) {
    for (c2 in 0 until c) {
      if (c2 == c1) continue
      for (c3 in 0 until c) {
        if (c3 == c1 || c3 == c2) continue
        val cost1 = cCount[0].withIndex().map { it.value * dMatrix[it.index][c1] }.sum()
        val cost2 = cCount[1].withIndex().map { it.value * dMatrix[it.index][c2] }.sum()
        val cost3 = cCount[2].withIndex().map { it.value * dMatrix[it.index][c3] }.sum()
        val cost = cost1 + cost2 + cost3
        ans = Math.min(ans, cost)
      }
    }
  }
  println(ans)
}

Measured memory_bytes: 72444
c=Hash.new(0)
n=gets.to_i
s=n.times.map{gets.chars[0]}.select{ |e| 'MARCH'.chars.include?(e) }.each{ |e| c[e]+=1}
ans=c.values.combination(3).map{ |e| e.inject(:*)}.inject(:+)
puts ans.nil? ? 0: ans


Measured memory_bytes: 12284
N=int(input())
a=list(map(int, input().split()))
a=sorted(a, reverse=True)
#print(N,a)

alice=0
bob=0

for i in range(N):
  if i%2==0:
    alice += a[i]
  else:
    bob += a[i]
    
print(alice - bob)

Measured memory_bytes: 3060
object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    val Array(tHP, tATK, aHP, aATK) = readLine.split(" ").map(_.toInt)

    val tTurn = (aHP / tATK) + (if (aHP % tATK != 0) 1 else 0)
    val aTurn = (tHP / aATK) + (if (tHP % aATK != 0) 1 else 0)

    val ans = (tTurn <= aTurn)
    println(if(ans) "Yes" else "No")
  }
}


Measured memory_bytes: 54836
#include <iostream>
#include <algorithm>

using namespace std;

int main(void){
  int n, a[100000] = {0}, x, sum;
  int i;
  cin >> n;
  for(i = 0; i < n; i++){
    cin >> x;
    a[x - 1]++;
  }
  sort(a, a + 100000, greater<int>());
  for(i = 0; i < n;){
    if(a[i] > 2){
      a[i] = a[i] - 2;
    }else if(a[i] > 1 && a[i + 1] != 0){
      a[i] = a[i] - 1;
      a[i + 1] = a[i + 1] - 1;
    }else {
      i++;
    }
  }
  for(i = 0; i < n; i++){
    if(a[i] == 1){
      sum++;
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
char arr[105][105];
int main(){
    cin.tie(NULL); cout.tie(NULL);
    ios_base:: sync_with_stdio(false);
    ll a,b;cin>>a>>b;
    for(ll i=0;i<50;i++)for(ll j=0;j<100;j++)arr[i][j]='.';
    for(ll i=50;i<100;i++)for(ll j=0;j<100;j++)arr[i][j]='#';
    a--;b--;
    for(ll i=0;i<49;i+=2){
        for(ll j=0;j<100;j++){
            if(!b)break;
            if( j%2==0)arr[i][j]='#',b--;
        }
    }
    for(ll i=51;i<100;i+=2){
        for(ll j=0;j<100;j++){
            if(!a)break;
            if( j%2==0)arr[i][j]='.',a--;
        }
    }

    cout<<"100 100\n";
    for(ll i=0;i<100;i++){
        for(ll j=0;j<100;j++)cout<<arr[i][j];
        cout<<"\n";
    }
}

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

int main() {
  int X, a, b, c, d;
  cin >> X;
  
  a = X / 1000;
  b = (X - 1000 * a) / 100;
  c = (X - 1000 * a - 100 * b) / 10;
  d = X - 1000 * a - 100 * b - 10 * c;
  
  if(a == b & b == c){
    cout << "Yes" << endl;
  }
  else if(b == c & c == d){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

#define ll long long
#define INF 100000000000
int n;
ll we,k;

ll dp[102][100003],w[100003],v[100003];

ll solve(int i,ll j){
    if(i<0){
        return 0;
    }
    if(dp[i][j]!=-1) return dp[i][j];
    if(j-w[i]<0) return dp[i][j]=max(dp[i][j],solve(i-1,j));
    return dp[i][j]=max(solve(i-1,j-w[i])+v[i],solve(i-1,j));
}

int main(){
    int t=1,tn=1;
//    scanf("%d",&t);
    while(t--){
        scanf("%d%lld",&n,&we);
        for(int i=0;i<n;i++)
            for(int j=0;j <=we;j++)
                dp[i][j]=-1;
        for(int i=0;i<n;i++)
            scanf("%lld %lld",&w[i],&v[i]);
        printf("%lld",solve(n-1,we));

    }
    return 0;
}


Measured memory_bytes: 78592
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;
#define endl '\n'
#define eb emplace_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

// value
ull N, K;
vector<ull> A;
int bit[64];

void solve() {

	cin >> N >> K;
	A.resize(N);

	for (int i = 0; i < N; i++) {
		cin >> A[i];
		for (int j = 0; j < 64; j++) {
			if ((A[i] >> j) & 1ULL) bit[j]++;
		}
	}

	ull X = K;

	for (int i = 64 - 1; i >= 0; i--) {
		if (N - bit[i] <= bit[i]) X &= ~(1ULL << i);
		else {
			ull tmp = X;
			X |= (1ULL << i);
			if (X > K) X = tmp;
		}
	}

	ull ans = 0ULL;

	for (int i = 0; i < N; i++) {
		ans += X ^ A[i];
	}

	cout << ans << endl;

	return;

}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;

}


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


int main(){
  int N;
  cin >> N;
  
  vector<pair<int,int>>D(N);
  
  rep(i,N){
    cin >> D[i].first >> D[i].second;
  }
  
  int count = 0;
  
  rep(i,N){
    
    if(count >= 1){
      if(D[i].first == D[i].second){
        count++;
        if(count == 3){
          cout << "Yes" << endl;
          return 0;
        }
        continue;
      }
      else count = 0;
    }
    
    
    if(D[i].first == D[i].second){
      count++;
    }
    
  }
  cout << "No" << endl;
  return 0;
}

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

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	char a,b;
	cin>>a>>b;
	if(a=='H') cout<<b<<'\n';
	else cout<<(b=='H'?'D':'H')<<'\n';
}




Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void chey(){ cout <<"hey" <<endl; }


int main() {
  ll N,K; cin >>N >>K;
  N %= K;
  N = min(N, abs(N-K));
  cout <<N <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MD=1e9+7;
const int N=1e5+5;
int a[N],n,f[N];
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	f[0]=3;
	int ans=1;
	for(int i=1;i<=n;i++) {
		ans=1LL*ans*f[a[i]]%MD;
		f[a[i]]--;
		f[a[i]+1]++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1152
from itertools import accumulate
def solve(string):
    n, k, *v = map(int, string.split())
    r = min(n, k)
    """
    for i in range(k + 1):
        for j in range(k - i + 1):
            base = sorted(v[:i] + v[max(n - k + i + j, i):])
            ans = max(ans, sum([b for l, b in enumerate(base) if b >= 0 or j <= l]))
    """

    def s(w):
        l = [0] * (k + 1)
        for i in range(1, k + 1):
            _w = sorted(w[:i], reverse=True)
            tmp = sum(_w)
            l[i] = max(l[i], tmp)
            j = 0
            while i + j < k and _w and _w[-1] < 0:
                j += 1
                tmp -= _w.pop()
                l[i + j] = max(l[i + j], tmp)
        return accumulate(l, func=max)

    *lefts, = s(v)
    *rights, = s(v[::-1])
    ans = max([lefts[i] + rights[k - i] for i in range(k + 1)])
    ans = min(ans, sum([_v for _v in v if _v > 0]))
    return str(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))


Measured memory_bytes: 3064
N, M = list(map(int, input().split()))

intersection = None

for _ in range(N):
  nth_list = list(map(int, input().split()))
  nth_list = nth_list[1:]
  nth_set = set(nth_list)
  if intersection is None:
    intersection = nth_set
  else:
    intersection &= nth_set
print(len(intersection))

Measured memory_bytes: 3064