akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define FORW(a, b, c) for(int a = b; a >= c; --a)
#define fi first
#define se second
#define pb push_back
#define int long long

typedef pair<int, int> ii;
typedef pair<int, ii> iii;

const int N = 2e5 + 100;
const int oo = 1e8;
const int mod = 1e9 + 7;

int n;
int f[N], g[N], sz[N], frac[N], fracw[N], pr[N];
vector<int> vi[N], rig[N];

void add(int &x, int y) {  x = (x + y) % mod; }
void mul(int &x, int y) { x=  x % mod * (y % mod) % mod; }

int pow(int x, int y)  {
    if(!y) return 1;
    int res = 1;
    while(y > 0)    {
        if(y & 1) res = res % mod * x % mod;
        x = x * x % mod;
        y >>= 1;
    }
    return res;
}
int ckn(int k, int n)   {
    int res = frac[n];
    mul(res, fracw[n - k]);
    mul(res, fracw[k]);
    return res;
}

void dfs2(int u, int val) {
    g[u] = 1;
    if(u != 1)  {
        int cur = n - sz[u];
        g[u] = ckn(n - sz[pr[u]], cur - 1) * g[ pr[u] ] % mod * val % mod;
    }

    int cnt = rig[u].size() - 1, lef = 1, slef =  0;
    for(auto v: vi[u]) if(v != pr[u]){
        cnt --;
        dfs2(v, lef * rig[u][cnt] % mod * ckn(slef, sz[u] - sz[v] - 1) % mod);
        mul(lef, f[v] * ckn(sz[v], sz[v] + slef));
        slef += sz[v];
    }
}

void dfs1(int u,int p)    {
    sz[u] = 1; pr[u] = p;
    for(auto v: vi[u]) if(v != p)  {
        dfs1(v, u);
        sz[u] += sz[v];
    }

    f[u] = 1;
    int srig = 0; rig[u].pb(1);
    for(int i = vi[u].size() - 1; i >= 0; --i) if(vi[u][i] != p) {
        int v = vi[u][i];
        mul(f[u], f[v] * ckn(sz[v], srig + sz[v]) % mod);
        rig[u].pb(f[u]);
        srig += sz[v];
    }
}

signed main()  {
//    freopen("test.inp", "r", stdin);
//    freopen("test.out", "w", stdout);
    ios_base::sync_with_stdio(false); cout.tie(0);
    frac[0] = 1; FOR(i, 1, N - 1) frac[i] = frac[i - 1] * i % mod;
    FOR(i, 0, N - 1) fracw[i] = pow(frac[i], mod - 2);

    cin >> n;
    FOR(i, 1, n - 1)    {
        int u, v; cin >> u >> v;
        vi[u].pb(v);
        vi[v].pb(u);
    }
    dfs1(1, 1);
    dfs2(1, 1);
    FOR(i, 1, n)    {
        int res = g[i] * ckn(n - sz[i], n - 1);
        int cur = sz[i] - 1;
        for(auto v: vi[i]) if(v != pr[i])
            mul(res, f[v] * ckn(sz[v], cur)), cur -= sz[v];
        cout << res << '\n';
    }
}


Measured memory_bytes: 36720
#include<iostream>
#include<algorithm>

using namespace std;

bool comp(const pair<int, long long>& p1, const pair<int, long long>& p2)
{
    return p1.second > p2.second;
}

int main(int argc, char *argv[])
{
	int N, M;
	int L, R;
	pair<int, long long> p[100001];
	long long d[100001] = {0};
	unsigned long long A[100001];

	cin >> N >> M;
	
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A, A + N);

	for (int i = 0; i < M; i++) {
		int B;
		long long C;
		cin >> B >> C;
		p[i] = make_pair(B, C);
	}
	sort(p, p + M, comp);

	int cnt = 0;
	for (int i = 0; i < M; i++) {
		for (int j = 0; j < p[i].first; j++) {
			if (cnt == N) {
				break;
			}
			d[cnt++] = p[i].second;
		}
		if (cnt == N) {
			break;
		}
	}

	for (int i = 0; i < cnt; i++) {
		if (A[i] < d[i]) {
			A[i] = d[i];
		}
	}

	unsigned long long sum = 0;
	for (int i = 0; i < N; i++) {
		sum += A[i];
	}
	cout << sum << "\n";
	return 0;
}


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

const int MAXN = 200010;

template<typename T> inline T read() {
	T x(0), f(1);
	char ch = getchar();
	for(; !isdigit(ch); ch = getchar()) if(ch=='-') f=-1;
	for(; isdigit(ch); ch = getchar()) x = (x*10)+(ch^48);
	return x * f;
}

int e, st[MAXN], to[MAXN<<1];
int nxt[MAXN<<1];
inline void add(int u, int v) {
	to[++e] = v, nxt[e] = st[u];
	st[u] = e;
}

int E, St[MAXN], To[MAXN<<1];
int Nxt[MAXN<<1];
inline void Add(int u, int v) {
	To[++E] = v, Nxt[E] = St[u];
	St[u] = E;
}

int n, dep[MAXN], rx, ry;
int fa[MAXN][20], ans;
bool vis[MAXN], flag[MAXN];

void dfs(int u) {
	for(int i = st[u]; i; i = nxt[i]) {
		int v = to[i];
		if(v == fa[u][0]) continue;
		dep[v] = dep[u]+1;
		fa[v][0] = u, dfs(v);
	}
}

inline int LCA(int u, int v) {
	if(dep[u] < dep[v]) swap(u, v);
	for(int i = 18; i >= 0; i--) 
		if(dep[fa[u][i]] >= dep[v]) 
			u = fa[u][i];
	if(v == u) return u;
	for(int i = 18; i >= 0; i--) 
		if(fa[u][i] ^ fa[v][i])
			u = fa[u][i], v = fa[v][i];
	return fa[u][0];
}

void Dfs(int u, int d) {
	if(flag[u]) {
		printf("-1\n");
		exit(0);
	}
	vis[u] = true;
	ans = max(ans, (dep[u]-1)<<1);
	for(int i = St[u]; i; i = Nxt[i]) {
		int v = To[i];
		if(vis[v]) continue;
		if(dep[v] <= d+1) continue;
		Dfs(v, d+1);
	}
}

int main() {
	n = read<int>();
	rx = read<int>(), ry = read<int>();
	for(int i = 1; i < n; i++) {
		int u = read<int>(), v = read<int>();
		Add(u, v), Add(v, u);
	}
	for(int i = 1; i < n; i++) {
		int u = read<int>(), v = read<int>();
		add(u, v), add(v, u);
	}
	dep[ry] = 1;
	dfs(ry);
	for(int k = 1; k <= 18; k++) 
		for(int i = 1; i <= n; i++) 
			fa[i][k] = fa[fa[i][k-1]][k-1];
	for(int u = 1; u <= n; u++) {
		for(int i = St[u]; i; i = Nxt[i]) {
			int v = To[i];
			if(dep[u]+dep[v]-(dep[LCA(u, v)]<<1) > 2) 
				flag[u] = flag[v] = true;
		}
	}
	Dfs(rx, 1);
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 33280
A = []
n, q = gets.chomp.split(" ")
n.to_i.times {
    A.push([])
}

q.to_i.times{
    choice,  t, x = gets.chomp.split(" ")
     case choice
     when "0"
        A[t.to_i].push(x)
     when "1"
        puts A[t.to_i].join(' ') 
     when "2"
        A[t.to_i].clear
     end
}



Measured memory_bytes: 41344
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef long int li;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef pair<ll, ll>P;
typedef tuple<ll, int, int>T;
#define PI 3.14159265358979


int main(){
  int a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  if(a==0){cout<<1;}
  if(b==0){cout<<2;}
  if(c==0){cout<<3;}
  if(d==0){cout<<4;}
  if(e==0){cout<<5;}
  
}


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

int main(){
	string s, t, jg;
	cin >> s >> t;
	int lens=s.size(), lent=t.size(), minv=10000, cnt=0;
	
	for(int i=0; i<lens-lent+1; i++){
		jg=s.substr(i, lent);
		for(int j=0; j<lent; j++){
			if(jg[j]!=t[j]) cnt++;
		}
		if(cnt<minv) minv=cnt;
		cnt = 0;
	}
	cout << minv;
	return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long int a, b, c;
	cin >> a >> b >> c;
	if((a % 2 == 0)||(b % 2 == 0)||(c % 2 == 0)) {
		cout << "0" << endl;
	} else {
		cout << min(min(a*b, b*c), c*a) << endl;
	}

	return 0;
}

Measured memory_bytes: 256
from functools import reduce
from operator import mul
MOD = 10 ** 9 + 7

def combination(n, r, mod=None):
    r = min(n - r, r)
    if r == 0:
        return 1
    elif n < r:
        return 0
    if mod is None:
        over = reduce(mul, range(n, n - r, -1))
        under = reduce(mul, range(1, r + 1))
        return over // under
    else:
        numer = denom = 1
        for i in range(1, r + 1):
            numer = numer * (n + 1 - i) % mod
            denom = denom * i % mod
        return numer * pow(denom, mod - 2, mod) % mod


X, Y = map(int, input().split())

# a := →→↑ の個数
# b := →↑↑ の個数
# 2a + b = X
# a + 2b = Y より、
a = (2 * X - Y) / 3
b = (2 * Y - X) / 3

if a < 0 or b < 0 or not a.is_integer() or not b.is_integer():
    print(0)
    exit(0)

ans = combination(int(a + b), int(a), mod=MOD)
print(ans)

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

using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<ll> vec(1e7+1, 0);
  for (int i = 1; i <= 1e7; ++i)
    for (int j = i; j <= 1e7; j+=i)
      ++vec[j];
  ll ans = 0;
  for (ll i = 1; i <= n; ++i) {
    ans += i * vec[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 81408
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), y = scanner.nextInt();
			System.out.println(
					Arrays.stream(getResult(n, y)).mapToObj(i -> String.valueOf(i)).collect(Collectors.joining(" ")));
		}
	}

	/**
	 * @param n 合計枚数
	 * @param y 合計金額
	 * @return [1万円札の枚数, 5千円札の枚数, 1千円札の枚数]の配列
	 */
	private static int[] getResult(final int n, final int y) {
		for (int i = 0; i <= Math.min(y / 5000, n); i++) {
			int count = n - i;
			int sum = y - i * 5000;
			int diff = sum - count * 1000;
			if ((diff >= 0) && (0 == diff % 9000) && (diff / 9000 <= count)) {
				return new int[] { diff / 9000, i, count - diff / 9000 };
			}
		}
		return new int[] { -1, -1, -1 };
	}
}


Measured memory_bytes: 36160
import java.util.*;
import java.lang.*;


public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        double a = sc.nextDouble();
        double b = sc.nextDouble();
        double x = sc.nextDouble();

        double bottleCapacity = a*a*b;

        if(x*2 < bottleCapacity){
            //solve a*b*b/2tan8 == x
            System.out.println(Math.toDegrees(Math.atan(a*b*b/(2*x))));
        }else{
            //solve a*a*a*tan8/2 = cap-x
            System.out.println(Math.toDegrees(Math.atan(2*(bottleCapacity-x)/(a*a*a))));
        }

    }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
#include <stdlib.h>
#include <numeric>
#include <string>
using namespace std;
int main(){
  	int N, i, j;

    cin >> N;
	  double A[N], B[N], ans;

    for(i=0; i<N; i++){
      cin >> A[i];
    }
    if(N==2){
      ans=(A[0]+A[1])/2;
    }else{
      sort(A, A+N);
      ans=ans=(A[0]+A[1])/2;
      for(i=2; i<N; i++){
      ans=(ans+A[i])/2;
      }
    }

      cout <<std::fixed<< ans <<endl;

    
}

Measured memory_bytes: 256
s = input()
t = input()

match_ans = 0

for i in range(len(s)-len(t)+1):
    tgt_pos = i
    match_cnt = 0
    for j in range(len(t)):
        if s[tgt_pos+j] == t[j]:
            match_cnt += 1
    match_ans = max(match_ans,match_cnt)

print(len(t) - match_ans)

Measured memory_bytes: 9084
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const long long MOD = 998244353;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll = long long;
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())
#define RSORT(v) std::sort(v.rbegin(), v.rend())
constexpr auto PI = 3.14159265358979323846264338327950L;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int D, G;
    cin >> D >> G;
    vector<int> p(D), c(D);
    for (int i = 0; i < D; ++i) {
        cin >> p[i] >> c[i];
    }
    int ans = INF;
    for (int bit = 0; bit < (1 << D); ++bit) {
        int sum = 0;
        int now = 0;
        for (int i = 0; i < D; ++i) {
            if (bit & (1 << i)) {
                sum += 100 * p[i]*(i+1) + c[i];
                now += p[i];
            }
        }
        for (int j = D; j--;) {
            if (bit & (1 << j))continue;
            for (int k = 0; (k<p[j]&&sum<G); ++k) {
                sum += 100 * (j + 1);
                ++now;
            }
        }
        ans = min(ans, now);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! { n:i64, };

    let unit_digit = n % 10;

    let ans = match unit_digit {
        2 | 4 | 5 | 7 | 9 => "hon",
        0 | 1 | 6 | 8 => "pon",
        3 => "bon",
        _ => unreachable!(),
    };

    println!("{}", ans);
}

Measured memory_bytes: 2124
#include<iostream>
#include<cstdio>
using namespace std;
int a,b,c,i,j,k[10];
int che(int n){
	while(n>0){
		if(k[n%10]){
			return 1;
		}
		n/=10;
	}
	return 0;
}
int main(){
	cin>>a>>b;
	for(i=1;i<=b;i++){
		int t;
		cin>>t;
		k[t]=1;
	}
	while(che(a)){
		a++;
	}
	cout<<a<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const int INF=1000000000;

int D;
string K;
LL memo[100001][2][101];


int dfs(int k,bool t,int p){
    if(~memo[k][t][p]) return memo[k][t][p];
    if(k==K.length()) return memo[k][t][p]=(p%D==0?1:0);
    int x=(t?K[k]-'0':9);
    LL ret=0;
    for (int i = 0; i <= x; i++) {
        ret+=dfs(k+1,t&(i==x?1:0),(p+i)%D);    
    }
    return memo[k][t][p]=ret%mod;
}



int main(){
    cin >> K >> D;
    memset(memo,-1,sizeof(memo));
    cout << (dfs(0,1,0)+mod-1)%mod << endl;
    return 0;
}



Measured memory_bytes: 158976
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>

int main(){
  long long int P, Q, R;

  scanf("%lld%lld%lld", &P, &Q, &R);

  long long int ans = std::min(P+Q, std::min(Q+R, R+P));

  std::cerr << "Answer:" << std::endl;
  std::cout << ans << std::endl;
  return 0;
  
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
#define LLINF 2000000000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
// #define int long long

signed main(){
  int a,b;
  cin >> a >> b;
  int ma = max(a,b);
  int mi = min(a,b);
  LOOP(i,ma){
    cout << mi;
  }
}


Measured memory_bytes: 256
/*
author: orthodoxparadox
15-Sep-2018
17:18:04
*/

#include <bits/stdc++.h>
using namespace std;
#define dbl long double
#define int ll
#define ll long long
#define pii pair<int, int>
#define fup(i, a, n) for (ll i = a; i < n; i++)
#define fnu for(ll i = 0; i < n; i++)
#define rev(s) reverse(all(s))
#define oiint ostream_iterator<int>(cout, " ") 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define all(a) a.begin(), a.end()
#define initialise(a, x) memset(a, x, sizeof(a))
#define onlyunique(v) v.erase(unique(all(v)), v.end()); //only for sorted vector
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#ifdef __APPLE__
#define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << "  ";
	__f(comma + 1, args...);}
#else
#define dbg(...)
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int __gcd(int a, int b){return b ? __gcd(b, a%b) : a;}
// for unordered set of pairs
struct pair_hash {inline std::size_t operator()(const std::pair<int, int> & v) const {return v.first*31+v.second;}};
const int mod = 1e9 + 7;

vector<int> binarycut(int x){
	vector<int> v;
	while(x){
		if(x&1) v.pb(1); else v.pb(0);
		x>>=1;}
	reverse(all(v)); return v;}

int takemod(int a){return ((a%mod)+mod)%mod;}

int fast_exp(int base, int expo) {
	int res=1;
	while(expo>0) {
		if(expo&1) res=(res*base)%mod;
		base=(base*base)%mod;
		expo>>=1;}
	return res;}

int modinv(int a){return takemod(fast_exp(takemod(a), mod-2));}

// void siev(int n){
// 	sieve[0]=false; sieve[1]=false;
// 	for(int i=2; i<=sqrtl(n); i++)
// 		if(sieve[i])
// 			for(int j=i; i*j<=n; j++)
// 				sieve[i*j]=false;
// }

signed main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	#ifdef __APPLE__
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt", "w", stderr);
	#endif
	time_t t1, t2;
	t1 = clock();

	int n, x;
	cin >> n >> x;
	vector<int> v;
	fnu
	{
		int x;
		cin >> x;
		v.pb(x);
	}
	sort(all(v));
	int cnt = 0;
	fnu
	{
		if(i == n-1)
		{
			if(x == v[i])
			{
				cnt++;
				break;
			}
			else break;
		}
		if(x >= v[i])
		{
			x -= v[i];
			cnt++;
		}
		else break;
	}
	cout << cnt << endl;
	t2 = clock(); cerr << "time taken: " << t2-t1;
	return 0;
}

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

using namespace std;

typedef long long LL;
#define N 1200000

const LL mod=998244353;
LL n,m,x,ans,mu[N],pr[N],vis[N],tot,f[N],g[N];

void upd(LL &x,LL y){
	x=(x+y)%mod;
}

int main(){
	n=1000000;
	mu[1]=1; pr[1]=0;
	for (LL i=2;i<=n;++i){
		if (!vis[i]){
			pr[++tot]=i;
			mu[i]=-1;
		}
		for (LL j=1;j<=tot;++j)
			if (i*pr[j]<=n){
				vis[i*pr[j]]=pr[j];
				if (i%pr[j]==0){
					mu[i*pr[j]]=0;
					break;
				}
				mu[i*pr[j]]=-mu[i];
			}
			else break;
	}
	for (LL i=1;i<=n;++i) if (mu[i])
		for (LL j=1;i*j<=n;++j)
			upd(f[i*j],mu[i]*i*i%mod*j);
	scanf("%lld",&m);
	for (LL i=1;i<=m;++i){
		scanf("%lld",&x);
		upd(ans,-x);
		++g[x];
	}
	for (LL i=1;i<=n;++i){
		LL tmp=0;
		for (LL j=1;i*j<=n;++j)
			upd(tmp,j*g[i*j]);
		upd(ans,f[i]*tmp%mod*tmp);
	}
	ans=(ans*((mod+1)/2)%mod+mod)%mod;
	printf("%lld\n",ans);
	
	return 0;
}
			

Measured memory_bytes: 39424
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
using namespace std;
typedef long long ll;
ll mod = 1000000007;

int main() {
    ll a,b,c,k; cin >> a >> b >> c >> k;
    if (k <= a) cout << k << "\n";
    else if (k <= a + b) cout << a << "\n";
    else cout << 2 * a + b - k << "\n"; 
}

Measured memory_bytes: 3632
# ITP1_6_D
n, m = map(int, input().split())
A = [[] for i in range(n)]
B = [0 for i in range(m)]
c = [[0]*1 for i in range(m)]

for i in range(n):
    A[i] = list(map(int, input().split()))

for i in range(m):
    B[i] = int(input())

for i in range(n):
    ans = 0
    for j in range(m):
        ans += A[i][j]*B[j]
    print("%d"%(ans))


Measured memory_bytes: 6032
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll ans = 0;
    rep(i,n){
        while(a[i] % 2 == 0){
            a[i] /= 2;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

string S;
bool judge() {
  for (int i = 0; i < S.length(); ++i) {
    if (S[i] == 'R' && i % 2 != 0) {
      return false;
    }
    if (S[i] == 'L' && i % 2 != 1) {
      return false;
    }
  }
  return true;
}
int main() {
  cin >> S;
  cout << (judge() ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())

a = []
for _ in range(n):
    _, *fav = map(int, input().split())
    a.append(set(fav))

common_fav = a[0]
for i in range(1, n):
    common_fav = common_fav & a[i]
print(len(common_fav))


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

int pref[100001];

int main(void)
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	int n,q;
	std::cin>>n>>q;
	std::string s;
	std::cin>>s;
	for(int i=2;i<=n;i++)
	{
		if(s[i-1] == 'C' && s[i-2] == 'A')
		pref[i]++;
		pref[i] += pref[i-1];	
	}	
	while(q--)
	{
		int l,r;
		std::cin>>l>>r;
		int pv = pref[r] - pref[l-1];
		if((l > 1) && s[l-1] == 'C' && s[l-2] == 'A')
		pv--;	
		std::cout<<pv<<"\n";
	}
	return 0;
}

Measured memory_bytes: 1488
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

typedef unsigned long long ULLONG;
typedef long long LLONG;

template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}
static const long long MOD_NUM = 1000000007LL;

static void A_task();

int main()
{
	A_task();
	fflush(stdout);
	return 0;
}

static void A_task()
{
	int A, B;
	get2int(A, B);

	printf("%d\n", std::max(0, A - (2 * B)));
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    abc052b()
}

fun abc052b() {
    val n = readLine()!!.toInt()
    val s = readLine()!!.map { it == 'I' }

    var curr = 0
    var max = 0
    s.forEach {
        if (it) max = Math.max(max, ++curr) else curr--
    }

    println(max)
}


Measured memory_bytes: 33648
#include<bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using vll = vector<ll>;
struct mint {
  ll divisor = 998244353;
  ll val;
  constexpr mint(ll v = 0) noexcept : val(v % divisor) {
    if (val < 0) val += divisor;
  }
  constexpr mint operator + (const mint& rhs) const noexcept {
    return mint(*this) += rhs;
  }
  constexpr mint operator - (const mint& rhs) const noexcept {
    return mint(*this) -= rhs;
  }
  constexpr mint operator * (const mint& rhs) const noexcept {
    return mint(*this) *= rhs;
  }
  constexpr mint operator / (const mint& rhs) const noexcept {
    return mint(*this) /= rhs;
  }
  constexpr mint operator ~ () const noexcept {
    ll a = this->val, b = divisor, u = 1, v = 0;
    while (b > 0) {
      ll t = a / b;
      a -= t * b;
      u -= t * v;
      ll c = a; a = b; b = c;
      ll w = u; u = v; v = w;
    }
    if (u < 0) u += divisor;
    u %= divisor;
    return u;
  }
  constexpr mint& operator += (const mint& rhs) noexcept {
    val += rhs.val;
    if (val >= divisor) val -= divisor;
    return *this;
  }
  constexpr mint& operator -= (const mint& rhs) noexcept {
    if (val < rhs.val) val += divisor;
    val -= rhs.val;
    return *this;
  }
  constexpr mint& operator *= (const mint& rhs) noexcept {
    val = val * rhs.val % divisor;
    return *this;
  }
  constexpr mint& operator /= (const mint& rhs) noexcept {
    val = val * (~(mint(rhs))).val % divisor;
    return *this;
  }
  friend mint modpow (mint a, ll n) noexcept {
    auto res = mint(1);
    while(n > 0) {
      if(n&1) res *= a;
      a *= a;
      n >>= 1;
    }
    return res;
  }
  friend std::ostream& operator << (std::ostream& os, const mint& a) noexcept {
    return os << a.val;
  }
};

void answer() {
  ll N, S;
  cin >> N >> S;
  vll A(N);
  rep(i,N) cin >> A[i];
  vector<mint> dp(S+1, 0), p(S+1, 0);
  dp[0] = 1;
  rep(i,N) {
    swap(dp, p);
    repc(j,S) {
      dp[j] = p[j] * 2;
      if(A[i] <= j) dp[j] += p[j-A[i]];
    }
  }
  cout << dp[S] << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
#include <iomanip>
#include <algorithm>
#define ll long long
#include <unordered_map>
using namespace std;
 
int main() {
  ll H, W, K, cnt = 0, ans = 0;
  cin >> H >> W >> K;
  vector<vector<char>> c(H, vector<char>(W)), d(H, vector<char>(W));
  for(ll i = 0; i < H; i++) {
    for(ll j = 0; j < W; j++) cin >> c.at(i).at(j);
  }
  for(ll i = 0; i < pow(2, H); i++) {
    for(ll j = 0; j < pow(2, W); j++) {
      cnt = 0;
      for(ll k = 0; k < H; k++) {
        for(ll l = 0; l < W; l++) d.at(k).at(l) = c.at(k).at(l);
      }    
      for(ll k = 0; k < H; k++) {
        if((ll)(i / pow(2, k)) % 2 == 1) {
          for(ll m = 0; m < W; m++) d.at(k).at(m) = '.';
        }
      }
      for(ll l = 0; l < W; l++) {
        if((ll)(j / pow(2, l)) % 2 == 1) {
          for(ll n = 0; n < H; n++) d.at(n).at(l) = '.';
        }
      }
      for(ll k = 0; k < H; k++) {
        for(ll l = 0; l < W; l++) {
          if(d.at(k).at(l) == '#') cnt++;
        }
      }
      if(cnt == K) ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4080
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

A, B = MAP()
print(max(0, A-B*2))


Measured memory_bytes: 38384
/* *
 *
 * Author: Hamkor
 *
 * */
 
#include <bits/stdc++.h>

using namespace std;

/* * * *   * * *   	* * * */
typedef long long ll;
const int oo = 1e9;
const ll mod = 100000000;
typedef complex<ll> P;
#define X real()
#define Y imag()
/* * * *   * * *   	* * * */
int n;
string s; 
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string s; cin>>s;
	int o = 0, z = 0;
	for (int i=0; i<(int)s.size(); ++i) if (s[i] == '1') o++;else z++;
	cout<<2*min(z, o);
	return 0;
}

Measured memory_bytes: 512
using System;
namespace TestSpace
{
    class Test
    {
        static void Main(string[] args)
        {
            int i, j, k, l, z;
            l = 10;
            int[] arrInt = new int[l];

             for (k = 0; k < l; k++)
            {
                arrInt[k] = int.Parse(Console.ReadLine());
            }

           l = l - 1;
            for (i = 0; i < l; i++)
            {
                for (j = l; i < j; j--)
                {
                    if (arrInt[j - 1] < arrInt[j])
                    {
                        z = arrInt[j];
                        arrInt[j] = arrInt[j - 1];
                        arrInt[j - 1] = z;
                    }
                }
            }
            Console.WriteLine("{0}", arrInt[0]);
            Console.WriteLine("{0}", arrInt[1]);
            Console.WriteLine("{0}", arrInt[2]);
        }
    }
}



Measured memory_bytes: 15936
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<functional>
#include<utility>

using namespace std;

const long long INF = (1LL << 62); 
vector<vector<pair<int, int>>> a, b;
int n;

struct edge{
    int to, cost;
};

void dijkstra(int s, vector<vector<edge>> g, vector<long long>& c){
    c[s] = 0;
    priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> q;
    q.push({0LL, s});
    while(!q.empty()){
        auto p = q.top();
        q.pop();
        int f = p.second;
        if(c[f] < p.first) continue;
        for(int i = 0; i < g[f].size(); i++){
            edge e = g[f][i];
            if(c[f] + e.cost < c[e.to]){
                c[e.to] = c[f] + e.cost;
                q.push({c[e.to], e.to});
            }
        }
    }
}

int main(){
	int m, s, t;
	cin >> n >> m >> s >> t;
    vector<vector<edge>> a(n + 1);
    vector<vector<edge>> b(n + 1);
    for(int i = 0; i < m; i++){
        int u, v, x, y;
        cin >> u >> v >> x >> y;
        a[u].push_back({v, x});
        a[v].push_back({u, x});
        b[u].push_back({v, y});
        b[v].push_back({u, y});
    }
    vector<long long> c1(n + 1, INF), c2(n + 1, INF), ans(n + 1);
    dijkstra(s, a, c1);
    dijkstra(t, b, c2);
    for(int i = 1; i <= n; i++){
        ans[i] = c1[i] + c2[i];
    }
    for(int i = n - 1; i > 0; i--){
        ans[i] = min(ans[i], ans[i + 1]);
    }
    for(int i = 1; i <= n; i++){
        cout << (long long)1e15 - ans[i] << endl;
    }
	return 0;
}


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

using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define inf 1000000100

int main()
{
    int n;
    cin >> n;
    vi time;
    ll totaltime = 0;
    while(n--)
    {
        int t;
        cin >> t;
        time.pb(t);
        totaltime += t;
    }
    int m;
    cin >> m;
    while(m--)
    {
        int p, x;
        cin >> p >> x;
        cout << totaltime - (time[p-1] - x) << endl;
    }
}

Measured memory_bytes: 256
import copy


H, W, M = map(int, input().split())
hw1 = [tuple(map(int, input().split())) for _ in range(M)]
hw2 = copy.deepcopy(hw1)
ans1 = 0
ans2 = 0

# hから見る
h_cnt = [0 for _ in range(3*10**5 + 3)]
w_cnt = [0 for _ in range(3*10**5 + 3)]
for h, w in hw1:
    h_cnt[h] += 1
    w_cnt[w] += 1

h_max = -1
h_idx = 999999999999

for i in range(len(h_cnt)):
    if h_cnt[i] > h_max:
        h_max = h_cnt[i]
        h_idx = i
    elif h_cnt[i] == h_max:
        if w_cnt[i] > w_cnt[h_idx]:
            h_idx = i


L = []
for i in range(len(hw1)):
    h, w = hw1[i]
    if h == h_idx:
        ans1 += 1
        L.append(hw1[i])

hw1 = list(set(hw1) - set(L))

w_cnt = [0 for _ in range(3*10**5 + 3)]
for h, w in hw1:
    w_cnt[w] += 1

w_max = -1
w_idx = 999999999999
for i in range(len(w_cnt)):
    if w_cnt[i] > w_max:
        w_max = w_cnt[i]
        w_idx = i

for h, w in hw1:
    if w == w_idx:
        ans1 += 1


# wから見る
w_cnt = [0 for _ in range(3*10**5 + 3)]
h_cnt = [0 for _ in range(3*10**5 + 3)]

for h, w in hw2:
    h_cnt[w] += 1

w_max = -1
w_idx = 999999999999

for i in range(len(w_cnt)):
    if w_cnt[i] > w_max:
        w_max = w_cnt[i]
        w_idx = i
    elif w_cnt[i] == w_max:
        if h_cnt[i] > h_cnt[w_idx]:
            w_idx = i


L = []
for i in range(len(hw2)):
    h, w = hw2[i]
    if w == w_idx:
        ans2 += 1
        L.append(hw2[i])

hw2 = list(set(hw2) - set(L))

h_cnt = [0 for _ in range(3*10**5 + 3)]
for h, w in hw2:
    h_cnt[h] += 1

h_max = -1
h_idx = 999999999999
for i in range(len(h_cnt)):
    if h_cnt[i] > h_max:
        h_max = h_cnt[i]
        h_idx = i
for h, w in hw2:
    if h == h_idx:
        ans2 += 1


print(max(ans1, ans2))


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

int main()
{
    int n;
    cin>>n;
    int ac=0,wr=0,tle=0,re=0;
    for(int i=1; i<=n; i++)
    {
        string ar;
        cin>>ar;
        if(ar=="AC")
        {
            ac++;
        }
        else if(ar=="WA")
            wr++;
        else if(ar=="TLE")
            tle++;
        else if(ar=="RE")
            re++;
    }
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wr<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl;
}


Measured memory_bytes: 3596
while True:
    H,W=map(int,input().split())
    if (H,W)==(0,0):
        break
    for i in range(H):
        if i==0 or  i==H-1:
            for j in range(W):
                if j<W-1:
                    print("#",end="")
                else:
                    print("#")
        else:
            for j in range(W):
                if j==0:
                    print("#",end="")
                elif j<W-1:
                    print(".",end="")
                else:
                    print("#")
    print("")


Measured memory_bytes: 7004
import java.util.*;
import java.awt.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(in);
        long N=sc.nextLong();
        long M=sc.nextLong();
        if(N*2<=M){
            out.println(N+(M-2*N)/4);
        }else{
            out.println(M/2);
        }
    }
}

Measured memory_bytes: 23124
N, M, Q = map(int, input().split())


def f(i = 0, l = []):
    if i == N:
        return [l]

    t = []
    if i == 0:
        for e in range(1, M + 1):
            t += f(i+1, [e])
    else:
        for e in range(l[-1], M + 1):
            t += f(i+1, l + [e])

    return t


D = []
for _ in range(Q):
    D.append(list(map(int, input().split())))

N = f()

m = 0
for n in N:
    t = 0
    for a, b, c, d in D:
        if n[b-1] - n[a-1] == c:
            t += d
    m = max(t, m)

print(m)


Measured memory_bytes: 23236
import java.util.*;
public class Main {
	
	private static final double EPS = 1.0e-08;

	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int x = sc.nextInt();
			int y = sc.nextInt();
			int z = sc.nextInt();
			if((x|y|z) == 0) break;
			int [] xlist = new int[x];
			for(int i = 0; i < x; i++){
				xlist[i] = sc.nextInt();
			}
			
			int [][] elist = new int[y+1][3];
			for(int i = 0; i < z; i++){
				int n = sc.nextInt();
				int e = sc.nextInt();
				int a = sc.nextInt();
				elist[n][0] = e;
				elist[n][1] = a;
			}
			
			double [][] dp = new double[5001][y+1];
			dp[0][0] = 1;
			for(int i = 0; i < y; i++){
				for(int j = 0; j < 5001; j++){
					if(dp[j][i] <EPS)continue;
					for(int k = 0; k < xlist.length; k++){
						int xx = i + xlist[k];
						
						if(xx > y){
							xx = y;
						}
						
						if(elist[xx][0] == 0){
							dp[j][xx] += dp[j][i] * (1.0 / x);
						}
						else{
							if(elist[xx][0] == 1){
								//step
								int xxx = xx + elist[xx][1];
								if(xxx > y){
									xxx = y;
								}
								dp[j][xxx] += dp[j][i] * (1.0 / x);
							}
							else {
								int mo = j;
								if(elist[xx][0] == 2){
									mo += elist[xx][1];
								}
								else{
									mo-= elist[xx][1];
									if(mo < 0)
										mo = 0;
								}
								
								dp[mo][xx] += dp[j][i] * (1.0 / x);
							}
						}
					}
				}
			}
			double ans = 0;
			for(int i = 0; i < 5001; i++){
				ans += dp[i][y] * i;
			}
			System.out.println((int)ans);
		}
	}
	
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doit();
	}
}

Measured memory_bytes: 17000
n = int(input())
a = list(map(int, input().split()))

def x1(a):
    s = 0
    for v1, v2 in zip(a[::2], a[1::2] + [0]):
        s += (v1 - v2)
    return s

x = [0] * n
x[0] = x1(a)
for i in range(1, n):
    x[i] = a[i - 1] * 2 - x[i - 1]
print(" ".join(map(str, x)))



Measured memory_bytes: 85220
#include<bits/stdc++.h>
#define int long long
const int inf=8938103643641919514ll;
const int mod=1000000007ll;
const int dd[]={0,-1,0,1,0};
using namespace std;
int a,b,c,d;
signed main(){
	int i,j;
	cin>>a;
	string s;
	cin>>s;
	string t;
	int n=0,m=0;
	for(auto x:s){
		if(x=='(')
			n++;
		if(x==')'){
			if(n>0)
				n--;
			else if(n==0)
				m++;
		}
	}
	for(i=0;i<m;i++)
		t.push_back('(');
	t+=s;
	n=0;
	m=0;
	for(auto it=rbegin(t);it!=rend(t);it++){
		if(*it==')')
			n++;
		if(*it=='('){
			if(n>0)
				n--;
			else if(n==0)
				m++;
		}
	}
	for(i=0;i<m;i++)
		t.push_back(')');
	cout<<t<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
struct uftree{
private:
  vector<ll> par,val,rnk;
public:
  uftree(ll n){
    par.resize(n+5);
    val.resize(n+5);
    rnk.resize(n+5);
    for(int i=0;i<=n;i++){
      par[i]=i;
      val[i]=0;
      rnk[i]=0;
    }
  }
  void set_val(ll pos,ll x){
    val[pos]=x;
  }
  ll find(ll pos){
    if(par[pos]==pos) return pos;
    else return par[pos]=find(par[pos]);
  }
  bool same(ll a,ll b){
    return find(a)==find(b);
  }
  ll sum(ll pos){
    return val[find(pos)];
  }
  void unite(ll a,ll b){
    a=find(a);
    b=find(b);
    if(same(a,b)) return;
    if(rnk[a]<rnk[b]){
      par[a]=b;
      val[b]+=val[a];
    }
    else{
      par[b]=a;
      val[a]+=val[b];
      if(rnk[a]==rnk[b]) rnk[a]++;
    }
  }
};
ll las[100005]={0};
int main(){
  ll n,m;
  cin>>n>>m;
  uftree uf(n+5);
  for(int i=1;i<=n;i++) uf.set_val(i,1);
  for(int i=1;i<=n;i++){
    ll k;
    cin>>k;
    for(int j=0;j<k;j++){
      ll l;
      cin>>l;
      if(las[l]!=0) uf.unite(las[l],i);
      las[l]=i;
    }
  }
  cout<<(uf.sum(1)==n?"YES":"NO")<<endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char* argv[])
{
	int N,i;
	cin>>N;
	vector<int> Pa(N);
	for (i=0;i<N;i++){
		cin>>Pa[i];
	}
	int ans=0;
	for (i=0;i<N-2;i++){
		int Max=max(Pa[i],max(Pa[i+1],Pa[i+2]));
		int Min=min(Pa[i],min(Pa[i+1],Pa[i+2]));
		int P=Pa[i+1];
		if (P!= Min&& P!=Max){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

int main()
{
	int n[31] = {0},s[30];
	
	for(int i=1; i<=28; i++){
		cin>>s[i];
		n[s[i]] = 1;
	}

	for(int i=1; i<=30; i++){
		if(!n[i])
			cout<<i<<endl;
	}

	return 0;

}

Measured memory_bytes: 1160
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;

int main()
{
    string n;
    int i, judge = 0;
    
    cin >> n;
    
    if(n[0] != '9') {
        judge = 2;
        
        for(i = 1; i < n.length(); i++) {
            if(n[i] != '9') {
                judge = 3;
            }
        }
    } else {
        for(i = 1; i < n.length(); i++) {
            if(n[i] != '9') {
                judge = 1;
            }
        }
    }
    
    if(judge == 0) {
        cout << 9 * int(n.length()) << endl;
    } else if(judge == 1) {
        cout << (9 * (int(n.length()) - 1)) + 8 << endl;
    } else if(judge == 2) {
        cout << (9 * (int(n.length()) - 1)) + (int(n[0]) - 48) << endl;
    } else {
        cout << (9 * (int(n.length()) - 1)) + (int(n[0]) - 49) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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 int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int N, M;
int p[101010];
int x[101010], y[101010];
vector<int> G[101010];
bool used[101010];

void dfs(vector<int>& indexes, set<int>& values, int pos) {
  if (used[pos]) return;

  indexes.push_back(pos);
  values.insert(p[pos]);
  used[pos] = true;

  for (auto e : G[pos]) {
    dfs(indexes, values, e);
  }
}

int main() {
  cin >> N >> M;
  repe(i, 1, N) { cin >> p[i]; }
  repe(i, 1, M) {
    cin >> x[i] >> y[i];
    G[x[i]].push_back(y[i]);
    G[y[i]].push_back(x[i]);
  }

  ll ans = 0;
  repe(i, 1, N) {
    if (used[i]) continue;

    vector<int> indexes;
    set<int> values;
    dfs(indexes, values, i);

    for (auto i : indexes) {
      if (values.count(i) == 1) {
        ++ans;
      }
    }
  }

  cout << ans << endl;
}


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

int main() {
  int answer = 1;
  int N;
  int K;
  cin >> N >> K;
  
  for (int i = 0; i < N; i++) {
    if (answer * 2 < answer + K) {
      answer *= 2;
    }
    else {
      answer += K;
    }
  }
  
  cout << answer << endl;
}

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

int main(){
	char c;
	cin >> c;
	if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u')
		cout << "vowel" << endl;
	else
		cout << "consonant" << endl;
	
	return 0;
}

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

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

  int C = 1;
  int ans = 0;

  while (true) {
    if (C >= B) break;
    else {
      C = C - 1 + A;
      ans++;
    }
  }

  cout << ans << endl;
}


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

using namespace std;

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

	int n;
	deque<int> d;
	cin >> n;
	for(int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		if((n % 2 == 0 && i % 2 == 0) || (n % 2 == 1 && i % 2 == 1))d.push_back(a);
		else d.push_front(a);
	}
	for(int i = 0; i < n; i++)cout << d[i] << (i != n - 1 ? " " : "");
	cout << endl;

	return 0;
}


Measured memory_bytes: 3072
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*
        PEOPLE'S LIVES DON'T END WHEN THEY DIE.
        IT ENDS WHEN THEY LOSE FAITH
                                     -ITACHI UCHIHA
        EXPLAINATION BELOW->
        SAME AS EDITORIAL
       
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
void solve()
{
  int n,k,i;cin>>n>>k;
  ll A[n];
  fo(i,0,n)cin>>A[i];
  sort(A,A+n,greater<int>());
  i=k;
  ll sum=0;
  for(;i<n;i++)sum+=A[i];
  cout<<sum<<"\n";
}
int main()
{
   fastio
   solve();
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
using namespace std;

int main() {
    int h, w, x[100] = {}, y[100] = {};
    cin >> h >> w;
    string s[100] = {};
    for (int i = 0; i < h; i++) {
        cin >> s[i];
    }
    for (int i = 0; i < h; i++) {
        bool flag=1;
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '#') flag = 0;
        }
        if (flag) x[i] = 1;
    }
    for (int i = 0; i < w; i++) {
        bool flag = 1;
        for (int j = 0; j < h; j++) {
            if (s[j][i] == '#') flag = 0;
        }
        if (flag) y[i] = 1;
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (x[i] == 0 && y[j] == 0) cout << s[i][j];
        }
        if(x[i]==0) cout<<endl;
    }
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using namespace std;

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

string s;
string dp[55][55];

inline string update(string a,string b){
	if(a=="invalid") return b;
	if(b=="invalid") return a;
	if(a.size()>b.size()) return a;
	if(b.size()>a.size()) return b;
	return max(a,b);	
}

string rec(int l,int r){
	string &ret=dp[l][r];
	if(ret!="") return ret;

	ret="invalid";
	if(l>=r) return ret;	
	// Number
	{
		string cur=s.substr(l,r-l);
		int m=cur.size();
		//cout << l << " " << r << endl;
		//cout << cur << " " << m << endl;
		bool ok=true;
		rep(i,m){
			if(cur[i]=='?') cur[i]='9';
			if(isdigit(cur[i])==false) ok=false;
		}
		if(cur[0]=='0' && m>=2) ok=false;
		//cout << cur << endl;
		if(ok) return ret=cur;
	}

	// L
	{
		bool ok=true;
		if(s[l]!='L' && s[l]!='?') ok=false;
		if(s[l+1]!='(' && s[l+1]!='?') ok=false;
		if(s[r-1]!=')' && s[r-1]!='?') ok=false;

		if(ok){
			for(int i=l+3;i<r-1;++i){
				if(s[i]!=',' && s[i]!='?') continue;
				string left=rec(l+2,i),right=rec(i+1,r-1);
				if(left=="invalid"||right=="invalid") continue;
				ret=update(ret,left);
			}
		}
	}

	{
		bool ok=true;
		if(s[l]!='R' && s[l]!='?') ok=false;
		if(s[l+1]!='(' && s[l+1]!='?') ok=false;
		if(s[r-1]!=')' && s[r-1]!='?') ok=false;

		if(ok){
			for(int i=l+3;i<r-1;++i){
				if(s[i]!=',' && s[i]!='?') continue;
				string left=rec(l+2,i),right=rec(i+1,r-1);
				if(left=="invalid"||right=="invalid") continue;
				ret=update(ret,right);
			}
		}
	}

	return ret;
}


int main(void){
	cin >> s;
	int n=s.size();
	cout << rec(0,n) << endl;
	return 0;
}

Measured memory_bytes: 3244
// #pragma GCC optimize("O3")
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace ::std;
// clang-format off
template<typename T> T nxt() {T res; cin >> res; return res;}
#define tests() for (int _ = nxt<int>(); _ >= 0; _--)
#define nxt1(t,n) t (n); cin >> n
#define nxt2(t,n,m) t (n),(m); cin >> n >> m
#define nxt3(t,n,m,k) t (n),(m),(k); cin >> n >> m >> k
#define rep(i, A) for (int i = 0 ; i < A ; i++)
#define ll long long
typedef pair<int,int> pii;typedef pair<ll, ll> pll;typedef vector<int> vi;typedef vector<vi> vvi;typedef vector<ll> vl;typedef vector<vl> vvl;
#define dbg(vari) cerr<<#vari<<" = "<<(vari)<<endl;
template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
template<typename T> ostream& operator<<(ostream &s,vector<T> t){for(T ti : t)s<<ti<<" ";return s; }
#define all(x) (x).begin(), (x).end()
#define last(vec) vec[vec.size()-1]
#define has(c,x) ((c).find(x) != (c).end())
// clang-format on

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

    nxt2(int, H, W);

    vector<string> grid(H);
    vvl dp(H, vl(W, 0));

    rep(i, H) {
        cin >> grid[i];
    }

    auto is_wall = [&grid](int x, int y) -> bool {
        return grid[x][y] == '#';
    };

    const ll MOD = 1e9L + 7;
    dp[0][0] = 1;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (is_wall(i, j))
                continue;
            if (j > 0)
                dp[i][j] = (dp[i][j] + dp[i][j - 1]) % MOD;
            if (i > 0)
                dp[i][j] = (dp[i][j] + dp[i - 1][j]) % MOD;
        }
    }

    cout << dp[H - 1][W - 1] % MOD << endl;
    return 0;
}


Measured memory_bytes: 12424
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;

int main () {
  int n, k;
  string s;
  cin >> n >> k;
  //  cin >> s;
  char str[51];
  scanf("%s", str);
  str[k-1]=str[k-1] + 32;
  printf("%s", str);


  return 0;
}


Measured memory_bytes: 256