akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int n, i, j, k, a, b, ans, m, x;
	cin >> n;
	vector<vector<int>> adj(n + 1);
	for (i = 0; i < n - 1; i++) {
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}

	vector<int> parent(n + 1, -1), s(n + 1, 1);
	queue<int> q;
	stack<int> st;
	parent[1] = 0;
	q.push(1);
	while (!q.empty()) {
		int id = q.front();
		q.pop();
		for (auto p : adj[id]) {
			if (parent[p] == -1) {
				parent[p] = id;
				st.push(p);
				q.push(p);
			}
		}
	}

	while (!st.empty()) {
		int id = st.top();
		st.pop();
		s[parent[id]] += s[id];
	}

	vector<int> path;
	x = n;
	do {
		path.push_back(x);
		x = parent[x];
	} while (x > 0);

	m = path.size();
	if (m % 2 == 0) x = path[(m - 1) / 2];
	else x = path[m / 2 - 1];

	b = s[x];
	a = n - b;

	if (a > b) cout << "Fennec\n";
	else cout << "Snuke\n";

	return 0;
}


Measured memory_bytes: 7416
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;
typedef pair<int,int>P;

int main() {

  string t,g;cin>>t>>g;

  if(t[0]==g[2]&&t[1]==g[1]&&t[2]==g[0])out("YES")
  else out("NO")

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string str;
    cin>>str;
    int maxday = 0;
    for(int i=0; i<3; i++){
        int days = 0;
        while(i<3 && str[i]=='R'){
            days++;
            i++;
        }

        maxday = max(days, maxday);
    }

    cout<<maxday<<'\n';
    
    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<lli,lli> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
#define deb(x) cout << #x": " << (x) << endl;

const int N = 2e4;
const lli INF = 1e18+10;
const lli MOD = 1e9+7;
const ld EPS = 1e-9;

lli SUM(lli a, lli b, lli mod=MOD){
	return (a+b+mod)%mod;
}

lli PROD(lli a, lli b, lli mod=MOD){
	return a*b % mod;
}


lli powm(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = (res * a)%MOD;
		a = (a*a)%MOD;
		b/=2;
	}
	return res;
}

lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}
// ---- コーディングはここから！ ('-')7




int main(){_
	int n; cin>>n;
	map<ii,int>x;
	lli z = 0;
	fore(i,0,n){
		lli a,b; cin>>a>>b;
		if(a==0 and b==0){
			z++;
			continue;
		}
		lli u = gcd(abs(a),abs(b));
		if(a<0)a*=-1,b*=-1;
		if(a==0)b=abs(b);
		x[{a/u,b/u}]++;
	}
	lli res = 1;
	for(auto &[a,b]:x){
		if(!b)continue;
		lli c = -a.f, d = a.s,u=0;
		if(d<0)c*=-1, d*=-1;
		else if(d==0 and c<0)c*=-1;
		if(x.count({d,c})){
			u=x[{d,c}];
			x[{d,c}]=0;
		}
		res= PROD(res,SUM(SUM(powm(2,u),powm(2,b)),-1));
	}
	cout<<SUM(res,z-1)<<ENDL;

}


Measured memory_bytes: 16120
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    vector<int> x(n);
    int sum = 0;
    rep(i, n) {
        cin >> x[i];
        sum += x[i];
    }

    ll dp[n+1][n+1][sum+1];  // dp[i+1][j][k] : i番目(iは0-index)まででj枚選んで合計kになる場合の数
    
    rep(j, n+1) {
        rep(k, sum+1) {
            dp[0][j][k] = 0;
        }
    }

    dp[0][0][0] = 1LL;
    rep(i, n) {
        rep(j, n+1) {
            rep(k, sum+1) {

                dp[i+1][j][k] = dp[i][j][k];

                if(j >= 1 && k >= x[i]) {
                    dp[i+1][j][k] += dp[i][j-1][k-x[i]];
                }
            }
        }
    }
    
    ll ans = 0;
    for(int j = 1; j <= n; j++) {
        if(j*a <= sum) {
            ans += dp[n][j][j*a];
        }
    }

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

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/11/22  Problem: 012_agc_a / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;

LL ans = 0LL;

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

	cin >> N;
	N *= 3;
	VL a(N);
	FOR(i, 0, N) { cin >> a[i]; }
	SORT(a);
	int cnt = 0;
	for (int i = N - 2; cnt<N/3; i -= 2) {
		ans += a[i];
		cnt++;
	}
	cout << ans << "\n";

	return 0;
}

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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define ALL(obj)	(obj).begin(),(obj).end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define VEC vector

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;
typedef vector<int>				Vint;
typedef vector<Vint>			VV;

template<typename T>string join(const v(T)&v)
{stringstream s;REP(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define MAX 		400010

const ll LINF = (ll)9e18+7;		//
const int INF = 100100100;			//2,147,483,647 (Max int)
const ll MOD = 1e9+7;
// テンプレ終了
//====================================================================//

// int DP[MAX];

//
int main(){
	int N;cin>>N;
	Vint L(N);
	REP(i,N)cin>>L[i];

	sort(ALL(L));

	ll ans = 0;

	REP(a,N-1)REPS(b,a+1,N){
		int l = lower_bound(ALL(L),L[a]+L[b]) - L.begin();
		int r = upper_bound(ALL(L),L[b]-L[a]) - L.begin();
		// cout << a << " " << b << endl;
		r = max(a+1,r);
		// cout << " " << r << " " << l << endl;
		int suml = (l-r);
		if(r<=b && b<=l)suml--;
		// cout << "=" << suml << endl;
		ans += suml;
	}

	cout << ans/2 << endl;

	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define debug(x) cerr<<#x<<": "<<x<<endl;
#define MOD 1000000007ULL;
#define rep(i,n) for(int i=0;i<n;i++)


int main() {
	ll N;
  	cin>>N;
    int count[10000000];
  	rep(i,N) count[i]=0;
  
  	rep(x,100){
     	rep(y,100){
         	rep(z,100){
              int s=x+1,t=y+1,u=z+1;
              int ans=s*s+t*t+u*u+s*t+t*u+u*s;
              if(ans>10000) continue;
              count[ans]++;
            }
        }
    }
  
  	rep(i,N) cout<<count[i+1]<<endl;
  	
  	
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 998244353;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

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

template <class T>
T pow_ (T x, T n, T M){
    uint64_t u = 1, xx = x;
    while (n > 0){
        if (n&1) u = u * xx % M;
        xx = xx * xx % M;
        n >>= 1;
    }
    return static_cast<T>(u);
};



int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    int sum = accumulate(v.begin(), v.end() , 0);
    auto dp = make_v(n+1, sum+1, 0LL);
    dp[0][0] = 1;
    auto dp2 = dp;
    int x = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= x; ++j) {
            (dp[i+1][j+v[i]] += dp[i][j]) %= MOD;
            (dp[i+1][j] += dp[i][j]*2) %= MOD;
            (dp2[i+1][j+v[i]] += dp2[i][j]) %= MOD;
            (dp2[i+1][j] += dp2[i][j]) %= MOD;
        }
        x += v[i];
    }
    ll ans = pow_(3, n-1, MOD);
    for (int i = (sum+1)/2; i <= sum; ++i) {
        (ans += MOD - dp[n][i]) %= MOD;
    }
    if(sum%2 == 0){
        (ans += dp2[n][sum/2]) %= MOD;
    }
    cout << (ans*3)%MOD << "\n";
    return 0;
}


Measured memory_bytes: 423104
#include<stdio.h>
int main(void)
{
	int a,b,c,i,x;
	x=0;
	scanf("%d %d %d",&a,&b,&c);
	for(i=a;i<=b;i++)
	{
		if(c%i==0)
		{
			x=x+1;
		}
	}
	printf("%d\n",x);
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

string s;
int N, a, b, cnt, dob;

int main()
{
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> s;
        int sz = s.size();
        b += s[0] == 'B', a += s[sz - 1] == 'A';
        if (s[0] == 'B' && s[sz - 1] == 'A')
            a--, b--, dob++;
        for (int j = 0; j + 1 < sz; j++)
            cnt += s[j] == 'A' && s[j + 1] == 'B';
    }
    if (dob > 0 && (a > 0 || b > 0))
        a++, b++;
    cout << cnt + min(a, b) + (dob - 1) * (dob >= 2) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int a[222];
int n;

bool is_sorted()
{
	for(int i=0;i+1<n;i++)
	{
		if(a[i]>a[i+1]) return false;
	}
	return true;
}

vi moves;

void cyc()
{
	for(int i=1;i<n;i++) swap(a[i],a[i-1]); 
	moves.pb(1);
}

void swp()
{
	swap(a[0],a[n-1]); moves.pb(n-1);
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	while(!is_sorted())
	{
		vi swapid;
		for(int i=n-2;i>=0;i--)
		{
			if(!swapid.empty()&&swapid.back()==i+1) continue;
			if(a[i]>a[i+1]) swapid.pb(i);
		}
		for(int i=0;i<n;i++)
		{
			cyc();
			if(!swapid.empty()&&swapid.back()==i) {swp();swapid.pop_back();}
		}
	}
	cout<<moves.size()<<'\n';
	for(int v:moves) cout<<v<<'\n';
}


Measured memory_bytes: 764
n, k = map(int, input().split())

# a, b, cいずれもkの倍数か、kが偶数かつa, b, cをkで割った余りが等しい
ans = (n//k)**3
if k%2 == 0:
    ans += (len(range(k//2, n+1, k)))**3
print(ans)

Measured memory_bytes: 2940
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val a = sc.nextLong()
    val op = sc.next()
    val b = sc.nextLong()
    val out = op match {
      case "+" => a + b
      case "-" => a - b
    }
    print(out)
  }
}


Measured memory_bytes: 22336
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String next = "Sunny";
        if (line.equals("Sunny")) {
        	next = "Cloudy";
        } else if (line.equals("Cloudy")) {
        	next = "Rainy";
        } else if (line.equals("Rainy")) {
        	next = "Sunny";
        }

        System.out.println(next);


    }

    



}

Measured memory_bytes: 21076
#include<iostream>
using namespace std;
int main()
{
    // 文字列の入力
    string s;
    cin >> s;
  	if(s[2]==s[3] && s[4]==s[5])
      cout << "Yes" << endl;
    else
      cout << "No" << endl; 
    return 0;
}

Measured memory_bytes: 3068
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <map>
#include <sstream>
// #include <bits/stdc++.h>
#define req(i,h) for(int i = h; i > 0; i--)

using namespace std;


int main(void) {
   string s;
   cin >> s;
   int t,count = 0,cou = 0;
   t = s.length();
   if(s.at(0) == 'A') {
       for(int i = 2; i < s.length()-1; i++) {
           if(s.at(i) == 'C') {
               count++;
           }
       }
       if(count == 1) {
           for(int i = 0; i < s.length(); i++) {
               if(65 <= s.at(i) && s.at(i) <= 90) {
                   cou++;
               }
           }
           if(cou == 2) {
               cout << "AC" << endl;
               return 0;
           }
       }
   }
   cout << "WA" << endl;

    return 0;
}


Measured memory_bytes: 256
//ΔABC 070A
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
int main()
{
	int n;
	cin>>n;
	if(n/100==n%10)
		cout<<"Yes\n";
	else
		cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n[6];
    for(int i=0;i<6;i++)
    cin >> n[i];
    cout << (n[0]+5*n[1]+10*n[2]+50*n[3]+100*n[4]+500*n[5]>=1000) << endl;
}


Measured memory_bytes: 3112
#include<cstdio>
#include<algorithm>
using namespace std;
#define M 2005
typedef long long ll;
const int maxn=2e9;
struct qwe{
    int a,c;
}kk[M<<1];
int cnt,k[M],dp[M],dp2[M],ans[M],se[M];
char S[M];
int read(){
    ll l=0,f=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')f=0;ch=getchar();}
    while(ch>='0'&&ch<='9'){l=(l<<1)+(l<<3)+(ch^'0');ch=getchar();}
    return f?l:-l;
}
void dfs1(int x,int fa){
    int v,l=0,q=0,p=0;
    dp[x]=se[x];
    dp2[x]=ans[x]=0;
    for(int i=k[x];i;i=kk[i].c)if((v=kk[i].a)!=fa){
        dfs1(v,x);
        if(dp2[v]+dp[v]>l)l=dp2[v]+dp[v],p=ans[v];
        dp[x]+=dp[v];
        dp2[x]+=dp2[v]+dp[v];
    }
    q=dp2[x];
    if(l*2<=q)ans[x]=q>>1;
    else ans[x]=(q-l)+min(p,(2*l-q)>>1);
}
void jia(int x,int y){kk[++cnt].a=y;kk[cnt].c=k[x];k[x]=cnt;}
int main(){
    int n,x,y,uns=maxn;
    n=read();
    scanf("%s",S);
    for(int i=0;i<n;++i)se[i+1]=S[i]-'0';
    for(int i=1;i<n;++i){
        x=read();y=read();
        jia(x,y);jia(y,x);
    }
    for(int i=1;i<=n;++i){
        dfs1(i,0);
        if(((dp2[i]&1)==0)&&(ans[i]==dp2[i]/2))uns=min(ans[i],uns);
        // printf("dp2 %d ans %d\n",dp2[i],ans[i]);
    }
    if(uns!=maxn)printf("%d\n",uns);
    else puts("-1");
    getchar();
    getchar();
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i,n) cin >> d[i];
    sort(d.begin(),d.end());
    cout << d[n/2] -d[n/2-1] << endl;
    
    return 0;
}


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

int main(){
    string s, t;
    cin >> s >> t;
    int a,b;
    cin >> a >> b;
    string r;
    cin >> r;
    if(s == r) cout << a-1 << " " << b << endl;
    else cout << a << " " << b-1 << endl;
    return 0;
}

Measured memory_bytes: 256
import math

a, b, k = map(int, input().split())

if math.ceil((b - a - 1) / 2) + 1 >= k + 1:
    for i in range(a, a + k):
        print(i)
    for i in range(b - k + 1, b + 1):
        print(i)
else:
    for i in range(a, b + 1):
        print(i)


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

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

    ll n, s, t;
    int q;
    cin >> n >> q >> s >> t;
    n /= 2; s--; t--;

    using P = pair<ll, ll>;
    VV<P> ok(q + 1);
    ok[q].push_back({t, t + 1});

    for (int ph = q - 1; ph >= 0; ph--) {
        for (auto p: ok[ph + 1]) {
            ll lw = p.first, up = p.second;
            assert(lw <= up);
            if (lw < n && up <= n) {
                ok[ph].push_back({2 * lw, 2 * up});
            } else if (n <= lw && n <= up) {
                ok[ph].push_back({2 * (lw - n), 2 * (up - n)});
            } else {
                ok[ph].push_back({2 * lw, 2 * n});
                ok[ph].push_back({0LL, 2 * (up - n)});
            }
        }
        sort(ok[ph].begin(), ok[ph].end());
        V<P> buf;
        for (auto p: ok[ph]) {
            if (!buf.empty() && p.first <= buf.back().second) {
                buf.back().second = max(buf.back().second, p.second);
                continue;
            }
            buf.push_back(p);
        }
        ok[ph] = buf;

/*        for (auto p: ok[ph]) {
            cout << "(" << p.first << " " << p.second << "), ";
        }
        cout << endl;*/
    }

    auto contain = [&](int ph, ll x) {
        for (auto p: ok[ph]) {
            if (p.first <= x && x < p.second) return true;
        }
        return false;
    };

    if (!contain(0, s)) {
        cout << -1 << endl;
        return 0;
    }

    V<int> ans;
    for (int i = 1; i <= q; i++) {
        int f = s % 2; s /= 2;
        if (contain(i, s)) {
            ans.push_back(f ^ 0);
        } else {
            s += n;
            assert(contain(i, s));
            ans.push_back(f ^ 1);
        }
    }

    for (int d: ans) {
        cout << d << "\n";
    }

    return 0;
}


Measured memory_bytes: 71284
//
//  aaaaa.c
//  
//
//  Created by Fourier Shuzaei on 2018/05/26.
//
b;x;
main(a){
    scanf("%d",&a);
    char n[a+1];
    int c[a],d[a],e[a];
    scanf("%s",&n);
    for(b=0;b<a;++b){
        c[b]=(n[b]=='W'?1:-1);
    }

    d[0]=(c[0]==1?1:0);
    for(b=1;b<a;++b){
        if(c[b]==1)d[b]=d[b-1]+1;
        else d[b]=d[b-1];
    }

    e[a-1]=(c[a-1]==1?0:1);
    for(b=a-2;b>-1;--b){
        if(c[b]==1)e[b]=e[b+1];
        else e[b]=e[b+1]+1;
    }

    int p,q;
    if(e[1]<d[a-2]){p=e[1];q=0;}
    else{p=d[a-2];q=a-1;}

    for(b=1;b<a-1;++b){
        int t = e[b+1]+d[b-1];
        if (t<p){p=t;q=b;}
    }
    printf("%d",p);

}


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

using namespace std;

const int N = 110;

int res, n;
char str[N];

int main()
{
    cin >> n >> str;
    for(int i = 0; i < n - 2; i++)
        if(str[i] == 'A' && str[i + 1] == 'B' && str[i + 2] == 'C')
            res++;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long N = sc.nextLong();
    long M = sc.nextLong();
    if(N>=M/2){//Sが多い時は、cの数/2でいい
      System.out.println(M/2);
      return;
    }
    //cのほうが2倍の分多いときは、(2*N+M)/4でいい
    System.out.println((2*N+M)/4);
      
  }
  

  
}


Measured memory_bytes: 23764
N, K = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)
MOD = 10 ** 9 + 7

def mod_pow(x, n, mod)
  return 1 if n == 0
  res = mod_pow(x * x % mod, n / 2, mod)
  if n[0] == 1
    res = res * x % mod
  end
  res
end

count1 = 0
(0...N).each do |i|
  n = as[i]
  (0...N).each do |j|
    count1 += 1 if n > as[j]
  end
end
count1 = count1 % MOD
count1 = (count1 * (K * (K - 1) / 2 % MOD)) % MOD if K > 1

count2 = 0
(0...N).each do |i|
  n = as[i]
  ((i + 1)...N).each do |j|
    count2 += 1 if n > as[j]
  end
end

ans = (count1 + (count2 * K % MOD)) % MOD
puts ans


Measured memory_bytes: 3836
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string>

using namespace std;

int main(void)
{
	int N;
	cin >> N;
	for (int i = N; i < 1000; i++){
		int a = i % 10;
		int b = (i / 10) % 10;
		int c = i / 100;
		if (a == b && b == c){
			cout << i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

double radians(int a)
{
  return a * M_PI / 180;
}

int main()
{
  int len, d, a = 90;
  double x = 0, y = 0;
  for (;;) {
    scanf("%d,%d", &len, &d);
    if (len == 0 && d == 0) break;
    x += len * cos(radians(a));
    y += len * sin(radians(a));
    a -= d;
  }
  printf("%d\n%d\n", (int)x, (int)y);
  return 0;
}

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

int main() {
	/*
	int a, b;
	std::cin >> a >> b;

	if (a - b * 2 > 0) {
		std::cout << a - b * 2;
	}
	else {
		std::cout << 0;
	}
	*/

	/*
	int N;
	std::cin >> N;
	std::vector<int> takoyaki;
	for (int i = 0; i < N; ++i) {
		int hoge;
		std::cin >> hoge;
		takoyaki.push_back(hoge);
	}

	int sum = 0;
	for (int i = 0; i < N - 1; ++i) {
		for (int j = i + 1; j < N; ++j) {
			sum += takoyaki[i] * takoyaki[j];
		}
	}
	std::cout << sum;
	*/

	/*
	int N;
	std::cin >> N;

	std::string S;
	std::cin >> S;

	int count = 1;
	for (int i = 0; i < N - 1; ++i) {
		if (S[i] != S[i + 1]){
			count += 1;
		}
	}
	std::cout << count;
	*/

	int N;
	std::cin >> N;
	int count = 0;

	std::vector<int> L(N);
	for (int i = 0; i < N; ++i) {
		std::cin >> L[i];
	}
	std::sort(L.begin(), L.end());

	for (int i = 0; i < N - 2; ++i) {
		for (int j = i + 1; j < N - 1; ++j) {
			for (int k = j + 1; k < N; ++k) {
				if (L[i] >= L[j] + L[k] || L[j] >= L[i] + L[k] || L[k] >= L[i] + L[j]) {
					break;
				}
				count++;
			}
		}
	}

	std::cout << count;

	return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
//#define N 100010
//#define M 61
//#define MOD 100003
//vector <pair<int,int> > edge[M];
//int d[N][N];
//priority_queue <pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> > >q;
//queue <int> q;
//ll cnte[N];
//int ans=0;
//vector <int> edge[N];
//int arr[N];
char ch[8][8];
char pro[8][8];
void solve()
{
	int h,w,K;
	cin>>h>>w>>K;
	int ans=0;
	for (int i=1;i<=h;i++)
		for (int j=1;j<=w;j++)
			cin>>ch[i][j];
	for (int i=0;i<(1<<h);i++)
		for (int j=0;j<(1<<w);j++)
		{
			for (int r=1;r<=h;r++)
				for (int c=1;c<=w;c++)
					pro[r][c]=ch[r][c];
			int k=1,l=1;
			int cnt;
			cnt=1;
			while (k<(1<<h))
			{
				if (k&i)
					for (int c=1;c<=w;c++)
						pro[cnt][c]='0';
				k<<=1;
				cnt++;
			}
			cnt=1;
			while (l<(1<<w))
			{
				if (l&j)
					for (int r=1;r<=h;r++)
						pro[r][cnt]='0';
				l<<=1;
				cnt++;
			}
	//		cout<<"i:"<<i<<endl; 变量名不要混了 
	//		cout<<"j:"<<j<<endl;
	//		for (int r=1;r<=h;r++)
	//		{
	//			for (int c=1;c<=w;c++)
	//				cout<<pro[r][c]<<" ";			
	//			cout<<endl;
	//		}
			int as=0;

			for (int r=1;r<=h;r++)
				for (int c=1;c<=w;c++)
					if (pro[r][c]=='#')
					{
						
						as++;
					}
	//		cout<<"as: "<<as<<endl;
	//		cout<<"k: "<<k<<endl;
			if (as==K)
				ans++;
		}
		cout<<ans<<endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
//	int t;
//	cin>>t;
//	while (t--)
		solve();
	return 0;
} 

Measured memory_bytes: 3580
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));
        int n = Integer.parseInt(br.readLine());
        int[] arr = new int[n];
        String[] tokens = br.readLine().split(" ");
        for(int i = 0; i < n; ++i)
            arr[i] = Integer.parseInt(tokens[i]) - (i+1);
        Arrays.sort(arr);
        if(n%2==1)
            System.out.println(got(arr, arr[n/2]));
        else {
            int res = (int)((long)arr[n/2] + arr[(n+1)/2])/2;
            System.out.println(got(arr, res));
        }
    }
    private static long got(int[] arr, int b){
        long res = 0;
        for(int i = 0, n = arr.length; i < n; ++i)
            res += Math.abs(arr[i] - b);
        return res;
    }
}

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

int main(){
  int N;
  cin >> N;
  N++;
  int64_t L1 = 2, L2 = 1, tmp;
  if (N == 1)
  cout << L1 << endl;
  else if (N == 2)
  cout << L2 << endl;
  else{
    for (int i = 0; i < N - 2; i++){
      tmp = L1;
      L1 = L2;
      L2 = L1 + tmp;
    }
    cout << L2 << endl;
  }
}

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

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[][] ary=new int[2][n];
        for(int i=0;i<n;i++){
            ary[0][i]=sc.nextInt();
            ary[1][ary[0][i]-1]=i+1;
        }
        sc.close();
        for(int i=0;i<n;i++){
            System.out.print(ary[1][i] +" ");
        }
        System.out.println();
    }
}

Measured memory_bytes: 62632
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;

int main(){
    ll x,y,a,b,c; cin >> x >> y >>a >> b >> c;
    vector<ll> p(a),q(b),r(c);
    rep(i,a) cin >> p.at(i);
    rep(i,b) cin >> q.at(i);
    rep(i,c) cin >> r.at(i);
    sort(p.rbegin(),p.rend());
    sort(q.rbegin(),q.rend());
    sort(r.rbegin(),r.rend());

    vector<ll> applelist(0);
    rep(i,x){
        applelist.push_back(p.at(i));
    }
    rep(i,y){
        applelist.push_back(q.at(i));
    }
    sort(applelist.begin(),applelist.end());

    for(int i=0;i<c;i++){
        if(x+y<=i) break;
        if(r.at(i)>applelist.at(i)){
            applelist.at(i) = r.at(i);
        }
    }
    
    ll ans = 0;
    rep(i,x+y){
        ans += applelist.at(i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4724
"use strict";
function main(input) {
  const h = parseInt(input[0]);
  let two = [1];

  let i=1;
  while(true){
    let a = two[i-1]*2;
    if(a<10000000000000){
      two[i] = a;
      i++;
    }else{
      break;
    }
  }
  for(let i=0;i<two.length;i++){
    if(h<two[i]){
      console.log(two[i]-1);
      break;
    }
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<ll, ll, ll> T;

int N, C;
vector<vector<int>> d(31, vector<int>(31, 0));
vector<vector<int>> c(501, vector<int>(501, 0));
vector<vector<P>> p(3);
vector<vector<P>> r(3);

int main(void){
    
    scanf("%d %d", &N, &C);
    for(int i = 0; i < C; ++i) for(int j = 0; j < C; ++j) scanf("%d", &d[i][j]);
    for(int i = 0; i < N; ++i) for(int j = 0; j < N; ++j) scanf("%d", &c[i][j]);
    for(int i = 0; i < N; ++i) for(int j = 0; j < N; ++j) p[(i + j) % 3].push_back(make_pair(i, j));
    
    for(int i = 0; i < C; ++i){
        for(int j = 0; j < 3; ++j){
            int cnt = 0;
            for(auto x : p[j]) cnt += d[c[x.first][x.second] - 1][i];
            r[j].push_back(make_pair(cnt, i));
        }
    }
    for(int i = 0; i < 3; ++i) sort(r[i].begin(), r[i].end());
    
    int ans = INT_MAX;
    for(int i = 0; i < 3; ++i){
        for(int j = 0; j < 3; ++j){
            if(r[0][i].second == r[1][j].second) continue;
            for(int k = 0; k < 3; ++k){
                if(r[0][i].second == r[2][k].second || r[1][j].second == r[2][k].second) continue;
                ans = min(ans, r[0][i].first + r[1][j].first + r[2][k].first);
            }
        }
    }
    printf("%d\n", ans);
    
    return 0;
}


Measured memory_bytes: 3624
{-# OPTIONS_GHC -O2 #-}
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import Data.Array.Unboxed
import Data.Array.ST
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Control.Monad.ST
import Data.STRef 
import Data.List
import Data.Char
import qualified Data.Map.Strict as M

main :: IO ()
main = do
    [r,c] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    css <- V.replicateM r $ VU.unfoldrN c BS.uncons <$> BS.getLine
    let all = runST $ do
        all <- newSTRef []
        forM_ [0..r-1] $ \i -> do
            forM_ [0..c-1]$ \j -> do
                when ('#' == (css V.! i) VU.! j) $ modifySTRef all ((i,j):)
        readSTRef all
    let solve = runST $ do
            arrived <- newArray ((0,0),(r-1,c-1)) (-1)
            go 0 all [] arrived
            where go :: Int -> [(Int,Int)] -> [(Int,Int)] -> STUArray s (Int,Int) Int -> ST s Int
                  go count [] [] _ = return count
                  go count [] ys arrived = go (count+1) ys [] arrived
                  go count ((v,w):xs) ys arrived = 
                    if not (0 <= v && v <= r-1 && 0 <= w && w <= c-1) then go count xs ys arrived 
                    else do
                        xx <- readArray arrived (v,w)
                        if xx == -1 then writeArray arrived (v,w) count >> go count xs ((v+1,w):(v-1,w):(v,w+1):(v,w-1):ys) arrived
                        else go count xs ys arrived
    print $ if length all == r*c then 0 else solve-1


Measured memory_bytes: 404860
S = input()
mae = S[0:2]
ato = S[2:4]
if '01' <= mae <= '12' and '01' <= ato <= '12':
    print('AMBIGUOUS')
elif '01' <= ato <= '12':
    print('YYMM')
elif '01' <= mae <= '12':
    print('MMYY')
else:
    print('NA')


Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<numeric>

#define endl "\n"
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define REP(i, n) for(int i = 0; i < n; i++)
using Graph = vector<vector<int>>;

int main(){
    ll x;
    cin>>x;
    ll k = 360 * x / gcd(360,x) / x;
    cout<<k<<endl;
}

Measured memory_bytes: 3596
#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 (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int 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 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-9;

bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}



signed main(void)
{
    ll n, a, b;
    cin >> n >> a >> b;
    ll r = 0;
    r = min(a*n, b);
    
    mes(r);
    
    
    
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a, b, c, d, n, k, sum=0;
  cin >> n >> k;
  vector<int> vec(k);
  
  for(int i=0; i<k; i++){
    cin >> vec.at(i);
  }
  
  bool brk = false;
  int i;
  
  for(i=n; i <= 99999; i++){
    int tmp = i;
    brk = false;
    
    while(tmp>0) {
      for(int j=0; j<k; j++){
        if((tmp%10) == vec.at(j)){
           brk = true;
           break;
        }
      }
      if(brk){
         break;
      }
      tmp /= 10;
    }
    if(!brk){
      break;
    }
  }
 
  
  cout << i << endl;
}


Measured memory_bytes: 256
// Indrajeet Mishra
 
/*#pragma warning(disable:4996)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")*/
 
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define test(s) if (!(s)) { cout << __LINE__ << " " << #s << endl; exit(-1); }
#define debug(x) do { std::cerr << x; } while (0)
#define endl "\n"
#define pb push_back
#define pf push_front
#define vll vector<ll>
#define dll deque<ll>
#define sll set<ll, greater <ll>>
#define mll map<ll, ll>
#define vii vector<int>
#define dii deque<int>
#define sii set <int, greater <int>>
#define mii map<int, int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mod 1000000007
#define inv2 500000004
#define inv6 166666668
#define N 1000005
#define inf 200000000
#define eps 1e-10
#define PI 3.14159265359
#define all(v) (v).begin(),(v).end()
#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))
#define gcd(a,b) __gcd(a,b)
 
ll dp[101][101];
void dp_initialiser(){
    memset(dp,-1,sizeof(dp));
}

int main() {
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    //dp_initialiser();
    ll n=0,k=0;cin>>n>>k;
    ll a[n]={0};
    rep(i,0,n)cin>>a[i];
    rep(i,k,n){
        if(a[i]>a[i-k])cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 5156
s = input()
s_len = len(s)
ans = 0
for i in range(1, s_len):
    if (s_len-i)%2 == 0:
        if s[:(s_len-i)//2] == s[(s_len-i)//2:s_len-i]:
            ans = s_len - i
            break
print(ans)

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

long min(long a, long b, long c) {
    if(a < b) {
        if(a < c) {
            return a;
        } else {
            return c;
        }
    } else {
        if(b < c) {
            return b;
        } else {
            return c;
        }
    }
}

int main() {
    int n;
    cin >> n;
    vector<long> a(n);
    long sum = 0;
    for(int i = 0; i < n; i++) {
        cin >> a.at(i);
        sum += a.at(i);
    }
    long ave1 = sum / n;
    long ave2 = ave1 - 1;
    long ave3 = ave1 + 1;
    
    long res1 = 0;
    long res2 = 0;
    long res3 = 0;
    
    for(int i = 0; i < n; i++) {
        res1 += pow((a.at(i) - ave1), 2);
        res2 += pow((a.at(i) - ave2), 2);
        res3 += pow((a.at(i) - ave3), 2);
    }
    long res = min(res1, res2, res3);
    
    cout << res << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int r,g,b,k; cin >> r >> g >> b >> k;
  // int xG =  ceil(log2(r/(double)g));
  // if (xG > k) {
  //   cout << "No" << endl;
  //   return 0;
  // }
  // k -= xG;
  // g *= pow(2, xG);
  // int xB =  ceil(log2(g/(double)b));
  // if (xB > k) {
  //   cout << "No" << endl;
  //   return 0;
  // } 
  // cout << "Yes" << endl;
  while (r >= g) {
    k--;
    g <<= 1; 
  }
  while (g >= b) {
    k--;
    b <<= 1;
  }
  if (k >=0 && b > g && g > r) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
 
int binarysearch(int q[], int key, int n)
{
    int left = 0;
    int right = n;
     
    while (left < right)
    {
        int mid = (left + right) / 2;
        if (q[mid] == key)  return 1;
        else if (q[mid] > key) right = mid;
        else left = mid + 1;
    }
    return 0;
}
 
int main()
{
    int n,a;
    scanf("%d", &n);
    int s[100000];
 
    for (int i = 0; i < n; i++) {
        scanf("%d", &a);
        s[i] = a;
    }
     
    int n_t, key;
    int sum = 0;
    scanf("%d", &n_t);
    for (int i = 0; i < n_t; i++) {
        scanf("%d", &key);
        if(binarysearch(s,key,n)) sum++;
    }
 
    printf("%d\n", sum);
}

Measured memory_bytes: 3064
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
void times(alias pred)(int n) {
    foreach(i; 0..n) pred();
}
auto rep(alias pred, T = typeof(pred()))(int n) {
    T[] res = new T[n];
    foreach(ref e; res) e = pred();
    return res;
}

void main() {
    int MOD = 26;
    int[] str = readln.chomp.map!(c => c-'a').array.to!(int[]);
    int K = readln.chomp.to!int;
    int i = 0;
    while(K > 0 && i<str.length) {
        while (i<str.length && str[i] == 0) i++;
        if (i>=str.length) break;
        if (MOD - str[i] <= K) {
            K -= MOD - str[i];
            str[i] = 0;
        }
        i++;
    }
    K %= MOD;
    str.back += K;

    str.map!(a => (a+'a').to!char).writeln;
}


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

int main()
{
    int n, x;
    cin >> n >> x;
    
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    sort(a.begin(), a.end());
    
    int ans;
    int sum = 0;

    for(int i = 0; i < n; i++){
        sum += a.at(i);
        if(sum == x){
            ans = i + 1;
            break;
        }else if(sum > x){
            ans = i;
            break;
        }else if(i == n - 1 && sum < x){
            ans = i;
            break;
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
string blue[200],red[200];
int scnt[200];
char s[100];
bool cmp(const string &a,const string &b)
{
    return a<b;
}
int main()
{
    int n,m;
    while(scanf("%d",&n)==1)
    {
        for(int i = 0; i < n; i++)
        {
            scanf("%s",s);
            blue[i] = s;
        }
        scanf("%d",&m);
        for(int i = 0; i < m; i++)
        {
            scanf("%s",s);
            red[i] = s;
        }
        sort(blue,blue+n,cmp);
        sort(red,red+m,cmp);
        scnt[0] = 1;
        for(int i = 1; i < n; i++)
            scnt[i] = blue[i] == blue[i-1] ? scnt[i-1]+1:1;
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < m; j++)
            {
                if(blue[i] == red[j])
                    scnt[i]--;
            }
        }
        int maxs = scnt[0];
        for(int i = 1; i < n; i++)
        {
            if(scnt[i] > maxs)
                maxs = scnt[i];
        }
        printf("%d\n",maxs>0?maxs:0);
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[105];
int main(){
    int n;
    scanf("%d", &n);
    double ans = 0;
    for(int i=1;i<=n;i++){
        scanf("%d", &a[i]);
        ans += 1.0/a[i];
    }
    printf("%.10lf\n", 1/ans);
}

Measured memory_bytes: 3768
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <algorithm>
#include <map>
#include <numeric>
using namespace std;

int main()
{
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;

    float max = 0.0;
    int maxwater = 0;
    int maxsuger = 0;

    vector<int> waterv;
    vector<int> sugerv;

    for (int wa = 0; wa <= f; wa++) {
        for (int wb = 0; wb <= f; wb++) {
            if (wa == 0 && wb == 0) continue;
            int water = (wa * a + wb * b) * 100;
            if (water > f) continue;
            waterv.push_back(water);
        }
    }

    for (int sc = 0; sc <= f; sc++) {
        for (int sd = 0; sd <= f; sd++) {
            int suger = sc * c + sd * d;
            if (suger > f) continue;
            sugerv.push_back(suger);
        }
    }
           
    for (int i = 0; i < waterv.size(); i++) {
        for (int j = 0; j < sugerv.size(); j++) {
            if (waterv[i] + sugerv[j] > f) continue;
            if (sugerv[j] * 100 > waterv[i] * e) continue;
            float noudo = (float)sugerv[j] / ((float)waterv[i] + (float)sugerv[j]);
            if (max < noudo) {
                max = noudo;
                maxwater = waterv[i];
                maxsuger = sugerv[j];
            }
        }
    }

    if (maxwater + maxsuger == 0) {
        maxwater = a * 100;
        printf("%d %d\n", maxwater + maxsuger, maxsuger);
    } else {
        printf("%d %d\n", maxwater + maxsuger, maxsuger);
    }
}

Measured memory_bytes: 1400
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <utility>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <cstdlib>
#include <set>
#include <chrono>
#include <climits>
#include <unordered_map>
#include <iomanip> 

#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define repf(i,st,end,inc) for(int i = st; i < end; i += inc)
#define repb(i,st,end,dec) for(int i = st; i >= end; i -= dec) 

#define MOD 1000000007

#define trace1(a) cout << a << endl;
#define trace2(a,b) cout << a << " | " << b << endl;
#define trace3(a,b,c) cout << a << " | " << b << " | " << c << endl;
#define trace4(a,b,c,d) cout << a << " | " << b << " | " << c << " | "<< d << endl;

using namespace std;
using namespace std::chrono;


int main(){
	fast;
	#ifdef LOCAL_PROJECT
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

	auto start = high_resolution_clock::now(); 

	int n;
	cin >> n;
	vector<ll int> a(n);
	vector<ll int> pref(n+1, 0);
	for(int i = 0; i< n; i++){
		cin >> a[i];
		pref[i+1] = pref[i] + a[i];
	}

	vector<vector<ll int> > dp(n, vector<ll int>(n, 0));

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

	for(int k = 1; k < n; k++){
		for(int i = 0; i + k < n; i++){
			int j = i+k;
			ll int tot1 = pref[j+1] - pref[i+1];
			ll int tot2 = pref[j] - pref[i];
			dp[i][j] = max(a[i] + (tot1 - dp[i+1][j]), a[j] + (tot2 - dp[i][j-1]));
		}
	}

	cout << 2*dp[0][n-1] - pref[n] << "\n";

	auto stop = high_resolution_clock::now(); 
	auto duration = duration_cast<microseconds>(stop - start);	
	// cout << endl;
	// cout << fixed << setprecision(9) << double(duration.count()) / 1000000 << endl; 

	return 0;
}


Measured memory_bytes: 70784
#C Maximal Value
n=int(input())
b=list(map(int,input().split()))
a=0
if n==2:
    print(b[0]*2)
else:
    for i in range(n-2):
        a+=min(b[i],b[i+1])
    a+=b[0]+b[n-2]
    print(a)

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

public class Main{
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        
        PrintWriter out = new PrintWriter(System.out);
        while(true){
            int height = Integer.parseInt(in.next()), width = Integer.parseInt(in.next());
            
            if(height == 0 && width == 0) break;

            draw_rect(height, width, out);
        }

        out.flush();
    }

    static void draw_rect(int height, int width, PrintWriter out){
        for(int i = 0; i < height; i++){
            for(int j = 0; j < width; j++){
                if((i % 2 == 0 && j % 2 == 0) || (i % 2 == 1 && j % 2 == 1)){
                    out.print("#");
                }
                else out.print(".");
            }
            out.println();
        }
        out.println();
    }
}


Measured memory_bytes: 28368
import java.util.*;

//aとbの比較プログラム
public class Main {
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		String[] input = sc.nextLine().split(" ");
		int a = Integer.parseInt(input[0]);
		int b = Integer.parseInt(input[1]);

		if(a>b)
		{
			System.out.println("a > b");
		}
		else if(a<b)
		{
			System.out.println("a < b");
		}
		else
		{
			System.out.println("a == b");
		}
		sc.close();
	}
}



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

int main(){
  int A1, A2, A3;
  cin >> A1 >> A2 >> A3;
  
  int ans;
  ans = A1 + A2 + A3;
  
  if(ans >= 22){
    cout << "bust" << endl;
  }
  else{
    cout << "win" << endl;
  }
  return 0;
}

Measured memory_bytes: 256