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

inline int lowbit(int n){return n & (-n);}

const int moder = 1e9 + 7;
const int N = 300;

int n, m;
int power[N], fac[N], inv[N], mat[N][N], digit[N], dp[1 << 16];

int powermod(int a, int exp){
	int ret = 1;
	for ( ; exp; exp >>= 1){
		if (exp & 1){
			ret = 1ll * ret * a % moder;
		}
		a = 1ll * a * a % moder;
	}
	return ret;
}

int comb(int n, int m){
	if (n < m || m < 0){
		return 0;
	}
	return 1ll * fac[n] * inv[m] % moder * inv[n - m] % moder;
}

int main(){
	fac[0] = 1;
	for (int i = 1; i < N; ++ i){
		fac[i] = 1ll * fac[i - 1] * i % moder;
	}
	inv[N - 1] = powermod(fac[N - 1], moder - 2);
	for (int i = N - 1; i; -- i){
		inv[i - 1] = 1ll * inv[i] * i % moder;
	}
	power[0] = 1;
	for (int i = 1; i < N; ++ i){
		power[i] = 2 * power[i - 1] % moder;
	}
	scanf("%d%d", &n, &m);
	for (int i = 0, u, v; i < m; ++ i){
		scanf("%d%d", &u, &v);
		-- u, -- v;
		mat[u][v] = 1;
	}
	dp[0] = 1; 
	for (int i = 0; i < 1 << n; ++ i){
		if ((i >> 0 & 1) != (i >> 1 & 1)){
		//	continue;
		}
		int cnt = 0, x = i, y;
		for ( ; x; x -= lowbit(x)){
			digit[cnt ++] = lowbit(x);
		}
		for (int j = 0; j < 1 << cnt; ++ j){
			x = 0;
			for (int k = 0; k < cnt; ++ k){
				if (j >> k & 1){
					x ^= digit[k];
				}
			}
			y = i ^ x;
			if ((x >> 0 & 1) != (x >> 1 & 1) || !x){
				continue;
			}
			int ans = 1, cccnt = 0;
			for (int k = 0; k < n; ++ k){
				if (y >> k & 1){
					int ccnt = 0;
					for (int kk = 0; kk < n; ++ kk){
						if (x >> kk & 1){
							if (mat[k][kk]){
								++ ccnt;
							}
							if (mat[kk][k]){
								++ cccnt;
							}
						}
					}
					ans = 1ll * ans * (power[ccnt] - 1 + moder) % moder;
				}
			}
			dp[i] = (dp[i] + 1ll * ans * power[cccnt] % moder * dp[y]) % moder;
		}
	}
	return printf("%d\n", (power[m] - dp[(1 << n) - 1] + moder) % moder), 0;
}

Measured memory_bytes: 384
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
N = int(input())
arrA = np.array(input().split(),dtype=np.int64)
arrA = arrA -1

ans = 0
for i in range(N):
    num = arrA[i]
    if arrA[num]==i:
        ans += 1

print(ans//2)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 22612
#include <stdio.h>
#include <algorithm>

using namespace std;

int to_color(int rate) {
    if (rate >= 3200) return 8;
    return rate / 400;
}

int N;
int a[101];

int main() {
    int h[9] = {0};
    scanf("%d", &N);
    for (int i = 0; i < N; i ++) {
        scanf("%d", &a[i]);
    }
    for (int i = 0; i < N; i ++) {
        int c = to_color(a[i]);
        h[c] ++;
    }
    int m = 0;
    for (int i = 0; i < 8; i ++) {
        if (h[i] > 0) m ++;
    }
    printf("%d %d\n", max(m, 1) , m + h[8]);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;
#define ll long long
#define cpp mp::cpp_int
#define dequeue deque
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = 1; i <= n; i++)
#define drep(i, n) for(int i = n-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define vi vector<int>
#define P pair<ll, ll>
int mod = 1'000'000'000 + 7;
struct edge {
	int to;
	ll cost;
};

void COME_LET_THE_GAMES_BEGIN() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << setprecision(20);
}
void reverse(string* s) {
	reverse((*s).begin(), (*s).end());
}
int main() {
	// COME_LET_THE_GAMES_BEGIN();
	int w, h, x, y;
	scanf("%d%d%d%d", &w, &h, &x, &y);
	cout << (double)w * h / 2 << endl;
	if (x + x == w && y + y == h) {
		puts("1");
	}
	else {
		puts("0");
	}
}

Measured memory_bytes: 256
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int res = 0;
  string s;
  cin >> s;
  REP(i,(int)s.size()/2) {
    if(s[i] != s[s.size()-1-i]) res++;
  }
  cout << res << endl;
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int main()
{
	int a[101][101], b[101][101];
	long long c[101][101], s;
	int i, j, k;
	int n, m, l;

	scanf("%d%d%d", &n, &m, &l);
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) scanf("%d", &a[i][j]);
	}
	for (i = 0; i < m; i++) {
		for (j = 0; j < l; j++) scanf("%d", &b[i][j]);
	}

	for (i = 0; i < n; i++) {
		for (j = 0; j < l; j++) {
			s = 0;
			for (k = 0; k < m; k++) {
				s += a[i][k] * b[k][j];
			}
			c[i][j] = s;
		}
	}

	for (i = 0; i < n; i++) {
		printf("%lld", c[i][0]);
		for (j = 1; j < l; j++) printf(" %lld", c[i][j]);
		putchar('\n');
	}
	return 0;
}






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

int main(){
	int x, y, d, r;
	double a, b, f;
	
	cin >> a >> b;
	x = a;
	y = b;
	d = a/b;
	r = x%y;
	f = a/b;
	
	printf("%d %d %f\n", d, r, f);
	
	return 0;
}

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

int main(){
long long n; cin >>n;
int ans =0;
vector<long long> c;
for(long long i=2;i*i<=n;i++){
  if(n%i==0) {
    int count =1;
    int cnt =0;
    c.push_back(i);
    while(n%i==0) {
      n /=i;
      cnt ++;
    }
  while(count <= cnt ) {
    cnt -= count;
    count ++;
    ans ++;
  }
}
}
if(!(n==1)) ans +=1;

cout << ans <<endl;
cout << endl;

}

Measured memory_bytes: 3624
#include <iostream>

using namespace std;

int main()
{
    int yama[51], tmp[51];

    int n, r;
    while (cin >> n >> r, (n || r))
    {
        for (int i = 0; i < n; i++)
        {
            yama[i] = i + 1;
        }

        for (int i = 0; i < r; i++)
        {
            int p, c;
            cin >> p >> c;
            for (int j = 0; j < c; j++)
            {
                tmp[c - 1 - j] = yama[n - p - j];
            }
            for (int j = n - p + 1; j < n; j++)
            {
                yama[j - c] = yama[j];
            }
            for (int j = 0; j < c; j++)
            {
                yama[n - c + j] = tmp[j];
            }
        }

        cout << yama[n - 1] << endl;
    }
}


Measured memory_bytes: 2992
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

int main(int argc, char const *argv[])
{
	int a, b ,c, d;
	cin >> a >> b >> c >> d;

	if (a * b > c * d)	
	{
		cout << a * b << endl;
	} else	{
		cout << c * d << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		String[] tokens = in.readLine().split(" ");
		int N = Integer.parseInt(tokens[0]);
		int X = Integer.parseInt(tokens[1]);
		int[] L = new int[N];
		tokens = in.readLine().split(" ");
		for (int i = 0; i < N; ++i) {
			L[i] = Integer.parseInt(tokens[i]);
		}
		in.close();

		int count = 1;
		int val = 0;
		for (int i = 0; i < N; ++i) {
			val += L[i];
			if (val <= X) {
				++count;
			} else {
				break;
			}
		}
		System.out.println(count);
	}

}


Measured memory_bytes: 21204
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import java.util.Comparator;
import java.util.Collections;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D solver = new D();
        solver.solve(1, in, out);
        out.close();
    }

    static class D {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int X = in.nextInt();
            int Y = in.nextInt();
            int Z = in.nextInt();
            int K = in.nextInt();

            List<Long> A = new ArrayList<>();
            List<Long> B = new ArrayList<>();
            List<Long> C = new ArrayList<>();
            for (int i = 0; i < X; i++) {
                A.add(in.nextLong());
            }
            for (int i = 0; i < Y; i++) {
                B.add(in.nextLong());
            }
            for (int i = 0; i < Z; i++) {
                C.add(in.nextLong());
            }
            Collections.sort(A, Comparator.reverseOrder());
            Collections.sort(B, Comparator.reverseOrder());
            Collections.sort(C, Comparator.reverseOrder());

            List<Long> ret = new ArrayList<>();
            for (int i = 0; i < A.size(); i++) {
                for (int j = 0; j < B.size(); j++) {
                    for (int k = 0; k < C.size(); k++) {
                        if ((i + 1) * (j + 1) * (k + 1) <= K) {
                            ret.add(A.get(i) + B.get(j) + C.get(k));
                        } else {
                            break;
                        }
                    }
                }
            }
            Collections.sort(ret, Collections.reverseOrder());
            for (int i = 0; i < K; i++) {
                out.println(ret.get(i));
            }
        }

    }
}



Measured memory_bytes: 31280
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>  // https://boostjp.github.io/tips/math.html
#include <boost/dynamic_bitset.hpp>  // https://boostjp.github.io/tips/dynamic_bitset.html

constexpr int64_t DIV1097 = 1000000007LL;

using namespace std;

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

    std::vector<int64_t> A;
    for (decltype(N) i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        A.push_back(t);
    }

    std::vector<int64_t> B;
    for (decltype(N) i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        B.push_back(t);
    }

    std::vector<int64_t> C;
    for (decltype(N) i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        C.push_back(t);
    }

    std::sort(std::begin(A), std::end(A));
    std::sort(std::begin(B), std::end(B));
    std::sort(std::begin(C), std::end(C));

    int64_t ans = 0;
    for (int64_t i = 0; i < N; ++i) {
        auto b = B[i];
        auto c_count = std::distance(std::upper_bound(C.begin(), C.end(), b), C.end());
        auto a_count = std::distance(A.begin(), std::lower_bound(A.begin(), A.end(), b));

        ans += c_count * a_count;
    }

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

    return 0;
}


Measured memory_bytes: 3316
const main = (input: string) => {
  const YY = parseInt(input.slice(0, 2));
  const MM = parseInt(input.slice(2, 4));
  let answer: string = "NA";

  if (isInMonth(YY) && isInMonth(MM)) {
    answer = "AMBIGUOUS";
  } else if (isInMonth(MM)) {
    answer = "YYMM";
  } else if (isInMonth(YY)) {
    answer = "MMYY";
  }

  console.log(answer);
};

const isInMonth = (num: number) => {
  const min = 1;
  const max = 12;
  return num >= min && num <= max;
};

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#define _USE_MATH_DEFINES // M_PI
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,a,n) for(int (i)=(n)-1; (i)>=(a);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2147483647;
constexpr ll mod = 1000000007;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N, K; cin >> N >> K;
	vector<double>p(N);
	rep(i, N) {
		cin >> p[i];
	}
	p[0] = (p[0] + 1) / 2;
	REP(i, 1, N) {
		p[i] = (p[i] + 1) / 2 + p[i - 1];
	}
	double ans = p[K - 1];
	REP(i, 1, N - K) {
		chmax(ans, p[i + K] - p[i]);
	}
	cout << ans << "\n";


	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int,int>P;
typedef pair<P,int>P1;
#define fi first
#define pb push_back
#define sc second
int n;
vector<P1>query;
typedef long long ll;
//range add + range maximum query
#define INF 1000000000000000LL
struct lazy_segtree{
	const static int s = (1<<18);
	ll seg[s];
	ll lazy[s];
    void init(){
        fill(seg,seg+s,INF);
        fill(lazy,lazy+s,INF);
    }
	void lazy_evaluate(int k){
		if(k*2+2>=s) return ;
		lazy[k*2+2]=min(lazy[k],lazy[k*2+2]);
		lazy[k*2+1]=min(lazy[k],lazy[k*2+1]);
		seg[k*2+2]=min(lazy[k],seg[k*2+2]);
		seg[k*2+1]=min(lazy[k],seg[k*2+1]);
		lazy[k]=INF;
	}
	ll update(int beg,int end,int idx,int lb,int ub,ll num){
		if(ub<beg||end<lb){
			return seg[idx];
		}
		if(beg<=lb&&ub<=end){
			lazy[idx]=min(lazy[idx],num);
			seg[idx]=min(seg[idx],num);
			return seg[idx];
		}
		if(lazy[idx] != INF){
			lazy_evaluate(idx);
		}
		return seg[idx]=min(update(beg,end,idx*2+1,lb,(lb+ub)/2,num),update(beg,end,idx*2+2,(lb+ub)/2+1,ub,num));
	}
	ll update(int beg,int end,ll num) { return update(beg,end,0,0,s/2-1,num); }
	ll query(int beg,int end,int idx,int lb,int ub){
		if(ub<beg||end<lb){
			return INF;
		}
		if(beg<=lb&&ub<=end){
			return seg[idx];
		}
		if(lazy[idx] != INF){
			lazy_evaluate(idx);
		}
		return min(query(beg,end,idx*2+1,lb,(lb+ub)/2),query(beg,end,idx*2+2,(lb+ub)/2+1,ub));
	}
	ll query(int beg,int end) { return query(beg,end,0,0,s/2-1); }
}kaede;
int m;
int main(){kaede.init();
    cin >> n >> m;
    rep(i,m){
        int a,b,c; cin >> a >> b >> c;
        query.pb(P1(P(a,b),c));
    }
    sort(query.begin(),query.end());
    kaede.update(1,1,0);
    rep(x,3){
    rep(i,query.size()){
        int a = query[i].fi.fi, b = query[i].fi.sc;
        ll v = kaede.query(a,b); //cout << v << endl;
        //cout << a << b << v+query[i].sc << endl;
        kaede.update(a,b,v+query[i].sc);
    }}
    ll ans = kaede.query(n,n); if(ans == INF) ans = -1;
    cout << ans << endl;
}

Measured memory_bytes: 6008
#include <iostream>
#include <fstream>
using namespace std;
const int nmax=100005;
int p[nmax];
int n,m,i,x,y;
int main()
{
   // freopen("data.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin>>n>>m;
    for(i=1;i<=m;i++)
    {
        cin>>x>>y;
        p[x]^=1;
        p[y]^=1;
    }
    int cate=0;
    for(i=1;i<=n;i++)
        if(p[i])
         cate++;
    if(cate<=1) cout<<"YES";
    else cout<<"NO";
    return 0;
}


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

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

    int l = 0, r = n+1;
    for(int i=0;i<m;i++){
        int a,b;
        cin >> a >> b;
        if(l<a) l = a;
        if(r>b) r = b;
    }

    if(l>r) cout << 0 << endl;
    else cout << r-l+1 << endl;
}

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

int main(){
  int N,M,P;

  while(true){
    cin >> N >> M >> P;
    if(!N && !M && !P) break;
    int nm[101],sum = 0;
    for(int i = 0 ; i < N ; i++){
      cin >> nm[i];
      sum += nm[i];
    }
    if(!nm[M-1]){
      cout << '0' << endl;
      continue;
    }
    int money = sum*(100-P)/nm[M-1];
    cout << money << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
/*
  Compete against Yourself.
  Author - Aryan Choudhary (@aryanc403)
*/

#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define endl "\n"

typedef long long int lli;
typedef long double mytype;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef vector<lli> vi;

clock_t time_p=clock();
void aryanc403()
{
#ifdef ARYANC403
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
#endif
}

#ifdef ARYANC403
#include "/home/priank/codes/PastCodes/header.h"
#else
    #define dbg(args...)
#endif

const lli INF = 0xFFFFFFFFFFFFFFFL;

lli seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}

class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{    return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y ));   }};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt==m.end())         m.insert({x,cnt});
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}

const lli mod = 1000000007L;
// const lli maxN = 1000000007L;

    lli T,n,i,j,k,in,cnt,l,r,u,v,x,y;
    lli m,ans;
    string s;
    vector<vi> e;
    //priority_queue < ii , vector < ii > , CMP > pq;// min priority_queue .

lli po(lli a,lli n)
{
    if(n<0)
    {
        a=po(a,mod-2);
        return po(a,-n);
    }
    if(n==0)
        return 1;
    if(n&1)
        return (a*po(a,n-1))%mod;
    return po(a*a%mod,n/2);
}

lli dfs(lli u,lli p)
{
    lli cnt=1,pr=0;

    for(auto x:e[u])
    {
        if(x==p)
            continue;
        lli v=dfs(x,u);
        pr=(pr+po(2,v)-1)%mod;
        cnt+=v;
    }
    pr=(pr+po(2,n-cnt))%mod;
    pr=(pr*po(2,-n+1))%mod;
    pr=(1-pr+mod)%mod;
    pr*=(mod+1)/2;
    ans=(ans+pr)%mod;
    dbg(u,pr);
    return cnt;
}
int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// cin>>T;while(T--)
{

    cin>>n;
    e.resize(n+1,vi());
    fo(i,n-1)
    {
        cin>>u>>v;
        e[u].pb(v);
        e[v].pb(u);
    }

    dfs(1,1);
    cout<<ans<<endl;
}   aryanc403();
    return 0;
}


Measured memory_bytes: 24832
# -*- coding: utf-8 -*-
import sys

N = int(input().strip())
#-----


class factorization():
    def get_divisor(self, n :int) -> dict:
        divisor_dic={}
        
        tmp_num = n
        for i in range(2,n):
            while tmp_num % i == 0:
                divisor_dic.setdefault(i,0)
                divisor_dic[i] += 1
                
                tmp_num //= i
        
        return divisor_dic


divisor_dic={}  # 階乗を素因数分解し、結果を入れる
for num in range(2,N+1):
    # 階乗の、それぞれの数字について、約数を抽出
    fa = factorization()
    ret = fa.get_divisor(num)

    for key,v in ret.items():
        divisor_dic.setdefault(key,0)
        divisor_dic[key] += v
    
    divisor_dic.setdefault(num,0)
    divisor_dic[num] += 1


cnt_divisor_dic={ i:0 for i in [74,24,14,4,2]}
# 約数の個数が74以上、24,14,4,2以上、で場合分けし、件数を集計
for key,v in divisor_dic.items():
    for j in [74,24,14,4,2]:
        if v >= j:
            cnt_divisor_dic[j] += 1


# 75=5*5*3　をもとに、すべての組み合わせを考え、合計する。
# 75
# 25 × 3(選択した「25以上」の約数は、「3以上」の約数でもあるため、1引いておく)
# 15 × 5(選択した「15以上」の約数は、「5以上」の約数でもあるため、1引いておく)
# 5×5×3 (「5以上」の約数から2つ選択する組み合わせxC2)
sum = cnt_divisor_dic[74] + \
      cnt_divisor_dic[24] * (cnt_divisor_dic[2] - 1) + \
      cnt_divisor_dic[14] * (cnt_divisor_dic[4] - 1) + \
      cnt_divisor_dic[4] * (cnt_divisor_dic[4] - 1) // (2*1) * (cnt_divisor_dic[2] - 2)

print(sum)


Measured memory_bytes: 3064
s = input()
n = len(s)

l = []
length = 1
for i in range(n-1):
    if s[i] == s[i+1]:
        length += 1
    else:
        l.append([i, length])
        length = 1
l.append([i+1, length])

res = [0] * n
for i in range(0, len(l), 2):
    if l[i][1] % 2 == 1:
        res[l[i][0]] = (l[i][1] + l[i+1][1] + 1) // 2
        res[l[i][0]+1] = (l[i][1] + l[i+1][1]) // 2
    else:
        res[l[i][0]] = (l[i][1] + l[i+1][1]) // 2
        res[l[i][0]+1] = (l[i][1] + l[i+1][1] + 1) // 2

for v in res:
    print(v, end=" ")

Measured memory_bytes: 59680
#include <iostream>

using namespace std;

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

	int s = S % 60;
	int m = S / 60;
	int h = m / 60;
	m = m % 60;

	cout << h << ':' << m << ':' << s << endl;

	return 0;
}




Measured memory_bytes: 3136
#include<stdio.h>

int main(void){
  int x , y;
  int i = 0;
  int num;

  for(i = 0; i < 10000; i++){
    scanf("%d %d", &x,&y);

    if(x == 0 && y == 0){
      break;
    }

    if(x > y){
      num = x;
      x = y;
      y = num ;
    }
 printf("%d %d\n",x,y);

  }
  return 0;
}



Measured memory_bytes: 2040
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func gcd(a, b int) int {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}

type xy struct {
	x, y int
}

func main() {
	sc.Split(bufio.ScanWords)

	N := getInt()
	x := make([]int, N)
	y := make([]int, N)
	pt := make(map[xy]int)
	for i := 0; i < N; i++ {
		x[i], y[i] = getInt(), getInt()
		pt[xy{x[i], y[i]}] = 1
	}

	ans := 0
	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			if i == j {
				continue
			}
			dx := x[i] - x[j]
			dy := y[i] - y[j]
			cnt := 0
			// dx,dy（設問のp,q）の距離にあるものをカウント
			for k := 0; k < N; k++ {
				px := dx + x[k]
				py := dy + y[k]
				_, ok := pt[xy{px, py}]
				if ok {
					cnt++
				}
			}
			if ans < cnt {
				ans = cnt
			}
		}
	}
	out(N - ans)
}


Measured memory_bytes: 640
/**
*   Bismillahir Rahmanir Rahim.
*   Imtiaz_rafi
*   PCIU, CHITTAGONG
**/
#include<bits/stdc++.h>
using namespace std;
#define speed() ios::sync_with_stdio(0);cin.tie(0);
#define file() freopen ("input.txt", "r", stdin);freopen ("output.txt", "w", stdout);
#define rep(i,a) for(ll i=0;i<a;i++)
#define rep1(i,begin,end) for(ll i=begin;i<=end;i++)
#define trace(x) cerr << #x << " = " << x << endl
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define all(v)   v.begin(),v.end()
#define rall(v)   v.rbegin(),v.rend()
#define pb push_back
#define pf push_front
#define mp make_pair
#define F first
#define S second
#define pi acos(-1)
#define en '\n'
// bitshift (1LL<<(3)) *2^3
typedef long long int ll;
typedef vector<ll>vi;
typedef map<ll,ll>mi;
typedef pair<ll,ll>pll;
typedef vector<pll> vll;
typedef set<ll>st;
typedef set<char>sc;
ll dx[] = {-1,+1,0,0,+1,-1,+1,-1};
ll dy[] = {0,0,-1,+1,+1,+1,-1,-1};
const ll mx = 1e5+123;
const ll MOD = 1e9+7;

template <class T> T power(T a,T b){a%=MOD;if(!a) return 0;T p=1;while(b>0){if(b&1){p*=a;p%=MOD;}a*=a;a%=MOD;b=b>>1;}return p;}
template <class T> void print(vector<T> &v){for(T u:v){cout<<u<<" ";}cout<<endl;}
template <class T> T gcd(T a, T b){return (b!=0?gcd<T>(b,a%b):a);}
template <class T> T lcm(T a, T b){return (a/gcd<T>(a,b)*b);}

int main()
{
    speed();
    ll a,i,j,sum = 0,ans=0;
    cin>>a;
    vi v(a);
    rep(i,a){
        cin>>v[i];
        sum+=v[i]%MOD;
    }
    rep(i,a){
        sum-=v[i];
        ans+=(((sum%MOD)*(v[i]%MOD))%MOD);
    }
    cout<<ans%MOD<<endl;
return 0;
}


Measured memory_bytes: 4752
package main

import (
	"fmt"
	"math"
	"sort"
	"strconv"
	"strings"
)

func main() {
	var n int
	fmt.Scan(&n)
	var ps, qs string
	for i := 0; i < n; i++ {
		var p int
		fmt.Scan(&p)
		p--
		ps += strconv.Itoa(p)
	}
	for i := 0; i < n; i++ {
		var q int
		fmt.Scan(&q)
		q--
		qs += strconv.Itoa(q)
	}

	o := make([]string, n)
	for i := range o {
		o[i] = strconv.Itoa(i)
	}

	var sl []string
	for {
		sl = append(sl, strings.Join(o, ""))

		if !nextPermutation(sort.StringSlice(o)) {
			break
		}
	}

	sort.Strings(sl)
	var a, b int
	for i, s := range sl {
		if s == ps {
			a = i
		}
		if s == qs {
			b = i
		}
	}

	fmt.Println(math.Abs(float64(a - b)))
}

func nextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}


Measured memory_bytes: 6016
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	int sx,sy,tx,ty;
	public void solve() {
		sx = nextInt();
		sy = nextInt();
		tx = nextInt();
		ty = nextInt();

		int R = tx - sx;
		int U = ty - sy;
		for(int i = 0;i < U;i++){
			out.print("U");
		}
		for(int i = 0;i < R;i++){
			out.print("R");
		}
		for(int i = 0;i < U;i++){
			out.print("D");
		}
		for(int i = 0;i < R;i++){
			out.print("L");
		}

		out.print("L");
		for(int i = 0;i < U + 1;i++){
			out.print("U");
		}
		for(int i = 0;i < R + 1;i++){
			out.print("R");
		}
		out.print("D");
		out.print("R");
		for(int i = 0;i < U + 1;i++){
			out.print("D");
		}
		for(int i = 0;i < R + 1;i++){
			out.print("L");
		}
		out.print("U");
		out.println();
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 8404
def yakusu(n):
    if n == 1:
        return []
    results = []
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            results.append(i)
            results.append(n // i)
    return list(set(results)) + [n]

N = int(input())
count = 0
for i in yakusu(N):
    NN = N
    while NN >= i:
        if NN % i == 0:
            NN //= i
        else:
            NN %= i
    if NN == 1:
        count += 1
for i in yakusu(N-1):
    NN = N
    while NN >= i:
        if NN % i == 0:
            NN //= i
        else:
            NN %= i
    if NN == 1:
        count += 1
print(count)


Measured memory_bytes: 39664
n,k = map(int,input().split())
a = list(map(int,input().split()))
l = 0
r = 10 ** 9

while r-l > 1 :
    m = (l+r)//2 
    b = list(map(lambda x: -(-x//m) - 1 ,a))
    ans = sum(b)
    if ans <= k :
        r = m
    else :
        l = m

print(r)

         



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


int main()
{
	int n;
	std::cin >> n;
	int act = 3;
	std::vector<std::vector<int>> v(n);
	for (auto& elem : v) elem.resize(act, 0);
	for (auto& elem : v)
		for (auto& happy : elem) std::cin >> happy;

	std::vector<int> sum(act, 0);
	std::vector<int> prev(act, 0);
	for (int day = 0; day < n; ++day) {
		for (int i = 0; i < act; ++i) {
			if (prev[(i + 1) % act] > prev[(i + 2) % act]) {
				sum[i] = v[day][i] + prev[(i + 1) % act];
			}
			else {
				sum[i] = v[day][i] + prev[(i + 2) % act];
			}
		}
		prev = sum;
	}

	std::cout << *std::max_element(sum.begin(), sum.end()) << "\n";
}

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

int main(void){

  int N,S;
  int sum;

  while(1){

    cin >> N;

    if( N == 0 ) break;

      sum = 0;

      for( int j = 1 ; j*j <= N; j++ ){
	
	if( N % j == 0 ){ 
	  sum += j;
	  if( j*j != N ) sum += N/j;
           
	}
    }
      
      sum -= N;

    if( N < sum ) cout << "abundant number" << endl;
    else if( N > sum ) cout << "deficient number" << endl;
    else cout << "perfect number" << endl;

  }

  return 0;

}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll A, B; cin >> A >> B;
    cout << 6 - A - B << endl;
}

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


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <iomanip>
#include <deque>
#include <queue>
#include <unordered_map>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
ll intpow(ll N, ll P){
    if(P==0) return 1;
    if(P%2==0){
        ll t = intpow(N, P/2);
        return t*t;
    }
    return N * intpow(N, P-1);
}
ll modpow(ll N, ll P,ll k){
    if(P==0) return 1;
    if(P%2==0){
        ll t = modpow(N, P/2,k)%k;
        return t*t%k;
    }
    return N * modpow(N, P-1,k)%k;
}
ll modkai(ll n,ll m,ll k){//n*(n-1)*(n-2)*...(m+1)%k
    if(n == m)return 1;
    return modkai(n-1,m,k)*n%k;
}
ll mod_cnb(ll n,ll m,ll k){//nCm%k,kは十分大きい素数
  int m_=modkai(m,0,k);
  return modkai(n,n-m,k)*modpow(m_,k-2,k)%k;
}
ll gcd(ll n,ll m){
    ll n_ = max(n,m);
    ll m_ = min(n,m);
    if(n_%m_ == 0)return m_;
    return gcd(m_,n_%m_);
}
ll lcm(ll n,ll m){
    return n*m/gcd(n,m);
}
int main(){
    ll n,k;cin>>n>>k;
    ll p=1e9+7;
    rep(i,k){
        if(n-k+1<i+1||k<i+1)cout<<0<<endl;
        else cout<<mod_cnb(n-k+1,i+1,p)*mod_cnb(k-1,i,p)%p<<endl;
        }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrepi(i,a,b) for(int i=((int)(b)-1);i>=(a);--i)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) rrepi(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define ZERO(x) memset(x,0,sizeof(x))
#define MINUS(x) memset(x,-1,sizeof(x))
#define UNIQUE(x) (x).erase(unique(ALL(x)), (x).end())
#define debug(var)  do{std::cout << #var << " : "; view(var);}while(0)
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){for(const auto& v : vv){ view(v); } }
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void viewarr(T arr[], int n) { for(int i = 0; i < n; ++i) std::cout << arr[i] << " "; std::cout << std::endl; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll qp(ll a,ll b){ll ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
ll qp(ll a,ll b,ll mo){ll ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const int INF = 1e9;
const ll INFL = 1e18;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5;

struct unionfind {
    int n;
    vector<int> par;

    unionfind(int n):n(n),par(n,-1){}

    int root(int x) {
        if(par[x] < 0) {
            return x;
        } else {
            return par[x] = root(par[x]);
        }
    }

    int size(int x) {
        return -par[root(x)];
    }

    bool unite(int a, int b) {
        a = root(a);
        b = root(b);
        if(a == b) return 0;
        if(size(a) < size(b)) swap(a,b);
        par[a] += par[b];
        par[b] = a;
        return 1;
    }

    bool same(int a, int b) {
        return root(a) == root(b);
    }
};


int main() {
    int N, M, K; cin >> N >> M >> K;
    vector<int> A(M), B(M), C(K), D(K);
    vector<int> E(N,0);
    vector<int> F(N,0);
    vector<int> ans(N);
    unionfind uni(N);
    rep(i,M) {
        cin >> A[i] >> B[i];
        --A[i]; --B[i];
        ++E[A[i]]; ++E[B[i]];
        uni.unite(A[i], B[i]);
    }
    rep(i,K) {
        cin >> C[i] >> D[i];
        --C[i]; --D[i];
        if(uni.same(C[i],D[i])) {
            ++F[C[i]]; ++F[D[i]];
        }
    }
    rep(i,N) {
        ans[i] = uni.size(i) - E[i] - F[i] - 1;
    }
    rep(i,N) printf("%d%c", ans[i], (i != N-1 ? ' ' : '\n'));
    return 0;
}


Measured memory_bytes: 3968
#include<stdio.h>
int main(){
  char s1,s2;
  char tenn;
  int data[3]={0};
  int i;
  data[0]=1;
  while(scanf(" %c",&s1)!=EOF){
    scanf("%c%c",&tenn,&s2);
    if(data[s1-'A']==1){
      data[s1-'A']=0;
      data[s2-'A']=1;
    } else if(data[s2-'A']==1){
      data[s1-'A']=1;
      data[s2-'A']=0;
    } else{
      data[s1-'A']=0;
      data[s2-'A']=0;
    }
  }
  
  for(i=0;i<3;i++){
    if(data[i]==1){
      printf("%c\n",('A'+i));
    }
  }
  return(0);
}

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

using namespace std;
const long long INF = (long long) (1e18)+1;

int main() {
  long long x;
  cin >> x;
  // 500 => 1000
  // 5 -> 5
  
  long long ans = 0;
  long long num_500 = x / 500;
  x -= 500 * num_500;
  long long num_5 = x / 5;
  ans = (num_500 * 1000) + (num_5 * 5); 
  
  cout << ans << endl;
  return 0;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string c;
  cin>>c;
  if(c[0]=='a'&&c[1]=='b'&&c[2]=='c')
    cout<<"Yes";
  else if(c[0]=='a'&&c[1]=='c'&&c[2]=='b')
    cout<<"Yes";
  else if(c[0]=='b'&&c[1]=='a'&&c[2]=='c')
    cout<<"Yes";
  else if(c[0]=='b'&&c[1]=='c'&&c[2]=='a')
    cout<<"Yes";
  else if(c[0]=='c'&&c[1]=='a'&&c[2]=='b')
    cout<<"Yes";
  else if(c[0]=='c'&&c[1]=='b'&&c[2]=='a')
    cout<<"Yes";
  else cout<<"No";
  return 0;
}

Measured memory_bytes: 256
n,w = map(int,input().split())
wv_list = [map(int,input().split()) for _ in range(n)]
dp = [0]*(w+1)
for ww,vv in wv_list:
    for i in range(w, ww-1, -1):
        t = dp[i-ww] + vv
        dp[i] = max(dp[i], t)
print(max(dp))

Measured memory_bytes: 41708
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
using namespace std;
using ll = long long;
using pii = pair<int,int>;
template<typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a){
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os, vector<T> v){
    for(auto x:v)os << x << ' ';
    return os;
}
void debug(){cerr << '\n';}
template<typename H, typename... T>
void debug(H a, T... b){
    cerr << a;
    if(sizeof...(b))cerr << ", ";
    debug(b...);
}
int main(){
    int ans = 0;
    int M, D;
    cin >> M >> D;
    for(int i = 1; i <= M; i++){
        for(int j = 1; j <= D; j++){
            int a = j / 10;
            int b = j % 10;
            if(a >= 2 and b >= 2 and a * b == i){
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
long long f[300010], inv[300010];

long long modpow(long long b, long long e) {
  if(e == 0) return 1;
  if(e & 1) return (modpow(b, e-1) * b) % mod;
  long long m = modpow(b, e >> 1);
  return (m * m) % mod;
}
long long inverse(long long x) {
  return modpow(x, mod - 2);
}
long long nCr(int n, int r) {
  long long num = f[n];
  long long den = (inv[r] * inv[n - r]) % mod;
  return (num * den) % mod;
}
int main() {
	int n, a, b;
	long long k;
	scanf("%d %d %d %lld", &n, &a, &b, &k);
	
	f[0] = inv[0] = 1;
	for(int i = 1; i <= n; i++) {
		f[i] = f[i - 1] * i;
		f[i] %= mod;
		inv[i] = inverse(f[i]);
	}
	long long ans = 0;
	for(int i = 0; i <= n; i++) {
		long long j = k - (i * a);
		if(j >= 0 && j % b == 0) {
			j /= b;
			if(j <= n) ans += nCr(n, i) * nCr(n, j);
			ans %= mod;
		}
	}
	printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 4992
//hate penalty

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

int dsu[200001], dsu2[200001];
map <pair<int, int> ,int> mp;

int find(int x){
	if (dsu[x]) return dsu[x]=find(dsu[x]);
	return x;
}

int find2(int x){
	if (dsu2[x]) return dsu2[x]=find2(dsu2[x]);
	return x;
}

int main(){
	int n, k, l;
	cin >> n >> k >> l;
	int x, y;
	for (int i=1; i<=k; i++){
		cin >> x >> y;
		if (find(x)!=find(y)){
			dsu[find(x)]=find(y);
		}
	}
	for (int i=1; i<=l; i++){
		cin >> x >> y;
		if (find2(x)!=find2(y)){
			dsu2[find2(x)]=find2(y);
		}
	}
	for (int i=1; i<=n; i++){
		mp[make_pair(find(i),find2(i))]++;
	}
	for (int i=1; i<n; i++){
		cout << mp[make_pair(find(i), find2(i))] << " ";
	}
	cout << mp[make_pair(find(n), find2(n))] << "\n";
}


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

#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define mp make_pair
#define all(x) (x).begin(), (x).end()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 3003, MOD = 1e9 + 7;
int n, q, a[N], X[N], Y[N], dp[N][N], pw[N];
int rt = (MOD + 1) / 2;

void add(int & x, int y) {
	x += y;
	if (x >= MOD) {
		x -= MOD;
	}
}

void dbg() {
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			cout << dp[i][j] << ' ';
		}
		cout << '\n';
	}
	cout << '\n';
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	cin >> n >> q;
	pw[0] = 1;
	for (int i = 1; i < N; i++) {
		pw[i] = (ll)pw[i - 1] * 2 % MOD;
	}
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= q; i++) {
		cin >> X[i] >> Y[i];
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (i == j) {
				continue;
			}
			if (a[i] < a[j]) {
				dp[i][j] = 1;
			}
		}
	}
	for (int i = 1; i <= q; i++) {
		int x = X[i], y = Y[i];
		int t1 = dp[x][y], t2 = dp[y][x];
		add(dp[x][y], t2);
		add(dp[y][x], t1);
		dp[x][y] = (ll)dp[x][y] * rt % MOD;
		dp[y][x] = (ll)dp[y][x] * rt % MOD;
		for (int j = 1; j <= n; j++) {
			if (j == x || j == y) {
				continue;
			}
			int d1 = dp[j][x], d2 = dp[j][y];
			int d3 = dp[x][j], d4 = dp[y][j];
			add(dp[j][x], d2);
			dp[j][x] = (ll)dp[j][x] * rt % MOD;
			add(dp[j][y], d1);
			dp[j][y] = (ll)dp[j][y] * rt % MOD;
			add(dp[x][j], d4);
			dp[x][j] = (ll)dp[x][j] * rt % MOD;
			add(dp[y][j], d3);
			dp[y][j] = (ll)dp[y][j] * rt % MOD;
		}
	}
	int res = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j < i; j++) {
			add(res, dp[i][j]);
		}
	}
	cout << (ll)res * pw[q] % MOD;
}


Measured memory_bytes: 35584
import copy
n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
a=0
b=0
pp=copy.copy(p)
qq=copy.copy(q)
pp.sort()
qq.sort()

def fact(x):
    if x<1:
        return 1
    return x*fact(x-1)

for i in range(n):
    f=fact(n-(i+1))
    ppp=p[i]
    qqq=q[i]
    ap=1
    bq=1
    for j in range(len(pp)):
        if j<len(pp):
            if ppp==pp[j]:
                pp.pop(j)
                ap=j+1
        if j<len(qq):
            if qqq==qq[j]:
                qq.pop(j)
                bq=j+1
    a+=f*ap
    b+=f*bq
print(abs(a-b))

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

using namespace std;

int main()
{
    
    long long n,m;
    cin>>n>>m;
    if(n==1||m==1){cout<<1<<endl;return 0;}
    cout<<(m/2+m%2)*(n/2+n%2)+(m/2)*(n/2)<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if ((a+d-1)/d >= (c+b-1)/b)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i += 2) {
        int c = 0;
        for (int j = 1; j <= i; j++) if (i % j == 0) c++;
        if (c == 8) ans++;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
// Two Coins

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>
#include <numeric>

using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    if (a+b >= c) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }


    return 0;
}


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

int main() {
	vector<int>v(5); for (int i = 0; i < 5; i++)cin >> v[i];
	int maxi = 0;
	for (int i = 0; i < 5; i++) {
		if (v[i] % 10 == 0) continue;
		maxi = max(maxi, 10 - v[i] % 10);
	}

	int maxIte = 0;
	for (int i = 0; i < 5; i++) {
		if (maxi == (10-v[i] % 10)) maxIte = i;
	}

	int ans = 0;
	for (int i = 0; i < 5; i++) {
		if (i != maxIte) {
			if(v[i] % 10 == 0) ans += v[i];
			else ans += (v[i] + (10 - v[i] % 10));
		}
	}
	ans += v[maxIte];
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int inf=0x7f7f7f7f;
int n,tot,head[1010],nxt[1010],to[1010];
unsigned int x[1010],dp[5010],f[1010];
void add_edge(int u,int v){
	nxt[++tot]=head[u];
	to[tot]=v;
	head[u]=tot;
	return;
}
void dfs(int u){
	for(int i=head[u];~i;i=nxt[i])
		dfs(to[i]);
	memset(dp,127,sizeof(dp));
	dp[0]=0;
	for(int i=head[u];~i;i=nxt[i]){
		int v=to[i];
		for(int j=x[u];~j;j--){
			unsigned int tmp=inf;
			if(j>=x[v])
				tmp=min(tmp,dp[j-x[v]]+f[v]);
			if(j>=f[v])
				tmp=min(tmp,dp[j-f[v]]+x[v]);
			dp[j]=tmp;
		}
	}
	for(int i=0;i<=x[u];i++)
		f[u]=min(f[u],dp[i]);
	return;
}
int main(){
	memset(head,-1,sizeof(head));
	scanf("%d",&n);
	for(int i=2;i<=n;i++){
		int fthr;
		scanf("%d",&fthr);
		add_edge(fthr,i);
	}
	for(int i=1;i<=n;i++)
		scanf("%u",x+i);
	memset(f,127,sizeof(f));
	dfs(1);
	puts(f[1]!=inf?"POSSIBLE":"IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 256
//110
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include <vector>
using namespace std;
int main(){
    int N;
    cin >> N;
    
    vector<string> vec(N);

    for(int i = 0; i < N; i++)
    {
        /* code */
        cin >> vec[i];
    }

    bool flag = true;
    for(int i = 1; i < N; i++)
    {
        /* code */
        int sl = vec[i-1].size();
        if(vec[i][0] != vec[i-1][sl-1]){
            flag = false;
        }
        for(int j = 0; j < i; j++)
        {
            /* code */
            if(vec[i] == vec[j]){
                flag = false;
            }
        }
        
    }
    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  
  int N,V[20]={},C[20]={},i,max=0,pro[20]={};
  
  scanf("%d",&N);
  
  for(i=0;i<N;i++)
    scanf("%d",&V[i]);
  for(i=0;i<N;i++)
    scanf("%d",&C[i]);
  
  for(i=0;i<N;i++){
    pro[i]=V[i]-C[i];
    if(pro[i]>0)
      max+=pro[i];
  }
  printf("%d",max);
  
    
  
}

Measured memory_bytes: 128