akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int mod = 200003;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define fr(s,n) for (int i=(int)(s);i<(int)(n);i++)
#define lc cout<<"\n"

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,flag=0;
    cin>>n;
    ll a[n];
    fr(0,n){
        cin>>a[i];
        if(a[i]==0){
            flag=1;
        }
    }
    if(flag){
        cout<<0;
    }
    else{
    ll s=1;
    fr(0,n){
        if(a[i]>1000000000000000000/s){
            s=-1;break;
        }
        s=s*a[i];
    }
    cout<<s;
    }
}


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

int N;
vvl edges;
vl color;
vl ans;

void input() {
    cin >> N;
    edges.resize(N);
    rep(i,N-1) {
        int a, b; cin >> a >> b;
        a--; b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
}

void dfs(int v, int pre, int c) {
    color[v] = c;
    c = 1 - c;
    for (auto to : edges[v]) {
        if (to == pre) continue;
        dfs(to, v, c);
    }
}
void coloring() {
    color.assign(N,0);
    dfs(0, -1, 0);
    // rep(i,N) cerr << color[i] << endl;
}

void solve() {
    coloring();

    vector<queue<int>> wannaColor(2);
    rep(i,N) wannaColor[color[i]].push(i);

    vector<queue<int>> restNums(3);
    rng(i,1,N+1) restNums[i%3].push(i);

    if (wannaColor[0].size() > wannaColor[1].size()) {
        swap(wannaColor[0], wannaColor[1]);
    }
    ans.assign(N,0);
    auto f = [&](int x, int y) {
        while (!wannaColor[x].empty() and !restNums[y].empty()) {
            ans[wannaColor[x].front()] = restNums[y].front();
            wannaColor[x].pop(); restNums[y].pop();
        }
    };
    if (wannaColor[0].size() <= N / 3) {
        f(0,0);
        f(1,0); f(1,1); f(1,2);
    } else {
        f(0,1); f(1,2);
        f(0,0); f(1,0);
    }
}

void output() {
    rep(i,N) cout << ans[i] << endl;
}

int main() {
    input();
    solve();
    output();
    return 0;
}


Measured memory_bytes: 19456
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int k,a,b;
    cin>>k>>a>>b;
    cout<<((b/k)*k>=a?"OK":"NG")<<endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,a[100005],b[100005];
map<int,int>cnt;
int par[100005],ran[100005];
void init(){ for(int i=0;i<100005;i++) par[i] = i; }
int find(int x){ if(x == par[x]) return x; else return par[x] = find(par[x]); }
void unite(int x,int y){
	x = find(x); y = find(y); if(x==y) return;
	if(ran[x] < ran[y]) par[x] = y;
	else{
		par[y] = x;
		if(ran[x] == ran[y]) ran[x]++;
	}
}
bool same(int x,int y){ return find(x)==find(y); }
int main(){
	scanf("%d",&n);
	int X = 0;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]); cnt[a[i]]++; X^=a[i];
	}
	cnt[X]++; a[n+1] = X;
	X = 0;
	for(int i=1;i<=n;i++){
		scanf("%d",&b[i]); cnt[b[i]]--; X^=b[i];
	}
	cnt[X]--; b[n+1] = X;
	for(map<int,int>::iterator it = cnt.begin();it != cnt.end();++it){
		if(it->sc != 0){
			puts("-1"); return 0;
		}
	}
	//a->b : swap(i,n+1)
	init();
	int ret = -1;
	map<int,vector<int> >M;
	for(int i=1;i<=n+1;i++){
		if(i<=n && a[i] == b[i]) continue;
		if(i<=n) ret++;
		M[a[i]].pb(i);
	}
	set<int>used;
	for(int i=1;i<=n+1;i++){
		if(i<=n && a[i] == b[i]) continue;
		if(used.find(b[i]) != used.end()){
			if(M.find(b[i]) != M.end()){
				unite(i,M[b[i]][0]);
			}
			continue;
		}
		if(M.find(b[i]) == M.end()) continue;
		
		used.insert(b[i]);
		vector<int>&vi = M[b[i]];
		for(int i=1;i<vi.size();i++){
			unite(vi[i-1],vi[i]);
		}
		unite(i,vi[0]);
	}
	for(int i=1;i<=n+1;i++){
	    if(i<=n && a[i] == b[i]) continue;
		if(find(i) == i) ret++;
	}
	cout << ret << endl;
}

Measured memory_bytes: 22144
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using i64 = long long;



int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout<<fixed<<setprecision(10);

  int n;
  cin>>n;
  int res=0;
  rep(i,0,n) {
    int x;
    cin>>x;
    while (x%2==0) ++res, x/=2;
  }
  cout<<res<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int h,w;
    int i,j;

    while(1){
        scanf( "%d %d ", &h, &w );
        if( h==0&&w==0 ) break;
        for( i=0;i<h;i++ ){
            for( j = 0;j<w;j++){
                if(i==0||i==h-1||j==0||j==w-1){
                    printf("#");
                }else{
                    printf(".");
                }
            }
            printf( "\n" );
        }
        printf("\n");
    }
    return 0;
}

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

int main(){
  int N,x,y;
  int ans=0;
  cin>>N;
  int A[N];//証言の数
  vector<pair<int,int>>T[N];
   
  //証言を入力  
  for(int i=0;i<N;i++){
    cin>>A[i];
    for(int j=0;j<A[i];j++){
      cin>>x>>y;
      x--;
      T[i].push_back({x,y});
    }
  }
  
  //bit全探索
  for(int i=0;i<(1<<N);i++){
    int cnt=0;//正直者の数
    for(int j=0;j<N;j++){
      if(i & (1<<j)){
        cnt++;
      }
    }
    
    int flag=1;
    for(int j=0;j<N;j++){
      if(i & (1<<j)){     
        //jが正直者として証言が矛盾しないかチェック　矛盾したらflag=0でbreak;
        for(int k=0;k<A[j];k++){
          if(i & 1<<(T[j].at(k).first)){
            if(T[j].at(k).second==1){
              continue;
            }
            else{
              flag=0;
              break;
            }
          }
          else{
            if(T[j].at(k).second==0){
              continue;
            }
            else{
              flag=0;
              break;
            }
          }
        }
      }
    }
    if(flag){
      ans=max(ans,cnt);
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3612
#include <iostream>

using namespace std;

#define forsn(i,s,n) for(int i=s;i<(int)(n);i++)
#define forn(i,n) forsn(i,0,n)

typedef long long int tint;

const tint MOD = 998244353;

tint dp[3010][3010][2];

int main() {
	
	tint a, b, c, d; cin >> a >> b >> c >> d;
	
	dp[a][b][0] = 1;
	dp[a][b][1] = 0;
	
	forsn(i, a, c + 1) forsn(j, b, d + 1) if (i != a || j != b) {
		dp[i][j][0] = 0;
		dp[i][j][1] = 0;
		if (i > a) {
			dp[i][j][0] = ((dp[i - 1][j][0] + dp[i - 1][j][1]) * j) % MOD;
		} 
		if (j > b) {
			dp[i][j][1] = (dp[i][j - 1][1] * i + dp[i][j - 1][0]) % MOD;
			if (i == a) dp[i][j][0] = (dp[i][j - 1][0] * (i - 1)) % MOD;
		}
	}
	
	cout << ((dp[c][d][0] + dp[c][d][1]) % MOD) << endl;
}



Measured memory_bytes: 144528
#[doc = " https://github.com/hatoo/competitive-rust-snippets"]
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
mod util {
    use std::fmt::Debug;
    use std::io::{stdin, stdout, BufWriter, StdoutLock};
    use std::str::FromStr;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn chars() -> Vec<char> {
        line().chars().collect()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
    #[allow(dead_code)]
    pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
        let out = stdout();
        let writer = BufWriter::new(out.lock());
        f(writer)
    }
}
#[allow(unused_macros)]
macro_rules ! get { ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ;; ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; ( $ t : ty ;; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ;; ) ) . collect ::< Vec < _ >> ( ) } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }
const BIG_STACK_SIZE: bool = true;
#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}
fn solve() {
    let s = util::chars();

    if if s.first() == s.last() {
        s.len() % 2 == 0
    } else {
        s.len() % 2 == 1
    } {
        println!("First");
    } else {
        println!("Second");
    }
}


Measured memory_bytes: 8572
#include<iostream>
using namespace std;
int main()
{
    int ans[3]={-1,-1,-1},n,m,i,s,c;
    cin >> n >> m;
    for(i=0;i<m;i++){
        cin >> s >> c;
        if(ans[s-1]!=-1 && ans[s-1]!=c){
            cout << "-1";
            return 0;
        }
        ans[s-1]=c;
    }
    if(ans[0]==0 && n!=1){
            cout << "-1";
            return 0;
    }
    for(i=0;i<n;i++){
        if(ans[i]==-1){
            if(i==0 && n!=1) cout << '1';
            else cout << '0';
        }
    else cout << ans[i];
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <queue>
#include <deque>
#include <string>
#include <iomanip>
#include <cmath>

using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define rep(i, N) for (ll i = 0; i < (N); ++i)

int main()
{
    cin.tie(nullptr);

    int A, B, H, M;

    std::cin >> A >> B >> H >> M;

    double const Hpos = H / 12. * 360 + M / 60. * (360 / 12);
    double const Mpos = M / 60. * 360;
    double const diffpos_abs = std::abs(Hpos - Mpos);
    double const diff_pos = std::min(diffpos_abs, 360 - diffpos_abs);
    double const diff_rad = diff_pos / 180 * 3.14159265358979;

    double const ans = std::sqrt(A * A + B * B - 2 * A * B * std::cos(diff_rad));

    std::cout << std::setprecision(15) << ans << std::endl;

    return 0;
}


Measured memory_bytes: 4132
n = int(input())

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

def num_left(pos):
	if pos % 2 == 0:
		return (n - pos) // 2 + 1
	else:
		return (n - pos - 1) // 2 + 1

d = [{} for i in range(n)]
for i in range(n):

	if i < 2:
		d[i][0] = 0
		d[i][1] = a[i]

	else:			
		left = num_left(i + 2)
		#print("i = ", i, left)
		j = i - 2
		while j >= 0:
			max_count = max(d[j].keys())
			
			if max_count + left + 1	 < n // 2: 
				break

			else: 
				for count, v in d[j].items():
					#print(count, v)
					if count + left + 1 >= n // 2:
						if count + 1 in d[i]:
							d[i][count + 1] = max(d[i][count + 1], v + a[i])
						else:
							d[i][count + 1] = v + a[i]							
			j -= 1

		if 1 + left >= n // 2:
			d[i][0] = 0

best = None
for i in range(n):
	for count, result in d[i].items():
		if count == n // 2:
			if best is None:
				best = result
			else:
				best = max(best, result)

#print(d)
print(best)


Measured memory_bytes: 149080
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
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;}

const ll INF = 1000000000;

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

    vector<int> x(n, 0);
    int sum_x = 0;
    for(int i = 0; i < n; i++){
        cin >> x[i];
        sum_x += x[i];
    }
    int ave = sum_x / n;

    int ans_1 = 0, ans_2 = 0, ans_3 = 0;
    for(int i = 0; i < n; i++){
        ans_1 += (x[i] - ave) * (x[i] - ave);
        ans_2 += (x[i] - (ave + 1)) * (x[i] - (ave + 1));
        ans_3 += (x[i] - (ave - 1)) * (x[i] - (ave - 1));
    }

    cout << min({ans_1, ans_2, ans_3}) << endl;


    return 0;
}


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

int main() {
  int N;
  bool Y = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    if (S == "Y") {
      Y = 1;
    }
  }
  if (Y) {
    cout << "Four" << endl;
  }
  else {
    cout << "Three" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, D, ans=0;
  cin >> N >> D;
  vector<vector<int>> X(N, vector<int> (D));
  for (int i=0; i<N; i++){
    for (int j=0; j<D; j++){
      cin >> X.at(i).at(j);
    }
  }
  for (int i=0; i<N-1; i++){
    for (int j=i+1; j<N; j++){
      int norm = 0;
      for (int k=0; k<D; k++){
        int diff =0;
        diff = abs(X[i][k] - X[j][k]);
        norm += diff*diff;
      }
      bool flag = false;
      for (int l=0; l <= norm; l++){
        if (norm == l*l)
          flag = true;
      }
      if (flag)
        ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    long long a, b, x, ans;
    cin >> a >> b >> x;
    if (a >= 1) {
        ans = b / x + 1 - ((a - 1) / x + 1);
    } else {
        ans = b / x + 1;
    }
    cout << ans << endl;
}
/*
xで割り切れるものの個数をX1, X2とすると：
X1(0以上b以下の範囲) - X2(0以上a「未満」の範囲)
0も約数なので+1。
*/

Measured memory_bytes: 256
n = int(input())
a = list(int(input()) for _ in range(n))
d = {}
for i in range(n):
    d[a[i]] = d.get(a[i], 0) + 1
ans = 0
for v in d.values():
    if v % 2 == 1:
        ans += 1
print(ans)

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> mt;
typedef vector<mt> v3;

const ll INF = 1ll << 58;

ll n,k;
vl a,r,b;
ll sum_a,sum_r,sum_b;
ll ans = INF;

v3 dp;

int main(){
	cin >> n >> k;
	a = vl(n);
	r = b = vl(k);
	for(ll i = 0;i < n;i++) cin >> a[i];
	for(ll i = 0;i < k;i++) cin >> r[i];
	for(ll i = 0;i < k;i++) cin >> b[i];
	sort(a.rbegin(),a.rend());
	sort(r.rbegin(),r.rend());
	sort(b.rbegin(),b.rend());

	sum_a = accumulate(a.begin(),a.end(),0ll);
	sum_r = accumulate(r.begin(),r.end(),0ll);
	sum_b = accumulate(b.begin(),b.end(),0ll);
	dp = v3(k+2,mt(k+2,vl(sum_a*2+1,INF)));
	dp[0][0][0] = 0;
	for(ll i = 0;i <= k;i++){
		for(ll j = 0;j <= k;j++){
			ll t = i+j;
			if(t >= n) continue;
			for(ll l = 0;l <= sum_a;l++){
				if(i < k) dp[i+1][j][l+a[t]] = min(dp[i+1][j][l+a[t]],dp[i][j][l]+max(0ll,a[t]-r[i]));
				if(j < k) dp[i][j+1][l] = min(dp[i][j+1][l],dp[i][j][l]+max(0ll,a[t]-b[j]));
			}
		}
	}

	for(ll i = 0;i <= k;i++){
		for(ll j = 0;j <= k;j++){
			if(i+j == n){
				for(ll l = 0;l <= sum_a*2;l++){
					if(l <= sum_r && sum_a-l <= sum_b){
						ans = min(ans,dp[i][j][l]);
					}
				}
			}
		}
	}
	if(ans == INF){
		cout << -1 << endl;
	}else{
		cout << ans << endl;
	}
}



Measured memory_bytes: 186016
#include <iostream>
#include <string>
#include <vector>
#define sz(a) (int)(a).size()

using namespace std;

typedef vector<int> vi;
typedef long long ll;



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	vector<vi> v(3, vi(n));
	for(int i=0;i<n;i++){
		cin>>v[0][i]>>v[1][i]>>v[2][i];
	}
	vector<ll> a(n);
	vector<ll> b(n);
	vector<ll> c(n);
	a[0]=v[0][0];
	b[0]=v[1][0];
	c[0]=v[2][0];
	for(int i=1;i<n;i++){
		a[i]=v[0][i]+max(b[i-1],c[i-1]);
		b[i]=v[1][i]+max(a[i-1],c[i-1]);
		c[i]=v[2][i]+max(b[i-1],a[i-1]);
	}
	ll res=max(a[n-1],b[n-1]);
	cout<<max(c[n-1],res)<<"\n";
}


Measured memory_bytes: 3832
#include <iostream>
#include <vector>
using namespace std;
const int MOD = 1e9 + 7;
int main(){
    long long N;
    cin >> N;
    vector<long long> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    long long ans = 1;
    vector<long long> v(3, 0);
    for(int i = 0; i < N; i++){
        long long cnt = 0;
        int flag;
        for(int j = 0; j < 3; j++){
            if(A[i] == v[j]) {
                cnt++;
                flag = j;
            }
        }
        ans = ans * cnt % MOD;
        v[flag]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4048
#include <iostream>
#include <algorithm>
#include <deque>
using namespace std;
typedef long long lint;

int N;
const int MAX_N = 100005;
int a[MAX_N];
int b[MAX_N];
void solve(){
	cin >> N;
	for(int i=0;i<N;i++){
		cin >> a[i];
	}
	for(int i=0,j=1;i<N;i++,j*=-1){
		if(i==0||i==N-1)b[i] = j;
		else b[i] = 2*j;
	}

	sort(a,a+N);
	sort(b,b+N);

	lint sum0 = 0, sum1 = 0;
	for(int i=0;i<N;i++){
		sum0 += a[i]*b[i];
		sum1 += a[N-1-i]*(-b[i]);
	}

	cout << max(sum0,sum1) << endl;
}

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

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

int D[100];
int a[100][100];

int main() {
  for (int i = 0; i < 100; i++){
    for (int j = 0; j < 100; j++){
	  a[i][j] = 0;
	  }
	 }
	int n,u,k,v;
	cin >> n;
	for (int i = 0; i < n; i++) {
	  cin >> u >> k;
	  for (int j = 0; j < k; j++) {
	    cin >> v;
		a[u][v] = 1;
		}
	  }
queue<int> Q; //整数を管理するキューの定義
  for (int i = 1; i < n+1; i++){
   D[i] = -1;
   }
  int src = 1;
  Q.push(src);
  D[src] = 0; //出発点
  while (! Q.empty()) {
    int cur = Q.front(); //先頭要素を取り出す
	Q.pop();
	for(int dst = 1 ; dst <= n; dst++) { //各行き先dstに対して
	if((a[cur][dst] == 1 && D[dst] == -1)) { //curからdstに辺があり、dstが未訪問なら
	      D[dst] = D[cur] + 1; //
		    Q.push(dst); //dstを訪問先に入れる
			}
		  }
		}
	for (int i=1; i < n+1; i++){
	  cout << i << " " << D[i] << endl;
	  }
	}

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

int main() {
  
  int N,X;
  cin>>N>>X;
  
  vector<int> L(N);
for (int i = 0; i < N; i++) {
  cin >> L.at(i);
}
  
  int sw=0;
  int asai=0;
  
  for (int i = 0; i < N; i++) {
    sw=sw+L.at(i);
    if(sw<=X){
      asai++;
    }
}
  
  cout<<asai+1<<endl;
  
  
}


  
  
  

Measured memory_bytes: 256
let () =
  let line = read_line () in
  let result = Str.split (Str.regexp " ") line |>
               List.map int_of_string |>
               (function | [w; h; x; y; r] when x-r < 0 -> "No"
                         | [w; h; x; y; r] when y-r < 0 -> "No"
                         | [w; h; x; y; r] when w < x+r -> "No"
                         | [w; h; x; y; r] when h < y+r -> "No"
                         | _ -> "Yes") in
  print_endline result

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

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n; cin >> n;
    string s; cin >> s;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (i == n-1 || s[i] != s[i+1]) ans++;    
    }
    cout << ans << '\n';
}



Measured memory_bytes: 512
from collections import Counter
n=int(input())
vs=list(map(int,input().split()))
xs=vs[0::2]
ys=vs[1::2]
cx=Counter(xs).most_common()
cy=Counter(ys).most_common()
if len(cx)==1:
    cx.append((0,0))
if len(cy)==1:
    cy.append((-1,0))
if not cx[0][0]==cy[0][0]:
    print(len(xs)-cx[0][1]+len(ys)-cy[0][1])
else:
    mx=len(xs)-cx[1][1]+len(ys)-cy[0][1]
    my=len(xs)-cx[0][1]+len(ys)-cy[1][1]
    print(min(mx,my))


Measured memory_bytes: 21084
N = int(input())

DP = [[0 for _ in range(10)] for _ in range(10)]

for i in range(1, N+1):
  DP[int(str(i)[0])][int(str(i)[-1])] += 1

ans = 0
for i in range(10):
  for j in range(10):
    ans += DP[i][j] * DP[j][i]

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;


int main(){
  string s;
  cin >> s;
  int sz=s.size();
  ll cnt=0;
  if(s[0]==s.back()){
    if(sz%2==1){ cout << "Second" << endl; return 0; }
    else{ cout << "First" << endl; return 0; }
  } else {
    if(sz%2==0){ cout << "Second" << endl; return 0; }
    else{ cout << "First" << endl; return 0; }
  }
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <iomanip>
using namespace std;

typedef long long ll;

int main()
{
    ll N,C;
    cin >> N >> C;
    vector < vector <ll> > conditions(N, vector<ll>(2));
    for(int i=0; i<N; i++){
        cin >> conditions[i][0] >> conditions[i][1];//[0]がx0からの距離[1]が価値
    }
    vector<ll> gain_clock(N), gain_counter(N);
    gain_clock[0]=conditions[0][1]-conditions[0][0];
    gain_counter[0]=conditions[N-1][1]-(C-conditions[N-1][0]);
    ll ans=max(gain_clock[0], gain_counter[0]);
    ans=max(ans, (ll)0);
    for(int i=1; i<N; i++){
        gain_clock[i]=gain_clock[i-1]+conditions[i][1]-(conditions[i][0]-conditions[i-1][0]);
        ans=max(gain_clock[i], ans);
        gain_counter[i]=gain_counter[i-1]+conditions[N-i-1][1]-(conditions[N-i][0]-conditions[N-i-1][0]);
        ans=max(gain_counter[i], ans);
    }

    vector<ll> to_clock(N-1), to_counter(N-1);
    if(N>1){
        to_clock[N-2]=gain_counter[0];
        to_counter[N-2]=gain_clock[0];
    }
    for(int i=N-3; i>=0; i--){
        to_clock[i]=max(to_clock[i+1], gain_counter[N-i-2]);
        to_counter[i]=max(to_counter[i+1], gain_clock[N-i-2]);
    }

    for(int i=0; i<N-1; i++){
        ll tmp=gain_clock[i];
        /*vector<ll> copied(N-i-1);
        copy(gain_counter.begin(), gain_counter.begin()+N-i-1, copied.begin());
        sort(copied.begin(), copied.end(), greater<ll>());*/

        ans=max(ans, tmp-conditions[i][0]+to_clock[i]);//copied[0]

        tmp=gain_counter[i];
        /*copy(gain_clock.begin(), gain_clock.begin()+N-i-1, copied.begin());
        sort(copied.begin(), copied.end(), greater<ll>());*/

        ans=max(ans, tmp-(C-conditions[N-i-1][0])+to_counter[i]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 8832
#include<iostream>

using namespace std;

int main() {
	int x =1;
	int y =1;
		cin >> x >> y ;	
	while (x != 0 || y != 0) {
		if (x > y) {
			cout << y << " " << x << endl;
		} else {
			cout << x << " " << y << endl;
		}
		cin >> x >> y ;
	}
	return 0;
}


Measured memory_bytes: 3076
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  maxn = 1e6 + 5;
const int N = 4000 + 5;

int n;
char s[N];
set<int> ss[3];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>s+1;
	ll res=0;
	vector<int> G[3];
	for(int i=1;i<=n;i++){
		if(s[i]=='R') G[0].push_back(i),ss[0].insert(i);
		if(s[i]=='G') G[1].push_back(i),ss[1].insert(i);
		if(s[i]=='B') G[2].push_back(i),ss[2].insert(i);
	}
	for(int i=1;i<=n-3;i++){
		for(int j=i+3;j<=n;j++){
			if(s[i]==s[j]) continue;
			char x=s[i],y=s[j];
			int u,v,w;
			if(x=='R') u=0;
			else if(x=='G') u=1;
			else if(x=='B') u=2;
			if(y=='R') v=0;
			else if(y=='G') v=1;
			else if(y=='B') v=2;
			w=3-u-v;
			int L=upper_bound(G[w].begin(),G[w].end(),i)-G[w].begin();
			int R=upper_bound(G[w].begin(),G[w].end(),j)-G[w].begin();
			res+=(R-L);
		}
	}
	for(int i=1;i<=n-3;i++){
		for(int j=i+3;j<=n;j++){
			if((i+j)%2!=0) continue;
			if(s[i]==s[j]) continue;
			char x=s[i],y=s[j];
			int u,v,w;
			if(x=='R') u=0;
			else if(x=='G') u=1;
			else if(x=='B') u=2;
			if(y=='R') v=0;
			else if(y=='G') v=1;
			else if(y=='B') v=2;
			w=3-u-v;
			int k=(i+j)/2;
			if(ss[w].find(k)!=ss[w].end()) res--;
		}
	}
	cout<<res;
	return 0;
}


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

using namespace std;

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

	int a;

	for (int i = 0; i < n; i++)
	{
		cin >> a;
	}

	int num = 0;

	n -= k;
	num++;

	while (n >0)
	{
		n -= (k - 1);
		num++;
	}

	cout << num << endl;


	return 0;
}

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

#define pb push_back
#define f first 
#define s second
#define ll long long
#define FOR(i, s) for(int i = 0; i<s; i++)
#define sz(s) (int)s.size()
#define vi vector<int>
#define ii pair<int, int>
#define vvi vector<vi>

ll n, m, q;

const ll mod = 1e9+7; 
ll ile[61];

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> n;
    ll ans = 0;
    FOR(i, n){
    	ll temp;
    	cin >> temp;
    	
    	FOR(j, 61){
     		bool zapalony = (temp & (1ll<<j)) > 0;
    		ll val = (1ll<<j)%mod;
    		if(zapalony)
    			ans = (ans + val*(i-ile[j]))%mod;
    		else
    			ans = (ans + val*ile[j])%mod;
    		ile[j] += zapalony;
    	}
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
from collections import deque

n, x, y = map(int, input().split())

ans = [0] * (n+1)

g = [[i+1, i-1] for i in range(n+1)]
#g[0].clear() pypyにclearなし
g[1].pop(1)
g[n].pop(0)

g[x].append(y)
g[y].append(x)

for i in range(1,n+1):
    q = deque()
    time = 0
    visit = [False] * (n+1)
    q.append((i, time))

    while(len(q) > 0):
        item = q.popleft()

        if visit[item[0]] == False:
            visit[item[0]] = True
            ans[item[1]] += 1
            for k in g[item[0]]:
                q.append((k, item[1]+1))

for i in range(1,n):
    print(ans[i]//2)


Measured memory_bytes: 49372
#include <bits/stdc++.h>
using namespace std;
long long n, i, ans;
long long numbers[200005];

int main() {
    //freopen("test.in", "r", stdin);
    scanf("%lld\n", &n);
    ans = 0;

    for (i=0; i < n; i++) {
        scanf("%lld", &numbers[i]);
    }

    for (i=1; i < n; i++) {
        if (numbers[i] < numbers[i-1]) {
            ans += numbers[i-1] - numbers[i];
            numbers[i] = numbers[i-1];
        }
    }

    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 5380
#include <stdio.h>

int main(){
    int i, j, k;
    int n, x, s;
    
    while(scanf("%d %d", &n, &x), n > 0){
        s = 0;
        
        for(i = 1; i <= n; ++i){
            for(j = i + 1; j <= n; ++j){
                for(k = j + 1; k <= n; ++k){
                    if(i + j + k == x){
                        ++s;
                    }
                }
            }
        }
        
        printf("%d\n", s);
    }
    
    return 0;
}


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

using namespace std;


void eating_symbols_easy()
{
  string s;
  cin >> s;

  int cnt = 0;
  for (int i = 0; i < 4; ++i)
  {
    if (s[i] == '+') ++cnt;
    else --cnt;
  }
  cout << cnt << "\n";
}


void multiple_of_2_and_n()
{
  int n;
  cin >> n;

  if (n % 2 == 0) cout << n << "\n";
  else cout << 2 * n << "\n";
}


void task_scheduling_problem()
{
  vector<int> a(3);
  for (int i = 0; i < 3; ++i) cin >> a[i];

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

  cout << a[2] - a[0] << "\n";
}


void rated_for_me()
{
  int r;
  cin >> r;

  if (r < 1200) cout << "ABC\n";
  else if (r < 2800) cout << "ARC\n";
  else cout << "AGC\n";
}


void atcoder_crackers()
{
  int n, k;
  cin >> n >> k;

  if (n % k == 0) cout << 0 << "\n";
  else cout << 1 << "\n";
}


void garden()
{
  int a, b;
  cin >> a >> b;

  cout << (a - 1) * (b - 1) << "\n";
}


int main()
{
  //eating_symbols_easy();
  //multiple_of_2_and_n();
  //task_scheduling_problem();
  //rated_for_me();
  //atcoder_crackers();
  garden();
}

Measured memory_bytes: 256
//code source : https://www.geeksforgeeks.org/lcm-of-n-numbers-modulo-m/
#include <bits/stdc++.h> 
#define F first 
#define S second 
#define MAX 10000003 
using namespace std; 

typedef long long ll; 
const int mod = 1000000007; 

void add(ll &a, ll b)
{
	a += b;
	if(a>=mod)
		a %= mod;
}

ll modInverse(ll a, ll m) 
{ 
    ll m0 = m; 
    ll y = 0, x = 1; 
  
    if (m == 1) 
      return 0; 
  
    while (a > 1) 
    { 
        // q is quotient 
        ll q = a / m; 
        ll t = m; 
  
        // m is remainder now, process same as 
        // Euclid's algo 
        m = a % m, a = t; 
        t = y; 
  
        // Update y and x 
        y = x - q * y; 
        x = t; 
    } 
  
    // Make x positive 
    if (x < 0) 
       x += m0; 
  
    return x; 
} 


int prime[MAX]; 
unordered_map<int, int> max_map; 

int power(int a, int n) 
{ 
	if (n == 0) 
		return 1; 
	int p = power(a, n / 2) % mod; 
	p = (p * p) % mod; 
	if (n & 1) 
		p = (p * a) % mod; 
	return p; 
} 

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

ll lcmModuloM(const ll* ar, int n) 
{ 

	for (int i = 0; i < n; i++) { 
		int num = ar[i]; 
		unordered_map<int, int> temp; 
 
		while (num > 1) { 

			int factor = prime[num]; 

			temp[factor]++; 

			num /= factor; 
		} 

		for (auto it : temp) { 

			max_map[it.first] = max(max_map[it.first], it.second); 
		} 
	} 

	ll ans = 1; 

	for (auto it : max_map) { 
		ans = (ans * power(it.F, it.S)) % mod; 
	} 
	return ans; 
} 
 
int main() 
{ 
	sieve(); 
	int n;
	cin>>n;
	ll a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	ll lcm = lcmModuloM(a,n);
	ll ans = 0;
	//cout<<lcm<<'\n';

	for(int i=0;i<n;i++)
	{
		add(ans,lcm*(modInverse(a[i],mod)));
	} 
	cout<<ans;
} 


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

void add(ll& a, ll b) { (a += b) %= mod; }

int main() {
    ll N, S, ans = 0; cin >> N >> S;
    vl A(N), dp(3030, 0);
    rep(i,N) cin >> A[i];
    rep(i,N) {
        vl ndp(3030, 0);
        ndp[0] = ndp[A[i]] = 1;
        rep(j,3030) {
            add(ndp[j], dp[j]);
            if (j+A[i] > S) continue;
            add(ndp[j+A[i]], dp[j]);
        }
        add(ans, ndp[S]);
        dp = ndp;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main(){
    ll a,b;
    string S;
    cin >> a >> b >> S;
    bool flag = true;
    REP(i,a + b + 1){
        if(i == a){
            if(S[i] != '-'){
                flag = false;
            }
        }
        else{
            if(! isdigit(S[i])){
                flag = false;
            }
        }
    }
    if(flag){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


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

int main() {
  int n;
  cin>>n;
  n*=3;
  long long int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  sort(a,a+n);
  long long int ans=0;
  int cnt=0;
  for(int i=1;i<n;i++){
    ans+=a[n-2*i];
    cnt++;
    if(cnt==n/3)
      break;
  }
  cout<<ans;
}

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

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

int main(){
  int n; cin >> n;
  int c = 0;
  int a;
  rep(i,n){
    cin >> a;
    while(a%2==0){
      a/=2;
      c++;
    }
  }
  cout << c << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<cstring>
#include<utility>
using namespace std;
int n,m;
vector<int> v[111111];
int dist[111111],ans;
void dfs(int x)
{
	for(int i=0;i<v[x].size();i++)
	{
		int p=v[x][i];
		if(dist[p]==0)
		{
			dist[p]=1;
			dfs(p);
		}
	}
}
int main()
{
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int u,V,w;
		scanf("%d %d %d",&u,&V,&w);
		v[u].push_back(V);
		v[V].push_back(u);
	}
	for(int i=1;i<=n;i++)
	{
		if(dist[i]==0)
		{
			dist[i]=1;
			dfs(i);
			ans++;
		}
	}
	printf("%d",ans);
}

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

#define ONLINE_JUDGE
#define pb(a) push_back(a)
#define ALL(a) a.begin(), a.end()
#define FOR(x,to) for(x=0;x<(to);x++)

using ll = long long;

const int E5 = 1e5;

//////////// Solution /////////////////////////////////

void solve() {	
	ll N,M;
	cin >> N >> M;
	if (N == 1 && M == 1) {
		cout << 1 << '\n';
	} else if (N == 1) {
		cout << M-2 << '\n';
	} else if (M == 1) {
		cout << N-2 << '\n';
	} else {
		cout << (N-2) * (M-2) << '\n';
	}
}	

/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

	#ifndef ONLINE_JUDGE
	FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
	clock_t time_start = clock();
	#endif

	ios::sync_with_stdio(false);
	cin.tie(NULL);

	solve();

	#ifndef ONLINE_JUDGE
	fclose(FIN);
	cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock()-time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m";
	#endif

	return 0;
}

//////// End Initialization ///////////////////////////////////////

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

#define F(i, a, b) for(int i=a; i<b; i++)
#define mem(arr, val) memset(arr, val, sizeof(arr))
#define rev(a) reverse(a.begin(), a.end())
#define UPPER(a) transform(a.begin(), a.end(), a.begin(), ::toupper)
#define LOWER(a) transform(a.begin(), a.end(), a.begin(), ::tolower)
#define INF 1000000000000001
#define epsilon 1e-15

typedef long long int ll;
typedef unsigned long long int ull;

ll p = 1000000007;
const int MAX = 500001;

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("OUTPUT.txt", "w", stdout);
    #endif

    int n;
    cin >> n;
    int A[n];
    for(int i=0; i<n; i++)
    	cin >> A[i];
    ll ans = 0;
    for(int i=1; i<n; i++){
    	if(A[i-1] > A[i]){
    		ans = ans + (A[i-1] - A[i]);
    		A[i] = A[i-1];
    	}
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 4396
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
   
int n, m;
vector<int> p1, p2;
int main()
{
  while(true){
    scanf("%d%d", &n, &m);
    if(!n && !m)
      break;
  
    p1.clear();
    p2.clear();
       
    //chap1
    p1.push_back(0);
    for(int i = 0; i < n; i++){
      int p;
      scanf("%d", &p);
      p1.push_back(p);
    }
   
    //chap2
    for(int i = 0; i <= n; i++)
      for(int j = i; j <= n; j++)
    p2.push_back(p1[i] + p1[j]);
   
    sort(p2.begin(), p2.begin() + p2.size());
   
    //chap3
    int ans = 0;
    for(int i = 0; i < p2.size(); i++){
      vector<int>::iterator count2 = upper_bound(p2.begin(), p2.end(), m - p2[i]);
      if(count2 != p2.begin())
    ans = max(ans, *(count2 - 1) + p2[i]);
    }
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 3144
import java.io.*;
public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
        int a=Integer.parseInt(buf.readLine());
        int[] num=new int[a];
        int i,j,tmp,min;
        int cnt=0;
        String[] str=buf.readLine().split(" ");
        for(i=0;i<num.length;i++){
            num[i]=Integer.parseInt(str[i]);
        }
        
        for(i=0;i<num.length;i++){
            min=i;
            for(j=i+1;j<num.length;j++){
                    if(num[j]<num[min]){
                        min=j;
                    }
            }
            if(i!=min){
                cnt++;
        tmp=num[i];
        num[i]=num[min];
        num[min]=tmp;
            }
        }
        for(int x=0;x<num.length-1;x++){
            System.out.print(num[x]+" ");
}
        System.out.println(num[a-1]);
        System.out.println(cnt);
    }
}

Measured memory_bytes: 24376
n = int(input())
a = [int(i) for i in input().split()]
cnta = 0
cntb = 0

for i in range(n):
    if a[i]%4 == 0:
        cnta += 1
    elif a[i]%2 == 0:
        cntb += 1

if 2*cnta+1 >= n or 2*cnta + cntb >= n:
    ans = "Yes"
else:
    ans = "No"

print(ans)

Measured memory_bytes: 14224
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	rep(i, h) cin >> s[i];
	const int dx[] = { 0,1,0,-1 ,1,-1,1,-1};
	const int dy[] = { 1,0,-1,0 ,1,-1,-1,1};
	vector<vector<int>> ans(h, vector<int>(w, -1));
	rep(i, h)rep(j, w) {
		if (s[i][j] == '#') continue;
		int cnt = 0;
		rep(k, 8) {
			int a = i + dx[k],b = j + dy[k];
			if (a < 0 || b < 0 || a >= h || b >= w) continue;
			if (s[a][b] == '#') cnt++;
		}
		ans[i][j] = cnt;
	}
	rep(i, h) {
		rep(j, w) {
			if (ans[i][j] == -1) cout << "#";
			else cout << ans[i][j];
		}cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3652
n, a, b = map(int, input().split())
s = input()

count_a = 0
count_b = 0

for w in s:
    if w == "a":
        if (count_a + count_b) < (a + b):
            count_a += 1
            print("Yes")
        else:
            print("No")
    elif w == "b":
        if (count_a + count_b) < (a + b) and count_b < b:
            count_b += 1
            print("Yes")
        else:
            print("No")
    else:
        print("No")


Measured memory_bytes: 4016
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int [][] cards = new int[4][13];
		int i, j;
		for(i = 0; i < 4; i++) {
			for(j = 0; j < 13; j++) {
				cards[i][j] = 0;
			}
		}
		String ill;
		int num;
		for(i = 0; i < n; i++) {
			ill = sc.next();
			num = sc.nextInt();
			if(ill.equals("S")) {
				cards[0][num - 1] = 1;
			}
			if(ill.equals("H")) {
				cards[1][num - 1] = 1;
			}
			if(ill.equals("C")) {
				cards[2][num - 1] = 1;
			}
			if(ill.equals("D")) {
				cards[3][num - 1] = 1;
			}
		}

		for(i = 0; i < 4; i++) {
			for(j = 0; j < 13; j++) {
				if(cards[i][j] == 0) {
					if(i == 0)	System.out.printf("S %d\n", j + 1);
					if(i == 1)	System.out.printf("H %d\n", j + 1);
					if(i == 2)	System.out.printf("C %d\n", j + 1);
					if(i == 3)	System.out.printf("D %d\n", j + 1);
				}
			}
		}
	}
}



Measured memory_bytes: 26232
N = int(input())  
sps = []
ss = []
for i in range(1, N+1):
    s, p = input().split(' ')
    sps.append([i, s, int(p)])
    if s not in ss:
        ss.append(s)

sps = sorted(sps, key=lambda x: x[2], reverse=True)
ss = sorted(ss)
ret = []
for s in ss:
    t = [tmp for tmp in sps if tmp[1]==s]
    ret.extend(t)

for i in range(N):
    print(ret[i][0])

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

struct Node{
  int p,l,r;
};

struct Node T[MAX];
int n,D[MAX],H[MAX];

int getDepth(int u){
  int d = 0;

  while(1){
    u = T[u].p;
    if(u == NIL) break;
    d++;
  }
  return d;
}

int getSibling(int u){
  if(T[u].p != NIL){
    if(T[T[u].p].l != u && T[T[u].p].l != NIL) return T[T[u].p].l;
    if(T[T[u].p].r != u && T[T[u].p].r != NIL) return T[T[u].p].r;
  }
  
  return NIL;
}

void print(int u){
  int deg = 0;

  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("sibling = %d, ",getSibling(u));

  if(T[u].l != NIL) deg++;
  if(T[u].r != NIL) deg++;

  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);

  if(T[u].p == NIL){
    printf("root\n");
  }
  else if(T[u].l == NIL && T[u].r == NIL){
    printf("leaf\n");
  }
  else{
    printf("internal node\n");
  }
}

int main(){
  int i,v,l,r,p,c;

  scanf("%d",&n);

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

  for(i = 0;i < n;i++){
    scanf("%d %d %d",&v,&l,&r);

    T[v].l = l;
    T[v].r = r;

    if(l != NIL){
      T[l].p = v;
    }
    if(r != NIL){
      T[r].p = v;
    }
  }

  for(i = 0;i < n;i++){
    D[i] = getDepth(i);
    H[i] = 0;
  }

  for(i = 0;i < n;i++){
    if(T[i].l == NIL && T[i].r == NIL){
      H[i] = 0;
      p = T[i].p;
      c = 1;

      while(1){
	if(p == NIL) break;
	if(H[p] < c){
	  H[p] = c;
	}
	c++;
	p = T[p].p;
      }
    }
  }

  for(i = 0;i < n;i++){
    print(i);
  }

  return 0;
}
    



Measured memory_bytes: 2108
#include<iostream>
#include<algorithm>
#define maxn 200010
using namespace std;
int n;
int num[maxn];
struct ti{
	int x,id;
}a[maxn]; 
bool cmp(ti aa,ti bb){
	return aa.x <bb.x ;
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i].x;
		a[i].id =i;
	}
	for(int i=1;i<=n;i++)num[i]=1;
	sort(a+1,a+1+n,cmp);
	//for(int i=1;i<=n;i++)cout<<a[i].id <<" ";cout<<endl;
	
	int cnt=1;
	for(int i=1;i<=n;i++){
		 int ans=a[i].id ;
	//	cout<<ans<<endl;
		while(ans<a[i+1].id&&i<n){
			num[cnt]++;
			ans=a[++i].id;
		}
	//	cout<<num[cnt]<<endl;
		cnt++;
	}
//	for(int i=1;i<cnt;i++)cout<<num[i]<<" ";cout<<endl;;
	
	int sum=1;
	for(int i=1;i<cnt;i++){
		if(sum<num[i])sum=num[i];
	}
	cout<<n-sum<<endl;
	return 0;
}

Measured memory_bytes: 3068
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t a,b,c;
    cin >> a >> b >> c;
    cout << (c>=a&&c<=b?"Yes":"No") << endl;
}


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


int main() {
  
  int N, sa;
  cin >> N ;
    
  vector<int> a(N);
  
  for ( int i = 0; i < N; i++ ) {
    cin >> a.at(i);
  }
  
  sort ( a.begin(), a.end() );
    sa = a.at(N-1) - a.at (0);
  
  cout << sa << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define ull unsigned long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vvll vector<vll>
#define all(v) v.begin(),v.end()
#define itr(r,v) for(auto r=v.begin();r!=v.end();r++)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define ffor(i,a,b) for(ll i=a;i<=b;i++)
#define rfor(i,a,b) for(ll i=a;i>=b;i--)
#define space cout<<"\n\n";
#define endl "\n"
#define pqmx priority_queue<ll>
#define pqmn priority_queue<ll,vll,greater<ll>>
#define fps(x,y) fixed<<setprecision(y)<<x
#define merg(a,b,c) set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.begin()))
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define ctime auto start = high_resolution_clock::now()
#define etime auto stop = high_resolution_clock::now()
#define ptime auto z1z = duration_cast<microseconds>(stop-start); cout<<"Time elapsed : "<<z1z.count()<<" microseconds\n"
#define dbg1(x)             cout <<#x<<": "<<x<<'\n';
#define dbg2(x, y)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<'\n';
#define dbg3(x, y, z)       cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<'\n';
#define dbg4(a, b, c, d)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<'\n';
#define dbg5(a, b, c, d, e) cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<'\n';

using namespace std;
using namespace std::chrono;

const ll MOD = 1e9+7;
const ll N = 1e6+6;
const ll maxN = 1e6+6;

ll power(ll x,ll y, ll M = MOD) // default argument
{ll v=1;x=x%M;while(y>0){if(y&1)v=(v*x)%M;y=y>>1;x=(x*x)%M;}return v;}

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input1.txt", "r", stdin);
        freopen("output1.txt", "w", stdout);
    #endif
    FIO
    ll n;
    cin>>n;
    ll a[4]={};
    FOR(i,n){
        string s; cin>>s;
        if(s == "AC")a[0]++;
        else if(s == "WA") a[1]++;
        else if(s == "TLE") a[2]++;
        else a[3]++;
    }
    cout<<"AC x "<<a[0]<<endl;
    cout<<"WA x "<<a[1]<<endl;
    cout<<"TLE x "<<a[2]<<endl;
    cout<<"RE x "<<a[3]<<endl;

    return 0;
}


Measured memory_bytes: 3644
n, k = map(int,input().split())

def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

# print(Base_10_to_n(n, k))
print(len(Base_10_to_n(n, k)))

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

int main(){
    vector<int> H;
    vector<int> W;
    int h;
    int w;
    
    while(1){
      cin >> h >> w;
      if(h==0 && w==0) break;
      H.push_back(h);
      W.push_back(w);
    }
    
    for(int i=0;i<H.size();i++){
      if(H[i]==0 && W[i]==0) break;
      for(int j=0;j<H[i];j++){
	for(int k=0;k<W[i];k++){
	  if(k!=0 && j!=0 && W[i]-1!=k && H[i]-1!=j){
	  cout << ".";
	  }
	  else cout << "#";
	}
	cout << endl;
      }
      cout << endl;
    }
   
    return 0;
}



Measured memory_bytes: 3144