akhauriyash/Code-Regression huggingface dataset:
// abc132a.cpp : Fifty-Fifty
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;

#define rep(i,n) for(int i=0;i<(n);i++)
#define in(x) cin>>(x)
#define oute(x) cout<<(x)<<endl

int main(){
  string S; cin>>S;
  vi c(26); rep(i,4) c[S[i]-'A']++;
  int f = 0; rep(i,26) if(c[i]==2) f++;
  if(f==2) oute("Yes"); else oute("No");
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		int l = scanner.nextInt();
		int A[][] = new int[n][m];
		int b[][] = new int[m][l];
		long c[][] = new long[n][l];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				A[i][j] = scanner.nextInt();
			}
		}
		for (int j = 0; j < m; j++) {
			for (int k = 0; k < l; k++) {
				b[j][k] = scanner.nextInt();
			}
		}
		for (int i = 0; i < n; i++) {
			for (int k = 0; k < l; k++) {
				for (int j = 0; j < m; j++) {
					c[i][k] = A[i][j] * b[j][k]+c[i][k];
				}

			}
		}
		for (int i = 0; i < n; i++) {
			for (int k = 0; k < l; k++) {
				System.out.print(c[i][k]);
				if (k == l - 1) {
					System.out.println();
				} else {
					System.out.print(" ");
				}
			}
		}

	}
}



Measured memory_bytes: 55000
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;cin>>n;
unordered_map<string,int>map;
map["AC"]=0;map["WA"]=0;map["TLE"]=0;map["RE"]=0;
for(int i=0;i<n;i++){
string s;cin>>s;
map[s]++;
}
cout<<"AC x "<<map["AC"]<<endl;
cout<<"WA x "<<map["WA"]<<endl;
cout<<"TLE x "<<map["TLE"]<<endl;
cout<<"RE x "<<map["RE"]<<endl;
}


Measured memory_bytes: 3608
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
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(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	debug("debug test\n");
   	ll a,b;cin>>a>>b;
	ll ans = 0;

	ll limit = max(sqrt(a), sqrt(b)) + 2;
	for(int i = 2;i < limit;i++){
		bool f1=false, f2=false;
		while(a%i==0){
			a/=i;
			f1 = true;
		}
		while(b%i==0){
			b/=i;
			f2 = true;
		}
		if(f1&&f2){
			ans++;
		}
	}
	if(a==b&&a>1)ans++;
	cout << ans+1 << endl;
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
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;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int A,B,C; cin >> A >> B >> C;
    int K; cin >> K;
    bool f=false;
    for(int i=0;i<K;i++){
        if(A>=B){
            B *= 2;
        }else if(B>=C){
            C *= 2;
        }
    }
    if(C > B && B > A){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
int a[202020];
LL ball[202020];

int main(){
    
    // 1. 入力情報.
    int N;
    scanf("%d", &N);
    rep(i, N){
        scanf("%d", &a[i]);
        // a[i] が 書かれているボールの数.
        ball[a[i]]++;
    }
    
    // 2. N個のボールで, 条件を満たす2個のボールの選び方は？
    LL total = 0;
    repx(i, 1, N + 1) total += ball[i] * (ball[i] - 1) / 2;
    
    // 3. k番目のボールを除いた場合, 条件を満たす2個のボールの選び方は？
    rep(k, N){
        LL b = ball[a[k]], ans = total;
        // ans = ans - b * (b - 1) / 2 + (b - 1) * (b - 2) / 2
        // => ans = ans - b + 1
        if(b > 1) ++ans -= b;
        printf("%lld\n", ans);
    }
    return 0;
    
}

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

X,A,B = inputIL()

if B<=A:
  print("delicious")
elif B<=A+X:
  print("safe")
else:
  print("dangerous")

Measured memory_bytes: 65644
import sys
from fractions import gcd

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def lcm(x, y):
    return x * y // gcd(x, y)


def main():
    N, M, *A = map(int, read().split())
    B = A[::]

    while not any(b % 2 for b in B):
        B = [b // 2 for b in B]

    if not all(b % 2 for b in B):
        print(0)
        return

    semi_lcm = 1
    for a in A:
        semi_lcm = lcm(semi_lcm, a // 2)

    print((M // semi_lcm + 1) // 2)
    return


if __name__ == '__main__':
    main()


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

int main() {
	long long int test,n,i,j,k,x,y,t;
	cin>>test;
	map<string,long>p;
	while(test--){
	 string s;
	 cin>>s;
	 p[s]++;
	    
	}
	cout<<"AC x "<<p["AC"]<<endl;
	cout<<"WA x "<<p["WA"]<<endl;
	cout<<"TLE x "<<p["TLE"]<<endl;
	cout<<"RE x "<<p["RE"]<<endl;
}


Measured memory_bytes: 3636
/*
author : seryu
title : contest
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(all(x), val), x.end())
typedef long long ll;
typedef pair<int, int> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;
int INF = 1001001001;

void solve()
{
	string s, t;
	cin >> s >> t;
	t.pop_back();
	if(s == t)cout << "Yes" << endl;
	else cout << "No" << endl;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 3576
#include<iostream>
#include<string.h>
using namespace std;
char s[100001] = { '\0' };
int main(void)
{
	int sum = 0;
	cin >> s;
	for (int i = 1; i < strlen(s); i++)
	{
		if (s[i - 1] != s[i])
		{
			sum++;
		}
	}
	cout << sum;
}

Measured memory_bytes: 384
#include<cstdio>
#define RI register int
#define CI const int&
using namespace std;
const int N=200005,mod=1e9+7;
int n,x,pre[N],f[N];
inline void inc(int& x,CI y)
{
	if ((x+=y)>=mod) x-=mod;
}
int main()
{
	RI i,j; for (scanf("%d",&n),f[0]=i=1;i<=n;pre[x]=i++)
	if (scanf("%d",&x),f[i]=f[i-1],pre[x]&&pre[x]!=i-1) inc(f[i],f[pre[x]]);
	return printf("%d",f[n]),0;
}

Measured memory_bytes: 3296
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.List (unfoldr)
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as BS
import Data.Bits

f :: (Int,Int) -> (Int,Int) -> (Int,Int)
f (x,m) (y,n) = case (x + y) `quotRem` 10 of
          (a,b) -> (a + b, m + n + 1 + a)

gen :: Int -> U.Vector (Int,Int)
gen a = U.iterateN 64 (\x -> f x x) (a,0)

computed :: V.Vector (U.Vector (Int,Int))
computed = V.fromList $ map gen [0..9]

pow' :: Int -> Int -> (Int,Int)
pow' a n = foldr1 f [ computed V.! a U.! i | i <- [0..60], testBit n i ]

main = do
  m <- readLn
  xs <- U.replicateM m $ do
    [d,c] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    -- c should be Int64
    return (pow' d c)
  print $ snd $ U.foldr1 f xs


Measured memory_bytes: 20860
#include <iostream>
using namespace std;
int main(){
	while (1) {
		int n;
		cin>>n;
		if(n == 0)break;
		char list[n][2];
		for (int i = 0; i < n; i++) {
			cin>>list[i][0]>>list[i][1];
		}
		int m;
		cin>>m;
		char str[m];
		for (int i = 0; i < m; i++) {
			cin>>str[i];
			for (int j = 0; j < n; j++) {
				if(str[i] == list[j][0]){
					str[i] = list[j][1];
					break;
				}
			}
		}
		for (int c = 0; c < m; c++) {
			cout<<str[c];
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) lower_bound(all(v),k)-v.begin()
#define chmin(x,y) if(x>y)x=y
#define chmax(x,y) if(x<y)x=y
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
ll inf=100100100100;
const int mod=1000000007;
int main(){
    int n;cin>>n;
    ll ans=0;
    vi v(n);
    rep(i,n)cin>>v[i];
    sort(all(v));
    rep(i,n){
        REP(j,i+1,n){
            int c=v[i]+v[j];
            int r=lb(v,c);
            int l=j+1;
            ans+=r-l;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int n,a;
    scanf("%d",&n);
    int x[n];
    for(int i=1;i<=n;i++){
        scanf("%d",&a);
        x[a-1]=i;
    }
    for(int j=0;j<n;j++){
        printf("%d ",x[j]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 1152
# ABC127 D-Integer Cards
from operator import itemgetter
N,M = map(int,input().split())
A = list(map(int,input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]

A.sort()
BC.sort(key=itemgetter(1),reverse=True)
# print(A)
# print('sort',BC)
c = 0
for i in range(M):
    for j in range(BC[i][0]):
        if A[c] < BC[i][1]:
            A[c] = BC[i][1]
        else:
            print(sum(A))
            exit()
        c += 1
        if c == N:
            print(sum(A))
            exit()
# for i in range(M):
#     x = 0
#     while x < BC[i][0]:
#         A.sort()
#         print(i,A)
#         if BC[i][1] > A[0]:
#             A[0] = BC[i][1]
#         x += 1 
print(sum(A))

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

int main(){
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
	if(x-r<0 || x+r>W || y-r<0 || y+r>H){
		cout << "No\n";
	}
    else{
		cout<<"Yes\n";
	}
    
    return 0;
}


Measured memory_bytes: 3100
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){

    int n,W;
    cin>>n>>W;
    int weight[n],values[n];
    int sum_values=0;
    for(int i=0;i<n;i++){
        cin>>weight[i]>>values[i];
    }
    for(int i=0;i<n;i++){
        sum_values+=values[i];
    }

    vector<long long int>dp(W+1,0);
    for(int i=0;i<n;i++){

        for(int j=W-weight[i];j>=0;j--){
            dp[j+weight[i]]=max(dp[j+weight[i]],dp[j]+values[i]);
        }
    }

    cout<<*max_element(dp.begin(),dp.end());
return 0;
}
  //


Measured memory_bytes: 3968
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

const (
	initialBufSize = 10000
	maxBufSize     = 1000000
)

func rateAdd(m map[int]bool, rate int) {
	if _, ok := m[rate]; !ok {
		m[rate] = true
	}
}

func main() {
	var wtr = bufio.NewWriter(os.Stdout)
	var sc = bufio.NewScanner(os.Stdin)
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)

	sc.Scan()
	strconv.Atoi(sc.Text())

	sc.Scan()
	temp := strings.Split(sc.Text(), " ")
	m := map[int]bool{}
	other := 0
	for _, v := range temp {
		rate, _ := strconv.Atoi(v)
		if 1 <= rate && rate <= 399 {
			rateAdd(m, 399)
		} else if 400 <= rate && rate <= 799 {
			rateAdd(m, 799)
		} else if 800 <= rate && rate <= 1199 {
			rateAdd(m, 1199)
		} else if 1200 <= rate && rate <= 1599 {
			rateAdd(m, 1599)
		} else if 1600 <= rate && rate <= 1999 {
			rateAdd(m, 1999)
		} else if 2000 <= rate && rate <= 2399 {
			rateAdd(m, 2399)
		} else if 2400 <= rate && rate <= 2799 {
			rateAdd(m, 2799)
		} else if 2800 <= rate && rate <= 3199 {
			rateAdd(m, 3199)
		} else if rate >= 3200 {
			other++
		}
	}
	var min, max int
	if len(m) == 0 && other > 0 {
		min = 1
		max = other
	} else {
		min = len(m)
		max = len(m) + other
	}
	fmt.Fprintln(wtr, min, max)
	_ = wtr.Flush()
}


Measured memory_bytes: 1784
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner cin = new Scanner(System.in);
		
		int A,B,C,D;
		
		A = cin.nextInt();
		B = cin.nextInt();
		C = cin.nextInt();
		D = cin.nextInt();
		
		while(true) {
			
			C -= B;
			if(C<=0) {
				System.out.println("Yes");
				return;
			}
			A -= D;
			if(A<=0) {
				System.out.println("No");
				return;
			}
			
		}
		
		
	}

}


Measured memory_bytes: 35788
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    H, W, K = rli()
    grid = []
    for i in range(H):
        grid.append(input())
    ans = 0
    for mh in range(0, 2**H):
        for mw in range(0, 2**W):
            cnt = 0
            for h in range(H):
                for w in range(W):
                    if grid[h][w] == '#' and ((mh>>h)&1) and ((mw>>w)&1):
                        cnt += 1
            if cnt == K:
                ans += 1
    print(ans)



if __name__ == '__main__':
    main()


Measured memory_bytes: 9144
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = 1e17;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,c;
    cin >> n;
    vector<ll> a(n),num(n,0);
    rep(i,n){
        cin >> c;
        c--;
        a[i] = c;
        num[c]++;
    }
    ll cnt = 0;
    rep(i,n){
        if (num[i] == 0 || num[i] == 1) continue;
        cnt += num[i]*(num[i]-1)/2;
    }
    rep(i,n){
        if (num[a[i]] == 1) PRINT(cnt);
        else if (num[a[i]] == 2) PRINT(cnt-1);
        else{
            PRINT(cnt-num[a[i]]*(num[a[i]]-1)/2+(num[a[i]]-1)*(num[a[i]]-2)/2);
        }
    }
}


Measured memory_bytes: 5760
#JMD
#Nagendra Jha-4096

 
import sys
import math

#import fractions
#import numpy
 
###File Operations###
fileoperation=0
if(fileoperation):
    orig_stdout = sys.stdout
    orig_stdin = sys.stdin
    inputfile = open('W:/Competitive Programming/input.txt', 'r')
    outputfile = open('W:/Competitive Programming/output.txt', 'w')
    sys.stdin = inputfile
    sys.stdout = outputfile

###Defines...###
mod=1000000007
 
###FUF's...###
def nospace(l):
    ans=''.join(str(i) for i in l)
    return ans
 
 
 
##### Main ####
t=1
for tt in range(t):
    #n=int(input())
    n,m= map(int, sys.stdin.readline().split(' '))
    a=list(map(int,sys.stdin.readline().split(' ')))
    tot=sum(a)
    d=(tot//(4*m))
    if((tot%(4*m))!=0):
        d+=1
    c=0
    for num in a:
        if(num>=d):
            c+=1
    if(c>=m):
        print("Yes")
    else:
        print("No")
    
    
#####File Operations#####
if(fileoperation):
    sys.stdout = orig_stdout
    sys.stdin = orig_stdin
    inputfile.close()
    outputfile.close()

Measured memory_bytes: 3064
#include <iostream>

using namespace std;


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

	int sum = 0;

	for (int i = 0; i < 2;i++) {
		if (a >= b) {
			sum += a;
			a--;
		}
		else {
			sum += b;
			b--;
		}
	}

	cout << sum;
	return 0;
}

Measured memory_bytes: 256
use itertools::Itertools;
use proconio::{input, marker::Usize1};

fn main() {
    input!(n: usize, a: [Usize1; 3 * n]);

    let mut add = 0;

    let mut max = vec![i64::min_value(); n];
    max[a[0]] = 0;
    max[a[1]] = 0;

    let mut dp = vec![vec![i64::min_value(); n]; n];
    dp[a[0]][a[1]] = 0;
    dp[a[1]][a[0]] = 0;

    for (a, b, c) in a.iter().copied().skip(2).tuples() {
        let m = *max.iter().max().unwrap();
        let mut queue = vec![];
        let mut update = |i, j, v| queue.push((i, j, v));
        if a == b && b == c {
            add += 1;
            continue;
        }
        for (p, q, r) in [a, b, c, a, b].iter().copied().tuple_windows() {
            if p == q {
                for k in 0..n {
                    update(k, r, dp[p][k] + 1);
                    update(k, r, dp[k][p] + 1);
                }
            }
            update(q, r, dp[p][p] + 1);
            update(p, q, m);
            for k in 0..n {
                update(k, p, max[k]);
            }
        }
        for &(x, y, v) in &queue {
            dp[x][y] = dp[x][y].max(v);
            dp[y][x] = dp[y][x].max(v);
            max[x] = max[x].max(v);
            max[y] = max[y].max(v);
        }
    }

    let last = *a.last().unwrap();
    dp[last][last] += 1;

    let ans = add + dp.iter().flatten().max().unwrap();

    println!("{}", ans);
}


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

int mod = 1000000007;
	bool ii[100000],oo[100000];

	int N;
void p(){
	string str;
	for(int i = 0;i < N;i++){
		if(oo[i]) str += 'S';
		else str += 'W';
	}
	cout << str;
}

bool r(bool s,bool p,bool a){
	return (s != (p != a));
}
int main() {
	// your code goes here
	string in,out;
	cin >> N;
	cin >> in;
	for(int i = 0;i < N;i++){
		ii[i] = (in[i] == 'o');
	}
	oo[0] = true;
	oo[1] = true;
	for(int i = 2;i < N;i++){
		oo[i] = r(ii[i-1],oo[i-1],oo[i-2]);
	}
	if(oo[0] == r(ii[N-1],oo[N-1],oo[N-2]) && oo[1] == r(ii[0],oo[0],oo[N-1])){
		p();
		return 0;
	}
	oo[0] = false;
	oo[1] = true;
	for(int i = 2;i < N;i++){
		oo[i] = r(ii[i-1],oo[i-1],oo[i-2]);
	}
	if(oo[0] == r(ii[N-1],oo[N-1],oo[N-2]) && oo[1] == r(ii[0],oo[0],oo[N-1])){
		p();
		return 0;
	}
	oo[0] = true;
	oo[1] = false;
	for(int i = 2;i < N;i++){
		oo[i] = r(ii[i-1],oo[i-1],oo[i-2]);
	}
	if(oo[0] == r(ii[N-1],oo[N-1],oo[N-2]) && oo[1] == r(ii[0],oo[0],oo[N-1])){
		p();
		return 0;
	}
	oo[0] = false;
	oo[1] = false;
	for(int i = 2;i < N;i++){
		oo[i] = r(ii[i-1],oo[i-1],oo[i-2]);
	}
	if(oo[0] == r(ii[N-1],oo[N-1],oo[N-2]) && oo[1] == r(ii[0],oo[0],oo[N-1])){
		p();
		return 0;
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 896
import itertools
import math

n = int(input())
grid = [list(map(int, input().split())) for i in range(n)]

l = []
for i in range(n):
  l.append(i)

sum = 0
for v in itertools.permutations(l):
  for i in range(n - 1):
    sum += ((grid[v[i]][0] - grid[v[i + 1]][0]) ** 2 + 
                 (grid[v[i]][1] - grid[v[i + 1]][1]) ** 2) ** (1 / 2)

print(sum / math.factorial(n))

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

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

  if (b - a <= 0) {
    cout << "delicious" << endl;
  } else if (b - a <= x) {
    cout << "safe" << endl;
  } else {
    cout << "dangerous" << endl;
  }

  return (0);
}

Measured memory_bytes: 256
N = int(input())
h = [int(i) for i in input().split()]

# dpの最小値を変更する関数
def chmin(a, b):
    if a > b:
        return b
    else:
        return a
      
dp=[1000000000]*N
dp[0]=0
#dp[1]=abs(h[1]-h[0])
 
#配るDP
for i in range(0,N-1):
    #print(abs(h[i]-h[i+1])+dp[i],dp[i+1],abs(h[i]-h[i+2])+dp[i],dp[i+2])
    dp[i+1]=chmin(abs(h[i]-h[i+1])+dp[i],dp[i+1])
    if i < N-2:
        dp[i+2]=chmin(abs(h[i]-h[i+2])+dp[i],dp[i+2])
    
print(dp[-1])


Measured memory_bytes: 20692
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int main(){
	static ll n,m,x[10010],y[10010],z[10010],sum[10010]={},ans=0;
	cin>>n>>m;
	REP(i,n){
		cin>>x[i]>>y[i]>>z[i];
	}
	for(int i=-1;i<=1;i+=2){
		for(int j=-1;j<=1;j+=2){
			for(int k=-1;k<=1;k+=2){
				REP(l,n){
					sum[l]=i*x[l]+j*y[l]+k*z[l];
				}
				sort(sum,sum+n,greater<ll>());
				ll dim=0;
				REP(l,m){
					dim+=sum[l];
				}
				if(dim>ans){
					ans=dim;
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 892
#include <stdio.h>
long long int zet(long long int a){
  if(a > 0){
    return a;
  }
  return -a;
}
long long int min(long long int a,long long int b){
  if(a > b){
    return b;
  }
  return a;
}
int main(){
  long long int i,n,sum = 0,mini = -1,bsum = 0;
  scanf("%lld",&n);
  long long int a[n];
  for(i = 0;i < n;i++){
    scanf("%lld",&a[i]);
    sum += a[i];
  }
  for(int i = 0;i < n - 1;i++){
    bsum += a[i];
    if(mini < 0){
      mini = zet(sum - 2 * bsum);
    }else{
      mini = min(mini,zet(sum - 2 * bsum));
    }
  }
  printf("%lld\n",mini);
  return 0;
}

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

public class Main{
    static Scanner sc = new Scanner(System.in);
    static int n = sc.nextInt();
    static int[] a = new int[n];
    static int[] b = new int[n];
    static int[] c = new int[n];

    public static void main(String[] args){
        for (int i=0; i<n; i++) a[i] = sc.nextInt();
        Arrays.sort(a);
        for (int i=0; i<n; i++) b[i] = sc.nextInt();
        Arrays.sort(b);
        for (int i=0; i<n; i++) c[i] = sc.nextInt();
        Arrays.sort(c);

        long ans = 0;

        for (int i=0; i<n; i++){
            long low = lowerbound(a, b[i]);
//            long high = lowerbound(c, b[i]+1);

            int high = upperbound(c, b[i]);
            long tmp = low*(n-high);
            ans += tmp;
        }

        System.out.println(ans);

    }

    private static int lowerbound(int[] x, int y){
        int left = 0;
        int right = n;
        while (left<right){
            int mid = (left+right)/2;
            if (x[mid]<y){
                left = mid+1;
            }else {
                right = mid;
            }
        }
//        System.out.println(left);
        return left;
    }

    private static int upperbound(int[] x, int y){
        int left = 0;
        int right = n;
        while (left<right){
            int mid = (left+right)/2;
            if (x[mid]<=y){
                left = mid+1;
            }else {
                right = mid;
            }
        }
//        System.out.println(left);
        return left;
    }
}

Measured memory_bytes: 94132
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<complex>
#include<stack>
#include<cmath>
  
using namespace std;
  
#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)


int getday(int y,int m,int d){
	return y*366 + (m-1)*32 + d;
}


int main(){
	
	string hoge[5]={"pre-meiji","meiji","taisho","showa","heisei"};
	
	int sp[5];
	sp[0] = getday(1868,9,8);
	sp[1] = getday(1912,7,30);
	sp[2] = getday(1926,12,25);
	sp[3] = getday(1989,1,8);
	sp[4] = getday(10000,1,8);
	
	int mn[5]={0,1868,1912,1926,1989};
	
	int a,b,c;
	while(cin>>a>>b>>c){
		rep(i,5){
			if(getday(a,b,c)<sp[i]){
				cout<<hoge[i];
				if(i!=0){
					cout<<" "<<a-mn[i]+1<<" "<<b<<" "<<c;
				}
				cout<<endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 1204
def solve():
    N = int(input())
    A = list(map(int, input().split()))

    num_balls = [0 for i in range(N+1)]
    for a_i in A:
        num_balls[a_i] += 1

    comb = 0
    for n in range(N+1):
        comb += num_balls[n] * (num_balls[n]-1) // 2

    for a_i in A:
        ori = num_balls[a_i] * (num_balls[a_i]-1) // 2
        rev = (num_balls[a_i]-1) * (num_balls[a_i]-2) // 2
        print(comb + rev - ori)


solve()


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

#define rep(i,n) for(int i=0;i<(n);i++)

using ll=long long;

int main(){
    int h,w;
    cin>>h>>w;
    string s[h+2];
    rep(i,w+2){
        s[0]+="#";
        s[h+1]+="#";
    }
    string a;
    for(int i=1;i<h+1;i++){
        s[i]="#";
        cin>>a;
        s[i]+=a;
        s[i]+="#";
    }
    rep(i,h+2)cout<<s[i]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  char bf = 0;
  bool f = false;
  set<string> se;
  rep(i, n){
    string s;
    cin >> s;
    if(i == 0){
      se.insert(s);
      bf = s.back();
    }else{
      if(s.front() != bf || se.count(s) == 1) f = true;
      se.insert(s);
      bf = s.back();
    }
  }
  if(f == false) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

int main(){
  int s,t,u;
  cin >>s;
  t = s/100;
  u = s%100;
  if(1<=t && t<=12){
    if(1<=u && u<=12) cout << "AMBIGUOUS" << endl;
    else cout << "MMYY" << endl;
  }
  else {
    if(1<=u && u<=12) cout << "YYMM" << endl;
    else cout << "NA" << endl;
  }
  return 0;
}

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


def solve(N: int, a: "List[int]"):
    s = sum(a)
    ret = float('inf')
    tmp = 0
    for i in range(N - 1):
        tmp += a[i]
        ret = min(ret, abs(tmp - (s - tmp)))
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 25056
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr,0,sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int n, m;
        cin >> n >> m;
        if(n == m){
            cout << "Yes\n";
        }else{
            cout << "No\n";
        }
    } 
}

Measured memory_bytes: 31488
//AOJ0541 DPµÄNñà¢½ãÌ¶ðvZµÄÀs
#include<stdio.h>
#include<string.h>
int c[1005][1005];
char d[1005][1005];
int main(){
	int h,w,n,i,j,x,y;
	FILE *fp;
	//fp=fopen("test.txt","r");
	fp=stdin;
	while(1){
		fscanf(fp,"%d%d%d",&h,&w,&n);
		if(h==0 && w==0 && n==0)break;
		memset(d,0,sizeof(d));
		memset(c,0,sizeof(c));
		for(i=1;i<=h;i++){
			for(j=1;j<=w;j++){
				fscanf(fp,"%d",&x);
				if(x==1)d[i][j]=1;
			}
		}
		c[1][1]=n-1;
		for(i=1;i<=h;i++){
			for(j=1;j<=w;j++){
				//ÅÌ¶ÉæÁÄêª¯µÄvZ
				if(d[i][j]==1){
					c[i][j+1]+=(c[i][j]+1)/2;
					c[i+1][j]+= c[i][j]   /2;
				}else{
					c[i][j+1]+= c[i][j]   /2;
					c[i+1][j]+=(c[i][j]+1)/2;
				}
				//ñãÌ(i,j)Ì¶
				d[i][j]=(c[i][j]+d[i][j])%2;
				//printf("%d ",d[i][j]);
			}
			//printf("\n");
		}
		x=y=1;
		while(y<=h && x<=w){
			if(d[y][x]==1) x++;
			else y++;
		}
		printf("%d %d\n",y,x);
	}
	return 0;
}

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

using namespace std;
typedef long long int ll;

int main()
{
    char s;
    cin >> s;

    if (isupper(s))
    {
        cout << "A" << endl;
    }
    else
    {
        cout << "a" << endl;
    }

    return 0;
}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define rep(i, n) for(int i=0; i<n; ++i)
#define REP(i, n) for(int i=1; i<=n; ++i)
#define all(obj) (obj).begin(), (obj).end()
const int inf = 1e9;
const ll INF = 1e18;
const ll MOD = 1e9+7;
const ll MAX = 1e9+7;

int main(){
    int h1, h2, m1, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int wakeup = h1*60 + m1;
    int sleep = h2*60 + m2;
    int ans = sleep - wakeup - k;
    if(ans >= 0) cout << ans << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <map>
#include <stack>
#include <queue>
#include <sstream>
#define INF 0x3f3f3f3f
using namespace std;

typedef long long ll;
const int mod = 1e9 + 7;
const ll maxn = 1000005;
const double pi = acos(-1.0);

int n;
int d[maxn];

int main()
{
    while(cin >> n)
    {
        for(int i = 0; i < n; i ++)
            cin >> d[i];
        sort(d, d + n);
        int num = n / 2;
        cout << d[num] - d[num - 1] << endl;
    }
    return 0;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = Console.ReadLine().Trim().Split(' ');

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            string sOut = "No";
            if (sS[0][0] == sS[0][1] && sS[0][0] == sS[0][2]) { sOut = "Yes"; }
            if (sS[0][1] == sS[0][2] && sS[0][1] == sS[0][3]) { sOut = "Yes"; }

            // 出力
            Console.WriteLine("{0}", sOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
}


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

using namespace std;
template <typename T> void print(T vec) {for(auto d: vec) cout<<d<<' ';cout<<'\n';}
template<typename T> void print2D(T mat) {for(auto vec:mat) print(vec);}




int main() {
    int n,k;
    cin>>n>>k;
    vector<int> A(n + 1);
    for(int i = 1; i <= n;i++) cin>>A[i];
    vector<int> dp(n + 1, INT_MAX);
    dp[1] = 0; 
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= k && j + i <= n; j++) {
            dp[i+j] = min(dp[i + j], dp[i] + abs(A[i] - A[i + j]));
        }
        // print(dp);
    }
    // print(dp);
    cout<<dp[n]<<'\n';
    return 0;
}

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

int n,k,naj,tret,j;
int niz[100006];
int valu[100006];
int main () {
	
	cin >>n>>k;
	for(int i=0;i<n;i++)
		cin >>niz[i];
	valu[0] = 0;
	for(int i=1;i<n;i++) {
		naj = abs(niz[i] - niz[i - 1]) + valu[i - 1];
		j = 1;
		while (i - j >= 0 && j <= k) {
			tret = abs(niz[i] - niz[i - j]) + valu[i - j];
			naj = min(naj, tret);
			j++;
		}
		valu[i] = naj;
	}
	/*for(int i=0;i<n;i++) {
		cout <<valu[i]<<" ";
	}*/
	cout <<valu[n - 1];
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;

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

using ll = long long;

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

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int a; std::cin >> a;
  std::cout << a + a*a + a*a*a << std::endl;
  return 0;
}



Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
   int n;
   cin >> n;
   int l[2*n],sum=0;
   for(int i=0;i<2*n;i++) cin >> l[i];
   sort(l,l+2*n);
   for(int i=0;i<2*n;i+=2){
      sum+=l[i];
   }
   cout << sum<<endl;
}


Measured memory_bytes: 256
import itertools
N = int(input())
S = [input() for _ in range(N)]
n = [0] * 5
for i in range(N):
    for j in range(5):
        if S[i][0] == ['M', 'A', 'R', 'C', 'H'][j]:
            n[j] += 1
ans = 0
for i in itertools.combinations(range(5), 3):
    ans += n[i[0]] * n[i[1]] * n[i[2]]
print(ans)


Measured memory_bytes: 83060
#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 N; cin >> N;
    vector<int> L(N);
    vector<vector<int>> plus(N, vector<int>(N));
    ll ans =0;

    rep(i,N){
        cin >> L[i];
    }

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



    rep(i,N-2){
        for(int j=i+1;j <N-1; j++){

        plus[i][j] = L[i]+L[j];

            for(int k=j+1; k <N; k++){

                if(L[k] < plus[i][j]){
                    ans++;
                }
                
            }

        }
    }

    cout << ans << endl;
}



Measured memory_bytes: 17920
#include <bits/stdc++.h>
using namespace std;
typedef int64_t LL;
const int MOD=1e9+7;
const int MAX=1e6;
vector<LL> NMR(MAX),DNM(MAX),INV(MAX);
LL BNM(int n,int k)
{
  if(n<k)return 0;
  if(n<0||k<0)return 0;
  k=min(k,n-k);
  NMR.at(0)=NMR.at(1)=1;
  DNM.at(0)=DNM.at(1)=1;
  INV.at(0)=INV.at(1)=1;
  for(int i=2;i<MAX;i++)
  {
    NMR.at(i)=NMR.at(i-1)*i%MOD;
    INV.at(i)=MOD-INV.at(MOD%i)*(MOD/i)%MOD;
    DNM.at(i)=DNM.at(i-1)*INV.at(i)%MOD;
  }
  return NMR.at(n)*(DNM.at(k)*DNM.at(n-k)%MOD)%MOD;
}
int main()
{
  int x,y,z;
  cin>>x>>y;
  if((x+y)%3>0){cout<<0<<endl;return 0;}
  z=(x+y)/3;
  x-=z;
  y-=z;
  if(x<0||y<0){cout<<0<<endl;return 0;}
  cout<<BNM(x+y,x)<<endl;
}

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

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

vector<int> op(4);
string abcd;


void solve(int depth, vector<int> &current) {

    if (depth == 3) {
        int tmp = (int) (abcd[0] - '0');

        rep(i, 3) {
            int value = (int) (abcd[i + 1] - '0');
            if (current[i] == 0) tmp -= value;
            else tmp += value;
        }
        if (tmp == 7) copy(current.begin(), current.end(), op.begin());

        return;
    }

    rep(i, 2) {
        current[depth] = i;
        solve(depth + 1, current);
    }

}

int main() {

    cin >> abcd;
    vector<int> current(4);
    solve(0, current);

    string ans;
    rep(i, 3) {
        ans += abcd[i];
        ans += op[i] ? '+' : '-';
    }
    ans += abcd[3];
    ans += "=7";

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_pair tree<pair<int,int>,null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_mutiset tree<int,null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> pi; 
#define PI 3.1415926535897932384
#define FOR(i,vv,n) for(int i=vv;i<n;i++)
#define FORR(i,n,vv) for(int i=n-1;i>=vv;i--)
#define ve vector 
#define maxind(v) (max_element(v.begin(),v.end())-v.begin())
#define minind(v) (min_element(v.begin(),v.end())-v.begin())
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007ll
#define INF 1000000000000000000ll
#define PRECISE cout.precision(18);
#define all(v) v.begin(),v.end()
#define BS(v,n) binary_search(all(v),n)
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(all(v),greater <ll>())
#define uni(v) v.resize(unique(all(v))-v.begin())
#define F first
#define S second
#define GET(i,p) get<p>(i)

ll maxn=365;
ll d=0;
ve <ll> c(26);
ve <ve <ll>> v(maxn,ve <ll> (26));
ve <ll> last(26,-1);
ve <ll> assigned(maxn,-2);
ll ini=0;
//ll a[26][365][2];

ll score(){
	ll sats=0;
	FOR(i,0,d){
	FOR(j,0,26){
		sats-=c[j]*(i-last[j]);
	 }
	ll take=assigned[i];
	sats+=v[i][take]+c[take]*(i-last[take]);
	last[take]=i;
	//cout<<sats<<"\n";
}
return sats;
}

pair <ll,ll> fun1(ll da,ll q){

ll x1=-1,x2=d;
FORR(i,da,0)
if(assigned[i]==q){
	x1=i;
	break;
}
FOR(i,da+1,d)
if(assigned[i]==q){
	x2=i;
	break;
}
return make_pair(x1,x2);
}

ll modify(ll da,ll q){
pair <ll,ll> a1=fun1(da,assigned[da]);
pair <ll,ll> a2=fun1(da,q);
ll z=ini;
ll f=assigned[da];
z-=v[da][f];
z-=c[f]*(da-a1.F)*(a1.S-da);
z+=v[da][q];
z+=c[q]*(da-a2.F)*(a2.S-da);
return z;
}

void change(ll da,ll q){
 	assigned[da]=q;
}





int main(){


    FAST
//	PRECISE


cin>>d;
FOR(i,0,26)
cin>>c[i];

FOR(i,0,d)
	FOR(j,0,26)
		cin>>v[i][j];

ve <ll> dummy(d);
FOR(i,0,d){
dummy[i]=rand()%26;
}
assigned=dummy;
ini=score();

ll it=100000;
while(it>0){
	it--;
	ll x1=rand()%d;
	ll x2=rand()%26;
	ll z=modify(x1,x2);
	if(z>ini){
		ini=z;
		change(x1,x2);
	}
}

FOR(i,0,d)
cout<<assigned[i]+1<<"\n";




return 0;
 }

Measured memory_bytes: 3740
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}



//head

ll a, b, c;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> a >> b >> c;

  if(a+b+1 <= c) {
    cout << a+b+1+b << endl;
  }
  else {
    cout << b+c << endl;
  }
}

Measured memory_bytes: 3564
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

//#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define mkt make_tuple
#define no {cout << -1; return;}

const int N = 2e5 + 7, M = 1e6 + 7;

struct Node {
    map <char, int> nxt;
    bool term;

    Node() : term(0) {};
};

string s[N];
Node bor[M];
int sz = 1, ans, alph[26];

void add(int v, int num, int pos) {
    if (pos == s[num].size()) {
        bor[v].term = 1;
        return;
    }
    if (bor[v].nxt.find(s[num][pos]) == bor[v].nxt.end())
        bor[v].nxt[s[num][pos]] = sz++;
    add(bor[v].nxt[s[num][pos]], num, pos + 1);
}

void ask(int v, int num, int pos) {
    if (pos == s[num].size())
        return;
    for (auto it : bor[v].nxt)
        if (alph[it.F - 'a'] && bor[it.S].term)
            ++ans;
    --alph[s[num][pos] - 'a'];
    ask(bor[v].nxt[s[num][pos]], num, pos + 1);
}

void solve() {
    int n; cin >> n;
    loop(i, n) {
        cin >> s[i];
        reverse(all(s[i]));
        add(0, i, 0);
    }
    loop(i, n) {
        for (int c : s[i])
            ++alph[c - 'a'];
        ask(0, i, 0);
    }
    cout << ans - n;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

Measured memory_bytes: 112276
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int N; cin >> N;
    int x[N], y[N], t[N]; REP(i,N) cin >> t[i] >> x[i] >> y[i];
    int xi = 0, yi = 0, ti = 0;
    REP(i,N){
        if(abs(x[i]-xi) + abs(y[i]-yi) <= t[i]-ti && (abs(x[i]-xi) + abs(y[i]-yi))%2 == (t[i]-ti)%2){
            xi = x[i]; yi = y[i]; ti = t[i];
        }
        else{
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1408