akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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 main(){
    int n, m;
    cin >> n >> m;
    vector<int> dp(n+10);
    rep(i, m){
        int num; cin >> num; 
        dp[num] = -1;
    }
    dp[0] = 1;
    int res = 0;
    rep(i, n){
        if(dp[i] == -1) continue;  
        if(dp[i+1] != -1) dp[i+1] += dp[i] % MOD;
        if(dp[i+2] != -1) dp[i+2] += dp[i] % MOD;
    }
    cout << dp[n] % MOD << ln;
}


Measured memory_bytes: 640
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(200002)

n, m = list(map(int, input().split()))

graph = [[] for i in range(n)]
for i in range(m):
    l, r, d = list(map(int, input().split()))

    graph[l-1].append([r-1, d])
    graph[r-1].append([l-1, -d])
# print(graph)


def dfs(s):
    for t, d in graph[s]:
        if x[t] is None:
            x[t] = x[s]+d
            if not dfs(t):
                return False
        else:
            if x[t]-x[s] != d:
                return False
    return True


x = [None]*n
ans = True
for i in range(n):
    if x[i] is None:
        x[i] = 0
        if not dfs(i):
            ans = False

print(('No', 'Yes')[ans])


Measured memory_bytes: 132120
using System;

class Class01
{
    public static void Main(string[] args)
    {
        while (true)
        {
            double x, y;
            double[] a = new double[6];
            string s = Console.ReadLine();
            if (s == null) break;
            string[] ss = s.Split();

            for (int i = 0; i < 6; i++)
            {
                a[i] = int.Parse(ss[i]);
            }
            x = (a[1] * a[5] - a[2] * a[4]) / (a[1] * a[3] - a[0] * a[4]);
            y = (a[0] * a[5] - a[2] * a[3]) / (a[0] * a[4] - a[1] * a[3]);

            Console.WriteLine("{0:f3} {1:f3}",Math.Floor(x*1000)/1000,Math.Floor(y*1000)/1000);
        }
    }
}

Measured memory_bytes: 9056
#include <bits/stdc++.h>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define ff first
#define setp setprecision(6)<<fixed
#define ss second
#define fori(v) for(lli i=0; i<v; i++)
#define forj(v) for(int j=0; j<v; j++)
#define fork(v) for(int k=0; k<v; k++)
#define forl(v) for(int l=0; l<v; l++)
#define fort(v) for(int t=0; t<v; t++)
#define forz(v) for(int z=0; z<v; z++)
#define lli long long int
#define MAX 220020
#define ld long double
#define pb push_back
int inf = pow(10,9)+7;
lli modulo = pow(10,9)+7;
double eps = 1e-11;
ifstream in;
ofstream out;
//#define cin in
//#define cout out
void disp(vector<pair<int,int> > edg, vector<int> w, int n){
	cout<<n<<" "<<edg.size()<<endl;
	fori(edg.size())
		cout<<edg[i].ff<<" "<<edg[i].ss<<" "<<w[i]<<endl;
}
void deal(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	lli sy1 = 0, sy2 = 0;
	int n,k;
	cin>>n>>k;
	for(int i=1; i<=n; i++){
		if(!(k&1) && (i%k == k/2))
			++sy1;
		else if((i%k==0))
			++sy2;
	}
	lli cav = 0;
	cav = sy1*sy1*sy1 + sy2*sy2*sy2;
	cout<<cav;
}

int main() {
	deal();
	return 0;
}   

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


int main(){
  ll n, sh;
  cin >> n >> sh;
  ll t[n];
  rep(i, n) cin >> t[i];
  ll ans = 0, now = 0;
  rep(i,n-1){
    now = t[i];
    ans += min(sh, t[i+1]-t[i]);
  }
  ans += sh;
  cout << ans << endl;
}


Measured memory_bytes: 5104
var
s:string;
i,l,sc,sf:longint; 
begin
read(s);
l:=length(s);sc:=maxlongint;
for i:=1 to l do if s[i]='F'then sf:=i;
for i:=l downto 1 do if s[i]='C'then sc:=i;
if sc<sf then writeln('Yes')
else writeln('No');
end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int h,w,a,b;
int c[1005][1005];
void check(){
    for(int i=1;i<=w;i++){
        int x=0;
        for(int j=1;j<=h;j++){
            x+=c[j][i];
        }
        if(x==b||h-x==b)continue;
        cout<<-1<<endl;
        exit(0);
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin>>h>>w>>a>>b;
    for(int i=1;i<=h;i++){
        if(i<=b){
            for(int j=1;j<=a;j++)c[i][j]=1;
        }else{
            for(int j=a+1;j<=w;j++)c[i][j]=1;
        }
    }
    check();
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++)cout<<c[i][j];
        cout<<endl;
    }
}

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

int main() {
    int height, width;
    cin >> height >> width;

    vector<vector<char> > table(height, vector<char>(width));
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            cin >> table.at(i).at(j);
        }
    }

    bool canPaint = true;
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            // 白く塗りたいマスは無視する
            if(table.at(i).at(j) == '.')
                continue;

            if(0 <= i-1 && i+1 < height && 0 <= j-1 && j+1 < width)
            {
                // 上下左右に'#'があれば、それと一緒に塗ることで、白く塗りたいマスを黒く塗らずに済む
                if(table.at(i-1).at(j) == '#' || table.at(i+1).at(j) == '#' || table.at(i).at(j-1) == '#' || table.at(i).at(j+1) == '#')
                    continue;
                // '#'がなければ、白く塗りたいマスを巻き込んで黒く塗ってしまうので、目的を達成できない
                else
                {
                    canPaint = false;
                    goto outOfNestedForLoop;
                }
                
            }
        }
    }
    outOfNestedForLoop:

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    vector<int> a(n,0);
    int x = 0;
    for(int i = 0; i<n; i++){
        cin>>a[i];
        x += (i%2==0?1:-1)*a[i];
    }
    x = x/2;
    for (int i = 0; i < n; i++)
    {
        cout<<2*x<<" ";
        x = a[i] - x;
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

i64 dfs(i64 now, char t, string s)
{
  if (now == 0)
  {
    cout << s << endl;
    return 0;
  }
  for (char i = 'a'; i <= t; i++)
    dfs(now - 1, max(t, (char)(i + 1)), s + i);
  return 0;
}

int main()
{
  i64 N;
  cin >> N;
  dfs(N, 'a', "");
  return 0;
}


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

using ll = long long;
using pii = pair<int, int>;

#define vt          vector
#define sz(x)       (int)(x).size()
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

signed main() {
    ios::sync_with_stdio(0), cin.tie(0);

    int n;
    ll k;
    cin >> n >> k;
    vt<int> a(n), f(n);
    for (int &i : a) cin >> i;
    for (int &i : f) cin >> i;

    sort(all(a));
    sort(rall(f));

    ll l = 0, r = 1ll << 60;
    while (l < r) {
        ll mi = (l + r) / 2;

        ll train = 0;
        for (int i = 0; i < n; i++) {
            if ((ll)a[i] * f[i] <= mi) continue;
            train += a[i] - mi / f[i];
        }

        if (train > k) l = mi + 1;
        else r = mi;
    }

    cout << l;
}


Measured memory_bytes: 4772
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String[] tokens = in.nextLine().split(" ");
		int H = Integer.parseInt(tokens[0]);
		int W = Integer.parseInt(tokens[1]);
		char[][] a = new char[H][W];
		for (int i = 0; i < H; ++i) {
			String line = in.nextLine();
			for (int j = 0; j < W; ++j) {
				a[i][j] = line.charAt(j);
			}
		}
		char[][] result = remove(a);
		for (int i = 0; i < result.length; ++i) {
			for (int j = 0; j < result[i].length; ++j) {
				System.out.print(result[i][j]);
			}
			System.out.println("");
		}
		in.close();
	}

	public static char[][] remove(char[][] origMat) {
		int rmRowIndex = checkRow(origMat);
		int rmColIndex = checkCol(origMat);
		char[][] temp = null;
		if (rmRowIndex < 0) {
			temp = origMat;
		} else {
			temp = removeRow(origMat, rmRowIndex);
		}
		char[][] temp2 = null;
		if (rmColIndex < 0) {
			temp2 = temp;
		} else {
			temp2 = removeCol(temp, rmColIndex);
		}
		if (origMat.length == temp2.length && origMat[0].length == temp2[0].length) {
			return temp2;
		} else {
			return remove(temp2);
		}
	}

	public static char[][] removeRow(char[][] origMat, int rmRowIndex) {
		char[][] result = new char[origMat.length - 1][origMat[0].length];
		for (int i = 0; i < rmRowIndex; ++i) {
			for (int j = 0; j < origMat[0].length; ++j) {
				result[i][j] = origMat[i][j];
			}
		}
		for (int i = rmRowIndex + 1; i < origMat.length; ++i) {
			for (int j = 0; j < origMat[0].length; ++j) {
				result[i - 1][j] = origMat[i][j];
			}
		}
		return result;
	}

	public static char[][] removeCol(char[][] origMat, int rmColIndex) {
		char[][] result = new char[origMat.length][origMat[0].length - 1];
		for (int i = 0; i < rmColIndex; ++i) {
			for (int j = 0; j < origMat.length; ++j) {
				result[j][i] = origMat[j][i];
			}
		}
		for (int i = rmColIndex + 1; i < origMat[0].length; ++i) {
			for (int j = 0; j < origMat.length; ++j) {
				result[j][i - 1] = origMat[j][i];
			}
		}
		return result;
	}

	public static int checkCol(char[][] mat) {
		int result = -1;
		for (int i = 0; i < mat[0].length; ++i) {
			boolean allSpace = true;
			for (int j = 0; j < mat.length; ++j) {
				if (mat[j][i] == '#') {
					allSpace = false;
					break;
				}
			}
			if (allSpace) {
				result = i;
				break;
			}
		}
		return result;
	}

	public static int checkRow(char[][] mat) {
		int result = -1;
		for (int i = 0; i < mat.length; ++i) {
			boolean allSpace = true;
			for (int j = 0; j < mat[i].length; ++j) {
				if (mat[i][j] == '#') {
					allSpace = false;
					break;
				}
			}
			if (allSpace) {
				result = i;
				break;
			}
		}
		return result;
	}
}

Measured memory_bytes: 27988
import sys

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 9 + 7

def P(m, n):
    num = 1
    for i in range(n):
        num = (num*(m-i)) % INF
    return num


n, k = list(map(int, sys.stdin.readline().split()))
graph = [dict() for i in range(n)]
for i in range(n):
    graph[i]["eda"]=[]
for i in range(n - 1):
    a, b = list(map(int, sys.stdin.readline().split()))
    graph[a - 1]["eda"].append(b - 1)
    graph[b - 1]["eda"].append(a - 1)
ans = 1
check = [False] * n
stack = [0]
ans = 1
while len(stack) > 0:
    x = stack.pop()
    check[x] = True
    count = 0
    for i in graph[x]["eda"]:
        if not check[i]:
            count += 1
            stack.append(i)
    if x == 0:
        temp = P(k - 1, count)
        ans = (ans * temp) % INF
    else:
        temp = P(k - 2, count)
        ans = (ans * temp) % INF

print((ans * k) % INF)


Measured memory_bytes: 91440
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=300030,mod=1000000007,to[9][2]={{1,3},{2,0},{1,1},{4,6},{5,3},{4,4},{7,6},{8,6},{7,7}};
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
int n,f[maxn][9],ans;
char s[maxn];
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	f[0][0]=1;
	FOR(i,0,n-1) FOR(j,0,8){
		if(s[i+1]!='1') f[i+1][to[j][0]]=(f[i+1][to[j][0]]+f[i][j])%mod;
		if(s[i+1]!='0') f[i+1][to[j][1]]=(f[i+1][to[j][1]]+f[i][j])%mod;
	}
	FOR(i,3,8) if(i!=5) ans=(ans+f[n][i])%mod;
	printf("%d\n",ans);
}
//.

Measured memory_bytes: 11136
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
#include <climits>

using namespace std;
int N, A, B, C, m = INT_MAX;
vector<int> take;

int calc(vector<int> v)
{
    int a = 0, b = 0, c = 0, mp = 0;
    for (int i = 0; i < N; i++)
    {
        if (v[i] == 0)
        {
            if (a > 0)
            {
                mp += 10;
            }
            a += take[i];
        }
        else if (v[i] == 1)
        {
            if (b > 0)
            {
                mp += 10;
            }
            b += take[i];
        }
        else if (v[i] == 2)
        {
            if (c > 0)
            {
                mp += 10;
            }
            c += take[i];
        }
    }
    if(!a || !b || !c) {
        return INT_MAX;
    }
    mp += abs(A - a);
    mp += abs(B - b);
    mp += abs(C - c);
    return mp;
}

int dfs(int d, vector<int> v)
{
    if (d == N)
    {
        return m = min(calc(v), m);
    }
    for (int i = 0; i < 4; i++)
    {
        v[d] = i;
        dfs(d + 1, v);
    }
}

int main()
{
    cin >> N >> A >> B >> C;
    for (int i = 0; i < N; i++)
    {
        int l;
        cin >> l;
        take.push_back(l);
    }
    vector<int> v(N, 0);
    dfs(0, v);
    cout << m << endl;
}


Measured memory_bytes: 384
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main() {
  int n, k, s;
  cin >> n >> k >> s;

  const int MAX = 500'000'000;

  if (s >= MAX / 2) {
    rep(i, n) { cout << (i < k ? s : 1) << " "; }
    cout << endl;
  } else {
    rep(i, n) { cout << (i < k ? s : 2 * s) << " "; }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1280
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC114A
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = int.Parse(Console.ReadLine());

            if (x == 3 || x == 5 || x == 7)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");

            Console.ReadKey();
        }
    }
}


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


public class Main {
    static long mod = 1000000000+7;
    static int maxn=2;
    static long[] f5ac, inv;
    static ArrayList<Integer>[] rec;
    static int[] v;
    static int n,q;
    public static void main(String[] args) throws Exception {
        //Scanner sc = new Scanner(System.in);
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String[] buf = reader.readLine().split(" ");
        n = Integer.parseInt(buf[0]); q = Integer.parseInt(buf[1]);
        TreeMap<Integer,Integer> valIdx = new TreeMap<>();
        int[] D = new int[q];
        block[] rec = new block[n];
        for(int i=0;i<n;i++){
            buf = reader.readLine().split(" ");
            int s = Integer.parseInt(buf[0]), t = Integer.parseInt(buf[1]), x = Integer.parseInt(buf[2]);
            rec[i] = new block(s,t,x);
        }
        for(int i=0;i<q;i++){
            buf = reader.readLine().split(" ");
            D[i] = Integer.parseInt(buf[0]);
            valIdx.put(D[i],i);
        }
        Arrays.sort(rec,(a,b)->(a.x-b.x)); // let the ones with smaller x come first
        // check for every block
        int inf = Integer.MAX_VALUE/2;
        int[] res = new int[q];
        Arrays.fill(res,inf);
        for(int i=0;i<n;i++){
            block cur = rec[i];
            Integer left = valIdx.ceilingKey(cur.s-cur.x);
            Integer right = valIdx.lowerKey(cur.t-cur.x);
            if(left==null||right==null||left>right) continue; // no person affected
            int riBound = right;
            while(left!=null&&left<=riBound){
                int pos = valIdx.get(left);
                res[pos] = cur.x;
                valIdx.remove(left);
                left = valIdx.ceilingKey(cur.s-cur.x);
            }
        }
        PrintWriter out = new PrintWriter(System.out);
        for(int i=0;i<q;i++){
            if(res[i]==inf) out.println(-1);
            else out.println(res[i]);
        }
        out.flush();
    }
    static class block{
        int s, t, x;
        public block(int st, int te, int pos){
            this.s = st; this.t = te; this.x = pos;
        }
    }
}



Measured memory_bytes: 95164
def isEnd(list):
    if (list[0]==0) and (list[1]==0):
        return True
    return False

def answer(list):
    kumi = 0
    if list[1] < 6:
        return kumi
    for i in range(1, list[1]+1):
        for j in range(i+1, list[1]+1):
            another = list[1]-i-j
            if (another > j) and(another <= list[0]):
                kumi += 1
    return kumi

flag = True
a = []

while flag:
    t = list(map(int, input().split()))
    if isEnd(t):
        flag = False
        continue
    a.append(t)

for i in a:
    ans = answer(i)
    print(ans)


Measured memory_bytes: 5600
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let vec: Vec<i32> = read_vec();
    if (vec[0] * vec[1]) % 2 == 0 {
        println!("Even");
    } else {
        println!("Odd");
    }
}


Measured memory_bytes: 4352
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
ll N;
const ll MAX_N=500,INF=1e18;
ll dp[MAX_N+1],mv[MAX_N+1],a[MAX_N][MAX_N];
void dfs(ll l,ll r,ll lev){
	if(r-l==1)return;
	ll m=mv[r-l];
	FOR(i,l,l+m){
		FOR(j,l+m,r){
			a[i][j]=lev;
		}
	}
	dfs(l,l+m,lev+1);
	dfs(l+m,r,lev+1);
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>N;
	dp[1]=0;
	FOR(n,2,N+1){
		dp[n]=INF;
		FOR(j,1,n){
//			dp[n]=min(dp[n],max(dp[j],dp[n-j])+1);
			if(dp[n]>max(dp[j],dp[n-j])+1){
				dp[n]=max(dp[j],dp[n-j])+1;
				mv[n]=j;
			}
		}
	}
	dfs(0,N,1);
	REP(i,N-1){
		REP(j,N-i-1){
			if(j)cout<<' ';
			cout<<a[i][i+j+1];
		}
		cout<<endl;
	}
}

Measured memory_bytes: 2432
#include <stdio.h>
#include <ctype.h> //??????????????¢??£???????????????

int main(void)
{
  int i=0;
  char str[1200];

  scanf("%[^\n]",str); //[^??????] == ????????????????????§

  for(i=0; (!(str[i])) == '\0'; i++){ //??????????????????????????§
    if(isupper(str[i])) //??§????????????
      str[i] = tolower(str[i]); //?°??????????
    else //?°?????????????
      str[i] = toupper(str[i]); //??§?????????
  }
  
  printf("%s\n",str);
  
  return(0);
}

Measured memory_bytes: 952
import java.util.*;

//素数探索系 cf p0009
//素数を各々取得するのでArrayListでデータを取得するのがよい。
//データを挿入する時には、LinkedListの方が早いので途中でコピーするのもあり。

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

	public void run() {
		while(sc.hasNext()){
			double n=sc.nextDouble();
			double sum=n;
			for(int i=2;i<=10;i++){
				if(i%2==0){
					n*=2;
				}else{
					n/=3;
				}
				sum+=n;
			}
			ln(sum);
		}
	}

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

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}

	public static void ln() {
		System.out.println();
	}
}

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

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

ll lcm(ll a, ll b)
{
   return a * b / gcd(a, b);
}

int main(){
  ll A, B, C, D; cin>>A>>B>>C>>D;
  ll ansb=(B/C)+(B/D)-(B/lcm(C, D));
  ll ansa=((A-1)/C)+((A-1)/D)-((A-1)/lcm(C, D));
  // cout<<lcm(C, D)<<endl;
  cout<<B-A+1-(ansb-ansa)<<endl;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;


#[fastout]
fn solve() {
    const MOD: usize = 1_000_000_007;
    const INF: usize = std::usize::MAX;
    
    input!{
        mut a: isize, b: isize, mut c: isize, d: isize,
    }

    // true: takahashi, false: aoki
    let mut player = true;

    loop {
        if player {
            c -= b;
        } else {
            a -= d;
        }

        if a <= 0 || c <= 0 {
            break;
        }

        player = !player;
    }

    if player {
        println!("Yes");
    } else {
        println!("No");
    }
    
}


fn main() {
    solve()
}

#[cfg(test)]
mod test {
    use super::solve;
}


Measured memory_bytes: 2200
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
namespace io{
    #define ll long long
    #define inf 0x3f3f3f3f
    #define il inline
    #define re register
    #define in1(a) read(a)
    #define in2(a,b) in1(a),in1(b)
    #define in3(a,b,c) in2(a,b),in1(c)
    #define in4(a,b,c,d) in2(a,b),in2(c,d)
    il void readl(ll &x){
        x=0;ll f=1;char c=getchar();
        while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
        x*=f;
    }
    il void read(int &x){
        x=0;int f=1;char c=getchar();
        while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
        x*=f;
    }
}using namespace io;
#define N 100005
int n,k,q;
int a[N];
int main(){
	int x;
	in3(n,k,q);
	while(q--){
		read(x);
		a[1]--;
		a[x]++;
		a[x+1]--;
		a[n+1]++;
	}
	for(re int i=1;i<=n;i++){
		a[i]+=a[i-1];
		if(a[i]+k>0) puts("Yes");
		else puts("No");
	}
	return 0;
}

Measured memory_bytes: 896
class unionfind:
	def __init__(s,n):
		s.size = n
		s.ufp = [i for i in range(n)]
		s.ufr = [1 for i in range(n)]
	def find(s,x):
		if x == s.ufp[x]:
			return x
		else:
			s.ufp[x] = s.find(s.ufp[x])
			return s.ufp[x]
	def union(s,x,y):
		x = s.find(x)
		y = s.find(y)
		if x == y:
			return 0
		if s.ufr[x] > s.ufr[y]:
			s.ufp[y] = x
			s.ufr[x] += s.ufr[y]
			return ((s.ufr[x]-s.ufr[y])*s.ufr[y])
		else:
			s.ufp[x] = y
			s.ufr[y] += s.ufr[x]
			return ((s.ufr[y]-s.ufr[x])*s.ufr[x])
n,m=map(int,input().split())
ans=[n*(n-1)//2]
g=[list(map(lambda a:int(a)-1,input().split())) for i in range(m)]
uf = unionfind(n)
for v in reversed(g):
	ans.append(ans[-1]-uf.union(v[0],v[1]))
for v in reversed(ans[:-1]):
	print(v)

Measured memory_bytes: 34984
from operator import mul
from functools import reduce
 
def cmb(n,r):
    r = min(n-r,r)
    if r==0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
  

from collections import defaultdict
dic = defaultdict(int)
N = int(input())
for n in range(N):
  s = list(input())
  s.sort()
  k = tuple(s)
  dic[k] += 1
ans = 0
for k in dic.keys():
  if dic[k]<2:
    continue
  ans += cmb(dic[k],2)
print(ans)


Measured memory_bytes: 130776
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#define db double
#define ll long long
#define inf 0x3f3f3f3f
#define FAST_IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
const int maxn=1e5+7;
int main(){
	FAST_IO;
	int n,a;
	int mx;
	cin >> n;
	int flag=0;
	cin >> a;
	mx=a;
	for(int i=1;i<n;i++){
		cin >> a;
		if(mx-a>=2){
			flag=1;
		}
		mx=max(a,mx);
	}
	if(flag==1) cout << "No" << endl;
	else cout << "Yes" << endl; 
	return 0;
}

Measured memory_bytes: 256
/*
ID:dyx_6661
TASK:
LANG:
*/
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<stack>
#include<algorithm>
#include<deque>
#include<set>
#include<map>
#include<vector>
#include<iostream>
using namespace std;
typedef long long int ll;
typedef double db;
typedef string str;
typedef pair<int,int> pa;
typedef vector<int> vec;

const int n_size=1e5+5;

ll f[2*n_size][30];
char a[2*n_size],b[n_size];
 
ll ans=0,cnt=1;
 
int main(){
//  freopen(".in","r",stdin);
//  freopen(".out","w",stdout);
	scanf("%s",a+1);scanf("%s",b+1);
	ll n=strlen(a+1),m=strlen(b+1);
	for(ll i=1;i<=n;i++) a[i+n]=a[i];
	for(ll i=2*n;i>=1;i--){
		for(int j=1;j<=26;j++){
			if(a[i]==j+'a'-1){
				f[i][j]=i;
			}else{
				f[i][j]=f[i+1][j];
			}
		}
	}
	
	for(ll i=1;i<=m;i++){
		if(!f[1][b[i]-'a'+1]){
			printf("-1");
			return 0;
		}
		ans+=f[cnt][b[i]-'a'+1]-cnt+1;
		if(f[cnt][b[i]-'a'+1]>n) cnt=f[cnt][b[i]-'a'+1]-n;
		cnt=f[cnt][b[i]-'a'+1]+1;
	}
	printf("%lld",ans);
	return 0;
}


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

using namespace std;

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

int A, B, Q;
int s[110000], t[110000], x[110000];

signed main() {
    cin >> A >> B >> Q;
    for (int i = 1; i <= A; i++)cin >> s[i];
    for (int i = 1; i <= B; i++)cin >> t[i];
    s[0] = t[0] = -1e11;
    s[A + 1] = t[B + 1] = 1e11;
    for (int i = 0; i < Q; i++)cin >> x[i];
    for (int i = 0; i < Q; i++) {
        auto sb = lower_bound(s, s + A + 2, x[i]), tb = lower_bound(t, t + B + 2, x[i]);
        int s1 = abs(x[i] - *(sb - 1)), s2 = abs(x[i] - *sb), t1 = abs(x[i] - *(tb - 1)), t2 = abs(x[i] - *tb);
        int c = min(max(s1, t1), max(s2, t2));
        c = min(c, s1 + t2 * 2);
        c = min(c, s1 * 2 + t2);
        c = min(c, s2 + t1 * 2);
        c = min(c, s2 * 2 + t1);
        cout << c << endl;
    }
}


Measured memory_bytes: 3712
object Main extends App {
  val amount = Array(500,100,50)
  val in = Iterator.continually(io.StdIn.readLine.toInt)
    .take(4).toArray

  val ans = {
      for {
        i <- 0 to in(0)
//        if amount(0)*i <= in(3)
        j <- 0 to in(1)
//        if amount(1)*j <= in(3)
        k <- 0 to in(2)
        if amount(0)*i + amount(1)*j + amount(2)*k == in(3)
      } yield  true
    }.size

  println(ans)
}

Measured memory_bytes: 27904
#include <cstdio>
#define scanf __builtin_scanf
#include <algorithm>
using namespace std;

const long mod=1000003;
long fact[1000010];

long modpow(long x, long n)
{
    long res=1;
    for(; n>0; n>>=1) {
        if (n&1) res=res*x%mod;
        x=x*x%mod;
    }
    return res;
}

int main()
{
    fact[0]=1;
    for(int i=1; i<mod; ++i) fact[i]=fact[i-1]*i%mod;

    int Q; scanf("%d", &Q);
    while (Q--) {
        int x, d, n; scanf("%d%d%d", &x, &d, &n);
        if (d==0) {
            printf("%ld\n", modpow(x, n));
            continue;
        }
        auto a=x*modpow(d, mod-2)%mod;
        if (mod-(n-1)<=a or a==0) {
            puts("0");
            continue;
        }
        printf("%ld\n", modpow(d, n)*fact[a+n-1]%mod*modpow(fact[a-1], mod-2)%mod);
    }
}


Measured memory_bytes: 8576
module Main where
import qualified Control.Monad as C
import qualified Data.Char as C
import qualified Data.List as L
import qualified Data.Map as M
import qualified Data.Array as A

int = read :: String -> Int
getWord :: IO String
getWord = do
  c <- getChar
  if C.isSpace c
  then
    return []
  else do
    ws <- getWord
    return (c:ws)
getInt = fmap int getWord
replace pred a = map (\x -> if pred x then a else x)

main = interact $ printer . solver . parser
parser :: String -> [Int]
parser = map int . words 
printer :: [Int] -> String
printer = (++"\n") . unwords . map show

solver [n,x,y] = [min x y, max 0 (x+y-n)]

Measured memory_bytes: 508
#include<cstdio>
#include<string>
#include<vector>
#include<fstream>
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<cwctype>
#include<algorithm>
#include<math.h>

using namespace std;

int data[101];

int gcd(int x,int y){
	if(y==0)return x;
	if(x>y)return gcd(y,x%y);
	else return gcd(x,y%x);
}

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

	cout<<gcd(a,b)<<endl;

		return 0;
}

Measured memory_bytes: 1160
a,b = input().split()

a = int(a)
b_list = list(b)
b_list.pop(1)
b_list = [int(s) for s in b_list]

p_100 = a*b_list[0]*100 + a*b_list[1]*10 + a*b_list[2]
p = p_100//100

print(p)

Measured memory_bytes: 9168
n,m,v,p = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse = True)

ok = p-1
ng = n
while ng-ok > 1:
    mid = (ok+ng)//2

    if v-1 <= p-2:
        if a[mid]+m >= a[p-1]:
            ok = mid
        else:
            ng = mid
    else:
        if a[mid]+m < a[p-1]:
            ng = mid
        else:
            r = v-p
            cnt = 0
            for i in range(p-1,n):
                if i == mid:
                    continue
                cnt += min(m,a[mid]+m-a[i])
            if cnt >= r*m:
                ok = mid
            else:
                ng = mid
print(ok+1)

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

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

long long nCr(long long n, long long r){
  long long ans = 1;
  for(long long i = n; i > n - r; i--){
    ans = ans*i;
    ans %= 1000000007;
  }
  for(long long i = 1; i < r + 1; i++){
    ans *= modinv(i, 1000000007);
    ans %= 1000000007;
  }
  return ans;
}

int main(){
  long long X, Y;
  cin >> X >> Y;
  long long nowX = 0, nowY = 0;
  map<long long, long long> road1;
  while(nowY <= Y){
    road1.insert(make_pair(nowX, nowY));
    nowX += 1;
    nowY += 2;
  }
  nowX = X, nowY = Y;
  bool canGoal = false;
  while(nowX >= 0){
    if(road1.count(nowX) == 0){
      nowX -= 2;
      nowY -= 1;
    }else{
      if(road1[nowX] != nowY){
        nowX -= 2;
        nowY -= 1;
      }else{
        canGoal = true;
        break;
      }
    }
  }
  if(canGoal){
    long long numAct1 = nowX;
    long long numAct2 = Y - nowY;
    long long ans = nCr(numAct1+numAct2, numAct1);
    cout << fixed;
    cout << setprecision(10) << ans << endl;
  }else cout << 0 << endl;
}

Measured memory_bytes: 31488
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main() {
    int N; cin >> N;
    char s[100];
    sprintf(s, "%d", N);
    int len = strlen(s);
    bool ok = false;
    for (int i = 0; i < len; ++i) {
        if (s[i] == '7') {
            ok = true;
        }
    }
    if (ok) {
        puts("Yes");
    } else {
        puts("No");
    }
    return 0;
}


Measured memory_bytes: 3752
# include <cmath>
# include <iostream>
# include <queue>
# include <set>
# include <stack>
# include <string>
# include <vector>


using namespace std;


int main() {
    int a1, a2, a3; cin >> a1 >> a2 >> a3;
    if (a1+a2+a3 >= 22) {
        cout << "bust" << endl;
    }
    else {
        cout << "win" << endl;
    }
    return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<stack>
using namespace std;
typedef long long ll;
int main(){
	int a,b,c,t;
	cin>>a>>b>>c;
	if(a>c){
		t=a; a=c; c=t;
	} 
	if(a>b){
		t=a; a=b; b=t;
	}
	if(b>c){
		t=b; b=c; c=t;
	}
	cout<<a*b/2;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
signed main(){
  int a,b;
  cin>>a>>b;
  if(a%2==1&&b%2==1)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define maxn 100005
using namespace std;
int a[maxn],q[maxn][2],lq=0,l1,r1,l2,r2,n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	l1=-1;  r1=-1;  l2=n;  r2=n;
	for(int i=1;i<=n;i++)
	  if(a[i]<0)r1=i,l2=i;
	  else break;
	
	if(l1<r1&&l2<r2){
	  while(1)
	  {
	    if(l2+1<r2){
	      q[++lq][0]=a[r1];  q[lq][1]=a[l2+1];
	      a[r1]-=a[l2+1];
	      l2++;
	    }
	    else break;
	  }
	  for(int i=1;i<=r1;i++)q[++lq][0]=a[n],q[lq][1]=a[i],a[n]-=a[i];
	  printf("%d\n",a[n]);
	}
	else if(l1<r1){
	  for(int i=1;i<n;i++)q[++lq][0]=a[n],q[lq][1]=a[i],a[n]-=a[i];
	  printf("%d\n",a[n]);
	}
	else {
	  for(int i=2;i<n;i++)q[++lq][0]=a[1],q[lq][1]=a[i],a[1]-=a[i];
	  q[++lq][0]=a[n];  q[lq][1]=a[1];
	  a[n]-=a[1];
	  printf("%d\n",a[n]);
	}
	for(int i=1;i<=lq;i++)printf("%d %d\n",q[i][0],q[i][1]);
	return 0;
}

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


int main() {
  int x, a;
  cin >> x >> a;
  if (x < a) {
    cout << 0 << endl;
  } else {
    cout << 10 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iterator>
#include <iomanip>
#include <cmath>
#include <vector>
#include <numeric>
#include <cstdio>
#include <bitset>
#include <map>
#include <string>
// #include <cctype>


using namespace std;

int main()
{
    int n;
    while (cin >> n && n != 0)
    {

        vector<double> scores(n);
        double sum = 0;

        int i = 0;
        while (i < n)
        {
            cin >> scores[i];
            sum += scores[i++];
        }

        
        double mean = sum/n;

        i = 0;
        double variance = 0;
        while (i < n)
        {
            variance += pow(scores[i++]-mean, 2)/n;
        }

        double deviation = sqrt(variance);

        cout << fixed << deviation << endl;
    }
}


Measured memory_bytes: 3276
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"
#include "string"

using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i = 0; i < (n); i++)

int main() {
	cout << fixed << setprecision(10);
	int w, h, x, y;
	cin >> w >> h >> x >> y;
	cout << (double)w * h / 2 << " ";
	if (w == x * 2 && h == y * 2) cout << 1 << endl;
	else cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 3788
#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 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long 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())
vector<pair<string,P> >vec;

void solve(long long N, vector<long long> A, vector<long long> B){
	ll res = 0;
	rep(i, N) {
		if (A[i] >= B[i]) {
			res += B[i];
		} else {
			B[i] -= A[i];
			res += A[i];
			if (A[i+1] >= B[i]) {
				A[i+1] -= B[i];
				res += B[i];
			} else {
				res += A[i+1];
				A[i+1] = 0;
			}
		}
	}
	cout << res << endl;
}

int main(){	
	long long N;
	scanf("%lld",&N);
	vector<long long> A((N+1)-1+1);
	vector<long long> B(N-1+1);
	for(int i = 0 ; i <= (N+1)-1 ; i++){
		scanf("%lld",&A[i]);
	}
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&B[i]);
	}
	solve(N, A, B);
	return 0;
}



Measured memory_bytes: 3328
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL){
    x = x->right;
  }
  return x;
}

Node treeSearch(Node u, int k){
  if(u == NIL || k == u->key){
    return u;
  }
  if(k < u->key){
    return  treeSearch(u->left,k);
  }
  else{
    return treeSearch(u->right,k);
  }
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL){
    return treeMinimum(x->right);
  }
  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL || z->right == NIL){
    y = z;
  }
  else{
    y = treeSuccessor(z);
  }

  if(y->left != NIL){
    x = y->left;
  }
  else{
    x = y->right;
  }

  if(x != NIL){
    x->parent = y->parent;
  }

  if(y->parent == NIL){
    root = x;
  }
  else if(y == y->parent->left){
    y->parent->left = x;
  }
  else{
    y->parent->right = x;
  }

  if(y != z){
    z->key = y->key;
  }
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }

  z->parent = y;

  if(y == NIL){
    root = z;
  }
  else if(z->key < y->key){
    y->left = z;
  }
  else{
    y->right = z;
  }

}

void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  if(u != NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);

    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);

      if ( t != NIL ) printf("yes\n");
      else printf("no\n");

    } 
    else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } 
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } 
    else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }
  
  return 0;
}

Measured memory_bytes: 19364
/*
C++14
iloveUtaha
seica
fumiphys
autumn_eel
FF256grhy


Python3 (3.4.3)
maspy

PyPy3 (2.4.0)
blcn
*/

#include <bits/stdc++.h>
using namespace std;

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  vector<vector<ll>> a(4, vector<ll>(4));
  REP1(i, 4){
    REP1(j, 4){
      cin >> a[i][j]; 
    }
  }

  if(a[2][2] == a[2][1] + a[1][2] - a[1][1] && a[3][2] == a[3][1] + a[2][2] - a[2][1] \
      && a[2][3] == a[2][2] + a[1][3] - a[1][2] && a[3][3] == a[3][2] + a[2][3] - a[2][2])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    string s;
    cin >> s;
    int ans = 0;
    for(char c: s)
        ans += (c-'0');
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

int main()
{
    ll N, K;
    cin >> N >> K;
    ll A[N+3];
    ll P[N+3];
    for(int i = 0; i < N; ++i) cin >> A[i];
    ll x = 0;
    for(int i = 0; i < N; ++i) {
        for(int j = i + 1; j < N; ++j)
            if(A[i] > A[j]) x = (x + 1)%mod;
        int tmp = 0;
        for(int j = 0; j < N; ++j) {
            if(i != j && A[j] < A[i]) ++tmp;
        }
        P[i] = tmp;
    }

    ll res = 0;
    res = (x*K)%mod;
    ll sm = (K%2 == 0) ? (K/2)*(K-1)%mod : K*((K-1)/2)%mod ;
    for(int i = 0; i < N; ++i) {
        ll tmp = P[i]*sm%mod;
        res = (res + tmp)%mod;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
/*
        _            _                  _            _       _     _         _   _          _          _             _        
       / /\         / /\               / /\         / /\    / /\  /\ \      /\_\/\_\ _     /\ \       /\ \     _    /\ \      
      / /  \       / /  \             / /  \       / / /   / / /  \ \ \    / / / / //\_\   \ \ \     /  \ \   /\_\ /  \ \     
     / / /\ \__   / / /\ \           / / /\ \__   / /_/   / / /   /\ \_\  /\ \/ \ \/ / /   /\ \_\   / /\ \ \_/ / // /\ \_\    
    / / /\ \___\ / / /\ \ \         / / /\ \___\ / /\ \__/ / /   / /\/_/ /  \____\__/ /   / /\/_/  / / /\ \___/ // / /\/_/    
    \ \ \ \/___// / /  \ \ \        \ \ \ \/___// /\ \___\/ /   / / /   / /\/________/   / / /    / / /  \/____// / / ______  
     \ \ \     / / /___/ /\ \        \ \ \     / / /\/___/ /   / / /   / / /\/_// / /   / / /    / / /    / / // / / /\_____\ 
 _    \ \ \   / / /_____/ /\ \   _    \ \ \   / / /   / / /   / / /   / / /    / / /   / / /    / / /    / / // / /  \/____ / 
/_/\__/ / /  / /_________/\ \ \ /_/\__/ / /  / / /   / / /___/ / /__ / / /    / / /___/ / /__  / / /    / / // / /_____/ / /  
\ \/___/ /  / / /_       __\ \_\\ \/___/ /  / / /   / / //\__\/_/___\\/_/    / / //\__\/_/___\/ / /    / / // / /______\/ /   
 \_____\/   \_\___\     /____/_/ \_____\/   \/_/    \/_/ \/_________/        \/_/ \/_________/\/_/     \/_/ \/___________/    
                                                                                                                              
*/
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl '\n'
#define pb emplace_back
#define mkp make_pair
#define p_q priority_queue
#define INF 2000000000
#define PI 3.1415926
#define coutdb cout << fixed << setprecision(10)

const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

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

  int n, a[100000], t; cin >> n >> t;
  REP(i, n) cin >> a[i];

  int mn = 1145141919, mx = -1;
  map<int, int> mp;
  REP(i, n){
    mp[a[i]-mn]++;
    mx = max(mx, a[i]-mn);
    mn = min(mn, a[i]);
  }
  cout << mp[mx] << endl;

  return 0;
}

Measured memory_bytes: 7296
def good_grid(N: int, C: int, D: list, c: list) -> int:
    # (i+j) % 3 ごとに色の出現頻度を取る
    freqs = [{}, {}, {}]
    for i, row in enumerate(c):
        for j, e in enumerate(row):
            r = (i + j) % 3
            freq = freqs[r]
            if e not in freq:
                freq[e] = 0
            freq[e] += 1

    # (i+j) % 3 ごとの色の出現頻度から他の色に変更した際の
    # 違和感を全探索
    discomforts = [[(-1, float('inf'))] * 3 for _ in range(3)]

    for freq, discomfort in zip(freqs, discomforts):
        for y in range(C):
            sum_d = sum(D[x - 1][y - 1] * f for x, f in freq.items())
            discomfort.append((y, sum_d))

    # (i+j) % 3 ごとに y の値が被らないように決定して
    # 全体の不快感を最小にする。
    min_dis = float('inf')
    for y1, v1 in discomforts[0]:
        for y2, v2 in discomforts[1]:
            for y3, v3 in discomforts[2]:
                if y1 == y2 or y2 == y3 or y3 == y1:
                    continue
                if v1 + v2 + v3 < min_dis:
                    min_dis = v1 + v2 + v3

    return min_dis


if __name__ == "__main__":
    N = 0
    C = 0
    N, C = map(int, input().split())
    D = [[int(s) for s in input().split()] for _ in range(C)]
    c = [[int(s) for s in input().split()] for _ in range(N)]
    ans = good_grid(N, C, D, c)
    print(ans)


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

long long power(long long x, long long y)
{
    long long ret = 1;
    while(y > 0)
    {
        if (y & 1)
        {
            ret = (ret * x);
        }
        x = (x * x);
        y >>= 1;
    }
    return ret;
}

long long xxor(long long a, long long b)
{
    long long x = 0;
    long long ans = 0;
    while(1)
    {
        if (a == 0 && b == 0)
        {
            break;
        }
        long long cnt = 0;
        if (a & 1)
        {
            cnt++;
        }
        if (b & 1)
        {
            cnt++;
        }
        
        if (cnt % 2 == 1)
        {
            ans += power(2,x);
        }
        x++;
        
        a >>= 1;
        b >>= 1;
    }
    return ans;
}

int main(void)
{
    long long N;
    cin >> N;
    vector<long long> a(N);
    for (long long i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    vector<long long> b(N);
    for (long long i = 0; i < N; i++)
    {
        b[i] = a[i];
    }

    long long ans = 0;
    long long x =0;
    while(1)
    {
        for (long long i = 0; i < N; i++)
        {
            if (b[i] != 0)
            {
                break;
            }
            if (i == N-1)
            {
                for (long long i = 0; i < N; i++)
                    {
                        long long answer = xxor(ans, a[i]);
                        cout << answer << " ";
                    }
                    cout << endl;
                    exit(0);
            }
        }
        long long cnt = 0;
        for (long long i = 0; i < N; i++)
        {
            if (b[i] & 1)
            {
                cnt++;
            }
        }
        if (cnt % 2 == 1)
        {
            ans += power(2,x);
        }
        x++;
        for(long long i = 0; i < N; i++)
        {
             b[i] >>= 1;
        }
    }
}

Measured memory_bytes: 6592
import Foundation
func readInts() -> [Int] { readLine()!.split(separator: " ").map { Int($0)! } }

let n = Int(readLine()!)!
let k = Int(readLine()!)!
let xi = readInts()
let ans = xi.map { min($0, k - $0) * 2 }.reduce(0) { $0 + $1 }
print(ans)

Measured memory_bytes: 13412