akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define inf 10000000000000007
#define all(vec) vec.begin(),vec.end()
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

string s, t;
int ans;

signed main() {
	cin >> s;
	t = s;
	for (int i = 1; i < s.size(); i++) {
		if (t[i] == t[i - 1]) {
			ans++;
			if (t[i - 1] == '0')t[i] = '1';
			else t[i] = '0';
		}
	}
	cout << ans << endl;
}

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

a = [int(input()) for i in range(q)]
b = [0 for i in range(n)]

for i in range(q):
  b[a[i]-1] += 1

for j in range(n):
  if k - q + b[j] > 0:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 8640
/*
ID: kiwio
LANG: C++14
TASK: 
*/
 
#include <bits/stdc++.h>
using namespace std;

int n, i, e[300005], w[300005], east, west, ans;
char dir[300005];

int main () {
	ios_base::sync_with_stdio(0); cin.tie(NULL);/*
#ifndef turtle
	ofstream cout (".out");
	ifstream cin (".in");
#endif*/
	cin >> n;
	for (i=1; i<=n; i++) {
		cin >> dir[i];
		e[i]=east;
		if (dir[i]=='E') {
			east++;
		}
	}
	for (i=n; i>=1; i--) {
		w[i]=west;
		if (dir[i]=='W') {
			west++;
		}
		ans=max(ans, w[i]+e[i]);
	}
	cout << n-ans-1;
 }

Measured memory_bytes: 2944
#include<iostream>
using namespace std;
int main(){
int n,m,b,c;
cin>>n>>m>>b;
c=b;
for(int i=0;i<100;i++){
if(c%(n+m)<=n){
goto a;
}
c+=60;
}
c=-1;
a:
cout<<c<<endl;
return 0;
}

Measured memory_bytes: 1160
import java.util.*;

/* 階乗の素因数分解の仕方。参考: https://youtu.be/28IanD3lXGg */

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		
		int n = in.nextInt();
	
		// find prime factor
		int[] primeFactor = new int[n + 1];
		for (int i = 2; i <= n; i++) {
			int x = i;
			while (1 < x) {
				for (int j = 2; j <= x; j++) {
					if (x % j == 0) {
						primeFactor[j]++;
						x /= j;
						break;
					}
				}
			}
		}
		
		long count = 1;
		for (int i = 2; i <= n; i++) {
			count *= (primeFactor[i] + 1);
			count %= 1000000007;
		}
		System.out.println(count);
	}
	
}

Measured memory_bytes: 21716
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
    n: usize,
    uvw: [(usize, usize, usize); n-1],
    }
    let mut g: Vec<Vec<(usize, usize)>> = vec![vec![]; n];
    for i in 0..n-1 {
        let (u, v, w) = uvw[i];
        g[u-1].push((v-1, w));
        g[v-1].push((u-1, w));
    }
    let mut color = vec![-1; n];
    color[0] = 0;
    dfs(&g, & mut color, 0, 0);
    for i in 0..n {
        println!("{}", color[i]);
    }
}

fn dfs(ref g: &Vec<Vec<(usize, usize)>>, color: &mut Vec<i32>, x: usize, y: usize) {
    for edge in &g[x] {
        let (u, w) = *edge;
        if color[u] == -1 {
            let tmp = (y + w) % 2;
            color[u] = tmp as i32;
            dfs(&g, color, u, y + w);
        }
    }
}

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

int main() {
  long long N, K;
  cin >> N >> K;

  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);

  vector<int> s;
  vector<int> ord(N + 1, -1);
  int C = 1, L = 0;
  {
    int v = 1;
    while (ord.at(v) == -1) {
      ord.at(v) = s.size();
      s.push_back(v);
      v = A.at(v - 1);
    }
    C = s.size() - ord.at(v);
    L = ord.at(v);
  }

  if (K < L)
    cout << s.at(K) << endl;
  else {
    K -= L;
    K %= C;
    cout << s.at(L + K) << endl;
  }
}

Measured memory_bytes: 5864
fun main(args: Array<String>) {
    abc081c()
}

fun abc081c() {
    val (n, k) = readLine()!!.split(" ").map { it.toInt() }
    val aList = readLine()!!.split(" ").map { it.toInt() }

    val grouped = aList.groupBy { it }.map { it.value.size }

    if (grouped.size <= k) return println(0)

    val answer = grouped.sorted().dropLast(k).sum()

    println(answer)
}


Measured memory_bytes: 112604
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val r = sc.nextLong()
    println(problem134_a(r))
}

fun problem134_a(r: Long): Int {
    return (3 * Math.pow(r.toDouble(), 2.0)).toInt()
}

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

int main() {
  int A, B;
  cin >> A >> B;
  
  int ans = 0;
  
  ans += max(A, B);
  if (ans == A) {
    A--;
  } else {
    B--;
  }
  
  ans += max(A, B);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<long long,int> P;



int main(){
    int n;
    vector<int> g[105];
    cin >> n;
    rep(i, n){
        int a, b;
        cin >> a >> b;
        rep(j, b){
            int c;
            cin >> c;
            g[a].push_back(c);
        }
    }
    queue<int> que;
    int dist[105];
    rep(i, n + 1) dist[i] = -1;
    dist[1] = 0;
    que.push(1);

    while(!que.empty()){
        int v = que.front();
        que.pop();
        for (auto nv : g[v]){
            if (dist[nv] != -1) continue;
            dist[nv] = dist[v] + 1;
            que.push(nv);
        }
    }

    rep(i, n) cout << i + 1 << " " << dist[i+1] << endl;

    return 0;
}


Measured memory_bytes: 3172
N = int(input())
H = list(map(int, input().split()))

count = 0
max_count = 0
for i in range(len(H)-1):
    if H[i]>=H[i+1]:
        count += 1
    else:
        max_count = max(max_count, count)
        count = 0
max_count = max(max_count, count)

print(max_count)

Measured memory_bytes: 14224
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
struct tree{
	int go[26],size,where;
}t[410000];
int len,num[110000][26][26],n,w[26][26],A[26],m,pre[110000];
char ch[410000];
void insert(int wh){
	int k=strlen(ch+1); int now=0;
	for (int i=1;i<=k;i++){
		if (t[now].go[ch[i]-'a']==0)
			t[now].go[ch[i]-'a']=++len;
		now=t[now].go[ch[i]-'a']; t[now].size++;
	}
	t[now].where=wh;
}
void dfs(int k,int k2){
	if (t[k].where) memcpy(num[t[k].where],w,sizeof w),pre[t[k].where]=k2;
//	cout<<k<<" "<<w[0][1]<<" "<<w[1][0]<<endl;
	for (int i=0;i<26;i++){
		if (t[k].go[i]==0) continue;
		for (int j=0;j<26;j++)
			if (i!=j)
				w[i][j]+=t[t[k].go[j]].size;
		dfs(t[k].go[i],k2+(t[k].where>0));
		for (int j=0;j<26;j++)
			if (i!=j)
				w[i][j]-=t[t[k].go[j]].size;
	}
}
int main(){
	scanf("%d",&n); len=0;
	for (int i=1;i<=n;i++){
		scanf("%s",ch+1);
		insert(i);
	}
	memset(w,0x00,sizeof w);
	dfs(0,0);
	scanf("%d",&m);
	for (;m;m--){
		int k1; scanf("%d",&k1);
		scanf("%s",ch);
	//	cout<<ch+1<<endl;
		for (int i=0;i<26;i++) A[i]=ch[i]-'a';
		int ans=1+pre[k1];
		for (int i=0;i<26;i++)
			for (int j=0;j<i;j++){
			//	if (num[k1][A[i]][A[j]]) cout<<"fa "<<i<<" "<<j<<" "<<A[i]<<" "<<A[j]<<" "<<num[k1][A[i]][A[j]]<<endl;
				ans+=num[k1][A[i]][A[j]];
			}
		printf("%d\n",ans);
	}
}


Measured memory_bytes: 278272
//おまじない
//#include <bits/stdc++.h>
//#include <stdio.h>
#include <iostream>
//#include <math.h>
#include<iomanip>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define space ' '
#define pll pair<ll,ll>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

int main(){
//    cout << (int)'a'<<endl;
//    vector<vector<int>> q(26);
//    q[1].push_back(1);q[1].push_back(3);q[1].push_back(5);q[1].push_back(7);
//    int a = upper_bound(q[1].begin(),q[1].end(),4)-q[1].begin();
//    cout << a<<endl;
//    int a = upper_bound(q.begin(),q.end(),0)-q.begin();
//    cout <<a<<endl;
    
    ll ans = 0;
    ll p=-1;
    string s,t;
    vector<vector<int> > v(26);
    
    cin >> s>>t;
    
    s = s+s;
    //cout << s<<endl;
    rep(i,s.size()){
        v[(int)s[i]-97].push_back(i);
    }
    
    rep(i,t.size()){
        int argi = (int)t[i]-97;
        if(v[argi].size()==0){
            ans=-1;
            break;
        }
        
        ll q = upper_bound(v[argi].begin(),v[argi].end(),p)-v[argi].begin();
        ans += v[argi][q]-p;
        //cout <<"p:"<<p<< " q:"<<q<<" v[argi][q]:"<<v[argi][q]<<" ans:"<<ans<<endl;
        p=v[argi][q];
        
        if(p>=s.size()/2)p-=s.size()/2;
    }
    
    cout << ans<<endl;
    
    return 0;
}


Measured memory_bytes: 1784
n=int(input())
n_d=len(str(n))
ans=0
if n_d >1:
	for i in range(1,n_d,2):
		part1=9
		part2=10**i
		total=part1*part2
		total=total//10
		ans+=total
if n_d%2!=0:		
	part1=10**(n_d-1)
	part2=n-part1
	ans+=(part2+1)
print(int(ans))
# your code goes here

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
	double a,b,c;
  	ios::sync_with_stdio(false);
  	cin.tie(nullptr);
  	cin>>a>>b>>c;
  	if(a/b>(int)(a/b)){
    	cout<<((int)(a/b)+1)*c<<endl;
    }
  	else
      	cout<<(int)((a/b)*c)<<endl;
  	return 0;
}

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

int main() {
  int n,mini=999999999,maxi=0;
  cin >> n;
  for(int i=0; i < n; i++) {
    int x;
    cin >> x;
    mini = min(x,mini);
    maxi = max(x,maxi);
  }
  cout << maxi - mini << endl;
}

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

int main() {
	int a, b, c, d;cin >> a >> b >> c >> d;
	bool ans = 0;
	if (abs(c - a) <= d) {
		//cout << "c-a" << endl;
		ans = 1;
	}
	if (abs(a - b) <= d && abs(b - c) <= d) {
		//cout << "a-borb-c" << endl;
		ans = 1;
	}
	if (ans)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#powerful discount tickets
n,m=map(int,input().split())
lists=list(map(int,input().split()))
uselist=[0 for i in range(n)]
for j in range(n):
    uselist[j]=lists[j]*(-1)
import heapq
heapq.heapify(uselist)
for _ in range(m):
    #m回この作業を繰り返す
    mini=heapq.heappop(uselist)
    heapq.heappush(uselist,mini/2) 
#バイナリツリーと同じ方法で保管していると考えられる
ans=0
import math
for some in uselist:
    ans+=math.floor(-some)
print(ans)


Measured memory_bytes: 14224
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
using namespace std;
char s[20];
int main(){
	int n;
	cin>>n;
	int t = n;
	int ans = 0;
	while(n){
		ans += n%10;
		n /= 10;
	}
	if(t % ans) cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
youbou = [list(map(int,input().split())) for i in range(m)]
youbou.sort(key = lambda x: x[1])
ans,prev = 0,-1
for i in range(m):
	if prev < youbou[i][0]:
		prev = youbou[i][1] - 1
		ans += 1
print(ans)

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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i < b; i++)
#define REPE(i,a,b) for (int i = a; i <= b; i++)

int main() {
	int n = 0;
	scanf("%d", &n);
	vector<int> arr(n + 1, 0), dp(n + 1, 0);
	int i = 0;
	for (i = 0; i < n; i++)
		cin >> arr[i];
	dp[1] = abs(arr[1] - arr[0]);
	for (i = 2; i < n; i++) {
		dp[i] = min(dp[i - 1] + abs(arr[i] - arr[i - 1]),
		            dp[i - 2] + abs(arr[i] - arr[i - 2]));
	}
	cout << dp[n - 1] << endl;
	return 0;
}

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

#define all(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};

int main() {
    int h, w; cin >> h >> w;
    V<string> b(h);
    for(int i = 0; i < h; i++) cin >> b[i];

    int ans = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(b[i][j] == '#') continue;
            queue<P<int, int> > que;
            que.push({i, j});
            V<V<int> > d(h, V<int>(w, -1));
            d[i][j] = 0;
            int ma = 0;
            while(!que.empty()){
                auto p = que.front();
                que.pop();
                int x = p.second;
                int y = p.first;
                for(int k = 0; k < 4; k++){
                    int nx = x + dx[k];
                    int ny = y + dy[k];
                    if(nx < 0 || w <= nx || ny < 0 || h <= ny) continue;
                    if(b[ny][nx] == '#') continue;
                    if(d[ny][nx] != -1) continue;
                    d[ny][nx] = d[y][x] + 1;
                    que.push({ny, nx});
                    ma = max(ma, d[ny][nx]);
                }
            }
            ans = max(ans, ma);
        }
    }
    cout << ans << endl;
}


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

int main() {

  string s;
  cin >> s;

  int answer = 0;

  for (int i = 0; i < s.size() / 2; i++)  {

    if (s[i] != s[s.size() - 1 - i]) {
      answer++;
    }

  }

  cout << answer << endl;

}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

const int MAX_N = 200000;

vector<ll> power_for_one;
vector<ll> power_for_zero;

int count_bit(const string &S) {
    int ans = 0;

    for (int i = 0; i < (int) S.size(); i++) {
        if (S[i] == '1') {
            ans++;
        }
    }

    return ans;
}

ll do_calc(const int mod, const vector<ll> &power, const string &S) {
    ll v = 0;
    string T = S;
    reverse(T.begin(), T.end());
    for (int i = 0; i < (int) T.size(); i++) {
        if (T[i] == '1') {
            v = (v + power[i]) % mod;
        }
    }

    return v;
}

ll calc_for_one(const int mod, const vector<ll> &power, const string &S) {
    if (mod == 0) {
        return 0;
    } else {
        return do_calc(mod, power, S);
    }
}

ll calc_for_zero(const int mod, const vector<ll> &power, const string &S) {
    return do_calc(mod, power, S);
}

void prepare_power(const int mod, vector<ll> &power) {
    power.resize(MAX_N + 1, 0);
    if (mod == 0) {
        return;
    }

    power[0] = 1 % mod;

    for (int i = 1; i <= MAX_N; i++) {
        power[i] = (power[i - 1] * 2) % mod;
    }

}

int main(void) {
    int N;
    cin >> N;
    string S;
    cin >> S;

    const int bit_count = count_bit(S);
    const int mod_for_one = bit_count - 1;
    const int mod_for_zero = bit_count + 1;

    prepare_power(mod_for_one, power_for_one);
    prepare_power(mod_for_zero, power_for_zero);

    ll second_step_for_one = calc_for_one(mod_for_one, power_for_one, S);
    ll second_step_for_zero = calc_for_zero(mod_for_zero, power_for_zero, S);

    for (int i = 0; i < N; i++) {
        ll x;
        ll mod;
        if (S[i] == '1') {
            mod = mod_for_one;
            x = second_step_for_one;
            if ((x += mod - power_for_one[N - 1 - i]) >= mod) x -= mod;
        } else {
            mod = mod_for_zero;
            x = second_step_for_zero;
            x = (x + power_for_zero[N - 1 - i]) % mod;
        }

        // printf("%d: %lld\n", i, x);

        if (mod == 0) {
            printf("%d\n", 0);
            continue;
        }

        int cnt = 1;
        while (x > 0) {
            int bit_count = __builtin_popcountll(x);
            x = x % bit_count;
            cnt++;
        }

        printf("%d\n", cnt);
    }

    return 0;
}


Measured memory_bytes: 6828
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
int n,k,a[111],dp[101010];
int main()
{
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	dp[0]=1;
	for(int i=1;i<=k;i++)
	{
		dp[i]=1;
		for(int j=0;j<n;j++)
		{
			if(a[j]<=i)
			{
				if(dp[i-a[j]]==1)
				{
					dp[i]=0;
					break;
				}
			}
		}
	}
	if(dp[k])
	{
		cout<<"Second"<<endl;
	}
	else
	{
		cout<<"First"<<endl;
	}
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++) 
#define all(v) begin(v),end(v)
using ll = long long;

int main() {
  int n,k,q;cin>>n>>k>>q;
  vector<int> a(q),ans(n);
  rep(i,q){
    cin>>a[i];
    ans[a[i]-1]++;
  }
  rep(i,n){
    if(q-ans[i]<k)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
}

Measured memory_bytes: 4012
if __name__ == '__main__':
    N = int(input())
    S = input()

    if '#' not in S or '.' not in S:
        print(0)
        exit()

    b_num = 0
    w_num = S.count('.')
    ans = 10e6

    for i in range(N+1):
        ans = min(ans, b_num + w_num)
        if i != N:
            if S[i] == '#':
                w_num += 1
            else:
                b_num -= 1

    print(ans)


Measured memory_bytes: 3500
H,W=map(int,input().split())
s=[list(input()) for _ in range(H)]
D={}

for h in range(H):
    for w in range(W):
        if s[h][w] in D:
            D[s[h][w]]+=1
        else:
            D[s[h][w]]=1

odd=0
semi=0
for d in D:
    if D[d]%4==1:
        odd+=1
    elif D[d]%4==2:
        semi+=2
    elif D[d]%4==3:
        odd+=1
        semi+=2

if H%2==0 and W%2==0:
    if odd==semi==0:
        print("Yes")
    else:
        print("No")
elif H%2==1 and W%2==1:
    if odd==1 and semi<=H+W-2:
        print("Yes")
    else:
        print("No")
else:
    if H%2==1:
        if odd>0 or semi>W:
            print("No")
        else:
            print("Yes")
    else:
        if odd>0 or semi>H:
            print("No")
        else:
            print("Yes")

Measured memory_bytes: 8992
#include<bits/stdc++.h>
using namespace std;
const int N=305;
int a,b,c,tmp;
double n,dp[N][N][N];
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>tmp;
		if(tmp==1)a++;
		else if(tmp==2)b++;
		else c++;
	}
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=n;j++)
		{
			for(int k=0;k<=n;k++)
			{
				if(!i&&!j&&!k)continue;
				if(i)dp[i][j][k]+=dp[i-1][j+1][k]*i;
				if(j)dp[i][j][k]+=dp[i][j-1][k+1]*j;
				if(k)dp[i][j][k]+=dp[i][j][k-1]*k;
				dp[i][j][k]=dp[i][j][k]/(i+j+k);
				dp[i][j][k]+=n/(i+j+k);
			}
		}
	}
	cout<<fixed<<setprecision(12)<<dp[c][b][a]<<endl;
	return 0;
}

Measured memory_bytes: 220796
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>

using namespace std;

int main()
{
    int d,t,s;
    double time2reach;
    cin>>d>>t>>s;
    time2reach = double(d)/double(s);
    if(time2reach<=double(t))
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;  
}

Measured memory_bytes: 3520
# ABC126E - 1 or 2
def dfs(start: int) -> None:
    stack = [start]
    while stack:
        v = stack.pop()
        for u in G[v]:
            if not visited[u]:
                visited[u] = color
                stack.append(u)


def main():
    global G, visited, color
    N, M, *X = map(int, open(0).read().split())
    G = [[] for _ in range(N + 1)]
    for v, u in zip(X[::3], X[1::3]):
        G[v].append(u), G[u].append(v)
    visited, color = [0] * (N + 1), 1
    for v in range(1, N + 1):
        if not visited[v]:
            visited[v] = color
            dfs(v)
            color += 1
    ans = color - 1
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 32180
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e18;
using Graph = vector<vector<int>>;

signed main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for( int i = 0; i < N; i++ ) cin >> A[i];
  sort(A.begin(), A.end());

  //正の数と負の数に分ける
  vector<int> plus;
  vector<int> minus;
  int Z = 0;
  for( int i = 0; i < N; i++ ){
    if( A[i] > 0 ) plus.push_back(A[i]);
    else if( A[i] < 0 ) minus.push_back(A[i]);
    else Z++;
  }

  //負の数、0の数、正の数の個数から、K番目の数の正負を求める
  int M = (int)minus.size();
  int P = (int)plus.size();
  int m_num = M*P;
  int z_num = Z*(Z-1)/2 + Z*P + Z*M;

  if( K <= m_num ){ //答えが負になるとき
    int l = -INF;
    int r = -1;
    while( r-l > 1 ){
      int mid = (l+r)/2;
      int cnt = 0;
      for( int i = 0; i < plus.size(); i++ ){
        auto Iter = upper_bound(minus.begin(), minus.end(), (mid-plus[i]+1)/plus[i]);
        cnt += Iter - minus.begin();
      }
      if( cnt < K ) l = mid;
      else r = mid;
    }
    cout << r << endl;

  }else if( K <= m_num+z_num ){
    cout << 0 << endl;
  }else{ //答えが正になるとき

    //負の数も絶対値の大きい順に
    for( int i = 0; i < M; i++ ) minus[i] *= -1;
    sort(minus.begin(), minus.end());

    int l = 0;
    int r = INF;
    K -= (m_num+z_num);
    while( abs(r-l) > 1 ){
      int mid = (l+r)/2;
      int cnt = 0;
      for( int i = 0; i < P; i++ ){
        auto Iter = upper_bound(plus.begin(), plus.end(), mid/plus[i]);
        int ok = Iter - plus.begin();
        if( i < ok ) ok--;
        cnt += ok;
      }
      for( int i = 0; i < M; i++ ){
        auto Iter = upper_bound(minus.begin(), minus.end(), mid/minus[i]);
        int ok = Iter - minus.begin();
        if( i < ok ) ok--;
        cnt += ok;
      }
      cnt /= 2; //同じ組み合わせを2回数えてるので割る
      if( cnt < K ) l = mid;
      else r = mid;
     // cout << l << " " << r << " " << mid << endl;
    }
    cout << r << endl;
  }
}


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

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

    int ans = 0;
    for (int i = 1; i <= n; i += 2) {
        int num = 0;
        for (int j = 1; j <= i; j++) {
            if (i % j == 0) num++;
        }
        if (num == 8) ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
/*
    If they say
    Who cares if one more light goes out?
    In a sky of a million stars
    It flickers, flickers
    Who cares when someone's time runs out?
    If a moment is all we are
    We're quicker, quicker
    Who cares if one more light goes out?
    Well I do
*/

#include<bits/stdc++.h>
using namespace std;

#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) ((a) / gcd(a,b)) * (b)
#define all(x)  x.begin(),x.end()

#define ll long long
#define ull unsigned long long
#define VI vector<int>
#define VLL vector<ll>
#define VS vector<string>
#define MPII map<int, int>
#define SET set<int>
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define INF (int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))
#define fast_io   ios_base::sync_with_stdio(false);cin.tie(0),cout.tie(0);

ll MOD = 1e9+7;

ll add(ll a, ll b)
{
    a+=b; a%=MOD;
    if(a<0) a+=MOD;
    return a;
}
ll mult(ll a, ll b)
{
    if(a>MOD) a%=MOD;
    if(b>MOD) b%=MOD;
    ll ans=(a*b)%MOD;
    if(ans<0) ans+=MOD;
    return ans;
}
ll pw(ll a, ll b)
{
    ll r=1;
    while(b){
        if(b&1) r=mult(r,a);
        a=mult(a,a);
        b>>=1;
    }
    return r;
}

void solve(){
  string a, b;
  cin >> a >> b;
  size_t as = a.size();
  size_t bs = b.size();

  if (as > bs) {
    cout << "GREATER" << endl;
  } else if (as < bs) {
    cout << "LESS" << endl;
  } else {
    bool eq = true;
    for (int i = 0; i < as; i++) {
      if (a[i] > b[i]) {
        cout << "GREATER" << endl;
        eq = false;
        break;
      } else if (b[i] > a[i]) {
        cout << "LESS" << endl;
        eq = false;
        break;
      }
    }
    if (eq) {
      cout << "EQUAL" << endl;
    }
  }
}

int main(){
    fast_io;
    ll t, k=0;
    t=1;
    while(t--){
        //k++;
        //cout<<"Case "<<k<<": ";
        solve();
    }
}



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

A = [False] * N
B = [False] * N
for i in range(M):
    a, b = map(int, input().split())
    if a == 1:
        A[b-1] = True
    if b == N:
        B[a-1] = True

flag = False
for i in range(N):
    if A[i] and B[i]:
        flag = True
        break

print('POSSIBLE' if flag else 'IMPOSSIBLE')



Measured memory_bytes: 6132
n = int(input())
v = list(map(int,input().split()))

if max(v)==min(v):
	print(int(n/2))
else:
	dic1 = {}
	dic2 = {}
	
	for i in range(n):
		if i % 2 == 1:
			if str(v[i]) in dic1.keys():
				dic1[str(v[i])] = dic1[str(v[i])] + 1
			else:
				dic1[str(v[i])] = 1
	
		if i % 2 == 0:
			if str(v[i]) in dic2.keys():
				dic2[str(v[i])] = dic2[str(v[i])] + 1
			else:
				dic2[str(v[i])] = 1
	
	max1 = max(dic1, key=dic1.get)
	max2 = max(dic2, key=dic2.get)
	p1 = dic1[max1]
	p2 = dic2[max2]
	if max1 == max2:
		dic1.pop(max1)
		dic2.pop(max2)
		if dic1 == {}:
			p3 = 0
		else:
			max3 = max(dic1, key=dic1.get)
			p3 = dic1[max3]
		if dic2 == {}:
			p4 = 0
		else:
			max4 = max(dic2, key=dic2.get)
			p4 = dic2[max4]
		if p1 + p4 > p2 + p3:
			p2 = p4
		else:
			p1 = p3
	
	print(n-p1-p2)

Measured memory_bytes: 21468
#include<iostream>  
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
//ll a[N],sum[N];  
struct node {
	ll a, b, c;
}p[N];
int n, m, i, j, k;
bool cmp(node x, node y) {
	return x.a*i + x.b*j + x.c*k>y.a*i + y.b*j + y.c*k;
}
int main(void) {
	cin >> n >> m;
	ll ans = 0;
	for (int i = 1; i <= n; i++)   cin >> p[i].a >> p[i].b >> p[i].c;
	for (i = -1; i <= 1; i += 2) { 
		for (j = -1; j <= 1; j += 2) {
			for (k = -1; k <= 1; k += 2) {
				sort(p + 1, p + 1 + n, cmp);
				ll t[4] = { 0 };
				for (int te = 1; te <= m; te++)    t[1] += p[te].a, t[2] += p[te].b, t[3] += p[te].c;
				ans = max(ans, t[1] * i + t[2] * j + t[3] * k);
			}
		}
	}
	cout << ans << endl;
}

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

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

int N, M;

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

    cout << 6 - N - M << endl;
    return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  rep(x, 12000) {
    // cerr << x << " ";
    // cerr << x * 0.08 << " " << floor(x * 0.08) << " ";
    // cerr << x * 0.10 << " " << floor(x * 0.10) << endl;
    if (floor(x * 0.08) == a && floor(x * 0.1) == b) {
      cout << x << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fol(i,n) for(int i=0;i<n;i++)
#define pb push_back
typedef long long ll;
typedef pair<int,ll> P;
typedef vector<P> vip;

void solve(){
    bool flag=true;
    string s;cin>>s;
    int a[26]={};
    int n=s.size();
    fol(i,n){
        a[s[i]-'a']++;
    }
    fol(i,26){
        if(a[i]%2==1) flag=false;
    }
    cout <<(flag?"Yes":"No") <<endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,a,b,c;
string s[100005];
char ans[100005];
void print(){
	cout<<"Yes"<<endl;
	for(int i=1;i<=n;i++) cout<<ans[i]<<endl;
}
void check(){
	for(int i=1;i<=n;i++){
		if(s[i]=="AB"){
			if(a==0&&b==0){
				cout<<"No";
				exit(0);
			}
			if(a==1&&b==1&&c==0&&i!=n&&s[i+1]=="AC"){
				ans[i]='A';
				a++;
				b--;
				continue;
			}
			if(a==1&&b==1&&c==0&&i!=n&&s[i+1]=="BC"){
				ans[i]='B';
				b++;
				a--;
				continue;
			}
			if(a>b){
				ans[i]='B';
				b++;
				a--;
			}else{
				ans[i]='A';
				a++;
				b--;
			}
		}
		if(s[i]=="AC"){
			if(a==0&&c==0){
				cout<<"No";
				exit(0);
			}
			if(a==1&&b==0&&c==1&&i!=n&&s[i+1]=="AB"){
				ans[i]='A';
				a++;
				c--;
				continue;
			}
			if(a==1&&b==0&&c==1&&i!=n&&s[i+1]=="BC"){
				ans[i]='C';
				c++;
				a--;
				continue;
			}
			if(a>c){
				ans[i]='C';
				c++;
				a--;
			}else{
				ans[i]='A';
				a++;
				c--;
			}
		}
		if(s[i]=="BC"){
			if(b==0&&c==0){
				cout<<"No";
				exit(0);
			}
			if(a==0&&b==1&&c==1&&i!=n&&s[i+1]=="AB"){
				ans[i]='B';
				b++;
				c--;
				continue;
			}
			if(a==0&&b==1&&c==1&&i!=n&&s[i+1]=="AC"){
				ans[i]='C';
				c++;
				b--;
				continue;
			}
			if(b>c){
				ans[i]='C';
				c++;
				b--;
			}else{
				ans[i]='B';
				b++;
				c--;
			}
		}
	}
	print();
}
int main(){
	cin>>n>>a>>b>>c;
	for(int i=1;i<=n;i++) cin>>s[i];
	check();
	return 0;
}

Measured memory_bytes: 6860
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include<cmath>
#include <limits>
using namespace std;
typedef long long ll;

typedef pair<ll, ll> P;
const int INF = 100000000;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

#define REP(i, a,b) for(i=a;i<b;i++) 
#define REP1(i,b,a) for(i=b-1;i>=a;i--)
#define output(x) cout<<x<<endl;
#define pb(x) push_back(x);
const int MOD = 1000000007;



int main() {
	ll i,j, k, l, m, n, sum, flag, cc, M, X,N,Y, Z, K, y, z,A,B,Q,x,rights,lefts,rightt,leftt;
	cin >> A >> B >> Q;
	vector<ll>s(A+2);
	vector<ll>t(B+2);
	REP(i, 1, A+1) {
		cin >> s[i];
	}
	REP(i, 1, B+1) {
		cin >> t[i];
	}
	s[0] = t[0] = -100000000000;
	s[A + 1] = t[B + 1] = 100000000000;
	ll C[2];
	ll D[2];
	vector<ll>ans;
	REP(i, 0, Q) {
		cin >> x;
		ans.clear();
		C[0]=distance(s.begin(),lower_bound(s.begin(),s.end(),x))-1;
		C[1] = C[0] + 1;
		D[0]= distance(t.begin(), lower_bound(t.begin(), t.end(), x))-1;
		D[1] = D[0] + 1;
		for (j = 0; j < 2; j++) {
			for (k = 0; k < 2; k++) {
				ans.push_back(abs(x - s[C[j]]) + abs(s[C[j]] - t[D[k]]));
				ans.push_back(abs(x -t[D[k]]) + abs(s[C[j]] - t[D[k]]));
			}
		}
		sort(ans.begin(), ans.end());
		output(ans[0]);
	}

	return 0;
}








Measured memory_bytes: 2944
/*input
5 5 6
11010
01110
10101
11101
01010
1 1 5 5
1 2 4 5
2 3 3 4
3 3 3 3
3 1 3 5
1 1 3 4
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back

#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)

#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int raise(int a,int n,int m = MOD){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= raise(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

int floor1(int n,int k){
    if(n%k == 0 || n >= 0)return n/k;
    return (n/k)-1;
}

int ceil1(int n,int k){
    return floor1(n+k-1,k);
}

const int N = 2001;
int pref[N][N];
int rp[N][N];
int cp[N][N];
int n,m,q;
bool a[N][N];

void solve(){
    cin >> n >> m >> q;
    RE(i,n){
      RE(j,m){
        char o;cin >> o;
        a[i][j] = o-'0';
        pref[i][j] = pref[i-1][j]+pref[i][j-1]+a[i][j]-pref[i-1][j-1];
      }
    }
    RE(i,n){
      RE(j,m){
        rp[i][j] = rp[i-1][j]+rp[i][j-1]+(a[i][j] and a[i][j-1])-rp[i-1][j-1];
        cp[i][j] = cp[i-1][j]+cp[i][j-1]+(a[i][j] and a[i-1][j])-cp[i-1][j-1];
      }
    }
    while(q--){
      int xa,ya,xb,yb;
      cin >> xa >> ya >> xb >> yb;
      int blues = pref[xb][yb]-pref[xb][ya-1]-pref[xa-1][yb]+pref[xa-1][ya-1];
      ya++;
      int hori = 0;
      if(ya <= yb)hori = rp[xb][yb]-rp[xb][ya-1]-rp[xa-1][yb]+rp[xa-1][ya-1];
      ya--;
      xa++;
      int veri = 0;
      if(xa <= xb)veri = cp[xb][yb]-cp[xb][ya-1]-cp[xa-1][yb]+cp[xa-1][ya-1];
      //cout << hori << endl;
      cout << blues-(veri+hori) << endl;
    } 
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;
  //cin >> t;
  while(t--){
    solve();
  }
  return 0;
}

Measured memory_bytes: 101380
#define z(c)for(i=1;i<c)
n,m,a,b,i;char p[1009][1009];x(i,j){p[i][j]=94;p[i+1][j]=118;b--;}main(j){scanf("%d%d%d%d",&n,&m,&a,&b);z(n+1;)memset(p[i++]+1,46,m);z(n&&b&&m&1;i+=2)x(i,m);b&n&m>2&n>1&&x(n-1,m-2);z(n;i++)for(j=1;j<=m&&b;j++)p[i][j]+p[i+1][j]<99&&x(i,j);z(n+1;i++)for(j=1;j<m&&a;)if(p[i][j++]+p[i][j]<99)p[i][j-1]=60,p[i][j]=62,a--;puts(a|b?"NO":"YES");z(n+1&!a&!b;)puts(p[i++]+1);}

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

ll inf=1e18;

int main() {
  ll h,n;
  cin >> h >> n;
  vector<ll> a(n);
  vector<ll> b(n);
  for(int i=0;i<n;i++) {
    cin >> a[i] >> b[i];
  }
  vector<ll> dp(h+1,inf);
  dp[0]=0;
  for(ll i=0;i<n;i++) {
    for(ll j=0;j<=h;j++) {
      if(j-a[i]>-1) {
        dp[j]=min(dp[j],dp[j-a[i]]+b[i]);
      }
      else {
        dp[j]=min(dp[j],b[i]);
      }
    }
  }
  cout << dp[h] << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
    string s;
    cin >> s;

    const int mapsize = 26;
    vector<bool> charmap(mapsize, false);
    for (int i = 0; i < s.length(); ++i)
        charmap[s[i] - 'a'] = true;

    for (int i = 0; i < mapsize; ++i) {
        if (!charmap[i]) {
            cout << char('a' + i) << '\n';
            return 0;
        }
    }
    cout << "None\n";
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

map<LL,int> memo;
int dfs(ll currX, ll currY, int depth){

	if (memo.count(LL(currX, currY))){
		int curr = memo[LL(currX, currY)];
		if (curr % 2 == 0){
			cerr << "Brown win." << endl;
		}else{
			cerr << "Alice win." << endl;
		} // end if
		return memo[LL(currX, currY)];
	} // end if

	if (currX <= 1 && currY <= 1){
		if (depth % 2 == 0){
			cerr << "Brown win." << endl;
		}else{
			cerr << "Alice win." << endl;
		} // end if
		return memo[LL(currX, currY)] = depth;
	} // end if

	cerr << "currX: " << currX << " currY: " << currY << " depth: " << depth << endl;

	int res = 0;
	for (int i = 1LL;; ++i){
		bool ok = false;
		// X から取る
		if (currX - 2LL * i >= 0LL){
			ok |= true;
			res = dfs(currX - 2LL * i, currY + i, depth + 1);
		} // end if
		// Y から取る
		if (currY - 2LL * i >= 0LL){
			ok |= true;
			res = dfs(currX + i, currY - 2LL * i, depth + 1);
		} // end if
		if (!ok) break;
	} // end for
	memo[LL(currX, currY)] = res;
}
 
int main()
{
//	memo.clear();
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll X, Y; cin >> X >> Y;

	if (abs(X - Y) <= 1LL){
		cout << "Brown" << endl;
	}else{
		cout << "Alice" << endl;
	} // end if

//	dfs(X, Y, 0);

	return 0;
}

Measured memory_bytes: 256
import sys
from collections import Counter
from collections import deque
import heapq
import math
import fractions
import bisect
import itertools
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))


t=list(input())
n=len(t)
for i in range(n):
    if t[i]=="?":
        t[i]="D"
print(*t,sep="")

Measured memory_bytes: 94812
/*

N 

3
1 2 
2 3



*/

#include <bits/stdc++.h>
using namespace std;

using ll = long long; 

const int nax = 1e5+5;

const int mod = 1e9+7;

int mul(int a, int b) {
    return (ll) a * b % mod;
}

int add(int a, int b) {
    return (a + b) % mod;
}

vector<vector<int>> adj_list(nax);

vector<int> dfs(int x, int parent) {
    // dp[0] - no. of ways to paint it white 
    // dp[1] - no. of ways to paint it black
    vector<int> dp(2);
    
    int all_white = 1;
    
    int sth_black = 0;
    
    for (int y : adj_list[x]) {
        if (y != parent) {
            vector<int> p = dfs(y, x);
            // p.first - no. of ways to paint 'y' white
            // p.second - no. of ways to paint 'y' black
            sth_black = add(mul(all_white, p[1]), mul(sth_black, add(p[0], p[1])));
            all_white = mul(all_white, p[0]);
        }
    }
    
    dp[0] = add(all_white, sth_black); // paint this as white
    
    dp[1] = all_white; // paint this as black
    
    return dp;
}

int main() {
    int n;
    
    scanf("%d", &n);
    
    for (int i = 0; i < n - 1; i++) {
        int xi;
        int yi;
        scanf("%d%d", &xi, &yi);
        adj_list[xi].push_back(yi);
        adj_list[yi].push_back(xi);
    }
    
    vector<int> ans = dfs(1, -1);
    
    printf("%d", add(ans[0], ans[1]));
    
	return 0;
}

Measured memory_bytes: 18176
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cassert>
#include <functional>
#include <string>
#include <sstream>
using namespace std;


int main(){
  int r, g, b; cin >> r >> g >> b;
  stringstream ss;
  ss << r << g << b;
  int n;
  ss >> n;
  if(n%4 == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
  
}


Measured memory_bytes: 256
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]

ans = b[a[0]-1]
for i in range(1,n):
  if a[i] == a[i-1] + 1 :
    ans += c[a[i-1]-1]
  ans += b[a[i]-1]

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>                        
#define pb push_back                            
#define mp make_pair                            
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)((x).size())
#define jonathan ios_base::sync_with_stdio(0)
#define livingston cin.tie(0)
using namespace std;                            
                                                
void yes() {cout << "Yes" << endl;}                                               
void no() {cout << "No" << endl;}                                                        
                                                
int dx[] = {1, 0, -1, 0, -1, -1, 1, 1};         
int dy[] = {0, 1, 0, -1, -1, 1, -1, 1}; 

const int INF = 1e9 + 9;
const long long LINF = 1e18 + 8;
const double EPS = 1e-9;
const long long MOD = 1e9 + 7; //998244353
const double PI = acos(-1);

void solve() {
    int n; cin >> n;
    vector<int> a(n);
    vector<int> cnt(n);
    for (int i = 0; i < n; i++) cin >> a[i], cnt[a[i]]++;
    sort(all(a));
    reverse(all(a));
    bool ok = true;
    if (a[0] == 1 and n > 2) ok = false;
    for (int j = a[0]; j > (a[0] + 1) / 2; j--) {
        if (cnt[j] < 2) {
            ok = false;
            break;
        }
    }
    if (cnt[(a[0] + 1) / 2] != 2 and (a[0] & 1)) ok = false;
    if (cnt[(a[0] + 1) / 2] != 1 and !(a[0] & 1)) ok = false;
    for (int j = (a[0] + 1) / 2 - 1; j >= 1; j--) if (cnt[j] > 0) ok = false;
    if (ok) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
} 

int main() {
    jonathan; 
    livingston;
    solve();
    return 0;
}

Measured memory_bytes: 3636
E = []
for i in range(3):
  E.append(list(map(int, input().split())))
  
A = [0]*4

for i in range(3):
  A[E[i][0] - 1] += 1
  A[E[i][1] - 1] += 1
  
if A[0] * A[1] * A[2] * A[3] == 4:
  print('YES')
else:
  print('NO')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define inf 1000000000
using namespace std;
typedef long long ll;
int s[1010][1010],H,W,h,w;
int main(){
	ll ans=0;
	scanf("%d%d%d%d",&H,&W,&h,&w);
	if(h==1&&w==1)return puts("No"),0;
	int a=(inf-1)/(h*w-1),b=-a*(h*w-1)-1;
	for(int i=1;i<=H;++i)for(int j=1;j<=W;++j)s[i][j]=a;
	for(int i=h;i<=H;i+=h)for(int j=w;j<=W;j+=w)s[i][j]=b;
	for(int i=1;i<=H;++i)for(int j=1;j<=W;++j)ans+=s[i][j];
	if(ans<=0)return puts("No"),0;
	puts("Yes");
	for(int i=1;i<=H;++i,puts(""))
		for(int j=1;j<=W;++j)
			printf("%d ",s[i][j]);
}

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}

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

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int n,m;
    cin>>n;

    int p=n%10;n/=10;
    int q=n%10;n/=10;
    int r=n%10;

    if(p==7||q==7||r==7)flag=true;
    else flag=false;


    //cout <<fixed<<setprecision(16)<< << endl;

    if(flag)cout << "Yes" <<endl;
    else cout << "No" <<endl;

    return 0;
}


Measured memory_bytes: 3636
let for_range s e step f =
  let rec loop i =
    if i <= e then begin f i;loop (i + step) end
  in loop s;;
 
let sieve num =
  let p = Array.init num (fun x -> x mod 2) in
  let rec loop i =
    if i*i < num then
      begin
        if p.(i) = 1 then for_range (i*i) num (i*2) (fun x -> p.(x) <- 0);
        loop (i+2)
      end
  in
  p.(0) <- 0; p.(1)<-(0);p.(2)<-1;loop 3;
  for i = 3 to num-1 do
    p.(i) <- p.(i) + p.(i-1);
  done;
  p
;;
 
let _ =
  let p = sieve 1000000 in
  let rec read () =
    try let n = read_int () in
        Printf.printf "%d\n" p.(n);
        read ()
    with End_of_file -> ()
  in read ()
;;

Measured memory_bytes: 10148
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <cmath>

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define step(i, f, n, a) for(int (i) = (f); (i) < (n); (i)+=a)
#define rstep(i, f, n, a) for(int (i) = (f); (i) >= (n); (i)-=a)
#define p(...) printf(__VA_ARGS__); cout << endl;
#define gets(x) x; cin >> x;
#define puts(x) x; cout << x << endl;
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](const a, const b){ return c ;}
#define key(t, x, compare) [](const t& a, const t& b){ return a x compare b x ;}

using namespace std;

using ll = long long;
using pii = pair<int, int>;

int main(){
  int A, B;
  gets(A) gets(B)
  if (A == B){
    puts("Draw")
  }else if ((A > B && B != 1) || A == 1) {
    puts("Alice")
  }else{
    puts("Bob")
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int k,a,b;
  	cin >> k >> a >> b;
  	bool e = false;
  	for(int i=a;i<=b;i++){
    	if(i % k == 0) e = true;
    }
  	if(e == true) cout <<"OK" << endl;
  	else cout << "NG" << endl;
}

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

using namespace std;
const int maxn = 1e5+10;

int n;
long long m;
vector<int> graph[maxn];
long long dp[maxn];
vector<long long> pref[maxn];
vector<long long> suf[maxn];
long long sol[maxn];

long long dfs1(int pos, int parr) {
	dp[pos] = 1;
	pref[pos].push_back(1);
	suf[pos].push_back(1);

	for (int i = 0; i < graph[pos].size(); i++) {
		int tren = graph[pos][i];
		if (tren == parr) continue;

		long long ac = dfs1(tren, pos) + 1; ac %= m;
		dp[pos] *= ac, dp[pos] %= m;
		//if (pref[pos].size() == 0) pref[pos].push_back(ac);
		pref[pos].push_back((pref[pos].back() * ac) % m);
	}

	for (int i = graph[pos].size() - 1; i >= 0; i--) {
		int tren = graph[pos][i];
		if (tren == parr) continue;

		long long ac = dp[tren] + 1; ac %= m;
		//if (suf[pos].size() == 0) suf[pos].push_back(ac);
		suf[pos].push_back((suf[pos].back() * ac) % m);
	}
	reverse(suf[pos].begin(), suf[pos].end());
	return dp[pos];
}

void dfs2(int pos, int parr, long long solution) {
    sol[pos] = pref[pos].back() * solution, sol[pos] %= m;
    int ptr = 0;
    for (int i = 0; i < graph[pos].size(); i++) {
        int tren = graph[pos][i];
        if (tren == parr) continue;

        long long ac = pref[pos][ptr] * suf[pos][ptr + 1]; ac %= m;
        long long sen = ac * solution + 1; sen %= m;
        dfs2(tren, pos, sen);
        ptr++;
    }
}

int main() {
	scanf("%d%lld", &n, &m);
	for (int i = 1; i < n; i++) {
		int a, b;
		scanf("%d%d", &a, &b);

		graph[a].push_back(b);
		graph[b].push_back(a);
	}

	dfs1(1, -1);
	dfs2(1, -1, 1);
	for (int i = 1; i <= n; i++)
		printf("%lld\n", sol[i]);
	return 0;
}


Measured memory_bytes: 27264
import java.util.*;

public class Main{
    
    public static final int MOD = (int)1e9+7;
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        long k = Long.parseLong(sc.next());
        
        int[][] dp = new int[100][n];
        for(int i=0; i<n; i++){
            dp[0][i] = Integer.parseInt(sc.next())-1;
        }
        
        for(int i=0; i<64; i++){
            for(int j=0; j<n; j++){
                dp[i+1][j] = dp[i][dp[i][j]];
            }
        }
        
        int ans = 0;
        for(int i=0; i<64; i++){
            if((k & (1L<<i)) > 0){
                ans = dp[i][ans];
            }
        }
        
        System.out.println(ans+1);
        
    }
}


Measured memory_bytes: 156452