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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
vector< T > dijkstra(WeightedGraph< T > &g, int s) {//kaizou shimasita
  const auto INF = numeric_limits< T >::max();
  vector< T > dist(g.size(), INF);
  vector< T > from(g.size(), INF);  

  using Pi = pair< T, int >;
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  dist[s] = 0;
  que.emplace(dist[s], s);
  while(!que.empty()) {
    T cost;
    int idx;
    tie(cost, idx) = que.top();
    que.pop();
    if(dist[idx] < cost) continue;
    for(auto &e : g[idx]) {
      auto next_cost = cost + e.cost;
      if(dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      que.emplace(dist[e.to], e.to);
      
      from[e.to]=e.src;
    }
  }
  return from;
  //return dist;
}

int main()
{
    int n,m;
    cin>>n>>m;
    WeightedGraph< int > g(n);
    vector<int> a(m),b(m);
    for (int i = 0; i < m; i++)
    {
        cin>>a[i]>>b[i];
        a[i]--;
        b[i]--;
    }
    for (int i = 0; i < m; i++)
    {
        g[a[i]].emplace_back(a[i],b[i],1);
        g[b[i]].emplace_back(b[i],a[i],1);
    }
    vector<int> di = dijkstra(g,0);
    
    cout<<"Yes"<<endl;
    for (int i = 1; i < n; i++)
    {
        cout<<di[i]+1<<endl;
    }
    
    
    
    return 0;
}

Measured memory_bytes: 16956
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    stack<char> st;
    string s;
    cin >> s;

    rep(i, s.size()) {
        if (s[i] == 'B') {
            if (st.size() != 0) {
                st.pop();
            }
        }
        else {
            st.push(s[i]);
        }
    }
    string ans = "";
    while (st.size() != 0) {
        ans += st.top();
        st.pop();
    }

    reverse(all(ans));
    cout << ans << endl;
    return 0;
}

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

int main(){
  int K=-1,S=-1,count = 0;
  cin >> K >> S;
  if( K < 0 || S < 0) cout << "error" << endl;
  
  for(int i = 0;i < K + 1;++i){
  	for(int j = 0;j < K + 1;++j){
    	if(S - i - j <= K && S - i -j >= 0) count++ ;
    }
  }
  cout <<  count << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n1,n2,a[100001],b[100001],m;
int main()
{
	scanf("%d%d%d",&n1,&n2,&m);int mna=0x3f3f3f3f,mnb=0x3f3f3f3f,ans=0x3f3f3f3f;
	for(int i=1;i<=n1;++i)scanf("%d",&a[i]),mna=min(mna,a[i]);for(int i=1;i<=n2;++i)scanf("%d",&b[i]),mnb=min(mnb,b[i]);ans=mna+mnb;
	for(int i=1;i<=m;++i)
	{
		int c,x,y;scanf("%d%d%d",&x,&y,&c);
		ans=min(ans,a[x]+b[y]-c);
	}
	printf("%d\n",ans);return 0;
}

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

long long p = 1000000007;
long long mod_fact[200000];

void mod_fact_init(){
    mod_fact[0]=mod_fact[1]=1;
    for(int i=2;i<200000;i++){
        mod_fact[i]=(mod_fact[i-1]*i)%p;
    }
}


long long mod_pow(long long a,long long b){
  
    a%=p;
    if(b<=0){
        return 1;
    }else if(b%2==0){
        return mod_pow(a*a,b/2)%p;
    }else{
        return (a*mod_pow(a,b-1))%p;
    }
}

long long mod_comb(long long a,long long b){
    if(a<=0||b<=0)return 1;
    long long c = (mod_fact[a]*mod_pow(mod_fact[a-b],p-2))%p;
    return (c*mod_pow(mod_fact[b],p-2))%p;
}

int main() {
int l,a[100000],b[100000],c[100000],q[100000];
long long w=0;
string s;
cin>>s;
l=s.length();

mod_fact_init();

a[0]=b[0]=c[0]=q[0]=0;
switch(s[0]){
        case 'A':a[0]++;break;
        case 'B':b[0]++;break;
        case 'C':c[0]++;break;
        case '?':q[0]++;break;
}


for(int i=1;i<l;i++){
    a[i]=a[i-1];
    b[i]=b[i-1];
    c[i]=c[i-1];
    q[i]=q[i-1];
    switch(s[i]){
        case 'A':a[i]++;break;
        case 'B':b[i]++;break;
        case 'C':c[i]++;break;
        case '?':q[i]++;break;
    }
  
}

for(int i=0;i<l;i++){
  
    if(s[i]=='A'){
        long long r=q[l-1]-q[i];
        long long d=((r*(r-1))/2)%p;
        w=(w+(d*mod_pow(3,q[l-1]-2))%p)%p;
    }else if(s[i]=='B'){
        long long r=(a[i]*(c[l-1]-c[i]))%p,d=(q[i]*(q[l-1]-q[i]))%p;
        w=(w+(r*mod_pow(3,q[l-1]))%p)%p;
        w=(w+(d*mod_pow(3,q[l-1]-2))%p)%p;
        w=(w+(((a[i]*(q[l-1]-q[i]))%p)*mod_pow(3,q[l-1]-1))%p)%p;
        w=(w+(((q[i]*(c[l-1]-c[i]))%p)*mod_pow(3,q[l-1]-1))%p)%p;
    }else if(s[i]=='C'){
        long long r=q[i];
        long long d=((r*(r-1))/2)%p;
        w=(w+(d*mod_pow(3,q[l-1]-2))%p)%p;
    }else{
        w=(w+(((a[i]*(c[l-1]-c[i]))%p)*mod_pow(3,q[l-1]-1))%p)%p;
    }
    //cout<<w<<endl;
}
long long r=q[l-1];
  if(r>2){
w=(w+(((r*(r-1)*(r-2))/6)%p)*mod_pow(3,r-3))%p;
  }
cout<<w<<endl;
	return 0;
}

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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

const char lf = '\n';

namespace ae86
{
	const int bufl = 1 << 15;

	char buf[bufl],*s=buf,*t=buf;

	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}

	inline int ty()
	{
		int a=0;int b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 200007 , mo = 998244353;

template<typename T1,typename T2> inline T1 ad(T1 &a,T2 b){return a=a+b>=mo?a+b-mo:a+b;}
template<typename T1,typename T2> inline T1 dl(T1 &a,T2 b){return a=a>=b?a-b:a-b+mo;}
template<typename T1,typename T2> inline T1 add(T1 a,T2 b){return a+b>=mo?a+b-mo:a+b;}
template<typename T1,typename T2> inline T1 del(T1 a,T2 b){return a>=b?a-b:a-b+mo;}

lint powa(lint a,lint t)
{
	lint b=1;a=(a+mo)%mo;
	while(t){if(t&1)b=b*a%mo;a=a*a%mo,t>>=1;}
	return b;
}

inline lint inva(lint a)
{
	return powa(a,mo-2);
}

vector<int> e[_];

int n,fa[_]={0},rt=0,mxdep=0;

void dfs(int x,int ff,int dep)
{
	fa[x]=ff;
	if(dep>mxdep)mxdep=dep,rt=x;
	for(auto b:e[x])if(b!=ff)dfs(b,x,dep+1);
}

int ps[_]={0},lps=0;
lint f[_][3][3]={0};

void dfs2(int x,int ff,int dep)
{
	fa[x]=ff;
	memset(f[x],0,sizeof(f[x]));
	if(dep==lps/2)f[x][1][1]=1;
	else f[x][0][0]=1;

	for(auto b:e[x])
	{
		if(b==ff)continue;
		dfs2(b,x,dep+1);
		lint sf[3][3];memset(sf,0,sizeof(sf));
		for(int i=0;i<3;i++)
			for(int j=0;j<3;j++)
				for(int p=0;p<3;p++)
					for(int q=0;q<3;q++)
						for(int r=-1;r<=1;r++)
						{
							int pp=r==1?p:0,qq=r==-1?q:0;
							pp=min(2,pp+i),qq=min(2,qq+j);
							ad(sf[pp][qq],f[x][i][j]*f[b][p][q]%mo);
						}
		memcpy(f[x],sf,sizeof(sf));
	}
}

int main()
{
	ios::sync_with_stdio(0),cout.tie(nullptr);

	n=ty();
	for(int i=1,a,b;i<n;i++)a=ty(),b=ty(),e[a].emplace_back(b),e[b].emplace_back(a);

	dfs(1,0,1),mxdep=0,dfs(rt,0,1);
	for(int i=rt;i;i=fa[i])ps[++lps]=i;

	if(lps&1)
	{
		int mid=ps[lps/2+1];
		dfs2(mid,0,0);
		cout<<f[mid][1][1]*inva(2)%mo<<lf;
		return 0;
	}
	
	int ll=ps[lps/2],rr=ps[lps/2+1];
	dfs2(ll,rr,1),dfs2(rr,ll,1);
	cout<<add(add(f[ll][1][0],f[ll][1][1]),f[ll][1][2])
		*add(add(f[rr][0][1],f[rr][1][1]),f[rr][2][1])%mo<<lf;

	return 0;
}


Measured memory_bytes: 37120
#include <bits/stdc++.h>
using namespace std;
int main(){
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int x3, y3, x4, y4;
    int a = x2-x1, b=y2-y1;
    x3 = x2 - b, y3 = y2 + a;
    x4 = x3 -a, y4=y3-b;
    printf("%d %d %d %d\n", x3, y3, x4, y4);
    return 0;
}

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#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;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl

int main(){
    int n,m;
    cin >> n;
    map<int,int> d;
    REP(i,n){
        int p;
        cin >> p;
        d[p]++;
    }
    cin >> m;
    bool flag = true;
    REP(i,m){
        int p;
        cin >> p;
        d[p]--;
        if(d[p]<0){
            flag = false;
            break;
        }
    }
    
    if(flag) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
} 

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
int a[1000];
int main()
{
    int l,k,i,j,n,m,d,x=0,ans=0;
    cin >> n >> k;
    for(i=1; i<=k; i++)
    {
        cin >> d;
        while(d--)
        {
            cin >> x;
            a[x]++;
        }
    }
    for(i=1; i<=n; i++)
    {
        if(a[i]==0)
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3616
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main(void){
    int n;

    cin >> n;

    if(n > 999){
        cout << "ABD" << endl;
        return 0;
    } 
    else{
        cout << "ABC" << endl;
        return 0;
    }
       
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public int minJumps(int[] heights) {
        int n = heights.length;
        int[] dp = new int[n];
        for (int i = 1; i < n; i++) {
            int oneJump = Math.abs(heights[i] - heights[i - 1]) + dp[i - 1];
            int twoJumps = 1_000_000_000;
            if (i > 1) {
                twoJumps = Math.abs(heights[i] - heights[i - 2]) + dp[i - 2];
            }
            dp[i] = Math.min(oneJump, twoJumps);
        }
        return dp[n - 1];
    }
	

    public static void main(String[] args)  {
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            int n = Integer.parseInt(br.readLine());
            String heightsStr = br.readLine();
            String[] split = heightsStr.split(" ");
          	int[] heights = new int[n];
            for (int i = 0; i < n; i++) {
              	heights[i] = Integer.parseInt(split[i]);
            }
          	Main app = new Main();
            int result = app.minJumps(heights);
            System.out.println(result);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 33496
n = int(input())

ans = 0

bou = list(map(int,input().split()))
bou.sort(reverse=True)
l_bou = len(bou)

for i in range(l_bou):
    for j in range(i+1, l_bou):
        for k in range(j+1, l_bou):
            if ((bou[i] != bou[j]) and (bou[j] != bou[k]) and (bou[i] != bou[k])): 
                if (bou[i] < bou[j] + bou[k]):
                    ans += 1

print(ans)


Measured memory_bytes: 9164
#include<bits/stdc++.h>
using namespace std;
#define INFTY 1<<20
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long int ll;
const int MOD=1000000007;
int main(){
    int a,b;
    cin>>a>>b;
    cout<<a*b<<endl;
    return 0;   
}

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

int main() {
	vector<vector<int>> a(3, vector<int>(3));
	vector<vector<int>> d(3, vector<int>(3));
	rep(i, 3) {
		rep(j, 3) {
			cin >> a[i][j];
		}
	}
	int n;
	cin >> n;
	rep(i, n) {
		int x;
		cin >> x;
		rep(i, 3) rep(j, 3) if (a[i][j] == x) d[i][j] = 1;
	}

	int ans = false;
	rep(i, 3) {
		int count = 0;
		rep(j, 3) count += d[i][j];
		if (count == 3) ans = true;
	}
	rep(i, 3) {
		int cnt = 0;
		rep(j, 3) cnt += d[j][i];
		if (cnt == 3) ans = true;
	}
	{
		int cnt = 0;
		rep(j, 3) cnt += d[j][j];
		if (cnt == 3) ans = true;
	}
	{
		int cnt = 0;
		rep(j, 3)cnt += d[j][2 - j];
		if (cnt == 3)ans = true;
	}
	if (ans) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
		return 0;
}


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

struct disk{
    int x,y,r,c;
    disk(int x, int y, int r, int c):x(x),y(y),r(r),c(c){}
    disk(){}
};
bool bittrue(int n, int i){
    return (n&(1<<i)) != 0;
}

int main(){
    while(1){
        int n;
        cin >> n;
        if(n==0) break;

        vector<disk> d(n);
        vector<vector<int> > ovl(n);
        for(int i=0; i<n; i++){
            int x,y,r,c;
            cin >> x >> y >> r >> c;
            d[i] = disk(x,y,r,c);
            for(int j=0; j<i; j++){
                if((x-d[j].x)*(x-d[j].x)+(y-d[j].y)*(y-d[j].y) < (r+d[j].r)*(r+d[j].r)){
                    ovl[i].push_back(j);
                }
            }
        }

        char ans = 0;
        vector<char> dp(1<<n, -1);
        dp[0] = 0;
        for(int b=0; b<(1<<n); b++){
            if(dp[b]==-1) continue;
            for(int i=0; i<n; i++){
                if(bittrue(b,i)) continue;
                bool flag=true;
                for(int k=0; k<(int)ovl[i].size(); k++){
                    if(!bittrue(b,ovl[i][k])){
                        flag = false;
                        break;
                    }
                }
                if(!flag) continue;
                
                for(int j=i+1; j<n; j++){
                    if(bittrue(b,j) || d[i].c != d[j].c) continue;
                    bool flag = true;
                    for(int k=0; k<(int)ovl[j].size(); k++){
                        if(!bittrue(b, ovl[j][k])){
                            flag=false;
                            break;
                        }
                    }
                    if(flag){
                        int next = b|(1<<i)|(1<<j);
                        dp[next] = max((int)dp[next], dp[b]+2);
                        ans = max(ans, dp[next]);
                    }
                }
            }
        }

        cout << (int)ans << endl;
    }
    return 0;
}

Measured memory_bytes: 19484
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
     Scanner ap = new Scanner(System.in);
     //整数入力
     int A = ap.nextInt();
     int P = ap.nextInt();
     
     int pie = (A*3 + P) / 2;
      
      System.out.println(pie);
      
    }
}

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

#define mem(arr,x) memset(arr,x,sizeof(arr))
#define pb push_back
#define ll long long
#define mp make_pair
#define rep(i,n)  for(ll i=0;i<n;i++)
#define repi(i,n)  for(ll i=1;i<=n;i++)
#define all(x)   (x.begin(),x.end())

const double PI = 3.1415926535897932;
const int mod = 1e9 + 7;  
int max(int a,int b)
{
	if(a>b)
	return a;
	return b;
}


int main()
{
	
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
int a[n];
rep(i,n)
cin>>a[i];
sort(a,a+n);
ll 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++)
		{
			if(a[i]+a[j]>a[k] && a[i]!=a[j] && a[j]!=a[k] && a[i]!=a[k])
			ans++;
		}
	}
}
cout<<ans<<'\n';
		





}
  

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG
#define fi first
#define se second

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=acos(-1);
const ll MOD=1e9+7;
const ll INF=(1LL<<60);


struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

struct edge{
    int u,v;
    ll cost;
};
bool comp(const edge& e1,const edge& e2){
    return e1.cost<e2.cost;
}

int V,E;
edge es[200010];
vvll a(300,vll(300,0));

//Vは頂点数
//Eは辺の数
//esはedgeを管理する配列

ll kruskal(){
    sort(es,es+E,comp);
    UnionFind uf(V+1);
    ll res=0;
    for (int i=0;i<E;i++){
        edge e1=es[i];
        if (!uf.issame(e1.u,e1.v)){
            uf.merge(e1.u,e1.v);
            res+=e1.cost;
            //cout<<e1.cost<<endl;
        }
        else{
            int b1=1;
            rep(j,V){
                if (j==e1.u || j==e1.v)continue;
                if (a[e1.u][j]+a[j][e1.v]==a[e1.u][e1.v])b1=0;
            }
            if (b1)res+=e1.cost;
        }

    }
    return res;
}

int main() {
    int n;
    cin>>n;
    V=n;
    E=n*(n-1)/2;
    rep(i,n)rep(j,n)cin>>a[i][j];
    vvll a1=a;
    rep(k,n)rep(i,n)rep(j,n)a1[i][j]=min(a1[i][j],a1[i][k]+a1[k][j]);
    rep(i,n){
        rep(j,n){
            if (a[i][j]!=a1[i][j]){
                cout<<-1<<endl;
                return 0;
            }
        }
    }
    int c=0;
    for (int i=0;i<n-1;i++){
        for (int j=i+1;j<n;j++){
            edge e1={i,j,a[i][j]};
            es[c]=e1;
            c+=1;
        }
    }
    ll ans=kruskal();
    cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 2432
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstdlib>
#include<algorithm>
#include<map>
using namespace std;
#define N 100010
int has[N];
int long long n;
int main(){
    int n,q,a,b,c;
    long long sum;
    while (scanf("%d",&n)!=EOF) {
        sum = 0;
        for(int i=0;i<=100000;i++)
            has[i] = 0;
        for (int i=0;i<n;i++) {
            scanf("%d",&a);
            has[a]++;
            sum+=a;
        }
        scanf("%d",&q);
        while (q--) {
            scanf("%d %d",&b,&c);
            sum-=b*has[b];
            sum+=c*has[b];
            has[c]+=has[b];
            has[b] = 0;
            printf("%lld\n",sum);
        }
    }

    return 0;
}


Measured memory_bytes: 3572
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner scn = new Scanner(System.in)) {
			final long A = scn.nextLong();
			final long B = scn.nextLong();
			final long K = scn.nextLong();

			System.out.printf("%d %d%n", Math.max(A - K, 0), Math.max(0, Math.min(B, B - (K - A))));
		}
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    ll X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<ll> P(A), Q(B), R(C);
    rep(i, A) cin >> P[i];
    rep(i, B) cin >> Q[i];
    rep(i, C) cin >> R[i];
    sort(all(P), greater<ll>());
    sort(all(Q), greater<ll>());
    vector<ll> S;
    rep(i, X) S.pb(P[i]);
    rep(i, Y) S.pb(Q[i]);
    rep(i, C) S.pb(R[i]);
    sort(all(S), greater<ll>());
    ll ans = 0;
    rep(i, X + Y) ans += S[i];
    output(ans);
    
    return 0;
}


Measured memory_bytes: 8944
import math
k=int(input())
s=[]
ans=0
for a in range(1,k):
  for b in range(a+1,k+1):
    s.append(math.gcd(a,b))
for c in range(1,k+1):
  for i in range(len(s)):
    ans+=math.gcd(s[i],c)*2
  for j in range(1,k+1):
    ans+=math.gcd(c,j)
print(ans)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
const int INF = 1000000007;

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;

int main(){
    string S;
    cin >> S;
    reverse(all(S));
    vector<string> T = {"dream", "dreamer", "erase", "eraser"};
    rep(i, 4){
        reverse(all(T[i]));
    }

    int c = 0;
    bool ans = true;

    while(c < S.size()){
        bool flag = false;
        rep(i, 4){
            if(S.substr(c, T[i].size()) == T[i]){
                flag = true;
                c += T[i].size();
                break;
            }
        }
        if(flag) continue;
        else{
            ans = false;
            break;
        }
    }

    if(ans) cout << "YES" << endl;
    else cout << "NO" << endl;

}

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

int main() {
  int s = 10;
  int t = 0;
  for (int i = 0; i < 5; i++) {
    int x;
    cin >> x;
    if (x%10!=0) s = min(s,x%10);
    t += ((x-1)/10+1)*10;
  }
  cout << t-10+s << endl;
}

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

#include <boost/rational.hpp>

using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

const int INF = 1 << 30;

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

  int N, ma, mb;
  cin >> N >> ma >> mb;

  int mincost = INF;
  vector<tuple<int, int>> x_minus, x_plus;
  REP(i, N) {
    int a, b, c;
    cin >> a >> b >> c;
    int x = a * mb - ma * b;
    if (x == 0) {
      if (mincost > c) {
        mincost = c;
        // cerr << "x = 0, cost = " << c << endl;
      }
    } else if (x < 0) {
      x_minus.emplace_back(c, -x);
    } else {
      x_plus.emplace_back(c, x);
    }
  }

  // dp_*[i] := mincost of total weight i.
  const int XMAX = 1000;
  vector<int> dp_plus(XMAX + 1, INF), dp_minus(XMAX + 1, INF);
  dp_plus[0] = dp_minus[0] = 0;
  REP(i, x_plus.size()) {
    int ci = get<0>(x_plus[i]);
    int xi = get<1>(x_plus[i]);
    for (int w = XMAX - xi; w >= 0; --w) {
      dp_plus[w + xi] = min(dp_plus[w + xi], dp_plus[w] + ci);
    }
  }
  REP(i, x_minus.size()) {
    int ci = get<0>(x_minus[i]);
    int xi = get<1>(x_minus[i]);
    for (int w = XMAX - xi; w >= 0; --w) {
      dp_minus[w + xi] = min(dp_minus[w + xi], dp_minus[w] + ci);
    }
  }
  REP(w, XMAX) {
    int wp = dp_plus[w + 1], wm = dp_minus[w + 1];
    if (wp != INF && wm != INF && mincost > wp + wm) {
      //   cerr << "Found: weight = " << (wp + wm) << " (" << wp << " + " << wm
      //        << ")\n";
      mincost = wp + wm;
    }
  }
  cout << (mincost == INF ? -1 : mincost) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define int ll
#define pb push_back
#define sz(i) (int)(i.size())
#define fi first
#define se second
#define ld long double
#define pii pair<int, int>
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = 1e9 + 7;
using namespace std;
#ifndef ONLINE_JUDGE
#define tr(...) {__l(__LINE__);__f(#__VA_ARGS__, __VA_ARGS__);}
inline void __l(int line) { cerr << "#" << line << ": "; }template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << std::endl;}template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define tr(...)
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}template<typename T>inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v){bool first = true;os << "[";for(auto i: v){if(!first)os << ", ";os << i;first = false;}return os << "]";}
const int N = 5*1e5 + 10;

int dp[N], n, h[N], k;

int solve(int idx){
   if(idx == n-1){
      return 0;
   }
   if(idx > n){
      return inf;
   }
   int &ans = dp[idx];
   if(ans != -1)
      return ans;
   ans = inf;
   for (int i = idx+1; i <= min(n-1, idx+k) ; ++i)
   {
      smin(ans, solve(i)+abs(h[idx]-h[i]));
   }
   return ans;
}

int32_t main(){_

   cin>>n>>k;

   for (int i = 0; i < n; ++i)
   {
      cin>>h[i];
   }


   memset(dp, -1, sizeof dp);
   cout<<solve(0);

   return 0;
}

Measured memory_bytes: 12032
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
const double eps = 1e-8;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T> ostream& operator << (ostream& os, const set<T>& s) { for (auto si : s) os << si << " "; return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { (a += (b % mod + mod)) %= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12);
    int T;
    T = 1;
    while (T--) solve();
}

void solve() {
    int x, y;
    cin >> x >> y;
    vector<int> v(3);
    cin >> v;
    vector<vector<int> > vv(3);
    rep(i, 3) {
        rep(j, v[i]) {
            int a;
            cin >> a;
            vv[i].eb(a);
        }
    }
    rep(i, 3) sort(all(vv[i]), greater<>());
    
    priority_queue<int> q;
    rep(i, x) q.emplace(vv[0][i]);
    rep(i, y) q.emplace(vv[1][i]);
    rep(i, v[2]) q.emplace(vv[2][i]);
    
    ll ans = 0;
    rep(i, x + y) {
        ans += q.top();
        // cerr << q.top() << endl;
        q.pop();
    }
    cout << ans << endl;
}


Measured memory_bytes: 6508
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define rFORe(i, a, n) for(int (i) = (int)(n); (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 1, (n))
#define REPo(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rREPe(i, n) rFORe((i), 1, (n))
#define rREPo(i, n) rFORe((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define dup(x, y) (((x)+(y)-1)/(y))
#define vc(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using vp = vector<P>;
using vt = vector<T>;

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; }

int main() {
  int n, k;
  cin >> n >> k;
  set<int> s;
  REP(i, k) {
    int d;
    cin >> d;
    REP(j, d) {
      int a;
      cin >> a;
      s.insert(a);
    }
  }
  cout << n-s.size() << endl;

  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <time.h>
#include <unordered_map>

using namespace std;

#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define PI 3.1415926535897932384626

int main()
{
  int a, b, h, m;
  cin >> a >> b >> h >> m;

  double d_a = 2 * PI * (h + m / 60.0) / 12;
  double d_b = 2 * PI * m / 60;

  double x = sqrt(a * a + b * b - 2 * a * b * cos(d_a - d_b));
  cout << fixed << setprecision(20);
  cout << x << endl;
}


Measured memory_bytes: 4192
n=int(input())
p=list(map(int,input().split()))
flag=0
for i in range(1,n-1):
 if p[i] > p[i-1] and p[i] < p[i+1] or p[i] < p[i-1] and p[i] > p[i+1]:
  flag+=1
print(flag)


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,c,ct=0,dd,d,i,j,k;
    cin>>a>>b>>c;
    vector<long long >dc;
    vector<long long >vc;
    for(i=0; i<b; i++)
    {
        cin>>k;
        vc.push_back(k);
    }
 

    for(i=0; i<a; i++)
    {
        dd=0;
        for(j=0; j<b; j++)
        {
            cin>>d;
            dd=dd+d*vc[j];

        }

        if(dd+c>0)
            ct++;
    }
    cout<<ct<<endl;


}


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;

int main(){

    int A,B,C;
    cin >> A >> B >> C;
    cout << C << " " << A << " " <<  B << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

const int N = 200010;

int n;
bool vis[N], par[N];
vector<int> ver[2];
int cnt[3], pc[2], mat[3];
int ans[N];

vector<int> g[N];

void dfs(int u) {
  ++pc[par[u]];
  ver[par[u]].push_back(u);
  vis[u] = true;
  for (int v : g[u])
    if (!vis[v]) {
      par[v] = !par[u];
      dfs(v);
    }
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  cin >> n;
  for (int rep = 1; rep < n; ++rep) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1);
  for (int i = 1; i <= n; ++i) ++cnt[i % 3];
  int mi = pc[0] < pc[1] ? 0 : 1, mj = cnt[1] < cnt[2] ? 1 : 2;
  if (pc[mi] < cnt[mj]) {
    mat[1] = mat[2] = !mi;
  } else {
    mat[mj] = mi;
    mat[3 - mj] = !mi;
  }
  for (int i = 1; i <= n; ++i) if (i % 3) {
    ans[ver[mat[i % 3]].back()] = i;
    ver[mat[i % 3]].pop_back();
  }
  for (int i = 1; i <= n; ++i) if (i % 3 == 0) {
    if (ver[0].empty()) swap(ver[0], ver[1]);
    ans[ver[0].back()] = i;
    ver[0].pop_back();
  }
  for (int i = 1; i <= n; ++i) cout << ans[i] << ' ';

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 19572
def main():
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())
    B, C = [0]*Q, [0]*Q
    for i in range(Q):
        B[i], C[i] = map(int, input().split())

    ans = sum(A)
    d = dict()
    for i, a in enumerate(A):
        d[a] = d.get(a, 0) + 1

    for b, c in zip(B, C):
        if b not in d:
            print(ans)
            continue
        ans += d[b] * (c-b)
        if c not in d:
            d[c] = 0
        d[c] = d[c] + d[b]
        d[b] = 0
        print(ans)

main()

Measured memory_bytes: 87348
#include<stdio.h>

typedef struct{
  char mark;
  int value;
} Card;

int main(){
  Card a[36],b[36],t;
  int i,j,N,mini,c=0;
  scanf("%d",&N);
  for(i=0;i<N;i++)scanf(" %c%d",&a[i].mark,&a[i].value);
  for(i=0;i<N;i++)b[i]=a[i];
  // for(i=0;i<N;i++) printf("%c%d ",a[i].mark,a[i].value);
  // printf("\n");
  //buble
 
  for(i=0;i<N;i++){
    for(j=N-1;j>i;j--){
      if(a[j].value<a[j-1].value){
         t=a[j];
	 a[j]=a[j-1];
	 a[j-1]=t;       
      }
    }
  }
  for(i=0;i<N-1;i++) printf("%c%d ",a[i].mark,a[i].value);
  printf("%c%d\n",a[N-1].mark,a[N-1].value);
  printf("Stable\n");
  //serection
   for(i=0;i<N-1;i++){
    mini=i;
    for(j=i;j<N;j++){
      if(b[j].value<b[mini].value)mini=j;
    }
    t=b[i];
    b[i]=b[mini];
    b[mini]=t;
  }
  
   for(i=0;i<N-1;i++) printf("%c%d ",b[i].mark,b[i].value);
   printf("%c%d\n",b[N-1].mark,b[N-1].value);
    //stable?
   for(i=0;i<N;i++){
     if(a[i].mark!=b[i].mark){
       printf("Not stable\n");
       return 0;
     }
   }
   printf("Stable\n");
   
   return 0;
}



Measured memory_bytes: 2104
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        BigDecimal A = new BigDecimal(sc.next());
        BigDecimal B = new BigDecimal(sc.next());
        System.out.println((A.multiply(B).toString().split("\\."))[0]);
    }
}

Measured memory_bytes: 35956
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
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; }

int main(){
	string s;cin>>s;
	ll k;cin>>k;
	for(int i = 0; i < s.size(); i++) {
		if(s[i] != 'a' && k >= 'z' - s[i] + 1){
			k -= 'z' - s[i] + 1;
			s[i] = 'a';
		}
	}
	if (k > 0){
		k %= 26;
		s[s.size() - 1] = 'a' + ((s[s.size() - 1] - 'a' + k) % 26);
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 3760
import java.io.BufferedReader; 
import java.io.*;
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer; 
import java.util.*;
import java.math.*;
public class Main 
{ 
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader()
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next()
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine();
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
   public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        PrintWriter pw=new PrintWriter(System.out);
        int t = 1;//sc.nextInt();
        while(t-- > 0)
        {
            int l = sc.nextInt(),a=0;
            for(int i=1;i<=l;i++)
            {
                if(sc.nextInt()%2==1 && i%2==1) a++;
            }
            pw.println(a);
        }
        pw.close();
    }
}

Measured memory_bytes: 35776
h, w = map(int, input().split())
lst = []
for _ in range(h):
    lst.append(list(input()))
    
MOD = 10**9 + 7
dp = [[0] * (w+1) for _ in range(h+1)]
for i in range(1, h+1):
    for j in range(1, w+1):
        if i == 1 and j == 1:
            dp[i][j] = 1
        elif lst[i-1][j-1] == '.':
            dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MOD
print(dp[h][w])

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

int inf = 1<<29;
const int nmax = 40;
const int abmax = 10;

//dp[i][j][k]はグローバルで宣言（ローカルだとメモリ制限に引っかかる）
// i : 加えた薬品数
// j : 物質Aの合計の量
// k : 物質Bの合計の量
int dp[nmax+1][nmax*abmax+1][nmax*abmax+1] = {0};

int main()
{
	int N, Ma, Mb;
	cin >> N >> Ma >> Mb;

	vector<int> a(nmax+1, 0);
	vector<int> b(nmax+1, 0);
	vector<int> c(nmax+1, 0);

	for(int i = 0; i < N; i++)
	{
		cin >> a[i] >> b[i] >> c[i];
	}

	//dp配列を無限大で初期化（最小値を求めるため）
	for(int i = 0; i <= N; i++)
	{
		for(int j = 0; j <= nmax*abmax; j++)
		{
			for(int k = 0; k <= nmax*abmax; k++)
			{
				dp[i][j][k] = inf;
			}
		}
	}


	//加える薬品数が0の場合は、物質Aも物質Bも重さは0
	dp[0][0][0] = 0;

	for(int i = 0; i < N; i++)
	{
		for(int j = 0; j <= nmax*abmax; j++)
		{
			for(int k = 0; k <= nmax*abmax; k++)
			{
				if(dp[i][j][k] == inf) continue;
				dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]);
				dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k]+c[i]);
			}
		}
	}

	int ans = inf;
	for(int i = 1; i <= nmax*abmax; i++)
	{
		for(int j = 1; j <= nmax*abmax; j++)
		{
			if(i*Mb == j*Ma) ans = min(ans, dp[N][i][j]);
		}
	}

	if(ans == inf) ans = -1;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 25984
N = int(input())
a = [0]+list(map(int,input().split()))
#print(a)

b = []
c = [0]*(N+1)
for i in range(N,0,-1):
  #print('  a[{}]={}'.format(n,a[n-1]))
  total = 0
  for m in range(i+i,N+1,i):
    total += c[m]
  if total%2!=a[i]:
    c[i] += 1
    b.append(i)

print(len(b))
for bm in b:
  print('{} '.format(bm))


Measured memory_bytes: 67804
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

using ll = long long;
using ull = unsigned long long;

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    cout << (n / (a + b)) * a + min(n % (a + b), a) << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int[] balls = new int[N];
		long[] sizes = new long[N + 1];
		Set<Integer> contain = new HashSet<>();
		long answerT = 0;
		Map<Integer, Long> temp1 = new HashMap<>();
		Map<Integer, Long> temp2 = new HashMap<>();

		for (int i = 0; i < N; i++) {
			int num = scanner.nextInt();
			balls[i] = num;
			contain.add(num);
			sizes[num]++;
		}

		for (int k : contain) {
			long size = sizes[k];
			temp1.put(k, size * (size - 1) / 2);
			temp2.put(k, (size - 1) * (size - 2) / 2);
			answerT += temp1.get(k);
		}

		for (int i = 0; i < N; i++) {
			int ball = balls[i];
			long answer = 0;

			answer = answerT - temp1.get(ball) + temp2.get(ball);
			System.out.println(answer);
		}
	}
}

Measured memory_bytes: 114056
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[])
{
    int in, i;
    char line[256];

    for (i=1;; i++) {

        memset(line, 0, sizeof(line));
        if (!fgets(line, sizeof(line), stdin)) {
            fprintf(stderr, "error input val\n");
            return -1;
            ;
        }

        if (sscanf(line, "%d", &in) != 1) {
            //      fprintf(stderr, "error input format\n");
            //      return -1;
            ;
        }

        if (!in) {
            break;
        }
        printf("Case %d: %d\n", i, in);
    }

    return 0;
}

Measured memory_bytes: 612
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
int main(){
    string a;
    getline(cin,a);
    int s=a.size();
    int l=1;
    int ans1,ans2,ans=0;
    for(int i=0;i<s;i++)
    if(l&&a[i]=='A')
    {
        ans1=i;
        l=0;
    }
    else if(a[i]=='Z')
    ans2=i;
    for(int i=ans1;i<=ans2;i++)
    ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
int main(){

  int n,m,i,j;
  char transA[100000],transB[100000],print[100000],scan;

  while(1){
    
    scanf("%d",&n);
    
    if(n != 0){
      
      for(i = 0; i < n; i++){
	
	scanf("\n%c %c",&transA[i],&transB[i]);
	
      }
      
      /*
	for(i = 0; i < n; i++){
	
	printf("\n%c %c",transA[i],transB[i]);
	
	}
      */
      
      
      scanf("%d",&m);
      
      for(i = 0; i < m; i++){
	
	scanf("\n%c",&scan);
	
	for(j = 0; j < n; j++){
	  
	  if(scan == transA[j]){
	    
	    scan=transB[j];
	    break;
	    
	  }
	  
	}
	
	print[i]=scan;
	
      }
      
      for(i = 0; i < m; i++) printf("%c",print[i]);
      
      printf("\n");
      
    } else {

    break;

    }

  }

  return 0;

}

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

using namespace std;

const int maxn = 18;

typedef long long ll;

int n, a[maxn][maxn];

ll cost[1<<maxn];
ll dp[1<<maxn];

void calc(void)
{
	for (int mask = 0; mask < (1<<n); mask++)
	{
		ll soma = 0LL;

		for (int i = 0; i < n; i++)
		{
			if (!(mask&(1<<i))) continue;

			for (int j = i+1; j < n; j++)
			{
				if (!(mask&(1<<j))) continue;

				soma += 1LL*a[i][j];
			}
		}

		cost[mask] = soma;
	}
}

ll solve(int mask)
{
	if (!mask) return 0;
	if (dp[mask] != -1) return dp[mask];

	ll ans = 0;
	for (int sub = mask; sub > 0; sub = (sub-1)&mask)
		ans = max(ans, cost[sub]+solve(mask^sub));

	return dp[mask] = ans;
}

int main(void)
{
	cin >> n;

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

	calc();

	memset(dp, -1, sizeof dp);

	cout << solve((1<<n)-1) << "\n";
}

Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <numeric>

using namespace std;

int gcd(int a, int b) {
    if (a%b == 0) {
        return b;
    } else {
        return(gcd(b, a%b));
    }
}

int main(void) {
    int K, sum = 0;
    cin >> K;

    for (int i = 1; i <= K; i++) {
        for (int j = 1; j <= K; j++) {
            for (int k = 1; k <= K; k++) {
                // cout << i << j << k << endl;
                sum += gcd(gcd(i, j), k);
            }
        }
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3160
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
struct Node {
    int key;
    struct Node *prev, *next;
};
 
struct Node *nil;
 
void init() {
    nil = (struct Node *)malloc(sizeof(struct Node));
    nil->next = nil;
    nil->prev = nil;
}
 
void insert(int key) {
    struct Node *x = (struct Node *)malloc(sizeof(struct Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}
 
struct Node* listSearch(int key) {
    struct Node *cur = nil->next;
    while(cur != nil && cur->key != key ) {
        cur = cur-> next;
    }
    return cur;
}
 
void deleteNode(struct Node *t) {
    if (t == nil) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}
 
void deleteFirst() {
    deleteNode(nil->next);
}
 
void deleteLast() {
    deleteNode(nil->prev);
}
void deleteKey(int key) {
    deleteNode(listSearch(key));
}
 
void printList() {
    struct Node *cur;
    cur = nil->next;
    int isf = 0;
 
    while(1) {
        if (cur == nil) break;
        if(isf++ > 0) printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
    }
    printf("\n");
}
 
 
int main(void) {
    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d", &n);
    init();
    for (i = 0; i < n; i++) {
        scanf("%s%d",com, &key);
        if(com[0] == 'i') {
            insert(key);
            np ++;
            size++;
        }else if(com[0] == 'd') {
            if(strlen(com) > 6) {
                if( com[6] == 'F') {
                    deleteFirst();
                }else if(com[6] == 'L') {
                    deleteLast();
                }
            }else {
                deleteKey(key);
                nd ++;
            }
            size --;
        }
    }
    printList();
    return 0;
 
}

Measured memory_bytes: 31788
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
x = [inpl() for i in range(n)]
y = [inpl() for i in range(n)]
x.sort(reverse=True)
y.sort(key = lambda x: x[1])
res = 0
used = set()
for i in range(n):
    a,b = x[i][0], x[i][1]
    for j in range(n):
        c,d = y[j][0], y[j][1]
        if a<c and b<d and not j in used:
            res += 1
            used.add(j)
            break
print(res)

Measured memory_bytes: 5588
#include<cstdio>
int m,b,a;
char s[12];
int main()
{
	scanf("%d%d%s",&a,&b,s);
	for(b+=a+1;b--;)
		if(b==a && s[b]!='-' || b-a && (s[b]<'0' || s[b]>'9')) m=1;
	printf(m?"No":"Yes");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main() {
    string s;
    int x = 0;
    cin >> s;
    for(int i = 0; i < 3;i++)
        if (s[i] == 'o')
            x++;
    cout << 700 + (100 * x) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} //配列vにn個の要素を入力する

int main(){
    int a,b;
    cin >> a >> b;
    if(a==1){a = 14;}
    if(b==1){b = 14;}
    if(a>b){cout << "Alice";}
    else if(a==b){cout << "Draw";}
    else{cout << "Bob";}

}

Measured memory_bytes: 256