akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
  int n,k;
  cin >> n >> k;
  vi h(n);
  REP(i,n) {
    cin >> h[i];
  }
  sort(ALL(h));
  int ans=INF;
  REP(i,n-k+1) {
    ans=min(h[i+k-1]-h[i],ans);
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n;
  cin >> n;
  map<string, int> M;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    ++M[s];
  }
  ll asw = 0;
  for (auto &i : M) {
    ll tmp = i.second;
    asw += tmp * (tmp - 1) / 2;
  }
  cout << asw << endl;
  return 0;
}


Measured memory_bytes: 11264
def extract(i)
  left = i*2
  right = i*2 + 1
  length = A.length

  if left < length && A[left] > A[i]
    @largest = left
  else
    @largest = i
  end

  if right < length && A[right] > A[@largest]
    @largest = right
  end

  if @largest != i
    A[i], A[@largest] = A[@largest], A[i]
    extract(@largest)
  end
end

def insert(i)
  parent = i/2
  if parent == 0
    return
  end

  if A[i] > A[parent]
    A[i], A[parent] = A[parent], A[i]
    insert(parent)
  end
end

A = Array.new
A << 0

until (input=gets.chomp) == "end"
  if input == "extract"
    puts A[1]
    A[1] = A.pop
    extract(1)
  else
    input = input.split(" ")
    A << input[1].to_i
    insert(A.length-1)
  end
end



Measured memory_bytes: 14776
#include <iostream>

using namespace std;

 

int main() {

	int a,b;

	cin>>a;

	cin>>b;

	if(a>b){

		cout<<"a > b"<<endl;

	}

	if(a<b){

		cout<<"a < b"<<endl;

	}

	if(a==b){

		cout<<"a == b"<<endl;

	}

}

Measured memory_bytes: 3064
n, m, k = map(int, input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

for i in range(1,n):
    A[i] += A[i-1]
for i in range(1,m):
    B[i] += B[i-1]
A.insert(0,0)
B.insert(0,0)

j = m
ans = 0
for i in range(n+1):
    if A[i] > k:
        break
    
    while B[j] > k-A[i]:
        j -= 1
    ans = max(ans, i+j)

print(ans)


Measured memory_bytes: 40628
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}



int main(){
    int n;cin>>n;
    VEC(int,l,n);
    sort(ALL(l));
    int sum = 0;
    rep(i,n-1)sum += l[i];
    cout<<(l[n-1]<sum ? "Yes":"No");
}



Measured memory_bytes: 256
/// Kazuki Hoshino


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
//#define endl '\n'
typedef tree<
int,
null_type,less<int>,
rb_tree_tag,tree_order_statistics_node_update>
ordered_set;



int n,ans,w=0;
string s;

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

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

cin >> s;
n = s.size();
rep1(i, n-1,0){
       if(s[i]=='B')ans+=w;
       else w++;
}
cout << ans << endl;






return 0;}
///....


Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
using P = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int Inf = (1 << 30);
ll inf = (1LL << 60);
const int MOD = 1e9 + 7;
int main() {
	int n;
	cin >> n;
	vector<pair<string, pair<int, int>>> rest;
	rep(i, n) {
		string s;
		cin >> s;
		int a;
		cin >> a;
		int I = i + 1;
		rest.push_back(make_pair(s, make_pair(-a, I)));
	}
	sort(all(rest));
	rep(i, rest.size()) {
		cout << rest[i].second.second << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int a, b; char c;
	cin >> a >> c >> b;
	if (c == '+') cout << a + b << endl;
	if (c == '-') cout << a - b << endl;
	return 0;
}

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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = --end(s); i != begin(s); --i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
constexpr ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }

int n, m;
vector<int> g[100005];
int ans[100005];
int d[100005];
void solve() {
    cin >> n >> m;

    rep(i, n + m - 1) {
        int a, b; cin >> a >> b; --a, --b;
        g[a].push_back(b);
        ++d[b];
    }

    int root;
    rep(i, n) if (d[i] == 0) { root = i; break; }

    std::queue<int> que;
    que.push(root);
    ans[root] = -1;
    while (!que.empty()) {
        auto p = que.front(); que.pop();

        rep(i, g[p].size()) {
            auto v = g[p][i];
            --d[v];
            if (d[v] == 0) {
                ans[v] = p;
                que.push(v);
            }
        }
    }

    rep(i, n) cout << ans[i] + 1 << endn;

}

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


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

using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
// vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'


signed main() {
    int n, k;
    cin >> n >> k;
    vl a(n);
    rep (i, n) cin >> a[i];

    vl sum1(n + 1), sum2(n + 1);
    rep (i, n) {
        sum1[i + 1] = sum1[i] + a[i];
        if (a[i] > 0) sum2[i + 1] = sum2[i] + a[i];
        else sum2[i + 1] = sum2[i];
    }
    DEBUG_VEC(sum1);
    DEBUG_VEC(sum2);

    ll ans = 0;
    for (int i = 0; i + k <= n; i++) {
        chmax(ans, sum2[i] + max(0LL, sum1[i + k] - sum1[i]) + (sum2[n] - sum2[i + k]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 5760
N,K = map(int,input().split())
h = list(map(int,input().split()))
inf = float("inf")
dp = [0]*N
dp[0] = 0
dp[1] = abs(h[1]-h[0])

for i in range(2,N):
  cost = []
  for j in range(1,min(K,i)+1):
    cost.append(dp[i-j] + abs(h[i]-h[i-j]))
  dp[i] = min(cost)
print(dp[-1])

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

using namespace std;

int main() {
    long long Q, H, S, D, N, ans = 0;
    cin >> Q >> H >> S >> D >> N;
    N *= 4;
    H = min(H, 2*Q);
    S = min(S, 2*H);
    D = min(D, 2*S);
    ans += D * (N / 8);
    N = N % 8;
    ans += S * (N / 4);
    N = N % 4;
    ans += H * (N / 2);
    N = N % 2;
    ans += N * (Q / 2);
    cout << ans << endl; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pw (ll)pow 
#define MAX 1000005
using namespace std;

int main()	
{
	int n;
	cin >> n;
	ll x,s=0;
	map<int,int> mp;
	for(int i=0; i<n; i++)	{
		cin >> x;
		s+=x;
		if(mp.find(x)!=mp.end())	mp[x]++;
		else mp.insert({x,1});
	}
	int q;
	cin >> q;
	while(q--)	{
		int b,c;
		cin >> b >> c;
		mp[c]+=mp[b];
		s+=(c-b)*mp[b];
		mp[b]=0;
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 7952
#include <iostream>
using namespace std;
int main(){
  int a,b,c,x;
  int count;
  
  cin >> a >> b >> c >> x;
  
    for(int i = 0; i<= a; i++){
      for(int j = 0; j <= b; j++){
        for(int k = 0; k <= c; k++){
          if(500*i + 100*j + 50*k == x)
            count++;
        }
      }
    }
  cout << count << endl;
}

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

int main() {
    string s;
    cin >> s;
    vector< int> v(26, 0);
    for (char c : s) v[c - 'a'] ^= 1;
    if (accumulate(v.begin(), v.end(), 0)) puts("No");
    else puts("Yes");
}

Measured memory_bytes: 256
def checker(L1, L2):
    N = len(L1)
    for i in range(N):
        if L1[i] == L2[i] or L1[i] == "?":
            pass
        else:
            return False
 
    return True
 
 
def solve():
    while 1:
        try:
            S_prime = list(input())
            T = input()
            if len(T) > len(S_prime):
                print("UNRESTORABLE")
                raise EndLoop
            elif S_prime.count("?") == 0:
                if T in "".join(S_prime):
                    print("".join(S_prime))
                    raise EndLoop
                else:
                    print("UNRESTORABLE")
                    raise EndLoop
            elif S_prime.count("?") == len(S_prime):
                S = "".join(["a" for _ in range(len(S_prime) - len(T))]) + T
                print(S)
                raise EndLoop
 
            possible_ans = []
            for i in range(len(S_prime) - len(T) + 1):
                tmp_str = list(S_prime[i:len(T) + i])
                if checker(tmp_str, T):
                    if i + len(T) == len(S_prime):
                        S = "".join(S_prime[:i]) + "".join(T)
                        possible_ans.append(S.replace("?", "a"))
                    else:
                        S = "".join(S_prime[:i]) + T + "".join(S_prime[i + len(T):])
                        possible_ans.append(S.replace("?", "a"))
                        
            if len(possible_ans) == 0:
                print("UNRESTORABLE")
            else:
                print(min(possible_ans))
            break
        except:
            break
 
 
solve()

Measured memory_bytes: 3188
fn solve(n: &str) -> &str {
    let p = "Possible";
    let i = "Impossible";
    let n: usize = n.parse().unwrap();
    let mut a = String::new();
    std::io::stdin().read_line(&mut a).unwrap();
    let a: Vec<usize> = a.split_whitespace().map(|x|x.parse().unwrap()).collect();
    let &l=a.iter().min().unwrap();
    let &r=a.iter().max().unwrap();
    if n<=r { return i; }
    let mut c = vec![0;n];
    for v in a { c[v]=c[v]+1; }
    if c[l]>2 || l-c[l]+1 != r-l { return i; }
    for &v in c[l+1..r+1].iter() { if v<2 { return i; } }
    p
}
fn main() {
    loop {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let s = s.trim_right();
        if s=="" { break; }
        println!("{}",solve(&s));
    }
}

Measured memory_bytes: 380
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;

namespace AIZU {
	class Program {
		#region Reserve
		static int cin() { return cin(-1); }
		static int cin(int D) {
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return D;
			return int.Parse(s);
		}
		static int[] cins(char spliter) {
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return new int[] { };
			string[] ss = s.Split(spliter);
			int[] Res = new int[ss.Length];
			for (int i = 0; i < ss.Length; i++)
				Res[i] = int.Parse(ss[i]);
			return Res;
		}
		static int[] cins() { return cins(' '); }
		static void print(object j) { Console.WriteLine(j.ToString()); }
		static void print(string j) { Console.WriteLine(j); }
		#endregion
		
		static void Main(string[] args) {
			int N = cin();
			List<int> s = new List<int>();
			for (int i = 0; i < N; i++) {
				s.Add(cin());
			}
			int Res = s.Sum();
			var odd = s.Where(i => i % 10 != 0);
			if (odd.Count() == 0) print(0);
			else {
				if (Res % 10 == 0) 
					Res -= odd.Min();
				print(Res);
			}
			Console.ReadLine();
		}
		
	}
}

Measured memory_bytes: 13396
#include <cmath>
#include <iostream>
#include <cassert>
#include <string>
#include <vector>
#include <algorithm>

typedef long long LL;

int main() {
  int M, K; std::cin >> M >> K;
  if (K == 0) {
    for (int i = 0; i < pow(2, M) - 1; ++i) {
      std::cout << i << " " << i << " ";
    }
    std::cout << pow(2, M) - 1 << " " << pow(2, M) - 1 << std::endl;
  } else if (M > 1 && K < pow(2, M)) {
    std::cout << K << " ";
    for (int m = 0; m < pow(2, M); ++m) {
      if (m == K) continue;
      std::cout << m << " ";
    }
    std::cout << K << " ";
    for (int m = pow(2, M) - 1; m > 0; --m) {
      if (m == K) continue;
      std::cout << m << " ";
    }
    std::cout << "0" << std::endl;
  } else {
    std::cout << "-1" << std::endl;
  }
}


Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  ll N;
  std::cin >> N;
  std::vector< ll > va(N, 0LL);
  for (ll i = 0; i < N; i++) {
    std::cin >> va[i];
  }

  ll cnt4 = 0LL;
  ll cnt1 = 0LL;
  for (ll i = 0; i < N; i++) {
    if (va[i] % 4 == 0) cnt4++;
    if (va[i] % 2 == 1) cnt1++;
  }
  ll cnt2 = N - cnt1 - cnt4;

  bool judge = false;
  if (cnt2 > 0 && cnt1 <= cnt4) judge = true;
  if (cnt2 == 0 && cnt1 <= cnt4 + 1) judge = true;
  if (judge) print("Yes");
  else print("No");

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+7;
vector<int >ve[N];
int mark[N];
void bfs(int start){
	queue<int>que;
	que.push(start);
	mark[start]=1;
	while(que.size()){
		int u=que.front();
		que.pop();
		for(int i=0;i<ve[u].size();i++){
			if(!mark[ve[u][i]]){
				mark[ve[u][i]]=u;
				que.push(ve[u][i]); 
			}
		}
	}
}
int main(){
	int n,m,x,y;
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>x>>y;
		ve[x].push_back(y);
		ve[y].push_back(x);
	}
	bfs(1);
	bool flag=0; 
	for(int i=2;i<=n;i++){
		if(!mark[i]){
			flag=1;
			break;
		}	
 	}
 	if(flag) puts("No");
 	else {
 		puts("Yes");
 		for(int i=2;i<=n;i++){
 			cout<<mark[i]<<endl;
		 }
	 }
	return 0;
} 

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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int n,m,root,deg[100005],vis[100005],par[100005];
vii a[100005];
vi stk;
void dfs(int node){
    vis[node]=1;
    for(auto i:a[node]){
        if(!vis[i.x]){
            dfs(i.x);
        }
    }
    stk.pb(node);
}
void solve(){
    cin>>n>>m;
    rep(i,0,n+m-1){
        int x,y;
        cin>>x>>y;
        a[x].pb({y,i});
        deg[y]++;
    }
    rep(i,1,n+1){
        if(deg[i]==0) root=i;
    }
    dfs(root);
    memset(vis,0,sizeof vis);
    rep(i,0,sz(stk)){
        for(auto j:a[stk[i]]){
            if(!vis[j.x]){
                par[j.x]=stk[i];
                vis[j.x]=1;
            }
        }
    }
    rep(i,1,n+1) cout<<par[i]<<endl;
}

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

Measured memory_bytes: 12664
# move the dice from south to north
def s2n(dice):
    aft_dice = [dice[1],dice[5],dice[2],dice[3],dice[0],dice[4]]
    return aft_dice

# move the dice from west to east
def w2e(dice):
    aft_dice = [dice[3],dice[1],dice[0],dice[5],dice[4],dice[2]]
    return aft_dice

# spin the dice to right
def rspin(dice):
    aft_dice = [dice[0],dice[2],dice[4],dice[1],dice[3],dice[5]]
    return aft_dice

# is same dice ?
def isd(dice1, dice2):
    flag = 0
    for i in xrange(4):
        for j in xrange(4):
            flag += 1 if dice1 == dice2 else 0
            dice2 = rspin(dice2)
        dice2 = s2n(dice2)

    dice2 = w2e(dice2)
    for i in xrange(4):
        flag += 1 if dice1 == dice2 else 0
        dice2 = rspin(dice2)

    dice2 = w2e(dice2)
    dice2 = w2e(dice2)
    for i in xrange(4):
        flag += 1 if dice1 == dice2 else 0
        dice2 = rspin(dice2)
    return flag

# MAIN
dices = []
n = input()
for i in xrange(n):
    dices.append( map(int, raw_input().split()) )

for i in xrange(n-1):
    for j in xrange(i+1,n):
        if isd(dices[i], dices[j]) > 0:
            print "No"
            exit()
print "Yes" 

Measured memory_bytes: 6504
#include <bits/stdc++.h>
#include<unordered_map>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 50
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S;
ll ans = 0;

int main() {
	cin >> S;
	if (S[0] == S[1] || S[1] == S[2] || S[2] == S[0])cout << "No";
	else cout << "Yes";
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
using namespace std;
typedef long long ll;
int n,a,b;
vector<int>v[2];
void out(int x,int y){
	cout << (v[x][y]^a) << ' ';
}
int main(){
	ios::sync_with_stdio(false);
	cin >> n >> a >> b;
	v[0].push_back(0);
	v[1].push_back(1);
	for(int i=2; i<=n ;i++){
		for(int j=(1<<(i-2))-1; j>=0 ;j--){
			v[0].push_back(((1<<(i-1)))|v[0][j]);
			v[1].push_back(((1<<(i-1)))|v[1][j]);
		}
	}
	int curx,cury;
	for(int i=0; i<v[0].size() ;i++){
		if(v[0][i]==(a^b)) curx=0,cury=i;
		if(v[1][i]==(a^b)) curx=1,cury=i;
	}
	if((curx+cury)%2==0){
		cout << "NO\n";
		return 0;
	}
	cout << "YES\n";
	for(int i=0; i<cury ;i++){
		if(i&1){
			out(1,i);out(0,i);
		}
		else{
			out(0,i);out(1,i);
		}
	}
	for(int i=cury; i<v[0].size() ;i++){
		out(1^curx,i);
	}
	for(int i=v[0].size()-1; i>=cury ;i--){
		out(curx,i);
	}
}

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

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;

using ld = long double;
using vd = vector<double>;
using vvd = vector<vd>;

using vb = vector<bool>;
using vvb = vector<vb>;

#define FOR(i,a,b) for(ll i=(a); i < (b); (i)++)

#define DBG 0
#define TR(X) ({if (DBG) cerr << "TR " << (#X) << " = " << (X) << endl; })
#define TRM(i,j,c) ({if (DBG) cerr << "TR (" << (i) << ", " << (j) << ") = " << (c)[i][j] << endl;})

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

    ll N;
    cin >> N;

    vl a(N);
    FOR(i,0,N)
        cin >> a[i];

    vvl dp(N+1, vl(N));

    FOR(i,1,N+1) FOR(j,0,N) {
        ll k = j+(i-1);
        if(k >= N)
            continue;

        if(j+1 >= N) {
            dp[i][j] = a[k] - dp[i-1][j];
        } else {
            dp[i][j] = max(a[j] - dp[i-1][j+1], a[k] - dp[i-1][j]);
        }
        TR(k);
        TRM(i,j,dp);
    }

    cout << dp[N][0] << endl;
}


Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
int main()
{
	// #ifndef ONLINE_JUDGE
 //    freopen("input.txt", "r", stdin);
 //    freopen("output.txt", "w", stdout);
	// #endif
    cin.sync_with_stdio(0);
    cin.tie(0); cin.exceptions(cin.failbit);
	string s,t;
	cin>>s>>t;
	if(s.size()!=t.size()-1)
		cout<<"No";
	else{
		rep(i,0,s.size())
		{
			if(s[i]!=t[i])
			{
				cout<<"No";return 0;			}
		}
		cout<<"Yes"<<endl;
	}
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define ll long long
#define f   first
#define s   second
#define pb          push_back
#define mod         1000000007
#define hell        998244353
#define inf         1000000000000000000LL
using namespace std;
ll n,k,m;
//ll dp[15][1005];
vector<ll> primes;
bool prime[10000005];
/*void SieveOfEratosthenes(int n) 
{ 
     
    memset(prime, true, sizeof(prime)); 
  
    for (ll p=2; p*p<=10000005; p++) 
    { 
        if (prime[p] == true) 
        {  
            for (ll i=p*p; i<=10000005; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (ll p=2; p<=n; p++) 
       if (prime[p]) 
          primes.pb(p); 
} */
void solve()
{   ll X,Y,Z;
    cin>>n;
    ll ans=0;
    ll x=n-1;
    set<ll> s1;
    for(ll i=1;i*i<=x;i++){
        if(x%i==0) {s1.insert(i);s1.insert(x/i);}
    }   
    for(ll i=2;i*i<=n;i++)
    {   ll y=n;
        if(y%i==0)
        {
            while(y%i==0) y/=i;
            if(y%x==1) s1.insert(i);
        }
        if(n%i==0 && i*i!=n)
        {
            y=n;
            while(y%i==0) y/=i;
            if(y%i==1) s1.insert(i);
        }
        
    }
    s1.erase(1);s1.insert(n);
    cout<<s1.size();
    
    
}

int main()
{   //seive();
    ll t=1;
    //cin>>t;
    while(t--)
        solve();

}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1'000'000'000'000'000'000;
namespace utils{
    template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
    template<class T> using min_queue = p_queue<T, greater<T>>;
    template<class T> using max_queue = p_queue<T, less<T>>;

    template<class T> bool min_update(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
    template<class T> bool max_update(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }
    using V_Set = unordered_set<int>;
    using E_Set = unordered_map<int, V_Set>;

#define ALL(x) begin(x), end(x)
#define rALL(x) rbegin(x), rend(x)
}
using namespace utils;


void sub_main(istream &is) {
    ll K, X;
    is >> K >> X;
    if(!is) return;
    for (int i = -K+1; i < K; ++i) {
        cout << X + i << ' ';
    } // end i
    cout << endl;

}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    string test_cases = "test_B.txt";
    cerr << "DEBUG MODE" <<  endl;
    cerr << test_cases << " -->" << endl;
    auto fs = fstream(test_cases, fstream::in);
    int lp = 0;
    while(fs) {
        lp++;
        cout << lp <<  "#------\n";
        sub_main(fs);
    }
    cout << "------#" << endl;
    if(lp <= 1) sub_main(cin);
#else
    sub_main(cin);
#endif
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<queue>
using namespace std;
priority_queue<int> pq;

int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		int x;
		scanf("%d",&x);
		pq.push(x);
	}
	for(int i=0;i<m;i++){
		int price=pq.top(); pq.pop();
		price/=2;
		pq.push(price);
	}
	long long sum=0;
	int i=0;
	while(i<n){
		sum+=pq.top();pq.pop();
		i++;
	}
	printf("%lld\n",sum);

}


Measured memory_bytes: 892
#include <iostream>
#include <bits/stdc++.h>
#define int long long
#define sc(x) scanf("%lld",&(x));
#define sci(x) scanf("%d",&(x));
#define si signed
#define P pair<int,int>
#define fi first
#define se second

using namespace std;
int n,m;
string s;
si main() {
    cin>>s;
    int len = s.length();
    for(int i=0;i<len;i++){
        if(s[i]!=s[len-i-1]){
            puts("No");
            return 0;
        }
    }
    int k = (len-1)/2;
    for(int i=0;i<k;i++){
        if(s[i]!=s[k-i-1]){
            puts("No");
            return 0;
        }
    }
    k = (len +1)/2;
    for(int i=k;i<len;i++){
        if(s[i]!=s[len-i-1]){
            puts("No");
            return 0;
        }
    }
    puts("Yes");


    return 0;
}


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

int main() {
  ll x,y; cin >> x >> y;
  ll h = 0;
  if(y%2!=0) h++;
  if(4*x<y) h++;
  if(2*x>y) h++;
  
  if(h>0) cout << "No" << endl;
  else cout << "Yes" << endl;
    
  return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ms memset
#define MOD 1000000007
#define sp fixed<<setprecision
#define sz sizeof
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
bool pr[1000007];
ll fpow(ll x,ll y){x=x%MOD;ll res=1;while(y){if(y&1)res=res*x;res%=MOD;y=y>>1;x=x*x;x%=MOD;}return res;}
ll inv(ll a,ll m=MOD){ll c=m;ll y=0,x=1;if(m==1)return 0;while(a>1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=c;return x;}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n;
	cin>>n;
	ll a[n];
	ll sum=0;
	for(int i=0;i<n;i++)
	{
	cin>>a[i];
	sum+=a[i];
}
ll dp[n][n];
for(int i=n-1;i>=0;i--)
{
	for(int j=i;j<n;j++)
	{
		if(i==j)
		dp[i][j]=a[i];
		else if(j==i+1)
		dp[i][j]=max(a[i],a[j]);
		else
		{
			ll choice1=a[i]+min(dp[i+2][j],dp[i+1][j-1]);
			ll choice2=a[j]+min(dp[i][j-2],dp[i+1][j-1]);
			dp[i][j]=max(choice1,choice2);
		}
	}
}
cout<<2*dp[0][n-1]-sum;
}


Measured memory_bytes: 46464
#define FNAME ""

#include <bits/stdc++.h>

#define forn(i, n) for (int i = 0; i < (n); i++)
#define forab(i, a, b) for (int i = (a); i < (b); i++)
#define fornr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(), v.end()

using namespace std;

typedef long long LL;
typedef LL ll;
typedef unsigned long long ULL;
typedef ULL ull;
typedef long double LD;
typedef vector <int> vi;
typedef pair <int, int> pii;
const int M = 1e5 + 10;
ll a[M];
vector<int> g[M];

void fin() { 
    cout << "NO";
    exit(0);
}

void dfs(int v, int p) {
//    cerr << v << endl;
    ll su = 0;
    int x = 0;
    vector<ll> vx;
    for (auto u : g[v]) {
        if (u == p) continue;
        x++;
        dfs(u, v);
        su += a[u];
        vx.pb(a[u]);
    }
    ll tmp = su - a[v];
    sort(vx.begin(), vx.end());
    ll ma;
    ll su2 = 0;
    if (x) {
     for (int i = 0; i < (int)vx.size() - 1; i++) su2 += vx[i];
        if (su2 >= vx.back())
            ma = su / 2;
        else
            ma = su2;
    }
    if (v == 1) {
        if (x == 1) {
            if (su != a[v]) fin();
        } else {
            if (tmp > ma) fin();
            if (!(0 <= tmp && tmp <= a[v])) fin();
            a[v] -= tmp;
             if (a[v]) fin();
        }
        cout << "YES";
        exit(0);
        
    }
    if (x == 0) return;
    if (x == 1) {
        if (su != a[v]) fin();
    } else {
        if (tmp > ma) fin();
        if (!(0 <= tmp && tmp <= a[v])) fin();
        a[v] -= tmp;
    }
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
#ifdef LOCAL
    freopen(FNAME".in", "r", stdin);
    freopen(FNAME".out", "w", stdout);
#endif
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 0; i < n - 1; i++) {
        int s, f;
        cin >> s >> f;
        g[s].pb(f);
        g[f].pb(s);


    }
    dfs(1, -1);
    if (a[1]) fin();
    cout << "YES\n";



    return 0;
}

Measured memory_bytes: 17152
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll n, cnt[100], dp[110000];
int main(){
    cin >> n;
    string s;
    string t;
    cin >> s >> t;
    dp[0] = 1;
    REP(i, n){
        dp[i] += cnt[t[i] - 'a'];
        dp[i] %= MOD;
        cnt[s[i] - 'a'] += dp[i];
        cnt[s[i] - 'a'] %= MOD;
    }
    cout << dp[n - 1] << endl;
}




Measured memory_bytes: 4096
#include<iostream>
using namespace std;
int main(){
    int N,ans = 0,max_value = 0;
    cin>>N;
    for(int i=0;i<N;i++){
        int p;
        cin >>p;
        max_value = max(max_value,p);
        ans += p;
    }
    ans -= max_value/2;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

#define rep(i, c) for(int i = 0; i < int(c); i++)
#define ALL(obj) (obj).begin(), (obj).end() //sort(ALL(obj))みたいな



using namespace std;

int main() {
  int a,n,ans;
  cin >> a;
  vector<int> v;
  rep(i, a) {
    cin >> n;
    v.push_back(n);
  }
  ans = v.size();
  sort(ALL(v));
  v.erase(unique(ALL(v)), v.end());

  if (ans == v.size()) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 1400
N = int(input())
A = [0] * N

# 連結成分数＝ノード数-辺の数
# これを集合単位（L,R）単位ではなく、ノードごとに注目して計算できる、と言うこと。
for i in range(N):
  A[i] = (i+1) * (N-i)
ans = sum(A)

#print(A)
for _ in range(N-1):
  u,v = map(int, input().split())
  if u > v:
    u,v = v-1,u-1
  else:
    u,v = u-1,v-1
  ans -= (u+1) * (N-v)
  
print(ans)


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

int main(){
  int n,z,x,y; 
  string s,t;
  cin >>n>>s>>t ;
  vector<int> a(n);
  vector<int> sum(n);
  z=0;
   for(int i=0;i<n;i++){cout<<s[i];
                       cout<<t[i];}
cout<<endl;       
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static final long MOD = 1_000_000_007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt(), w = sc.nextInt(), k = sc.nextInt();
        long[][] dp = new long[h + 1][w + 2];
        dp[0][1] = 1;
        for (int i = 0; i < h; i++) {
            for (int j = 1; j <= w; j++) {
                long left = j - 2;
                long right = w - j - 1;
                long Straight = myPow(left) * myPow(right);
                long Left = myPow(left - 1) * myPow(right);
                long Right = myPow(left) * myPow(right - 1);
                dp[i + 1][j] = dp[i][j] * Straight + dp[i][j - 1] * Left + dp[i][j + 1] * Right;
                dp[i + 1][j] %= MOD;
            }
        }
        System.out.println(dp[h][k]);
    }

    static long myPow(long weight) {
        if (weight <= 0) return 1;

        long retV = 0;
        loop:
        for (int j = 0; j < (1L << weight); j++) {
            verify:
            for (int k = 0; k < weight; k++) {
                if (k == 0) continue verify;
                if (((j >> k) & 1) == 1 && ((j >> k - 1) & 1) == 1) continue loop;
            }
            retV++;
        }
        return retV;
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
int N,M;
vector<int> v;
int same[100001];//1ペアで1
int p[100001];
int main(){
        REP(i,100001){
            same[i]=0;
            p[i]=0;
        }
	cin>>N>>M;
	//Mが1の対策
	if(M==1){
	   cout<<N/2<<endl;
	   return 0;
	}
	REP(i,N){
	    int a;
	    cin>>a;
            v.push_back(a);
	}
        sort(v.begin(),v.end());
        int temp=v[0];
        p[temp%M]++;
        for(int i=1;i<N;i++){
            if(v[i]==temp){
               same[temp%M]++;
               p[temp%M]++;
               if(i!=N-1){
                  temp=v[i+1];
                  p[temp%M]++;
               }
               i++;
               continue;
            }
            temp=v[i];
            p[temp%M]++;
        }
      /*  REP(i,M){
            cout<<"p["<<i<<"]="<<p[i]<<" "<<same[i]<<endl;
        }*/
        long long ans=0;
        REP(i,M/2+1){
            if(i==0){
                ans+=p[i]/2;
                continue;
            }
            if((M%2==0)&&(i==M/2)){
                ans+=p[i]/2;
               // cout<<p[i]/2<<endl;
                break;
            }
            int a=min(p[i],p[M-i]);
            //cout<<p[i]<<"a"<<p[M-i]<<endl;
            p[i]-=a;
            p[M-i]-=a;
            ans+=a;
            int b=min(p[i]/2,same[i]);
            int c=min(p[M-i]/2,same[M-i]);
            ans+=b;
            ans+=c;
            //cout<<a<<" "<<b<<" "<<c<<endl;
        }
        cout<<ans<<endl;
	return(0);
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);


int main(){
  int X;
  cin >> X;
  int f=0;
  int x=X;
  while(x>0){
    f += x%10;
    x /= 10;
  }
  cout << (X%f==0 ? "Yes" : "No") << endl;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int dp[100000+9], h[100000+9], n, k;
unsigned int OO = 2e9;
int solve(int cur=0){
    if(cur == n-1) return 0;
    int &ret=dp[cur];
    if(ret!=-1) return ret;
    ret=OO;

    int last=min(cur+k, n-1);
    for(int i=cur+1;i<=last;i++){
        ret=min(ret, solve(i)+abs(h[cur]-h[i]));
    }

    return ret;

}

int main(){
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++) dp[i]=-1;
    for(int i=0;i<n;i++) scanf("%d",&h[i]);
    printf("%d",solve());
    return 0;
}


Measured memory_bytes: 4096
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int x,ans,k;
int main(){
	scanf("%d",&x);
	if(x==1){printf("1");return 0;}
	for(int i=2;i<=x;++i){
		int j=2;
		k=pow(i,j);
		while(k<=x){
			ans=max(ans,k);
			if(ans==x){printf("%d",ans);return 0;}
			k=pow(i,++j);
		}
	}
	printf("%d",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;

typedef pair<int,int>P;

struct edge{
	int to;
	int cost;
};

const int MAX_N = 5001;

int n,k;
ll d[MAX_N];
int c[MAX_N];
int r[MAX_N];
int dd[MAX_N][MAX_N];
deque<int> deq;
vector<int> G[MAX_N];
vector<edge> GG[MAX_N];

void dijkstra(int s)
{
	priority_queue<P,vector<P>,greater<P> > que;
	d[s] = 0;
	que.push(P(0,s));
	while(!que.empty()){
		P p = que.top();
		que.pop();
		int v = p.second;
		if(d[v] < p.first) continue;
		vector<edge>::iterator it = GG[v].begin();
		while(it != GG[v].end()){
			if(d[it->to] > d[v] + it->cost){
				d[it->to] = d[v] + it->cost;
				que.push(P(d[it->to],it->to));
			}
			it++;
		}
	}
}

int main()
{
	int x,y;
	scanf("%d%d",&n,&k);
	rep(i,n){
		scanf("%d%d",&c[i],&r[i]);
	}
	rep(i,k){
		scanf("%d%d",&x,&y);
		G[x-1].push_back(y-1);
		G[y-1].push_back(x-1);
	}
	rep(i,n){
		fill(dd[i],dd[i]+n,INF);
		deq.push_back(i);
		dd[i][i]=0;
		while(!deq.empty()){
			int u = deq[0];
			deq.pop_front();
			rep(j,G[u].size()){
				if(dd[i][G[u][j]]>dd[i][u]+1){
					dd[i][G[u][j]]=dd[i][u]+1;
					deq.push_back(G[u][j]);
				}
			}
		}
	}
	rep(i,n){
		rep(j,n){
			if(dd[i][j]<=r[i]){
				edge e;
				e.to = j,e.cost=c[i];
				GG[i].push_back(e);
			}
		}
	}
	fill(d,d+n,(1LL << 60));
	dijkstra(0);
	printf("%lld\n",d[n-1]);
	return 0;
}

Measured memory_bytes: 225384
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <list>
#include <string>
#include <map>
#include <vector>
#include <stack>
#include <queue>
using namespace std;
#define REPD(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) REPD(i, 0, n)
typedef long long ll;
#define fin(ans) cout << (ans) << '\n'
/*

*/
int main()
{
    ll X;
    cin >> X;
    REPD(i,-200,201){
        REPD(j,-200,201){
            if((ll)i*i*i*i*i-(ll)j*j*j*j*j == X){
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3164
N = int(input())
tmp = []
Cnt = []

for i in range(1, N+1):
    cnt = 0
    for j in range(1, i+1):
        if i % 2 != 0 and i % j == 0:
            cnt += 1
    tmp.append(cnt)
    if cnt == 8:
        Cnt.append(cnt)

print(len(Cnt))

Measured memory_bytes: 9180
def resolve():
    S = input()
    sub = "BW"
    cnt = 0
    sum = 0

    # 左端からのWと右端からのBは無関係のため除外
    st = 0
    end = 0
    for i, s in enumerate(S):
        if s == "B":
            break
        else:
            st += 1

    for i, s in enumerate(S[::-1]):
        #print(s)
        if s == "W":
            break
        else:
            end += 1

    #print(st, end)
    S = S[st:len(S)-end]
    #print(S)

    foundB = False
    for i, s in enumerate(S):
        if s == "B":
            cnt += 1
            foundB = True
        elif s == "W":
            sum += cnt
            foundB = False
        
        #print(s, cnt, sum)

    print(sum)


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 9236
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    char c;
    cin >> c;
    c++;
    cout << c << endl;
}


Measured memory_bytes: 764
N = int(input())
a = map(int,input().split())
A = list(a)
A.sort(reverse = True)
ans = 0
_ans = 0
for i in range(N):
  _i = i * 2
  if _i <= N-1 :
    ans += A[_i]
for _q in range(N):
  _ii = _q * 2 +1    
  if _ii <= N-1:
    _ans -= A[_ii]
print(ans + _ans)



Measured memory_bytes: 3060
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int k,x;
    cin >> k >> x;
    for(int i = x -k+1; i<= x+k-1; ++i)
    {
        cout << i << ' ';
    }



    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	int a,b,c,i;
	scanf("%d %d",&a,&b);
	c = b;
	i = 0;
	while(c >= 1)
	{
		c /= 10;
		i++;
	}
	float sum =a * pow(10,i) + b;
	if((int)sqrt(sum) * (int)sqrt(sum) == sum)
		printf("Yes\n");
		else
			printf("No\n");
			return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define vi vector<int>
#define lvi vector<long long>
#define pi pair<int,int>
#define lpi pair<long long ,long long>
#define mp make_pair
#define pb push_back
#define ll long long 
#define N 100005
#define faltu ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mod 1000000007
#define mod1 1000000000000000007
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>multiordered_set;
ll int pw(ll int a, ll int b,ll md) {
    if (b == 0) return 1;
    ll int t = pw(a, b / 2,md);
    if (b % 2 == 0) return (t * t)%mod;
    else return ((t * t)%mod * a)%mod;
}
vector<int> pm;
void prm(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
              prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p]) pm.push_back(p);
}
bool cmp(const pair<ll int,ll int> &a,const pair<ll int,ll int> &b)
{
    if(a.first==b.first)return a.second<b.second;
    return a.first<b.first;
}
ll int gcd(ll int a,ll int b)
{
    if(!a)return b;
    return gcd(b%a,a);
}
bool isPrime(int n) 
{ 
    if (n <= 1) 
        return false; 
    for (int i = 2; i < n; i++) 
        if (n % i == 0) 
            return false; 
    return true; 
} 
map<int,int>pa;
int find(int i){
    if(pa[i]==i)return i;
    return pa[i]=find(pa[i]);
}     
void join(int i,int j){
    int a=find(i);
    int b=find(j);
    if(b>=a)pa[b]=a;
    else pa[a]=b;
}               
int ddx[]={-1,-1,-1,0,1,1,1,0};
int ddy[]={-1,0,1,1,1,0,-1,-1};
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
int main()
{
    faltu;
    int t=1;
    //cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int a[n+1];
        int ans=0;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        for(int i=0;i<n;i++)
        {
            for(int j=i+1;j<n;j++)
            {
                ans+=(a[i]*a[j]);
            }
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3612