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

vector<long long> v;
void dfs(ll x, ll num, ll st, ll cc){
	if(v.size() > 100050) return;
	if(num == 0) num += x;
	else {
		num *= 10;
		num += x;
	}
	if(cc > st) return;
	if(cc == st){
		v.push_back(num);
		return;
	}
	if(x-1 >= 0) dfs(x-1,num,st,cc+1);
	if(x+1 <= 9) dfs(x+1,num,st,cc+1);
	dfs(x,num,st,cc+1);
	return;
}

int main(){
	
	ll k; cin>>k;
	for(int i = 1; i <= 10000; i++){
		for(int j = 1; j <= 9; j++){
			dfs(j,0,i,1);
		}
	}
	sort(v.begin(),v.end());
	cout<<v[k-1]<<"\n";
}


Measured memory_bytes: 1400
#include<stdio.h>
int main(){
    int a,b,result;
    scanf("%d %d",&a,&b);
    result=a*b;
    if(a>=1 && a<=9){
        if(b>=1 && b<=9) printf("%d\n",result);
        else printf("-1\n");
    }
    else printf("-1\n");

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define forn(i,b) for(int i=0 ; i< b ;i++)
#define for1(i,b) for(int i=1 ; i<=b ;i++)
#define reps(i,a,b) for(int i=a ; i< b.length() ;i++)
typedef long long ll;
#define MOD 1000000007

using namespace std;




int main()
{
  string str ;
  cin >> str ;
  if (str[2]==str[3] && str[4]==str[5])
    cout << "Yes" ;
  else
    cout << "No" ; 


  return 0 ;
}


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

#define PI acos(-1)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
#define all(c) (c).begin(), (c).end()
#define TIMESTAMP fprintf(stderr, "Execution time: %.3lf s.\n", (double)clock()/CLOCKS_PER_SEC)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair <int, int> pii;
typedef vector <vi> vvi;
typedef vector <pii> vpii;
typedef vector<string> vs;

const int INF = 100500;
const int MAXN = 1e5 + 9;
const int MOD = 1e9 + 7;

ll n;

void input() {                  
	cin >> n;
}

ll ans[1050];

ll go(int x) { 
	int p = 2;
	while(x >= p) {
		int power = 0;
		while(x % p == 0) {
			x /= p;
			power++;
		}
		ans[p] += power;
		p++;
	}                 
}

void solve() {          
	ll res = 1;
	for(int i = 2; i <= n; i++) go(i);
	for(int i = 0; i < 1050; i++) 
		res = (res * (ans[i] + 1)) % MOD;
	cout << res << endl;
}

int main() {     
#ifdef LOCAL
	freopen("xxx.in", "r", stdin);
	freopen("xxx.out", "w", stdout);
#else
	//freopen("xxx.in", "r", stdin);
	//freopen("xxx.out", "w", stdout);
#endif	
	input();
	solve();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

long long x;

int main() {
    cin >> x;
    if(x <= 6) {
        cout << 1 << endl;
    }else {
        long long cnt = x/11;
        long long now = x - cnt*11;
        // 6-5と動かす
        if(now == 0) cout << cnt*2 << endl;
        else if(now <= 6) cout << cnt*2 + 1 << endl;
        else cout << (cnt+1)*2 << endl;
    }
}

Measured memory_bytes: 256
a=input()
b=input()
dp=[[0 for i in range(len(a)+1)] for j in range(len(b)+1)]
for i in range(1,len(b)+1):
  for j in range(1,len(a)+1):
    if a[j-1]==b[i-1]:
      dp[i][j]=dp[i-1][j-1]+1
    else:
      dp[i][j]=max(dp[i-1][j],dp[i][j-1])

res=''

j=len(a)
i=len(b)
while j>0 and i>0:
 
    if dp[i][j]==dp[i-1][j]:
        i-=1
  
    elif dp[i][j]==dp[i][j-1]:
        j-=1
    elif dp[i][j]==dp[i-1][j-1]+1:

        res+=a[j-1]
        i-=1
        j-=1
    
print(res[::-1])
        


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

int n;
int a[100000];

int main()
{
	cin >> n;

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

	int p = a[0];

	for (int i = 1; i < n; i++) {
		int q = a[i], r = p % q;

		while (r > 0) {
			p = q;
			q = r;
			r = p % q;
		}

		p = q;
	}

	cout << p << endl;

	return 0;
}

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

int main(){
  int n;
  cin >> n;
  
  vector<int>a(n);
  bool ans = false;
  for(int i=0; i<n; i++){
    cin >> a[i];
    if(a[i]%2==1) ans=true;
  }
  
  if(ans) cout << "first" << endl;
  else cout << "second" << endl;
  
  return 0;
  
  
}

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

int main() {
    int numbers[5];
    int x;
    for (int i=0; i<5; i++) {
        cin >> x;
        numbers[i] = x;
    }
    for (int i=0; i<5; i++){
        for (int j=i; j<5; j++){
            if (numbers[j] > numbers[i]){
                int temp = numbers[j];
                numbers[j] = numbers[i];
                numbers[i] = temp;
            }
        }
        cout << numbers[i];
        if (i < 4) {
            cout << ' ';
        }
    }
    cout << endl;
    return 0;
}

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

#define int long long

int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int N, A;

signed main() {
    cin >> N >> A;
    if (N % 500 <= A) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <set>
#include <map>
using namespace std;

set<int> s[200005], r[200005];
set<int> g[200005];
int grundy[200005];

int main()
{
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        int p;
        cin >> p;
        p--;
        s[p].insert(i);
        r[i].insert(p);
    }
    queue<int> que;
    for(int i = 0; i < n; i++){
        if(s[i].size() == 0){
            que.push(i);
        }
    }
    while(que.size()){
        int u = que.front();
        que.pop();
        int c = 0;
        for(auto itr = g[u].begin(); itr != g[u].end(); itr++){
            if(*itr != c) break;
            c++;
        }
        grundy[u] = c;
        for(auto itr = r[u].begin(); itr != r[u].end(); itr++){
            int v = *itr;
            g[v].insert(grundy[u]);
            s[v].erase(u);
            if(s[v].size() == 0){
                que.push(v);
            }
        }
    }
    for(int i = 0; i < n; i++){
        int c = 0;
        for(auto itr = g[i].begin(); itr != g[i].end(); itr++){
            if(*itr != c) break;
            c++;
        }
        grundy[i] = c;
    }
    int l;
    for(l = 0; l < n; l++){
        if(s[l].size()) break;
    }
    if(l == n){
        cout << "POSSIBLE" << endl;
        return 0;
    }
    que.push(l);
    bool b[200005]{0};
    while(que.size()){
        int u = que.front();
        if(b[u]){
            l = u;
            break;
        }
        b[u] = true;
        for(auto itr = s[u].begin(); itr != s[u].end(); itr++){
            int v = *itr;
            que.push(v);
        }
    }
    map<int, int> mp;
    for(int i = 0; i < n; i++) b[i] = false;
    int u = l;
    int c = -1;
    int k = 0;
    while(!b[u]){
        if(c == -1) c = grundy[u];
        if(c != grundy[u]){
            cout << "POSSIBLE" << endl;
            return 0;
        }
        b[u] = true;
        u = *s[u].begin();
        k++;
    }
    if(k % 2) cout << "IMPOSSIBLE" << endl;
    else cout << "POSSIBLE" << endl;
}


Measured memory_bytes: 47872
n = gets.chomp.to_i
s = gets.chomp.split(" ").map(&:to_i)
q = gets.chomp.to_i
t = gets.chomp.split(" ").map(&:to_i)

c = 0
t.each { |i|
	top = 0
	last = n-1

	while top<=last
		mid = (top + last) / 2
		if s[mid] == i
			c += 1
			break
		elsif s[mid] > i
			last = mid - 1
		else
			top = mid + 1
		end
	end
}
puts c

Measured memory_bytes: 18168
#include<bits/stdc++.h>
using namespace std;
typedef long long lli;
const int maxn = 5e5 + 50;
typedef pair<int, int> P;

int arr[maxn];
int a, b, c, d, e, f, g;
void solve();
int main()
{
	int t = 1;
//	cin >> t;
	for(int i=0; i<t; i++)
	{
		solve();
	}
	return 0;
}

// type below

void solve()
{
	cin >> a;
	double tmp = (double)a / 3;
	double ans = tmp * tmp * tmp;
	printf("%.10lf", ans);
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static int constraints1(int a,int b,int c){
		int result1 = 0;
		if(0 < a || a <= 10000 || 0 < b || b <= 10000 || 0 < c || c<= 10000 ){ //a,b,c????????¶??????(??????????????´???)
			result1 = 1;
		}
		else{
			result1 = 0; //?????????????????¨???
		}
		return result1;
	}
	public static int constraints2(int a,int b){
		int result2 = 0;
		if(b-a >= 0){//a<=b????????????????????¶??????
			result2 = 1;
		}
		else{
			result2 = 0; //?????????????????¨???
		}
		return result2;
	}
	public static void main(String[] args) {
		/**
		 * ?????°?????£?¨?
		 */
		int a,b,c;
		int f=0; //?????????
		int count=0;
		int len1,len2;

		/**
		 * ???????????£?¨?
		 */
		ArrayList<String> st = new ArrayList<String>();
		ArrayList<Integer> parse = new ArrayList<Integer>();
		ArrayList<Integer> bet = new ArrayList<Integer>();
		/**
		 * ??\?????¨????????????????´?
		 */
		Scanner scan = new Scanner(System.in);
		for(int i = 0; i < 3; i++){ //??\?????´??°???3???
		st.add(scan.next());
		}
		len1 = st.size(); //?????????????´???°

		/**
		 * String???int??????,int???????????????????´?
		 */
		a = Integer.parseInt(st.get(0));
		parse.add(a);
		b = Integer.parseInt(st.get(1));
		parse.add(b);
		c = Integer.parseInt(st.get(2));
		parse.add(c);
		/**
		 * ???????????????
		 */
		if(constraints1(a,b,c) == 0){
			System.out.println("a,b,c?????????1~10000??§??\?????????????????????.???????????????.");
			System.exit(0);;
		}
		if(constraints2(a,b) == 0){
			System.out.println("a,b?????????a<=b??§??\?????????????????????.???????????????.");
			System.exit(0);;
		}
		/**
		 * ????????\?¨?
		 */
		for(f = a; f <= b; f++){ //a??????b???????????°???(a???b???????????????)
			bet.add(f); //????????°???????????????int?????????????´?
		}
		len2 = bet.size();

		for(int j = 0;j < len2; ++j){
			if(c % bet.get(j) == 0){ //c????????£?????¨???????????????0???????????????????´???°
				++count;
			}
		}
		System.out.println(count);
	}

}

Measured memory_bytes: 26900
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
int main(){
    int n,m;
    cin>>n>>m;
    ll x[n][3];
    for(int i = 0; i < n; i++){
        cin>>x[i][0]>>x[i][1]>>x[i][2];
    }
    ll res;// = INT_MIN;
    for(int i = 0; i < 8; i++){
        vll v;
        for(int j = 0; j < n; j++){
            ll sum = 0;
            for(int k = 0; k <3; k++){
                if( i&(1<<k) )
                    sum += x[j][k];
                else sum -= x[j][k];
            }
            v.push_back(sum);
        }
        sort(v.begin(),v.end());
        reverse(v.begin(),v.end());
        if( i == 0){
            ll s = 0;
            for(int p = 0; p < m;p++)
                s+= v[p];
            res = s;
        }
        else{
            ll s = 0;
            for(int p = 0; p < m;p++)
                s+= v[p];
            res = max(res,s);
        }
            //res = max(res, (ll)accumulate(v.begin(),v.begin()+m,0));
    }

    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

template<int MOD>
class ModInt {
public:
    ModInt() :value(0) {}
    ModInt(long long val) :value((int)(val<0 ? MOD + val%MOD : val%MOD)) { }

    ModInt& operator+=(ModInt that) {
        value = value + that.value;
        if (value >= MOD)value -= MOD;
        return *this;
    }
    ModInt& operator-=(ModInt that) {
        value -= that.value;
        if (value<0)value += MOD;
        return *this;
    }
    ModInt& operator*=(ModInt that) {
        value = (int)((long long)value * that.value % MOD);
        return *this;
    }
    ModInt &operator/=(ModInt that) {
        return *this *= that.inverse();
    }
    ModInt operator+(ModInt that) const {
        return ModInt(*this) += that;
    }
    ModInt operator-(ModInt that) const {
        return ModInt(*this) -= that;
    }
    ModInt operator*(ModInt that) const {
        return ModInt(*this) *= that;
    }
    ModInt operator/(ModInt that) const {
        return ModInt(*this) /= that;
    }
    ModInt pow(long long k) const {
        if (value == 0)return 0;
        ModInt n = *this, res = 1;
        while (k) {
            if (k & 1)res *= n;
            n *= n;
            k >>= 1;
        }
        return res;
    }
    ModInt inverse() const {
        long long a = value, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return ModInt(u);
    }
    int toi() const { return value; }

private:
    int value;
};
typedef ModInt<1000000007> mint;
ostream& operator<<(ostream& os, const mint& x) {
    os << x.toi();
    return os;
}

int n, m;

mint sum(vll &a) {
    int L = sz(a);
    mint res;
    for (int i = 0; i < L - 1; ++i) {
        // どこが左端になるか？右端になるか
        mint l = i + 1, r = L - 1 - i;
        res += l*r*(a[i + 1] - a[i]);
    }
    return res;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    vll X(n), Y(m);
    rep(i, n)cin >> X[i];
    rep(i, m)cin >> Y[i];

    mint ans = sum(X)*sum(Y);
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#define EPS 1e-10
 
using namespace std;
typedef long long int ll;
 
double add(double a, double b){
	if(abs(a+b)<EPS*(abs(a)+abs(b))) return 0;
	return a+b;
}
 
struct P{
	double x, y;
	P() {}
	P(double x, double y): x(x), y(y){
	}
	P operator+ (P p){
		return P(add(x, p.x), add(y, p.y));
	}
	P operator- (P p){
		return P(add(x, -p.x), add(y, -p.y));
	}
	P operator* (double d){
		return P(x*d, y*d);
	}
	double dot(P p){
		return add(x*p.x, y*p.y);
	}
	double det(P p){
		return add(x*p.y, -y*p.x);
	}
};

int main()
{
	while(1){
      int n;
      scanf("%d", &n);
      if(n==0) return 0;
      P p[300];
      for(int i=0; i<n; i++){
        double x, y;
        scanf("%lf %lf", &x, &y);
        p[i]=P(x, y);
      }
      
      int ans=1;
      for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
          double d=sqrt((p[i]-p[j]).dot(p[i]-p[j]));
          if(d>2.0) continue;
          P q;
          q.x=-(p[i]-p[j]).y;
          q.y=(p[i]-p[j]).x;
          double t=sqrt((1-((p[i]-p[j]).dot(p[i]-p[j]))/4.0)/(q.dot(q)));
          P r1=(p[i]+p[j])*0.5+q*t;
          P r2=(p[i]+p[j])*0.5-q*t;
          int c=2;
          for(int k=0; k<n; k++){
            if(k==i || k==j) continue;
            if(sqrt((p[k]-r1).dot(p[k]-r1))<1.0) c++;
          }
          if(ans<c) ans=c;
          c=2;
          for(int k=0; k<n; k++){
            if(k==i || k==j) continue;
            if(sqrt((p[k]-r2).dot(p[k]-r2))<1.0) c++;
          }
          if(ans<c) ans=c;
        }
      }
      printf("%d\n", ans);
    }
	return 0;
}



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

typedef long long ll;

const int maxn = 15;
int seq[maxn], n, ans = 0;

void dfs(int dep, ll cur) {
    if (dep == n) {
	if (cur % 2 == 0) ans++;
	return;
    }
    else {
	dfs(dep + 1, cur * seq[dep]);
	dfs(dep + 1, cur * (seq[dep] - 1));
	dfs(dep + 1, cur * (seq[dep] + 1));
    }
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
	cin >> seq[i];
    }
    dfs(0, 1);
    cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
class K
{
	static void Main() => WriteLine(Solve());
	static long Solve()
	{
		var S = ReadLine();
		var s = S.Select(c => c - 'a').ToArray();
		int N = S.Length, odd = 0, mid = -1;
		var cnt = new int[26];
		foreach (var c in s) cnt[c]++;
		for (var c = 0; c < 26; c++)
		{
			if (cnt[c] % 2 == 1) { mid = c; odd++; }
			cnt[c] /= 2;
		}
		if (odd > 1) return -1;
		var left = new List<int>();
		foreach (var c in s) if (cnt[c] > 0) { cnt[c]--; left.Add(c); }
		int[] t = new int[N], ind = new int[26], p = new int[N];
		for (var i = 0; i < left.Count; i++) t[N - 1 - i] = t[i] = left[i];
		if (mid >= 0) t[N / 2] = mid;
		for (var i = 0; i < N; i++)
		{
			var c = s[i];
			while (t[ind[c]] != c) ind[c]++;
			p[i] = ind[c]++;
		}
		return BIT.Inversion(p);
	}
}
class BIT
{
	public readonly int Size;
	readonly int[] bit;
	public BIT(int size) { Size = size; bit = new int[size + 1]; }
	public void Add(int index, int value) { for (var i = index + 1; i <= Size; i += i & (-i)) bit[i] += value; }
	public int Sum(int to) { var sum = 0; for (var i = to; i > 0; i -= i & (-i)) sum += bit[i]; return sum; }
	public static long Inversion(int[] s)
	{
		var ans = 0L;
		var bit = new BIT(s.Length);
		for (var j = 0; j < s.Length; j++)
		{
			ans += j - bit.Sum(s[j]);
			bit.Add(s[j], 1);
		}
		return ans;
	}
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

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


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin>>s;
      s[3]='8';
      Cout(s);
     

       
return 0;
}


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

def dfs(s):
    if int(s)>n:
        return 0
    if all(s.count(c)>0 for c in "753"):
        a=1
    else:
        a=0

    for c in "753":
        a=a+dfs(s+c)

    return a

print(dfs("0"))

Measured memory_bytes: 2940
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	bool b[1010] = {};//??±????????????
	for (int m, n; cin >> m >> n&&m;) {
		memset(b, 0, sizeof(b));
		int cnt = 0;
		int j = 0;
		rep(i, 1, n + 1) {
			//dump(i);
			//dump(j);
			string s; cin >> s;
			if (cnt == m - 1)continue;
			string t = to_string(i);
			if (i % 3 == 0 && i % 5 == 0)t = "FizzBuzz";
			else if (i % 3 == 0)t = "Fizz";
			else if (i % 5 == 0)t = "Buzz";

			if (s != t) {
				b[j] = true;
				cnt++;
			}
			(++j) %= m;
			while (b[j])(++j) %= m;
			//dumpc(b);
		}
		vector<int> ans;
		rep(i, 0, m) {
			if (!b[i])ans.push_back(i + 1);
		}
		sort(all(ans));
		cout << ans[0];
		rep(i, 1, ans.size())cout << " " << ans[i];
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3244
from heapq import heappop, heappush
from bisect import bisect_right


class SegmentTree(object):

    def __init__(self, init_array, seg_func=min, seg_func_null=10 ** 9 + 7):

        self.seg_func = seg_func
        self.seg_func_null = seg_func_null
        self.n = 1
        while self.n < len(init_array):
            self.n *= 2
        self.dat = [0] * (2 * self.n - 1)
        for i in range(len(init_array)):
            self.dat[self.n - 1 + i] = init_array[i]
        for i in range(self.n - 2, -1, -1):
            self.dat[i] = self.seg_func(self.dat[2 * i + 1], self.dat[2 * i + 2])

    def update(self, k, a):
        k += self.n - 1
        self.dat[k] = a
        while k > 0:
            k = (k - 1) // 2
            self.dat[k] = self.seg_func(self.dat[k * 2 + 1], self.dat[k * 2 + 2])

    def query(self, p, q):
        # [p, q)
        if q <= p:
            return self.seg_func_null

        p += self.n - 1
        q += self.n - 2
        res = self.seg_func_null

        while q - p > 1:
            if p & 1 == 0:
                res = self.seg_func(res, self.dat[p])
            if q & 1 == 1:
                res = self.seg_func(res, self.dat[q])
                q -= 1
            p = p // 2
            q = (q-1) // 2
        if p == q:
            res = self.seg_func(res, self.dat[p])
        else:
            res = self.seg_func(self.seg_func(res, self.dat[p]), self.dat[q])

        return res


def solve(n, x_list, le_list):
    right_limits = dict()
    for i in range(n):
        right_limits[x_list[i] + le_list[i]] = 0
    right_limits_list = list(sorted(list(right_limits.keys())))
    s = SegmentTree([0] * len(right_limits_list), max, -1)

    h = []
    for i in range(n):
        heappush(h, (x_list[i] + le_list[i], i))

    for k in range(n):
        right, i = heappop(h)
        left = x_list[i] - le_list[i]
        ind_left = bisect_right(right_limits_list, left)
        ind_right = bisect_right(right_limits_list, right) - 1
        if ind_left == 0:
            r = s.query(ind_right, ind_right + 1)
            if r == 0:
                s.update(ind_right, 1)
        else:
            r = s.query(ind_right, ind_right + 1)
            l_max = s.query(0, ind_left)
            if r < l_max + 1:
                s.update(ind_right, l_max + 1)

    return s.query(0, n)


def main():
    n = int(input())
    x_list = [0] * n
    le_list = [0] * n
    for i in range(n):
        x, le = map(int, input().split())
        x_list[i] = x
        le_list[i] = le
    res = solve(n, x_list, le_list)
    print(res)


def test():
    assert solve(4, [2, 4, 9, 100], [4, 3, 3, 5]) == 3
    assert solve(2, [8, 1], [20, 10]) == 1
    assert solve(5, [10, 2, 4, 6, 8], [1, 1, 1, 1, 1]) == 5


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 104536
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
    int X,A;
    cin>>X>>A;
    if(X<A){
        cout<<"0"<<endl;
    }
    else{
        cout<<"10"<<endl;
    }
    }

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

int main() {
    ll N, A, B;
    cin >> N >> A >> B;
    ll blue = (N/(A+B))*A;
    if (N%(A+B)!=0) {
        if (N%(A+B) >= A) {
            blue += A;
        }
        else {
            blue += N%(A+B);
        }
    }
    cout << blue << endl;
}

Measured memory_bytes: 3636
using namespace std;
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define mem(x,val) memset((x),(val),sizeof(x));
#define rite(x) freopen(x,"w",stdout);
#define read(x) freopen(x,"r",stdin);
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define sqr(x) ((x)*(x))
#define pb push_back
#define clr clear()
#define inf (1<<30)
#define ins insert
#define xx first
#define yy second
#define eps 1e-9
typedef long long i64;
typedef unsigned long long ui64;
typedef string st;
typedef vector<int> vi;
typedef vector<st> vs;
typedef map<int,int> mii;
typedef map<st,int> msi;
typedef set<int> si;
typedef set<st> ss;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
#define mx 0
int main() {
   	ios_base::sync_with_stdio(0);cin.tie(NULL);
   	//Solution
   	int n, m;
   	cin >> n >> m;
   	vector<int> edg(n, 0);
   	for (int i = 0; i < m; ++i)
   	{
   		int a, b;
   		cin >> a >> b;
   		if(a != 1 && b!= 1 ){
   			edg[a-1]++;
   			edg[b-1]++;
   		}
   		else if(a == 1){
   			edg[b-1]++;
   		}else if(b == 1){
   			edg[a-1]++;
   		}
   	}
   	bool even = true;
   	for (int i = 0; i < n; ++i)
   	{
   		if(edg[i]%2) even = false;
   		//cout << edg[i] << endl;
   	}
   	if (even)
   	{
   		cout << "YES" << endl;
   	}else{
   		cout << "NO" << endl;
   	}


   	
   	return 0;
}


//g++-4.9 agc014_b.cpp -o agc014_b && ./agc014_b < agc014_b.in > agc014_b.out






Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define f0(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
#define f2(i,a,b) for(int i=a;i>b;i--)
#define f3(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define pb push_back
#define mp make_pair
#define pii pair<int,int>

#define fi first
#define se second
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test int t;cin>>t;while(t--)

signed main(){
    fast
   

int n;
    cin>>n;
    f0(i,0,n)cout<<"ACL";
}

Measured memory_bytes: 3652
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.math.*;
 
public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		String a = br.readLine();

		sb.append(a.replace(","," "));
		System.out.println(sb);
	}
}

Measured memory_bytes: 8276
import math
def main():
    N, A, B = map(int, input().split())
    v = sorted(map(int, input().split()))[::-1]
    L = []
    for i in range(A, B+1):
        L += [[sum(v[:i]) / i, v[:i]]]
    LMAX = []
    x = L[0][0]
    for i in L:
        if i[0] == x : LMAX += [i]
    ans = 0
    for i in LMAX:
        a = 1
        for j in set(i[1]):
            if i[1].count(j) == 1:
                a *= v.count(j)
            else:
                x = v.count(j)
                y = i[1].count(j)
                
                
                a *= (math.factorial(x) // math.factorial(x-y)) // math.factorial(y)
        ans += a
    print(LMAX[0][0])
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 39280
#include <iostream>

int main() {
  // 入力
  int parking_hour, a_fee, plan2_fee;
  std::cin >> parking_hour >> a_fee >> plan2_fee;

  // 最小料金
  int plan1_fee = parking_hour * a_fee;
  int minimum_fee = (plan1_fee < plan2_fee) ? plan1_fee : plan2_fee;

  // 出力
  std::cout << minimum_fee << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(){
    int a,b;
    cin >> a >> b;
    cout << "a ";
    if(a<b) cout << "< ";
    if(a==b) cout << "== ";
    if(a>b) cout << "> ";
    cout << "b" << endl;
     
     
    return 0;
}


Measured memory_bytes: 3080
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (ll i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define Rev(a) reverse(a.begin(), a.end())
#define MATHPI acos(-1)
#define itn int
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-19;

signed main() {
    ll n;
    cin >> n;
    
    vll a(n+2);
    a[0] = 0;
    a[n+1] = 0;
    vll mon(n+2, 0);
    vll mon2(n+2, 0);
    ll sum = 0;
    rrep(i, n+1) {
        cin >> a[i];
        mon[i] = abs(a[i]-a[i-1]);
        sum += mon[i];
        if (i > 1) mon2[i] = abs(a[i]-a[i-2]);
    }
    
    ll r = 0;
    rrep(i, n) {
        r = sum;
        r -= mon[i] + mon[i+1];
        r += mon2[i+1];
        mes (r);
    }
    
    

}
    
    
    
    
    


Measured memory_bytes: 5640
#include <iostream>
#include <unordered_set>

using namespace std;

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

	unordered_set<int> s;
	for (int i = 0; i < N; ++i) {
		int A;
		cin >> A;
		auto r = s.insert(A);
		if (!r.second) {
			s.erase(r.first);
		}
	}
	cout << s.size() << endl;
}


Measured memory_bytes: 4388
#include <stdio.h>
#include <string.h>

int main(void)
{
  int n,i,j,k;
  char s[100000];

  scanf("%s",s);
  n=strlen(s);
  j=0;
  k=0;
  for(i=0;i<n;i++){
        if(s[i]=='0') j++;
        else if(s[i]=='1') k++;
        }
  if(j<k) printf("%d\n",j*2);
  else if(j>k) printf("%d\n",k*2);
  else printf("%d\n",j*2);
  return 0;
}


Measured memory_bytes: 256
xy = list(map(int,input().split()))

if xy[2] - xy[0] == 0:
    if xy[3] > xy[1]:
        x3 = xy[2] - (xy[3]-xy[1])
        y3 = xy[3] - (xy[2]-xy[0])
        x4 = xy[0] - (xy[3]-xy[1])
        y4 = xy[1] - (xy[2]-xy[0])
    else:
        x3 = xy[2] + (xy[1]-xy[3])
        y3 = xy[3] - (xy[0]-xy[2])
        x4 = xy[0] + (xy[1]-xy[3])
        y4 = xy[1] - (xy[0]-xy[2])
else:
    if xy[2] > xy[0]:
        x3 = xy[2] + (xy[1]-xy[3])
        y3 = xy[3] + (xy[2]-xy[0])
        x4 = xy[0] + (xy[1]-xy[3])
        y4 = xy[1] + (xy[2]-xy[0])
    else:
        x3 = xy[2] - (xy[3]-xy[1])
        y3 = xy[3] + (xy[2]-xy[0])
        x4 = xy[0] - (xy[3]-xy[1])
        y4 = xy[1] + (xy[2]-xy[0])

print(x3,y3,x4,y4)


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

//Compiler version g++ 6.3.0

int main()
{
  int n, m, a[100000];
  cin >> n >> m;
  long long sum = 0;
  for(int i = 0; i < m; i++){
    int x; cin >> x;
    sum += x;
  }
  if(sum > n) cout << "-1\n";
  else cout << n - sum << "\n";
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define int long long
#define rep(i, l, r) for(register int i = l; i <= r; ++ i)
using namespace std;
const int N = 10010;
inline int read()
{
	register char cc = getchar(); register int cn(0), flus(1);
	while(cc < '0' || cc > '9') {if(cc == '-') flus = - flus; cc = getchar();}
	while(cc >= '0' && cc <= '9') {cn = cn * 10 + cc - '0'; cc = getchar();}
	return cn * flus;
}
int h,n,a,b,dp[N];
signed main()
{
	memset(dp,0x3f,sizeof(dp));
	dp[0]=0;
	h = read();
	n = read();
	while(n--)
	{
		a = read();
		b = read();
		rep(i, 1, h) dp[i]=min(dp[max(i-a,(long long)0)]+b,dp[i]);
	}
	printf("%lld\n",dp[h]);
	return 0;
}


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

int main() {
  int N,A;
  cin >> N;
  A=0;

  for(int i=0;i<N;i++){
    int a,b;
    cin >> a >> b;
    A += b-a+1;
  }
  cout << A << endl;
}


Measured memory_bytes: 256
//============================================================================
// Name        : ATcoder.cpp
// Author      : Akari Fujii
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cctype>
#include <string>
#include<algorithm>
using namespace std;

int main() {


	int n;
	int k;
	int x[100];
	int t;
	int s;
	int d=0;


	cin>>n;
	cin>>k;
		for(int i=1; i<n+1; i++){
			cin>>x[i];


			t=x[i]*2;
			s=(k-x[i])*2;

			if( t < s ){
				d+=t;
			}else if( s < t ){
				d+=s;
			}else if( s = t ){
				d+=s;
			}
		}
		cout<<d<<endl;
}




Measured memory_bytes: 256
import math

a, b, h, m = map(int, input().split())
h_rad = (h * 60 + m) * math.pi / 360
m_rad = m * math.pi / 30
cosine = math.cos(abs(h_rad - m_rad))

print(math.sqrt(a ** 2 + b ** 2 - 2 * a * b * cosine))

Measured memory_bytes: 9364
#include <stdio.h>

int
main(void)
{
    int a, b, sum;
    int n_digits;

    while (scanf("%d %d", &a, &b) == 2) {
        sum = a + b;
        n_digits = 0;

        while (sum > 0) {
            n_digits++;
            sum /= 10;
        }

        printf("%d\n", n_digits);
    }

    return 0;
}

Measured memory_bytes: 600
/**
*   @Author : MeGaCrazy
*   @InitTime : Tue Jul 30 07:16:56 2019
*   @Idea :
*
*
*
*
*
*  Happy Solving :)
**/
#include <bits/stdc++.h>
using namespace std;
int main(){
#ifndef ONLINE_JUDGE
   //freopen("in","r",stdin);
   //freopen("out","w",stdout);
#endif
   set<string>st={"dream","dreamer","erase","eraser"};

   string cur="";

   string in;
   cin>>in;
   for(int i=in.size()-1;i>=0;i--){
    	cur=in[i]+cur;
    	if(st.count(cur)){
    	  cur="";
    	}
   }
   if(cur==""){
   	cout<<"YES";
   }else{
   	cout<<"NO";
   }
   



}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

struct LazySegTree{
    int n; vector<int> dat,lazy;
    //初期化
    LazySegTree(int _n){
        n=1;
        while(n<_n) n*=2;
        dat=vector<int>(2*n-1,0);
        lazy=vector<int>(2*n-1,0);
    }

    void setLazy(int k, int v){
        lazy[k] = v;
        dat[k] = v;
    }

    void push(int k, int l, int r){
        if(lazy[k]!=0){
            setLazy(2*k+1,lazy[k]);
            setLazy(2*k+2,lazy[k]);
        }
        lazy[k]=0;
    }

    void fix(int k, int l, int r){
        dat[k] = dat[2*k+1]&dat[2*k+2];
    }

    int merge(int x, int y){
        return x&y;
    }

    //内部的に投げられるクエリ
    void _update(int a, int b, int x, int k, int l, int r){
        if(r<=a || b<=l) return;
        if(a<=l && r<=b){
            setLazy(k,x);
            return;
        }

        push(k,l,r);
        _update(a,b,x,2*k+1,l,(l+r)/2);
        _update(a,b,x,2*k+2,(l+r)/2,r);

        fix(k,l,r);
    }
    //[a,b)をxに更新
    void update(int a, int b, int x){
        return _update(a,b,x,0,0,n);
    }

    //内部的に投げられるクエリ
    int _query(int a, int b, int k, int l, int r){
        if(r<=a || b<=l) return 1;
        if(a<=l && r<=b) return dat[k];

        push(k,l,r);
        int vl=_query(a,b,2*k+1,l,(l+r)/2);
        int vr=_query(a,b,2*k+2,(l+r)/2,r);
        return merge(vl,vr);
    }
    //[a,b)
    int query(int a, int b){
        return _query(a,b,0,0,n);
    }
};

const int N = 200000;
vector<int> C[N],Q[N];

int main(){
    int n,m,q;
    scanf(" %d %d %d", &n, &m, &q);

    vector<int> d(m),a(m),b(m);
    rep(i,m) scanf(" %d %d %d", &d[i], &a[i], &b[i]);

    vector<int> e(q),s(q),t(q);
    rep(i,q) scanf(" %d %d %d", &e[i], &s[i], &t[i]);

    vector<int> v;
    rep(i,m) v.pb(d[i]);
    rep(i,q) v.pb(e[i]);
    sort(all(v));
    v.erase(unique(all(v)), v.end());
    int V = v.size();

    rep(i,m){
        int idx = lower_bound(all(v), d[i])-v.begin();
        C[idx].pb(i);
    }
    rep(i,q){
        int idx = lower_bound(all(v), e[i])-v.begin();
        Q[idx].pb(i);
    }

    LazySegTree st(n);
    vector<bool> ans(q);
    rep(i,V){
        for(int &ID:Q[i]) ans[ID] = st.query(s[ID], t[ID]);
        for(int &ID:C[i]) st.update(a[ID], b[ID], 1);
    }
    rep(i,q) printf("%s\n", (ans[i]?"Yes":"No"));
    return 0;
}



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

int main ( ) 
{
	int w , a , b ; 
	scanf("%d%d%d" ,&w, &a , &b ) ; 
	if (a <b) 
	{
		if ((a+w) >= b) 
		{
			cout << 0 ;
		}
		else 
		cout << b - (a+w) ;	
	}
	else 
	if ( b<a)
	{
		if ((b+w) >=a)
		cout << 0 ; 
		else 
		cout << a - (b+w) ;
	}
	else if ( a ==b) 
	{
		cout << 0 ;
	}
		return 0 ; 
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <numeric>

using namespace std;

const int INF = 1 << 30;
const uint64_t MOD = 1000000000 + 7;

int main()
{
	int n, m;
	cin >> n >> m;

	vector<int> a(m);
	for (int i = 0; i < m; i++)
	{
		cin >> a.at(i);
	}

	if (n >= m)
	{
		cout << 0 << endl;
		return 0;
	}

	sort(a.begin(), a.end());

	vector<int> b(m);
	for (int i = 0; i < m - 1; i++)
	{
		b.at(i) = a.at(i + 1) - a.at(i);

		b.at(i) *= (b.at(i) < 0) ? -1 : 1;
	}

	sort(b.begin(), b.end());

	cout << accumulate(b.begin(), b.end() - (n - 1), 0) << endl;
}

Measured memory_bytes: 1024
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <iostream> 
#include <iomanip>  
#include <string>
#include <sstream>  
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <cstring>
#include <cmath>
#include <cassert>


#define INF              (int)1000000007
#define EPS              1e-9
#define pb               push_back
#define mp               make_pair
#define all(c)           c.begin(), c.end()
#define forall(i,a,b)    for(int i=a;i<(b);++i)
#define trav(a,x)        for(auto & a: x)
#define in(a,b)          ((b).find(a) != (b).end())
#define sz(c)            (int)(c).size()
#define input(a)         for(auto & x : a) cin >> x;

using namespace std;

typedef vector<int>      vi;
typedef pair<int,int>    ii;
typedef vector<vi>       vvi;
typedef vector<ii>       vii;
typedef long long        ll;

#ifdef DEBUG
#define trace(...)       __f(#__VA_ARGS__, __VA_ARGS__)
#define debug(args...)   {dbg,args; clog<<endl;}
#define print_( a )      for( auto & x : a ) clog << x << ' '; clog << '\n';
#define printPair_( a )  for( auto & x : a ) clog << '(' << x.first << ',' << x.second << ')' << ' '; clog << '\n';
#else
#define trace(...)       
#define debug(args...)            
#define print_( a )               
#define printPair_( a )           
#endif

struct debugger {
  template<typename T> debugger& operator , (const T& x) {    
    clog << x << " ";    return *this;    
  }
}dbg;

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << ": " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << arg1 << " | ";
    __f(comma + 1, args...);
}

auto ____ =[]() { std::ios::sync_with_stdio(0); cin.tie(0); return nullptr; }();

int main( int argc, char * argv[] ){
  int n; cin >> n; 
  vector<ll> v(n); input(v);
  vector<vector<ll>> dp(n,vector<ll>(n));
  vector<ll> cumsum(n+1);
  cumsum[0] = 0;
  forall(i,0,n) cumsum[i+1] = cumsum[i] + v[i];
  auto get_part = [&](int l, int r){ return cumsum[r+1] - cumsum[l]; };
  for(int L = n-1; L >= 0; --L){
    for(int R = L; R < n; ++R ){
      if( L == R ){ dp[L][R] = 0; continue; }
      if( R - L == 1 ){ dp[L][R] = v[L] + v[R]; continue; }
      ll res = numeric_limits<ll>::max();
      forall(k,L,R){
        if( k == L ) res = min( res, v[L]+ get_part(k+1,R) + dp[k+1][R] );
        else if( k == R-1 ) res = min( res, dp[L][k] + get_part(L,k) + v[R] );
        else res = min(res, dp[L][k] + dp[k+1][R] + get_part(L,R));
      }
      trace(L, R, dp[L][R], res);
      dp[L][R] = res;
    }
    print_(dp[L]);
  }
  cout << dp[0][n-1] << endl;

  
  return 0;
}


Measured memory_bytes: 1536
#!/usr/bin/python
# -*- coding:utf-8 -*-

n = int(input())
s = input()

max = 0
for i in range(1, len(s)):
    left = s[:i]
    right = s[i:]
    buf = []
    for j in left:
        if j in right and j not in buf:
            buf.append(j)
    if max < len(buf):
        max = len(buf)
print(max)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int n,a,b,c;
vector<string> v;
#define pb push_back
stack<char> st;
int recur(int idx,int a,int b,int c){
        if(idx==n){return 1; }
        int d[3]; d[0]=a,d[1]=b,d[2]=c;
        d[v[idx][0]-'A']++,d[v[idx][1]-'A']--;
        if(d[0]>=0&&d[1]>=0&&d[2]>=0) { int res=recur(idx+1,d[0],d[1],d[2]); if(res){ st.push(v[idx][0]); return 1; }  }
        d[v[idx][0]-'A']-=2; d[v[idx][1]-'A']+=2;
        if(d[0]>=0&&d[1]>=0&&d[2]>=0) { int res=recur(idx+1,d[0],d[1],d[2]); if(res){ st.push(v[idx][1]); return 1; }  }
        return 0;
}

int main(){
        cin>>n>>a>>b>>c; string s;
        for(int i=1;i<=n;i++) { cin>>s; v.pb(s); }
        int res=recur(0,a,b,c);
        if(!res){ cout<<"No"<<endl; return 0;}
        cout<<"Yes"<<endl;
        while(!st.empty()){
                cout<<st.top()<<endl;
                st.pop();
        }
}


Measured memory_bytes: 12708
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;

#define mod 1000000007

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)


double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

#define fi first
#define se second

#define int long long

int power(int x, int y, int p) 
{ 
    int res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or 
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
  
// Returns n^(-1) mod p 
int modInverse(int n, int p) 
{ 
    return power(n, p-2, p); 
} 
  
// Returns nCr % p using Fermat's little 
// theorem. 
int nCrModPFermat(int n, int r, int p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
  
    // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r 
    int fac[n+1]; 
    fac[0] = 1; 
    for (int i=1 ; i<=n; i++) 
        fac[i] = fac[i-1]*i%p; 
  
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
} 

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll x,y;
	cin>>x>>y;
	if((x+y)%3)
	{
		cout<<0;
		return 0;
	}
	ll k=(x+y)/3;
	if((x-k)<0 || (2*k-x)<0)
	{
		cout<<0;
		return 0;
	}
	cout<< (nCrModPFermat(k,x-k,mod));
    return 0;
}


//252908XL

Measured memory_bytes: 5504
/* package codechef; // don't place package name! */
// old but im not that old
import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
    static class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next(){
            while(st == null || !st.hasMoreElements()){
                try{
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e){
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt(){
            return Integer.parseInt(next());
        }
        long nextLong(){
            return Long.parseLong(next());
        }
        double nextDouble(){
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try{
                str = br.readLine();
            } catch (Exception e){
                e.printStackTrace();
            }
            return str;
        }
    }
    static int modPower(int x, int y, int mod){
        int res = 1;
        x %= mod;
        if(x==0) return 0;
        while(y>0){
            if(y%2==1){
                res = (res*x)%mod;
            }
            y = y>>1;
            x = (x*x)%mod;
        }
        return res;
    }
    public static void main (String[] args) throws java.lang.Exception
    {
        // your code goes here
        FastReader in = new FastReader();
        int n = in.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = in.nextInt();
        }
        Arrays.sort(a);
        long ans = a[n-1];
        if(n >= 3){
            ans += a[n-2];
        }
        if(n>=4){
            ans += a[n-2];
        }
        int k = n-3;
        for(int i = n - 5; i >= 0; i-=2){
            ans += a[k];
            if(i > 0){
                ans += a[k];
            }
            k--;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 55620