akhauriyash/Code-Regression huggingface dataset:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
kai=sum(b)-sum(a)
if kai<0:
    for i in range(n):
        if a[i]!=b[i]:print("No");exit()
    print("Yes")
else:
    akai=kai
    bkai=kai
    for i in range(n):
        if a[i]==b[i]:continue
        if a[i]>b[i]:
            bkai-=a[i]-b[i]
        else:
            if (b[i]-a[i])%2:
                b[i]+=1
                bkai-=1
            akai-=(b[i]-a[i])//2
        if akai<0 or bkai<0:print("No");exit()
    print("Yes")if bkai==2*akai else print("No")




Measured memory_bytes: 4596
#include <stdio.h>

long long int a[101010];
long long int num[101010];

long long int min(long long int a, long long int b){
    if(a < b) return a;
    else return b;
}

int main(){
    int n; scanf("%d",&n);
    for(int i=0; i<=n; i++) scanf("%lld",&a[i]);
    num[0] = 1;
    for(int i=0; i<=n; i++){
        if(num[i] < a[i]){
            printf("-1\n");
            return 0;
        }
        if(i == n) break;
        num[i] -= a[i];
        num[i+1] = min(1LL<<60, num[i] * 2);
    }
    long long int ans = a[n];
    long long int now = a[n];
    for(int i=n-1; i>=0; i--){
        ans += min(num[i], now) + a[i];
        now += a[i];
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 3296
#include <bits/stdc++.h>
typedef long long lint;
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> count(n);
    for (int i = 1; i < n; i++) {
        int a;
        cin >> a;
        a--;
        count[a]++;
    }
    for (auto e : count) {
        cout << e << endl;
    }
}

Measured memory_bytes: 3996
//#include "pch.h"
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };




signed main() {
	int N, M, sum = 0;

	cin >> N >> M;

	for (int i = 0; i < M; i++) {
		int num;
		cin >> num;
		sum += num;
	}

	N -= sum;

	if (N < 0) {
		cout << -1 << endl;
	}
	else {
		cout << N << endl;
	}

	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define uniq(x) ((x).erase(unique(all(x)),(x).end()))
#define sz(x) ((int)(x).size())

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

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

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


int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N,Q;
  cin >> N >> Q;
  fenwick_tree<ll> fw(N);
  rep(i,N){
    int a;
    cin >> a;
    fw.add(i,a);
  }
  rep(_,Q){
    int q;
    cin >> q;
    if(q==0){
      int p,x;
      cin >> p >> x;
      fw.add(p,x);
    }
    else if(q==1){
      int l,r;
      cin >> l >> r;
      cout << fw.sum(l,r) << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 8244
from fractions import gcd

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

forward = []
backward = [0 for x in range(n)]

if n == 2:
    print(max(a[0], a[1]))
    exit(0)

for i in range(n):
    if i == 0:
        forward.append(a[i])
    else:
        forward.append(gcd(forward[i - 1], a[i]))


for i in range(n - 1, -1, -1):
    if i == n - 1:
        backward[i] = a[i]
    else:
        backward[i] = gcd(backward[i + 1], a[i])


ans = 1

for i in range(n):
    if i == 0:
        ans = max(ans, backward[1])
    elif i == n - 1:
        ans = max(ans, forward[n - 2])
    else:
        ans = max(ans, gcd(forward[i - 1], backward[i + 1]))

print(ans)


Measured memory_bytes: 16152
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
using int_vec = vector<long>;

void print(const int_vec& v) {
    int_vec::const_iterator it;
    for (it = v.begin(); it != v.end()-1; ++it) {
        cout << *it << " ";
    }
    cout << *it << endl;
}


int insertion_sort(int_vec& v, int g) {
    int count = 0;
    for (int i = g; i < v.size(); ++i) {
        auto x = v[i];
        int j = i - g;
        for (; j >= 0 && v[j] > x; j -= g) {
            v[j+g] = v[j];
            ++count;
        }
        v[j+g] = x;
    }
    return count;
}

int shell_sort(int_vec& v) {
    int_vec G;
    for (int i = 1; i <= v.size(); i = i * 3 + 1) {
        G.push_back(i);
    }
    reverse(G.begin(), G.end());
    cout << G.size() << endl;
    print(G);

    int count = 0;
    for (auto it = G.begin(); it != G.end(); ++it) {
        count += insertion_sort(v, *it);
    }
    return count;
}

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

    int_vec v;
    for (int i = 0; i < n; ++i) {
        long x;
        cin >> x;
        v.push_back(x);
    }

    auto c = shell_sort(v);
    cout << c << endl;
    // cerr << "debug:" << v.size() << endl;
    for (auto it = v.begin(); it != v.end(); ++it) {
        cout << *it << endl;
    }

    return 0;
}

Measured memory_bytes: 11148
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

queue<pair<int, string>> que;

int main()
{
    int n, q, t = 0;
    cin >> n >> q;
    for (int i = 0; i < n; i++)
    {
        string s;
        int a;
        cin >> s >> a;
        pair<int, string> p = make_pair(a, s);
        que.push(p);
    }
    while (que.size())
    {
        pair<int, string> p = que.front();
        que.pop();
        if (p.first <= q)
        {
            t += p.first;
            cout << p.second << " " << t << endl;
            ;
        }
        else
        {
            t += q;
            auto k = make_pair(p.first - q, p.second);
            que.push(k);
        }
    }
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }

typedef tuple<int, int, int> ti3;
double p[305][305][305], l[305][305][305];

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n; cin >> n;
	int c1 = 0, c2 = 0, c3 = 0;
	rep(i, 0, n) {
		int t; cin >> t;
		if (t == 1) c1++;
		else if (t == 2) c2++;
		else if (t == 3) c3++;
		else exit(1);
	}

	l[c1][c2][c3] = 0.;
	p[c1][c2][c3] = 1.;

	int maxsum = c1 + c2 * 2 + c3 * 3;

	for (int sum = maxsum; sum > 0; sum--) {
		for (int v1 = 0; v1 <= n; v1++) {
			for (int v2 = 0; v1 + v2 <= n; v2++) {
				int v3 = sum - v1 - v2 * 2;
				if (v3 % 3 != 0 || v3 < 0) continue;
				v3 /= 3;
				
				//printf("%d %d %d: L = %.4lf, P = %.4lf\n", v1, v2, v3, l[v1][v2][v3], p[v1][v2][v3]);
				
				if (p[v1][v2][v3] == 0.) continue;

				// fix accumulation
				l[v1][v2][v3] /= p[v1][v2][v3];
				int cs = v1 + v2 + v3;
				double dl = l[v1][v2][v3] + 1.0 * n / cs;
			
				//printf("  CS = %d\n", cs);

				if (v3) {
					double np = p[v1][v2][v3] * v3 / cs;
					//printf("--> %d %d %d P = %.4lf\n", v1, v2 + 1, v3 - 1, np);
					l[v1][v2 + 1][v3 - 1] += dl * np;
					p[v1][v2 + 1][v3 - 1] += np;
				}
				if (v2) {
					double np = p[v1][v2][v3] * v2 / cs;
					//printf("--> %d %d %d P = %.4lf * %.4lf = %.4lf\n", v1 + 1, v2 - 1, v3, p[v1][v2][v3], np);
					l[v1 + 1][v2 - 1][v3] += dl * np;
					p[v1 + 1][v2 - 1][v3] += np;
				}
				if (v1) {
					double np = p[v1][v2][v3] * v1 / cs;
					//printf("--> %d %d %d P = %.4lf\n", v1 - 1, v2, v3, np);
					l[v1 - 1][v2][v3] += dl * np;
					p[v1 - 1][v2][v3] += np;
				}
			}
		}
	}

	cout << fixed << setprecision(15);
	die(l[0][0][0]);
}


Measured memory_bytes: 438528
N=int(input())
e=[0]*(N+1)
for i in range(2,N+1):
    cur=i
    for j in range(2,i+1):
        while cur%j==0:
            e[j]+=1
            cur//=j
def num(m):return len(list(filter(lambda x:x>=m-1,e)))
print(num(75)+num(25)*(num(3)-1)+num(15)*(num(5)-1)+num(5)*(num(5)-1)*(num(3)-2)//2)

Measured memory_bytes: 3064
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
//#define int long long int
using namespace std;


int main(){
    ll N,M; cin>>N>>M;
    multiset <ll> A;
    for(int i=0;i<N;i++) {ll a; cin>>a; A.insert(a);}
 

    for(int i=0;i<M;i++){
        auto dis = A.end();
        dis--;
        ll value = *dis/2;
        A.erase(dis);
        A.insert(value);
    }

    ll ans = 0;

    for(auto itr = A.begin();itr != A.end();itr++){
        ans += *itr;
    }

    cout<<ans<<endl;


    return 0 ;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  int index =1;
  int sum = 1000000;
  while (index < n/2+1){
      int a, b;
      a = index;
      b = n-index;
      int sumA, sumB;
      sumA=0;
      sumB=0;
      while (true) {
          if (a==0){
              break;
          }
          sumA+=a%10;
          a /=10;
      }
      while (true) {
          if (b==0){
              break;
          }
          sumB+=b%10;
          b /=10;
      }
      if (sumA+sumB < sum){
          sum=sumA+sumB;
      }
      index++;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
n = int(input())
s ={}
for i in range(n):
    string = input()
    s[string] = s[string] + 1 if string in s else 1 
m = int(input())
for i in range(m):
    string = input()
    s[string] = s[string] - 1 if string in s else -1
print(max(0,max(s.values())))

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

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

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; }

typedef long long ll;
typedef pair<int, int> P;

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

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

    cout << a + a * a + a * a * a << endl;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  vi32 v;
  int cnt = 0;
  char prev = '1';
  rep(i, n) {
    if (s[i] != prev) {
      v.push_back(cnt);
      cnt = 1;
      prev = s[i];
    } else {
      cnt++;
    }
  }
  v.push_back(cnt);
  if (s[n - 1] == '0') v.push_back(0);
  vi32 sums(v.size() + 1);
  partial_sum(all(v), sums.begin() + 1);
  i32 ans = 0;
  for (int i = 0; i < v.size(); i += 2) {
    int r = min((int) v.size(), i + 2 * k + 1);
    amax(ans, sums[r] - sums[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1272
#include<iostream>
using namespace std;
int main(){
	int a, b, c,tmp;
	cin >> a >> b >> c;

	if (a > b){
		tmp = a;
		a = b;
		b = tmp;
	}

	if (b > c){
		tmp = b;
		b = c;
		c = tmp;

	}
	
	if (a > b){
		tmp = a;
		a = b;
		b = tmp;
	}

	cout << a << ' ' << b << ' ' << c << endl;

	return 0;
}



Measured memory_bytes: 3072
import sys
from heapq import heappush, heappop

n, m = list(map(int, input().split()))
works = []
for line in sys.stdin:
    a, b = map(int, line.split())
    if a > m:
        continue
    works.append((a, b))

works.sort(reverse=True)

q = []
ans = 0
for i in range(1, m + 1):
    while works and works[-1][0] <= i:
        a, b = works.pop()
        heappush(q, -b)
    # print(q)
    if q:
        b = -heappop(q)
        ans += b
print(ans)


Measured memory_bytes: 17212
X, Y = map(int, input().split())
X, Y = max(X,Y), min(X,Y)

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

N = 10**6

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

def test(X, Y):
  if ((X+Y)%3 != 0):
    return 0
  if not(X <= 2*Y <= 4*X):
    return 0
  n = (X+Y)//3
  r = X - n
  return cmb(n,r,mod)

print(test(X,Y))

Measured memory_bytes: 121992
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;

int main(int argc, char const *argv[]) {
  int N;
  cin >> N;
  int a[N];
  for(int i = 0; i < N; i++){
    cin >> a[i];
  }
  sort(a, a+N);
  long ans = 10000000000;
  for(int i = a[0]; i <= a[N-1]; i++){
    long cand = 0;
    for(int j = 0; j < N; j++){
      cand += (a[j] - i) * (a[j] - i);
    }
    if(cand < ans) ans = cand;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import sys
import math
a,b,h,m = map(int, input().split())
h_rad=h*30+30*(m/60)
m_rad=m*6
if abs(h_rad-m_rad)>180:
    g=360-abs(h_rad-m_rad)
else:
    g=abs(h_rad-m_rad)


cosg=math.cos(math.radians(g))
C=a*a+b*b-2*a*b*cosg
c=math.sqrt(C)

print(c)

Measured memory_bytes: 9448
N = int(input())
A = [(a, i) for i, a in enumerate(map(int, input().split()))]
A.sort(reverse=True)
A.append((0, 0))

ans = [0] * N
now = float('inf')

for j, (a, i) in enumerate(A[:N], start=1):
    now = min(now, i)
    ans[now] += j * (a - A[j][0])

print(*ans, sep='\n')


Measured memory_bytes: 24140
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    string S;
    cin >> S;
    
    int ans = S.size();
    for (int i = 0; i < 2; i++){
        int cnt = 0;
        for (int j = 0; j < S.size(); j++){
            if (j % 2 == 0 && S[j] != (char)(i + '0')) cnt++;
            if (j % 2 != 0 && S[j] == (char)(i + '0')) cnt++;
        }
        ans = min(ans, cnt);
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>

using namespace std;
typedef long long ll;
const int maxn = 100005;



int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "w", stdout);
#endif
  int n,x,y;
  cin>>n>>x>>y;
  int t = x + y;
  cout<<min(x,y)<<" "<<(t>n?t-n:0)<<endl;
  return 0;
}

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

int main()
{
    long long  a,b,c,d,m,n,s,t;
    cin>>a>>b>>c>>d;
    m=a*d;
    n=a*c;
    s=b*c;
    t=b*d;
   // cout<<n<<endl;
    cout<<max(m,max(n,max(s,t)))<<endl;
    return 0;
}


Measured memory_bytes: 3640
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	int		a,b,c,i,j,k,n,m,x,y,ans = 0;

	cin >> n;
	vector<vector<int>> cnt(10,vector<int>(10));
	for(i=1;i<=n;i++) {
		x = i%10;
		y = i;
		while(y>=10) y /= 10;
		cnt[x][y]++;
	}
	for(i=1;i<=9;i++) {
		for(j=1;j<=9;j++) {
			ans += cnt[i][j]*cnt[j][i];
		}
	}
	cout << ans << endl;
	return 0;
}


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

public class Main {

  static int n;
  static int[] a, b;
  static final int INF = 200000000;
  
  public static void main(String[] args) throws Exception {
    
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    String[] in = br.readLine().split(" ");
    n = Integer.parseInt(in[0]);

    int[][] g = new int[n][n];

    for(int i = 0; i < n; i++){
      in = br.readLine().split(" ");
      for(int j = 0; j < n; j++){
        g[i][j] = Integer.parseInt(in[j+1]);
      }
    }
    
    br.close();

    int ans = 0;

    int[] cost = new int[n];
    Arrays.fill(cost, INF);

    cost[0] = 0;

    for(int i = 0; i < n; i++){
      int minCost = INF;
      int minCostIdx = -1;
      for(int j = 0; j < n; j++){
        if(cost[j] == -1) continue;
        if(cost[j] < minCost) {
          minCost = cost[j];
          minCostIdx = j;
        }
      }

      ans += cost[minCostIdx];

      for(int j = 0; j < n; j++){
        if(g[minCostIdx][j] == -1 || cost[j] == -1) continue;
        cost[j] = Math.min(g[minCostIdx][j], cost[j]);
      }

      cost[minCostIdx] = -1;

    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 27176
#include<stdio.h>
#include<string.h>
main()
{
	int w=0,x=0,p=0,len,i,y=0,z=0,cnt=0,c,cex=0;
	char s[10000];
	scanf("%s",s);
	len=strlen(s);
	if(s[0]=='A')
	{
		w=1;
	}
	for(i=2;i<len-1;i++)
	{
		if(s[i]>='A' && s[i]<='Z')
		{
			cnt++;
			c=i;
		}
	}

	if(cnt==1 && s[c]=='C')
	{
		x=1;
	}
	if(s[len-1]=='C' || (s[len-1]>='a' && s[len-1] <='z'))
	{
		y=1;
	}
	for(i=1;i<len-1;i++)
	{
		if(i!=c){
		if(s[i]>='a' && s[i]<='z' )
		{
			z=1;
		}
		else if(s[i]<'a' || s[i]>'z'){
		break;}}
	}
	if(w==1 && x==1 && y==1 && z==1)
	{
		printf("AC\n");
	}
	else printf("WA\n");
	
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define M 1000000007
#define all(a) (a).begin(),(a).end()
#define rep(i,n) reps(i,0,n)
#define reps(i,m,n) for(int i=(m);i<(n);i++)
int main(){
  ll n,k;cin>>n>>k;
  if(n%k==0){
    cout<<0;return 0;
  }
  ll m=abs(n-n/k*k);
  cout<<min(m,abs(m-k));
}

Measured memory_bytes: 256
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))

from random import randrange
from itertools import accumulate
from bisect import bisect_left
import time
#%%code

def calc(LIST):
    ans=0
    last=[0]*26
    for i in range(len(LIST)):
        a=i+1 #day a0
        x=LIST[i]-1
        #increase
        ans+=S[i][x]
        #decrease
        last[x]=a#update
        temp=0
        for j in range(26):
            temp+=C[j]*(a-last[j])
        #print(ans,temp,"deb")
        ans-=temp
        #print(ans)

    return ans

def answerer(c):
    """
    #方針その2
    最初にですが乱択をします。ただし、CとDの積に応じてあたりやすさをでかくします
    """
    acc=list(accumulate(c))
    ret=[]
    for d in range(D):
        acc=list(accumulate(c))
        miru=[]
        for i in range(len(c)):
            miru.append(acc[i]+S[d][i])
        temp=randrange(0,miru[-1])
        s=bisect_left(miru,temp)
        ret.append(s+1)

        #print(s+1)
    return ret

def resolve():
    global D,C,S
    #input of prob.A
    D,=pin()
    C=[*pin()]#0-indexed
    S=[[*pin()]for i in range(D)]
    answerer(C)


    ##print(acc)
    start=time.time()
    king=[1]*365
    max_score=calc(king)
    #print(max_score)

    while(time.time()-start<1.8):
        temp=answerer(C)
        challenge=calc(temp)
        if challenge>max_score:
            max_score=challenge
            king=temp[:]
        ##print(king,max_score)

    #assert len(king)==D
    print(*king,sep="\n")
    #print(max_score)
#%%submit!
resolve()

Measured memory_bytes: 85772
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const ll INF = LLONG_MAX/3;

ll solve(int n, int w){
    vector<ll> a(n);
    rep(i,n) scanf(" %lld", &a[i]);

    vector<ll> dp(n+1,INF);
    dp[0] = 0;
    rep(i,n){
        ll s = 0;
        for(int j=i; j<n; ++j){
            s += a[j];

            ll cost = abs(s-w);
            if(j==n-1) cost = max(0LL, s-w);

            dp[j+1] = min(dp[j+1], dp[i]+cost);
        }
    }
    return dp[n];
}

int main(){
    int C = 1;
    int n,w;
    while(scanf(" %d %d", &n, &w),n){
        printf("Case %lld: %d\n", C++, solve(n,w));
    }
    return 0;
}



Measured memory_bytes: 3168
#include<stdio.h>
#include<string.h>

#define N 3
#define LIM 32
#define HN 362897

struct dep{
  int depth,key;
};

int ans[N][N]={
  {1,2,3},
  {4,5,6},
  {7,8,0}
};

int min = LIM;
struct dep h[HN];

int hash1(int k)
{
  return k % HN;
}
int hash2(int k)
{
  return 1 + k%(HN-1);
}
int hash(int k, int i)
{
  return (hash1(k) + i*hash2(k))%HN;
}


void dfs(int p[N][N], int n)
{
  int i,j,i0,j0,a=0,b=1;
  int f=0;
  int tmp[N][N];
  for(i=0;i<N;i++)
  {
    for(j=0;j<N;j++)
    {
      if(ans[i][j]!=p[i][j])f++;
      if(p[i][j]==0)
      {
        i0=i;
        j0=j;
      }
      a+=p[i][j]*b;
      b*=10;
    }
  }

  if(f==0)
  {
    if(min>=n)
    {
      min=n;
    }
    return;
  }
  if(n>min) return;
  i=0;
  while(1)
  {
    b=hash(a, i);
    if(h[b].key == 0)
    {
      h[b].key=a;
      h[b].depth=n;
      break;
    }
    else if(h[b].key == a)
    {
      if(h[b].depth>n)
      {
        h[b].depth=n;
        break;
      }
      else return;
    }
    i++;
  }

  if(i0>0 && i0<N)
  {
    memcpy(tmp,p,sizeof(int)*N*N);
    f=tmp[i0][j0];
    tmp[i0][j0]=tmp[i0-1][j0];
    tmp[i0-1][j0]=f;
    dfs(tmp, n+1);
  }
  if(j0>0 && j0<N)
  {
    memcpy(tmp,p,sizeof(int)*N*N);
    f=tmp[i0][j0];
    tmp[i0][j0]=tmp[i0][j0-1];
    tmp[i0][j0-1]=f;
    dfs(tmp, n+1);
  }

  if(i0>=0 && i0<N-1)
  {
    memcpy(tmp,p,sizeof(int)*N*N);
    f=tmp[i0][j0];
    tmp[i0][j0]=tmp[i0+1][j0];
    tmp[i0+1][j0]=f;
    dfs(tmp, n+1);
  }
  if(j0>=0 && j0<N-1)
  {
    memcpy(tmp,p,sizeof(int)*N*N);
    f=tmp[i0][j0];
    tmp[i0][j0]=tmp[i0][j0+1];
    tmp[i0][j0+1]=f;
    dfs(tmp, n+1);
  }

}

int main()
{
  int i,j;
  int A[N][N];

  for(i=0;i<N;i++)
  {
    for(j=0;j<N;j++)
    {
      scanf("%d",&A[i][j]);
    }
  }
  dfs(A,0);

  printf("%d\n",min);

  return 0;
}



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

using namespace std;

int main() {
  int n; cin >> n;
  vector<long long> a(n);
  long long sum=0;
  for(int i=0;i<n;++i) cin >> a[i],sum+=a[i];
  long long tmp=a[0]; sum-=a[0];
  long long ans=abs(sum-tmp);
  for(int i=1;i<n-1;++i){
    tmp+=a[i]; sum-=a[i];
    ans=min(ans,abs(sum-tmp));
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main(){
    string str;
    cin >> str;
    map<char, int> m;
    for(char c: str){
        m[c]++;
    }
    if(m.size() == 1) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
bool check(ll n,ll pos)
{
    return n & (1ll<<pos);
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    ll n,k;
    ll bits[50];
    ll one[50]= {0};
    ll zero[50]= {0};
    bits[0]=1;
    ll sum=0;
    for(int i=1; i<=42; i++)
    {
        bits[i]=bits[i-1]*2ll;
    }
    cin>>n>>k;
    vector<ll>v;
    int lim=0;
    for(int i=0; i<n; i++)
    {
        ll a;
        cin>>a;
        v.push_back(a);
        sum+=a;
        for(int i=0; i<=40; i++)
        {
            if(check(a,i))
            {
                one[i]++;
                lim=max(lim,i);
            }
        }
    }
    for(int i=0; i<=40; i++)
    {
        zero[i]=n-one[i];
    }
    ll mx=sum,cur_k=k;
    for(int i=40; i>=0; i--)
    {
        if(zero[i] && cur_k>=bits[i])
        {
            ll x=sum-(one[i]*bits[i]);
            x+=(zero[i]*bits[i]);
            if(x>mx)
            {
                mx=x;
                sum=x;
                cur_k-=bits[i];
            }
        }
    }
    cout<<sum<<endl;


    return 0;
}


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

using namespace std;

struct input{input(){ios::sync_with_stdio(false);cin.tie(0);}}init;
#define rep(i,n) for(auto i=(n)*0;i<n;i++)
namespace _UF{
    #define SZ 500000
    int mem[2][SZ];
}
class UnionFind{
private:
    int *par,*rank;
    int find(int x){
	if(par[x]==x)return x;
	else return par[x]=find(par[x]);
    }
public:
    UnionFind(int n):par(_UF::mem[0]),rank(_UF::mem[1]){
	rep(i,n)par[i]=i,rank[i]=0;
    }
    bool unite(int x,int y){
	x=find(x);
	y=find(y);
	if(x==y)return false;
	if(rank[x]<rank[y])par[x]=y;
	else{
	    par[y]=x;
	    if(rank[x]==rank[y])rank[x]++;
	}
	return true;
    }
    bool same(int x,int y){
	return find(x)==find(y);
    }
};

int main(){
    int N,C,R;
    cin>>N>>C>>R;
    map<int,int> rs,cs;
    int bottom=1;
    int res=0;
    UnionFind uf(N);
    rep(i,N){
	int r,c;
	cin>>c>>r;
	if(rs.count(r))
	    res+=uf.unite(rs[r],i);
	else rs[r]=i;
	if(cs.count(c))
	    res+=uf.unite(cs[c],i);
	else cs[c]=i;
	bottom=min({bottom,r-1,c-1,R-r,C-c});
    }
    if(res==N-1)cout<<res<<endl;
    else{
	res+=(bottom>0);
	rep(i,N)
	    if(!uf.same(0,i)){
		res+=2;
		uf.unite(0,i);
	    }
	cout<<res<<endl;
    }
    return 0;
}

Measured memory_bytes: 6532
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main() {
	char W[11];
	char T[1000];
	char reader[1000];
	int cnt = 0;
	int flag = 0, lenflag = 1;
	scanf("%s", W);
	while (1) {
		scanf("%s", T);
		if (!strcmp(T, "END_OF_TEXT"))break;
		for (unsigned int i = 0; i < strlen(T); i++) {
			if (65 <= T[i] && 90 >= T[i]) {
				reader[i] = T[i] + 32;
			}
			else if (97 <= T[i] && 122 >= T[i]) {
				reader[i] = T[i];
			}
			if (i == strlen(W))lenflag = 0;
		}
		for (unsigned int i = 0; i < strlen(T); i++) {
			if (W[i] != reader[i]) {
				flag = 0;
				break;
			}
			if (i == strlen(W) - 1) {
				flag = 1;
				break;
			}
		}
		if (flag&&lenflag) cnt++;
		flag = 0; lenflag = 1;
		for (unsigned int i = 0; i<strlen(T); i++) {
			reader[i] = -52;
		}
	}
	printf("%d\n", cnt);
	return 0;
}


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

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

	int length;
	vector<string> words;

	cin >> length;
	string str;
	while (cin >> str) {
		words.push_back(str);
	}

	bool isFailed = false;
	bool isFirst = true;
	string last = "";
	for (int i = 0; i < length; ++i) {
		bool isExist = false;
		for (int j = 0; j < length; ++j) {
			if (i != j && words[j] == words[i]) {
				isExist = true;
				break;
			}
		}

		if (!isFirst && (isExist || last != words[i].substr(0, 1))) {
			isFailed = true;
			break;
		}
		isFirst = false;
		last = words[i].substr(words[i].size() - 1);
	}

	if (isFailed) {
		cout << "No\n";
	}
	else {
		cout << "Yes\n";
	}

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node {
  int l,p,r;
};
  struct Node A[MAX];
int n;

void pre(int x){
  if(x==NIL)return;
  printf(" %d",x);
  pre(A[x].l);
  pre(A[x].r);
}

void in(int x){
  if(x==NIL)return;
  in(A[x].l);
  printf(" %d",x);
  in(A[x].r);
}

void post(int x){
  if(x==NIL)return;
  post(A[x].l);
  post(A[x].r);
  printf(" %d",x);
}

int main(){
  int i,v,l,r,root;

  scanf("%d",&n);

  for(i=0;i<n;i++)
    {
      A[i].p=NIL;
    }

  for(i=0;i<n;i++){
    scanf("%d %d %d",&v,&l,&r);
    A[v].l=l;
    A[v].r=r;
    if(l!=NIL)A[l].p=v;
    if(r!=NIL)A[r].p=v;
  }
  for(i=0;i<n;i++){
    if(A[i].p==NIL)root=i;
  }

 printf("Preorder\n");
  pre(root);
  printf("\n");
  printf("Inorder\n");
  in(root);
  printf("\n");
  printf("Postorder\n");
  post(root);
  printf("\n");

  return 0;
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,M;
    cin >> N >> M;
    vector<int> A(N);
    int sum = 0;
    for(int i=0; i<N; i++){
        cin >> A[i];
        sum += A[i];
    }
    int cnt = 0;
    for(int i=0; i<N; i++){
        if(sum <= A[i]*4*M){
            cnt++;
        }
    }
    if(cnt >= M){
        cout << "Yes" << endl;
    }else{
        cout <<"No" << endl;
    }
    return 0;
}

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

using namespace std;

pair<int, int> a[1000];

int main() {
  int n; cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i].first >> a[i].second;
    if (i >= 3) {
      bool check = 1;
      for (int j = i-2; j <= i; ++j)
        if (a[j].first != a[j].second)
          check = 0;
      if (check) {
        cout << "Yes";
        return 0;
      }
    }
  }
  cout << "No";
  return 0;
}

Measured memory_bytes: 3472
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'a' = 97

int main()
{
    int x;
    int i = 1;
    while(1) {
        cin >> x;
        if (x != 0) {
            cout << "Case " << i << ": " << x << endl;
            i++;
        } else break;
    }

}



Measured memory_bytes: 3016
#ifndef CLASS_MODINT
#define CLASS_MODINT

#include <cstdint>

template <std::uint32_t mod>
class modint {
private:
	std::uint32_t n;
public:
	modint() : n(0) {};
	modint(std::int64_t n_) : n((n_ >= 0 ? n_ : mod - (-n_) % mod) % mod) {};
	static constexpr std::uint32_t get_mod() { return mod; }
	std::uint32_t get() const { return n; }
	bool operator==(const modint& m) const { return n == m.n; }
	bool operator!=(const modint& m) const { return n != m.n; }
	modint& operator+=(const modint& m) { n += m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator-=(const modint& m) { n += mod - m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator*=(const modint& m) { n = std::uint64_t(n) * m.n % mod; return *this; }
	modint operator+(const modint& m) const { return modint(*this) += m; }
	modint operator-(const modint& m) const { return modint(*this) -= m; }
	modint operator*(const modint& m) const { return modint(*this) *= m; }
	modint inv() const { return (*this).pow(mod - 2); }
	modint pow(std::uint64_t b) const {
		modint ans = 1, m = modint(*this);
		while (b) {
			if (b & 1) ans *= m;
			m *= m;
			b >>= 1;
		}
		return ans;
	}
};

#endif // CLASS_MODINT

#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	string S;
	cin >> S;
	vector<int> c(26);
	for (char ch : S) {
		++c[ch - 'a'];
	}
	int mx = *max_element(c.begin(), c.end());
	cout << (mx * 3 - 2 <= S.size() ? "YES" : "NO") << endl;
	return 0;
}

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

const int N = 105;
const int C = 100005;

int n, cap, w[N], v[N];
long long dp[N][C];

void go(int x, int y) {
	int u = y + v[x + 1];
	if (dp[x + 1][y] == -1) {
		dp[x + 1][y] = dp[x][y];
	} else {
		dp[x + 1][y] = min(dp[x + 1][y], dp[x][y]);
	}
	if (u > 100000) return;
	if (dp[x + 1][u] == -1) dp[x + 1][u] = dp[x][y] + w[x + 1];
	else dp[x + 1][u] = min(dp[x + 1][u], dp[x][y] + w[x + 1]);
}

int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> cap;
	for (int i = 1; i <= n; i++) {
		cin >> w[i] >> v[i];
	}
	memset(dp, -1, sizeof(dp));
	dp[0][0] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= 100000; j++) {
			if (dp[i][j] != -1) go(i, j);
		}
	}
	for (int i = 100000; i >= 0; i--) {
		if (dp[n][i] <= cap && dp[n][i] != -1) return cout << i, 0;
	}
	return 0;
}


Measured memory_bytes: 82304
#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i+=1)
#define reps(i,a,b) for(int i=a;i>=b;i-=1)
#define vi vector<int>
#define pb push_back
#define in(x) int x; cin>>x;
#define inn(x, y) int x, y; cin>>x>>y;
#define mi unordered_map<int,int>
#define mem(x) memset(x, 0, sizeof(x))
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
using namespace std;

//bool primes[1000001];vi prime;
//void seive(){memset(primes, true, sizeof(primes));primes[0] = primes[1] = false;for(int i = 2; i*i<=1000000;i += 1){
//if(primes[i]){for(int j = i*i; j <= 1000000;j += i) primes[j] = false;}}rep(i, 2, 1000001){if(primes[i]) prime.pb(i);}}

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

int32_t main(void){
	IOS;
	
	double r;
	cin>>r;
	double ans = (2.00*(22.0/7.0)*r);
	cout<<fixed<<setprecision(2)<<ans;
}


Measured memory_bytes: 3788
n = int(input())
abc = []
abc.append(int(input()))
abc.append(int(input()))
abc.append(int(input()))
abc.append(int(input()))
abc.append(int(input()))

# abcdeのうち、スタート側にあり最小の数値とその位置を求める
min_num, min_index = abc[4], 4

for i in [3,2,1,0]:
  if abc[i] <= min_num:
    min_num, min_index = abc[i], i
    
# 最小の数値で何回に分けて乗せるか
min_nums = n // min_num if n % min_num == 0 else n // min_num + 1

# 最小の位置までの距離＋何回に分けて乗せるか＋最小の位置からの距離
print(min_nums + 4)


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

using namespace std;

void hawawa(){
  int c[3][3];
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> c[i][j];
    }
  }
  int a[3] = { c[0][0], c[1][0], c[2][0] };
  int b[3] = { 0, c[0][1] - a[0], c[0][2] - a[0] };
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      if (a[i] + b[j] != c[i][j]) {
        cout << "No\n";
        return;
      }
    }
  }
  cout << "Yes\n";
}

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

Measured memory_bytes: 256
N = int(input())
box = []
for i in range(N):
    temp = int(input())
    box.append([])
    for _ in range(temp):
        box[i].append(list(map(int, input().split())))


ans = 0


# bit全探索
for i in range(2 ** N):
    temp = [True for _ in range(N)]
    flg = True
    for j in range(N):
        if ((i >> j) & 1):
            temp[j] = True
                
        else:
            temp[j] = False
        
    for nn, n in enumerate(temp):
        if n:
            for l, m in box[nn]:
                if m == 0:
                    if temp[l-1]:
                        flg = False
                        break
                else:
                    if not temp[l-1]:
                        flg = False
                        break
            
    if flg:
        ans = max(ans, temp.count(True))

print(ans)




Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
 
## Library
 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy
 
## input
 
# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
#    S = []
#    for _ in range(N):
#        S.append(list(input()))
 
N,D=map(int, input().split())
P = [list(map(int,input().split())) for i in range(N)]


ans = 0

for i in range(N):
    if math.sqrt(P[i][0]**2+P[i][1]**2) <= D:
        ans += 1

print(ans)

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

int main() {
    int N;
    cin >> N;
    vl A(N);
    rep(i, N) {
        cin >> A[i];
    }

    int cnt1 = 0;
    int cnt2 = 0;
    int cnt4 = 0;
    rep(i, N) {
        if (A[i] % 4 == 0) {
            cnt4++;
        } else if (A[i] % 2 == 0) {
            cnt2++;
        } else {
            cnt1++;
        }
    }

    if (cnt2 >= 1) {
        cnt1++;
    }

    if (cnt4 >= cnt1 - 1) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3984
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = int;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
ll n,k,ans=0;
void solve_dp(const vector<ll> &a,vector<vector<bool>> &dp){
  dp[0][0] = true;
  for(int i=0;i<n;i++){
    for(int j=0;j<k;j++){
      dp[i+1][j] = dp[i+1][j] | dp[i][j];
      int x = min(k,j+a[i]);
      if(x<k){
        dp[i+1][x] = dp[i+1][x] | dp[i][j];
      }
    }
  }
}
signed main(){
  init_io();
  cin >> n >> k;
  vector<ll> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  const ll INF = 2e9;
  vector<vector<bool>> dp1(n+1,vector<bool>(k+1,false));
  vector<vector<bool>> dp2(n+1,vector<bool>(k+1,false));
  vector<ll> d1,d2;
  solve_dp(a,dp1);
  reverse(a.begin(),a.end());
  solve_dp(a,dp2);
  for(int i=0;i<n;i++){
    bool no_need = true;
    for(int j=0;j<k;j++){
      if(dp1[n-1-i][j]){
        //cout << j<<" a"<<endl;
        d1.push_back(j);
      }
      if(dp2[i][j]){
       // cout << j<<" b"<<endl;
        d2.push_back(j);
      }
    }
    d2.push_back(INF);
    for(auto j:d1){
      ll mi = max(0,k-a[i]-j);
      auto itr = lower_bound(d2.begin(),d2.end(),mi);
      if(*itr+j<k){
        no_need = false;
      }
    }
    if(no_need){
      ans++;
    }
    d1.clear();
    d2.clear();
  }
  cout << ans << endl;
}


Measured memory_bytes: 8960
#include <iostream>

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

    if((N%10==2)||(N%10==4)||(N%10==5)||(N%10==7)||(N%10==9))
    {
        std::cout << "hon" << std::endl;
    }

    else if((N%10==0)||(N%10==1)||(N%10==6)||(N%10==8))
    {
        std::cout<<"pon"<<std::endl;
    }
    
    else
    {
        std::cout<<"bon"<<std::endl;
    }
}

Measured memory_bytes: 3600
a = []
for _ in range(3):
    a.extend(list(map(int, input().split())))

n = int(input())
b = []
for _ in range(n):
    b.append(int(input()))

marked = [False]*9
for i in b:
    for ind, num in enumerate(a):
        if i==num:
            marked[ind] = True
            break

bingos = [
    (0,1), (3,1), (6,1), (0,3), (1,3), (2,3), (0,4), (2,2)
]

for start, step in bingos:
    for i in range(start, start+3*step, step):
        if not marked[i]:
            break
    else:
        print('Yes')
        break
else:
    print('No')


Measured memory_bytes: 3188
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String n = br.readLine();

		String[] x = br.readLine().split(" ");

		String[] y = br.readLine().split(" ");

		Double p =0.0;

		Double p1 = 0.0 ;

		Double p2 = 0.0 ;

		Double p3 = 0.0;

		Double max = 0.0;



		for(int i= 0; i<Integer.parseInt(n); i++){

			p = Math.abs(Double.parseDouble(x[i])-Double.parseDouble(y[i]));

			p1 +=p;

			p2 += Math.pow(p, 2);

			p3 += Math.pow(p, 3);

			max = Math.max(max, p);

		}

		System.out.print(p1+"\n"+Math.sqrt(p2)+"\n"+Math.cbrt(p3)+"\n"+max+"\n");
	}

}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
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; }
const ll MOD = 998244353;

const int MAX_N = 200000;

ll fact[MAX_N+100];
ll frev[MAX_N+100];

ll rev(ll a, ll p){
    if(p == 0) return 1;
    ll tmp = rev(a, p/2);
    tmp = tmp * tmp % MOD;
    if(p % 2 == 1) tmp = tmp * a % MOD;
    return tmp;
}


void calc_fact(){
    fact[0] = frev[0] = 1;
    for(int i = 1; i <= MAX_N; i++){
        fact[i] = (fact[i-1] * i) % MOD;
        frev[i] = rev(fact[i], MOD-2);
    }
}


ll comb(int n, int k){
    if(n < 0 || k < 0 || n < k) return 0;
    if(n == 0 || k == 0) return 1;
    return fact[n] * frev[k] % MOD * frev[n-k] % MOD;
}

ll mod_pow(ll x, ll n, ll mod){
    ll res = 1;
    while(n > 0){
        if(n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    ll N, M, K;
    cin >> N >> M >> K;

    //in main function
    fact[0] = frev[0] = 1;
    for(int i = 1; i <= MAX_N; i++){
        fact[i] = (fact[i-1] * i) % MOD;
        frev[i] = rev(fact[i], MOD-2);
    }

    ll ans = 0;
    vector<ll> DP(K+10, 0);
    //REP(i,K+1){
    for(ll i = K; i >= 0; i--){
        ll left, right;
        left = M * mod_pow(M-1, N-1-i, MOD);
        left %= MOD;

        right = comb(N-1, i);
        //if(i != 0){
        //    for(ll x = 2*i; x <= K+1; x *= 2LL){
        //        right = MOD - DP[x];
        //        right %= MOD;
        //    }
        //}
        //DP[i] = right % MOD;

        ll add = left * right;
        add %= MOD;

        ans += add;
        ans %= MOD;
    }

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


Measured memory_bytes: 8012
#include<stdio.h>

int main()
{
  int i,max=0,mid=0,min=0,mount;

  for(i=0;i<10;i++){
    scanf("%d",&mount);

    if(mount > max ){
      min = mid;
      mid = max;
      max = mount;
    }
    else if(mount > mid){
      min = mid;
      mid = mount;
    }
    else if(mount > min){
      min = mount;
    }
  }
  printf("%d\n%d\n%d\n",max,mid,min);
  return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<string>
using namespace std;
string s;
int cnt;
int main(){
    cin>>s;
    int len=s.size();
    for(int i=0;i<len;i++)
	{
        if(s[i]=='C') cnt=1;
        if(s[i]=='F'&&cnt==1)
		{
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
const double pi = acos(-1);
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define EPS 1e-4
// bool operator<(const pair<int, int> &a, const pair<int, int> &b)
// {
//     if (a.first == b.first)
//         return a.second < b.second;
//     return a.first < b.first;
// };

/*unsigned int xor128(void)
{
    static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned int t = (x ^ (x << 11));
    x = y;
    y = z;
    z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
unsigned int xor128rnd(unsigned int m)
{
    return xor128() % m;
}*/

bool operator<(const pair<ll, ll> &a, const pair<ll, ll> &b)
{

    if (a.first == b.first)
        return a.second < b.second;

    return a.first < b.first;
}
int arr[310];
int c[3];
int N;
double dp[310][310][310];
bool flag[310][310][310];
double f(int c1, int c2, int c3)
{
    if (dp[c1][c2][c3] >= 0.0)
        return dp[c1][c2][c3];

    if (c1 == 0 && c2 == 0 && c3 == 0)
        return 0.0;

    double fs = 0.0;
    if (c1 > 0)
        fs += f(c1 - 1, c2, c3) * c1;
    if (c2 > 0)
        fs += f(c1 + 1, c2 - 1, c3) * c2;
    if (c3 > 0)
        fs += f(c1, c2 + 1, c3 - 1) * c3;
    fs += N;
    fs *= 1.0 / (c1 + c2 + c3);
    //cout << fs << endl;
    return dp[c1][c2][c3] = fs;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    cin >> N;
    for (int i = 0; i < N; ++i)
    {
        cin >> arr[i];
        arr[i]--;
    }

    for (int i = 0; i < N; ++i)
    {
        c[arr[i]]++;
    }
    for (int i = 0; i < 310; ++i)
    {
        for (int j = 0; j < 310; ++j)
        {
            for (int k = 0; k < 310; ++k)
            {
                dp[i][j][k] = -1.0;
            }
        }
    }
    double ans = 0.0;
    ans = f(c[0], c[1], c[2]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 233472
x = int(input())

if 400 <= x <= 599:
    print(8)

if 600 <= x <= 799:
    print(7)

if 800 <= x <= 999:
    print(6)

if 1000 <= x <= 1199:
    print(5)

if 1200 <= x <= 1399:
    print(4)

if 1400 <= x <= 1599:
    print(3)

if 1600 <= x <= 1799:
    print(2)

if 1800 <= x <= 1999:
    print(1)

Measured memory_bytes: 9200