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

using namespace std;

#define llong long long 
#define ii pair<int, int>
#define xx first
#define yy second
#define rep(i,n) for (int i = -1; ++i < n; )
#define sz(v) ((int)v.size())

#define maxn 101010
int n, m;

struct cmpyy {
  bool operator()(const ii& a, const ii& b) {
    if (a.yy == b.yy) return a.xx < b.xx;
    return a.yy < b.yy;
  }
};

multiset<ii, cmpyy> cur; 
multiset<ii> rem;

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cin >> n >> m;
  llong curans = 0;
  int last; cin >> last;
  rep(i, n - 1) {
    int b;
    cin >> b;
    if (last == b) continue;
    ii a(last, b); last = b;
    if (a.yy < a.xx) a.xx -= m;
    rem.insert(a);
    curans += a.yy - a.xx;
  }

  //clog << curans << endl;

  llong ans = 1e18;
  for (int i = 1; i <= m; ++i) {
    while (sz(cur) and cur.begin()->yy < i) {
      ii a = *cur.begin();
      cur.erase(cur.begin());
      curans += a.yy - a.xx - 1;
      a.xx += m; a.yy += m;
      rem.insert(a);
    }
    curans -= sz(cur);
    while (sz(rem) and rem.begin()->xx < i and rem.begin()->yy >= i) {
      ii a = *rem.begin();
      rem.erase(rem.begin());
      curans -= a.yy - a.xx;
      curans += a.yy - i + 1;
      cur.insert(a);
    }
    //clog << i << ' ' << curans << ": ";
    //for (auto i: cur) clog << i.xx << ':' << i.yy << ' ';
    //clog << endl;
    ans = min(ans, curans);
  }
  cout << ans;
  
  return 0;
}


Measured memory_bytes: 4992
a,b,c,d = map(int, input().split())
x = c-a
y = d-b
y1=''
y2=''
for i in range(y):
  y1+='U'
  y2+='D'
x1=''
x2=''
for i in range(x):
  x1+='R'
  x2+='L'
print(y1+x1+y2+x2+'L'+y1+'UR'+x1+'DR'+y2+'DL'+x2+'U')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(a) cout << #a << ": " << a << endl
#define sz(a) int(a.size())
#define rep(i,n) for(int i=0;i<n;i++)
#define forr(i, st, en) for(int i = st; i <= en; i++)
#define all(v) (v).begin(),(v).end()

#define fast cin.tie(0); ios::sync_with_stdio(false)

int32_t main(){ fast;
	int s, w; cin>>s>>w;
	if(w >= s){
		cout<<"unsafe"<<endl;
	}
	else cout<<"safe"<<endl;
}


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

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	int ans = 0;
	for(int i = 1; i <= n; i++){
		int digsum = i / 10000 + (i / 1000) % 10 + (i / 100) % 10 + (i / 10) % 10 + i % 10;
		if(a <= digsum && digsum <= b) ans += i;
	}
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef pair<int, int> pi;

#define pb push_back

#define rep(i, l, n) for (int i = (l); i < n; i++)
#define rep_d(j, n) for (int j = n; j >= 0; j--)
#define rep_d_op(j, n, a) for (int j = n; j >= a; j--)

template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}

const int MOD = 1000000007;

const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};
const ll INF = 1LL << 60;

// int max = *std::max_element(vec.begin(), vec.end());
// int sum = accumulate(list, list + size, 0);

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

using Graph = vector<vector<int>>;

Graph G;

vector<bool> seen;
void dfs(const Graph &G, int v)
{
    seen[v] = true;

    for (auto next_v : G[v])
    {
        if (seen[next_v])
            continue;
        dfs(G, next_v);
    }
}

int main()
{
    int n;
    cin >> n;
    ll h[n];
    rep(i, 0, n)
    {
        cin >> h[i];
    }

    ll dp[100010];
    rep(i, 0, 100010)
    {
        dp[i] = INF;
    }
    dp[0] = 0;

    rep(i, 1, n)
    {
        chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if (i >= 2)
        {
            chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
        }
    }
    cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;

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

int w, h, c[55][55], ans;
bool is_search[55][55];
int vx[8] = {0, -1, -1, -1, 0, 1, 1, 1},
    vy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};


void bfs(int x, int y) {
    queue<pair<int, int> > que;
    que.push(make_pair(x, y));
    is_search[x][y] = true;

    while (!que.empty()) {
        pair<int, int> p = que.front(); que.pop();
        //cout << p.first << " " << p.second << endl;
        rep(i,8) {
            int nx, ny;
            nx = p.first + vx[i], ny = p.second + vy[i];
            if (0 <= nx && nx < h && 0 <= ny && ny < w &&
                c[nx][ny] == 1 && is_search[nx][ny] == false) {
                   que.push(make_pair(nx, ny));
                   is_search[nx][ny] = true;
            }
        }
    }

}

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

    while (cin >> w >> h, w | h) {
        memset(c, 0, sizeof(c));
        memset(is_search, false, sizeof(is_search));
        ans = 0;
        rep(i,h) {
            rep(j,w) {
                cin >> c[i][j];
            }
        }

        rep(i,h) {
            rep(j,w) {
                if (is_search[i][j] == false && c[i][j] == 1) {
                    bfs(i,j);
                    ans++;
                }
            }
        }

        cout << ans << endl;
    }

    return 0;
}

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

using namespace std;

int main()
{
    string s, t;
    cin >> s >> t;

    sort(s.begin(), s.end());
    sort(t.rbegin(), t.rend());

    if (s < t) cout << "Yes" << endl;
    else cout << "No" <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
//#define S set<int>
#define itn int
bool dbg = false;


void solve() {
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    FOR(i, 0, (int)(S.size()))
        cout << 'x';
    cout << endl;
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[]) {
  int A, B;
  scanf("%d %d", &A, &B);
  if (abs(B - A) % 2 == 0) {
    printf("%d\n", (A + B) / 2);
  } else {
    printf("IMPOSSIBLE\n");
  }
  
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
string s,t,x;
int i,j,mn=10000,y;
int main()
{
	cin >> s >> t;
	for (i=0; i<=s.size()-t.size(); i++)
	{
		for (j=i; j<=i+t.size(); j++)
		x+=s[j];
		for (j=0; j<t.size(); j++)
		if (t[j]!=x[j]) y++;
		if (y<mn) mn=y;
		y=0; x="";
	}
	cout<<mn;
	
	
}

Measured memory_bytes: 3600
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int res[11][180000];

int p(int n){
	if(n==0) return 1;
	return 3*p(n-1);
}

priority_queue<pint,vector<pint>,greater<pint> > bfs;
int i;

void g(pint a){
	int j;
	for(j=0;j<i-1;j++){
		if(a.second%p(j+1)/p(j)==a.second%p(j+2)/p(j+1)){
			int k=a.second%p(j+1)/p(j);
			int l=a.second;
			l-=k*p(j)+k*p(j+1);
			if(k==0){
				bfs.push(mp(a.first+1,l+p(j)+2*p(j+1)));
				bfs.push(mp(a.first+1,l+2*p(j)+p(j+1)));
			}
			if(k==1){
				bfs.push(mp(a.first+1,l+2*p(j+1)));
				bfs.push(mp(a.first+1,l+2*p(j)));
			}
			if(k==2){
				bfs.push(mp(a.first+1,l+p(j+1)));
				bfs.push(mp(a.first+1,l+p(j)));
			}
		}
	}
	return;
}

int main() {
	memset(res,-1,sizeof(res));
	for(i=2;i<=10;i++){
		int j,k=0;
		while(!bfs.empty())bfs.pop();
		for(j=0;j<i;j++)k+=p(j)*0;
		res[i][k]=0;
		g(mp(0,k));
		k=0;
		for(j=0;j<i;j++)k+=p(j)*1;
		res[i][k]=0;
		g(mp(0,k));
		k=0;
		for(j=0;j<i;j++)k+=p(j)*2;
		res[i][k]=0;
//cout<<k<<endl;
		g(mp(0,k));
		while(!bfs.empty()){
			pint buf;
			buf=bfs.top();
			bfs.pop();
//cout<<buf.first<<" "<<buf.second<<endl;
			if(res[i][buf.second]!=-1&&res[i][buf.second]<=buf.first)continue;
			res[i][buf.second]=buf.first;
			g(buf);
		}
	}
//for(i=2;i<=10;i++){
//	int j;
//	for(j=0;j<p(i);j++){
//		int l;
//		for(l=0;l<i;l++){
//			if(j/p(l)%3==0)cout<<"r";
//			if(j/p(l)%3==1)cout<<"b";
//			if(j/p(l)%3==2)cout<<"g";
//		}
//		cout<<" "<<res[i][j]<<endl;
//	}
//}
	string str;
	while(cin>>str,str!="0"){
		int k=0;
		int j;
		for(j=0;j<str.size();j++){
			if(str[j]=='r')k=k*3+0;
			if(str[j]=='b')k=k*3+1;
			if(str[j]=='g')k=k*3+2;
		}
		if(res[str.size()][k]>=0)cout<<res[str.size()][k]<<endl;
		else cout<<"NA\n";
	}
	return 0;
}

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

const ll INF = 1LL << 60;

ll N, M;
vector<ll> a;

// 2で何回割れるか
ll f(ll x) {
    ll cnt = 0;
    while (x % 2 == 0) {
        x /= 2;
        cnt++;
    }
    return cnt;
}

// 最大公約数
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

// 最小公倍数
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }

int main() {
    cin >> N >> M;
    a.resize(N);
    rep(i, N) cin >> a[i];

    rep(i, N) a[i] = a[i] / 2;

    ll tmp = f(a[0]);

    for (int i = 0; i < N; i++) {
        ll t = f(a[i]);

        // 2の数が違う場合、条件を満たすものはない
        if (t != tmp) {
            cout << 0 << endl;
            return 0;
        }

        a[i] = a[i] >> tmp;
    }

    M = M >> tmp;

    // 最小公倍数
    ll l = 1;
    for (int i = 0; i < N; i++) {
        l = lcm(l, a[i]);
    }

    ll ans = (M / l + 1) / 2;
    cout << ans << endl;
}

Measured memory_bytes: 3972
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  vector<int> vec(3);
  cin>>vec[0]>>vec[1]>>vec[2];
  sort(vec.begin(),vec.end());
  
  cout<<vec[0]+vec[2]*10+vec[1]<<endl;
}


Measured memory_bytes: 3624
#include<cstdio>
using namespace std;
int main()
{
	int n,d,flg;
	scanf("%d %d",&n,&d);
	d=d*2+1;
	flg=0;
	if(n%d!=0)	flg=1;
	n/=d;
	// printf("n=%d d=%d\n",n,d);
	if(flg==1)	printf("%d\n",n+1);
	else printf("%d\n",n);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<map>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;

int main(){
	int n;
	cin>>n;
	int ans=0;
	if(n>=10) ans+=9;
	else ans+=n;
	int x=100,y=1000;
	while(1){
		if(n<x) break;
		if(n>=y){
			ans+=y-x;
		}
		else{
			ans+=n-x+1;
			break;
		}
		x*=100;
		y*=100;
	}
	cout<<ans;
    return 0;
}

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

using namespace std;

int main(){
  int n; cin >> n;
  string s; cin >> s;
  int right=0,up=0;
  for(int i=0;i<n;++i){
    if('A'<=s[i]&&s[i]<='M') up++;
    else if('N'<=s[i]&&s[i]<='Z') up--;
    else if('a'<=s[i]&&s[i]<='m') right++;
    else if('n'<=s[i]&&s[i]<='z') right--;
  }
  string ans;
  while(up!=0||right!=0){
    if(up>0) ans+='A',up--;
    else if(up<0) ans+='N',up++;
    if(right>0) ans+='a',right--;
    else if(right<0) ans+='n',right++;
  }
  cout << ans.size() << endl << ans << endl;
}



Measured memory_bytes: 3304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll n;
  cin >> n;
  vll a(3 * n);
  for (ll i = 0; i < 3 * n; i++) cin >> a[i];
  sort(all(a));
  ll ans = 0;
  for (ll i = 0; i < n; i++) ans += a[3 * n - 1 - (i * 2 + 1)];
  cout << ans << endl;
}

Measured memory_bytes: 2560
import sys
input = sys.stdin.readline

N = int(input())
A = [None] + [int(x) for x in input().split()]

answer = []
choose = [0] * (N+1)

for n in range(N,0,-1):
    x = sum(choose[2*n::n])
    if x % 2 == A[n]:
        continue
    choose[n] += 1
    answer.append(str(n))

print(len(answer))
print(' '.join(answer))



Measured memory_bytes: 87004
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 100000000
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(g);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double PI = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;


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

	string s;
	cin >> s;
	if (s == "a" || s == "e" || s == "i" || s == "o" || s == "u")
		cout << "vowel";
	else
		puts("consonant");
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
    int N=int.Parse(Console.ReadLine());
      int[] values1 = new int[N];
     for(int i=0;i<N;i++){
       values1[i]=int.Parse(Console.ReadLine());
     }
     int max=values1.Max();
     int[] dis=new int[N];
      values1.CopyTo(dis,0);
    Array.Sort(dis);
     Array.Reverse(dis);
      int sec=dis[1];

    
      for(int i=0;i<N;i++){

       if(values1[i]==max){
         Console.WriteLine(sec);
       }else{
         Console.WriteLine(max);
      }
                }
      
    }
    
  }

}


Measured memory_bytes: 44820
n=int(input())
ans=0
if ((n>=1) & (n<=9)):
    ans=n
elif ((n>=10) & (n<=99)):
    ans=9
elif ((n>=100) & (n<=999)):
    ans=n-90
elif ((n>=1000) & (n<=9999)):
    ans=909
elif ((n>=10000) & (n<=99999)):
    ans=n-9090
else:
    ans=90909
    
print(ans)

Measured memory_bytes: 38256
#include <stdio.h>
int main(void) {
    int n, p[100], c=0, i;
    
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&p[i]);
    
    for(i=0;i<n-2;i++){
        if((p[i]<p[i+1])&&(p[i+1]<p[i+2])) c++;
        else if((p[i]>p[i+1])&&(p[i+1]>p[i+2])) c++;
    }
    printf("%d\n",c);
    return 0;
}


Measured memory_bytes: 1700
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define All(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
#define IN(a, b, x) (a<=x&&x<b)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e9;
const ll infl = ll(1e18)+5;
/*
*ios::sync_with_stdio(false);
*cin.tie(0);
*/

int main(){
  string s;
  cin >> s;
  map<char,int> ma;
  for(auto c:s){
    ma[c]++;
  }
  if(abs(ma['a'] - ma['b']) > 1 || abs(ma['b']-ma['c']) > 1 || abs(ma['c']-ma['a'])>1){
    cout << "NO" << endl;
  }else{
    cout << "YES" << endl;
  }
  
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
using namespace std;

const int maxn=2e5+5;

int n,son[maxn][26],tot,now;
char S[maxn];

int calc(int tg)
{
	int sum=0;
	fo(i,1,10000)
	{
		sum+=i;
		if (sum>tg) return i-1;
	}
}

int main()
{
	scanf("%s",S+1);
	n=strlen(S+1);
	
	int ans=0, last=0, cnt=0;
	fo(i,1,n)
	{
		if (cnt==1)
		{
			if (S[i]!=last)
			{
				cnt=1;
				ans++;
			} else if (i<n)
			{
				ans++;
				cnt=2;
				i++;
			}
		} else
		{
			ans++;
			cnt=1;
		}
		last=S[i];
	}
	
	printf("%d\n",ans);
}

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

int main(){
int r, g, b;
  cin >> r >> g >> b;
  if(((r * 100 + g * 10 + b) % 4) == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  return 0;
  
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main
{
  public static void main(String[]args)
  {
  Scanner input=new Scanner(System.in);
    int a=input.nextInt();
    int b=input.nextInt();
    int c=input.nextInt();
    if (a>b && b>c)
      System.out.println(c+" "+b+" "+a);
    else if(b>a && a>c)
      System.out.println(c+" "+a+" "+b);
     else if(b>c && c>a)
      System.out.println(a+" "+c+" "+b);
     else if(c>b && b>a)
      System.out.println(a+" "+b+" "+c);
     else if(c>a && a>b)
      System.out.println(b+" "+a+" "+c);
     else if (a>c && c>b)
      System.out.println(b+" "+c+" "+a);
     else if (a==b && c>a && c>b)
       System.out.println(a+" "+b+" "+c);
     else if (b==c && a>b && a>c)
       System.out.println(b+" "+c+" "+a);
     else if (a==c && b>a && b>c)
        System.out.println(a+" "+c+" "+b);
     else if (a==b && c<a && c<b)
       System.out.println(c+" "+b+" "+a);
     else if (b==c && a<b && a<c)
       System.out.println(a+" "+b+" "+c);
     else if (a==c && b<a && b<c)
        System.out.println(b+" "+c+" "+a);
  }
     
}


Measured memory_bytes: 26204
#include <stdio.h>
#define MIN -1000000
#define MAX 1000000

int
main(void)
{
    int min = MAX;
    int max = MIN;
    int num, c;
    long long sum = 0;
    scanf("%d", &c);
    while (c--) {
        scanf("%d", &num);
        sum += num;
        min = num < min ? num : min;
        max = num > max ? num : max;
    }
    printf("%d %d %lld\n", min, max, sum);
    return 0;
}


Measured memory_bytes: 2108
prime_array = Array.new(10001){true}
prime_array[0] = false
prime_array[1] = false
10001.times do |i|
  next unless prime_array[i]
  for j in 2..(10000 / i) do 
    prime_array[i * j] = false
  end
end
non_pure_primes = prime_array.map.with_index do |tf, i|
  i if tf
end
pure_primes = non_pure_primes.find_all{|prime| !prime.nil?}
while true
  counter = 0
  head_index = 0
  queue = [pure_primes[0]]
  given_number = gets.to_i
  break if given_number == 0
  while true
    queue_sum = queue.inject(0){|sum, number| sum + number}
    counter += 1 if queue_sum == given_number
    if queue_sum < given_number
      head_index += 1
      break if head_index == pure_primes.length
      break if pure_primes[head_index] > given_number
      queue.push(pure_primes[head_index])
    else
      queue.shift
    end
  end
  puts counter
end

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

int main()
{
	int n;
	cin >> n;
	int a[n+1];
	int b[n+1];
	int cnt = 0;
	rep(i, n)
	{
		cin >> a[i];
	}
	rep(i , n)
	{
		if(a[a[i]] == i)
			cnt++;
	}
	cout << cnt / 2 << endl;
	return (0);
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <limits>
using namespace std;
// 素因数分解
typedef pair<long long, long long> P;
vector<P> prime_factorize(long long n)
{
vector<P> res;
for (long long p = 2; p * p <= n; ++p)
{
if (n % p != 0)
continue;
int num = 0;
while (n % p == 0)
{
++num;
n /= p;
}
res.push_back(make_pair(p, num));
}
if (n != 1)
res.push_back(make_pair(n, 1));
return res;
}
// 因数分解
long long gcd(long long x, long long y)
{
  if (y == 0)
  {
    return x;
  }
  else
  {
    return gcd(y, x % y);
  }
}
const int MOD = 1000000007;
typedef long long int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)

int main()
{
    ll n, k;
    cin >> n >> k;
    ll amari = n % k;
    ll hikaku = llabs(amari - k);
    ll ans = min(amari, hikaku);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int rp = rank(n, sc);
        int rq = rank(n, sc);
        System.out.println(Math.abs(rp - rq));
    }

    static int fact(int n) {
        int result = n;
        for(int i = 1; i < n; i++) result *= i;
        return result;
    }
    static int rank(int n, Scanner sc) {
        List<Integer> arr = new ArrayList<>();
        for(int i = 1; i <= n; i++) arr.add(i);
        int result = 1;
        for(int i = 0; i < n; i++) {
            int p = sc.nextInt();
            if(i == n - 1) break;
            if(arr.indexOf(p) != 0) result += fact(arr.size() - 1) * arr.indexOf(p);
            arr.remove(Integer.valueOf(p));
        }
        return result;
    }
}


Measured memory_bytes: 23764
import java.util.Scanner;

public class Main {
    
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line=sc.nextLine();
        int n=Integer.parseInt(line);
        
        String[] line1=sc.nextLine().split(" ");
        int[] num=new int[n];
        
        for(int i=0;i<n;i++) {
        	num[i]=Integer.parseInt(line1[i]); 	
        }
       
		int count=0;
		
		for(int i=0;i<n;i++) {
        	if(i%2==0 && num[i]%2==1) {
        		count++;
        	}
        }

        System.out.println(count);
        
        
	}
  
}


Measured memory_bytes: 35624
import java.io.*;
import java.util.*;


public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String s;
		while ((s = br.readLine()) != null) {
			String[] lc = s.split(" ");
			int a = Integer.parseInt(lc[0]);
			int b = Integer.parseInt(lc[1]);
			
			System.out.println((int)Math.log10(a+b)+1);
		}

	}
}

Measured memory_bytes: 24544
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;

#define INF 1e9
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

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


int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<char>> c(h, vector<char> (w));
    rep(i, h) {
        rep(j, w) {
            cin >> c.at(i).at(j);
        }
    }
    rep(i, h) {
        rep(k, 2) {
            rep(j, w) {
                cout << c.at(i).at(j);
            }
            cout << endl;
        }
    }
}

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

int main() {
    ll n;
    cin >> n;
    string name;
    while(1){
        int x = n % 26;
        if (x == 0) x = 26;
        name += 'a' + x-1;
        n -= x;
        if(n == 0) break;
        n /= 26;
    }
  	reverse(name.begin(), name.end());
    cout << name << endl;
  
}

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

using namespace std;

#define ll long long

#define DEBUG (0)

int main()
{
  int A,B,C,D = 0;
  cin >> A >> B >> C >> D;

  int AOKI,TAKAHASHI = 0;
  if(C%B == 0){
    AOKI = C/B;
  }else{
    AOKI = C/B+1;
  }

  if(A%D == 0){
    TAKAHASHI = A/D;
  }else{
    TAKAHASHI = A/D+1;
  }

  if(AOKI <= TAKAHASHI){
    cout << "Yes" << "\n";
  }else{
    cout << "No" << "\n";
  }

}


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

#define ll long long
#define MOD int(pow(10,9)+7)

ll dp[int(pow(10,5)+1)][13] = {};

int main(void){
    string s;
    cin >> s;
    ll n = s.length();
    dp[0][0]=1;
    for(ll i=0;i<s.length();i++){
        ll c;
        if(s[i]=='?') c = -1;
        else c = s[i]-'0';
        for(ll j=0;j<10;j++){
            if (c != -1 && c != j) continue;
            for(ll k=0;k<13;k++){
                dp[i+1][(k*10+j)%13] += dp[i][k]; 
            }
        }
        for(ll j=0;j<13;j++){
            dp[i+1][j] %= MOD;
        }
    }
    cout << dp[n][5]<< endl;
    return 0;

}

Measured memory_bytes: 10624
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<ll, ll>
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
#define pr(s) cout << (s) << '\n'
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
const ll INF = 1E+18;
 
 
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n, k;
    cin >> n >> k;
    vl p(n), c(n);
    rep(i, n) {
        cin >> p[i];
        p[i]--;
    }
    rep(i, n) {
        cin >> c[i];
    }
    vector<P> cycle(n);
    rep(i, n) {
        vector<bool> used(n);
        ll now = i;
        ll score = 0;
        ll num = 0;
        while (1) {
            if (used[p[now]]) break;
            now = p[now];
            score += c[now];
            used[now] = true;
            num++;
        }
        cycle[i] = P(score, num);
    }
    ll ans = -INF;
    rep(i, n) {
        ll res = -INF;
        ll num = k;
        ll score = 0;
        ll now = i;
        if (k<=n*2) {;}
        else if (cycle[i].first>0) {
            ll z = k/cycle[i].second;
            z--;
            if (z<0) z = 0;
            score += cycle[i].first*z;
            num -= cycle[i].second*z;
        }
        else {
            num %= cycle[i].second;
            num += cycle[i].second;
            if (num>k) num = k;
        }
        //debug(num);
        while (num>0) {
            now = p[now];
            score += c[now];
            //debug(res);
            chmax(res, score);
            num--;
        }
        chmax(ans, res);
    }
    
    pr(ans);
    return 0;
}

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

int main(){
    int k;
    cin >> k;
    vector<ll> a;
    for(int i=1; i <= 9; i++) a.push_back(i);
    while(1){
        if(k<=a.size()){
            cout << a[k-1] << endl;
            return 0;
        }
        k -= a.size();
        vector<ll> old;
        swap(old, a);
        for(ll x: old){
            for(int i=-1; i<=1; i++){
                int d = x%10 + i;
                if(d<0 || d>9) continue;
                ll nx = x*10 + d;
                a.push_back(nx);
            }
        }
    }
    return 0;
}

Measured memory_bytes: 4640
//
//  main.cpp
//  ProCon
//
//  Created by hashimotoryoma on 2017/08/20.
//  Copyright © 2017年 hashimotoryoma. All rights reserved.
//

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

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

using namespace std;

typedef long long ll;

int group(int n){
    if(n==2)
        return 2;
    else if(n==4 || n==6 || n==9 || n==11)
        return 1;
    else
        return 0;

}

int main() {
    // insert code here...    return 0;
    //////
    // input from txt
    /*
     std::ifstream in("input.txt");
     std::cin.rdbuf(in.rdbuf());
     std::ofstream out("output.txt");
     std::cout.rdbuf(out.rdbuf());
     ////
     */
    string N;
    cin >> N;
    cout <<(N[0]==N[2]? "Yes":"No")<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int i,a[30],k,b[40];
  for(k=1;k<=30;k++){
    b[k]=0;
  }
  for(i=0;i<28;i++){
    scanf("%d",&a[i]);
    for(k=1;k<=30;k++){
      if(a[i]==k){
	b[k]=k;
      }
    }
  }
  for(k=1;k<=30;k++){
    if(b[k]==0){
      printf("%d\n",k);
    }
  }
  return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;

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

		long H=sc.nextLong();
		long W=sc.nextLong();
		long diff=1000000007;

		long ni_kiriwake=0;

		long tmp1=0,tmp2=0,tmp3=0,tmp4=0;
		if(H%3==0 || W%3==0) {		//どちらかの辺が３の倍数ならば無条件でみんな同じ面積に切り分けることができる
			System.out.println(0);
		}

		else if(H==W) {		//正方形の時
			ni_kiriwake=(H+1)/2;

			for(int i=1; i<W; i++) {
				tmp1=(H-ni_kiriwake)*(W-i);
				tmp2=ni_kiriwake*(W-i);
				tmp3=H*i;
				tmp4=Math.max(tmp1, Math.max(tmp2, tmp3))-Math.min(tmp1, Math.min(tmp2, tmp3));
				diff=Math.min(diff, tmp4);
			}

			if(H>3) {
				diff=Math.min(diff, H);		// 320x320 なら 107　107　106*320　みたいに
			}
			System.out.println(diff);
		}

		else if(H!=W) {
			ni_kiriwake=(H+1)/2;

			for(int i=1; i<W; i++) {
				tmp1=ni_kiriwake*i;
				tmp2=(H-ni_kiriwake)*i;
				tmp3=H*(W-i);
				tmp4=Math.max(tmp1, Math.max(tmp2, tmp3))-Math.min(tmp1, Math.min(tmp2, tmp3));
				diff=Math.min(diff, tmp4);
			}

			if(H>3) {
				diff=Math.min(diff,W);		// 320x320 なら 107　107　106*320　みたいに
			}

			ni_kiriwake=(W+1)/2;

			for(int i=1; i<H; i++) {
				tmp1=ni_kiriwake*i;
				tmp2=(W-ni_kiriwake)*i;
				tmp3=W*(H-i);
				tmp4=Math.max(tmp1, Math.max(tmp2, tmp3))-Math.min(tmp1, Math.min(tmp2, tmp3));
				diff=Math.min(diff, tmp4);
			}

			if(W>3) {
				diff=Math.min(diff,H);		// 320x320 なら 107　107　106*320　みたいに
			}

			System.out.println(diff);
		}
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll; const ll MM = 1000000000;ll mod = MM + 7;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;

int main() {
  ll n; cin >> n;
  Rep(i, 1, 50000) {
    double a = (double)i * 1.08;
    a = (ll)a;
    if(a == n) {
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
}

Measured memory_bytes: 256
#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++)
#define fr(i,x,n) for(int i=x;i<=n;i++)
#define rf(i,n,x) for(int i=n;i>=x;i--)
#define mst(x,i) memset(x,i,sizeof(x))
#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define PB push_back
#define X first
#define Y second
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long LL;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int maxn=1E5+5;
const int maxm=1E5+5;
const int inf=0x3f3f3f3f;
const LL INF=0x3f3f3f3f3f3f3f3f;
const LL mod=1E9+7;
const double eps=1E-6;
const double PI=acos(-1.0);
LL dp[maxn],w[maxn],v[maxn];
void solve(){
    int n,W,sum=0;
    cin>>n>>W;
    rep(i,n) cin>>w[i]>>v[i],sum+=v[i];
    mst(dp,0x3f);
    dp[0]=0;
    rep(i,n){
        rf(j,sum-v[i],0){
            dp[j+v[i]]=min(dp[j+v[i]],dp[j]+w[i]);
        }
    }
    int ans=0;
    fr(i,0,sum) if(dp[i]<=W) ans=max(ans,i);
    cout<<ans<<"\n";
}
int main(){
    IOS;
    int T=1;
    //cin>>T;
    while(T--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 4348
import scala.io.StdIn

object Main extends App {

  val Array(r, c) = StdIn.readLine().split(' ').map(_.toInt)
  val result = Array.fill(r, c+1)(0) 
  val temp = Array.fill(c+1)(0)
  
  (0 until r).foreach{ i =>
    result(i) = (StdIn.readLine() + " 0").split(' ').map(_.toInt)
    result(i)(c) = result(i).sum

    (0 to c).foreach{ k =>
      temp(k) += result(i)(k)
    }
  }

  (0 until r).foreach{ i =>
    println(result(i).toList.mkString(" "))
  }
  println(temp.toList.mkString(" "))
  
}



Measured memory_bytes: 48884
k, a, b = map(int, input().split())
count= 0
cookies = 1
if b-a <= 2:
    cookies = k+1
else:
    while count < k:
        if k - count <= 1:
            cookies += 1
            count +=1
        elif cookies >= a and k-count >= 2:
            cookies += (b - a)*((k-count)//2)
            count +=((k-count)//2)*2
        elif cookies < a:
            cookies += a-1
            count += a-1
print(cookies)

Measured memory_bytes: 3064
module Boolean
	def -@
		!self
	end

	def *(other)
		self & other
	end	

	def +(other)
		self | other
	end	

	def >(other)
		!self | other
	end	
end

class TrueClass; include Boolean; end
class FalseClass; include Boolean; end

T = true
F = false

loop do
	s = gets.chomp
	break if s == ?#
	vars = s.scan(/[a-z]/).uniq

	s.sub!(?=, '==')
	s.gsub!('->', '>')

	puts [?T, ?F].repeated_permutation(vars.size).all?{|assign|
		eval s.tr(vars.join, assign.join)	
	} ? 'YES' : 'NO'
end

Measured memory_bytes: 11340
while 1:
    l = input()
    if l==0: break
    c = []; m = 0;
    for i in xrange(12):
        c += map(int, raw_input().split())
    for i in xrange(0,24,2):
        m += c[i]-c[i+1]
        if m>=l:
            print i/2+1; break;
    if m<l:
        print "NA"

Measured memory_bytes: 4212
import numpy as np 
x =[]
for i in range(5):
    x.append(int(input()))
x = np.array(x)
y = x.copy()
z = x%10
y[y%10 !=0] = y[y%10 !=0] + 10 - y[y%10 !=0]%10
if all(x%10==0):
    minz = 0
    print(sum(y))
else:
    minz = min(z[z%10!=0])
    print(sum(y)-10+minz)

Measured memory_bytes: 12396
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}

int main(){
    INT(n);
    string ans,front;
    int left=0,right=n-1,mid;
    out(left);
    cout.flush();
    cin>>front;
    if(front=="Vacant")return 0;
    out(right);
    cout.flush();
    cin>>ans;
    if(ans=="Vacant")return 0;
    while(left<right){
        mid=(right+left)/2;
        out(mid);
        cout.flush();
        cin>>ans;
        if(ans=="Vacant"){return 0;
        }else if(mid%2==0&&ans==front){
            left=mid;
        }else if(mid%2==1&&ans!=front){
            left=mid;
        }else if(mid%2==0&&ans!=front){
            right=mid;
        }else if(mid%2==1&&ans==front){
            right=mid;
        }
        if(right-left==1){
            out(right);
            cout.flush();
            cin>>ans;
            if(ans=="Vacant")return 0;
        }
    }
}

Measured memory_bytes: 3824
from itertools import combinations

N = int(input())
p = list(map(int, input().split()))

ans = 'NO'
p_sorted = list(sorted(p))
if p == p_sorted:
    ans = 'YES'
else:
    l = [i for i in range(N)]
    c = combinations(l, 2)
    for v in c:
        tmp = p.copy()
        tmp[v[0]], tmp[v[1]] = tmp[v[1]], tmp[v[0]]
        if tmp == p_sorted:
            ans = 'YES'
            break
print(ans)


Measured memory_bytes: 64740
# -*- coding: utf-8 -*-
"""



"""
import sys


def solve(N, M, A):
    MOD = 10**9 + 7
    A = set(A)
    dp = [0] * (N+1)
    dp[0] = 1
    dp[1] = 1 if 1 not in A else 0
    for i in range(2, N+1):
        if i in A:
            dp[i] = 0
        else:
            dp[i] = (dp[i-2] + dp[i-1]) % MOD
    return dp[-1]


def main(args):
    N, M = map(int, input().split())
    A = [int(input()) for _ in range(M)]
    ans = solve(N, M, A)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 13216
#!/usr/bin/env ruby

a,b,k = gets.split(' ').map(&:to_i)
if a <= k
  k -= a
  a=0 
elsif a > k
  a-=k
  k=0
end
if b <= k
  k-=b
  b = 0 
elsif b>k 
  b-=k                                                                                                   
end
puts "#{a} #{b}"


Measured memory_bytes: 1788
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace atcorder_keyence_2019
{
    struct DIFF_DATA
    {
        public int idx;
        public long diff;
    }

    class Program
    {
        static void Main(string[] args)
        {

            int cnt = int.Parse(Console.ReadLine());
            string[] dataA = Console.ReadLine().Split(' ');
            string[] dataB = Console.ReadLine().Split(' ');

            List<DIFF_DATA> ldd = new List<DIFF_DATA>();
            int changeCnt = 0;
            long changeDiff = 0;
            for (int i = 0; i < cnt; i++)
            {
                DIFF_DATA dd = new DIFF_DATA();

                long ia = int.Parse(dataA[i]);
                long ib = int.Parse(dataB[i]);

                if (ia > ib)
                {
                    dd.idx = i;
                    dd.diff = ia - ib;
                    ldd.Add(dd);
                }
                else if (ia < ib)
                {
                    changeCnt++;
                    changeDiff += ib - ia;
                }
            }

            int ret = 0;

            if (0 < changeCnt)
            {

                //ソート
                ldd.Sort((a, b) => a.diff.CompareTo(b.diff));

                ret = -1;

                for (int i = ldd.Count - 1; 0 <= i; i--)
                {
                    changeDiff -= ldd[i].diff;
                    changeCnt++;
                    if (changeDiff <= 0)
                    {
                        ret = changeCnt;
                        break;
                    }
                }

            }

            Console.WriteLine(ret);
        }
    }
}


Measured memory_bytes: 38108
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    ll x, y;
    cin >> x >> y;
    ll ans = 0;

    if (x == 3)
    {
        ans += 100000;
    }
    else if (x == 2)
        ans += 200000;
    else if (x == 1)
        ans += 300000;

    if (y == 3)
    {
        ans += 100000;
    }
    else if (y == 2)
        ans += 200000;
    else if (y == 1)
        ans += 300000;

    if (x == 1 && y == 1)
    {
        ans += 400000;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
    cin.tie(NULL); cout.tie(NULL);
    ios_base:: sync_with_stdio(false);
    ll n;cin>>n;
    vector< pair< pair<ll,ll> , ll > >a(2*n);
    for(ll i=0;i<n;i++)cin>>a[i].first.first>>a[i].first.second,a[i].second=0;
    for(ll i=n;i<2*n;i++)cin>>a[i].first.first>>a[i].first.second,a[i].second=1;
    sort(a.begin(),a.end());
    multiset<ll> st;
    ll ans = 0;
    for(ll i=0;i<2*n;i++){
        if(a[i].second==0)st.insert( -1 * a[i].first.second);
        else{
            auto ele= upper_bound(st.begin(),st.end(),-1*a[i].first.second);
            if(ele==st.end())continue;
            ans++;
            st.erase(ele);
        }
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

const int mod = 1000000007;
int a[100];
long long dp[2][100001];

int main() {
    int n, k, i, j;
    
    scanf("%d %d", &n, &k);
    
    for (i = 0; i < n; i++) scanf("%d", &a[i]);
    
    dp[0][0] = 1;
    
    for (i = 0; i < n; i++) {
        long long sum = 0;
        
        for (j = 0; j <= k; j++) {
            sum += dp[0][j];
            if (j - a[i] - 1 >= 0) sum -= dp[0][j - a[i] - 1];
            while (sum >= mod) sum -= mod;
            while (sum < 0) sum += mod;
            
            dp[1][j] = sum;
        }
        
        for (j = 0; j <= k; j++) {
            dp[0][j] = dp[1][j];
            dp[1][j] = 0;
        }
    }
    
    printf("%lld\n", dp[0][k]);
    
    return 0;
}


Measured memory_bytes: 1664
def examA():
    N = I()
    ans = 0
    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    N = I()
    A = LI()
    dp = 1
    for i in range(N):
        dp |= dp<<A[i]
    S = (sum(A)+1)//2
    ans = -1
    for i in range(S,2*S+1):
        if dp&(1<<i)>0:
            ans = i
            break
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

from decimal import Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examC()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

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

int main(){
  int r,D;
  long long x;
  cin >> r >> D >> x;
  
  for (int i=0;i<10;i++){
    x = r*x - D;
    cout << x << "\n";
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#define maxn 105
#define R register
#define INF 0x3f3f3f3f
using namespace std;
typedef long long lxl;
const lxl mod = 1e9+7;

inline lxl read()
{
	lxl x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') {x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
	return x*f;
}

inline lxl fmi(lxl a,lxl b)
{
	lxl ans=1;
	while(b>0)
	{
		if(b&1) ans=(ans*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return ans;
}

lxl n,h[maxn],H[maxn],W[maxn],X[maxn],Rm[maxn],tot;
int d[maxn][20],lg[maxn];
std::vector<int> ch[maxn];

inline void init()
{
	lg[0]=-1;
	for(R int i=1;i<=n;++i)
		lg[i]=lg[i>>1]+1;
	for(R int i=1;i<=n;++i)
		d[i][0]=h[i];
	for(R int j=1;j<=15;++j)
		for(R int i=1;i+(1<<(j-1))<=n;++i)
			d[i][j]=min(d[i][j-1],d[i+(1<<(j-1))][j-1]);
}

inline int query(int l,int r)
{
	int k=lg[r-l+1];
	return min(d[l][k],d[r-(1<<k)+1][k]);
}

inline int build(int l,int r,int fa)
{
	if(l>r) return 0;
	int p=++tot;
	int x=X[p]=query(l,r);
	H[p]=X[p]-X[fa];
	W[p]=r-l+1;
	int tl=l-1,tr=l-1;
	for(R int i=l;i<=r;++i)
	{
		if(h[i]==x&&tl<tr)
			ch[p].push_back(build(tl+1,tr,p));
		if(h[i]==x) tl=i,++Rm[p];
		else tr=i;
	}
	if(tl<tr) ch[p].push_back(build(tl+1,tr,p));
	return p;
}

lxl f[maxn][2];

inline void dp(int u)
{
	lxl res1=1,res2=1;
	for (std::vector<int>::iterator it = ch[u].begin(); it != ch[u].end(); ++it)
	{
		dp(*it);
		res1=(res1*f[*it][0])%mod;
		res2=(res2*((f[*it][0]*2%mod+f[*it][1])%mod))%mod;
	}
	f[u][0]=(fmi(2,H[u])*res1)%mod;
	f[u][1]=(fmi(2,Rm[u])*res2+(mod-2*res1%mod)%mod)%mod;
}

int main()
{
	n=read();
	for(R int i=1;i<=n;++i)
		h[i]=read();
	init();
	int rt=build(1,n,0);
	dp(rt);
	printf("%lld",(f[rt][1]+f[rt][0])%mod);
	return 0;
}


Measured memory_bytes: 256
import Control.Monad

main = do
  [n,c] <- fmap (map read . words) getLine
  xs <- replicateM n (fmap ((\(x:v:_)->(x,v)) . map read . words) getLine)
  print (solve c xs)


-- MaxState, CurrentState, CurrentX
type State = (Int, (Int, Int))

solve :: Int -> [(Int,Int)] -> Int
solve c xs =
  solveTurn roundR roundL
  where
    roundR = scanl f (0,(0,0)) xs
    roundL = scanr (flip f) (0,(0,0)) [(c-x,v)|(x,v)<-xs]

    f (m,(s,y)) (x,v) = let s' = s-(x-y)+v in (max m s', (s', x))


solveTurn :: [State] -> [State] -> Int
solveTurn ss1 ss2 =
  maximum (go ss1 ss2 ++ go ss2 ss1)
  where
    go :: [State] -> [State] -> [Int]
    go [(m1,(s1,x1))]     _                  = [m1]
    go ((m1,(s1,x1)):ss1) ((m2,(s2,x2)):ss2) = s1+m2-x1 : go ss1 ss2

Measured memory_bytes: 232828