akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
template<typename T = int, T mod = 1'000'000'007, typename U = long long>
struct umod{
    T val;
    umod(): val(0){}
    umod(U x){ x %= mod; if(x < 0) x += mod; val = x;}
    umod& operator += (umod oth){ val += oth.val; if(val >= mod) val -= mod; return *this; }
    umod& operator -= (umod oth){ val -= oth.val; if(val < 0) val += mod; return *this; }
    umod& operator *= (umod oth){ val = ((U)val) * oth.val % mod; return *this; }
    umod& operator /= (umod oth){ return *this *= oth.inverse(); }
    umod& operator ^= (U oth){ return *this = pwr(*this, oth); }
    umod operator + (umod oth) const { return umod(*this) += oth; }
    umod operator - (umod oth) const { return umod(*this) -= oth; }
    umod operator * (umod oth) const { return umod(*this) *= oth; }
    umod operator / (umod oth) const { return umod(*this) /= oth; }
    umod operator ^ (long long oth) const { return umod(*this) ^= oth; }
    bool operator < (umod oth) const { return val < oth.val; }
    bool operator > (umod oth) const { return val > oth.val; }
    bool operator <= (umod oth) const { return val <= oth.val; }
    bool operator >= (umod oth) const { return val >= oth.val; }
    bool operator == (umod oth) const { return val == oth.val; }
    bool operator != (umod oth) const { return val != oth.val; }
    umod pwr(umod a, U b) const { umod r = 1; for(; b; a *= a, b >>= 1) if(b&1) r *= a; return r; }
    umod inverse() const {
        U a = val, b = mod, u = 1, v = 0;
        while(b){
            U t = a/b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        if(u < 0)
            u += mod;
        return u;
    }
};
using U = umod<>;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	vector<U> ans(k + 1, 0);
	U res = 0;
	for(int i = k; i >= 1; i--){
		int o = 0;
		for(int j = i; j <= k; j += i){
			ans[i] -= ans[j];
			o++;
		}
		ans[i] += U(o) ^ n;
		res += ans[i] * i;
	}
	cout << res.val << '\n';
	return 0;
}


Measured memory_bytes: 3700
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int m = scan.nextInt();
    boolean[] ac = new boolean[n];
    long[] wrong = new long[n];
    for (int i = 0; i < m; i++) {
      int p = scan.nextInt();
      String s = scan.next();
      if (!ac[p-1]) {
        if (s.equals("WA")) wrong[p-1]++;
        else ac[p-1] = true;
      }
    }

    int wr = 0;
    int acc = 0;
    for (int i = 0; i < ac.length; i++) {
      if (ac[i]) {
        acc++;
        wr += wrong[i];
      }
    }

    System.out.println(acc + " " + wr);
  }
}


Measured memory_bytes: 64520
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define int long long
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr);
#endif
#define ff first
#define ss second
#define endl '\n'
#define all(c) c.begin(),c.end()
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" "; cout<<endl;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve(){
   int a,b,k;
   cin>>a>>b>>k;
   for(int i=a;i<=b;i++){
	  if(i<a+k or i>=b-k+1)cout<<i<<endl; 
	  }
}
int32_t main(){
  IOS;
  solve();
  //debug();
 #ifdef LOCAL_DEFINE
 cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
 #endif	
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
alice = []
bob = []
for i in range(n):
    if i % 2 == 0:
        alice.append(a[i])
    else:
        bob.append(a[i])

print(sum(alice) - sum(bob))

Measured memory_bytes: 9176
A,B,C,D,E,F = map(int, input().split())

can = []
for i in range(0, F + 1, 100 * A):
    for j in range(0, F - i + 1, 100 * B):
        water = i + j

        for k in range(0, F - water + 1, C):
            for l in range(0, F - water - k + 1, D):
                salt = k + l
                
                can.append((water, salt))

# (water, salt)
ans = (100 * A, 0)
noudo = 0
for water, salt in can:
    if water == salt == 0: continue

    if (water / 100) * E >= salt:
        tmp = 100 * salt / (water + salt)
        if noudo < tmp:
            ans = (water, salt)
            noudo = tmp

print(sum(ans), ans[1])

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

typedef long long ll;

vector<vector<int>> all(int m) {
    vector<vector<int>> ret;
    for (int a1 =  1;  a1 <= m; a1++)
    for (int a2 = a1;  a2 <= m; a2++)
    for (int a3 = a2;  a3 <= m; a3++)
    for (int a4 = a3;  a4 <= m; a4++)
    for (int a5 = a4;  a5 <= m; a5++)
    for (int a6 = a5;  a6 <= m; a6++)
    for (int a7 = a6;  a7 <= m; a7++)
    for (int a8 = a7;  a8 <= m; a8++)
    for (int a9 = a8;  a9 <= m; a9++)
    for (int a10 = a9; a10 <= m; a10++) {
        vector<int> p = {a1, a2, a3, a4, a5, a6, a7, a8, a9, a10};
        ret.push_back(p);
    }
    return ret;
}


int main() {
    ll n, m, q;
    cin >> n >> m >> q;
    vector<ll> A, B, C, D;
    for (int i = 0; i < q; i++) {
        ll ai, bi, ci, di;
        cin >> ai >> bi >> ci >> di;
        A.push_back(ai);
        B.push_back(bi);
        C.push_back(ci);
        D.push_back(di);
    }

    vector<vector<int>> ans = all(m);
    // cout << ans.size() << endl;

    ll score = 0;
    for (vector<int>& p : ans) {
        ll s = 0;
        for (int i = 0; i < q; i++) {
            if (p[B[i] - 1] - p[A[i] - 1] == C[i])
                s += D[i];
        }
        if (score < s)
            score = s;
    }
    cout << score << endl;

}

Measured memory_bytes: 9800
#define _USE_MATH_DEFINES
#include <iomanip>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <tuple>
#include <climits>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<long long>> VVLL;
typedef vector<vector<bool>> VVB;
typedef vector<vector<double>> VVD;

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

const int MOD = 1000000007;

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

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

void debug(VI &arr){
	int n=arr.size();
	rep(i,n){
		cout<<arr.at(i)<<endl;
	}
}

void debug(VVI &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout << board.at(i).at(j) << " ";
		}
		cout<<endl;
	}
}

void debug(VVLL &board){
	int h = board.size();
	int w = board.size();
	rep(i,h){
		rep(j,w){
			cout<<board.at(i).at(j)<<" ";
		}
		cout<<endl;
	}
}

LL gcd(LL a,LL b){
	return b==0?a:gcd(b,a%b);
}

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

int main(){
	//cout<<fixed;
	//cout<<setprecision(9)<<...
	int a;cin>>a;cout<<a*a<<endl;
	return 0;
}


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

int main() {
  ll N; cin >> N;
  vector<ll> a(N);
  for (ll i=0; i<N; i++) cin >> a.at(i);
  sort(a.begin(), a.end());
  ll n=0, c=0, total=0;
  for (ll i=0; i<N; i++) {
    if (a.at(i) != n) {
      if (n > c) total += c;
      else total += c-n;
      n = a.at(i); c=1;
    } else c++;
  }
  if (n > c) total += c;
  else total += c-n;
  cout << total << endl;
}

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

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

#define cauto const auto&
#else

#endif

using namespace std;


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

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

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

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;
int dp[2][100][100];
void mainmain(){
	int n,m;
	while(cin>>n>>m,n||m){
		rep(i,2){
			rep(j,100){
				rep(k,100){
					dp[i][j][k]=INF;
				}
			}
		}
		rep(i,n){
			int a,b,c,d;
			cin>>a>>b>>c>>d;
			a--;
			b--;
			dp[0][a][b]=c;
			dp[0][b][a]=c;
			dp[1][a][b]=d;
			dp[1][b][a]=d;
		}
		rep(k,m){
			rep(i,m){
				rep(j,m){
					rep(l,2){
						dp[l][i][j]=min(dp[l][i][j],dp[l][i][k]+dp[l][k][j]);
					}
				}
			}
		}
		int k;
		cin>>k;
		rep(i,k){
			int p,q,r;
			cin>>p>>q>>r;
			cout<<dp[r][p-1][q-1]<<endl;
		}
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

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

using namespace std;
using ll  = long long;
using ii  = pair < int , int >;
using i3  = pair < int , ii >;
using vi  = vector < int >;
using vii = vector < ii >;
using vi3 = vector < i3 >;

const int N = 1e4 + 4;
const ll INF = 1e12 , mod = 1e9 + 7;
const double eps = 1e-9 , PI = acos(-1);

char s[N];
ll mem[N][110][2];
int D , n;

ll dp(int i , int rem , bool f){
    if(i == n)return rem == 0;

    ll &ret = mem[i][rem][f];
    if(ret != -1)return ret;
    ret = 0;

    int mx = int(s[i] - '0');
    if(f)mx = 9;

    for(int j = 0 ; j <= mx ; j ++){
        ret += dp(i + 1 , (rem + j)%D , f | (j < mx) );
        ret %= mod;
    }
    return ret;
}

void solve(){
    scanf("%s %d" , s , &D);
    n = strlen(s);

    memset(mem , -1 , sizeof mem);
    printf("%lld\n" , ((dp(0 , 0 , 0) - 1)%mod + mod)%mod );
}

main(){
    int t = 1;
    //scanf("%d" , &t);

    while( t -- ){
            solve();
    }

    return 0;
}


Measured memory_bytes: 18176
N = int(input())
A = list(map(int, input().split()))

S = sum(A)
if S % (N * (N + 1) // 2) != 0:
    print('NO')
    exit()

K = S // (N * (N + 1) // 2)
B = [r - l - K for r, l in zip(A[1:] + [A[0]], A)]

if not all(b <= 0 and b % N == 0 for b in B):
    print('NO')
    exit()

if K == -sum([b // N for b in B]):
    print('YES')
    exit()

print('NO')


Measured memory_bytes: 14292
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	for(int i = 1; i <= 9; i++){
		for(int j = 1; j <= 9; j++){
			if(i * j == n){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}

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

using namespace std;

int main()
{
    string moji;
    cin >> moji;

    int max = 0,tmp=0;

    int i;
    for(i=0;i<11;i++){
        if(moji[i] == 'A' || moji[i] == 'T' || moji[i] == 'C' || moji[i] == 'G') tmp++;
        else{
            if(tmp > max) max = tmp;
            tmp = 0;
        }
    }

    cout << max;
}

Measured memory_bytes: 256
from math import factorial
X, Y = map(int, input().split())
MOD = 10 ** 9 + 7
#a(1,2)+b(2,1)
if (2 * Y - X) % 3 != 0:
  ans = 0
  print(ans)
  quit()
if (2 * X - Y) % 3 != 0:
  ans = 0  
  print(ans)
  quit()

a = int((2 * Y - X) / 3)
b = int((2 * X - Y) / 3)

if (a < 0) or (b < 0):
  ans = 0
  print(ans)
  quit()
  
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

ans = cmb(a + b,a)

print(int(ans % MOD))


Measured memory_bytes: 102028
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef complex<double> xy_t;
const lint mod = 1e9 + 7;

double dot(xy_t a, xy_t b){
    return (conj(a) * b).real();
}

double cross(xy_t a, xy_t b){
    return (conj(a) * b).imag();
}

bool cmp(const xy_t &p, const xy_t &q){
    if(p.real() == q.real()) return p.imag() < q.imag();
    return p.real() < q.real();
}

int n;
xy_t p[110], q[110];
vector<xy_t> ch(210);
double ans[110];

void convex_hull(){
    sort(p, p+n, cmp);
    int k = 0;
    rep(i, n){
        while(k > 1 && cross(ch[k-1]-ch[k-2], p[i]-ch[k-1]) <= 0) --k;
        ch[k++] = p[i];
    }
    for(int i=n-2, t=k; i>=0; --i){
        while(k > t && cross(ch[k-1]-ch[k-2], p[i]-ch[k-1]) <= 0) --k;
        ch[k++] = p[i];
    }
    ch.resize(k-1);
}

int main(){
    scanf("%d", &n);
    rep(i, n){
        double x, y;
        scanf("%lf%lf", &x, &y);
        p[i] = q[i] = xy_t(x, y);
    }
    convex_hull();
    auto f = [](const xy_t &a, const xy_t &b){if(a.real() == b.real()){return a.imag() < b.imag();} return a.real() < b.real();};
    typedef map<xy_t, double, decltype(f)> cmap;
    cmap ans(f);
    int k = ch.size();
    rep(i, k){
        ans[ch[i]] = (1 - arg((ch[(i-1+k)%k] - ch[i]) / (ch[(i+1)%k] - ch[i])) / acos(-1)) / 2;
    }
    rep(i, n) printf("%.10f\n", ans[q[i]]);
}

Measured memory_bytes: 384
#include <stdio.h>
#include <math.h>

#define MAX 1000000

int prime[MAX]={};

void eratos(void){
	int i,j;
	prime[0] = 1;
	prime[1] = 1;
	for(i = 2;i < MAX/2;i++){
		for(j = 2;i*j <= MAX;j++){
			prime[i*j] = 1;
		}
	}
}

int main(void){
	long i,j;
	long n;
	int cnt;
	int prime_cnt;

	eratos();
	while(scanf("%ld",&n) != EOF){
		prime_cnt = 0;
		for(i = 0;i <= n;i++){
			if(prime[i] == 0)
				prime_cnt++;
		}
		/*prime_cnt = 0;
		for(i = 0;i < n+1;i++){
			cnt = 0;
			if(i < 2) continue;
			if(i == 2){
				prime_cnt++;
				continue;
			}
			for(j = 2;j <= i/2;j++){
				if(i % j == 0){
					cnt++;
					break;
				}
			}
			if(cnt == 0) prime_cnt++;
		}
		printf("%d\n",prime_cnt);*/		
		printf("%d\n",prime_cnt);
	}
	return 0;
}

Measured memory_bytes: 4928
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
using namespace std;

#define INF 1e18
#define int long long

signed main() {
    string s; cin >> s;
    int idxC = s.find('C');
    int idxF = s.rfind('F');

    if(idxC != -1 && idxF != -1 && idxC < idxF) {
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;
    return 0;
}


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


void solve() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n, r;
  cin >> n >> r;
  if (n > 10) {
      cout << r << endl;
  } else {
      cout << r + 100 * (10 - n) << endl;
  }
}

int main() {
  solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD=1e9+7;
int main(){

  ll n;
  cin>>n;
  string s,t;
  cin>>s>>t;

  vector<ll> dp(n);
  dp[0]=1;
  map<char,ll> cnt;
  cnt[s[0]]++;
  for(ll i=1;i<n;++i){
    dp[i]=cnt[t[i]];
    cnt[s[i]]+=dp[i];
    cnt[s[i]]%=MOD;
  }
  cout<<dp.back()%MOD<<endl;


  return 0;
}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;

    bool flagc = false;
    bool flagf = false;
    rep (i, s.size()) {
        if (s[i] == 'C') {
            flagc = true;
        }
        if (s[i] == 'F' && flagc) {
            flagf = true;
        }
    }

    if (flagc && flagf) {
        Yes;
    } else {
        No;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(" ").map { it.toLong() }
    val h = readLine()!!.split(" ").map { it.toLong() }

    if(n <= k){
        println(0)
        return
    }
    var sum = h.sortedDescending().takeLast((n-k).toInt()).sum()
    println(sum)
}

Measured memory_bytes: 82960
from functools import reduce
from math import ceil

# 入力
N, H = map(int, input().split())
a, b = zip(*(map(int, input().split()) for _ in range(N)))

# 投げるべき刀を強力なものから投げる。その後、振るべき刀を降り続ける。
m = max(a)
c = sorted(filter(lambda x: x > m, b), reverse=True)
ans = (
    reduce(
        lambda acc, e: (acc[0] + 1, acc[1] + e) if acc[1] < H else acc,
        c,
        (0, 0)
    )[0] if sum(c) >= H else
    len(c) + ceil((H - sum(c)) / m)
)

# 出力
print(ans)


Measured memory_bytes: 59592
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string x;
	cin>>x;
	int n = 0, e = 0, w = 0, s = 0;
	for (int i = 0; i < x.length(); ++i)
	{
		if(x[i] == 'N')
			n = 1;
		if(x[i] == 'E')
			e = 1;
		if(x[i] == 'W')
			w = 1;
		if(x[i] == 'S')
			s = 1;
	}
	n^=s;
	e^=w;
	if(n || e)
		cout<<"No\n";
	else
		cout<<"Yes\n";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    string n;
    cin >> n;
    cout << "ABC" << n << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)),(x).end())

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

const int MAX = 200000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<31-1;
const int MOD = 1000000007;

int two, four, el;
void solve(void){
    int N;
    cin >> N;
    rep(N, i) {
        int A; cin >> A;
        if (A % 4 == 0) four++;
        else if (A % 2 == 0) two++;
        else el++;
    }
    bool f = false;
    if (two) {
        f = four >= el;
    }
    else f = four+1 >= el;

    cout << (f?"Yes":"No") << '\n';
}

int main(void){
  solve();
  return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn main() {
	let (n, m): (usize, f32) = (read(), read());
	let mut a = Vec::new();
	let mut temp: u32;
	let mut sum: f32 = 0.0;
	for _ in 0..n {
		temp = read();
		sum += temp as f32;
		a.push(temp);
	}
	let bound = (sum / (m * 4.0)).ceil() as u32;
	let mut count: usize = 0;
	for i in &a {
		if *i >= bound { count += 1; }
	}
	let m = m as usize;
	let ans = if count >= m { "Yes" } else { "No" };
	println!("{}", ans);
}

fn read<T: FromStr>() -> T {
	let stdin = stdin();
	let stdin = stdin.lock();
	let token: String = stdin
		.bytes()
		.map(|c| c.expect("failed to read char") as char)
		.skip_while(|c| c.is_whitespace())
		.take_while(|c| !c.is_whitespace())
		.collect();
	token.parse().ok().expect("failed to parse token")
}



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

int d, t, s;

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> d >> t >> s;
	if(d / s + (d % s ? 1 : 0) <= t) cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 3644
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  int a = (N + 999) / 1000 * 1000;
  cout << (a - N);
}
#endif


Measured memory_bytes: 3644
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int Q=in();
	set<int> S;
	REP(i,Q){
		int q=in();
		if(q==1){
			out(S.find(in())==S.end()?0:1);
		}
		else if(q==2){
			S.erase(in());
		}
		else{
			S.insert(in());
			out(S.size());
		}
	}
	return 0;
}


Measured memory_bytes: 12376
def readinput():
    n,m=map(int,input().split())
    sc=[]
    for _ in range(m):
        s,c=map(int,input().split())
        sc.append((s,c))
    return n,m,sc

def main(n,m,sc):
    ans=[-1]*n
    for s,c in sc:
        if ans[s-1]==-1:
            ans[s-1]=c
        else:
            if ans[s-1]!=c:
                return -1
    if ans[0]==0:
        if n==1:
            return 0
        else:
            return -1
    elif ans[0]==-1:
        if n==1:
            ans[0]=0
        else:
            ans[0]=1
    for i in range(1,n):
        if ans[i]==-1:
            ans[i]=0
    sum=0
    for i in range(n):
        sum*=10
        sum+=ans[i]
    return sum

def main2(n,m,sc):
    cands=[x for x in range(10**n)]
    for cand in cands:
        cc=str(cand)
        if (len(cc)!=n):
            continue
        i=0
        #print(cc)
        while(i<m):
            #print(sc[i])
            s,c=sc[i]
            if cc[s-1]!=str(c):
                break
            i+=1
        else:
            return cand
    return -1
        

if __name__=='__main__':
    n,m,sc=readinput()
    ans=main2(n,m,sc)
    print(ans)


Measured memory_bytes: 9300
from collections import Counter
from math import ceil
N = int(input())
S = [input() for _ in range(N)]
s = S[0]
for i in range(1,N):
  s += S[i]
  s = ''.join([key*(min(val//2,s.count(key)-S[i].count(key))) for key,val in Counter(s).items() if val > 1])
s = sorted(s)
print(''.join(s))

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

for x in range(N+1):
    for y in range(N-x+1):
        z = N - x - y
        if 10000 * x + 5000 * y + 1000 * z == Y:
            print(x, y, z)
            exit()

print("-1 -1 -1")

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

ll N, Q;
vector<vector<ll>> edges;
vector<ll> x, res;

void dfs(ll from, ll to, ll score) {
	score += x[to];
	res[to] = score;

	for (ll next : edges[to])if (next != from) {
		dfs(to, next, score);
	}
}

int main()
{
	cin >> N >> Q;
	edges.resize(N);
	x.resize(N, 0);
	res.resize(N, 0);

	rep(i, N - 1) {
		ll a, b;
		cin >> a >> b;
		a--; b--;
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	rep(i, Q) {
		ll p, tx;
		cin >> p >> tx;
		p--;
		x[p] += tx;
	}

	dfs(-1, 0, 0);
	rep(i, N)cout << (i == 0 ? "" : " ") << res[i];
	cout << endl;

	return 0;
}


Measured memory_bytes: 25856
#include <algorithm>
#include <iostream>
#include <vector>
#include <bitset>
using namespace std;

const int MAX_ROW = 625;    // to be set appropriately
const int MAX_COL = 625;    // to be set appropriately
struct BitMatrix {
    int H, W;
    bitset<MAX_COL> val[MAX_ROW];
    BitMatrix(int m = 1, int n = 1) : H(m), W(n) { }
    bitset<MAX_COL>& operator[](int i) { return val[i]; }
};
int GaussJordan(BitMatrix &A, bool is_extended = false) {
    int rank = 0;
    for (int col = 0; col < A.W; ++col) {
        if (is_extended && col == A.W - 1) break;
        int pivot = -1;
        for (int row = rank; row < A.H; ++row) {
            if (A[row][col]) { pivot = row; break; }
        }
        if (pivot == -1) continue;
        swap(A[pivot], A[rank]);
        for (int row = 0; row < A.H; ++row) {
            if (row != rank && A[row][col]) A[row] ^= A[rank];
        }
        ++rank;
    }
    return rank;
}
int linear_equation(BitMatrix A, vector<int> b, vector<int> &res) {
    int m = A.H, n = A.W;
    BitMatrix M(m, n + 1);          // augmented matrix: A|B
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < n; ++j) M[i][j] = A[i][j];
        M[i][n] = b[i];
    }
    int rank = GaussJordan(M, true);
    // check if it has no solution
    for (int row = rank; row < m; ++row) if (M[row][n]) return -1;
    // answer
    res.assign(n, 0);
    for (int i = 0; i < rank; ++i) res[i] = M[i][n];
    return rank;
};

int main() {
    int n, m; cin >> n >> m;
    BitMatrix A(m, n);
    for (int i = 0; i < m; i++) {
        int k; cin >> k;
        while (k--) {
            int s; cin >> s; s--;
            A[i][s] = 1;
        }
    }
    vector<int> b(m);
    for (int &bi: b) cin >> bi;
    vector<int> res;
    int rank = linear_equation(A, b, res);
    if (rank == -1) cout << 0 << endl;
    else cout << (1 << (n - rank)) << endl;
    return 0;
}

Measured memory_bytes: 384
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main{
	public static void main (String[] args) throws java.lang.Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
	    Shop shopA = new Shop(200,380,5,20);
	    Shop shopB = new Shop(300,550,4,15);
	    Shop shopC = new Shop(500,850,3,12);
	    
	    HashMap<Integer,Integer> costA = new HashMap<Integer,Integer>();
	    for(int i=0;i<=5000;i+=200){
	        costA.put(i,shopA.calcCost(i));
	    }
	    HashMap<Integer,Integer> costB = new HashMap<Integer,Integer>();
	    for(int i=0;i<=5000;i+=300){
	        costB.put(i,shopB.calcCost(i));
	    }
	    HashMap<Integer,Integer> costC = new HashMap<Integer,Integer>();
	    for(int i=0;i<=5000;i+=500){
	        costC.put(i,shopC.calcCost(i));
	    }
	    Set<Integer> keyA = costA.keySet();
	    Set<Integer> keyB = costB.keySet();
	    Set<Integer> keyC = costC.keySet();
	    int ans = Integer.MAX_VALUE;
	    while(!"0".equals(line)){
	        int n = Integer.parseInt(line);
	        
	        for(int a:keyA)
	        for(int b:keyB)
	        for(int c:keyC){
	            if(n == a+b+c){
	                ans = Math.min(ans,costA.get(a)+costB.get(b)+costC.get(c));
	            }
	        }
	        
	        
	        
	        line = br.readLine();
	        System.out.println(ans);
	        ans = Integer.MAX_VALUE;
	    }
	}
    
    public static class Shop{
        int quantity;
        int cost;
        int unit;
        float discount;
        
        Shop(int q,int c,int u,int d){
            this.quantity = q;
            this.cost = c;
            this.unit = u;
            this.discount = d/100f;
        }
        
        public int calcCost(int q){
            int ans = 0;

            int set = q/(unit*quantity);
            int sin = q%(unit*quantity)/quantity;
            ans += set*unit*cost*(1-discount);
            ans += sin*cost;
            
            return ans;
        }
        
    }
}

Measured memory_bytes: 27468
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

signed main(){
    
    int n; cin >> n;
    vector<int> x(n);   
    vector<int> y(n);   
    map<pair<int, int>, int> mp;
    for(int i = 0; i < n; i++){
        int w;
        cin >> x[i] >> y[i] >> w;
        mp[{x[i], y[i]}] += w;
    }
    
    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int di = -1; di < 2; di += 2){
            for(int dj = -1; dj < 2; dj += 2){
                int t = 0;
                for(int j = 0; j < 2; j++){
                    for(int k = 0; k < 2; k++){
                        
                        int nx = x[i] + j * di;
                        int ny = y[i] + k * dj;
                        t += mp[{nx, ny}];
                    }
                }
                ans = max(ans, t);
            }
        }
    }

    cout << ans << " / " << 1 <<  endl;
    
    return 0;
}



Measured memory_bytes: 60644
#include<bits/stdc++.h>
using namespace std;
const double eps=1e-10;
double n;
int main()
{
	scanf("%lf",&n);
	for(int i=1;i<=3500;i++)
	  for(int j=1;j<=3500;j++)
	  if(fabs(n-1/i-1/j)>eps)
	  {
		double tmp=4-n/i-n/j;
		double c=n/tmp;
		if(c<=(double)1e18)
		{
		long long tt=floor(c);
		if(tt<0) continue;
		if(fabs(c-tt)<eps) return printf("%d %d %lld",i,j,tt),0;
		tt++;
		if(fabs(c-tt)<eps) return printf("%d %d %lld",i,j,tt),0;
		}
	  }
}

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

int main() {
	int n; cin >> n;
	vector<int>a1(n + 1, 0), a2(n + 1, 0);
	for (int i = 1; i <= n; i++) {
		int tmp; cin >> tmp;
		a1[i] += a1[i - 1] + tmp;
	}
	for (int i = 1; i <= n; i++) {
		int tmp; cin >> tmp;
		a2[i] += a2[i - 1] + tmp;
	}

	int ans = 0;
	for (int i = 1; i <= n; i++) {
		ans = max(ans, a1[i] + a2[n] - a2[i - 1]);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3600
#include<stdio.h>
int main(){
    int h,n,sum=0;
    scanf("%d%d",&h,&n);
    int array[n];
    for(int i=0;i<n;i++){
        scanf("%d",&array[i]);
        sum = sum + array[i];
    }
    if(sum >= h) printf("Yes");
    else printf("No");
}

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

#define all(c) ((c).begin()), ((c).end())
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define mp make_pair
#define fst first
#define snd second
#define pb push_back
#define debug( fmt, ... ) \
        fprintf( stderr, \
                  fmt "\n", \
                  ##__VA_ARGS__ \
        )

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1 << 29;
const double EPS = 1e-10;

double zero(double d) {
    return d < EPS ? 0.0 : d;
}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &a) {
    os << '[';
    rep(i, a.size()) os << (i ? " " : "") << a[i];
    return os << ']';
}

string toString(int i) {
    stringstream ss;
    ss << i;
    return ss.str();
}

const int MOD = 1000000007;
// a^k
ll fpow(ll a, ll k, int M) {
    ll res = 1ll;
    ll x = a;
    while (k != 0) {
        if ((k & 1) == 1)
            res = (res * x) % M;
        x = (x * x) % M;
        k >>= 1;
    }
    return res;
}

struct prepare {
	prepare() {
	    cout.setf(ios::fixed, ios::floatfield);
	    cout.precision(8);
	    ios_base::sync_with_stdio(false);
	}
} _prepare;

int main() {
	int N;
	cin >> N;

	vi L(2*N);
    rep(i, 2*N)
        cin >> L[i];
    sort(all(L));

    int ans = 0;
    for(int i=0; i<2*N; i+=2) {
        ans += L[i];
    }

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

Measured memory_bytes: 384
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		if(N <= 999){
			System.out.println("ABC");
			return;
		}else{
			System.out.println("ABD");
		}
	}
}

Measured memory_bytes: 23124
S = input()
if S == "SUN":
 print("7")
elif S == "MON":
 print("6")
elif S == "TUE":
 print("5")
elif S == "WED":
 print("4")
elif S == "THU":
 print("3")
elif S == "FRI":
 print("2")
elif S == "SAT":
 print("1")

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
void Say(bool say, string a = "Yes", string b = "No"){cout << (say ? a : b) << endl;};

int main(){

    string s;
    ll n;
    cin >> s;
    cin >> n;
    for(ll i = 0; i < s.size(); i += n)cout << s[i];
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<unordered_set>
#include<unordered_map>
#include<random>
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

int N;
string S[1000000];
pair<int, int> v[1000000];
vector<pair<int, int>> v2;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> N;
    rep(i, N) cin >> S[i];

    rep(i, N){
        int r = 0;
        int l = 0;
        rep(j, S[i].size()){
            if(S[i][j] == '(') l++;
            else{
                if(l > 0)  l--;
                else r++;
            }
        }
        v[i] ={ r,l };
    }
    sort(v, v+N);

    int n = 0;
    rep(i, N){
        if(v[i].first > v[i].second){
            v2.pb({v[i].second, v[i].first});
            continue;
        }
        if(v[i].first > n){
            cout << "No" << endl;
            return 0;
        }
        n += v[i].second-v[i].first;
    }

    sort(all(v2));
    int m = 0;
    rep(i, v2.size()){
        if(v2[i].first > m){
            cout << "No" << endl;
            return 0;
        }
        m += v2[i].second-v2[i].first;
    }

    if(n != m){
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 46468
N,M = map(int, input().split()) 
H = list(map(int,input().split())) 

route = []
for i in range(N):
    route.append([])
    
more_high = []
for i in range(N):
    more_high.append([])
    
result = 0

for m in range(M):
    a,b = map(int, input().split()) 
    route[a-1].append(b-1)
    route[b-1].append(a-1)

c = 0
for r in route:
    route[c] = list(set(r))
    for target in route[c]:
        if H[c] <= H[target]:
            more_high[c].append(target)
    c += 1

for i in more_high:
    if i == []:
        result += 1

print(result)

Measured memory_bytes: 39620
#include<bits/stdc++.h>
using namespace std;
int N, D[100], ANS;
int main(void)
{
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> D[i];
	}
	for (int i = 0; i < N; i++)
	{
		for (int j = i + 1; j < N; j++)
		{
			ANS += D[i] * D[j];
		}
	}
	cout << ANS << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
// -----------------<fast IO>------------------
#define IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FLSH             fflush(stdout)
#define fileIO(name) \
    freopen(name".in", "r", stdin); \
    freopen(name".out", "w", stdout);
#define PRECISION(x)     cout << fixed << setprecision(x);
// -----------------<TypeDef Start>------------------
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
// -----------------<Constants>------------------
const int MAXN = 1000005;
const int SQRTN = 1003;
const int LOGN = 22;
const double PI=acos(-1);

const int INF=1e9;

int MOD = 1000000007;
const int FMOD = 998244353;
const double eps = 1e-9;
/*ll gcd(ll a,ll b)
{
    if(a==0)
    return(b);
    return(gcd(b%a,a));
}*/
// --------------------------------------------------</TEMPLATE>--------------------------------------------------


void solve()
{
    string s,t;
    cin>>s>>t;
    int ans=INT_MAX;
    int c=t.length();
    for(int i=0;i<s.length()-t.length()+1;i++)
    {
        int cnt=0;
        for(int j=0;j<t.length();j++)
        {
            if(s[i+j]!=t[j])
            {
                cnt++;
            }
        }
        ans=min(ans,cnt);
    }
    cout<<ans<<endl;

}

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


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define inf 1000000007
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
lol i[10000];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,d,e=0,f=0;
  string s,w;
  bool ans=true;
  cin >>s>>w;
  for(int n=0;n<s.size();n++){
      cout <<s[n];
      if(n!=w.size()) cout <<w[n];
  }
  cout <<'\n';
  return (0);
}


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

using namespace std;

typedef long long ll;

#define FOR(a, b, i) for(int i=a; i<b; i++)
#define RFOR(a, b, i) for(int i=a; i>=b; i--)
#define PB push_back
#define MP make_pair
#define MOD 1e9+7
#define newline cout<<"\n"

ll nax = 1e5+5;
int mx = 1e9+7;


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

    int n, w; cin>>n>>w;
    vector<int> wt(n), val(n);

    FOR(0, n, i)
    {
        cin>>wt[i]>>val[i];
    }

    // dp[i] is the mimimum weight needed to make a value i
    vector<int> dp(nax, mx);

    dp[0] = 0;

    FOR(0, n, i)
    {
        RFOR(nax-val[i]-1, 0, j)
        {
            dp[j+val[i]] = min(dp[j+val[i]], dp[j]+wt[i]);
        }
    }

    ll ans=0;
    FOR(0, nax, i)
    {
        if(dp[i]<=w)
        {
            if(i>ans) ans=i;
        }
    }

    cout<<ans;
    newline;
    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
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;
}

ll M = 1000000007;

void solve()
{
	string n;
	cin>>n;
	int len=size(n);
	ll sum=0;
	rep(i,len){
		sum+=n[i]-'0';
	}
	if(sum%9==0){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}

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


Measured memory_bytes: 3744
def insertion_sort(ary,num,g)
  count = 0
  for i in g..num-1
    v = ary[i]
    j = i - g
    while j >= 0 && ary[j] > v
      ary[j+g] = ary[j]
      j = j - g
      count += 1
    end
    ary[j+g] = v
  end
  count
end

def shell_sort(ary,num)
  cnt = 0
  g = []
  h = 1
  while h <= num 
    g << h
    h = 3*h+1
  end
  g.reverse!
  m = g.size
  for i in 0..m-1
    cnt += insertion_sort(ary,num,g[i])
  end
  puts m
  puts g.join(" ")
  puts cnt
end

n = gets.to_i
a = []
n.times do
  a << gets.to_i
end
shell_sort(a,n)
puts a

Measured memory_bytes: 16780
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K;
int A[22];
const ll mo=1000000007;
const int NUM_=400001;
static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];

ll modpow(ll a, ll n = mo-2) {
	ll r=1;a%=mo;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}

ll comb(ll N_, ll C_) {
	if (fact[0]==0) {
		inv[1]=fact[0]=factr[0]=1;
		for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
		for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
	}
	if(C_<0 || C_>N_) return 0;
	return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;
}

/*
ll dp[21];
ll FP[20202],FV[20202];
ll TP[20202],TV[20202];
*/

ll from[1010];
ll to[1010];


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	comb(1,1);
	
	int sum=0;
	FOR(i,K) {
		cin>>A[i];
		sum+=A[i];
	}
	
	ll ret=0;
	from[N]=1;
	FOR(i,K) {
		ZERO(to);
		FOR(x,N+1) if(from[x]) {
			FOR(y,A[i]+1) if(x>=y) {
				(to[x-y]+=from[x]*comb(x,y)%mo*comb(N-y,A[i]-y))%=mo;
			}
		}
		swap(from,to);
	}
	
	cout<<from[0]<<endl;
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 9600
#include<iostream>
#include<map>
#include<string>
#include<cmath>
#include<vector>
using namespace std;

int main(){
    int n,m,x,y;
    cin>>n>>m;
    vector<pair<int,int>> a(n),b(m);
    for(int i=0;i<n;i++){
        cin>>x>>y;
        a[i]=pair<int,int>(x,y);
    }
    for(int i=0;i<m;i++){
        cin>>x>>y;
        b[i]=pair<int,int>(x,y);
    }
    for(int i=0;i<n;i++){
        int itr=0;
        long long int tmp,maxt=9999999999;
        for(int j=0;j<m;j++){
            tmp=abs(a[i].first-b[j].first)+abs(a[i].second-b[j].second);
            //cout<<"j="<<j<<",tmp="<<tmp<<endl;
            if(tmp<maxt){
                maxt=tmp;
                itr=j+1;
            }
        }
        cout<<itr<<endl;
    }
}                                                

Measured memory_bytes: 256
str = str(input())
q = int(input())
for i in range(q):
    command, a, b, *p =input().split()
    a = int(a)
    b = int(b)
    p = ''.join(p)
    if command == 'print':
        print(str[a:b+1])

    elif command == 'reverse':
        str = str[:a] + str[a:b+1][::-1] + str[b+1:]
    else:
        str = str[:a] + p +str[b+1:]


Measured memory_bytes: 5612
# -*- coding: utf-8 -*-
import collections

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

linked_room = [[] for i in [1] * n]
sign = [0] * n
sign[0] = 1
arrivable_rooms = 0

for mi in range(m):
    tmp_a, tmp_b = map(int, input().split())
    linked_room[tmp_a-1].append(tmp_b)
    linked_room[tmp_b-1].append(tmp_a)

work_q = collections.deque([1])

while len(work_q) > 0:
    past_room = work_q.pop()
#    print("past room: " + str(past_room))
    next_rooms = linked_room[past_room-1]
    for nri in next_rooms:
        if sign[nri - 1] == 0:
            sign[nri - 1] = past_room
            arrivable_rooms += 1
            work_q.appendleft(nri)

if arrivable_rooms == n-1:
    print('Yes')
    for si in sign[1:n]:
        print(si)
else:
    print('No')



Measured memory_bytes: 94608
using System;
using System.Collections.Generic;

namespace relay_c
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            long x = (long)Math.Pow(2,n);
            LinkedList<int> a = new LinkedList<int>();
            for (long i = 0; i < x; i++) a.AddLast(int.Parse(Console.ReadLine()));
            while (a.Count > 1)
            {
                var b = a.First.Value; a.RemoveFirst();
                var c = a.First.Value; a.RemoveFirst();
                a.AddLast(b == c ? b : Math.Abs(b - c));
            }
            Console.WriteLine(a.First.Value);
        }
    }
}

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

using namespace std;

const int maxn=1e5+5;
const int mod=1e9+7;
typedef long long ll;

int a[maxn];

int main(){
	int n;scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",a+i);
	}
	for(int i=0;i<n-1;i++){
		if(a[i]-a[i+1]>1){
			printf("No");return 0;
		}
	}
	
	int flg=0;
	for(int i=1;i<n;i++){
		if(a[i-1]>a[i]&&flg){
			printf("No");return 0;
		}
		if(a[i-1]>a[i]&&!flg){
			flg=1;
		}
		if(a[i-1]<a[i]){
			flg=0;
		}
	}
	printf("Yes");
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

int main(){
 float sum=0;
 int i,n;
 scanf("%d", &n);
 float aa[n];
 for(i=0;i<n;i++){
	scanf("%f ", &aa[i]);
 }
 for(i=0;i<n;i++){
   sum += 1/aa[i];
 }
 printf("%f" , 1/sum);
  return 0;
}

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

int main(){
    int N, n;
    int S = 0;

    cin >> N;
    n = N;

    S += N % 10;
    while(N / 10 != 0){
        N /= 10;
        S += N % 10;
    }

    if(n % S == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>

int main(){
    double w, h, a, c;
    std::cin >> w >> h >> a >> c;

    double b = w - a, d = h - c;
    double ans = std::max(std::min(a * h, b * h), std::min(c * w, d * w));

    bool flg = a == b && c == d; 

    std::cout << std::fixed << std::setprecision(9) << w * h / 2 << " " << (int) flg << std::endl;

    return 0;
}

Measured memory_bytes: 888