akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

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

#define REP(i, n) for(ll i = 0; i < n; i++)












struct LazySegmentTree {
private:
    ll n;
    vector<ll> node, lazy;
    vector<bool> lazyFlag;

public:
    LazySegmentTree(vector<ll> v) {
        ll sz = (ll)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, INF);
        lazyFlag.resize(2*n-1, false);

        for(ll i=0; i<sz; i++) node[i+n-1] = v[i];
        for(ll i=n-2; i>=0; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }

    void lazyEvaluate(ll k, ll l, ll r) {
        if(lazyFlag[k]) {
            node[k] = min(node[k], lazy[k]);
            if(r - l > 1) {
                lazy[k*2+1] = min(lazy[k*2+1], lazy[k]);
                lazy[k*2+2] = min(lazy[k*2+2], lazy[k]);
                lazyFlag[k*2+1] = lazyFlag[k*2+2] = true;
            }
            lazyFlag[k] = false;
        }
    }

    void update(ll a, ll b, ll x, ll k=0, ll l=0, ll r=-1) {
        if(r < 0) r = n;
        lazyEvaluate(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] = min(lazy[k], x);
            lazyFlag[k] = true;
            lazyEvaluate(k, l, r);
        }
        else {
            update(a, b, x, 2*k+1, l, (l+r)/2);
            update(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = min(node[2*k+1], node[2*k+2]);
        }
    }

    ll find(ll a, ll b, ll k=0, ll l=0, ll r=-1) {
        if(r < 0) r = n;
        lazyEvaluate(k, l, r);
        if(b <= l || r <= a) return INF;
        if(a <= l && r <= b) return node[k];
        ll vl = find(a, b, 2*k+1, l, (l+r)/2);
        ll vr = find(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
    }
};
 
int main(){
    ll n, m;
    cin >> n >> m;
    vector<pair<pair<ll, ll>, ll>> v(m);
    REP(i, m){
        ll l, r, c;
        cin >> l >> r >> c;
        l--; r--;
        v[i] = {{l, r}, c};
    }
    sort(v.begin(), v.end(), [](pair<pair<ll, ll>, ll> p1, pair<pair<ll, ll>, ll> p2){
        ll a1 = p1.first.first, b1 = p1.first.second, c1 = p1.second;
        ll a2 = p2.first.first, b2 = p2.first.second, c2 = p2.second;
        if(a1 != a2) return a1 < a2;
        if(b1 != b2) return b1 < b2;
        return c1 < c2;
    });
    
    vector<ll> t(n, INF);
    LazySegmentTree tree(t);
    tree.update(0, 1, 0);
    REP(i, m){
        ll l = v[i].first.first, r = v[i].first.second, c = v[i].second;
        ll tmp = tree.find(l, r + 1);
        if(tmp == INF) continue;
        tree.update(l, r + 1, tmp + c);
    }
    ll ans = tree.find(n - 1, n); 
    cout << ((ans != INF)? ans : -1) << endl;
}

Measured memory_bytes: 8192
#55 ABC135E
k=int(input())
x,y=map(int,input().split())
def golf(a,b):
	if a<0:
		t=golf(-a,b)
		return -t[0],t[1]
	if b<0:
		t=golf(a,-b)
		return t[0],-t[1]
	if a>b:
		t=golf(b,a)
		return t[1],t[0]
	if a+b>=2*k:
		return a,b-k
	if a+b==k:
		return 0,0
	r=k-(a+b)//2
	return -r,a+b+r-k
if k%2==0 and (x+y)%2==1:
	print(-1)
else:
	res=[]
	while x or y:
		res.append([x,y])
		x,y=golf(x,y)
	print(len(res))
	for r in res[::-1]:
		print(r[0],r[1])

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

using namespace std;

int a[20][2], n, f[262144][19][2];
int F(int i,int j,int ok)
{
    if(f[i][j][ok]!=-1) return f[i][j][ok];
    if(i==(1<<n)-1) return 0;

    int res = 1e9, sl = 0, t = 0;
    for(int id = 1; id <= n; id++)
        if(i >> (id-1) &1) sl++;
    for(int id = 1; id <= n; id++)
    {
        if(i >> (id-1) & 1 ^ 1)
        {
            int nok = abs(sl-id+1)%2;
            if(a[id][nok] >=a [j][ok]) res = min(res, F(i|(1<<(id-1)), id, nok) + id - t - 1);
        }
        else t++;
    }
    f[i][j][ok] = res;
    return res;
}

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

    memset(f, -1, sizeof(f));
    int ans = F(0,0,0);
    if(ans == 1e9) ans = -1;
    cout << ans;
}


Measured memory_bytes: 42528
#include<stdio.h>
#include<string.h>
int main(){
	int i,a,b,k;
	scanf("%d%d%d",&a,&b,&k);
	for(i=1;i<=k;i++){
        if(i%2==1){
            if(a%2==1){
                a=a-1;
                b=b+a/2;
                a=a/2;
            }
            else if(a%2==0){
                b=b+a/2;
                a=a/2;
            }
        }
        if(i%2==0){
            if(b%2==1){
                b=b-1;
                a=a+b/2;
                b=b/2;
            }
            else if(b%2==0){
                a=a+b/2;
                b=b/2;
            }
        }
    }
    printf("%d %d\n",a,b);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
	long long n,k, ans=0;

	cin >> n >> k;

	vector<long long> h(n);

	for (long long i = 0; i < n; i++)
		cin >> h[i];

	if (k >= h.size())
	{
		ans = 0;
	}
	else
	{
		sort(h.begin(), h.end());

		for (long long i = 0; i < k; i++)
			h.pop_back();

		for (long long i = 0; i < h.size(); i++)
		{
			ans += h[i];
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef vector< pii > vii;

#define ll          long long
#define ff          first
#define ss          second
#define pb          push_back
#define mkp         make_pair
#define sz          size()

#define forf(a,b,c)    for(int i=a;i<=b;i+=c)
#define forr(a,b,c)    for(int i=a;i>=b;i-=c)
#define all(a)      a.begin(),a.end()
#define mem(a,b)    memset(a,b,sizeof(a))
#define pi          2*acos(0.0)
#define End         return 0;
#define nl endl

#define scan1(a)    scanf("%d",&a)
#define scan2(a,b)  scanf("%d %d",&a,&b)
#define scan3(a,b,c)  scanf("%d %d %d",&a,&b,&c)
#define scanl(a)    scanf("%lld",&a)
#define scanll(a,b) scanf("%lld %lld",&a,&b)
#define scanlll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)

#define print1(a)    printf("%d",a)
#define print2(a,b)  printf("%d %d",a,b)
#define print3(a,b,c)  printf("%d %d %d",a,b,c)
#define printl(a)    printf("%lld",a)
#define printll(a,b) printf("%lld %lld",a,b)
#define printlll(a,b,c) printf("%lld %lld %lld",a,b,c)

#define MAXN        100000007
#define INF 0x3f3f3f3f
bool mark[100005];vi prime;
void seive(ll N){for(int i=2;i<=N;i++){if(mark[i]==false){prime.pb(i);for(int j=i+i;j<N;j+=i)mark[j]=true;}}}
//freopen("input.txt", "r", stdin);

int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
   ll n,h,res;
   cin>>n;
   vll v(n+2),vv;
   for(int i=1;i<=n;i++) cin>>v[i];
   ll cnt=1;
   for(int i=2;i<=n;i++){
    if(v[i]<=v[i-1]) cnt++;
    else {
        vv.pb(cnt-1);
        cnt=1;
    }
   }
   vv.pb(cnt-1);
   //for(int i=0;i<vv.sz;i++) cout<<vv[i]<<" ";
   sort(all(vv));
   reverse(all(vv));
   cout<<vv[0]<<endl;
}



Measured memory_bytes: 2168
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 100010;
const int MAXK = 510;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
  char a, b;
  cin >> a >> b;
  if (a > b) cout << '>';
  else if (a < b) cout << '<';
  else cout << '=';
    return 0;
}

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

int main(void){
  string s;
  cin >> s;
  int sl = s.length();
  int str = sl - 7;
  string cs, ts1, ts2;
  bool flag = false;
  int count = 0;
  while(count < 7){
    cs = s.substr(0, count);
    ts1 = s.substr(count, str);
    ts2 = s.substr(count + str);
    cs += ts2;
    if(cs == "keyence") flag= true;
    count++;
  }
  if(flag) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define mkp make_pair
typedef long long ll;
using namespace std;
 
ll L,A,B,M;
 
ll MOD=1000000007;
 
typedef vector<ll> vec;//ll?
typedef vector<vec> mat;
 
mat mul(mat &A,mat &B){
  mat C(A.size(),vec(B[0].size()));
  for(int i=0;i<A.size();i++){
    for(int k=0;k<B.size();k++){
      for(int j=0;j<B[0].size();j++){
        C[i][j]=(C[i][j]+A[i][k]*B[k][j]%MOD)%MOD;
      }
    }
  }
  return C;
}
 
mat pow(mat A,ll n){
  mat B(A.size(),vec(A.size()));
  for(int i=0;i<A.size();i++){
    B[i][i]=1;
  }
  while(n>0){
    if(n&1) B=mul(B,A);
    A=mul(A,A);
    n=(n>>1);
  }
  return B;
}
 
 
 
int digit(ll val){
    if(val==0) return 0;
    else return (1+digit(val/10));
}
 
int main(){
  cin>>L>>A>>B>>M;
  MOD=M;
 
  ll ans=0;
  ll ten[20]={};
  ten[0]=1;
  for(int i=1;i<=18;i++) ten[i]=ten[i-1]*10%MOD;
 
  ll start=0;
  while(start<L){
    ll ng=L;
    ll ok=start;
    ll nowdigit=digit(A+B*start);
 
    while(ng-ok>1){
      ll mid=(ng+ok)/2;
      if(digit(A+B*mid)==nowdigit) ok=mid;
      else ng=mid; 
    }
    
    mat C(3,vec(3));
    C[0][0]=ten[nowdigit];
    C[0][1]=1;
    C[0][2]=A%MOD;
    C[1][0]=0;
    C[1][1]=1;
    C[1][2]=B%MOD;
    C[2][0]=0;
    C[2][1]=0;
    C[2][2]=1;
    C=pow(C,(ok-start+1));
 
    mat D(3,vec(1));
    D[0][0]=ans;
    D[1][0]=(B*start)%MOD;
    D[2][0]=1;
    D=mul(C,D);
 
    ans=D[0][0];
    ans=(ans+MOD)%MOD;
    start=ok+1;
  }
 
  cout<<ans<<endl;
 
 
  return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	string s;
	cin>>s;
	bool ok1=false;
	bool ok2=false;
	rep(i,s.size()){
		if(s[i]=='C') ok1=true;
		if(ok1&&s[i]=='F') ok2=true;
	}
	if(ok2) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 764
import java.util.*;

class Main {
	public static void main (String[] args) throws java.lang.Exception {
        Scanner sc = new Scanner(System.in);
        
        int num1 = sc.nextInt();
        int num2 = sc.nextInt();

        System.out.print(num1 / num2+" ");
        System.out.print(num1 % num2+" ");
        System.out.println(String.format("%.5f",(double)num1 / num2));
    }
}


Measured memory_bytes: 26592
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
    int n; cin >> n;
    ll a, b; cin >> a >> b;
    vector<ll> v(n);
    ll ans = 0;
    rep(i, n) cin >> v[i];
    for(int i = 0; i < n-1; i++){
        if((v[i+1]-v[i])*a < b){
            ans += (v[i+1]-v[i])*a;
        }
        else ans += b;
    }
    cout << ans << endl;
    system("pause");
}

Measured memory_bytes: 1272
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <queue>
#include <random>

using namespace std;

#define min(a,b) ((a)<(b) ? (a):(b))
#define max(a,b) ((a)>(b) ? (a):(b))

int gcd(int a, int b){
    while( b ){
        int m = a % b;
        a = b;
        b = m;
    }
    return a;
}

int lcm(int a, int  b){
    return (a*b)/gcd(a,b);
}

int isPrim(int a){
    if(a==1){
        return 0;
    }
    for(int i=2;i<=(a+1)/2;i++){
        if(a%i==0){
            return 0;
        }
    }
    return 1;
}

long long mod_pow(long long x, long long n, long long mod){
    //xのn乗を計算するのにn乗を2進表記にして計算
    //x^22 = x^16 + x^4 + x^2
    long long ret=1;
    while(n>0){
        if(n%2==1){
            ret=(ret*x)%mod;//答えに付加
        }
        x=(x*x)%mod;//2乗
        n=n/2;
    }
    return ret;
}

struct VV{
    int x;
    int y;
    int z;
};

class LessInt {
public:
    bool operator()(const VV& riLeft, const VV& riRight) const {
        if(riLeft.x == riRight.x){
            return riLeft.y > riRight.y;
        }
        return riLeft.x > riRight.x;
        
    }
};

class indInt {
public:
    bool operator()(const VV& riLeft, const VV& riRight) const {
        return riLeft.x < riRight.x;
        
    }
};

struct XX{
    int zenbu=0;
    int kidoku=0;
};

class xxIntu {
public:
    bool operator()(const VV& riLeft, const VV& riRight) const {
        //第1条件
        if(riLeft.z != riRight.z){
            return riLeft.z > riRight.z;//<:昇順(小さい順)、>:降順(大きい順)
        }
        //第2条件
        return riLeft.y < riRight.y;
    }
};
bool operator< (const VV &riLeft, const VV &riRight){
    return riLeft.z < riRight.z;
};
/*bool operator> (const XX &riLeft, const XX &riRight){
    return riLeft.a > riRight.a;
};*/



int main(int argc, const char * argv[])
{
    //std::ios::sync_with_stdio(false);
    //scanf("%s",S);
    //scanf("%d",&N);
    //getline(cin, target);
    //cin >> x >> y;
    //ここから
    
    string s;
    cin >>s;
    int ans=-1;
    int ff=0;
    for(int i='a';i<='z';i++){
        int f=0;
        for(int j=0;j<s.size()-1;j++){
            if(s[j]==i && s[j+1]==i){
                ans=j+1;
                f=1;
                break;
            }
        }
        if(f==1){
            break;
        }
    }
    if(ans==-1){
        for(int i='a';i<='z';i++){
            int f=0;
            for(int j=0;j<s.size()-2;j++){
                if(s[j]==i && s[j+2]==i){
                    ff=1;
                    ans=j+1;
                    f=1;
                    break;
                }
            }
            if(f==1){
                break;
            }
        }
    }

    if(ans==-1){
        cout << "-1 -1" << endl;
    }else if(ff==1){
        cout << ans << " " << ans+2 << endl;
    }else{
        cout << ans << " " << ans+1 << endl;
    }
    
    //ここまで
    //cout << "ans" << endl;改行含む
    //printf("%.0f\n",ans);//小数点以下表示なし
    //printf("%.7f\n",p);
    //printf("%f\n",pow(2,ans.size()));
    
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
void solve() {
	string T; cin >> T;
	if (T.size() == 1) {
		if (T[0] == '?') {
			cout << "D" << endl;
		} else {
			cout << T << endl;
		}
		return;
	}
	if (T[0] == '?') {
		if (T[1] == 'P') T[0] = 'D';
		else if (T[1] == 'D') T[0] = 'P';
		else T[0] = 'P';
	}	
	for (int i = 1; i < (T.size() - 1); ++i) {
		if (T[i] == '?') {
			//P?
			if (T[i - 1] == 'P') {
				if (T[i + 1] == 'P') T[i] = 'D';
				else if (T[i + 1] == 'D') T[i] = 'D';
				else T[i] = 'D';
			//D?
			} else if (T[i - 1] == 'D') { 
				if (T[i + 1] == 'P') T[i] = 'D';
				else if (T[i + 1] == 'D') T[i] = 'P';
				else T[i] = 'P';
			}
		}
	}
	if (T[T.size() - 1] == '?') T[T.size() - 1] = 'D';
	cout << T << endl;
	return;
}
int main() {
	solve();
	return 0;
}

Measured memory_bytes: 3760
#include <stdio.h>
#include <stdlib.h>

struct Node {
    int key;
    struct Node *next;
    struct Node *prev;
};
typedef struct Node node_t;
node_t *root;

int N;

void insert(int x)
{
    node_t *new = (node_t*)malloc(sizeof(node_t));
    new->key = x;
    new->next = root->next;
    new->prev = root;
    root->next->prev = new;
    root->next = new;
}

void deleteNode(node_t *p)
{
    p->prev->next = p->next;
    p->next->prev = p->prev;
    free(p);
}

void delete(int x)
{
    node_t *p = root->next;
    while (p != root) {
        if (p->key == x) {
            deleteNode(p);
            return;
        }
        p = p->next;
    }
}

void deleteFirst()
{
    deleteNode(root->next);
}

void deleteLast()
{
    deleteNode(root->prev);
}

void printList()
{
    node_t *p = root->next;
    
    // NULL ??§????????? root
    while (p != root) {
        printf("%d", p->key);
        p = p->next;
        if (p != root) {
            printf(" ");
        }
    }
    puts("");
}

int main()
{
    root = (node_t*)malloc(sizeof(node_t));
    root->next = root->prev = root;
    
    int i, j;
    char cmd[15];
    int x;
    
    scanf("%d", &N);
    for (i = 0; i < N; i++) {
        scanf("%s", cmd);
        switch (cmd[0]) {
        case 'i':
            scanf("%d", &x);
            insert(x);                
            break;
        case 'd':
            switch (cmd[6]) {
            case 'F':
                deleteFirst();
                break;
            case 'L':
                deleteLast();
                break;
            default:
                scanf("%d", &x);
                delete(x);
                break;
            }
            break;                
        }
    }
    
    printList();
    
    return 0;
}

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

int Janken(int n, int k, int r, int s, int p, string t);

int main()
{
    int N, K, R, S, P;
    string T;
    cin >> N >> K >> R >> S >> P >> T;
    cout <<Janken(N, K, R, S, P, T) << endl; 
}


int Janken(int n, int k, int r, int s, int p, string t)
{
    int point = 0;
    bool *win = new bool[n];
    
    for(int i = 0; i < k; i++)
    {
        if(t[i] == 'r') point += p;
        else if(t[i] == 's') point += r;
        else point += s;
        win[i] = true;
    }
    
    for(int i = k; i < n; i++)
    {
        if (t[i - k] == t[i])    
        {
            if(win[i - k])
                win[i] = false;
            else
            {
                if(t[i] == 'r') point += p;
                else if(t[i] == 's') point += r;
                else point += s;
                win[i] = true;
            }           
        }
        else
        {
            if(t[i] == 'r') point += p;
            else if(t[i] == 's') point += r;
            else point += s;
            win[i] = true;   
        }    
    }
    
    delete[] win;
    return point;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 100005;

int main() {
    int n, m; cin >> n >> m;
    if (n == 1 && m == 1) cout << 1 << endl;
    else if (n == 1 && m >= 2) cout << m-2 << endl;
    else if (n >= 2 && m == 1) cout << n-2 << endl;
    else {
        ll x = n-2, y = m-2;
        cout << x*y << endl;
    }
}

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

int main()
{
  string s;
  cin >> s;
  int len = s.length();

  int n0 = 0;
  for (int i = 0; i < len; i++){
    if (s[i] == '0'){ n0++; }
  }

  int ans = 2 * min(n0, len - n0);
  cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int a[300000][22];
int b[22];
int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin>>n;
    for (int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        for (int j=0;j<20;j++)
        {
            a[i][j]=x%2;
            x/=2;
        }
    }
    int l=1;
    ll ret=0;
    for (int r=1;r<=n;r++)
    {
        for (int j=0;j<20;j++)
            b[j]+=a[r][j];
        while(1)
        {
            int is=0;
            for (int j=0;j<20;j++)
                if (b[j]>1)
                    is=1;
            if (is)
            {
                for (int j=0;j<20;j++)
                    b[j]-=a[l][j];
                l++;
            }
            else
                break;
        }
        ret+=(r-l+1);
    }
    cout<<ret<<endl;
}


Measured memory_bytes: 18688
#include<stdio.h>
int ss(int A[], int N){
	int i, j, t, sw = 0, miji;
	for(i=0;i<N;i++){
		miji = i;
		for(j=i;j<N;j++){
			if(A[j]<A[miji]) miji=j;
		}
		t=A[i]; A[i] = A[miji]; A[miji]=t;
		if(i != miji) sw++;
	}
	return sw;
}
int main(){
	int N;
	int A[100];
	int i, sw;
	
	scanf("%d", &N);
	for(i=0; i<N; i++){
		scanf("%d", &A[i]);
	}
	sw = ss(A, N);
	for(i=0; i<N; i++){
		if(i>0){
			printf(" ");
		}
		printf("%d", A[i]);
	}
	printf("\n");
	printf("%d\n", sw);
	
	
	return 0;
}

Measured memory_bytes: 604
sx, sy, tx, ty = gets.split.map{|i|i.to_i}
dx = tx - sx
dy = ty - sy
path = ""

path += "R" * dx
path += "U" * dy

path += "L" * dx
path += "D" * dy

path += "D"
path += "R" * (dx + 1)
path += "U" * (dy + 1)
path += "L"

path += "U"
path += "L" * (dx + 1)
path += "D" * (dy + 1)
path += "R"

puts path


Measured memory_bytes: 1916
#include<stdio.h>
using namespace std;
int main() {
	int s1,s2,s3,ans=0;
	scanf("%1d%1d%1d",&s1,&s2,&s3);
	if(s1) ans++;
	if(s2) ans++;
	if(s3) ans++;
	printf("%d\n",ans);
	return 0;
}

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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;


int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	string S;
	cin >> S;

	int YYYY = atoi(S.substr(0, 4).c_str());
	int MM = atoi(S.substr(5, 2).c_str());
	int DD = atoi(S.substr(8, 2).c_str());

	if(YYYY <= 2018){
		printf("Heisei\n");
	}
	else if(YYYY == 2019 && MM <= 4){
		printf("Heisei\n");
	}
	else{
		printf("TBD\n");
	}
	return 0;
}


Measured memory_bytes: 3600
#include<stdio.h>
int main()
{
 int w,h,x,y,r;
 scanf("%d%d%d%d%d",&w,&h,&x,&y,&r);
 if(((x-r>=0) && (y-r>=0))&&((x+r<=w)&&(y+r<=h)))
  printf("Yes\n");
 else
  printf("No\n");
}


Measured memory_bytes: 2704
// Author : Harshdeep Sharma , IIT Indore
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
// #define MOD  998244353
#define ll long long
const double PI = atan(1.0) * 4;
// const ll INF = (int)1e9 ;
const int di[4] = { -1, 0, 1, 0} ;
const int dj[4] = {0, -1, 0, 1} ;
const ll INF = (ll)2e18 + 50;
const int maximum  = numeric_limits<int>::min();
const int minimum  = numeric_limits<int>::max();

// function to calculate any numbered power of some number without modulo
ll power(ll a , ll e) {
	ll res = 1LL ;
	while (e > 0) {
		if (e % 2 == 1) res = res * a;
		a =  a * a  ;
		e /= 2 ;
	}
	return res ;
}
// function to check whether a bracketed sequence is balanced or not
bool isBalanced(const string &exp) {
	// Initialising Variables
	bool flag = true;
	int count = 0;

	// Traversing the Expression
	for (int i = 0; i < exp.length(); i++) {

		if (exp[i] == '(') {
			count++;
		}
		else {
			count--;
		}
		if (count < 0) {
			flag = false;
			break;
		}
	}
	if (count != 0) {
		flag = false;
	}

	return flag;
}
// function to sort by second in a set of pairs
bool sortbysec(const pair<pair<int, int>, int> &a,
               const pair<pair<int, int>, int> &b) {
	return (a.second < b.second);
}

void uniformly_distribute_k_numbers_in_a_square_grid(int n , int k ) {
	int p = 0 , q = 0 ;
	vector<vector<int>> a(n, vector<int>(n)) ;
	for (int i = 1 ; i <= k ; ++i ) {
		a[p][q] = 1 ;
		p = p + 1 ;
		q = (q + 1) % n ;
		if (p == n) {
			p = 0  ;
			q = (q + 1) % n ;

		}
	}
}

ll f(ll n) {
	ll res ;
	if (n % 2 != 0) {
		ll pairs = (n + 1) / 2 ;
		if (pairs % 2 == 0) {
			res = 0  ;
		} else {
			res = 1 ;
		}
	} else {
		// cout << "i\n";
		ll pairs = n / 2 ;
		if (pairs % 2 == 0) {
			res = 0  ;
		} else {
			res = 1 ;
		}
		res ^= n ;
	}
	return res ;
}



// main funtion
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	// int t ;
	// cin >> t ;
	// while (t--) {

	string  s ;
	cin >> s ;
	bool ok = true ;
	int n = s.length() ;
	for (int i = 0 ; i < n - 1 ; i++) {
		if (s[i] == s[i + 1]) {
			ok = false ;
			break ;
		}
	}
	if (ok) cout << "Good\n";
	else cout << "Bad\n";






	// }







	return 0 ;
}


Measured memory_bytes: 3660
N, Y = map(int, input().split())
flg = False
if N * 1000 <= Y <= N * 10000:
    for i in range(N + 1)[::-1]:
        if Y < i * 10000:
            continue
        if flg or i * 10000 + (N - i) * 5000 < Y:
            break
        for j in range(N + 1 - i)[::-1]:
            m = i * 10000 + j * 5000 + (N - i - j) * 1000
            if Y < m:
                continue
            if m == Y:
                print(i, j, N - i - j)
                flg = True
            if m <= Y:
                break
if not flg:
    print(-1, -1, -1)


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

using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define rf(i,a,b) for(ll i=a; i>=b; i--)
#define pb push_back
#define mp make_pair
#define show(a) for(auto el:a)cout<<el<<" "
#define ff first
#define ss second
#define pairv vector<pair<ll,ll>>
#define vec vector <ll> 
#define all(a) a.begin(),a.end()
#define fam(v,i) for(auto i=v.begin();i!=v.end();i++)
#define fai(v,i) for(auto i : v)
#define mo 1000000007

#define nn cout<<"\n";
ll pow1(ll n,ll p)
{
if(p==0) return 1;
ll x=pow1(n, p/2);
x=(x*x)%mo;
if(p%2==0)
return x;
else
return (x*n)%mo;
}
bool sortbysec(const pair<ll,ll> &a, 
const pair<ll,ll> &b) 
{ 
return (a.second < b.second); 
} 
bool compare(const pair<ll, ll>&p1, const pair<ll,ll>&p2)
{
if(p1.ff < p2.ff) return true;
if(p1.ff == p2.ff) return p1.ff < p2.ss;
return false;
}
 
ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 
ll findlcm(ll arr[], ll n) 
{ 
    ll ans = arr[0]; 
   ll ma=1e+18;
    for (ll i = 1; i < n; i++) 
      {  ans = (((arr[i] * ans)) / 
                (gcd(arr[i], ans))); 
                if(ans>ma)
                {
                    ans=-1;
                    break;
                }
      }
  
    return ans; 
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
  
     ll n;
     cin>>n;
     char e;
     map<char,ll> m;
     fr(i,0,n)
     {
         cin>>e;
         m[e]++;
     }
     ll l=m.size();
     if(l==3)
     cout<<"Three";
     else 
     cout<<"Four";
     nn
   
    
     return 0;
}


Measured memory_bytes: 3584
a,b,c,x,y=map(int,input().split())

if a+b<=2*c:
    ans=a*x+b*y
else:
    if x>=y:
        ans=y*2*c
        ans+=(x-y)*a
    else:
        ans=x*2*c
        ans+=(y-x)*b

com=max(x, y) * (2 * c)
print(min(com,ans))


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		
		Node T = null;
		for(int i = 0; i < n; ++i) {
			String[] str = br.readLine().split(" ");
			if(str[0].equals("insert")){
				T = Node.insert(T, new Node(Integer.parseInt(str[1])));
			}else{
				Node.printInOrder(T);
				Node.printPreOrder(T);
			}
		}
	
	}
}

class Node{
	public int key;
	public Node left;
	public Node right;
	public Node p;
	public Node(int key){
		this.key = key;
	}
	public static Node insert(Node T, Node z){
		Node y = null;
		Node x = T;
		while(x != null){
			y = x;
			if(z.key < x.key){
				x = x.left;
			}else{
				x = x.right;
			}
		}
		z.p = y;
		
		if(y == null){
			T = z;
		}else if(z.key < y.key){
			y.left = z;
		}else{
			y.right = z;
		}
		return T;
	}
	public static void printInOrder(Node T){
		StringBuilder sb = new StringBuilder();
		sb.append(' ');
		inOrder(T, sb);
		System.out.println(sb);
	}
	public static void inOrder(Node z, StringBuilder sb){
		if(z == null){
			return;
		}

		if(z.left != null){
			inOrder(z.left, sb);
			sb.append(' ');
		}
		sb.append(z.key);
		if(z.right != null){
			sb.append(' ');
			inOrder(z.right, sb);
		}
	}
	public static void printPreOrder(Node T){
		StringBuilder sb = new StringBuilder();
		sb.append(' ');
		preOrder(T, sb);
		System.out.println(sb);
	}
	public static void preOrder(Node z, StringBuilder sb){
		if(z == null){
			return;
		}
		sb.append(z.key);
		if(z.left != null){
			sb.append(' ');
			preOrder(z.left, sb);
		}
		if(z.right != null){
			sb.append(' ');
			preOrder(z.right, sb);
		}
	}
}

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


int main(){
int x;
cin >>x;
if (x ==1) cout << "Hello World" << endl;
else {
  int a,b ;
  cin >> a>> b;
  cout <<a+b << endl;
}
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int r,D,x;
    int i;
    int num=0;

    scanf("%d %d %d",&r,&D,&x);

    for(i=0;i<10;i++){
        num=r*x-D;
        x=num;
        printf("%d\n",num);
    }

    return 0;
}

Measured memory_bytes: 128
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <unordered_set>
# include <unordered_map>
using namespace std;

long long n, m;
long long ans;

inline long long check(long long x, long long y) {
    return (x < y ? x : x % y + check(x / y, y));
}

void solve(long long x) {
    long long z = m - x;
    long long nn = n - z;
    if (nn % x == 0 && nn / x > z && nn / x > x) {
        if (nn / x != 1) ans = min(ans, nn / x);
    }
    return;
}

int main(int argc, const char * argv[]) {
#ifdef __APPLE__
    freopen("/Users/danya.smelskiy/Documents/Danya/Resources/input.txt","r",stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (long long i = 2; i * i <= n; ++i)
        if (check(n, i) == m) {
            cout << i << '\n';
            return 0;
        }
    ans = 1e18;
    if (n == m) ans = n + 1ll;
    for (long long i = 1; i * i <= n && i <= m; ++i)
        solve(i);
    cout << (ans == 1e18 ? -1 : ans) << '\n';
    return 0;
}



Measured memory_bytes: 256
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n, m = MAP()

if n == 1:
    if m == 1:
        print(1)
    else:
        print(m-2)
elif n == 2:
    print(0)
else:
    if m == 1:
        print(n-2)
    else:
        print((m-2)*(n-2))

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int N;
    cin >> N;
    vector<ll> A(N), B(N);
    rep(i, N) cin >> A[i] >> B[i];
    reverse(A.begin(), A.end());
    reverse(B.begin(), B.end());
    ll ans = 0, tmp = 0;
    rep(i, N) {
        ll a = A[i] + tmp;
        if (a%B[i] > 0) {
            tmp += B[i] - a%B[i];
            ans += B[i] - a%B[i];
        }
        // while (a%B[i] != 0) {
        //     a++;
        //     tmp++;
        //     ans++;
        // }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)



int main(){
    int n;
    cin>>n;
    int64_t sum=0;
    vector<int> amount(100005,0);
    rep(i,n){
        int a;
        cin>>a;
        sum+=a;
        amount[a]++;
    }
    int q;
    cin>>q;
    rep(i,q){
        int b,c;
        cin>>b>>c;
        sum+=(c-b)*amount[b];
        amount[c]+=amount[b];
        amount[b]=0;
        cout<<sum<<endl;
    }
}

Measured memory_bytes: 3760
import scala.io.StdIn.readLine
import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args:Array[String]) = {
    var n = 0
    val b = new ArrayBuffer[Int]
    while({n=readLine.trim.toInt;n}!=0) {
      var min = n
      for(i<-0 to 100) {
        for(j<-0 to Math.sqrt(n-i*i*i).toInt+1) {
          val m = j*j+i*i*i
          if(m>=0 && m<=n) {
            if(min > i+j+(n-m)) min = i+j+(n-m)
          }
        }
      }
      b += min
    }
    println(b.mkString("\n"))
  }
}

Measured memory_bytes: 70304
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
int n,m,v,i;
void solve(){
  cin.tie(0);
  ll a,b,c;
  ios::sync_with_stdio(false);
  cin>>a>>b>>c;
  if(c -1> a+b) cout<<(a+b)*2-a+1<<endl;
  else cout<<c+b<<endl;

}

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


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
    long int n, c;
    scanf("%ld %ld", &n, &c);
    long int x[n], v[n];
    for(int i = 0; i < n; i++){
        scanf("%ld %ld", &x[i], &v[i]);
    }
    long int mx1 = 0, mx2 = 0, mx3 = 0, mx4 = 0;
    long int sm = 0;
    long int pos = 0;
    long int a[n], b[n];
    for(int i = 0; i < n; i++){
        sm += v[i] - (x[i] - pos);
        pos = x[i];
        if (sm > mx1) mx1 = sm;
        a[i] = mx1;
    }
    pos = c;
    sm = 0;
    for(int i = n-1; i >= 0; i--){
        sm += v[i] - (pos - x[i]);
        pos = x[i];
        if (sm > mx3) mx3 = sm;
        b[i] = mx3;
    }
    // for(int i = 0; i < n; i++){
    //     printf("a[i] = %ld b[i] = %ld\n", a[i], b[i]);
    // }
    
    pos = 0;
    sm = 0;
    for(int i = 0; i < n - 1; i++){
        sm += v[i] - 2 * (x[i] - pos);
        pos = x[i];
        if (sm + b[i+1] > mx2) mx2 = sm + b[i+1];
        // printf("%ld %ld %d\n", sm, b[i+1], i+1);
    }
    pos = c;
    sm = 0;
    for(int i = n-1; i >= 1; i--){
        sm += v[i] - 2 * (pos - x[i]);
        pos = x[i];
        if (sm + a[i-1] > mx4) mx4 = sm + a[i-1];
    }
    // printf("%ld %ld %ld %ld\n", mx1, mx2, mx3, mx4);
    long int ans = max(max(mx1, mx2), max(mx3, mx4));
    printf("%ld\n", ans);
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//const ll MOD = pow(10, 9) + 7;
const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << endl; exit(0);}

int main()
{
  ll N, M;
  cin >> N >> M;
  vector<ll> A(M), C(M);
  for (ll i = 0; i < M; i++)
  {
    ll b;
    cin >> A.at(i) >> b;
    for (ll j = 0; j < b; j++)
    {
      ll c;
      cin >> c;
      c--;
      C.at(i) += (1LL << c);
    }
  }

  vector<ll> dp(1LL << N, INF);
  dp.at(0) = 0;
  for (ll i = 0; i < (1LL << N); i++)
  {
    for (ll j = 0; j < M; j++)
    {
      chmin(dp.at(i | C.at(j)), dp.at(i) + A.at(j));
    }
  }

  ll ans = dp.at((1LL << N) - 1);
  cout << ((ans == INF) ? -1 : ans) << endl;
}

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

bool augument(const vector<vector<int> >& g, int u, vector<int>& match_to, vector<bool>& visited)
{
  if (u < 0) {
    return true;
  }

  for (vector<int>::const_iterator it(g[u].begin()); it != g[u].end(); ++it) {
    if (!visited[*it]) {
      visited[*it] = true;
      if (augument(g, match_to[*it], match_to, visited)) {
        match_to[u] = *it;
        match_to[*it] = u;
        return true;
      }
    }
  }
  return false;
}

int bipartite_matching(const vector<vector<int> >& g, int L, vector<pair<int,int> >& matching)
{
  const int N = g.size();
  vector<int> match_to(N, -1);
  int match = 0;
  for (int u = 0; u < N; u++) {
    vector<bool> visited(N, false);
    if (augument(g, u, match_to, visited)) {
      match++;
    }
  }
  for (int u = 0; u < L; u++) {
    if (match_to[u] >= 0) {
      matching.push_back(make_pair(u, match_to[u]));
    }
  }
  return match;
}

int gcd(int a, int b)
{
  if (a < b) {
    swap(a, b);
  }
  int r;
  while ((r = a % b) != 0) {
    a = b;
    b = r;
  }
  return b;
}

int main()
{
  int n, m;
  while (cin >> m >> n && !(m == 0 && n == 0)) {
    vector<int> blue(m), red(n);
    for (int i = 0; i < m; i++) {
      cin >> blue[i];
    }
    for (int i = 0; i < n; i++) {
      cin >> red[i];
    }

    vector<vector<int> > g(n+m);
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < n; j++) {
        if (gcd(blue[i], red[j]) > 1) {
          g[i].push_back(m+j);
        }
      }
    }

    vector<pair<int,int> > matching;
    int ans = bipartite_matching(g, m, matching);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1672
import java.lang.Long

val mod = 1000000007

fun main(args: Array<String>) {
    val (L, R) = readInputLine().split(" ").map { Long.toString(it.toLong(), 2).padStart(64, '0').toCharArray() }

    L.reverse()
    R.reverse()

    // dp[xにMSBが現れたか][xがLより真に大きいか][yがRより真に小さいか][桁数]
    val dp = Array(2, {Array(2, {Array(2, {IntArray(64, {-1})})})})

    println(solve(L, R, dp, 63, 0, 0, 0))
}

fun readInputLine(): String {
    return readLine()!!
}

fun solve(L: CharArray, R: CharArray, dp: Array<Array<Array<IntArray>>>, pos: Int, Xflag: Int, Yflag: Int, MSBflag: Int): Int {
    if (pos == -1) {
        return 1
    }
    
    if (dp[MSBflag][Xflag][Yflag][pos] != -1) {
        return dp[MSBflag][Xflag][Yflag][pos]
    }
    
    var ret = 0
    
    // Xのビットが0, Yのビットも0のパターン
    // XがLより真に大きいことが確定している場合はXのビットは自由に動けるため、
    // Xが真に大きいフラグまたはLのビットが0を条件にする
    // Yのビットについては0にすると必ずRに等しいかRより真に小さくなるためDon't care
    if (Xflag == 1 || L[pos] == '0') {
        ret += solve(L, R, dp, pos - 1, Xflag, if (R[pos] == '1') 1 else Yflag, MSBflag)
        ret %= mod
    }
    
    // Xのビットが0, Yのビットが1のパターン
    // X条件は同様、YがRより真に小さいことが確定している場合はYのビットは自由に動けるため、
    // Yが真に小さいフラグまたはRのビットが0を条件にする
    // XのMSBが現れる前にこのパターンには入らない。
    // Yの最上位ビットが1, 対応するXのビットが0のパターンに該当するため。
    if ((Xflag == 1 || L[pos] == '0') && (Yflag == 1 || R[pos] == '1') && MSBflag == 1) {
        ret += solve(L, R, dp, pos - 1, Xflag, Yflag, MSBflag)
        ret %= mod
    }
    
    // Xのビットが1, Yのビットが1のパターン
    // Y条件は同様、Xのビットについては1にすると必ずLに等しいかLより真に大きくなるためDon't care
    // XとYのMSBが現れたとして、MSBflagには1を入れる
    if (Yflag == 1 || R[pos] == '1') {
        ret += solve(L, R, dp, pos - 1, if (L[pos] == '0') 1 else Xflag, Yflag, 1)
        ret %= mod
    }
    
    // Xのビットが1, Yのビットが0のパターンは繰り下がりが発生するためやらない。
    
    dp[MSBflag][Xflag][Yflag][pos] = ret
    return ret
}


Measured memory_bytes: 38000
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include <cassert>
    #include <cmath>

    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<int,int>;

    int main(){
      string s;cin>>s;
      int res = s.size();
      rep(i,res)cout<<'x';
      
    }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N; cin>>N;
  vi A(N);
  rep(i,0,N) cin>>A[i];
  sort(ALL(A));
  string ans="No";
  if(A[N-1]==0) ans="Yes";
  if(N%3==0&&A[0]==A[N/3-1]&&A[N/3]==A[N*2/3-1]&&A[N*2/3]==A[N-1]&&(A[0]^A[N/3]^A[N*2/3])==0)
    ans="Yes";
  cout<<ans<<endl;
  }


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main()
{
    int A1, A2, A3;
    cin >> A1 >> A2 >> A3;
    string ans;
    if (A1 + A2 + A3 >= 22) ans = "bust";
    else ans = "win";

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using iii = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
void cxxio() {
    ios::sync_with_stdio(false);
    cin.tie(0);
}
#define forn(i,n) for (int i=0; i<int(n); ++i)
#define pb push_back

vvi adj;
vi color;
vi dist;

void dfs(int v, int d, int c) {
    if (!color[v]) color[v]=c;
    if (dist[v]>=d) return;
    dist[v]=d;
    for (int u:adj[v])
        dfs(u, d-1, c);
}

int main() {
    cxxio();
    int n, m;
    cin>>n>>m;
    adj.resize(n);
    color.resize(n);
    dist.resize(n);
    while (m--) {
        int a, b;
        cin>>a>>b;
        a--, b--;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    int q;
    cin>>q;
    vector<iii> qs;
    forn(i, q) {
        int v, d, c;
        cin>>v>>d>>c;
        v--;
        qs.pb(iii(v, d, c));
    }
    while (!qs.empty()) {
        int v, d, c;
        tie(v, d, c)=qs.back();
        qs.pop_back();
        dfs(v, d, c);
    }
    for (int c:color)
        cout<<c<<'\n';
}


Measured memory_bytes: 8820