akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,x;
    cin>>n>>x;
    if(x==1||x==2*n-1) cout<<"No"<<endl;
    else{
      cout<<"Yes"<<endl;
      if(n==2) FOR(i,1,2*n) cout<<i<<endl;
      else{
        vector<ll> cnt;
        if(x==2){
          cnt.push_back(-1);
          FOR(i,1,2*n){
            if(i!=x-1 && i!=x && i!=x+1 && i!=x+2) cnt.push_back(i);
          }
          FOR(i,1,n-1) cout<<cnt[i]<<endl;
          cout<<x-1<<endl;
          cout<<x<<endl;
          cout<<x+1<<endl;
          cout<<x+2<<endl;
          FOR(i,n-1,len(cnt)) cout<<cnt[i]<<endl;
        }else{
          cnt.push_back(-1);
          FOR(i,1,2*n){
            if(i!=x-1 && i!=x && i!=x+1 && i!=x-2) cnt.push_back(i);
          }
          FOR(i,1,n-1) cout<<cnt[i]<<endl;
          cout<<x-1<<endl;
          cout<<x<<endl;
          cout<<x+1<<endl;
          cout<<x-2<<endl;
          FOR(i,n-1,len(cnt)) cout<<cnt[i]<<endl;
          //cout_vec(cnt);
        }
      }
    }
}

Measured memory_bytes: 3184
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<string>
#include<math.h>
#include<vector>
using namespace std;
int main(){
    int A,B,C,D;
    cin>>A>>B>>C>>D;
    int ans;
    ans=min(A,B)+min(C,D);
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 256
// Created by Nandu Vinodan
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define pi pair<int, int>
#define INF INT_MAX
#define _INF INT_MIN
#define TC 0 

using namespace std;
using ll = long long;

bool isPrime(int x) {
	for (int i=2; i<=sqrt(x); i++)
		if (x % i == 0)
			return false;

	return true;
}
void testcase() {
	int x;
    cin >> x;

    while (!isPrime(x)) {
    	x++;
    }
    cout << x << endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    if (TC)
        cin>>t;
    while(t--) {
        testcase();
    }
    return 0;
}

Measured memory_bytes: 256
import math
import itertools
N = int(input())
city = []
for i in range(N):
    city.append(list(map(int,input().split())))

def calc(xi,xj,yi,yj):
    return ((xi-xj)**2+(yi-yj)**2)**0.5

def calclen(list):
    s = 0
    for i in range(N-1):
        s += calc(city[list[i]][0],city[list[i+1]][0],city[list[i]][1],city[list[i+1]][1])
    return s

tmp = 0
permutations = list(itertools.permutations(range(N)))
for i in permutations:
    tmp += calclen(i)
print(tmp/math.factorial(N))

Measured memory_bytes: 8052
h, w = gets.split.map(&:to_i)
ch, cw = gets.split.map(&:to_i)
dh, dw = gets.split.map(&:to_i)

c = [?., ?#]
cc = Array.new(w+3, c[1])
s = [cc]
h.times do
    s << [c[1]]
    s[-1].push(*gets.chars)
    s[-1] << c[1]
end
s.push(cc, cc)

move = [[1,0], [-1,0], [0,1], [0,-1]]
warp = (-2..2).to_a.product((-2..2).to_a) - move - [[0,0]]

init = 1 << 30
d = Array.new(h+3) {Array.new(w+3, init)}
d[ch][cw] = 0
t = [[ch, cw]]

(0..).each do |k|
    break if t.empty? || d[dh][dw] < init
    u = []

    while (x,y = t.pop)
        move.each do |i,j|
            xx = x + i
            yy = y + j
            if s[xx][yy] == c[0] && d[xx][yy] > k
                d[xx][yy] = k
                t << [xx, yy]
            end
        end

        warp.each do |i,j|
            xx = x + i
            yy = y + j
            if s[xx][yy] == c[0] && d[xx][yy] > k + 1
                d[xx][yy] = k + 1
                u << [xx, yy]
            end
        end
    end

    t = u
end

p d[dh][dw] == init ? -1 : d[dh][dw]


Measured memory_bytes: 103668
#include <stdio.h>
int main(){
int i, j, H, W;
for (;;){
scanf("%d %d", &H, &W);
if (H == 0 && W == 0 ) break;
for ( i = 1; i < H+1; i++ ){
for ( j = 1; j < W+1; j++)
if ( j == 1 || j == W || i == 1 || i == H )
printf("#");
else
printf(".");
printf("\n");
}
printf("\n");
}
return 0;
}



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

using namespace std;
const int N = 100000 + 5;
const int INF = 0x3f3f3f3f;

int a[N];
vector<int> v;
//using P = pair<int,int>;
//using LL = long long;

void Init(){
    for(int i = 0; i < N; i++)
        a[i] = 0;
}

int main(){
    int k;
    cin >> a[0] >> a[1] >> a[2];
    cin >> k;
    sort(a, a + 3);
    a[2] = a[2] * int(pow(2, k));
    cout << a[0] + a[1] + a[2] << endl;

}


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

string s;

int main(){
    int amount = 700;
    cin >> s;
    for(int i = 0; i < 3; i++){
        if(s[i] == 'o'){
            amount += 100;
        }
    }
    cout << amount << endl;
    return 0;
}

Measured memory_bytes: 256
S = input()
if float(S[0:4]) < 2019:
    ans = 'TBD'
elif float(S[0:4]) > 2019:
    ans = 'Heisei'
else:
    s = int(S[5] + S[6])
    if int(s) <= 4:
        ans = 'Heisei'
    else:
        ans = 'TBD'
print(ans)

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

int main() {
    int N,K;
    cin >> N >> K;
    vector<int>A(N);
    vector<int>cnt(200000);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        cnt[A[i]-1]++;
    }
    sort(cnt.begin(),cnt.end());
    reverse(cnt.begin(),cnt.end());
    int cnt2 = 0;
    for(int i = 0; i < K; i++) {
        cnt2+=cnt[i];
    }
    cout << N-cnt2 << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
char s[100010];
int ans[100010];
int ans1[100010];
int n;
int main(){
    scanf("%s",s+1);n=strlen(s+1);
    for(int i=1;i<=n;i++){
        if(s[i]=='R'&&s[i+1]=='L'){
            int now=i;int flag=0;
            while(s[now]=='R'){
                ans[now]=i+flag;
                now--;
                flag=1-flag;
            }
            now=i+1;flag=1;
            while(s[now]=='L'){
                ans[now]=i+flag;
                now++;flag=1-flag;
            }
        }
    }
    for(int i=1;i<=n;i++) ans1[ans[i]]++;
    for(int i=1;i<=n;i++) printf("%d ",ans1[i]);
    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin>>a.at(i);
    }
    vector<int>ans(n);
    for(int i=(n-1)/2+1;i<n;i++){
        ans.at(i)=a.at(i);
    }
    for(int i=(n-1)/2;i>=0;i--){
        int j=2;
        int tmp=0;
        while((i+1)*j<=n){
            tmp+=ans.at((i+1)*j-1);
            j++;
        }
        ans.at(i)=(a.at(i)+tmp)%2;
    }





    //答えの出力
    int cnt=0;
    for(int i=0;i<n;i++){
        if(ans.at(i)==1){
            cnt++;
        }
    }
    cout<<cnt<<endl;
    for(int i=0;i<n;i++){
        if(ans.at(i)==1){
            cout<<i+1<<" ";
        }
    }
    cout<<endl;



    return 0;
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int co = 0;
	for(int i = 1; i < s.size(); i++){
		if(s[i] == s[i-1]){
			co++;
			if(s[i] == '1') s[i] = '0';
			else s[i] = '1';
		}
	}
	cout<<co<<"\n";
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin >> n;
	ll a[n][3];
	for(ll i = 0;i < n;i++){
		for(ll j = 0;j < 3;j++){
			cin >> a[i][j];
		}
	}
	for(ll i = n - 2;i >= 0;i--){
		ll b[3];
		for(ll j = 0;j < 3;j++){
			b[j] = 0;
			for(ll k = 0;k < 3;k++){
				if(k == j) continue;
				b[j] = max(b[j],a[i + 1][k]);
			}
			a[i][j] += b[j];
		}
	}
	cout << max(a[0][0],max(a[0][1],a[0][2]));
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

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

    // start
    int a, b, c;
    cin >> a >> b >> c;
    cout << (c - a + b <= 0 ? 0 : c - a + b) << endl;
    // end

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;

void solve() {
	int n, k; cin >> n >> k;
	if (n == 1) {
		if (k == 0) {
			cout << "0 1 1 0" << endl;
		}
		else {
			cout << -1 << endl;
		}
		return;
	}
	else if (n == 0) {
		if (k == 0) {
			cout << "0 0" << endl;
		}
		else {
			cout << -1 << endl;
		}
		return;
	}
	vector<int> ans;
	if (k >= (1 << n)) {
		cout << -1 << endl; return;
	}
	else {
		vector<int> ans;
		vector<int> c;
		rep(i, (1 << n)) {
			if (i != k)c.push_back(i);
		}
		ans.push_back(k);
		rep(i, c.size())ans.push_back(c[i]);
		ans.push_back(k);
		per(i, c.size())ans.push_back(c[i]);
		rep(i, ans.size()) {
			if (i > 0)cout << " ";
			cout << ans[i];
		}
		cout << endl;
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//experi(4);
	solve();
	//stop
	return 0;
}

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

using namespace std;

vector<vector<int> > g;
vector<vector<int> > v;
int main(){
	int n, m; cin>>n>>m;
	g.resize(n);
	for(int i = 0; i < m; i++){
		int u, v; cin>>u>>v; u--, v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	v = vector<vector<int> > (n, vector<int>(11));
	int q; cin>>q;
	vector<int> ops(q+1);ops[0] = 0;
	for(int i = 1; i <= q; i++){
		int u, d, c; cin>>u>>d>>c; u--;
		ops[i] = c;
		v[u][d] = i;
	}
	
	for(int i = 10; i > 0; i--){
		for(int j = 0; j < n; j++){
			v[j][i-1] = max(v[j][i-1], v[j][i]);
			for(int adj: g[j]){
				v[adj][i-1] = max(v[adj][i-1], v[j][i]);
			}
		}
	}
	for(int i = 0; i < n; i++){
		cout<<(ops[v[i][0]])<<endl;
	}
}


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

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

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

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

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	int n;
	scanf("%d", &n);
	vector<int> as(n);
	for(int i = 0; i < n; ++i){
		scanf("%d", &as[i]);
	}
	int cz = 0;
	vector<int> cnts(n + 1);
	LL ans = 1;
	for(int a : as){
		if(a == 0){
			ans *= 3 - cz++;
		}
		else{
			ans *= cnts[a - 1]--;
		}
		++cnts[a];
		ans %= MOD;
	}
	printf("%lld\n", ans);
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){
	throw;
}


Measured memory_bytes: 1024
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
//#include <vector>
//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 
 

int main(){


    string S;
    cin >> S;
    for( int ni = 0 ; ni < S.length() ; ni++ ){
        string sx;
        sx = S.substr(ni,1);
        if(sx=="9") cout << "1";
        else if(sx=="1") cout << "9";
    }
    

}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
 
int main() {
	int n,x;
	cin>>n>>x;
	int arr[n];
	for(int i=0;i<n;i++)
	 { cin>>arr[i];
	   arr[i]=abs(arr[i]-x);
	 }
	 int ans = arr[0];
    for(int i=0;i<n;i++)
    {
        ans = __gcd(ans, arr[i]);
    }
    cout << ans << "\n";  
	return 0;
}

Measured memory_bytes: 640
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
count = 0

for i in range(q):
    t = T[i]
    left = 0
    right = n
    while left < right:
        mid = (left + right) // 2
        if S[mid] == t:
            count += 1
            break
        elif t < S[mid]:
            right = mid
        else:
            left = mid + 1
print(count)



Measured memory_bytes: 16708
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll cnt[26];
int main() {
    init();
    ll H, W;
    cin >> H >> W;
    rep(i,H){
        string s;
        cin >> s;
        rep(i, W) cnt[s[i] - 'a']++;
    }

    ll n1 = (H & 1) * (W & 1), n2 = H % 2 * W / 2 + W % 2 * H / 2, n4 = H / 2 * (W / 2);
    ll c1 = 0, c2 = 0, c4 = 0;

    rep(i,26){
        c4 += cnt[i] / 4;
        c2 += cnt[i] % 4 / 2;
        c1 += cnt[i] & 1;
    }

    while(c4>n4){
        c4--;
        c2 += 2;
    }

    if(c1!=n1 or c2!=n2 or c4!=n4)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;

}

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

int main(void) {
	string S;
	cin >> S;

	string ans = "Yes\n";
	if (S[0] == S[1] && S[1] == S[2] && S[2] == S[0])
		ans = "No\n";

	cout << ans;
	return 0;
}


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

const int N = 2e5 + 10;

char s[N];

int main(){
	scanf("%s" , s + 1);
	int n = strlen(s + 1);
	for(int i = 1; i <= n; i++)
		if(s[i] != '?') putchar(s[i]);
		else putchar('D');
	return 0;
}

Measured memory_bytes: 3880
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int):
    ans = NO
    for i in range(int(100//4)):
        for j in range(int(100//7)):
            if 4*i + 7*j == N:
                ans = YES
                break
    print(ans)
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    N = int(input())  # type: int
    solve(N)

if __name__ == '__main__':
    main()


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

int main() {
	for(int i = 0; i < 9; i++) {
		int a, p;
		string id;
		cin >> id >> a >> p;
		cout << id << " " << a + p << " " << a * 200 + p * 300 << endl;
	}
}

Measured memory_bytes: 1204
#include<cstdio>
#include<math.h>
#include<algorithm>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001;
#define LLINF 1001001001001001001001;
#define LL long long

int main(){
    char c[4];
    scanf("%s",c);
    int ac=0,bc=0,cc=0;
    rep(i,4){
        if(c[i]=='a')ac++;
        if(c[i]=='b')bc++;
        if(c[i]=='c')cc++;
    }
    if(ac==1&&bc==1&&cc==1)printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
int main(void) {
  int x,pos;
  cin >> x;
  string weeks[] = { "sat", "sun", "mon", "tue", "wed", "thu", "fri" };
  pos = abs(x-9)%7;
  if (x < 9 && pos > 0) {
    pos = 7 - pos;
  }
  cout << weeks[pos] << endl;

  return 0;
}



Measured memory_bytes: 3196
#include "bits/stdc++.h"
using namespace std;

//44
typedef long long ll;

int main() {
	int n;
	cin >> n;
	vector<int> v(n - 1);
	for (int i = 0; i < n - 1; ++i) {
		cin >> v[i];
	}
	if (n == 2) {
		cout << 2 * v[0];
		return 0;
	}
	//vector<int> v(n);
	vector<int> ans(n);
	bool e = 1;
	int index = n - 2;
	for (int i = 0; i  + 1 < n - 1; ++i) {
		if (v[i] < v[i + 1]) {
			ans[i] = v[i];
			ans[i + 1] = v[i];
			index = i + 1;
			e = 0;
			break;
		}else {
			ans[i] = v[i];
		}
	}
	//map<ll,int> m;
	//if (index != -1) {
	int p = index + 1;
	for (int i = index; i < n - 1; ++i) {
		if(i + 1 < n - 1) {
			v[i] = min(v[i],v[i + 1]);
			ans[p] = v[i];
		}else {
			ans[p] = v[i];
		}
		++p;
	}
	ll sum = 0;
	if (e) {
	    sum += v[n - 2];
	}
	for (int i = 0; i < n; ++i) {
		//cout << ans[i] << " ";
		sum += (1LL * ans[i]);
	}
	cout << sum;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
#define p(x) cout<<(x)<<endl

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

  rep(i, n) {
    int a, b; cin >> a >> b;
    ans += b-a+1;
  }
  p(ans);
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
	int N,K;cin>>N>>K;
	long long ans = 0;
	for(int k=K+1;k<=N;k++){
		if(K==0)ans += (N/k)*(k-K) + (N%k>K?N%k-K:0);
		else ans += (N/k)*(k-K) + (N%k>=K?N%k-K+1:0);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
N, Y = map(int,input().split())

ans = (-1, -1, -1)
for x in range(N+1):
    if ans == (-1, -1, -1) and 0 <= Y - 10000*x <= 5000*(N-x):
        for y in range(N+1):
            z = N - x - y
            if 10000*x + 5000*y + 1000*z == Y:
                ans = (x, y, z)
                break

print(' '.join(map(str,ans)))

Measured memory_bytes: 3064
s = gets.chomp

result = true
odd = %W(R U D)
even = %W(L U D)
for i in 1..(s.length) do
  if i.odd?
    x = odd.find { |n| n == s[i - 1] }
    result = false if x == nil
  else
    y = even.find { |n| n == s[i - 1] }
    result = false if y == nil
  end
end

puts result ? 'Yes' : 'No'

Measured memory_bytes: 1788
package main

import (
	"fmt"
	"math"
)

func main() {
	var N, D int
	fmt.Scan(&N, &D)

	X := make([][]float64, N)
	for i := 0; i < N; i++ {
		X[i] = make([]float64, D)
		for j := 0; j < D; j++ {
			fmt.Scan(&X[i][j])
		}
	}

	ans := 0
	for i := 0; i < N-1; i++ {
		for j := i + 1; j < N; j++ {
			sum := 0.0
			for d := 0; d < D; d++ {
				y := X[i][d]
				z := X[j][d]
				sum += math.Pow(y-z, 2)
			}
			dd := math.Sqrt(sum)
			if dd == float64(int64(dd)) {
				ans++
			}
		}
	}

	fmt.Println(ans)
}


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

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0; i<N; i++) cin >> a[i];
  
  queue<int> q;
  for(int i=N; i>=1; i--){
    int d=i;
    int sum=0;
    while(d<=N){
      sum+=a[d-1];
      d+=i;
    }
    sum%=2;
    if(a[i-1]!=sum){
      a[i-1]=(a[i-1]+1)%2;
    }
    if(a[i-1]>0) q.push(i);
  }
  cout << q.size() << endl;
  while(!q.empty()){
    cout << q.front();
    q.pop();
    cout << (q.empty()?"\n":" ");
  }
}

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

#define is_uruu leapyear
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(a);i>(b);--i)
#define REP(i,a) for(int i=0;i<(a);++i)


	
int main(){
	
	int n, A[100005], B[100005];
	cin >> n;
	FOR(i, 1, n+1) cin >> A[i];
	
	if(n%2 != 0){
		ROF(i, n, 0) B[i] = (i/2)*2;
	} else {
		ROF(i, n, 0) B[i] = ((i+1)/2)*2-1;
	}
	
	sort(A+1, A+n+1);
	sort(B+1, B+n+1);
	
	FOR(i, 1, n+1){
		if(A[i] != B[i]){
			cout << 0 <<endl;
			return 0;
		}
	} 
	
	ll ans=1;
	REP(i, n/2) ans = (ans*2)%1000000007;
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
    ll N;
    cin >> N;
    string s = to_string(N);
    ll sn = 0;
    for(char c : s) sn += c - '0';
    cout << (N % sn ? "No" : "Yes") << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  int n;
  cin >> n;
  double ans = 3.14159;
  ans *= n * 2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3712
#include <stdio.h>

int main() {
   int a[10000], n, i, min, max;
   long int sum;

   scanf("%d", &n);
   for (i = 0; i < n; i++) {
      scanf("%d", &a[i]);
   }

   max = a[0];
   min = a[0];
   sum = 0;
   for (i = 0; i < n; i++) {
      if (a[i] > max) {
         max = a[i];
      }
      if (a[i] < min) {
         min = a[i];
      }
      sum = sum + a[i];
   }

   printf("%d %d %ld\n", min, max, sum);

   return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#define INF 10000000
int main()
{
	int n, x;
	scanf("%d", &n);
	int max_x = 0, min_x = INF;
	for(int i = 0; i < n; i++)
	{
		scanf("%d", &x);
		if(x > max_x) max_x = x;
		if(x < min_x) min_x = x;
	}
	int ans = max_x - min_x;
	printf("%d\n", ans);
	return 0;
}
		

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

int main() {
	unsigned long long x,y;
	cin>>x>>y;
	int ans=0;
	unsigned long long r=x;
	while(true){
		r*=2LL;
		ans++;
		if(r>y)break;
		
	}
	cout<<ans;
	return 0;
}

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

using ll = long long int;
using bigint = int64_t;

#define pll pair<ll, ll>
#define vll vector<ll>
#define vpll vector<pll>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ins insert
#define mp make_pair
#define w(t) cin >> t;while(t--)
#define bitcount __builtin_popcount
#define endl "\n"
#define sz(s) (int)s.size()
#define mem(n,m) memset(n,m,sizeof(n))
#define deb(x) cout << #x << " = " << x << endl;
#define rep(i,n) for(ll i = 0; i < n; i++)
#define ren(i,n) for(ll i = n-1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define fo(i, a, b) for(ll i = a; i <= b; i++)
#define ffo(i, a, b) for(ll i = a; i >= b; i--)
#define ffi(i,a,b,c) for(ll i = a ; i <= b ; i += c)
#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
const int MOD = 1000000007;

void io_set() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

void solve() {
	ll n;
	cin >> n;
	ll pk = (n/500)*1000 + ((n%500)/5)*5;
	ll dk = (n/5)*5;
	cout << max(pk, dk) << endl;
}

int main() {
	IOS;
	//io_set();
	ll tt = 1;
	//cin >> tt;
	while (tt--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]

ab.sort(key=sum, reverse=True)

sol = int(0)

for i, x in enumerate(ab):
  if i % 2:
    sol -= ab[i][1]
  else:
    sol += ab[i][0]

print(sol)


Measured memory_bytes: 32224
#include <iostream>

using namespace std;

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


int main()
{
    long L=0, R=0, Lmax=0, Rmin=0;
    long N=0, M=0;

    cin >> N; 
    cin >> M;

    Rmin = N+1;

    for(int i=0; M>i; i++){
        cin >> L; 
        cin >> R;

        Lmax = max(L, Lmax);
        Rmin = min(R, Rmin);
    }

    if(Rmin >= Lmax)
        cout << (Rmin - Lmax) + 1;
    else
        cout << 0;
    

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int H,W;
    while(1){
        cin >> H >> W;
        if (H==0&&W==0) break;
        for ( int i = 0; i < H; i++ ){
            for ( int j = 0; j < W; j++ ){
                cout << "#";
            }
            cout << "\n";
        }
        cout << endl;
    }return 0;
}


Measured memory_bytes: 3052
<?php
// Your code here!
fscanf(STDIN,"%d",$n);

$input = trim(fgets(STDIN));
$h = explode(" ",$input);

$cnt = 1;
$max = $h[0];

for($i=1;$i<$n;$i++){
    if($h[$i] >= $max){
        $cnt++;
        $max = $h[$i];
    }
}

echo $cnt;
?>


Measured memory_bytes: 4856
#include<iostream>
using namespace std;
int main(){
  int N;
  cin >> N;
  pair<pair<string, int>, int> S[100];
  for(int i=0; i<N; i++){
    string s;
    int p;
    cin >> s >> p;
    S[i] = make_pair(make_pair(s, -p), i);
  }
  sort(S,S+N);
  for(int i=0; i<N; i++){
    cout << S[i].second+1 << endl;
  }
  return 0;
}

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

int main(){
  int a,b,k,A = 0,B = 0;
  cin >> a >> b >> k;
  if(k % 2 == 0){
    for(int i = 0;i < k / 2;i++){
      if(a % 2 == 1){
        a--;
      }
      b += a / 2;
      A = a / 2;
      a -= A;
      if(b % 2 == 1){
        b--;
      }
      a += b / 2;
      B = b / 2;
      b -= B;
    }
  }
  else {
    for(int i = 0;i < (k -1) / 2;i++){
     if(a % 2 == 1){
       a--;
     }
     b += a / 2;
     A = a / 2;
     a -= A;
     if(b % 2 == 1){
       b--;
     }
     a += b / 2;
     B = b / 2;
     b -= B;
   }
   if(a % 2 == 1){
     a--;
   }
   b += a / 2;
   A = a / 2;
   a -= A;
  }
  cout << a << " " << b << endl;
}

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

int main()
{
    int d;
    cin >> d;
    switch (d)
    {
    case 22:
        cout << "Christmas Eve Eve Eve" << endl;
        break;
    case 23:
        cout << "Christmas Eve Eve" << endl;
        break;
    case 24:
        cout << "Christmas Eve" << endl;
        break;
    case 25:
        cout << "Christmas" << endl;
        break;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[])
{

    int x, y;
    char data[8][8];
    
    for (x = 0; x < 8; x++) {
        for (y = 0; y < 8; y++) {
            scanf("%c", &data[x][y]);
        }
        getchar();
    }
    
    printf("90\n");
    for (x = 0; x < 8; x++) {
        for (y = 7; y >= 0; y--) {
            printf("%c", data[y][x]);
        }
        printf("\n");
    }
    
    printf("180\n");
    for (x = 7; x >= 0; x--) {
        for (y = 7; y >= 0; y--) {
            printf("%c", data[x][y]);
        }
        printf("\n");
    }
    
    printf("270\n");
    for (x = 7; x >= 0; x--) {
        for (y = 0; y < 8; y++) {
            printf("%c", data[y][x]);
        }
        printf("\n");
    }
    
    
    return 0;
}

Measured memory_bytes: 524
A, B = map(int, input().split())
a, b, d = 'Alice', 'Bob', 'Draw'
if A == 1:
    A = 14
if B == 1:
    B = 14

if A > B:
    ans = a
elif A < B:
    ans = b
else:
    ans = d

print(ans)

Measured memory_bytes: 9020
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int W = sc.nextInt(); // 円のx座標
		int H = sc.nextInt(); // 円のy座標
		int x = sc.nextInt(); // 右上のx座標
		int y = sc.nextInt(); // 右上のy座標
		int r = sc.nextInt(); // 円の半径

        if (x - r >= 0 && y - r >=0 && x + r <= W && y + r <= H) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
	}
}


Measured memory_bytes: 26292
#include <iostream>

using namespace std;

int main()
{
	char s[13];
	cin >> s;
	for (int i = 0; i < 4; ++i)
		cout << s[i];
	cout << " ";
	for (int i = 4; i < 12; ++i)
		cout << s[i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

const int MAX_LEVEL = 55;
long long buns[MAX_LEVEL], patties[MAX_LEVEL], total[MAX_LEVEL];

long long no_of_patties(long long height, int level)
{
    const int OUTER_BUN = 1, MIDDLE_PATTY = 1;

    if(height >= total[level])
        return patties[level];
    if(height == 0 || height == OUTER_BUN)
        return 0;
    if(height - OUTER_BUN < total[level - 1])
        return no_of_patties(height - OUTER_BUN, level - 1);

    height -= OUTER_BUN;
    long long patties_here = 0;

    if(height >= total[level - 1])
    {
        patties_here += patties[level - 1];
        height -= total[level - 1];
    }
    if(height >= MIDDLE_PATTY)
    {
        patties_here += MIDDLE_PATTY;
        height -= MIDDLE_PATTY;
    }
    if(height > 0)
    {
        patties_here += no_of_patties(height, level - 1);
    }

    return patties_here;
}

int main()
{
    int levels;
    long long height;
    cin >> levels >> height;

    total[0] = patties[0] = 1;
    buns[0] = 0;

    for(int i = 1; i <= levels; i++)
    {
        const int FIRST_BUN = 1, MIDDLE_PATTY = 1, LAST_BUN = 1;

        buns[i] = FIRST_BUN + buns[i - 1] + buns[i - 1] + LAST_BUN;
        patties[i] = patties[i - 1] + MIDDLE_PATTY + patties[i - 1];
        total[i] = FIRST_BUN + total[i - 1] + MIDDLE_PATTY + total[i - 1] + LAST_BUN;
    }

    long long total_patties = no_of_patties(height, levels);

    cout << total_patties;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp> 
//using namespace __gnu_pbds; 
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int> >, rb_tree_tag,tree_order_statistics_node_update>
#define standardVar ll n,m,i,j,k,num,num1,num2,flag=0
#define nn <<"\n"
#define __ <<" "<<
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define ittr(x,v) for(auto x=v.begin();x!=v.end();x++)
#define itr(x,n) for(x=0;x<n;x++)
#define itrab(x,a,b) for(x=a;x<b;x++)
#define itpr(v) ittr(x,v)cout<<*x<<" "; cout nn
#define itppr(v) ittr(x,v)cout<<(*x).ff<<" "<<(*x).ss<<"  "; cout nn
#define pi 3.14159265359
#define dTor(x) ((x)*pi)/180.0
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef map<ll,ll> ml;
typedef set<ll> sl;
typedef string str;
typedef pair<ll, ll> pl;
typedef vector< pl > vpl;
typedef map<pl,ll> mpl;
typedef set< pl > spl;
typedef vector<str> vst;
typedef vector<vl> vvl;

const ll M=1000000007;
const ll N=998244353;

ll power(ll x, ll y, ll p){     //MODULAR EXPONENTIATION
    ll res=1;
    x=x%p;
    if(x==0)
        return 0;
    while(y>0){
        if(y&1)
            res=(res*x)%p;
        y=y>>1;
        x=(x*x)%p;
    }
    return res;
}
ll inv(ll x, ll m){             //FERMAT INVERSE
    return power(x,m-2,m);
}
struct comp{                    //COMPARISON ON PAIRS
    template<typename T>        
    bool operator()(const T &a, const T &b){
        if (a.ff==b.ff)
            return (a.ss<b.ss);
        else
            return (a.ff<b.ff);
    }
};
bool mod(const pair<ll,ll> &a, const pair<ll,ll> &b){   //COMPARATOR FOR PAIRS (SORTING)
    if(a.ff!=b.ff)
        return (a.ff<b.ff);
    else
        return (a.ss<b.ss);
}
void sieve(vl &prime){          //SIEVE OF ERATOSTHENES
    ll maxN=1e6;
    vector<bool> pr(maxN+1,1);
    for(int i=2;i*i<=maxN;i++)
        if(pr[i]==1)
            for(int j=i*i;j<=maxN;j+=i)
                pr[j]=0;
    for(ll i=2;i<=maxN;i++)
        if(pr[i]==1)
            prime.pb(i);
}
bool isValid(ll i, ll j, ll n, ll m){   //CHECKS FOR OVERFLOW
    if(i>=0&&i<n&&j>=0&&j<m){
        return true;
    }
    return false;
}

//MAIN FUNCTION STARTS HERE

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    standardVar;
    cin>>n;
    k=7%n;
    m=1;
    if(n%2&&n%5){
         while(1){
            if(k==0){
                cout<<m;
                break;
            }
            else{
                k=((k*10)%n+7)%n;
                m++;
            }
        }
    }
    else{
        cout<<-1 nn;
    }
    return 0;
}

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

#define vec              vector<int>
#define vecll            vector<ll>
#define vecd             vector<double>
#define vecst            vector<string>
#define vecb             vector<bool>
#define v2(v,n,m,init)   vector<vector<int>>  v(n, vector<int>(m, init))
#define vb2(v,n,m,init)  vector<vector<bool>> v(n, vector<bool>(m, init))
#define vll2(v,n,m,init) vector<vector<ll>>   v(n, vector<ll>(m, init))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
template <typename T>
bool chmax(T &a, const T& b){if(a<b){a=b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a>b){a=b; return true;} return false;}
//------------------------------------------------------------------

int main(void){
  int n;
  cin >> n;
  v2(f, n, 10, 0);
  rep(i,n){
    rep(j,10){
      cin >> f[i][j];
    }
  }
  vll2(p, n, 11, 0);
  rep(i,n){
    rep(j,11){
      cin >> p[i][j];
    }
  }

  ll ans = -1e18;
  rep(i,(1<<10)){
    if(i==0) continue;
    ll tmp = 0;
    rep(j,n){
      int ct = 0;
      rep(k,10){
        if((i&(1<<k)) && f[j][k]) ct++;
      }
      tmp += p[j][ct];
    }
    chmax(ans, tmp);
  }

  prt(ans);

}


Measured memory_bytes: 3644
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;

int main() {
  ll N, T;
  cin >> N >> T;

  vP lst(N + 1);
  vvll dp(N + 1, vll(T + 1, 0));

  for (ll i = 1; i <= N; i++) {
    cin >> lst[i].first >> lst[i].second;
  }
  sort(lst.begin(), lst.end());

  ll ans = LONG_LONG_MIN;
  for (ll i = 1; i <= N - 1; i++) {
    P p = lst[i];
    for (ll j = 0; j < T; j++) {
      dp[i][j] = dp[i - 1][j];
      if (j >= p.first)
        dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - p.first] + p.second);
    }  // j
    ll now = dp[i][T - 1] + lst[i + 1].second;
    chmax(ans, now);
  }  // i

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 70784
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main(){
    double a, b, C, S, L, h, c; 
    cin >> a >> b >> C;

    cout.precision(16);
    
    S = 0.5 * a * b * sin(C * (M_PI/180));
    cout << S << endl;
    
    c = sqrt(pow(a,2) + pow(b,2) - 2 * a * b *cos(C * (M_PI/180)));
    L = a + b + c;
    cout << L << endl;
    
    h = 2 * S / a;
    cout << h << endl;
    
    return 0;
}



Measured memory_bytes: 3540
n, q = map(int, input().split())
s = input()
cnt = 0
data = [0] * (n + 1)
ans = [0] * q
for i in range(n - 1):
    if s[i] == 'A' and s[i + 1] == 'C':
        cnt += 1
    data[i + 1] = cnt

data[n - 1] = cnt

for i in range(q):
    l, r = map(int, input().split())

    ans[i] = data[r - 1] - data[l - 1]

for i in range(q):
    print(ans[i])

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

#define ll long long
#define mx  40005
#define mod 1000000009
#define lim 10000000
#define inf 2000000000
#define N 18
#define eps 100000
#define PI acos(-1)

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	int n,x;cin>>n>>x;
	int a[n+5];

	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	int ans=0;
	for(int i=0;i<n;i++)
	{
		if(x-a[i]>=0)x-=a[i];
		else break;
		ans++;
	}
     if(x && ans==n)ans--;
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
//#define int long long int
using namespace std;


int main(){
ll ans = 0;
ll N; cin>>N;
vector <string> S;
for(int i=0;i<N;i++){
    string s; cin>>s;
    sort(s.begin(),s.end());
    S.push_back(s);
}

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

S.push_back("$$$");
ll cnt = 1;

for(int i=1;i<=N;i++){
    if(S[i] == S[i-1]) cnt++;
    else {
        ans += cnt * (cnt - 1) / 2;
        cnt = 1;
    }

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

Measured memory_bytes: 5748
using System;

class Program
{
	static void Main()
	{
		int[] D = new int[int.Parse(Console.ReadLine())];
		string[] sD = Console.ReadLine().Split(' ');
		long a = 0;
		for (int i = 0; i < sD.Length; i++)
		{
			a += D[i] = int.Parse(sD[i]);
		}
		Array.Sort(D);
		Console.WriteLine("{0} {1} {2}", D[0], D[D.Length - 1], a);
	}
}

Measured memory_bytes: 20088
#include <bits/stdc++.h>
using namespace std;
#define pi 3.1415926536
#define forn(i, a, b) for (int i = a; i < b; i++)
#define LL long long
#define MP make_pair
#define ff first
#define ss second
#define INF 2147483647
#define _INF -2147483647
#define pq priority_queue
#define MM multimap
#define PB push_back
#define ipair pair<int, int> s
#define lpair pair<LL, LL>
#define MAXN 100004

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    int ans = min(n*a,b);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[101],n,i,j,k,mx,jami,ans;
int main() {
    cin >> n;
    for (i=1; i<=n; i++)
        cin>>a[i];
    if (n<3)
    {
        cout<<0;
        return 0;
    }

    for (i=1; i<=n-2; i++)
    {
        for (j=i+1; j<=n-1; j++)
        {
            for (k=j+1; k<=n; k++)
            {
                mx=max(a[i],a[j]); mx=max(mx,a[k]);
                jami=a[i]+a[j]+a[k]-mx;
            if (a[i]!=a[j] && a[j]!=a[k] && a[i]!=a[k] && mx<jami) ans++;
            }
        }
    }
    cout<<ans;

}


Measured memory_bytes: 3576
import java.awt.List;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws Exception {
		FastScanner scanner = new FastScanner(System.in);
		int size = (int) scanner.nextInt();
		ArrayList<Integer> list = new ArrayList<Integer>();
		for (int i = 0; i < size; i++) {
			int tmp = (int) scanner.nextInt();
			if (!list.contains(tmp)) {
				list.add(tmp);
			}
		}
		PrintWriter printWriter = new PrintWriter(System.out);
		printWriter.printf("%d\n", list.size());
		printWriter.close();
	}

	static class FastScanner {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;

		public FastScanner(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
			tokenizer = null;
		}

		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public String nextLine() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					return reader.readLine();
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}

			return tokenizer.nextToken("\n");
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public long nextInt() {
			return Integer.parseInt(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = (int) nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}
	}
}


Measured memory_bytes: 22868
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, d[100];
    cin >> N;
    REP(i, N) cin >> d[i];

    ll ans = 0;
    REP(i, N - 1) FOR(j, i + 1, N) ans += d[i] * d[j];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define lmin LONG_MIN
#define lmax LONG_MAX
#define imin ll_MIN
#define imax ll_MAX
#define ffor(i,a,b) for(i=a;i<b;i++)
#define bfor(i,a,b) for(i=a-1;i>=b;i--)
#define mset(f,a) memset(f,a,sizeof(f))
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAXN   10000009


ll mod = 1e9 +7;



int main() 
{
    ll t=1,temp;
    //cin>>t;
    ffor(temp,0,t)
    {
        fastio;
        ll n;
        cin>>n;
        ll arr[n];
        ll i;
        ffor(i,0,n)
            cin>>arr[i];
        
        ll sum=0;
        ffor(i,0,n)
            sum=(sum+arr[i]);
        ll s[n];
        ffor(i,0,n)
        {
            s[i]=sum-arr[i];
            sum=sum-arr[i];
        }
        ll ans=0;
        ffor(i,0,n)
        {
            ans=(ans+((arr[i]%mod)*(s[i]%mod))%mod)%mod;
        }
        cout<<ans<<endl;
    }
      
    
}


Measured memory_bytes: 6776
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <algorithm>
#include <array>

using namespace std;


template<typename T>
class Heap
{
public:
	bool isInRange(const int index) { return 1 <= index && index <= static_cast<int>(nodes_.size()); }
	Heap(const vector<T>& v) :nodes_(v) {}
	void printAllNodeInfo() {
		const int n = nodes_.size();

		const function<void(int, string)> printValueIfInRange = [&](const int index, const string& name) {
			if (isInRange(index)) cout << name << " = " << nodes_.at(index - 1) << ", ";
		};

		for (int id = 1; id <= n; ++id) {
			const int parentIndex = static_cast<int>(floor(id * 0.5));
			const int leftIndex = 2 * id;
			const int rightIndex = leftIndex + 1;

			cout << "node " << id << ": ";
			printValueIfInRange(id, "key");
			printValueIfInRange(parentIndex, "parent key");
			printValueIfInRange(leftIndex, "left key");
			printValueIfInRange(rightIndex, "right key");
			cout << endl;
		}
	}
	void printAllKeys() const {
		for (const auto& key : nodes_)cout << " " << key;
		cout << endl;
	}
	void buildMaxHeap() {
		function<void(int)> maxHeapify = [&](const int index) {
			//indexは、ある節点のIDを示す。
			//本関数はこの節点を、MaxHeap条件が満たされるように葉に向かって下降させていく

			//自分と子の中で値が最大の節点のIDを求める
			const int maxID = [&]() {
				vector<size_t> indexArray; {
					indexArray.reserve(3);
					const size_t leftIndex = index * 2;
					const size_t rightIndex = leftIndex + 1;
					indexArray.push_back(index);
					if (isInRange(leftIndex)) indexArray.push_back(leftIndex);
					if (isInRange(rightIndex)) indexArray.push_back(rightIndex);
				}
				return *max_element(indexArray.begin(), indexArray.end(),
					[&](const size_t i1, const size_t i2) {return nodes_.at(i1 - 1) < nodes_.at(i2 - 1); }
				);
			}();

			//子が最大なら再帰呼び出し
			if (maxID != index) {
				swap(nodes_.at(index - 1), nodes_.at(maxID - 1));
				maxHeapify(maxID);
			}
		};
		const int roopStart = static_cast<int>(nodes_.size()*0.5);
		for (int i = roopStart; i >= 1; --i) maxHeapify(i);
	}

	vector<T> nodes_;
};

template<typename T>
void execute(T& cin) {
	int n;
	cin >> n;
	vector<int> v(n);
	for (auto& i : v)cin >> i;
	Heap<int> heap(v);
	//heap.printAllNodeInfo();
	heap.buildMaxHeap();
	heap.printAllKeys();

}

int main()
{
	execute(cin);


	return 0;
}


Measured memory_bytes: 6848