akhauriyash/Code-Regression huggingface dataset:
import sys


class Card:
    def __init__(self, suit, value):
        self.suit = suit
        self.value = value


SENTINEL_NUM = 10 ** 9 + 1
cnt = 0
sentinel = Card(None, SENTINEL_NUM)


def merge(A, left, mid, right):
    global cnt
    global sentinel
    n1 = mid - left
    n2 = right - mid
    L = A[left:mid] + [sentinel]
    R = A[mid:right] + [sentinel]

    i, j = 0, 0
    for k in range(left, right):
        cnt += 1
        if L[i].value <= R[j].value:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1


def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right)


def partition(A, p, r):
    x = A[r].value
    i = p - 1
    for j in range(p, r):
        if A[j].value <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i + 1], A[r] = A[r], A[i + 1]
    return i + 1


def quick_sort(A, p, r):
    if p < r:
        q = partition(A, p, r)
        quick_sort(A, p, q - 1)
        quick_sort(A, q + 1, r)


n = int(input())
A = [[None] * 2 for _ in range(n)]
B = [[None] * 2 for _ in range(n)]
for i in range(n):
    suit, value = input().split()
    A[i] = B[i] = Card(suit, int(value))

quick_sort(A, 0, n - 1)
merge_sort(B, 0, n)

if A == B:
    print("Stable")
else:
    print("Not stable")
for i in range(n):
    print(A[i].suit, A[i].value)



Measured memory_bytes: 28060
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <math.h>
using namespace std;
#define forn(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define ford(i, a, n) for (int i = (int)(n) - 1; i >= (int)(a); --i)
#define fore(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define printV(vec) for(int i = 0; i < SZ(vec); i++){cout << vec[i];if (i==SZ(vec)-1){cout<<endl;}else{cout << " ";}}
#define printA(arr,n) for(int i = 0; i < n; i++){cout << arr[i];if (i==n-1){cout<<endl;}else{cout << " ";}}
typedef long long ll;

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


  string s = "ABC";
  if (N > 999){
    s = "ABD";
  }
  cout << s << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main() {
	string s;
	while (cin >> s) {
		if (s == "0")return 0;
		int a = 0, b = 0;
		for (int i = 1; i < s.size(); i++) {
			if (s[i] == 'A')a++;
			else if (s[i] == 'B')b++;
		}
		if (a > b)a++; else b++;
		cout << a << ' ' << b << endl;
	}
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

int n_=1<<11;
class segtree{
public:
	short dp[1<<12];
	segtree(){
		memset(dp,0,sizeof(dp));
	}
	void update(int k,int v){
		k+=n_-1;
		dp[k]+=v;
		while(k>0){
			k=(k-1)/2;
			dp[k]=dp[k*2+1]+dp[k*2+2];
		}
	}

	short query(int a,int b,int k=0,int l=0,int r=n_){
		if(b<=l || r<=a)return 0;
		if(a<=l && r<=b)return dp[k];
		int mid=(l+r)/2;
		short vl=query(a,b,k*2+1,l,mid);
		short vr=query(a,b,k*2+2,mid,r);
		return vl+vr;
	}
};

segtree seg[2001][2];
segtree seg2[2001][2];

int H,W,T,q;
int B=50;
int data[2001][2001];
int cnt[45][45];
int cnt2[45][45];


int main(void){
	scanf("%d%d%d%d",&H,&W,&T,&q);
	memset(data,-1,sizeof(data));
	queue<PP> que;
	for(int i=0;i<q;i++){
		int t,c,h,w;
		scanf("%d%d%d%d",&t,&c,&h,&w);
		while(que.size()){
			PP p=que.front();
			if(p.first<=t){
				int hh=p.second.first;
				int ww=p.second.second;
				seg[hh][0].update(ww,-1);
				seg[hh][1].update(ww,1);
				seg2[ww][0].update(hh,-1);
				seg2[ww][1].update(hh,1);
				cnt[hh/B][ww/B]--;
				cnt2[hh/B][ww/B]++;
			}else break;
			que.pop();
		}
		h--;
		w--;
		if(c==0){
			if(data[h][w]==-1){
				cnt[h/B][w/B]++;
				data[h][w]=t+T;
				seg[h][0].update(w,1);
				seg2[w][0].update(h,1);
				que.push(PP(t+T,P(h,w)));
			}
		}
		if(c==1){
			if(data[h][w]!=-1 && data[h][w]<=t){
				cnt2[h/B][w/B]--;
				data[h][w]=-1;
				seg[h][1].update(w,-1);
				seg2[w][1].update(h,-1);
			}	
		}
		if(c==2){
			int h2,w2;
			scanf("%d%d",&h2,&w2);
			int res=0;
			int res2=0;
			int nh=h;
			int nh2=h2;
			while(nh<nh2 && nh%B!=0){
				res+=seg[nh][0].query(w,w2);
				res2+=seg[nh][1].query(w,w2);
				nh++;
			}
			while(nh<nh2 && nh2%B!=0){
				res+=seg[nh2-1][0].query(w,w2);
				res2+=seg[nh2-1][1].query(w,w2);
				nh2--;
			}
			int nw=w;
			int nw2=w2;
			while(nw<nw2 && nw%B!=0){
				res+=seg2[nw][0].query(nh,nh2);
				res2+=seg2[nw][1].query(nh,nh2);
				nw++;
			}
			while(nw<nw2 && nw2%B!=0){
				res+=seg2[nw2-1][0].query(nh,nh2);
				res2+=seg2[nw2-1][1].query(nh,nh2);
				nw2--;
			}
			for(int j=nh/B;j<nh2/B;j++){
				for(int k=nw/B;k<nw2/B;k++){
					res+=cnt[j][k];
					res2+=cnt2[j][k];
				}
			}
			printf("%d %d\n",res2,res);
		}
	}
	return 0;
}

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





int main() {
  string a,b,c;
  cin>>a>>b>>c;
  int asize=a.size(),bsize=b.size(),csize=c.size();
  
  if (a.at(asize-1)==b.at(0) and b.at(bsize-1)==c.at(0)){
    cout<<"YES"<<endl;
  }
  
  else {
    cout<<"NO"<<endl;
  }
  
  
  
}












Measured memory_bytes: 256
#include<map>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<stack>
#define REP(i,x,y) for(ll i=x;i<y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll>
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define UNIQUE_ARRAY(a,n) n = unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>x;i--)
typedef long long ll;
using namespace std;
int main(){
    ll n,a;
    cin>>n>>a;
    ll s=n%500;
    if (s<=a){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string N;
    int K;
    cin >> N >> K;
    int keta = N.size();
    vector<vector<vector<ll>>> dp(keta + 1, vector<vector<ll>>(2, vector<ll>(K + 1, 0)));//<左からN桁まで>、<境界は1、それ以外0>、<0以外の数>
    dp.at(1).at(1).at(1) = 1;
    dp.at(1).at(0).at(1) = N.at(0) - '0' - 1;
    for(int i = 2; i <= keta; i++)
    {
        dp.at(i - 1).at(0).at(0) = 1;
        int num = N.at(i - 1) - '0';
        for(int j = 1; j <= K; j++)
        {
            if(num > 0)
            {
                dp.at(i).at(1).at(j) = dp.at(i - 1).at(1).at(j - 1);
            } else {
                dp.at(i).at(1).at(j) = dp.at(i - 1).at(1).at(j);
            }
        }
        for(int j = 1; j <= K; j++)
        {
            //境界以外の桁が0の分
            dp.at(i).at(0).at(j) += dp.at(i - 1).at(0).at(j);
            //境界以外の桁が0以外の分
            dp.at(i).at(0).at(j) += dp.at(i - 1).at(0).at(j - 1) * 9;
            if(num > 0)
            {
                //境界の桁が0の分(numが0の時は境界の方に追加されているので追加しない)
                dp.at(i).at(0).at(j) += dp.at(i - 1).at(1).at(j);
                //境界の桁が0以外の分(境界の方を除くため-1)
                dp.at(i).at(0).at(j) += dp.at(i - 1).at(1).at(j - 1) * (num - 1);
            }
            
        }
    }
    ll answer = dp.at(keta).at(1).at(K) + dp.at(keta).at(0).at(K);
    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
d = [int(input()) for i in range(N)]

# num[i] は iの出現回数を示す。配列numを初期化
num = [0] * 101
# 最大の段数をカウント
count = 0

for i in range(N):
    num[d[i]] += 1

for i in range(101):
    if num[i] > 0:
        count += 1

print(count)


Measured memory_bytes: 3060
#include <iostream>
//#include <iomanip>
#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <bitset>
//#include <math.h>
using namespace std ;
//using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	int n ; cin >> n ;
	string s ; cin >> s ;
	int r,b ; r = b = 0 ;
	for(int i=0;i<n;i++) if(s.at(i)=='R') r++ ; else b++ ;
	cout << yorn(r>b) << endl ;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
    int a,s,m,h;
    cin >> s;
    h = s / 3600;
    s = s % 3600;
    m = s / 60;
    s = s % 60;
    cout << h << ":" << m << ":" << s << endl;

    return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <queue>
#include <stack>

using namespace std;
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)
#define ll long long
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
    int k;
    cin >> k;
    int a,b;
    a = k/2;
    b = k-a;
    cout << a*b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }



signed main(){

    int N, Ma, Mb; cin >> N >> Ma >> Mb;
    vec a(N), b(N), c(N);
    REP(i, N) cin >> a[i] >> b[i] >> c[i];

    mat dp(401, vec(401, INF));
    dp[0][0] = 0;
    REP(n, N){
        mat dp0 = dp;
        REP(i, 401 - a[n]){
            REP(j, 401 - b[n]){
                dp[i + a[n]][j + b[n]] = min(dp0[i + a[n]][j + b[n]], dp0[i][j] + c[n]);
            }
        }
    }
    
    int ans = INF;
    for(int i = 1; Ma * i <= 400 && Mb * i <= 400; i++) ans = min(ans, dp[Ma * i][Mb * i]);
    if(ans < INF) cout << ans;
    else cout << -1;
    
    return 0;
}

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

int main()
{
	int A, B, C, X, result(0);
	cin >> A >> B >> C >> X;

	for (int i = 0; i <= A; i++)
	{
		for (int m = 0; m <= B; m++)
		{
			int n = (X - m * 100 - 500 * i) / 50;
			if (0 <= n && n <= C)
				result++;
		}
	}

	cout << result << endl;

	return 0;
}


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

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif


#define ll long long 
#define ld long double
#define pb push_back
#define F first
#define S second
#define I insert
#define pll pair<ll,ll> 
#define vll vector<ll> 
#define vpll vector< pll >

int main() {
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	ll n,k,a,b,c,d,i,j;
	cin>>n>>k;
	a=n/k;if(k%2==0){b=n/(k/2);b-=a;}else b=0;
	cout<<a*a*a+b*b*b;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;

typedef long long LL;
const int MOD = 1e9+7;

void solve(){
	LL a,b,c;
	cin>>a>>b>>c;
	LL t = c-a-b;
	if(t>=0 && t*t>4*a*b){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}


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


Measured memory_bytes: 256
#include <stdio.h>
#define N 100005
int n, m, i, j, k, a, b, f[N], g[N];
int main(){
	scanf("%d%d", &n, &m);
	for(i=1; i<=n; i++){
		scanf("%d", &g[i]);
	}
	for(i=1; i<=m; i++){
		scanf("%d%d", &a, &b);
		if(g[a]>=g[b] && ++f[b]==1) n--;
		if(g[b]>=g[a] && ++f[a]==1) n--;
	}
	printf("%d\n", n);
	return 0;
}

Measured memory_bytes: 2512
//02, 12, 2018, 10:18:33 Rafaelcs cpp
#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> pii;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

const int N = 110;
int a[N];
const int TARGET = 75;
int dp[N][N];
bool used[N][N];

int solve(int pos, int mult){
    if(mult == TARGET){
        return 1;
    }

    if(pos == N){
        return 0;
    }

    if(mult > TARGET){
        return 0;
    }

    int &ans = dp[pos][mult];
    if(used[pos][mult]){
        return ans;
    }

    used[pos][mult] = true;

    for(int i = 0 ; i <= a[pos] ; i++){
        ans += solve(pos + 1, mult * (i + 1));
    }

    return ans;
}

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

    cin >> n;

    if(n <= 9){
        cout << 0 << endl;
        return 0;
    }

    for(int i = 1 ; i <= n ; i++){
        int k = i;

        for(int j = 2 ; j * j <= k ; j++){
            if(k % j == 0){
                int e = 0;

                while(k % j == 0){
                    e++;
                    k /= j;
                }

                a[j] += e;
            }
        }

        if(k != 1){
            a[k]++;
        }
    }

    printf("%d\n", solve(1, 1));

    return 0;
}

Measured memory_bytes: 384
using System;
using System.Linq;

namespace ABC117_B
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            var L = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            L = L.OrderByDescending(x => x).ToArray();

            int first_long = L.First();
            int other_all = L.Skip(1).Sum();

            Console.WriteLine(first_long < other_all ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 13396
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	String N;
	long result = 0;
	long[][] dp;

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	void sub(int keta) {
		int val = Integer.parseInt(N.substring(keta, keta + 1));
		// ピッタリ払う場合; dp[keta-1][0] + ピッタリ払う or 前の状態で余分に払っている分のおつりをもらう
		dp[keta + 1][0] = Math.min(dp[keta][0] + val, dp[keta][1] + (10 - val));

		// 超える範囲で払う場合
		// ピッタリ払う + val+1払う
		// or
		// 超えている分 - 1少ないおつりもらう
		dp[keta + 1][1] = Math.min(dp[keta][0] + val + 1, dp[keta][1] + (10 - val - 1));
	}

	Main(BufferedReader in) throws IOException {
		N = in.readLine();
		// 0: ピッタリ払う，1: 超える最小値
		this.dp = new long[N.length() + 1][2];
		dp[0][0] = 0;
		dp[0][1] = 1;

	}

	void calc() {
		for (int i = 0; i < N.length(); ++i) {
			sub(i);
		}
		result = Math.min(dp[N.length()][0], dp[N.length()][1]+1);
	}

	void showResult() {
		System.out.println(result);
	}
}


Measured memory_bytes: 109368
#include<iostream>
#include<cstdio>
//#include<cmath>
using namespace std;

long long a[200101],ans=1e17,v1,v2,n,sum;

long long abss(long long x,long long y)
{
	if(v1>v2)
		return v1-v2;
	return v2-v1;
}

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		sum+=a[i];
	}
	v1=a[1];
	v2=sum-a[1];
	ans=min(ans,abss(v2,v1));
	for(int i=2;i<n;i++)
	{
		v1+=a[i];
		v2-=a[i];
		ans=min(ans,abss(v2,v1));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(void)
{
  int i,a,b,c;
  scanf("%d",&i);
    while(i--) {
      scanf("%d%d%d",&a,&b,&c);
      if (a*a == b*b + c*c || b*b == a*a + c*c || c*c == a*a + b*b)
	puts("YES");
      else puts("NO");
    }

  return 0;

}

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

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


  if (n / 100 == 7){
    cout << "Yes" << endl;
  } else if((n % 100) / 10 == 7){
    cout << "Yes" << endl;
  } else if(n % 10 == 7){
    cout << "Yes" << endl;
  } else{
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 3620
void main() {
  import std.stdio, std.string, std.conv, std.algorithm;

  long n, k;
  rd(n, k);
  long tot = 0;
  for (long a = 1; a <= n; a++) {
    if ((a * 2) % k == 0) {
      auto x = (a + n) / k - (a + 1 + k - 1) / k + 1;
      tot += x * x;
    }
  }
  writeln(tot);

}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

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

    int ans = 0;
    for(int i=1; i<=n; i++){
        int tmpi = i;
        int sum = 0;
        while(tmpi!=0){
            sum += tmpi%10;
            tmpi /= 10;
        }
        if(a<=sum && sum<=b){
            ans += i;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
x,y,z,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=[]
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
for i in range(min(x,k)):
  for j in range(min(y,k)):
    for l in range(min(z,k)):
      if i*j*l>k:
        break
      else:
        ans.append(a[i]+b[j]+c[l])
ans.sort(reverse=True)
for i in range(k):
  print(ans[i])


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

#define pb push_back
#define mp make_pair

#define fi first
#define se second

#define all(x) (x).begin(), (x).end()

typedef long long ll;

using namespace std;             
const int N = (int) 1e5 + 5;

int n, a[N];

vector<int> g[N];

void dfs(int v, int pr) {
    if (g[v].size() == 1)return;
    
    ll sum = 0;
    int mx = 0;

    for (int to : g[v]) {
        if (to == pr) continue;                                                                                                 
        dfs(to, v);
        sum += a[to];
        mx = max(mx, a[to]);
    }

    if (a[v] > sum || sum > 2 * a[v]) {
        cout << "NO\n";
        exit(0);
    }

    int k = sum - a[v];
    if (k > sum - mx) {
        cout << "NO\n";
        exit(0);
    }

    a[v] -= k;

    return;
}


void solve() {    
    cin >> n;

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

    for (int i = 1; i < n; i++) {
        int l, r;
        cin >> l >> r;
        g[l].pb(r);
        g[r].pb(l);
    }

    if (n == 2) {
        if (a[1] == a[2]) {
            cout << "YES\n";
        }
        else cout << "NO\n";
        return;
    }

    int v = 1;
    while (g[v].size() == 1) {
        v++;
    }
    
    dfs(v, -1);
      
    if (a[v] == 0) {
        cout << "YES\n";
    }
    else {
        cout << "NO\n";
    }
      
    return;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int tt = 1;

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

    return 0;
}

Measured memory_bytes: 12800
#include<iostream>
#include<cstdio>
using namespace std;
long long x,a[200005],h[200005],yh[200005],ans;
int main() {    
	int n;    
	scanf("%d",&n);    
	h[0]=0;
	yh[0]=0;    
	for(int i=1;i<=n;i++)    
	{        
		scanf("%d",&a[i]);        
		h[i]=h[i-1]+a[i];        
		yh[i]=yh[i-1]^a[i];    
	}    
	int l=1;    
	ans=0;    
	for(int r=1;r<=n;r++)    
	{        
		while((h[r]-h[l-1])!=(yh[r]^yh[l-1])) l++;        
		ans+=r-l+1;    
	}    
	printf("%lld\n",ans);
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX=1e6+5;

int a[MAX],top;
void dfs(int step,int flag,ll num)
{
    if(num>1e9)return;
    if(step>10)return;
    if(flag==7)a[top++]=num;
    dfs(step+1,flag|1,num*10+3);
    dfs(step+1,flag|2,num*10+5);
    dfs(step+1,flag|4,num*10+7);
}
int main()
{
    dfs(0,0,0);
    sort(a,a+top);
  //  cout<<top<<endl;
  //  for(int i=0;i<=20;i++)cout<<a[i]<<endl;
    int n;
    while(cin>>n)
    {
        int x=lower_bound(a,a+top,n)-a;
        if(a[x]==n)x++;
        cout<<x<<endl;
    }
    return 0;
}


Measured memory_bytes: 384
program kadai
implicit none
integer  ::  n
integer,allocatable  ::  a(:,:)
integer  ::  i,j,time

read(*,*) n
allocate(a(2,n))
read(*,*) a

call qsort(a)
time=0
j=0
do i=1,n
time=time+a(1,i)
if (time>a(2,i)) then
    write(*,*) "No"
    stop
end if
end do
write(*,*) "Yes"

contains

!
! swap two arguments
!
subroutine swap(a, b)
implicit none
integer, intent(inout) :: a, b
integer :: c
c = a
a = b
b = c
end subroutine swap

!
! quick sort
!再帰的に定義
subroutine qsort(x)
implicit none
integer, intent(inout)  ::  x(:,:)
integer  ::  first,last
first=1
last=size(x(2,:))
!!前半と後半に区切りたいので、最初と最後の引数を入れたかsubroutineを呼ぶ
call q2sort(x,first,last)
return
end subroutine qsort



!!!クイックソートを実際に行うサブルーチン
recursive subroutine q2sort(x,first,last)
implicit none
integer, intent(inout)  ::  x(:,:)
integer, intent(inout) ::  first,last
integer  ::  fir, las   !!再帰時の頭と尾
integer  ::  i,j
integer  ::  n


!現在真ん中にある要素をpivotとして設定する。
n=x(2,(first+last)/2)

i=first
j=last


!!無限ループの中で、pivot以下を前に、pivot以上を後に動かす
do
    do while (x(2,i)<n)
        i=i+1
    end do
    do while(x(2,j)>n)
    j=j-1
    end do


    if (i>j .or. i==j) then
        exit
    end if

    call swap(x(2,i),x(2,j))
    call swap(x(1,i),x(1,j))
i=i+1
j=j-1

end do


!!pivot以下の組について再帰的に入れ替える
if (first<i-1) then
las=i-1
call q2sort(x,first,las)
end if

!!pivot以上の組について再帰的に入れ替える
if (last>j+1) then
fir=j+1
call q2sort(x,fir,last)
end if

end subroutine q2sort


end program kadai


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

int main(){
    ll a,b,x,ans=0,mem;
    cin >> a >> b >> x;
    if (a)ans = b / x - (a-1) / x;
    else ans = b / x + 1; 
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include<functional>
#include<queue>
#include<regex>
#include<time.h>
#include<type_traits>

using namespace std;
using ll = long long;

constexpr ll MOD = 1000000007;
constexpr ll INF = 1050000000;
constexpr ll LONGINF = 1050000000000000000;


vector<vector<int>> g;
vector<int> q;
vector<int> ans;
vector<int> mitou;//true まだ訪れていない false 訪れたことがある
vector<vector<pair<int, int>>> cost_g;//cost[from].emplace_back({to,cost});無向辺は両方に貼る

void dfs(int i,int c, int l) {
	if (mitou[i]) {
		mitou[i] = false;
		if (l & 1) {
			ans[i] = abs(c - 1);
		}
		else {
			ans[i] = c;
		}
		for (auto x : cost_g[i]) {
			if (mitou[x.first]){
				dfs(x.first, ans[i], x.second);
			}
		}
	}
}

int main() {
	int n; cin >> n;//入力

	cost_g = vector<vector<pair<int, int>>>(n);
	ans = vector<int>(n, -1);
	//g = vector<vector<int>>(n);
	//q = vector<int>(n);//各頂点のクエリあたりの総和が格納される。
	mitou = vector<int>(n, true);//通ったかどうかを判定する。

	for (int i = 0; i < n - 1; i++) {
		int u, v, w; cin >> u >> v >> w;
		u--; v--;
		cost_g[u].emplace_back(make_pair(v, w));
		cost_g[v].emplace_back(make_pair(u, w));
	}

	//根を0として深さ優先探索を行う。持つべきなのは、前の辺の長さとその色と頂点番号
	dfs(0, 0, 0);

	for (auto x : ans) {
		cout << x << " ";
	}

	return 0;
}

Measured memory_bytes: 7808
#include <bits/stdc++.h>
using namespace std;
#define                MXX 1000006
#define                FAST_IO ios_base::sync_with_stdio(false),cin.tie(NULL)
#define                exit() return 0
#define                mpii map<int, int>
#define                mpit map<int, int>::iterator it
#define                si set<int>
#define                sit set<int>::iterator it;
#define                ll long long int
#define                endl "\n";
const                  ll INF = 2000000000000000000LL;
const                  int MOD = 10000007;

int a[MXX], N, K;
int dp[MXX];
ll solve(int curr)
{
    if(curr>=N)
    {
        return INF;
    }
    if(curr == N - 1)
    {
        return 0;
    }
    if(dp[curr]!=-1)
    {
        return dp[curr];
    }
    ll x = INF;
    for(int i = 1; i<=K; i++)
    {
        x = min(x, solve(curr + i) + abs(a[curr] - a[curr+i]));
    }
    ll ans = x;
    dp[curr] = ans;
    return ans;
}
int main()
{
    FAST_IO;
    cin>>N>>K;
    for(int i = 0; i<N; i++)cin>>a[i];
    memset(dp, -1, sizeof(dp));
    cout<<solve(0)<<endl;
    return 0;
}


Measured memory_bytes: 11136
#include <iostream>
#include <queue>
#include <vector>
#include <set>
#include <algorithm>
#include <functional>
using namespace std;

const int INF = 1<<28;

struct edge_t {
    int from, to, cost;
    edge_t(int from, int to, int cost) : from(from), to(to), cost(cost) {}
    bool operator<(const edge_t &o) const {
        return (cost < o.cost);
    }
    bool operator>(const edge_t &o) const {
        return (cost > o.cost);
    }
};
struct state_t {
    int v;
    int min_cost;
    state_t(int v, int min_cost) : v(v), min_cost(min_cost) {}
    bool operator<(const state_t &o) const {
        return (min_cost < o.min_cost);
    }
    bool operator>(const state_t &o) const {
        return (min_cost > o.min_cost);
    }
};
typedef vector<edge_t> vertex_t;
struct graph_t {
    vector<vertex_t> g;

    graph_t() {}

    graph_t(int vertex_count) {
        g.resize(vertex_count);
    }
    graph_t(vector<vertex_t> g) : g(g) {}

    inline vertex_t& operator[](int index) {
        return g[index];
    }

    inline void push_back(vertex_t v) {
        g.push_back(v);
    }

    int prim() {
        bool used[g.size()];
        int min_span_cost = 0;
        priority_queue< edge_t, vector<edge_t>, greater<edge_t> > q;

        fill(used, used+g.size(), false);

        used[0] = true;
        for (int i = 0; i < g[0].size(); i++) {
            q.push(g[0][i]);
        }

        while (!q.empty()) {
            edge_t e = q.top(); q.pop();
            if (used[e.to]) continue;
            used[e.to] = true;
            min_span_cost += e.cost;
            for (int i = 0; i < g[e.to].size(); i++) {
                q.push(g[e.to][i]);
            }
        }

        return min_span_cost;
    }

    void dijkstra(int s, vector<int> &min_cost) {
        min_cost.resize(g.size());
        priority_queue< state_t, vector<state_t>, greater<state_t> > q;
        
        fill(min_cost.begin(), min_cost.end(), INF);

        min_cost[s] = 0;
        q.push(state_t(s, 0));

        while (!q.empty()) {
            state_t p = q.top(); q.pop();
            int v = p.v;
            if (min_cost[v] < p.min_cost) continue;
            for (int i = 0; i < g[v].size(); i++) {
                edge_t e = g[v][i];
                if (min_cost[e.to] > min_cost[v] + e.cost)  {
                    min_cost[e.to] = min_cost[v] + e.cost;
                    q.push(state_t(e.to, min_cost[e.to]));
                }
            }
        }
    }
};

int main() {
    int n, m;
    while (cin >> n >> m) {
        if (n == 0 && m == 0) break;
        graph_t graph(n);
        for (int i = 0; i < m; i++) {
            int a, b, cost;
            cin >> a >> b >> cost;
            graph[a].push_back(edge_t(a, b, cost));
            graph[b].push_back(edge_t(b, a, cost));
        }
        cout << graph.prim() << endl;
    }
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  bool can = false;

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (N == i * 4 + j * 7) {
        can = true;
        break;
      }
    }
  }
  if (can == true)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


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

using namespace std;
#define taskname ""
#define pb	push_back
typedef long double ld;
typedef long long ll;
const int maxn = 2e5 + 6;
pair<ll,ll> L[maxn] , H[maxn];
int n , a[maxn];
ll sum[maxn] , rsum[maxn];
void enter()
{
    cin >> n;
    for(int i = 1 ; i <= n ; ++i)cin >> a[i];
    for(int i = 1 ; i <= n ; ++i)sum[i] = sum[i - 1] + a[i];
    for(int i = n ; i >= 1 ; --i)rsum[i] = rsum[i + 1] + a[i];
}
void solve()
{
    int j = 1;
    for(int i = 1 ; i <= n ; ++i)
    {
        while(j < i)
        {
            if(abs(sum[j] - sum[i] + sum[j]) <= abs(sum[j + 1] - sum[i] + sum[j + 1]))
                break;
            ++j;
        }
        L[i] = {sum[j] , sum[i] - sum[j]};
        if(L[i].first < L[i].second)swap(L[i].first,L[i].second);
    }
    j = n;
    for(int i = n ; i >= 1 ; --i)
    {
        while(j > i)
        {
            if(abs(rsum[j] - rsum[i] + rsum[j]) <= abs(rsum[j - 1] - rsum[i] + rsum[j - 1]))
                break;
            --j;
        }
        H[i] = {rsum[j] , rsum[i] - rsum[j]};
        if(H[i].first < H[i].second)swap(H[i].first,H[i].second);
    }
    ll res = LLONG_MAX;
    for(int i = 1; i <= n; ++i)
    {
        ll Max = max(L[i].first , H[i + 1].first);
        ll Min = min(H[i + 1].second , L[i].second);
        res = min(res , Max - Min);
        //cout << Max << " " << Min << endl;
    }
    cout << res;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//freopen(taskname".INP", "r",stdin);
	//freopen(taskname".OUT", "w",stdout);
    enter();
    solve();
}


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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	string s;
	cin >> s;
	int n=s.size();
	int res=0;
	for(int i=0;i<n;i++){
		int j=n-1-i;
		if(j<i) break;
		if(s[i]!=s[j]) res++;
	}
	cout << res << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int x, y, r, temp;
  int count;
  while(1){
    count=1;
    if(scanf("%d %d", &x, &y)!=2) break;
    if(x<y){temp=x; x=y; y=temp;}
    if(x==0 && y==0) break;
    if(y<1)continue;
    while((r=x%y)!= 0){
      x=y;
      y=r;
      count++;
    }
    printf("%d %d\n", y, count);
  }
  return 0;
}

Measured memory_bytes: 600
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
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; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.first+a.second > b.first+b.second; }

int main() {
	SS(ll,n);
	if(n==2){
		SS(ll,a,b);
		p(a+b);
	}else
	{
		p("Hello World");
	}
	
}

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

int main() {
  int N;
  cin >> N;
  vector<vector<int>> V(N, vector<int>(3));
  for (auto &v : V) {
    cin >> v.at(0) >> v.at(1) >> v.at(2);
  }
  vector<vector<int>> DP(N, vector<int>(3));
  DP.at(0) = V.at(0);
  for (int i = 0; i + 1 < N; i++) {
    DP.at(i + 1).at(0) = max(DP.at(i).at(1), DP.at(i).at(2)) + V.at(i + 1).at(0);
    DP.at(i + 1).at(1) = max(DP.at(i).at(0), DP.at(i).at(2)) + V.at(i + 1).at(1);
    DP.at(i + 1).at(2) = max(DP.at(i).at(0), DP.at(i).at(1)) + V.at(i + 1).at(2);
  }
  cout << *max_element(DP.at(N - 1).begin(), DP.at(N - 1).end()) << "\n";
}

Measured memory_bytes: 14060
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
    int a,b,c;
    cin>>a;
    cin>>b;
    cin>>c;
    if(a<=c&&c<=b){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import math

(N, D) = (int(i) for i in input().split())

XY = []
for n in range(N):
    (x, y) = (int(i) for i in input().split())
    XY.append((x, y))

ans = 0
for (x, y) in XY:
    d = math.sqrt(x**2 + y**2)

    if d <= D:
        ans += 1

print(ans)

Measured memory_bytes: 36124
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i < n; i ++)
#define rep1(i, n) for (int i=1; i <= n; i ++)
#define _max(x, y) x = max(x, y)
using namespace std;


static int grid[2005][2005] = {};
static int L[2005][2005] = {};
static int R[2005][2005] = {};
static int D[2005][2005] = {};
static int U[2005][2005] = {};

int main() {
  int H, W;
  cin >> H >> W;

  rep(i, H) {
    string S;
    cin >> S;
    rep(j, W) {
      grid[i][j] = (S[j] == '.' ? 1 : -1);
    }
  }

  rep1(i, H) {
    int _i = H - i + 1;
    rep1(j, W) {
      int _j = W - j + 1;

      if (grid[i - 1][j - 1] != -1) {
        L[i][j] = L[i][j - 1] + 1;
        U[i][j] = U[i - 1][j] + 1;
      }
      if (grid[i - 1][_j - 1] != -1) R[i][_j] = R[i][_j + 1] + 1;
      if (grid[_i - 1][j - 1] != -1) D[_i][j] = D[_i + 1][j] + 1;
    }
  }
  int ans = 0;
  rep1(i, H) rep1(j, W) _max(ans, L[i][j] + R[i][j] + D[i][j] + U[i][j] - 3);
  cout << ans << endl;



  return 0;
}


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

int main(){
  int A,B;  cin >> A >> B;

  int count = 0;

  for(int i = A;i <= B;i++){

    string s = to_string(i);
    bool flag = true;

    for(int j = 0;j < 2;j++){//iは5桁.
      if(s[j] != s[s.size()-1-j])flag = false;
    }

    if(flag)count++;

  }

  cout << count << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define sz(v) (int)(v).size()
using namespace std;
using P = pair<int, int>;
typedef long long ll;
int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	string n;
	cin >> n;
	char last = n[sz(n)-1];
	if (last == '3') cout << "bon" << '\n';
	else if (last == '0' || last == '1' || last == '6' || last == '8') cout << "pon" << '\n';
	else cout << "hon" << '\n';

	return 0;
}

Measured memory_bytes: 3652
n, k = gets.strip.split.map(&:to_i)
as = gets.strip.split.map(&:to_i)

# まず1の場所を探す
i1 = as.index(1)

# 左端
il = [i1 - k + 1, 0].max

# 右端
ir = [i1 + k - 1, n - 1].min

def ceil(p, q)
    p % q == 0 ? p / q : p / q + 1
end

min = 10000000000
(il..i1).each do |left|
    # puts "left = #{left}, min = #{min}"
    if left == 0
        r = ceil(n - k, k - 1) + 1
        min = [r, min].min
        # puts "left = #{left}, new_min = #{min}"
    elsif left + k >= n - 1
        l = ceil(left, k - 1) + 1
        min = [l, min].min
    else
        both = ceil(n - ir, k - 1) + ceil(left, k - 1) + 1
        min = [both, min].min
        # puts "left = #{left}, new_min = #{min}"
    end
end

puts min

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



int main ()
{
    long n,W;
    cin>>n>>W;
    vector<long long>dp(W+1);
    long w,v;
    for (long i = 0; i <n ; ++i){
        cin>>w>>v;
        for (long j = W; j >=w ; --j) {
            dp[j]=max(dp[j-w]+v,dp[j]);
        }
    }
    cout<<dp[W]<<endl;


}


Measured memory_bytes: 1024
from operator import mul
from functools import reduce

N, P = map(int, input().split())
A = list(map(int, input().split()))
cE, cO = 0, 0

for a in A:
    if a % 2 == 0:
        cE += 1
    else:
        cO += 1


# 全て偶数
if cO == 0:
    ans = 2 ** N if P == 0 else 0
    print(ans)
else:
    # 偶数が含まれている
    # ある奇数$k$について考える
    # 残りの奇数がcO-1個，偶数がcE個残っている，この選び方は2 ** (N - 1)通り
    # 選んだ合計がSとする
    # - Sが奇数である: Akを選ぶと全体は偶数，選ばないと全体は奇数
    # - Sが偶数である: Akを選ぶと全体は奇数，選ばないと全体は偶数
    # よってそれぞれの2 ** (N - 1)通りについて，Akを選ぶ・選ばないが1通り存在する
    # print(2 ** (cO - 1) * 2 ** cE)
    print(2 ** (N - 1))

Measured memory_bytes: 38256
#include <iostream>

using namespace std;

int main(){

  long int l, r;
  long int min = 3000;
  cin >> l >> r;

  for(long int i = l; i <= r - 1; i++){
    for(long int j = i + 1; j <= r; j++){
      int tmp = (i * j) % 2019;
      if(tmp < min){
	min = tmp;
      }
      if(min == 0){
	break;
      }
    }
    if(min == 0){
      break;
    }
  }

  cout << min << endl;

  return 0;
}


Measured memory_bytes: 256
import itertools
L = list(input())
sm = ['+','-']
SM = list(itertools.product(sm,repeat=3))

for i,j,k in SM:
    if eval(L[0]+i+L[1]+j+L[2]+k+L[3])==7:
        print(L[0]+i+L[1]+j+L[2]+k+L[3]+'=7')
        exit()

Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N;
bool f(int one, int two, int four) {
  if (one == 0) return true;
  if (two == 0) return one - four <= 1;
  return one-four <= 0;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  int one = 0, two = 0, four = 0;
  rep(i, N) {
    int x;
    cin >> x;
    if (x%4==0) four++;
    else if (x%2==0) two++;
    else one++;
  }
  if (f(one, two, four)) cout << "Yes\n";
  else cout << "No\n";
  return 0;
}


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

int main()
{
  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2];

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

  cout << a[0] + a[1] << endl;


  return 0;

}


Measured memory_bytes: 256
#include<map>
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<fstream>
#include<iostream>
#include<algorithm>
#define re register
#define ll long long
using namespace std;
int n,m;
int main(){
	scanf("%d%d",&n,&m);
	printf("%d",(n-1)*(m-1));
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<set>
#include<map>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const int INF = 2000000000;

    ll N,M;
    ll A[101],B[101],C, X;
    std::string S[200],T[200];
    bool F=true;
    ll ans=0;
int main(){
    ios_base::sync_with_stdio(false);
    cin>>N;
    REP(i,N){cin>>A[i];ans+=A[i];}
    sort(A,A+N);
    DEB(ans)
    ans-=A[N-1]/2;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
# pragma GCC optimize("O3")
# include <bits/stdc++.h>
std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define rcg(s) cout << s;exit(0)
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define all(s) s.begin(),s.end()
# define sz(x) (int)((x).size())
# define int ll
using namespace std;
int gcd(int a, int b)
{
    if(b) return gcd(b,a%b);
    return a;
}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n,a[500];
int dp[500][500];

int32_t main(){_
    //freopen("in","r",stdin);
	cin >> n;
	for(int i = 1;i <= n;i++)
	{
		cin >> a[i];
		a[i] += a[i - 1];
	}
	for(int i = n;i >= 1;i--)
	{
		dp[i][i] = 0;
		for(int j = i + 1;j <= n;j++)
		{
			dp[i][j] = 1e18;
			for(int jj = i;jj < j;jj++)
			{
				dp[i][j] = min(dp[i][j],a[j] - a[i - 1] + dp[i][jj] + dp[jj + 1][j]);
			}
		}
	}
	rc(dp[1][n]);
}

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

#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define ALL(x) (x).begin(), (x).end()

typedef unsigned long long ll;
using namespace std;

const ll MOD = 1000000007;
const ll MAX = 1000000;
vector<ll> fac(MAX, 0ll);
vector<ll> finv(MAX, 0ll);
vector<ll> inv(MAX, 0ll);

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (ll 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;
  // n! / (r!(n-r)!)
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

  ll X, Y, n, m;
  cin >> X >> Y;

  COMinit();

  // 2n + m = X
  // n + 2m = Y
  // <=> m = (2Y - X)/3, n = Y - 2m;
  if ((X + Y) % 3 == 0) {
    m = ((2 * Y - X) / 3);
    n = (Y - 2 * m);
    cout << COM(n + m, m) << endl;
  } else {
    cout << 0 << endl;
    return 0;
  }

  return 0;
}


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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {

            String S, T, U;
            int A, B;

            string line = Console.ReadLine();
            string []strA = line.Split(' ');

            S = strA[0];
            T = strA[1];

            string[] str = Console.ReadLine().Split(' ');
            A = int.Parse(str[0]);
            B = int.Parse(str[1]);

            U = Console.ReadLine();
                        
            if (U == S )
            {
                Console.WriteLine((A - 1) + " " + B);
            }

            else {
                Console.WriteLine(A + " " + (B - 1));
            }
        }
    }
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vll;
typedef vector<pii>		vpii;
typedef vector<pll>		vpll;
typedef vector<vi>		vvi;
typedef vector<vll>		vvl;
const int mod = 1000000007;
const int N = 3e5;
vi g[N];
int a[N];
int mpow(int base, int exp); 
void ipgraph(int n, int m);
void dfs(int u, int par);

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int i,n,k,j;
	cin>>n>>k;
	ll ans = k;
	ans *= pow(k-1, n-1);
	cout<<ans<<endl;
	return 0;
} 

int mpow(int base, int exp) {
	base %= mod;
	int result = 1;
	while (exp > 0) {
	if (exp & 1) result = ((ll)result * base) % mod;
	base = ((ll)base * base) % mod;
	exp >>= 1;
	}
	return result;
}

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
for(int v:g[u]){
	if (v == par) continue;
	dfs(v, u);
}
}

Measured memory_bytes: 7424
# include <iostream>
# include <vector>


using namespace std ;



int main () {
    int n;
    string s[110];
    cin>>n;
    bool ans=true;
    for (int i=0;i<n;i++){
        cin>>s[i];
    }
    for (int j=0;j<n-1;j++){
        if (s[j][s[j].length()-1]!=s[j+1][0]){
            ans=false;
        }
    }
    for (int i=0 ; i<n-1;i++){
        for (int j=i+1 ; j<n;j++){
            if (s[i]==s[j]) ans=false;
        }
    }
    if (ans) {
        cout<<"Yes"<<endl;
    }else{
      	cout<<"No"<<endl;
    }
    return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdlib>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

int main() {
    int n;
    cin >> n;
    vector<int> v(n + 1, 0);
    REP (i, 1, n + 1) cin >> v[i];
    lli sum = 0;
    REP (i, 0, n + 1) {
        sum += (abs(v[i] - v[(i + 1) % (n + 1)]));
    }
    REP (i, 0, n) {
        cout << sum - abs(v[i + 1] - v[i]) - abs(v[(i + 2) % (n + 1)] - v[i + 1]) + abs(v[(i + 2) % (n + 1)] - v[i]) << endl;
    }
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define PI       3.1415926535897932384626433832795028841971
#define INF      5000000000000000000
#define EPS      1e-10
#define MOD      1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll a, b, c, d, e, f, g;

ll ans = 0;

int main(){
    cin >> a >> b >> c >> d >> e >> f >> g;
    ans = b;
    if(a%2 == 0){
        if(d%2 == 0 && e%2 == 0) ans += a+d+e;
        if(d%2 == 1 && e%2 == 0) ans += a+d+e-1;
        if(d%2 == 0 && e%2 == 1) ans += a+d+e-1;
        if(d%2 == 1 && e%2 == 1){
            if(a > 0) ans += a+d+e-1;
            else ans += a+d+e-2;
        }
    } else{
        if(d%2 == 0 && e%2 == 0) ans += a+d+e-1;
        if(d%2 == 1 && e%2 == 0){
            if(e > 0) ans += a+d+e-1;
            else ans += a+d+e-2;
        }
        if(d%2 == 0 && e%2 == 1){
            if(d > 0) ans += a+d+e-1;
            else ans += a+d+e-2;
        }
        if(d%2 == 1 && e%2 == 1) ans += a+d+e;
    }
    cout << ans << endl;
}


Measured memory_bytes: 384