akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long 
using namespace std;
const int somod = 1e9 + 7;
const int maxn = 2e3 + 7;

int n, m, a[maxn], dp[maxn][maxn], ans;

void Maximize(int &a, int b)
{
    if(a < b) a = b;
    ans = max(ans, a);
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin);
    cin >> n;
    vector<pair<int, int>> vt;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
        vt.emplace_back(a[i], i);
    }
    sort(vt.rbegin(), vt.rend());
    for(int i = 0; i < n; i++)
    {
        for(int le = 0; le <= i + 1; le++)
        {
            int ri = i + 1 - le;
            int curri = n - ri + 1;
            if(le)
            {
                Maximize(dp[le][ri], dp[le - 1][ri] + vt[i].first * abs(vt[i].second - le));
            }
            if(ri)
            {
                Maximize(dp[le][ri], dp[le][ri - 1] + vt[i].first * abs(vt[i].second - curri));
            }
        }
    }
    cout << ans << '\n';
}

Measured memory_bytes: 26380
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        int x = in.nextInt();
        int y = in.nextInt();

        String a = "";
        for (int i = 0; i < x; i++) {
            a = a + "" + y;
        }
        String b = "";
        for (int i = 0; i < y; i++) {

            b = b + "" + x;

        }

        String[] s = {a, b};
        Arrays.sort(s);
        System.out.println(s[0]);


    }

}


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

int main() {
	ll l, r;
	cin >> l >> r;
	if(l%2019 == 0)
	{
		cout << 0;
		return 0;
	}
	ll t1 = l + (2019-(l%2019));
	if(t1 <= r)
	{
		cout << 0;
		return 0;
	}
	ll t2 = r - (r%2019);
	if(t2 >= l)
	{
		cout << 0;
		return 0 ;
	}
	ll ans = 2019;
	for(ll i = l; i < r; i++)
	{
		for(ll j = i+1; j < r+1; j++)
		{
			ans = min(ans,  ( (i*j)%2019 ));
		}
	}
	cout << ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 384
def main():
    n, x, y = map(int, input().split())
    ans = [0] * (n+1)
    d = list()
    for i in range(1, n):
        for j in range(i+1, n+1):
            # x->yを通らない
            d1 = abs(j-i)
            # i->x->y->jの順 +1はx->yの分
            d2 = abs(x-i) + 1 + abs(j-y) 
            # i->y->x->jの順 +1はy->xの分
            d3 = abs(y-i) + 1 + abs(j-x)
            dist = min(min(d1, d2), d3)
            d.append(dist)
            ans[dist] += 1
    print(*ans[1:n], sep='\n')

if __name__ == '__main__':
    main()

Measured memory_bytes: 73036
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
     
  cin>>a>>b;
     
  int ans=b-a;
  int ans1=1;
     
 
  for(int i=2;i<=999;i++){
    ans1+=i;
    
    if(ans==(ans1-(ans1-i))&&ans1-b){
      cout<<ans1-b<<endl;
      break;
    }
  }
   
  return 0;
     
}


Measured memory_bytes: 256
#include<stdio.h>

int main(viod)
{
	int a,b,c,t;
	scanf("%d %d %d",&a,&b,&c);
	if(a > b){
		t = a;
		a = b;
		b = t;	
	}
	if(b > c){
		t = b;
		b = c;
		c = t;
	}
	if(a > b){
		t = a;
		a = b;
		b = t;
	}
	printf("%d %d %d\n",a,b,c);
	return 0;
 }


Measured memory_bytes: 2140
#include <stdio.h>
#include <limits.h>

#define TEST_MODE 0

int main(void) {
#if TEST_MODE
	long long  a,b;
	while(scanf("%lld%lld",&a,&b)==2) {
		if(a+b>=(long long)INT_MAX || a+b<(long long)INT_MIN)return 1;
		printf("%lld\n",a+b);
	}
#else
	int a,b;
	while(scanf("%d%d",&a,&b)==2) {
		printf("%d\n",a+b);
	}
#endif
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define int long long
int MAX=1000000007;



signed main() {
 int n,sa,sb,ga,gb,ba,bb;
 cin>>n>>ga>>sa>>ba>>gb>>sb>>bb;

 int ans[n+1];
 ans[0]=0;
 for(int i=1;i<=n;i++){
     ans[i]=ans[i-1]+1;
     if(i-ga>=0&&(ga<gb))ans[i]=max(ans[i-ga]+gb,ans[i]);
     if(i-sa>=0&&(sa<sb))ans[i]=max(ans[i-sa]+sb,ans[i]);
     if(i-ba>=0&&(ba<bb))ans[i]=max(ans[i-ba]+bb,ans[i]);
 }
 int ans2[ans[n]+1];
 ans2[0]=0;
 for(int i=1;i<=ans[n];i++){
     ans2[i]=ans2[i-1]+1;
     if(i-gb>=0&&(ga>=gb))ans2[i]=max(ans2[i-gb]+ga,ans2[i]);
     if(i-sb>=0&&(sa>=sb))ans2[i]=max(ans2[i-sb]+sa,ans2[i]);
     if(i-bb>=0&&(ba>=bb))ans2[i]=max(ans2[i-bb]+ba,ans2[i]);
 }
cout<<ans2[ans[n]];

 
   

      return 0;

}


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

void solve(){
   int A,B,C,d;
   cin>>A>>B>>C>>d;
    if(abs(A-C)<=d){cout<<"Yes"<<endl;}
    else if((abs(A-B)<=d)&&(abs(C-B)<=d)){cout<<"Yes"<<endl;}
    else{ cout<<"No"<<endl;}
}

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

Measured memory_bytes: 384
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(in);
String x=sc.next();
String y=sc.next();
String g1="1 3 5 7 8 10 12";
String g2="4 6 9 11";
if(x.equals("2")||y.equals("2")){
    out.println("No");
}else if((g1.contains(x)&&g1.contains(y))||(g2.contains(x)&&g2.contains(y))){
    out.println("Yes");
}else{out.println("No");}
}
}

Measured memory_bytes: 21844
import java.util.*;

/**
 * Created by Santa.
 */
public class Main {

    static long N;
    static int M;
    static int A;
    static long B;
    static long C;
//    static int[][] map;
    static int min = 9999999;


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        N = scanner.nextLong();
        int i = 1;
        if(N < 0){
            i = 0;
            N *= -1;
        }
        boolean ok = false;
        while(true){
            if(ok)break;
//            System.out.println(N + " = " + i);
            if(i > 40)break;

            if(N >> i == 0)break;
            if(((N >> i) % 2) == 1){
                N += (long)1 << (i + 1);
            }
            i += 2;
        }


        System.out.println(Long.toBinaryString(N));

    }




}



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

// judge possibility: all logs are cut into less tha Lmax within K steps
bool OK_cut_less_than( int Lmax, int K, vector<int> &a ){
    int count =0;
    for( int l : a ){
        // cut of a log s.t. max length is minimum => equal division
        count += (l-1)/Lmax; 
        // (l-1)/Lmax = number of cutting points
        // if l=Lmax: not need to cut => l-1
    }
    return count <=K;
}
    
int bisec_min( int &small, int &large, int K, vector<int> &a ){
    if( large - small <= 1 ){
        // find min Lmax
        return large;
    }
    // output should be rounded up (take large)
    int middle = ( small + large  )/2;
    if( OK_cut_less_than( middle, K, a ) ){
        // search Lmax<middle 
        return bisec_min( small, middle, K, a );
    }else{
        // search Lmax > middle
        return bisec_min( middle, large, K, a );
    };
}

int main(){
    // input
    int N,K;
    cin >> N >> K;
    vector<int> a(N);
    rep(i,N) cin >> a[i];
    //bisectial minimization
    int small = 0;
    int large = *max_element( a.begin(), a.end() );
    int Lopt = bisec_min( small, large, K, a );
    //output
    cout << Lopt << endl;
    return 0;
}


Measured memory_bytes: 3996
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;

ll gcd(ll a, ll b){
    while(b){
        ll t = a / b;
        a -= t * b; swap(a, b);
    }
    return a;
}

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


int main(){
    int n;
    cin >> n;
    ll ans = 1;
    for (int i = 1; i <= n; i++){
        ll t;
        cin >> t;
        ans = lcm(ans, t);
    }

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

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 300005;

/* ...o(^-^)o... */

int n;
vector<int> b;
vector<bool> removed;
vector<int> ans;

bool dfs(int m){
    int j = -1;
    rep(i, n){
        if(removed[i]) continue;
        j++; if(b[i] > j) return false;
    }
    if(m == 1){
        ans.push_back(0);
        return true;
    }

    j = -1;
    rep(i, n){
        if(removed[i]) continue;
        j++; if(b[i] != j) continue;
        removed[i] = true;
        if(dfs(m - 1)){
            ans.push_back(i);
            return true;
        }
        removed[i] = false;
    }
    return false;
}

int main(){
    cin >> n;
    b = vector<int>(n);
    rep(i, n){
        cin >> b[i]; b[i]--;
    }
    removed = vector<bool>(n, false);
    if(!dfs(n)){
        out(-1); return 0;
    }
    rep(i, n) out(b[ans[i]]+1);
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;
int main() {
    int H, W; scanf("%d %d", &H, &W);
    char x[W], a[W];
    for(int i = 0; i < W+2; i++) x[i] = '#';
    printf("%s\n", x);
    for(int i = 0; i < H; i++) {
        scanf("%s", a);
        printf("#%s#\n", a);
    }
    printf("%s\n", x);
}

Measured memory_bytes: 128
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
lint n;
lint x0;
lint rec(lint x,lint y){
  lint L=min({n-x-y,x,n-x0-y});
  dump(x);dump(y);dump(x+y);
  if(y==n-x0 || x==0) return 0;
  lint res=0;
  if(L==x){
    prl;
    lint dif=n-x-y-x;
    lint rep=max(1ll,dif/L);
    dump(rep);
    dump(n-x0-y);
    chmin(rep,(n-x0-y)/L);
    dump(rep);
    res+=L*3*rep;
    res+=rec(x,y+L*rep);
  }else{
    lint dif=x-(n-x-y);
    lint rep=max(1ll,dif/L);
    dump(rep);
    chmin(rep,x/L);
    dump(rep);
    res+=L*3*rep;
    res+=rec(x-L*rep,y);
  }
  return res;
}
int main(){
  cin>>n>>x0;

  lint res=rec(x0,0);
  cout<<res<<endl;
  return 0;
}




Measured memory_bytes: 256
import kotlin.math.*
import java.util.*

const val MOD = 1_000_000_007L

fun readI() = readLine()!!.toInt()
fun readL() = readLine()!!.toLong()
fun readD() = readLine()!!.toDouble()
fun readIs() = readLine()!!.split(' ').map(String::toInt)
fun readLs() = readLine()!!.split(' ').map(String::toLong)
fun readDs() = readLine()!!.split(' ').map(String::toDouble)

data class Seq(val c: Char, var n: Int)

fun finish(seq: List<Seq>, start: Int, end: Int): Boolean {
  return end - start == 1 && (
    (seq[start].c == 'R' && seq[end].c == 'W') ||
    (seq[start].c == 'R' && seq[end].c == 'R') ||
    (seq[start].c == 'W' && seq[end].c == 'W')
  )
}

fun main(args: Array<String>) {
  val n = readI()
  val s = readLine()!!
  val list = mutableListOf<Seq>()
  var i = 0
  while (i < n) {
    val j = i
    while (i + 1 < n && s[i] == s[i + 1]) i++
    list += Seq(s[j], i - j + 1)
    i++
  }
  var ans = 0
  var start = 0
  var end = list.size - 1
  do {
    while (start < end && list[start].c == 'R') start++
    while (start < end && list[end].c == 'W') end--
    if (end <= start) break

    val a = list[start]
    val b = list[end]
    if (a.n == b.n) {
      ans += a.n
      start++
      end--
    } else if (a.n < b.n) {
      ans += a.n
      start++
      b.n -= a.n
    } else {
      ans += b.n
      end--
      a.n -= b.n
    }
  } while (!finish(list, start, end))
  println(ans)
}


Measured memory_bytes: 43088
/**
 * Author  : dhakad_123
 * Created : 23.08.2020
 **/

#include<bits/stdc++.h>
using namespace std;



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


	int N , X , T;

	cin >> N >> X >> T;

	bool Ok = true;

	int ans = T;
	int res = X;

	while(res < N){
		ans += T;
		res += X;
	}

	
	cout << ans << endl;



       return 0;

}


Measured memory_bytes: 3636
def main():
    from fractions import gcd
    from functools import reduce
    mod=1000000000+7
    n=int(input())
    a=[int(i) for i in input().split()]
    l=reduce(lambda x,y:x//gcd(x,y)*y,a)
    ans=sum(map(lambda x:l//x,a))
    print(ans%mod)
main()


Measured memory_bytes: 6100
q,h,s,d=map(int,input().split())
n=int(input())

l=min(q*n*4,h*n*2,s*n,d*n//2)
if l != d*n//2:
    print(l)
else:
    m=min(q*4,h*2,s)
    print(d*(n//2)+m if n % 2 == 1 else l)


Measured memory_bytes: 2940
n,a,b = map(int,input().split())
sl = list(input())

naka = 0
soto = 0

for s in sl:
    if s == "c":
        print("No")
    if s == "a":
        if naka + soto < a + b:
            print("Yes")
            naka += 1
        else:
            print("No")
    if s == "b":
        if naka + soto < a + b and soto < b:
            print("Yes")
            soto += 1
        else:
            print("No")



Measured memory_bytes: 4712
#include<cstdio>
using namespace std;
#define N 1000006
#define max(a,b) (a>b?a:b)
#define rep(i,j,k) for(i=j;i<=k;++i)
#define down(i,j,k) for(i=j;i>=k;--i)
int n,i,j,k,ans,col,left,head,tail,delta;
int lst[N][26],s[N],t[N],q[N];
char ch;
void read(int &p){
	p=0; char x=getchar();
	while(x<'0' || x>'9') x=getchar();
	while(x>='0'&&x<='9'){p=p*10+x-'0'; x=getchar();}
}
void read(char &p){
	p=getchar();
	while(p<'a' || p>'z') p=getchar();
}
int main(){
//	freopen("in.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	read(n);
	rep(i,1,n){ read(ch); s[i]=ch-'a'; }
	rep(i,1,n){ read(ch); t[i]=ch-'a'; }
	rep(i,1,n){
		rep(j,0,25) lst[i][j]=lst[i-1][j];
		lst[i][s[i]]=i;
	}
	ans=0; left=n+1; head=1; tail=0;
	down(i,n,1){
		bool flag=false;
		if(i>=left){
			if(t[i]!=col){
				if(lst[left-1][t[i]]){
					col=t[i]; left=lst[left-1][t[i]];
					flag=true;
				}else{
					puts("-1");
					return 0;
				}
			}
		}else{
			if(s[i]!=t[i]){
				if(lst[i][t[i]]){
					col=t[i]; left=lst[i][t[i]];
					flag=true;
				}else{
					puts("-1");
					return 0;
				}
			}
		}
		if(flag){
			while((head<=tail)&&(q[head]-delta>i)) head++;
			delta++; tail++; q[tail]=left+delta;
		}
		ans=max(ans,tail-head+1);
	}
	printf("%d\n",ans);
//	read(k);
//	if(ans>k) printf("NO!!!");
//	else printf("Yes.");
	return 0;
}

Measured memory_bytes: 113408
#include <bits/stdc++.h>
#include <algorithm> 
#include <cstdlib>
#include <bitset>
#include <math.h>
#include <numeric>
#include <set>
#include <vector>
#define ll long long
#define pf printf
#define sf scanf
using namespace std;
int main(){
 //freopen("input.txt","r",stdin);
 //freopen("output.txt","w",stdout);
  int n,i;
  string s,t,k;
  k="";
  cin>>n>>s>>t;
  for(i=0;i<n;i++){
    k+=s[i];
    k+=t[i];
  }
  cout<<k;
  





  
  


  
 
 
 
    
 
return 0;
}

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

#define int long long
const int INF = (1LL << 31) - 1;
const int MAX = 1<<9;
struct LazySegmentTree {
  int N, K;
  vector<int> D;
  vector<bool> lazyFlag;
  vector<int> lazy;
  LazySegmentTree(int n) : N(n) {
    K = (N + MAX - 1) / MAX;
    D.assign(K * MAX, INF);
    lazyFlag.assign(K, false);
    lazy.assign(K, 0);
  }
  void eval(int k) {
    if (lazyFlag[k]) {
      lazyFlag[k] = false;
      for (int i = k * MAX; i < (k + 1) * MAX; ++i) {
        D[i] = lazy[k];
      }
    }
  }

  void update(int s, int t, int x) {
    for (int k = 0; k < K; ++k) {
      int l = k * MAX, r = (k + 1) * MAX;
      if (r <= s || t <= l)
        continue;
      if (s <= l && r <= t) {
        lazyFlag[k] = true;
        lazy[k] = x;
      } else {
        eval(k);
        for (int i = max(s, l); i < min(t, r); ++i) {
          D[i] = x;
        }
      }
    }
  }
  int find(int i) {
    int k = i / MAX;
    eval(k);
    return D[i];
  }
};

signed main() {
  int p, q;
  cin >> p >> q;
  LazySegmentTree segtree(p);
  for(int i=0; i<q; i++)  {
    int com;
    cin >> com;
    if (com == 0) {
      int s, t, x;
      cin >> s >> t >> x;
      segtree.update(s, t + 1, x);
    } else {
      int i;
      cin >> i;
      cout << segtree.find(i) << endl;
    }
  }
}



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

class dice {
private :
    map<string, int> face_num;
public :
    dice() {}
    dice(map<string, int> &face_num) {
        this->face_num = face_num;
    }

    void roll(const char &direction) {
        if (direction == 'E') {
            swap(face_num["top"], face_num["left"]);
            swap(face_num["right"], face_num["left"]);
            swap(face_num["bottom"], face_num["left"]);
        }
        else if (direction == 'N') {
            swap(face_num["front"], face_num["bottom"]);
            swap(face_num["top"], face_num["bottom"]);
            swap(face_num["back"], face_num["bottom"]);
        }
        else if (direction == 'S') {
            swap(face_num["top"], face_num["back"]);
            swap(face_num["front"], face_num["back"]);
            swap(face_num["bottom"], face_num["back"]);
        }
        else if (direction == 'W') {
            swap(face_num["top"], face_num["right"]);
            swap(face_num["left"], face_num["right"]);
            swap(face_num["bottom"], face_num["right"]);
        }
        else
            cout << "plz input direction" << '\n';
    }

    void rotate() {
        int front_num = face_num["front"];
        face_num["front"] = face_num["left"];
        face_num["left"] = face_num["back"];
        face_num["back"] = face_num["right"];
        face_num["right"] = front_num;
    }

    dice new_rolled_dice(const char &direction) {
        dice d = *this;
        d.roll(direction);
        return d;
    }
    dice new_fliped_dice() {
        dice d = *this;
        d.roll('W');
        d.roll('W');
        return d;
    }
    
    int position_num(const string &position) {
        return face_num[position];
    }

    void show() {
        cout << face_num["top"] << face_num["front"] << face_num["right"] << face_num["left"] << face_num["back"] << face_num["bottom"] << '\n';
    }
};

int main()
{
    map<string, int> num;
    cin >> num["top"] >> num["front"] >> num["right"] >> num["left"] >> num["back"] >> num["bottom"];
    int q;
    cin >> q;

    // for (auto x : num) {
    //     cout << x.first << " " << x.second << '\n';
    // }
    
    dice d = dice(num);

    vector<dice> dices(6);
    string dir = "ENSW";
    for(int i = 0; i < dices.size(); i++) {
        if (i == 0)
            dices[0] = d;
        else if (i == 5)
            dices[5] = d.new_fliped_dice();
        else
            dices[i] = d.new_rolled_dice(dir[i - 1]);
            // cout << dir[i - 1] << '\n';

    }
    int t, f;

    for(int x = 0; x < q; x++) {
        cin >> t >> f;
        for(int i = 0; i < dices.size(); i++) {
            for(int j = 0; j < 4; j++) {
                if (dices[i].position_num("top") == t && dices[i].position_num("front") == f) {
                    cout << dices[i].position_num("right") << '\n';
                    break;
                }
                    dices[i].rotate();
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3244
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
int main()
{
    ll n,k;
    scanf("%lld%lld",&n,&k);
    ll i,ans=0;
    if(k == 0)
        ans = n*n;
    else
        for(i=k+1;i<=n;i++)
        {
            ans += (i-k)*(n/i);
            ll b = (n/i)*i+k;
            if(n >= b)
                ans += n-b+1;
        }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define read() Read<int>()
namespace pb_ds{   
    namespace io{
        const int MaxBuff=1<<15;
        const int Output=1<<23;
        char B[MaxBuff],*S=B,*T=B;
		#define getc() ((S==T)&&(T=(S=B)+fread(B,1,MaxBuff,stdin),S==T)?0:*S++)
        char Out[Output],*iter=Out;
        inline void flush(){
            fwrite(Out,1,iter-Out,stdout);
            iter=Out;
        }
    }
    template<class Type> inline Type Read(){
        using namespace io;
        register char ch;
        register Type ans=0; 
        register bool neg=0;
        while(ch=getc(),(ch<'0' || ch>'9') && ch!='-');
        ch=='-'?neg=1:ans=ch-'0';
        while(ch=getc(),'0'<= ch && ch<='9') ans=ans*10+ch-'0';
        return neg?-ans:ans;
    }
    template<class Type> inline void Print(register Type x,register char ch='\n'){
        using namespace io;
        if(!x) *iter++='0';
        else{
            if(x<0) *iter++='-',x=-x;
            static int s[100]; 
            register int t=0;
            while(x) s[++t]=x%10,x/=10;
            while(t) *iter++='0'+s[t--];
        }
        *iter++=ch;
    }
}
using namespace pb_ds;
using namespace std;
typedef long long ll;
const int N=55;
const int M=2e5+5;
int n,m,sum,ans,X,D;
int fa[N],dp[M];
struct node{
	int val,w,d;
	inline bool operator < (const node &u)const{
		return 1ll*val*u.w>1ll*w*u.val;
	}
}a[N];
int main(){
	//freopen("alchemy.in","r",stdin);
	//freopen("alchemy.out","w",stdout);
	n=read(),X=read(),D=read(),m=min(D,n);
	for (int i=1;i<=n;++i){
		a[i].w=min(X+1,read());
		a[i].val=1,a[i].d=D-m;
		if (i^1) fa[i]=read();
	}
	for (int i=n;i>1;--i){
		a[fa[i]].w=min(a[fa[i]].w+a[i].w,X+1);
		a[fa[i]].val+=a[i].val,sum+=a[i].val*m;
	}
	sum+=a[1].val*n,a[1].d=max(0,(X/a[1].w)-n);
	for (int i=1;i<=sum;++i) dp[i]=X+1;
	for (int i=1;i<=n;++i)
		for (int j=1;j<=((i==1)?n:m);++j)
			for (int k=sum;k>=a[i].val;--k)
				dp[k]=min(dp[k],dp[k-a[i].val]+a[i].w);

	sort(a+1,a+n+1);
	for (int i=0;i<=sum;++i){
		if (dp[i]>X) continue;
		int now=X-dp[i],res=i;
		for (int j=1;j<=n;++j){
			if (now>=1ll*a[j].w*a[j].d) now-=a[j].w*a[j].d,res+=a[j].d*a[j].val;
			else res+=(now/a[j].w)*a[j].val,now%=a[j].w;
		}
		ans=max(ans,res);
	}
	printf("%d\n",ans);
	return 0;
}

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

using i64 = int_fast64_t;
using f64 = double;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    string s;
    cin >> s;
    cout << (s == "ABC" ? "ARC" : "ABC") << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


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

const int N = 200010;

int n, a, b;
bool vis[N];

std::vector <int> get(int bit){
    if (bit == 0){
        return {0};
    }
    std::vector <int> vec = get(bit - 1);
    for (int i = (1 << (bit - 1)) - 1; i >= 0; -- i){
        vec.push_back(1 << (bit - 1) | vec[i]);
    }
    return vec;
}

std::vector <int> solve(int bit, bool flag){
    std::vector <int> vec;
    for (int i = 0; i < n; ++ i){
        if (vis[i]){
            vec.push_back(i);
        }
    }
    std::vector <int> vec1 = get(vec.size());
    std::vector <int> vec2;
    for (auto u : vec1){
        int x = 0;
        for (int i = 0; i < vec.size(); ++ i){
            if (u >> i & 1){
                x |= 1 << vec[i];
            }
        }
        if (flag){
            x |= 1 << bit;
        }
        for (int i = 0; i < n; ++ i){
            if (!vis[i]){
                x |= (a >> i & 1) << i;
            }
        }
        vec2.push_back(x);
    }
    return vec2;
}

int main(){
    scanf("%d%d%d", &n, &a, &b);
    if ((__builtin_popcount(a) - __builtin_popcount(b)) % 2 == 0){
        puts("NO");
        return 0;
    }
    puts("YES");
    for (int i = 0; i < n; ++ i){
        vis[i] = true;
    }
    for (int i = 0; i < n - 1; ++ i){
        for (int j = 0; j < n; ++ j){
            if ((a ^ b) >> j & 1){
                vis[j] = false;
                std::vector <int> vec = solve(j, a >> j & 1);
                for (int i = 0; i < vec.size(); ++ i){
                    if (vec[i] == a){
                        std::rotate(vec.begin(), vec.begin() + i, vec.end());
                        break;
                    }
                }
                for (int i = 0; i < vec.size(); ++ i){
                    printf("%d ", vec[i]);
                }
                a = vec.back() ^ 1 << j;
                break;
            }
        }
    }
    printf("%d %d\n", a, b);
    return 0;
}

Measured memory_bytes: 1396
#ifndef ONPC
  #define _FORTIFY_SOURCE 0
  #pragma GCC optimize("Ofast")
  #pragma GCC optimize("no-stack-protector")
  #pragma GCC optimize("unroll-loops")
  #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
  #pragma GCC optimize("fast-math")
#endif

#include <bits/stdc++.h>

#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#endif


const int MAXN = 100;
//#define int long long
const int INF = 1e9;

signed main()
{
    #ifdef FILEIO
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif

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

    int n, k, c;
    cin >> n >> k >> c;
    string s;
    cin >> s;

    vector<int> ans1, ans2;

    for (int i = 0; i < n; i++){
      if ((int)ans1.size() >= k) break;
      if (s[i] == 'o' && (!ans1.size() || ans1.back() + c < i)) ans1.eb(i);
    }

    for (int i = n-1; i > -1; i--){
      if ((int)ans2.size() >= k) break;
      if (s[i] == 'o' && (!ans2.size() || ans2.back() - c > i)) ans2.eb(i);
    }

    reverse(ans2.begin(), ans2.end());

    for (int i =0; i < k; i++){
      if (ans1[i] == ans2[i]) cout << ans1[i] + 1 << '\n';
    }

    return 0;
}


Measured memory_bytes: 3468
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

  ll n, m, c;
  cin >> n >> m >> c;

  vll b(m);
  REP(i, m) cin >> b[i];
  vvll a(n, vll(m));
  ll s, ans = 0;
  REP(i, n){
    s = 0;
    REP(j, m){
      cin >> a[i][j];
      s += a[i][j] * b[j];
    }
    if(s + c > 0) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD =  998244353;

  
     signed main(){
     int n,m;
     cin>>n>>m;
     vector<int> hen[n];int a,b;
     for(int i=0;i<m;i++){
          cin>>a>>b;a--;b--;
          hen[a].push_back(b);
          hen[b].push_back(a);
     }
     int ans[n];bool used[n]={};
     fill(ans,ans+n,MOD);
     queue<int>que;
     que.push(0);
     used[0]=true;
     while(!que.empty()){
         int p=que.front();
         que.pop();
         
         
         
          for(auto&& i :hen[p])if(!used[i]){
               ans[i]=p;
               used[i]=true;
               que.push(i);
          }
     }
     cout<<"Yes"<<endl;
     for(int i=1;i<n;i++)cout<<ans[i]+1<<endl;

      }

        

Measured memory_bytes: 13164
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=1e5+5;
char s[N];int fa[N],b[N],sum[N],vis[N],n,m;
inline int val(R int x){return x<0?x+26:x;}
inline int find(R int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
int main(){
	scanf("%s",s+1),n=strlen(s+1);
	fp(i,1,n+1)s[i]-='a',fa[i]=i;
	s[n+1]=0;
	scanf("%d",&m);
	for(R int i=1,l,r;i<=m;++i)scanf("%d%d",&l,&r),fa[find(r+1)]=find(l);
	fp(i,1,n+1)b[i]=val(s[i]-s[i-1]);
	fp(i,1,(n+1)>>1)fa[find(n+2-i)]=find(i);
	fp(i,1,n+1)sum[find(i)]+=b[i];
	if((n+1)&1)vis[find((n+2)>>1)]=1;
	fp(i,1,n+1)if(i==find(i)&&sum[i]%26)
		if(!vis[i])return puts("NO"),0;
	puts("YES");
	return 0;
} 

Measured memory_bytes: 1280
using System.Linq;
using System;

public class Hello
{
	public static void Main()
	{
		string[] line = Console.ReadLine().Trim().Split(' ');
		var k = int.Parse(line[0]);
		var x = int.Parse(line[1]);
		Console.WriteLine(string.Join(" ", Enumerable.Range(x - k + 1, 2 * k - 1)));
	}
}

Measured memory_bytes: 11220
"use strict"
function Main(stdin){
stdin = stdin.trim().split("\n").reverse();
let stdout = [];
function input(){return stdin.pop()};
function print(x){stdout.push(x)};
function max(list){return list.reduce(function(a,b){ return Math.max(a,b) }) }
function min(list){return list.reduce(function(a,b){ return Math.min(a,b) }) }
function sum(list){return list.reduce(function(a,b){ return a+b }) }
function sortex(list, index){list.sort((a, b) => a[index] - b[index])}
function all(list){return list.reduce(function(a,b){ return a && b }) }
function any(list){return list.reduce(function(a,b){ return a || b }) }
/*START*/


let tmp = Array.from(input().split(" "), i => parseInt(i))
let a = tmp[0]
let b = tmp[1]
if (a === 1 || b === 1){
    print(1)
}else{
    print(Math.floor((a*b + 1)/2))
}



/*END*/
console.log(stdout.join("\n"));
return stdout
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"))

Measured memory_bytes: 9420
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=2e5+1e3+7;

char s[N];

int n,f[(1<<26)],g[N];

int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1;i<=n;i++)
		g[i]=g[i-1]^(1<<(s[i]-'a')); 
	memset(f,0x3f,sizeof(f));
	f[0]=0;
	for(int i=1;i<=n;i++)
	{
//		f[g[i]]=f[g[i]]+1;
		for(int j=0;j<26;j++)
			f[g[i]]=min(f[g[i]],f[g[i]^(1<<j)]+1);
	}
	cout<<max(f[g[n]],1);
}

Measured memory_bytes: 263424
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
static const ll max_n = 2010;
static const ll max_dist = 10000000;
vector<vector<ll>> distance_table(max_n, vector<ll>(max_n, max_dist));
vector<ll> distance_list(max_n);

ll N, X, Y;

void dijkstra(ll st){
    priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> PQ;
    PQ.push(make_pair(0, st));
    fill(distance_list.begin(), distance_list.begin()+N, max_dist);

    while (!PQ.empty()){
        pair<ll, ll> u = PQ.top(); PQ.pop();
        if(u.first > distance_list[u.second]){
            continue;
        }
        distance_list[u.second] = u.first;

        if(u.second > 0 && distance_list[u.second-1]>u.first+1){
            distance_list[u.second-1] = u.first + 1;
            PQ.push(make_pair(u.first + 1, u.second-1));
        }

        if(u.second+1 < N && distance_list[u.second+1]>u.first+1){
            distance_list[u.second+1] = u.first + 1;
            PQ.push(make_pair(u.first + 1, u.second+1));
        }

        if(u.second == X && distance_list[Y]>u.first+1){
            distance_list[Y] = u.first + 1;
            PQ.push(make_pair(u.first + 1, Y));
        }

        if(u.second == Y && distance_list[X] > u.first + 1){
            distance_list[X] = u.first + 1;
            PQ.push(make_pair(u.first + 1, X));
        }

    }

    for(ll i=0;i<N;i++){
        distance_table[st][i] = distance_list[i];
    }

}

int main(){
    // int u, v;
    // bool updated = false;
    scanf("%lld %lld %lld", &N, &X, &Y);
    vector<ll> distance_result(N, 0);

    // distance_list.resize(N);
    X = X - 1;
    Y = Y - 1;
    
    for(ll i=0;i<N;i++){
        // printf("dfs i = %lld\n", i);
        dijkstra(i);
    }
    // printf("dfs finish!\n");
    for(ll i=0;i<N;i++){
        for(ll j=i+1;j<N;j++){
            // printf("distance[%lld][%lld] = %lld\n", i, j, distance_table[i][j]);
            distance_result[distance_table[i][j]] ++;
        }
    }

    ll idx = 0;
    for(ll i=1;i<N;i++){
        printf("%lld\n", distance_result[i]);
    }
    return 0;

}

Measured memory_bytes: 31872
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)

using ll = long long;
using namespace std;

int main() {
    int n;
    cin >> n;
    int cnt = 0;

    rep1(i,n) {
        if(i - 10 < 0) {
            ++cnt;
            continue;
        }
        if(100 <= i && i < 1000) {
            ++cnt;
        }
        else if(10000<= i && i < 100000){
            ++cnt;
        }

    }
    cout << cnt;


    
}

Measured memory_bytes: 256
import sys

S = input()

DEVIDER = 10**9 + 7


def add(a, b):
    return (a + b) % DEVIDER

def mul(a, b):
    return (a % DEVIDER) * (b % DEVIDER) % DEVIDER

cache = [[0 for _ in range(4)] for _ in range(len(S) + 1)]
cache[0][0] = 1


def check(s, j):
    if j == 0 and s == 'A':
        return True
    if j == 1 and s == 'B':
        return True
    if j == 2 and s == 'C':
        return True
    return False


for i in range(len(S)):
    for j in range(4):
        if S[i] == '?':
            cache[i + 1][j] += 3 * cache[i][j]
        else:
            cache[i + 1][j] += cache[i][j]
        if j > 0:
            if check(S[i], j-1) or S[i] == '?':
                cache[i+1][j] += cache[i][j - 1]
        cache[i+1][j] %= DEVIDER

print(cache[len(S)][3])





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

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

	LL N;
	cin >> N;
	LL ans = INT_MAX;
	for(LL i=1; i<sqrt(N)+1; i++){
		if(N % i == 0){
			ans = min(ans, (LL)max(to_string(i).size(),to_string(N/i).size()));
		}
	}
	cout << ans << endl;

	return 0;
}


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

using namespace std;

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

    int p1, px, mins[N], alturas[N];

    for(int i = 0; i <= N; i++){
        if(i < N){
            cin >> px;
            alturas[i] = px;
        }
        else {
            cout << mins[N-1];
        }
        if(i == 0){
            p1 = px; 
        }
        else if(i == 1){
            mins[1] = abs(p1 - px);
        }
        else {
            int saltos = min(K, min(N, i));
            mins[i] = 1000000000; 
            for(int j = 0; j < saltos; j++){
                if(j == i-1){
                    mins[i] = min(mins[i], abs(p1 - px));
                }
                else {
                    int ult_salto = abs(px - alturas[i-j-1]);
                    mins[i] = min(mins[i], ult_salto + mins[i-j-1]); 
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1024
use strict;
use warnings;

my (@item);
while(<>){
	chomp;
	@item = split(/ /, $_) if($. == 2);
}

@item = sort{$a <=> $b}(@item);
until($#item == 1){
	push(@item,(($item[0] + $item[1]) / 2));
	shift(@item);
	shift(@item);
	@item = sort{$a <=> $b}(@item);
}

printf (($item[0] + $item[1]) / 2) . "\n";


Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define INF 1e9
#define PI acos(-1)
typedef long long ll;

int imos[30][100010];

int main() {
	int n, cnum;
	cin >> n >> cnum;
	for (int i = 0; i < n; i++) {
		int s, t, c;
		cin >> s >> t >> c;
		s--; c--;
		imos[c][s]++;
		imos[c][t]--;
	}
	for (int j = 0; j < cnum;j++)for (int i = 1; i < 100002; i++) {
		imos[j][i] += imos[j][i - 1];
	}
	for (int j = 0; j < cnum; j++)for (int i = 1; i < 100002; i++) {
		if (imos[j][i])imos[j][i] = 1;
	}

	int ans=0;
	for (int i = 0; i < 100002; i++) {
		int cnt = 0;
		for (int j = 0; j < cnum; j++) cnt += imos[j][i];
		ans = max(ans, cnt);
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 11904
#include <bits/stdc++.h>
using namespace std;
int n;
int c1,c2,c3,c4;
int main() {
   cin>>n;
   c4=n%10;
   c3=(n/10)%10;
   c2=(n/100)%10;
   c4=n/1000;
   if((c1==c2 && c2==c3)||(c2==c3 && c3==c4)){
       cout<<"Yes"<<endl;
   }
   else cout<<"No"<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N;
        public long MOD = 1000000007;

        public void Run()
        {
            N = Input.ReadInt();
            var A = Input.ReadIntArray();
            var R = new int[N];
            for (int i = 0; i < A.Length; i++)
            {
                R[A[i] - 1]++;
            }

            for (int i = 0; i < N; i++)
            {
                Console.WriteLine(R[i]);
            }
            
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

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

#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;

const int INF = 10000;

int main()
{
	int S;

	cin >> S;

	int h = S / 3600;

	int m = (S - 3600 * h) / 60;

	int s = (S - 3600 * h - 60 * m);

	cout << h << ":" << m << ":" << s << endl;
 
	return 0;

}



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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

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

const int maxn = 2005;

bitset<maxn * maxn> dp[2];
int a[maxn];

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    memset(dp, false, sizeof(dp));
    int n;
    cin >> n;
    int sum = 0;
    for(int i = 1;i <= n;i++){
        cin >> a[i];
        sum += a[i];
    }
    shuffle(a + 1, a + 1 + n, rng);
    dp[0].set(0);
    for(int i = 1;i <= n;i++){
        int cur = i & 1;
        int pre = cur ^ 1;
        dp[cur] = dp[pre] | (dp[pre] << a[i]);
    }
    for(int i = 0;i <= sum;i++){
        if(dp[n & 1].test(i)){
            if(sum - i <= i){
                cout << i << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 5612
#include "math.h"
#include<stdio.h>
#include<map>
#include<string>
#include<iostream>
#include<vector>

using namespace std;

int main(void){
    int a,b,c;


    cin>>a;
    cin>>b;
    cin>>c;

	if(a < c && a < b && c < b){
                cout<<"Yes"<<endl;
                return 0;
    }
	if(b < c && c < a && c < a){
                cout<<"Yes"<<endl;
                return 0;
    }
    
    cout<<"No"<<endl;
    return 0;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    String S = scanner.next();
    int Q = scanner.nextInt();
    StringBuilder head = new StringBuilder();
    StringBuilder tail = new StringBuilder();
    boolean reverse = false;
    for (int i = 0; i < Q; i++) {
      int T = scanner.nextInt();
      switch (T) {
        case 1:
          reverse = !reverse;
          break;
        case 2:
          int F = scanner.nextInt();
          char C = scanner.next().charAt(0);
          if (F == 1 && !reverse || F == 2 && reverse) head.append(C);
          else tail.append(C);
          break;
      }
    }
    head.reverse().append(S).append(tail.toString());
    if (reverse) System.out.println(head.reverse().toString());
    else System.out.println(head.toString());
  }
}


Measured memory_bytes: 121692
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(abs(a-c) <= d) {
    cout << "Yes" << endl;
  }
  else if(abs(a-b) <= d && abs(b-c) <= d) {
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>
#include <iomanip>
#include <tuple>

using namespace std;


int main(){
   int n,k;
   string s;
   cin>>n>>k>>s;
   s[k-1]=s[k-1]+0x20;
   cout<<s<<endl;
}

   


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long
map<pair<int,int>,int> m;
int ans;
int solve(vector<vector<int>> &mat,int day,int item){
  if(day >= mat.size()){
      return 0;
  }
  if(m.find({day,item}) != m.end())
      return m[{day,item}];
  int temp = 0;
  for(int j=0; j<3; j++){
    if(j != item)
      temp = max(temp,mat[day][item]+solve(mat,day+1,j));
  }
  return m[{day,item}] = temp;
}
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin>>n;
  vector<vector<int>> mat(n,vector<int>(3));
  for(int i=0; i<n; i++){
    for(int j=0; j<3; j++){
      cin>> mat[i][j];
    }
  }
  ans = 0;
  for(int i=0; i<3; i++){
    ans = max(ans,solve(mat,0,i));
  }
  cout<<ans;
  return 0;
}


Measured memory_bytes: 38528
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N, M;
i64 A[5050];
i64 B[5050][202];

i64 imos[5050][5050];
bool vis[5050];
int mate[5050];

void join(int p, int q)
{
	if (mate[p] == p) {
		if (mate[q] == q) {
			mate[p] = q;
			mate[q] = p;
		} else {
			mate[p] = mate[q];
			mate[mate[q]] = p;
		}
	} else {
		if (mate[q] == q) {
			mate[q] = mate[p];
			mate[mate[p]] = q;
		} else {
			mate[mate[p]] = mate[q];
			mate[mate[q]] = mate[p];
		}
	}
}

int main()
{
	scanf("%d%d", &N, &M);
	for (int i = 0; i < N - 1; ++i) scanf("%lld", A + i);
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < M; ++j) scanf("%lld", &(B[i][j]));
	}
	for (int i = 0; i < M; ++i) {
		vector<pair<i64, int> > cand;
		for (int j = 0; j < N; ++j) cand.push_back({ B[j][i], j });
		sort(cand.begin(), cand.end());

		for (int j = 0; j <= N + 1; ++j) {
			vis[j] = false;
			mate[j] = j;
		}
		for (auto p : cand) {
			int idx = p.second + 1;
			int lf = idx, rg = idx;
			vis[idx] = true;
			if (vis[idx - 1]) {
				lf = mate[idx - 1];
				join(idx - 1, idx);
			} 
			if (vis[idx + 1]) {
				rg = mate[idx + 1];
				join(idx, idx + 1);
			}
		//	printf("%d--%d, %d--%d %lld\n", lf, idx, idx, rg, p.first);
			imos[lf][idx] += p.first;
			imos[lf][rg + 1] -= p.first;
			imos[idx + 1][idx] -= p.first;
			imos[idx + 1][rg + 1] += p.first;
		}
	}
	for (int i = 0; i <= N; ++i) {
		for (int j = 1; j <= N; ++j) {
			imos[i][j] += imos[i][j - 1];
		}
	}
	for (int i = 1; i <= N; ++i) {
		for (int j = 0; j <= N; ++j) {
			imos[i][j] += imos[i - 1][j];
		}
	}
	i64 best = 0;
	for (int i = 0; i < N; ++i) {
		i64 cs = 0;
		for (int j = i; j < N; ++j) {
		//	printf("%d--%d %lld\n", i, j, imos[i + 1][j + 1]);
			best = max(best, imos[i + 1][j + 1] - cs);
			cs += A[j];
		}
	}
	printf("%lld\n", best);

	return 0;
}


Measured memory_bytes: 205668