akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define M_PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

int factorial[200001];

int powbin(int base, int p)
{
	ll mul;

	if (p == 1) mul = base;
	else {
		mul = (ll)powbin(base, p / 2);
		mul = (mul * mul) % MOD;
		if (p % 2) mul *= base;
	}

	return (int)(mul % MOD);
}

int combination(int n, int r)
{
	ll mul;

	mul = factorial[n];
	mul = (mul * powbin(factorial[r], MOD - 2)) % MOD;
	mul = (mul * powbin(factorial[n - r], MOD - 2)) % MOD;

	return (int)mul;
}

int main()
{
	int H, W, A, B;
	ll ans = 0, subans, f = 1;

	cin >> H >> W >> A >> B;

	factorial[0] = 1;
	repc(i, 1, H + W) {
		f = (ll)i * (ll)factorial[i - 1];
		factorial[i] = (int)(f % MOD);
	}

	rep(i, H - A) {
		subans = combination(i + B - 1, i);
		subans *= combination(H - i - 1 + W - B - 1, W - B - 1);
		subans %= MOD;
		ans = (ans + subans) % MOD;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(c, i, n) for (int i = c; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int N, D;
    cin >> N >> D;
    if (N % (1 + 2 * D) == 0)
    {
        cout << N / (1 + 2 * D) << endl;
    }
    else
    {
        cout << N / (1 + 2 * D) + 1 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
     
    using namespace std;
     
    int n;
    short s[510], t[510], a[64][510][510];
    unsigned long long u[510], v[510], ans[510][510], p[510];
    int cntHor[510][64], cntVer[510][64];
    bitset<64> hor[510], ver[510];
     
    void gen(){
    	p[0] = 1;
     
    	for(int i = 1; i < 64; i++) p[i] = p[i - 1] << 1;
    }
     
    void Fail(){
    	cout << "-1\n"; exit(0);
    }
     
    int main(){
    	gen();
    	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    	
    	cin >> n;
     
    	for(int i = 1; i <= n; i++) cin >> s[i];
    	for(int i = 1; i <= n; i++) cin >> t[i];
    	for(int i = 1; i <= n; i++) cin >> u[i];
    	for(int i = 1; i <= n; i++) cin >> v[i];
     
    	for(int k = 0; k < 64; k++){
    		for(int i = 1; i <= n; i++){
    			for(int j = 1; j <= n; j++){
    				if(s[i] == 0){
    					if(u[i] & p[k]) a[k][i][j] = 1;
    				} else {
    					if(u[i] & p[k]);
    					else a[k][i][j] = -1;
    				}
    			}
    		}
    	}
     
    	for(int k = 0; k < 64; k++){
    		for(int j = 1; j <= n; j++){
    			for(int i = 1; i <= n; i++){
    				if(t[j] == 0){
    					if(v[j] & p[k]){
    						if(a[k][i][j] == -1) Fail();
     
    						a[k][i][j] = 1;
    					}
    				} else {
    					if(v[j] & p[k]);
    					else {
    						if(a[k][i][j] == 1) Fail();
    						a[k][i][j] = -1;
    					}
    				}
    			}
    		}
    	}
     
    	for(int k = 0; k < 64; k++){
    		for(int i = 1; i <= n; i++){
    			for(int j = 1; j <= n; j++){
    				if(s[i] == 0 && a[k][i][j] != 1) cntHor[i][k]++;
    				if(t[j] == 0 && a[k][i][j] != 1) cntVer[j][k]++;
     
    				if(a[k][i][j] == 1){
    					if(s[i] == 1) hor[i][k] = true;
    					if(t[j] == 1) ver[j][k] = true;
    				}
    			}
    		}
    	}
     
    	for(int k = 0; k < 64; k++){
    		for(int i = 1; i <= n; i++){
    			for(int j = 1; j <= n; j++){
    				if(a[k][i][j] == 0){
    					if(s[i] == 1 && (t[j] == 1 || cntVer[j][k] > 1) && !hor[i][k]){
    						cntVer[j][k]--;
    						a[k][i][j] = 1;
    						hor[i][k] = true;
    					} else if (t[j] == 1 && (s[i] == 1 || cntHor[i][k] > 1) && !ver[j][k]){
    						cntHor[i][k]--;
    						a[k][i][j] = 1;
    						ver[j][k] = true;
    					}
    				}
     
    				if(a[k][i][j] == 1) ans[i][j] += p[k];
    			}
    		}
    	}
     
    	for(int i = 1; i <= n; i++){
    		unsigned long long x, y;
    		x = ans[i][1], y = ans[i][1];
     
    		for(int j = 1; j <= n; j++){
    			x &= ans[i][j];
    			y |= ans[i][j];
    		}
     
    		if(s[i] == 0 && u[i] != x) Fail();
    		else if (s[i] == 1 && u[i] != y) Fail();
    	}
     
    	for(int j = 1; j <= n; j++){
    		unsigned long long x, y;
    		x = ans[1][j], y = ans[1][j];
     
    		for(int i = 1; i <= n; i++){
    			x &= ans[i][j];
    			y |= ans[i][j];
    		}
     
    		if(t[j] == 0 && v[j] != x) Fail();
    		else if (t[j] == 1 && v[j] != y) Fail();
    	}
     
    	for(int i = 1; i <= n; i++){
    		for(int j = 1; j <= n; j++){
    			cout << ans[i][j] << " \n"[j == n];
    		}
    	}
     
    	return 0;
    }

Measured memory_bytes: 39532
N,K=gets.chomp.split.map(&:to_i)
S=gets.chomp.split("")
prev=S[0]
ss = []
ss << 0 if prev=='0'

cnt = 1
1.upto(N-1) do |i|
  if prev == S[i]
    cnt += 1
  else
    ss << cnt
    prev = S[i]
    cnt = 1
  end  
end
ss << cnt
ss << 0 if S[-1] == '0'

if ss.size/2 <= K
  puts N
  exit
end

tmp = 0
0.step(2*K) do |i|
  tmp += ss[i]
end
ans = tmp
(2*K+1).step(ss.size-2,2) do |i|
  tmp = tmp + ss[i] + ss[i+1] - ss[i-2*K-1] - ss[i-2*K]
  ans = tmp if tmp > ans
end
puts ans

Measured memory_bytes: 7804
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){
//		new A().doIt();
//		new B().doIt();
		new C().doIt();
//		new D().doIt();
	}
	class A{
		void doIt() {
			int N = sc.nextInt();
			int K = sc.nextInt();
			int X = sc.nextInt();
			int Y = sc.nextInt();
			
			int ans = 0;
			if(N <= K)ans = X*N;
			else ans = X*K + Y*(N - K);
			System.out.println(ans);
		}
	}
	class B{
		void doIt() {
			String str = sc.next();
			char ctr[] = str.toCharArray();
			int alf[] = new int [256];
			for(int i = 0;i < str.length();i++) {
				alf[ctr[i]]++;
			}
			System.out.println(check(alf));
		}
		String check(int alf[]) {
			for(char c = 'a';c <= 'z';c++) {
				if(alf[c] % 2 == 1)return "No";
			}
			return "Yes";
		}
	}
	class C{
		void doIt() {
			int N = sc.nextInt();
			int A = sc.nextInt();
			int x[] = new int[N];
			for(int i = 0;i < N;i++)x[i] = sc.nextInt();
			
			long box[][] = new long[51][3001];
			long ans = 0;
			
			box[0][0] = 1;
			for(int i = 0;i < N;i++)DP(box,i+1,x[i]);
			for(int i = 1;i <= N;i++)ans = ans + box[i][i*A];
			
			System.out.println(ans);
		}
		void DP(long box[][],int N,int num) {
			for(int i = N;i > 0;i--) {
				for(int j = num;j < 2501;j++) {
					box[i][j] = box[i][j] + box[i-1][j - num];
				}
			}
		}
	}
	class D{
		
	}
}


Measured memory_bytes: 25172
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#define MOD 1000000007
#define MAXN 200010
int head[MAXN], to[MAXN], next[MAXN], tot;
inline void $(int u, int v) {
    next[tot] = head[u], to[tot] = v, head[u] = tot++;
}
int size[MAXN], n, m, cur;
void dd(int x, int deep) {
    size[deep]++;
    m = std::max(m, deep);
    for (int i = head[x]; ~i; i = next[i]) dd(to[i], deep + 1);
}
struct state {
    long long v0, v1, v2;
    inline state(long long v0 = 0, long long v1 = 0, long long v2 = 0)
        : v0(v0), v1(v1), v2(v2) {}
    inline friend state operator|(const state &a, const state &b) {
        state ret;
        ret.v0 = a.v0 * b.v0 % MOD;
        ret.v1 = (a.v0 * b.v1 % MOD + a.v1 * b.v0 % MOD) % MOD;
        ret.v2 = (a.v0 * b.v2 % MOD + a.v1 * b.v1 % MOD + a.v1 * b.v2 % MOD +
                  a.v2 * b.v0 % MOD + a.v2 * b.v1 % MOD + a.v2 * b.v2 % MOD) %
                 MOD;
        return ret;
    }
};
inline long long fpow(long long x, int p) {
    register long long ret = 1;
    while (p) {
        if (p & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        p >>= 1;
    }
    return ret;
}
long long ans = 0, hf = fpow(2, MOD - 2), dl;
int pos[MAXN], ppp;
void g(int x) {
    pos[++ppp] = x;
    for (int i = head[x]; ~i; i = next[i]) g(to[i]);
}
std::vector<state> f[MAXN];
int p[MAXN], vnt;
inline int Merge(int x, int y) {
    if (f[x].size() < f[y].size()) std::swap(x, y);
    const int X = f[x].size(), Y = f[y].size();
    for (unsigned i = 0; i < f[y].size(); i++) {
        f[x][X - i - 1] = f[x][X - i - 1] | f[y][Y - i - 1];
    }
    return x;
}
int main() {
    std::cin >> n;
    dl = fpow(2, n + 1);
    memset(head, -1, sizeof(head));
    for (int i = 1; i <= n; i++) {
        int p;
        std::cin >> p;
        $(p, i);
    }
    g(0);
    for (register int _ = ppp; _; _--) {
        register int x = pos[_], y = 0;
        if (!~head[x]) {
            p[x] = vnt++;
            f[p[x]].push_back(state(hf, hf, 0));
        } else {
            p[x] = p[to[head[x]]];
            for (int i = next[head[x]]; ~i; i = next[i]) {
                y = std::max(y,
                             (int)std::min(f[p[x]].size(), f[p[to[i]]].size()));
                p[x] = Merge(p[x], p[to[i]]);
            }
            f[p[x]].push_back(state(hf, hf, 0));
        }
        const int size = f[p[x]].size() - 1;
        for (int i = 1; i <= y; i++)
            f[p[x]][size - i].v0 += f[p[x]][size - i].v2,
                f[p[x]][size - i].v2 = 0;
    }
    for (unsigned i = 0; i < f[p[0]].size(); i++) {
        (ans += f[p[0]][i].v1 * dl % MOD) %= MOD;
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 20592
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 100010;
const int MAXQ = 200010;

int M = 2000;
string a, b, c;
bool ab[MAXK], bc[MAXK], ac[MAXK];

bool match(char A, char B) {
    return (A == '?' || B == '?' || A == B);
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> a >> b >> c;
    int A = SZ(a), B = SZ(b), C = SZ(c);

    FOR(i,0,A-1) FOR(j,0,B-1) if (!match(a[i], b[j])) ab[i-j+50000] = true;
    FOR(i,0,A-1) FOR(j,0,C-1) if (!match(a[i], c[j])) ac[i-j+50000] = true;
    FOR(i,0,B-1) FOR(j,0,C-1) if (!match(b[i], c[j])) bc[i-j+50000] = true;

    int res = 3*M;
    FOR(i,-2*M,2*M)
        FOR(j,-2*M,2*M)
            if (!ab[i+50000] && !ac[j+50000] && !bc[j-i+50000]) {
                int L = min(0, min(i, j));
                int R = max(A, max(B + i, C + j));
                res = min(res, R - L);
            }
    cout << res;
    return 0;
}


Measured memory_bytes: 256
/**
	1.对题分析，要让转化次数越大，则先从最小开始。
	2.对一个数的x质数，最多能分为多少个不同的数
	3.只需求到根号n以内的变化值 
**/
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
int solve(int x){//计算以i为底，以x为指数一共有多少不同的值 
	int now=1,res=0;
	while(now<=x){
		x-=now;
		now++;
		res++;
	}
	return res;
}
int main(){
	ll n;
	int ans=0;
	cin>>n;
	for(ll i=2;i*i<=n;i++){
		if(n%i==0){
			int cnt=0;
			while(n%i==0){//计算以i为底的指数为多少 
				n/=i;
				cnt++;
			}
			ans+=solve(cnt);
		}
	}
	if(n!=1) ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3220
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long k,count=0,sum;
   cin>>k;
   for(int i=1;i<=k;i++)
   {
       for(int j=1;j<=k;j++)
       {
           if((i+j)%2!=0)
           {
               ++count;
           }
       }
   }
   cout<<count/2<<endl;
}



Measured memory_bytes: 256
use std::cmp::*;
use std::collections::*;
use std::io::*;
use std::str::FromStr;
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
fn main(){
    let n:usize = read();
    let w:usize = read();
    let mut weight:Vec<usize> = vec![0;n];
    let mut value:Vec<i64> = vec![0;n];
    for i in 0..n{
        weight[i] = read();
        value[i] = read();
    }
    let mut dp:Vec<Vec<i64>> = vec![vec![0;w + 1];n + 1];
    dp[0][0] = 0;
    for i in 0..n{
        for j in 0..w + 1{
            if(j as i64 - weight[i] as i64 >= 0){
                dp[i + 1][j] = max(dp[i][j],dp[i][j - weight[i]] + value[i]);
            }
            else {
                dp[i + 1][j] = dp[i][j];
            }
        }
    }
    //println!("{:?}",dp);
    println!("{}",dp[n][w]);
}

Measured memory_bytes: 81112
#include <bits/stdc++.h> 
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)
 
using ll  = long long;
using ull = unsigned long long;
using Pii = std::pair<int, int>;
 
int main(int argc, char *argv[])
{
    int N;
    std::cin >> N;

    int ans = 0;
    for (int i = 111; i < 1000; i += 111) {
        if (N <= i) {
            ans = i;
            break;
        }
    }    

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll n;
int main(){
    string s;
    cin>>s;
    int cnt1=0,cnt2=0;
    for(int i = 0;i < s.size(); i++){
        if((i+1)%2==0){
            if(s[i]!='0') cnt1++; //偶数番目を  0にする
            
        }
        else{
            if(s[i]!='1') cnt1++;
        }
    } 
    for(int i = 0;i < s.size(); i++){
        if((i+1)%2==0){
            if(s[i]!='1') cnt2++;
        }
        else{
            if(s[i]!='0') cnt2++;
        }
    }
    cout<<min(cnt1,cnt2)<<endl;
    return 0;
}

Measured memory_bytes: 512
// ACM-ICPCà\I2010 G. [U[õÌ½Ë

#include <iostream>
#include <vector>
#include <complex>

using namespace std;

typedef complex<double> P;

struct L {
	P p, q;
	L(P p, P q) : p(p), q(q) {}
};

const double EPS = 1e-8;
const double INF = 1e12;

double dot(P a, P b) { return real(conj(a)*b); }
double cross(P a, P b) { return imag(conj(a)*b); }
double angle(P a, P b) { return arg(conj(a)*b); }

P footPerp(L l, P p) {
	return l.p + (l.q-l.p)*(dot(l.q-l.p, p-l.p) / (abs(l.q-l.p)*abs(l.q-l.p)));
}

P lineShadow(L l, P p){
	return 2.0*footPerp(l, p)-p;
}

bool ssIntersect(L a, L b){
	if(abs(imag((a.q-a.p)/(b.q-b.p)))<EPS) return false;
	return cross(a.q-a.p, b.p-a.p)*cross(a.q-a.p, b.q-a.p) < 0 &&
    	   cross(b.q-b.p, a.p-b.p)*cross(b.q-b.p, a.q-b.p) < 0;
}

bool lpIntersect(L a, P p){
	return abs(imag((p-a.p)/(a.q-a.p)))<EPS;
}

P ssCrosspoint(L a, L b){
	double A = cross(a.q-a.p, b.q-b.p);
	double B = cross(a.q-a.p, a.q-b.p);
	return b.p + B/A * (b.q-b.p);
}

void check(vector<double> &agl, const vector<L> &vl, const vector<int> &idx, P s, P g){
	for(int i=0;i<idx.size();i++){
		if(lpIntersect(vl[idx[i]], g)) return ;
		g = lineShadow(vl[idx[i]], g);
	}
	agl.push_back(angle(P(1,0), g-s));
}

void dfs(vector<double> &agl, const vector<L> &vl, vector<int> &idx, P s, P g){
	check(agl, vl, idx, s, g);
	if(idx.size()==5) return ;
	for(int i=0;i<vl.size();i++){
		if(!idx.empty()&&idx.back()==i) continue;
		idx.push_back(i);
		dfs(agl, vl, idx, s, g);
		idx.pop_back();
	}
}

double calc(const vector<double> &agl, const vector<L> &vl, P s, P g){
	double res = INF;
	for(int i=0;i<agl.size();i++){
		P cur = s;
		P dir = P(cos(agl[i]), sin(agl[i]));
		double len = 0.0;
		for(int cnt=0; ;cnt++){
			P nxt = cur + 1000.0*dir;
			if(lpIntersect(L(cur, cur+dir), g)&&dot(dir, g-cur)>EPS) nxt = g;
			int idx = -1;
			for(int j=0;j<vl.size();j++){
				if(!lpIntersect(vl[j], cur)&&ssIntersect(L(cur, nxt), vl[j])){
					idx = j;
					nxt = ssCrosspoint(L(cur, nxt), vl[j]);
				}
			}
			len += abs(cur-nxt);
			if(abs(nxt-g)<EPS) break;
			if(idx == -1 || cnt == 6){
				len = INF;
				break;
			}
			dir = lineShadow(L(nxt, nxt+(vl[idx].q-vl[idx].p)*P(0,1)), cur) - nxt;
			dir /= abs(dir);
			cur = nxt;
		}
		res = min(res, len);
	}
	return res;
}

int main(){
	int n;
	while(cin >> n, n){
		P s, g;
		vector<L> vl;
		for(int i=0;i<n;i++){
			int px, py, qx, qy; cin >> px >> py >> qx >> qy;
			vl.push_back(L(P(px,py), P(qx,qy)));
		}
		int tx, ty, lx, ly; cin >> tx >> ty >> lx >> ly;
		s = P(tx, ty);
		g = P(lx, ly);
		vector<int> idx;
		vector<double> vd;
		dfs(vd, vl, idx, s, g);
		printf("%.4lf\n", calc(vd, vl, s,g));
	}
}

Measured memory_bytes: 1004
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>
typedef long long int ll;
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EREP(i, n) for (int i = (n - 1); i >= 0; --i)
#define D(n, retu)                                                             \
  REP(i, n) { cin >> retu[i]; }
#define mod 1000000007
#define INF 93193111451418101
#define MIN -93193111451418101
//#define INF 931931114518101
using namespace std;
typedef pair<ll, ll> P;
template <typename T> void fill_all(T &arr, const T &v) { arr = v; }
template <typename T, typename ARR> void fill_all(ARR &arr, const T &v) {
  for (auto &i : arr) {
    fill_all(i, v);
  }
}
#define yo 100001
//------------------変数-----------------------//
char grid[100][100];
//-------------------関数----------------------//
ll x[] = {-1, 0, 1, -1, 1, -1, 0, 1}, y[] = {1, 1, 1, 0, 0, -1, -1, -1};
int main() {
  fill_all(grid, '.');
  ll h, w;
  cin >> h >> w;
  FOR(i, 1, h + 1) {
    FOR(j, 1, w + 1) { cin >> grid[i][j]; }
  }
  FOR(i, 1, h + 1) {
    FOR(j, 1, w + 1) {
      if (grid[i][j] == '#') {
        cout << '#';
      } else {
        ll cnt = 0;
        REP(k, 8) {
          if (grid[i + x[k]][j + y[k]] == '#') {
            cnt++;
          }
        }
        cout << cnt;
      }
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <stack>

#define mod 1000000007
#define INF2 9999999999
#define INF (1<<30)
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
//#define P pair<int, int>

using namespace std;
using ll = __int64_t;

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

void solve(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if(abs(a-c) <= d){
    cout << "Yes" << endl;
  }else if(abs(a-b) <= d && abs(b-c) <= d){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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


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

main()
{
  int n,k;
  cin>>n>>k;
  int a[n];
  for(int i=0;i<n;++i) cin>>a[i];
  int ans[n]={};
  for(int i=1;i<n;++i)
  {
    ans[i]=INT_MAX;
    for(int j=1;j<=k and (i-j)>=0;++j)
      ans[i]=min(ans[i],abs(a[i]-a[i-j])+ans[i-j]);
  }
  cout<<ans[n-1];
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

long long dp[200][15][1121];
bool isprime[1121];
vector<int> primes;

int main(){
    memset(isprime, true, sizeof(isprime));
    for(int i=2;i<=1120;++i){
        if(isprime[i]){
            primes.push_back(i);
            for(int j=2;i*j<=1120;++j){
                isprime[i*j] = false;
            }
        }
    }
    int sz = primes.size();

    dp[0][0][0] = 1;
    
    for(int i=1;i<=sz;i++){
        for(int j=0;j<=14;j++){
            for(int k=0;k<=1120;k++){
                if(k+primes[i-1] <= 1120 && j != 14){
                    dp[i][j+1][k+primes[i-1]] += dp[i-1][j][k];
                }
                dp[i][j][k] += dp[i-1][j][k];
            }
        }
    }

    int n,k;
    while(cin >> n >> k){
        if((n|k) == 0) break;
        cout << dp[sz][k][n] << endl;
    }
}

Measured memory_bytes: 22000
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
const int MOD = 1e9 + 7;

ll N, M, K, Q, W, H, L, R, C;
string S, T;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int q;
    cin >> S >> T >> q;
    vector<int> a(q), b(q), c(q), d(q);
    for (int i = 0; i < q; i++) {
        cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
    }
    int s = (int)S.size();
    int t = (int)T.size();
    vector<ll> sa(s + 1), sb(s + 1);
    vector<ll> ta(t + 1), tb(t + 1);

    for (int i = 0; i < s; i++) {
        if (S[i] == 'A') {
            sa[i + 1] = 1;
        } else {
            sb[i + 1] = 1;
        }
    }
    for (int i = 0; i < t; i++) {
        if (T[i] == 'A') {
            ta[i + 1] = 1;
        } else {
            tb[i + 1] = 1;
        }
    }
    for (int i = 0; i < s; i++) {
        sa[i + 1] += sa[i];
        sb[i + 1] += sb[i];
    }
    for (int i = 0; i < t; i++) {
        ta[i + 1] += ta[i];
        tb[i + 1] += tb[i];
    }

    vector<bool> ans(q);
    for (int i = 0; i < q; i++) {
        ll snum = (sa[b[i]] - sa[a[i] - 1]) + (sb[b[i]] - sb[a[i] - 1]) * 2;
        ll tnum = (ta[d[i]] - ta[c[i] - 1]) + (tb[d[i]] - tb[c[i] - 1]) * 2;
        //cout << snum << " " << tnum << endl;
        if (snum % 3 == tnum % 3) {
            ans[i] = true;
        } else {
            ans[i] = false;
        }
    }
    for (int i = 0; i < q; i++) {
        if (ans[i]) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 5584
#include "omp.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <vector>
#include <cassert>
#include <fstream>
#include <algorithm>
#include <list>
#include <random>
#include <ctime>
#include <random>
#include <bitset>
#include <unordered_set>
#include <cassert>
#include <list>


using namespace std;

typedef long long ll;
typedef long double ld;


const int sze = 1 << 17, psze = 20;


signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int n;
	cin >> n;
	string l, r;
	cin >> l;

	r = l.substr(n, 100);
	l = l.substr(0, n);

	map<pair<string, string>, int> left, right;
	for (int i = 0; i < (1 << n); ++i)
	{
		string a, b;
		for (int j = 0; j < n; ++j)
		{
			if (i & (1 << j))
				a += l[j];
			else
				b += l[j];
		}

		left[{a, b}]++;
	}

	ll ans = 0;
	reverse(r.begin(), r.end());
	for (int i = 0; i < (1 << n); ++i)
	{
		string a, b;
		for (int j = 0; j < n; ++j)
		{
			if (i & (1 << j))
				a += r[j];
			else
				b += r[j];
		}

		if (left[{a, b}] != 0)
			ans += left[{a, b}];
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 91904
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int A,B;cin >> A >> B;
    if(A == 1 && B == 2)cout << 3 << endl;
    if(A == 1 && B == 3)cout << 2 << endl;
    if(A == 2 && B == 3)cout << 1 << endl;
    if(A == 2 && B == 1)cout << 3 << endl;
    if(A == 3 && B == 1)cout << 2 << endl;
    if(A == 3 && B == 2)cout << 1 << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	string S, T;
	cin >> S >> T;
	int ans = INF;
	FOR(i, T.size(), S.size() + 1) {
		int s = i - T.size();
		string sub = S.substr(s, T.size());
		int cur = 0;
		REP(j, T.size()) if (sub[j] != T[j]) ++cur;
		chmin(ans, cur);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n;
ll a[200005],b[200005],aa[200005];
ll ans[200005];
ll aans[200005];
int main(){
	scanf("%d",&n);
	repn(i,n){
		scanf("%lld",&a[i]);
	}
	stack<int>S;
	//Sには無限に0が入っているものとする
	b[1] = a[1];
	for(int i=2;i<=n;i++){
		ans[i] = ans[i-1];
		b[i] = a[i];
		if(b[i-1] >= b[i]){
			ll f = b[i-1]/b[i];
			while(f >= 4){
				f /= 4;
				S.push(i-1);
			}
		}
		else{
			while(b[i-1] < b[i]){
			    //cout<<b[i-1]<<" "<<b[i]<<endl;
				int x = 0;
				if(S.size()){
					x = S.top();
					S.pop();
				}
				b[i-1]*=4LL;
				ans[i] += i-1-x;
			}
		}
	}
	repn(i,n) aa[i] = a[n+1-i];
	stack<int>SS;
	b[1] = aa[1];
	//SSには無限に0が入っているものとする
	for(int i=2;i<=n;i++){
		aans[i] = aans[i-1];
		b[i] = aa[i];
		if(b[i-1] >= b[i]){
			ll f = b[i-1]/b[i];
			while(f >= 4){
				f /= 4;
				SS.push(i-1);
			}
		}
		else{
			while(b[i-1] < b[i]){
				int x = 0;
				if(SS.size()){
					x = SS.top();
					SS.pop();
				}
				b[i-1]*=4LL;
				aans[i] += i-1-x;
			}
		}
	}
	ll anss = 1e18;
	for(int i=0;i<=n;i++){
		anss = min(anss,2LL*(ans[i]+aans[n-i])+1LL*i);
	}
	cout<<anss<<endl;
}

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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver2 {
 public:
  int n, m, p;
  vector<int> reach;
  typedef pair<LL, int> PLI;
  struct Edge {
    int from, to;
    LL cost;
    Edge(int from, int to, LL cost)
        : from(from), to(to), cost(cost){};
  };
  typedef vector<vector<Edge>> Graph;
  Graph g, rev;
  Solver2(LL n, LL m, LL p) : n(n), m(m), p(p), reach(n + 1), g(n + 1), rev(n){};

  bool Bellman_Ford(const int start, const vector<vector<Edge>> &graph, vector<PLI> &prev) {
    int s = graph.size();
    bool update = true;
    fill(prev.begin(), prev.end(), make_pair(LINF, -1));
    prev[start] = make_pair(0ll, start);
    for (int i = 0; i < s && update; ++i) {
      update = false;
      for (int j = 0; j < s; ++j) {
        for (auto &e : graph[j]) {
          if (e.to < 0) continue;

          if (prev[j].first != LINF && prev[e.to].first > prev[j].first + e.cost) {
            prev[e.to].first = prev[j].first + e.cost;
            prev[e.to].second = j;
            update = true;
            if (i == s - 1) return false;
          }
        }
      }
    }

    return true;
  }

  void solve() {
    for (int i = 0; i < m; ++i) {
      int a, b;
      LL c;
      cin >> a >> b >> c;
      --a;
      --b;
      g[a].emplace_back(a, b, p - c);

      rev[b].emplace_back(b, a, p - c);
    }
    g[n - 1].emplace_back(n - 1, n, 0);
    reach[n - 1] = 1;
    reach[n] = 1;
    queue<int> Q;
    Q.push(n - 1);
    while (!Q.empty()) {
      int now = Q.front();
      Q.pop();
      for (auto &x : rev[now]) {
        if (!reach[x.to]) {
          reach[x.to] = 1;
          Q.push(x.to);
        }
      }
    }
    for (int i = 0; i < n; ++i) {
      for (auto &x : g[i]) {
        if (!reach[x.to]) {
          x.to = -1;
        }
      }
    }

    vector<PLI> prev(n + 1);
    bool ans = Bellman_Ford(0, g, prev);
    if (ans == false) {
      cout << -1 << endl;
    } else {
      cout << max(0LL, -prev[n].first) << endl;
    }
  }
};
}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0, m, p;
  std::cin >> n >> m >> p;

  Problem::Solver2 sol(n, m, p);
  sol.solve();
  return 0;
}


Measured memory_bytes: 768
from bisect import bisect_right

n = int(input())
order = sorted(list(map(int, input().split())))
ans = 0

for i in reversed(range(2, n)):
    for j in reversed(range(1, i)):
        ans += j - bisect_right(order[0:j], order[i]-order[j])

print(ans)

Measured memory_bytes: 52180
import java.util.Scanner;

/**
 * @author sguar <shugangcao@gmail.com>
 * welcome to kuaishou
 * Created on 2020-01-12
 */
public class Main {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        String s = cin.nextLine();
        char s0 = s.charAt(0);
        System.out.println((char) (s0+1));
    }
}


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

int main() {
    string S; cin >> S;
    vector<char> st(S.size());
    for (int i = 0; i < S.size(); i++) {
        st.at(i) = S.at(i);
    }
    sort(st.begin(), st.end());
    for (int i = 0; i < S.size()-1; i++) {
        if (st.at(i) == st.at(i+1)) {
            cout << "no" << endl;
            return 0;
        }
    }
    cout << "yes" << endl;
}

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

public class Main {
  Scanner sc;

  Main() {
    sc = new Scanner(System.in);
  }

  int ni() {
    return sc.nextInt();
  }

  int f(int y, int m, int d) {
    return (y - 1) * (19*5 + 20*5) + ((y - 1)/3)*5 + (m - 1)*20 - (y %3 == 0 ? 0 : (m - 1)/2) + d;
  }

  void run() {
    int n = ni();

    for(int i = 0; i < n; ++i) {
      int y = ni();
      int m = ni();
      int d = ni();

      System.out.println(f(1000, 1, 1) - f(y,m,d));
    }
  }

  public static void main(String[] args) {
    new Main().run();
  }

  void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  }
}

Measured memory_bytes: 20444
w = gets.chop.to_i
n = gets.chop.to_i

vls = (0...w).map { |k| k }
#p vls

for i in (0...n)
  a, b = gets.chop.split(",").map { |k| k.to_i - 1 }
  #p "#{a}<->#{b}"
  tmp = vls[a]; vls[a] = vls[b]; vls[b] = tmp
end

vls.each { |k| puts k + 1 }

Measured memory_bytes: 6100
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Integer[][] A = new Integer[N][2];
		for (int i = 0; i < A.length; i++) {
			A[i][0] = sc.nextInt();
			A[i][1] = i;
		}
		Arrays.sort(A, (x, y) -> {
			if (x[0].compareTo(y[0]) > 0) {
				return 1;
			} else if (x[0].compareTo(y[0]) < 0) {
				return -1;
			} else {
				return 0;
			}
		});
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < A.length; i++) {
			if (i != A[A.length - 1][1]) {
				sb.append(A[A.length - 1][0]);
			} else {
				sb.append(A[A.length - 2][0]);
			}
			sb.append("\n");
		}
		System.out.println(sb.toString());
		sc.close();
	}
}

Measured memory_bytes: 102564
#include<stdio.h>
#define m 200000
int main(void)
{
    int a[m],b[m],n,i,t=1;
    scanf("%d\n",&n);
    for(i=1;i<=n;i++)
{
    scanf("%d",&a[i]);
}
if(n%2==0)
{
    for(i=n;i>=2;i=i-2)
        b[t++]=a[i];
    for(i=1;i<=n-1;i=i+2)
        b[t++]=a[i];
}
else
{
    for(i=n;i>=1;i=i-2)
        b[t++]=a[i];
    for(i=2;i<=n-1;i=i+2)
        b[t++]=a[i];
}
for(i=1;i<=n;i++)
    printf("%d ",b[i]);
}

Measured memory_bytes: 3712
import sys

import math

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

if all(a == A[0] for a in A):
    print(0)
    sys.exit()

cm = math.ceil(sum(A) / len(A))
fm = math.floor(sum(A) / len(A))

kouho1, kouho2 = 0, 0
for a in A:
    kouho1 += (a - cm)**2
    kouho2 += (a - fm)**2
print(min(kouho1, kouho2))

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

int main(){
    string s;
    cin>>s;
    int n=s.size();
    ll ans=1;
    map<char,int>mp;
    rep(i,n){
        mp[s[i]]++;
        ans+=i+1-mp[s[i]];
    }
    cout<<ans<<endl;
}

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

using namespace std;

int main(){
    long long int m=1000000000000007,c;
    long int i,j;
    string s,t;
    cin>>s;
    cin>>t;
    long int f=t.length(),d=s.length();
    for(i=0;i<=(d-f);i++){
        c=0;
        for(j=0;j<f;j++){
            if(s[i+j]!=t[j]){
                c++;
            }
        }
        if(c<m){
            m=c;
        }
    }
    cout<<m;
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define MOD 1000000007
#define md %998244353
#define INF 2e9
#define EPS 1e-9
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define endl "\n"
#define FOR(i,a,b) for (long long i = a; i < b; i++)
#define REV(i,a,b) for (long long i = a; i > b; i--)
#define mset(a, v) memset(a, v, sizeof(a))
#define fd(n) fixed<<setprecision(n)
typedef std::pair<int, int> pii;
typedef std::vector<long long> vi;
typedef std::vector<vi> vvi;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll solve(ll x,ull y,ll p) {
    ll res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
  char c;
  cin>>c;
  
  if('z'>=c and c>='a')
    cout<<"a";
  else
    cout<<"A";
  
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define f(i,x,n) for(int i=x;i<(int)n;++i)
#define vpii vector<pair<int,int>>
#define vi vector<int>
#define mpii map<pair<int,int>,int>
#define mpivpii map<int,vector<pair<int,int>>>
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define mpi map<int,int>
#define vvi vector<vector<int>>
#define vvvi vector<vvi>
ld pie=3.141592653589;
int mod=1e9+7;

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

vi pr;

void solve(){
	int n; cin>>n;
	int a[n],b[n]; f(i,0,n) cin>>a[i]>>b[i];
	f(i,2,n){
		if(a[i]==b[i] && a[i-1]==b[i-1] && a[i-2]==b[i-2]){
			cout<<"Yes\n";
			return ;
		}
	}
	cout<<"No\n";
}


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

Measured memory_bytes: 3648
import java.util.Scanner;
class Main{
    public void yatary() {  
        Scanner sc = new Scanner(System.in);
        int i;
        int x;
        x = sc.nextInt();
        for(i=1; x!=0; i++){
            System.out.println("Case " + i + ": " + x);
            x = sc.nextInt();
        }
    }
    public static void main(String[] args){ 
        new Main().yatary();    
    }
}

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

int main() {
    std::ios::sync_with_stdio(false);
    string s ; cin >>s;
    if (s.length()%2!=0){cout << "No"; return 0;}
    for (int i = 0; i < s.length();i+=2){
        if (s[i]=='h' && s[i+1]=='i')continue;
        else {cout << "No"; return 0;}
    }
    cout << "Yes";
}

Measured memory_bytes: 764
# -*- coding: utf-8 -*-


N = int(input())
S = input()

count = 0

for i, s in enumerate(S[:-2]):
    if s != 'A':
        continue
    else:
        if N >= i + 2 and S[i+1] == 'B' and S[i+2] == 'C':
            count += 1

print(count)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 510000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  lli A,B,C,D,E,F,N,M,K,L,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N >> A >> B;
  M=N/(A+B);
  Out(A*M+(min(N-(M*(A+B)),A)));
}

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

typedef long long ll;

void print(){ std::cout << std::endl; }
template <typename Head> void print(Head&& head) { std::cout << head << std::endl; }
template <typename Head, typename... Tail> void print(Head&& head, Tail&&... tail)
{
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...); // or print(tail...);
}

ll a[51];
ll p[51];

ll f(ll level, ll x)
{
  if (x == 1) {
    return level == 0 ? 1 : 0;
  }
  if (1 < x && x < 1 + a[level-1] + 1) {
    return f(level-1, x-1);
  }
  if (x == 1 + a[level-1] + 1) {
    return p[level-1] + 1;
  }
  if (1 + a[level-1] + 1 < x && x < 1 + a[level-1] + 1 + a[level-1] + 1) {
    return p[level-1] + 1 + f(level-1, x - (1 + a[level-1] + 1));
  }
  if (1 + a[level-1] + 1 < x && x < 1 + a[level-1] + 1 + a[level-1] + 1) {
    return p[level-1] + 1 + f(level-1, x - (1 + a[level-1] + 1));
  }
  if (x == 1 + a[level-1] + 1 + a[level-1] + 1) {
    return p[level-1] * 2 + 1;
  }

  return -1;
}

int main(int argc, char* argv[])
{
  ll N, X;
  std::cin >> N >> X;

  a[0] = 1;
  p[0] = 1;
  for (ll i = 1; i <=50; i++) {
    a[i] = 2 * a[i-1] + 3;
    p[i] = 2 * p[i-1] + 1;
  }

  std::cout << f(N, X) << std::endl;
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    s = list(input())
    t = list(input())
    
    s.sort()
    t.sort()
    t.reverse()
    
    s = "".join(s)
    t = "".join(t)
    
    if s < t:
        print("Yes")
    else:
        print("No")
            	
if __name__ == "__main__":
	main()


Measured memory_bytes: 38512
#include <stdio.h>

int main(void){
    int a,b,c;

    scanf("%d %d %d", &a, &b, &c);

    if (a == b || b == c || c == a){
        if (a == b && b == c){
            printf("1");
        }
        else {
            printf("2");    
        }
    }
    else{
        printf("3");
    }

    return 0;
    
}

Measured memory_bytes: 1600
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>
#include <math.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define repv(x, arr) for (auto &x : arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 2147483600;
const ll infl = 1e17;

bool check(string s,int i){
    if (i%2==1)
        return false;
    int k = i / 2;
    rep(j,k){
        if (s[j]!=s[k+j])
            return false;
    }
    return true;
}

int main()
{
    string s;
    cin>>s;
    int n = s.size();
    repr(i,n-1,-1){
        if (check(s,i)){
            cout << i << endl;
            return 0;
        }
    }
}


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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int kekka = 0;

        if(a < c){
        	if(c < b){
        		if(b < d){
        			kekka = b - c;
        		}
        		else{
        			kekka = d - c;
        		}
        	}
        }

        if(c < a){
        	if(a < d){
        		if( d < b){
        			kekka = d - a;
        		}
        		else{
        			kekka = b - a;
        		}
        	}
        }

        else if(a==c){
        	if (b < d){
        		kekka = b - a;
        	}
        	else{
        		kekka = d - a;
        	}
        }

        System.out.println(kekka);
    }
}

Measured memory_bytes: 22612
import java.util.Scanner;

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

	int[] uta = new int[11];
	int[] iroha = new int[3];
	for(int i = 0; i < 3; i++){
	    iroha[i] = scan.nextInt();
	    uta[iroha[i]]++;
	}

	if(uta[5] == 2 && uta[7] == 1){
	    System.out.println("YES");
	}else{
	    System.out.println("NO");
	}
    }
}
    


Measured memory_bytes: 21844
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"
#include "cmath"
#include "set"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<ll> > mat;

int main()
{
  ll n, a, b;
  cin >> n >> a >> b;
  ll c = a + b;
  ll ans = (n / c) * a;
  ans += min(n % c, a);
  cout << ans << "\n";
}

Measured memory_bytes: 256
s = input().strip()

t1 = ('01' * (len(s) // 2 + 1))[:len(s)]
t2 = ('10' * (len(s) // 2 + 1))[:len(s)]

d1, d2 = 0, 0
for i in range(len(s)):
    cs, ct1, ct2 = s[i], t1[i], t2[i]
    if cs != ct1:
        d1 += 1
    else:
        d2 += 1

print(min(d1, d2))

Measured memory_bytes: 3444
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <sstream>
#include <fstream>

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

using namespace std;

int main() {
  int H, W;
  cin >> H >> W;
  vector< vector<char> > S(H, vector<char>(W));
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      cin >> S[i][j];
    }
  }
  int dx[4] = {0, 1, 0, -1};
  int dy[4] = {-1, 0, 1, 0};
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      bool isValid = false;
      if (S[i][j] != '#') continue;
      for (int k = 0; k < 4; ++k) {
	
	int yPos = i + dy[k];
	if (yPos < 0 || yPos > H - 1) continue;
	int xPos = j + dx[k];
	if (xPos < 0 || xPos > W - 1) continue;
	if (S[i][j] == '#' && S[yPos][xPos] == '#') isValid = true;
      }
      if (!isValid) {
	cout << "No" << endl;
	return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <forward_list>
#include <vector>
#include <cstdio>
#include <stack>
#include <algorithm>

using namespace std;

int cnt0 = 0;
int cnt1 = 0;
vector<int> sc;
vector<int> pre;
vector<int> low;

class Edge{
public:
    int v;
    int w;
    Edge(int vi,int wi):v(vi),w(wi){;}
};

class Graph{
public:
    int V;
    int E;
    vector<forward_list<int>> adj;
    Graph(int v,int e):V(v),E(e){
        adj.resize(V);
        sc.resize(V);pre.resize(V);low.resize(V);
        for(int i = 0; i< V;i++) {pre[i] = -1;low[i] = -1;}
    }
    void addEdge(int v,int w){adj[v].push_front(w);}
    void SCdfsR(Edge e);
};

stack<int> s;


void Graph::SCdfsR(Edge e){
    int w = e.w;
    int min_pre;
    s.push(w);
    pre[w] = cnt0++; low[w] = pre[w];min_pre = low[w];

    for(auto a = adj[w].begin();a!=adj[w].end();++a){
        int v = *a;
        if(pre[v] == -1) SCdfsR(Edge(w,v));
        min_pre = min(min_pre,low[v]);

    }

    if(min_pre < low[w]) {low[w] = min_pre;return;}
    else{
        int now;
        do{
            sc[(now = s.top())] = cnt1;
            s.pop();
            low[now] = V;
        }while(now != w);
        cnt1++;
    }
}


int main()
{
    int V,E,v,w;
    scanf("%d %d",&V,&E);
    Graph G(V,E);
    for(int i = 0; i < E;i++){
        scanf("%d %d",&v,&w);
        G.addEdge(v,w);
    }
    for(int i = 0; i < V;i++){
        if(pre[i] == -1){
            G.SCdfsR(Edge(i,i));
        }
    }
    int R;
    scanf("%d",&R);
    for(int i = 0; i < R;i++){
        scanf("%d %d",&v,&w);
        if(sc[v] == sc[w]) printf("%d\n",1);
        else printf("%d\n",0);
    }
}



Measured memory_bytes: 4408
def selective_sort(A):
    global N
    i = 0 
    swap = 0
    while i < N-1:
        mini = i 
        for j in range(i+1, N):
            if A[j] < A[mini]:
                mini = j
        if mini != i:
            A[i],A[mini] = A[mini],A[i]
            swap += 1
        i += 1
    return swap 

N = int(input())
A = list(map(int, input().split()))
swap = selective_sort(A)
print(' '.join(list(map(str, A))))
print(swap)

            


Measured memory_bytes: 5604