akhauriyash/Code-Regression huggingface dataset:
A,B,C,X = [int(input()) for i in range(4)]

def calc(a,b,c):
  return 500 * a + 100 * b + 50 * c

cont = 0

for a in range(A + 1):
  for b in range(B + 1):
    for c in range(C + 1):
      if calc(a,b,c) == X:
        cont += 1

print(cont)

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

int main(){

    string s, t;
    cin >> s >> t;

    int num = s.size();
    bool flg = false;
    string buf = s;
    for (int i=0; i<num; i++){
        char cbuf = buf.at(num-1);
        buf.erase(num-1);
        buf = cbuf + buf;

        if (buf == t) flg = true;
    }

    if (flg) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
LL a,b,n;
int main() {
  ios::sync_with_stdio(false);
  cin>>a>>b>>n;
  n=min(n,b-1);
  cout<<(a*n/b)-a*(n/b);
  return 0;
}

Measured memory_bytes: 3628
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
// #include<unordered_map>
#include<set>
// #include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
#include<functional>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
#define wl() cout << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
};
struct point {
	ll x, y, idx;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
};

template<typename T>
T minT(T a, T b) {
	if (a < b) return a;
	else return b;
}

template<typename T>
T maxT(T a, T b) {
	if (a > b) return a;
	else return b;
}

template<typename T>
T absT(T a) {
	if (a < 0) a *= -1;
	return a;
}

template<typename T>
T powT(T a, T x) {
	T res = 1;
	while (x > 0) {
		if (x & 1) res = res*a;
		a = a*a;
		x >>= 1;
	}
	return res;
}

ll StoLL(string str) {
	ll ret = 0, ini = 0;
	if (str[0] == '-') ini = 1;
	repi(i, ini, str.length()) {
		ret *= 10;
		ret += (ll)(str[i] - '0');
	}
	if (ini) ret *= -1;
	return ret;
}

///////////////////////////////////////////////////////////////////////////////////////

ll A[30], B[30];

int main() {
	ll N, ans = 0;
	string str;
	cin >> N >> str;
	repi(i, 0, N - 1) {
		ll t = 0;
		repi(j, 0, 30) {
			A[j] = 0;
			B[j] = 0;
		}
		repi(j, 0, N) {
			if (j <= i) {
				A[((int)str[j] - 'a')]++;
			}
			else {
				B[((int)str[j] - 'a')]++;
			}
		}
		repi(j, 0, 30) {
			if (A[j] > 0 && B[j] > 0) t++;
		}
		ans = max(ans, t);
	}

	wrln(ans);

	return 0;
}


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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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; }

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

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

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

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  int m1,d1,m2,d2;
  cin>>m2>>d1>>m2>>d2;
  if(d2!=1){
    cout<<0<<endl;
    
  }else
  {
    cout<<1<<endl;
  }
  
}


Measured memory_bytes: 256
n,k=[int(i) for i in input().split()]

a=[None]+[int(i) for i in input().split()]

circle=[1]
for i in range(n):
    circle.append(a[circle[-1]])

def get_head_double(circle):
    check=[0]*(n+1)
    for i in circle:
        check[i]+=1
    for i in circle:
        if check[i]>=2:
            ans=i
            break
    ans_list=[]
    while len(ans_list)<2:
        for i,j in enumerate(circle):
            if j==ans:
                ans_list.append(i)
    return ans_list

ans_list=get_head_double(circle)
circle_front=circle[:ans_list[0]]
circle_back=circle[ans_list[0]:ans_list[1]]

if len(circle_front)>k:
    print(circle_front[k])
else:
    k=k-len(circle_front)
    print(circle_back[k%len(circle_back)])







Measured memory_bytes: 32328
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int top, S[1000];

void push(int x)
{
    S[++top] = x;
}

int pop()
{
    top--;
    return S[top+1];
}

int main()
{
    int a, b;
    char s[100];

    top = 0;

    while (scanf("%s", s) != EOF) {
        if (s[0] == '+') {
            a = pop();
            b = pop();
            push(a + b);
        } else if (s[0] == '-') {
            b = pop();
            a = pop();
            push(a - b);
        } else if (s[0] == '*') {
            a = pop();
            b = pop();
            push(a * b);
        } else {
            push(atoi(s));
        }
    }

    printf("%d\n", pop());

    return 0;    
}


Measured memory_bytes: 2104
#include <iostream>
#include <string>

using namespace std;

class Solution {
private:
	int c(int n) {
		if (n < 2)
			return 0;
		return n * (n - 1) / 2;
	}
public:
	/* time: O(1), space: O(1) */
	int theNumberOfEvenPairs(int n, int m) {
		return c(n) + c(m);
	}
};

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

	Solution sol;
	const int ans = sol.theNumberOfEvenPairs(n, m);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
class DisjointSet:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.parents[self.find(x)]


N, M, *ab = map(int, open(0).read().split())
edges = [(a - 1, b - 1) for a, b in zip(*[iter(ab)] * 2)]

ans = 0
for i in range(M):
    ds = DisjointSet(N)
    for j in range(M):
        if i == j:
            continue
        ds.union(*edges[j])
    if len([-p for p in ds.parents if p < 0]) > 1:
        ans += 1
print(ans)


Measured memory_bytes: 9136
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> mpll;
typedef unordered_map<char, ll> mpcl;
typedef unordered_map<string, ll> mpsl;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

ll inl() {
    ll x;
    cin >> x;
    return (x);
}

string ins() {
    string x;
    cin >> x;
    return (x);
}

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
#pragma clang diagnostic pop
#endif
        ll n = inl(), m = inl();
        vl a;
        map<ll, ll> mp;
        rep(i, n) {
            a.eb(inl());
            mp[a[i]]++;
        }

        rep(i, m) {
            ll b = inl(), c = inl();
            mp[c] += b;
        }

        ll ans = 0;
        ll res = n;
        for (auto v = mp.rbegin(); v != mp.rend(); v++) {
            ans += min(res, v->second) * v->first;
            res -= min(res, v->second);
            if (res == 0) break;
        }

        cout << ans << endl;

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 13556
#include<stdio.h>
int main()
{
int a,b,c,d;
scanf("%d",&a);
scanf("%d",&b);
scanf("%d",&c);
scanf("%d",&d);
if(-d<=a-c&&a-c<=d){
puts("Yes");
}else if((-d<=a-b&&a-b<=d)&&(-d<=b-c&&b-c<=d)){
puts("Yes");
}else{
puts("No");
}
return 0;
}

Measured memory_bytes: 128
n = int(input())
a = list(map(int, input().split()))
a.insert(0, 0)
a.append(0)
dis = 0
for i in range(n + 1):
    dis += abs(a[i + 1] - a[i])
for i in range(n):
    if (a[i + 1] - a[i]) * (a[i + 2] - a[i + 1]) < 0:
        a_dis = dis - 2 * min(abs(a[i + 1] - a[i]), abs(a[i + 2] - a[i + 1]))
    else:
        a_dis = dis
    print(a_dis)

Measured memory_bytes: 14048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
//void chmin(int &a, int b) { if (a > b) a = b; }
//void chmax(int &a, int b) { if (a < b) a = b; }


int main() {
    double a,b;
    cin >> a >> b;
    double x,y;
    x = a/1.08;
    y = b/1.1;
    for (int i = 1; i <= 1000; ++i) {
        int tmp,tmp2;
        tmp = i*0.08;
        tmp2 = i*0.1;
        if(tmp == a && tmp2 == b){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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


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

    int N;
    cin >> N;
    vector<ll> A(N);
    vector<ll> sumA(N);

    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    sumA[0] = A[0];
    for(int i = 1; i < N; i++){
        sumA[i] = sumA[i-1] + A[i];
    }

    vector<ll> leftsep(N);
    vector<ll> rightsep(N);

    int i_lsep = 0;
    int i_rsep = 2;
    ll tmp_l = 0;
    ll tmp_r = 0;
    for(int i = 1; i < N-2; i++){
        
        tmp_l = abs(sumA[i] - sumA[i_lsep] - sumA[i_lsep]);
        for(int j = i_lsep; j < i-1; j++){
            if(abs(sumA[i] - sumA[j+1] - sumA[j+1]) > tmp_l){
                break;
            }else{
                tmp_l = abs(sumA[i] - sumA[j+1] - sumA[j+1]);
                i_lsep = j+1;
            }
        }
        leftsep[i] = i_lsep;

        i_rsep = max(i+1, i_rsep);
        tmp_r = abs((sumA[N-1] - sumA[i_rsep]) - (sumA[i_rsep] - sumA[i]));
        for(int j = i_rsep; j < N-2; j++){
            if(abs((sumA[N-1] - sumA[j+1]) - (sumA[j+1] - sumA[i])) > tmp_r){
                break;
            }else{
                tmp_r = abs((sumA[N-1] - sumA[j+1]) - (sumA[j+1] - sumA[i]));
                i_rsep = j+1;
            }
            
        }
        rightsep[i] = i_rsep;
    }

    // これで i = 1 ... N - 3 まで捜査
    ll ans = INF;
    ll tmp_ans = 0;
    ll P, Q, R, S;
    for(int i = 1; i < N - 2; i++){

        i_lsep = leftsep[i];
        i_rsep = rightsep[i];
        P = sumA[i_lsep];
        Q = sumA[i] - sumA[i_lsep];
        R = sumA[i_rsep] - sumA[i];
        S = sumA[N-1] - sumA[i_rsep];

        tmp_ans = max({P, Q, R, S}) - min({P, Q, R, S});
        
        chmin(ans, tmp_ans);
    }

    cout << ans << endl;


    return 0;
}



Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define lli long long int
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF 9223372036854775807+1

int main() {
  vector<int> wrong(2);
  cin >> wrong[0]>> wrong[1];
  sort(ALL(wrong));
  if(wrong[1]!=3)
    cout << 3 << endl;
  else if(wrong[0]!=1)
    cout << 1 << endl;
  else
    cout << 2 << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
#define Seg_Max_N (1<<18) 

using Value = int;
const Value ini = -1e9;
struct segtree {
	int N;
	vector<Value>dat;

	segtree() {}
	segtree(int n) :dat(2 * Seg_Max_N) {
		N = 1;
		while (N < n) N *= 2;
		for (int i = 0; i < 2 * N - 1; i++) {
			dat[i] = ini;
		}
	}
	Value connect(const Value&l, const Value&r) {
		return max(l,r);
	}
	// update k th element
	void update(int k, Value a) {
		k += N - 1;
		dat[k] = a;

		while (k > 0) {
			k = (k - 1) / 2;
			const Value al(dat[k * 2 + 1]);
			const Value ar(dat[k * 2 + 2]);
			dat[k] = connect(al, ar);
		}
	}
	// min [a, b)
	Value  query(int a, int b) { return query(a, b, 0, 0, N); }
	Value  query(int a, int b, int k, int l, int r) {
		if (r <= a or b <= l) return ini;
		if (a <= l and r <= b) return dat[k];
		const int m = (l + r) / 2;
		const Value al(query(a, b, k * 2 + 1, l, m));
		const Value ar(query(a, b, k * 2 + 2, m, r));
		return connect(al, ar);
	}
};


int solve(vector<int>b) {
	int num = 0;
	int ans=0;
	int pre = -1;
	for (auto a : b) {
		if (a > pre) {
			num++;
			ans=max(ans,num);
			pre = a;
		}
		else if (a == pre) {

		}
		else {
			pre = a;
			num = 1;
		}
	}
	return ans;
}
template<typename T> struct Compress {
	map<T, int>mp;
	map<int, T>revmp;

	Compress(vector<T>vs) {
		setmp(vs);
	}

	Compress() :mp(), revmp() {

	}
	void setmp(vector<T>vs) {
		sort(vs.begin(), vs.end());
		vs.erase(unique(vs.begin(), vs.end()), vs.end());
		for (int i = 0; i < static_cast<int>(vs.size()); ++i) {
			mp[vs[i]] = i;
			revmp[i] = vs[i];
		}
	}
};
int main() {
	long long int N;cin>>N;
	long long int ans=1;
	long long int plus=1;
	while (true) {
		if (N % 2) {
			ans+=plus;
			plus*=2;
			N/=2;
		}
		else {
			break;
		}
	}
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 3112
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <cstdlib>
#include <ctime>
#include <queue>
using namespace std;

#define X first
#define Y second
#define N 800010
#define M 500010

typedef unsigned long long ull;
typedef long long ll;
const ll INF = 1ll << 60;
const int Mod = 1000000007;


struct Segment_Tree
{
	ll mi[N];
	
	void Build(int x, int l, int r)
	{
		mi[x] = INF;
		if (l == r) return;
		int mid = (l + r) >> 1;
		Build(x << 1, l, mid);
		Build(x << 1 | 1, mid + 1, r);
	}
	
	void Modify(int x, int l, int r, int pos, ll v)
	{
		if (l == r) 
		{
			mi[x] = v;
			return;
		}
		int mid = (l + r) >> 1;
		if (pos <= mid) Modify(x << 1, l, mid, pos, v);
		else Modify(x << 1 | 1, mid + 1, r, pos, v);
		mi[x] = min(mi[x << 1], mi[x << 1 | 1]);
	}
	
	ll Query(int x, int L, int R, int l, int r)
	{
		if (l > r) return INF;
		if (l <= L && r >= R) return mi[x];
		if (l > R || r < L) return INF;
		
		int Mid = (L + R) >> 1;
		return min(Query(x << 1, L, Mid, l, r), Query(x << 1 | 1, Mid + 1, R, l, r));
	}
}tree[2];

int main()
{
	//freopen("in.in","r",stdin);
	//freopen("out.out","w",stdout);
	
	int n, Q, A, B, x;  ll del = 0;
	scanf("%d %d %d %d", &n, &Q, &A, &B);
	tree[0].Build(1, 1, n);
	tree[1].Build(1, 1, n);
	tree[0].Modify(1, 1, n, A, -A);
	tree[1].Modify(1, 1, n, A,  A);
	for (int i = 1, pre = B;i <= Q; ++i)
	{
		scanf("%d", &x);
		
		ll tmp1 = tree[0].Query(1, 1, n, 1, x) + x;
		ll tmp2 = tree[1].Query(1, 1, n, x, n) - x;
		ll tmp = min(tmp1, tmp2);
		tree[0].Modify(1, 1, n, pre, tmp - pre - abs(x - pre));
		tree[1].Modify(1, 1, n, pre, tmp + pre - abs(x - pre));
		
		del += abs(x - pre); pre = x;
	}
	ll res = INF;
	for (int i = 1; i <= n; ++i) res = min(res, tree[0].Query(1, 1, n, i, i) + i + del) ;
	printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 12544
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
using ll = long long; using ld = long double; const char nl = '\n';
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */

#include <bits/extc++.h>
namespace pbds =  __gnu_pbds;
template <typename key, typename val=pbds::null_type, typename comp=less<key>>
using ostree=pbds::tree<key,val,comp,pbds::rb_tree_tag,pbds::tree_order_statistics_node_update>;
using vi = vector< int >; using vll = vector< ll >;
#define all(x) std::begin(x), std::end(x)
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename...Args, template<typename...> typename T> string to_string(T<Args...> const&);
string to_string(string const&s){return '"'+s+'"';}
string to_string(char const &c) {return to_string(string(1,c));}
string to_string(char const *c) {return to_string(string(c));}
string to_string(bool const &b) {return (b ? "1" : "0");}
template<typename... Args> string to_string(pair<Args...> const&p)
{return "("+to_string(p.first)+", "+to_string(p.second)+")";}
template <typename...Args, template<typename...> typename T> string to_string(T<Args...> const&S)
{string s = "{"; for(auto const& e: S)s+=" "+to_string(e);s+=" }"; return s;}
template<typename Tail> void debug_out(Tail t) {cerr<<" "<<to_string(t)<<" ]"<<endl;}
template<typename Head, typename... Tail> void debug_out(Head h, Tail... t)
{cerr << " " << to_string(h) << ","; debug_out(t...);}
#define pr(...) cerr<<"["<<(#__VA_ARGS__)<<"] : [", debug_out(__VA_ARGS__)
template <typename T> void dbr(T lb, T ub)
{cerr<<'{';for(auto it=lb; it!=ub; it++)cerr<<' '<<to_string(*it); cerr<<" }"<<endl;}
template<typename T, typename Comp=less<T>> bool smin(T &mem, T const&v, Comp const&cmp=Comp())
{return cmp(v, mem) ? mem = v, true : false;}
template<typename T, typename Comp=less<T>> bool smax(T &mem, T const&v, Comp const&cmp=Comp())
{return cmp(mem, v) ? mem = v, true : false;}
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */



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

  ll n; cin >> n;
  ll a[n+n+1+1];
  for(int i=1; i<=n; i++) cin>>a[i], a[i+n] = a[i];

  for(int i=n+n-1; i>=1; i--) {
    a[i] = a[i] - a[i+1];
  }

  for(int i=1; i<=n; i++) cout << (a[i]+a[i+n]) << ' ';
  cout << endl;

}
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */


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


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

  int res1 = (c + b -1)/b;
  int res2 = (a + d-1)/d;

  if(res1 <= res2){cout << "Yes" << endl;}
  else{cout << "No" << endl;}
}

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

const int maxN = 5000 + 5;
const LL maxA = 1000000000 + 233;
int n, p[maxN];
LL A, B;
LL f[maxN];

int main() {
	cin >> n >> A >> B;
	p[0] = 0; p[n + 1] = n + 1;
	for(int i = 1; i <= n; ++i) cin >> p[i];
	f[0] = 0;
	for(int i = 1; i <= n + 1; ++i) {
		int mx = -1;
		int bigger = 0, smaller = 0;
		f[i] = maxN * maxA;
		for(int j = i - 1; j >= 0; --j) {
			if(p[j] > p[i]) {
				bigger ++;
			} else {
				if(p[j] > mx) {
					mx = p[j];
					f[i] = min(f[i], f[j] + bigger * A + smaller * B);
				}
				smaller ++;
			}
		}
	}
	cout << f[n + 1] << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<set>
#include<vector>
#include<cstring>
#include<cmath>
#include<stdio.h>
#include<string>
#include<stack>
#include<queue>
#include<iterator>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int inf=0x3f3f3f3f;
typedef long long ll;

int ans;
int n;

int main()
{
    cin>>n;
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j*i<n;++j)
        {
            ans++;
        }
    }
    cout<<ans<<endl;
}


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

int main() {
    int n;
    cin >> n;
    vector<long long> a(n), b(n), c(n);
    for (auto &x: a) cin >> x;
    for (auto &x: b) cin >> x;
    for (auto &x: c) cin >> x;
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    vector<long long> l(n);
    int j = 0;
    for (int i = 0; i < n; i++) {
        while (j < n && c[j] <= b[i]) j++;
        l[i] = n - j;
    }
    for (int i = n - 1; i > 0; i--) l[i-1] += l[i];
    long long ans = 0;
    j = 0;
    for (int i = 0; i < n; i++) {
        while (j < n && b[j] <= a[i]) j++;
        if (j == n) break;
        ans += l[j];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6424
#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define ll  long long
  #define ld long double
  #define pb push_back
  #define mp3 make_pair
  #define rep1(i,a,b) for(ll i=a;i<=b;i++)
  #define rep2(i,a,b) for(ll i=a;i<b;i++)
  const ll  mod=998244353;
  template<typename T> T pow(T a,T b, long long m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
  template<typename T> T add(T a,T b,ll m){a+=b;while(a>=0)a-=m;while(a<0)a+=m; return a;}
  template<typename T> T mul(T a,T b,ll m){return (a*1ll*b)%m;}

 int main(){
   IOS;
  int d,t,s;
  cin>>d>>t>>s;
  float x=1.0*t;
  float y=(float)d/s;
  if(y<=x){
    cout<<"Yes"<<endl;
  }
  else 
  cout<<"No"<<endl;
 }

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 61)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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

i64 ceil(i64 a, i64 b) { return (a+b-1)/b; }
mt19937 rnd(time(NULL));

int d, c[30], s[404][30];
int ans[400];
clock_t start;

int score(int a[400], int l, int r){
	int cnt = 0;
	int last[26] = {};
	fill(last,last+26,l-1);
	
	for(int i = l; i < r; i++){
		cnt += s[i][a[i]];
		last[a[i]] = i;
		for(int j = 0; j < 26; j++){
			cnt -= c[j]*(i-last[j]);
		}
	}
	return cnt;
}

void solve(){
	start = clock();
	
	cin >> d;
	for(int i = 0; i < 26; i++) cin >> c[i];
	for(int i = 0; i < d; i++){
		for(int j = 0; j < 26; j++) cin >> s[i][j];
	}
	
	int ma = 0;
	for(int i = 0; i < d; i++){
		int v = i%26;
		ans[i] = v;
	}
	ma = score(ans,0,d);
	
	int cc[30] = {};
	for(int i = 0; i < 26; i++){
		cc[i+1] = cc[i]+c[i];
	}
	
	int lp = 0;
	while(clock()-start < 1.9*CLOCKS_PER_SEC){
		int res[400] = {};
		// for(int i = 0; i < d; i++){
			// int v[30] = {};
			// for(int j = 0; j < 26; j++){
				// v[j+1] = v[j] + cc[j+1] + s[i][j];
			// }
			// int r = rnd() % v[26];
			// r = lower_bound(v,v+26,r)-v-1;
			// res[i] = r;
		// }
		for(int i = 0; i < d; i++){
			res[i] = ans[i];
			int r = rnd()%60;
			if(r == 0){
				r = rnd()%26;
				res[i] = r;
			}
		}
		
		if(chmax(ma,score(res,0,d))){
			for(int i = 0; i < d; i++){
				ans[i] = res[i];
			}
		}
		//cout << score(res,0,d) << endl;
		lp++;
	}
	//cout << lp << endl;
	//cout << ma << endl;
	
	for(int i = 0; i < d; i++){
		cout << ans[i]+1 << endl;
	}
}

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

Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define yesorno(a) printf(a ? "yes\n" : "no\n")
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define YESorNO(a) printf(a ? "YES\n" : "NO\n")
using P = pair<int,int>;
using vi = vector<int>;
using vii = vector<vi>;
using ll = long long;
const int dx4[4] = {1,0,-1,0};
const int dy4[4] = {0,1,0,-1};
const int dx8[8] = {-1,0,1,1,1,0,-1,-1};
const int dy8[8] = {1,1,1,0,-1,-1,-1,0};


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

  string s;
  cin >> s;
  int ans = 0;
  int cnt = 0;
  rep(i,s.size()){
    if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') cnt++;
    else{
      ans = max(ans, cnt);
      cnt = 0;
    }
  }
  ans = max(ans, cnt);
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
 public static void main(String args[]) {
 	Scanner scan = new Scanner(System.in);
   
	int a = scan.nextInt();
    int b = scan.nextInt();
   
   if ((a*b)%2 == 1) {
   	System.out.println("Odd");
   } else {
    System.out.println("Even");
   }
 }
}

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int a[3],n,r;
	while(cin>>a[0]>>a[1]>>a[2],a[0]){
		cin>>n;sort(a,a+3);
		for(int i=0;i<n;i++){
			cin>>r;
			cout<<((a[0]*a[0]+a[1]*a[1]<4*r*r)?"OK":"NA")<<endl;
		}
	}
}

Measured memory_bytes: 1168
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<string> s(n);
        vector<int> num(n, 0);
        vector<bool> v(n, false);
        for(int i=0; i<n; ++i){
            cin >> s[i];
            if(s[i][s[i].size()-1] == 'v'){
                v[i] = true;
                s[i].resize(s[i].size()-1);
                if(s[i].empty())
                    s[i] = '-';
            }
            int tmp = 1;
            while('0' <= s[i][s[i].size()-1] && s[i][s[i].size()-1] <= '9'){
                num[i] += tmp * (s[i][s[i].size()-1] - '0');
                tmp *= 10;
                s[i].resize(s[i].size()-1);
            }
        }

        map<pair<string, int>, int> m;
        vector<int> to(n, -1);
        for(int i=0; i<n; ++i){
            if(num[i] > 0){
                map<pair<string, int>, int>::iterator it;
                it = m.find(make_pair(s[i], num[i]+1));
                if(it != m.end()){
                    to[i] = it->second;
                    m.erase(it);
                }
                m.insert(make_pair(make_pair(s[i], num[i]), i));
            }

            if(v[i]){
                to[i+1] = i;
                continue;
            }

            if(num[i] <= 1){
                int j = i;
                do{
                    cout << (j+1) << endl;
                    j = to[j];
                }while(j != -1);
            }
        }
    }
}

Measured memory_bytes: 1952
//I am so vegetable
//#define _LOCAL_
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define PB push_back
#define IN insert
#define ER erase
#define CT count
#define EP empty
#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 _sfor(p,st) for(auto &p:st)
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll N = 1e5+5;
const int MOD = 10000;
const double eps = 1e-6;
const double pi = acos(-1);
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
ll qpow(ll x, ll y) { ll ans = 1; for (; y > 0; y >>= 1) { if (y & 1)ans *= x; x *= x; }return ans; }
ll inv(ll x, int mod = MOD) { return qpow(x, mod - 2) % mod; }

 int main() {
	//ofstream cout("E:\\acm dream\\out.txt",ios::out);
	FIO;
	bool flag = false;
	string s;cin>>s;
	_for(i,0,s.size()){
		if(s[i]=='7'){
			flag = true;
			break;
		}
	}
	if(flag)cout<<"Yes";
	else cout<<"No";
	return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll H, A;
    cin >> H >> A;
    cout << H / A + !!(H % A) << endl;
    return 0;
}


Measured memory_bytes: 3544
using System;
using System.Collections.Generic;
using System.Linq;
using static Scanner;

class Program
{
    static void Main() => new Program().Solve();

    public void Solve()
    {
        int n = ReadInt();
        int k = ReadInt();

        int[] a = ReadInt(n).ToArray();
        if (k == 0)
        {
            Console.WriteLine(a.Max());
            return;
        }
        int left = 0, right = 1000000000, x = (left + right) / 2;
        while (left + 1 != right)
        {
            int kk = 0;
            foreach (var aa in a)
            {
                kk += (int)Math.Ceiling((double)aa / x) - 1;
            }
            if (kk <= k)
            {
                right = x;
            }
            else
            {
                left = x;
            }
            x = (left + right) / 2;
        }
        Console.WriteLine(right);
    }
}

static class Scanner
{
    static Queue<string> que = new Queue<string>();
    public static string Read() { if (!que.Any()) foreach (var s in Console.ReadLine().Split()) que.Enqueue(s); return que.Dequeue(); }
    public static int ReadInt() => int.Parse(Read());
    public static IEnumerable<string> Read(long n) { for (long i = 0; i < n; i++) yield return Read(); }
    public static IEnumerable<int> ReadInt(long n) => Read(n).Select(int.Parse);
}


Measured memory_bytes: 54960
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <utility>
#include <iomanip>
#include <tuple>
#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
using namespace std;


int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	ll b[n];
	rep(i,1,n) cin >> b[i];
	ll ans = b[1];
	rep(i,2,n) ans += min(b[i-1],b[i]);
	ans += b[n-1];
	cout << ans << endl;
}


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

long upper(long l) {
    for ( int i = 1; i < l * 2; i++) if ( 1 << i > l) return 1 << i;
    return -1;
}

int main() {

    long a;
    cin >> a;
    vector<long> b(a);
    long i = 0;
    long n = 0;
    map<long, long> m;
    while (cin) { cin >> b[i];m[b[i]]++; i++;}
    sort(b.begin(), b.end(), greater<int>());
    long ret = 0;
    for (int i = 0; i < b.size(); i++) {
            long elem = b[i];
            if (m[elem] == 0) continue;
            m[elem]--;
            long d =  upper(elem) - elem;
            if (m[d] > 0) {
                    ret++;
                    m[d]--;
            }
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 26752
#include <iostream>
#include <utility>
#include <vector>
#include <vector>
#include <cmath>
#include <cstdio>
using namespace std;

#define fi first
#define se second

typedef pair<double,int> pdi;

template<class T>
T sqr(T x) { return x * x; }

int main() {
	int N;
	cin >> N;
	vector<int> R;
	vector<pdi> X;
	R.resize(N);
	for(int i = 0; i < R.size(); i++) {
		cin >> R[i];
	}
	X.push_back(pdi(0.0,-1));
	for(int i = 0; i < R.size(); i++) {
		double center_x = 0.0;
		for(int j = 0; j < X.size(); j++) {
			if(X[j].se == -1) {
				center_x = max(center_x, X[j].fi + R[i]);
			}
			else{
				// a^2 = b^2 + c^2
				// b = sqrt(sqr(c) - sqr(c))
				center_x = max(center_x,
						sqrt(sqr(R[i]+X[j].se) - sqr(R[i]-X[j].se)) + X[j].fi);
			}
		}
		X.push_back(pdi(center_x, R[i]));
	}

	double res = 0;
	for(int i = 0; i < X.size(); i++)
		res = max(res, X[i].fi + X[i].se);
	
	printf("%.10f\n", res);
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll a[200010],b[200010];
priority_queue<pair<ll,ll>> que;
int main() {
	ll n,cnt=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		b[i]=x;
		if(a[i]!=b[i]){
		que.push(make_pair(x,i));
		cnt++;
		}
	}
	ll ans=0;
	while(cnt!=0){
		pair<ll,ll> kari=que.top();
		que.pop();
		ll nowval=kari.first;
		ll nowiti=kari.second;
		ll l=nowiti-1,r=nowiti+1;
		if(l<0){
			l=n-1;
		}
		if(r==n){
			r=0;
		}
		ll lval=b[l],rval=b[r];
		ans++;
		nowval-=(lval+rval);
		ll herasu=(nowval-a[nowiti])/(lval+rval);
		ans+=herasu;
		  nowval-=herasu*(lval+rval);
		b[nowiti]=nowval;
		if(nowval<a[nowiti]){
			cout << "-1";
			return 0;
		}
		if(nowval==a[nowiti]){
			cnt--;
		}
		else{
		que.push(make_pair(nowval,nowiti));
		}
	}
	cout << ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 8944
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


using namespace std;

int main() {
    char M[101][101];
    int H, W;
    cin >> H >> W;
    rep(i, H) {
        rep(j, W) {
            cin >> M[i][j];
        }
    }

    int dp[H+1][W+1];
    rep(i, H) {
        rep(j, W) {
            if (i == j && i == 0) {
                if (M[0][0]== '#') {
                    dp[0][0] = 1;
                } else {
                    dp[0][0] = 0;
                }
            } else {
                dp[i][j] = 10000000;
            }

        }
    }




    rep(i, H) {
        rep(j, W) {
            if (i + 1 < H) {
                if (M[i][j] == '.' && M[i+1][j] == '#') {
                    dp[i+1][j] = min(dp[i][j] + 1, dp[i+1][j]);
                } else {
                    dp[i+1][j] = min(dp[i][j], dp[i+1][j]);
                }
            }

            if (j + 1 < W) {
                if (M[i][j] == '.' && M[i][j+1] == '#') {
                    dp[i][j+1] = min(dp[i][j] + 1, dp[i][j+1]);
                } else {
                    dp[i][j+1] = min(dp[i][j], dp[i][j+1]);
                }
            }
        }
    }

    cout << dp[H-1][W-1] << endl;

}

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

int main(){
  
  int A,B,C;
  cin >> A >> B >> C;
  
  if(A <= C && C <= B){
    
    cout << "Yes" <<endl;
    
  }else if(B <= C && C <= A){

    cout << "Yes" <<endl;
    
  }else {
    
    cout << "No" <<endl;
  }

  
  return 0;
}


Measured memory_bytes: 256
/* - - - - - - - - - - - - - - -
	User : 		VanishD
	problem :
	Points : 	
- - - - - - - - - - - - - - - */
# include <bits/stdc++.h>
# define 	ll 		long long
# define 	N 		10100
using namespace std;
const int inf = 0x3f3f3f3f, INF = 0x7fffffff;
const ll  infll = 0x3f3f3f3f3f3f3f3fll, INFll = 0x7fffffffffffffffll;
int read(){
	int tmp = 0, fh = 1; char ch = getchar();
	while (ch < '0' || ch > '9'){ if (ch == '-') fh = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9'){ tmp = tmp * 10 + ch - '0'; ch = getchar(); }
	return tmp * fh;
}
int T, num[N], cnt, eu[N], ev[N], ew[N];
int main(){
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	T = read();
	while (T > 1){
		if (T % 2 == 1){
			T -= 1;
			num[++cnt] = 0;
		}
		else {
			T /= 2;
			num[++cnt] = 1;
		}
	}
	int now = 1, n = 20, m = 0, id = 1;
	for (int i = 1; i < n; i++)
		eu[++m] = i, ev[m] = i + 1, ew[m] = 0;
	for (int i = cnt; i >= 1; i--){
		if (num[i] == 0)
			eu[++m] = 1, ev[m] = now, ew[m] = id, id += 1;
			else eu[++m] = now, ev[m] = ++now, ew[m] =id, id *= 2;
	}
	printf("%d %d\n", n, m);
	for (int i = 1; i <= m; i++)
		printf("%d %d %d\n", eu[i], ev[i], ew[i]);
	return 0;
}


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

int main(){
  int n;
  int a[100];
  int d;
  cin >> n;
  for(int i=0;i<100;i++) a[i]=0;
  for(int i=0;i<n;i++){
    cin >> d;
    a[d-1]=1;
  }
  int ans=0;
  for(int i=0;i<100;i++){
    if(a[i]) ans++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(c) c.begin(), c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    vector<int> price = {a, b, c};
    sort(all(price));
    cout << price[0] + price[1];
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int N, M, Q, a[55], b[55], c[55], d[55];
int A[15];

int rec(int n) {
  if (n == N) {
    int cost = 0;
    for (int i = 0; i < Q; i++) {
      if (A[b[i] - 1] - A[a[i] - 1] == c[i]) {
        cost += d[i];
      }
    }
    return cost;
  }
  int maxCost = 0;
  for(int i = 0; i < M; i++) {
    if (n > 0 && A[n - 1] > i) continue;
    A[n] = i;
    maxCost = max(rec(n + 1), maxCost);
  }
  return maxCost;
}

int main() {
  cin >> N >> M >> Q;
  for(int i = 0; i < Q; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  cout << rec(0) << endl;
  return 0;
}

Measured memory_bytes: 3636
n = int(input())
a = [int(input()) for _ in range(n)]
f = 0
s = 0
index = 0
for i in range(n):
    if a[i] > f:
        index = i
        s = f
        f = a[i]
    elif a[i] > s:
        s = a[i]

for i in range(n):
    if i == index:
        print(s)
    else:
        print(f)


Measured memory_bytes: 12532
#include <iostream>
#include <cmath>

using namespace std;

long long t;

long long a,b,c,d;

bool check(long long now,long long k)
{
  return b-now/(k+1)<=(a-now/(k+1)*k-now%(k+1))*k;
}

int main()
{
  scanf("%lld",&t);
  while(t--)
  {
    scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
    long long k=max(ceil(1.0*a/(b+1)),ceil(1.0*b/(a+1)));
    long long l=0,r=a+b+1;
    while(l<r)
    {
      long long mid=(l+r)>>1;
      if(check(mid,k)) l=mid+1;
      else r=mid;
    }
    r=l+b-l/(k+1)-(a-l/(k+1)*k-l%(k+1))*k+1;
    for(long long i=c;i<=min(d,l);i++)
    {
      if(i%(k+1)) printf("A");
      else printf("B");
    }
    for(long long i=max(c,l+1);i<=d;i++)
    {
      if((i-r)%(k+1)) printf("B");
      else printf("A");
    }
    printf("\n");
  }
}


Measured memory_bytes: 3184
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  priority_queue<int> que;
  rep(i, n){
    int a;
    cin >> a;
    que.push(a);
  }
  rep(i, m){
    int temp = que.top();
    que.pop();
    que.push(temp/2);
  }
  ll ans = 0;
  rep(i, n){
    ans += que.top();
    que.pop();
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3836
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
long long A[110000];
long long B[110000];
vector<int>g[110000];
int UF[110000];
int FIND(int a){
	if(UF[a]<0)return a;
	return UF[a]=FIND(UF[a]);
}
void UNION(int a,int b){
	a=FIND(a);b=FIND(b);if(a==b)return;
	UF[a]+=UF[b];
	UF[b]=a;
}
pair<long long,int> v[110000];
pair<long long,pair<int,int> > e[110000];
vector<pair<int,int> >G[210000];
int pt[210000];
long long dp[210000];
long long sum[210000];
int N;
void dfs(int a){
	if(a<N)sum[a]+=B[a];
	for(int i=0;i<G[a].size();i++){
		dfs(G[a][i].first);
		sum[a]+=sum[G[a][i].first];
	}
	if(a<N){
		dp[a]=A[a];
	}else{
		dp[a]=max(dp[G[a][0].first],A[G[a][1].second]-B[G[a][1].second])+sum[G[a][1].first];
		dp[a]=min(dp[a],max(dp[G[a][1].first],A[G[a][0].second]-B[G[a][0].second])+sum[G[a][0].first]);
	}
//	printf("%d: %lld %lld\n",a,dp[a],sum[a]);
}
int main(){
	int a,b;scanf("%d%d",&a,&b);N=a;
	for(int i=0;i<a;i++){
		scanf("%lld%lld",A+i,B+i);
		A[i]=max(A[i],B[i]);
	}
	for(int i=0;i<b;i++){
		int p,q;scanf("%d%d",&p,&q);p--;q--;
		g[p].push_back(q);
		g[q].push_back(p);
		e[i]=make_pair(max(A[p]-B[p],A[q]-B[q]),make_pair(p,q));
	}

	for(int i=0;i<a;i++){
		UF[i]=-1;
		pt[i]=i;
	}
	for(int i=0;i<a;i++){
		v[i]=make_pair(A[i]-B[i],i);
	}
	std::sort(v,v+a);
	std::sort(e,e+b);
	int id=a;
	for(int i=0;i<b;i++){
		if(FIND(e[i].second.first)==FIND(e[i].second.second))continue;
		G[id].push_back(make_pair(pt[FIND(e[i].second.first)],e[i].second.first));
		G[id].push_back(make_pair(pt[FIND(e[i].second.second)],e[i].second.second));
		UNION(e[i].second.first,e[i].second.second);
		pt[FIND(e[i].second.first)]=id;
		id++;
	}
	dfs(id-1);
	printf("%lld\n",dp[id-1]);
}



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

int main() {
  int N,K,x,distance;
  cin >> N >> K;
  for (int i = 0;i < N;i++){
    cin >> x;
    if (x <= K - x){
      distance += 2*x;    
    }
    else{
      distance += (K - x)*2;   
    } 
  }
  cout << distance << endl;
}

Measured memory_bytes: 256
function bomb(y,x){
   if(yx[y][x]=="#"){result="LOOP";return;}
   if(yx[y][x]=="."){result=x+" "+y;return;}
   var dx=0;
   var dy=0;
   if(yx[y][x]==">")dx++;
   if(yx[y][x]=="<")dx--;
   if(yx[y][x]=="^")dy--;
   if(yx[y][x]=="v")dy++;
   yx[y][x]="#";
   bomb(y+dy,x+dx);
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var n=Arr.shift().split(" ").map(Number);
   if(n[0]==0 && n[1]==0)break;
   var yx=[];
   for(var i=0;i<n[0];i++){
      var arr=(Arr.shift()).split("");
      yx.push(arr);
   }
   var result="";
   bomb(0,0);
   console.log(result);
}

Measured memory_bytes: 9576
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P pair<int,int>
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

signed main(){
  int n;
  cin >> n;
  vint A(n);
  rep(i,0,n) cin >> A[i];
  vint ans(n);
  int num = A[0];
  rep(i,1,n){
    num ^= A[i];
  }
  rep(i,0,n){
    ans[i] = num ^ A[i];
  }
  rep(i,0,n){
    cout << ans[i] << " ";
  }
}

Measured memory_bytes: 6360