akhauriyash/Code-Regression huggingface dataset:
N, K = [int(_) for _ in input().split()]
R, S, P = [int(_) for _ in input().split()]
T = input()
ans = 0
dp = {}
dp['r'] = []
dp['s'] = []
dp['p'] = []
for i in range(K):
    s = T[i::K]
    now = s[0]
    l = 1
    for d in s[1:]:
        if now == d:
            l += 1
        else:
            dp[now] += [l]
            now = d
            l = 1
    dp[now] += [l]
for r in dp['r']:
    ans += P * ((r + 1) // 2)
for s in dp['s']:
    ans += R * ((s + 1) // 2)
for p in dp['p']:
    ans += S * ((p + 1) // 2)
print(ans)


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

if (b-a)%2 == 0:
    print((b-a)//2)
else:
    if n-b > a-1:
        diff = a-1
        a -= diff
        b -= diff+1
        print(diff + 1 + (b-1)//2)
    else:
        diff = n-b
        a += diff+1
        b += diff
        print(diff + 1 + (n-a)//2)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    int arr[n],angka;
    int i,j=0,k=0,maxi = 0,cnt = 0;
    for(i=0;i<n;i++)
    {
        scanf("%d",&angka);
        if(angka % 2 == 0)
        {
            while(angka % 2 == 0)
            {
                cnt++;
                angka = angka / 2;
            }
        }
    }
    printf("%d\n",cnt);
    return 0;
}


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

int max(int a, int b){
    if(a>b) return a;
    return b;
}

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);

    int a, b;
    cin >> a >> b;
    
    int first = a + (a-1);
    int second = b + (b-1);
    int third = a + b;

    if(first >= second and first >= third) cout << first << endl;
    else if(second >= first and second >= third) cout << second << endl;
    else cout << third << endl;
    
}

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

int main()
{
  int n;
  int debt = 100000;

  scanf("%d", &n);
  for (int i = 0; i < n; i++){
    debt = debt / 100 * 105;
    if (debt % 1000 != 0){
      debt = (debt / 1000 + 1) * 1000;
    }
  }
  printf("%d\n", debt);

  return (0);
}

Measured memory_bytes: 1184
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>

using namespace std;

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  string s,t;
  int n,m;
  cin >> s >> t;
  n = s.size();
  m = t.size();
  for (int i = 0; i < n; i++){
    if (s[i] != t[i]){
      cout << "No\n";
      return 0;
    }
  }
  if (n == m - 1){
    cout << "Yes\n";
  }
  else{
    cout << "No\n";
  }
  return 0;
}

Measured memory_bytes: 3628
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

S=get_nsp
if S[2]==S[3] and S[4]==S[5]
    puts "Yes"
else
    puts "No"
end

Measured memory_bytes: 1788
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <memory.h>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <ctime>
#include <iostream>
#include <functional>
#include <complex>
#include <stdlib.h>
#include <random>
#include <fstream>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<pii, int> p3i;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<p3i> v3i;
typedef vector<vii> vvii;
typedef vector<p3i> vp3i;
typedef long double ld;
typedef vector<ld> vld;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define REPD(i, n) for (int (i) = (n) - 1; (i) >= 0; (i)--)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define FORD(i,a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define rv(v) reverse(all(v))
#define CL(v, val) memset((v), (val), sizeof((v)))
#define SORT(a) sort(all(a))
#define un(v) SORT(v), (v).resize(unique(all(v)) - (v).begin())
#define eps 1.0e-9
#define X first
#define Y second
#define bit(n) (1 << (n))
#define bit64(n) (ll(1) << (n))
#define sqr(x) ((x) * (x))
#define sq5(x) ((x) * (x) * (x) * (x) * (x))
#define N 100005

ll a[N];

int main(void) {
	int n;
	scanf("%d", &n);
	double l10 = 0;
	bool zero = 0;
	REP(i, n) {
		scanf("%lld", &a[i]);
		if (a[i] == 0) {
			zero = 1;
		}
		l10 += log10(1.0 * a[i]);
	}

	if (zero == 1) {
		printf("0\n");
		return 0;
	}

	//printf("%.9lf\n", l10);

	if (l10 - 18 > eps) {
		printf("-1\n");
		return 0;
	}

	ll res = 1;
	REP(i, n) {
		res *= a[i];
	}

	if (res > 1000000000000000000ll) {
		printf("-1\n");
		return 0;
	}

	printf("%lld\n", res);


	return 0;
}


Measured memory_bytes: 4812
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
const int64 INF = 1LL << 58;

int N, A[200000];
int64 sum[200000];

bool Find(const int& pos, const int64& size){
  int hoge = distance( sum, lower_bound( sum + pos + 1, sum + N + pos + 1, sum[pos] + size));
  if(hoge == N + pos + 1) return false;
  int fuga = distance( sum, lower_bound( sum + hoge + 1, sum + N + pos + 1, sum[hoge] + size));
  if(fuga == N + pos + 1) return false;
  int foo = distance( sum, lower_bound( sum + fuga + 1, sum + N + pos + 1, sum[fuga] + size));
  return(foo != N + pos + 1);
}


bool calc(int64 size){ //size: 1個あたりの大きさ
  for(int pos = 0; pos < N; pos++){
    if(Find(pos, size)) return true;
  }
  return false;
}

int main(){

  scanf("%d", &N);
  for(int i = 0; i < N; i++){
    scanf("%d", A + i);
    A[N + i] = A[i];
  }

  sum[0] = A[0];
  for(int i = 1; i < 2 * N; i++){
    sum[i] = sum[i - 1] + A[i];
  }

  int64 low = 0, high = sum[2 * N - 1] / 3;
  while(high != low){
    int64 mid = (low + high + 1) >> 1;
    if(calc(mid)) low = mid; else high = mid - 1;
  }
  printf("%lld\n", low);
}

Measured memory_bytes: 3532
#include<iostream>
using namespace std;
//C
//int h[100000];
//int a[100000], b[100000];
//int hflag[100000];

//D

int main() {
	//A
	/*char a[3];
	cin >> a;
	if (a[1] == 'B') { cout << "ARC"; }
	else { cout << "ABC"; };
	return 0;
	*/
	//B
	/*int n;
	int k;
	int d[100];
	int a[100][100];
	int sunuke[100];
	cin >> n;
	cin >> k;
	int i,j;
	for (i = 0; i < n; i++) {
		sunuke[i] = 0;
	}
	for (i = 0; i < k; i++) {
		cin >> d[i];
		for (j = 0; j < d[i]; j++)
		{
			cin >> a[i][j];
			sunuke[a[i][j]-1]++;
		}
	}
	int c = 0;
	for (i = 0; i < n; i++) {
		if (sunuke[i] == 0) { c++; }
	}
	cout << c;
	return 0;*/
	//C
	
	/*int n, m;
	cin >> n;
	cin >> m;

	int i;
	int c = 0;

	for (i = 0; i < n; i++) {
		cin >> h[i];
	}
	for (i = 0; i < m; i++) {
		cin >> a[i];
		cin >> b[i];
	}
	for (i = 0; i < 100000; i++) {
		hflag[i] = 1;
	}
	for (i = 0; i < m; i++) {
		cout << a[i];
		cout << ' ';
		cout << b[i];
		cout << ' ';
		if (h[a[i]-1] > h[b[i]-1]) {
			hflag[b[i]-1] = 0;
			//cout << b[i] - 1;
		}
		else if(h[a[i] - 1] < h[b[i] - 1]){
			hflag[a[i]-1] = 0;
			//cout << a[i] - 1;
		}
		else {
			hflag[a[i] - 1] = 0;
			hflag[b[i] - 1] = 0;
		}
		//cout << '\n';
	}
	for (i = 0; i < n; i++) {
		if (hflag[i] == 1) {
			c++;
		}
	}
	cout << c;
	return 0;*/
	//D
	long long int a, b, x;
	cin >> x;
	int i,j;
	for (i = 0; i < 140; i++) {
		for (j = 0; j < 140; j++) {
			if (i * i * i * i * i - j * j * j * j * j == x) {
				cout << i;
				cout << ' ';
				cout << j;
				return 0;
			}
			else if (i * i * i * i * i + j * j * j * j * j == x) {
				cout << i;
				cout <<' ';
				cout << -j;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
using vc = vector<char>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int main(){
  int n;
  cin >> n;
  vi b(n);
  rep(i,n){
    int a;
    cin >> a;
    if(a > i+1){
      cout << -1 << endl;
      return 0;
    }
    b.at(i) = a;
  }
  vb seen(n, false);
  vi ans;
  rep(i,n){
    int comp = n-i;
    for(int j=n-1; j>=0; j--){
      if(seen.at(j)) continue;
      if(b.at(j) == comp){
        ans.push_back(comp);
        seen.at(j) = true;
        break;
      }
      comp--;
    }
  }
  rep(i,ans.size()){
    cout << ans.at(ans.size()-1-i) << endl;
  }
}

Measured memory_bytes: 256
x = int(input())

y = 1000
s = -1000
t = -1000

a = 0
b = 0

while s < y:
    t = -y
    while t < y:
        if s ** 5 - t ** 5 == x:
            a = int(s)
            b = int(t)
        t += 1
    s += 1

print(a, b)






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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll A, V, B, W, T;
    cin >> A >> V >> B >> W >> T;

    ll d = (V - W) * T;
    ll e = abs(A - B);
    if (d >= e) {
        cout << "YES"
             << "\n";
    }
    else {
        cout << "NO"
             << "\n";
    }
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

vector<int> es[114514];

int main() {
  rep(i, 3) {
    int u, v;
    scanf("%d%d", &u, &v);
    --u;
    --v;
    es[u].eb(v);
    es[v].eb(u);
  }

  rep(i, 4) {
    if (es[i].size() >= 3) {
      puts("NO");
      return 0;
    } 
  }
  puts("YES");
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
import itertools


def actual(N, K):
    op_A = lambda i: i * 2
    op_B = lambda i: i + K

    patterns = list(itertools.product((op_A, op_B), repeat=N))

    results = []

    for pattern in patterns:
        num = 1

        for op in pattern:
            num = op(num)

        results.append(num)

    return min(results)

N = int(input())
K = int(input())

print(actual(N, K))


Measured memory_bytes: 9104
import math
N,K=map(int,input().split(" "))

X=0
Ans=0
for i in range(N):
    if i+1<K:
        X=math.log2(K/(i+1))
        X2=math.ceil(X)
        Ans+=((0.5)**X2)*(1/N)
    else:
        Ans+=((N-K+1)/N)
        break


print(Ans)

Measured memory_bytes: 3060
#include <stdio.h>

int main(void)
{
	int a, b, c;
	int sur, i;
	
	scanf("%d %d %d", &a, &b, &c);
	
	if(a == 1){
		printf("YES\n");
		return 0;
	}
	else{
		for(i=1; (sur!=a%b)||(i==2); i++){
			sur = a*i % b;
			
			if(sur == c){
				printf("YES\n");
				return 0;
			}
		}
	}
	
	printf("NO\n");
	
	
	return 0;
}


Measured memory_bytes: 128
/**
 *    author:  Mohamad Milhem
 *    created: 2020-01-26-19.28.52
**/

#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define MOD ll(1000000007)
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<endl;

int main(){

    FAST;

    int n,k;
    cin >> n >> k;
    vector<int> v(n);

    for (int i = 0 ; i < n ; i++){
        cin >> v[i];
    }

    sort(v.rbegin(),v.rend());

    long long sum = 0;

    for (int i = 0 ; i < n ; i++){
        if (i >= k)sum+= v[i];
    }

    cout << sum <<endl;


    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 
int main(void){
  char a,b;
  cin >> a >> b;
  if(a>b)cout<<">"<<endl;
  else if(a<b)cout << "<"<<endl;
  else cout << "=" << endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	String s = sc.next();
      	if(s.charAt(0) != s.charAt(1)
           && s.charAt(0) != s.charAt(2)
           && s.charAt(1) != s.charAt(2)){
        	System.out.println("Yes");
        }else{
        	System.out.println("No");
        }
    }
}

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

int64_t length['z' + 1];
map<pair<int,int64_t>, int64_t> assigned;

char *code;
int64_t expr(){
    if('0' <= *code && *code <='9'){
        int64_t value = *(code++) - '0';
        while('0' <= *code && *code <='9'){
            value = value * 10 + (*(code++) - '0');
        }
        return value;
    }
    int name = *(code++);
    assert(*(code++) == '[');
    int64_t idx = expr();
    assert(*(code++) == ']');
    if(idx < 0 || idx >= length[name] || assigned.count({name, idx}) == 0) return -1;
    else return assigned[{name, idx}];
}
bool parse(char *s){
    code = s;
    int name = *(code++);
    int lidx, rval;
    assert(*(code++) == '[');
    lidx = expr();
    assert(*(code++) == ']');
    if(*code == '='){
        ++code;
        rval = expr();
        if(rval < 0 || lidx < 0 || lidx >= length[name]) return false;
        assigned[{name, lidx}] = rval;
    }else{
        length[name] = lidx;
    }
    return true;
}

int main(){
    while(true){
        for(int c='a';c<='z';++c) length[c] = -1;
        for(int c='A';c<='Z';++c) length[c] = -1;
        assigned.clear();
        int ans = 0, line = 1;
        char s[81];
        scanf("%s", s);
        if(s[0] == '.') break;
        while(s[0] != '.'){
            if(ans == 0 && !parse(s)) ans = line;
            scanf("%s", s);
            ++line;
        }
        printf("%d\n", ans);
    }
    return 0;
}


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

int main(){
    int N, M;
    cin >> N >> M;
    int u = 0, v = 0;
    if (N >= 2) u = N *(N - 1) / 2;
    if (M >= 2) v = M * (M - 1) / 2;
    cout << u + v << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#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 maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T) >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<int,P> PP;

vector<PP> v;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
int main()
{
	ll n,m;
	cin >> n >> m;
	ll a[n];
	PQ(ll) Q;

	rep(i,n){
		cin >> a[i];
		Q.push(a[i]);
	}
	ll ans = 0;
	while(m>0){
		ll cost = Q.top();
		//cout << cost << endl;
		if(!cost) break;
		Q.pop();
		Q.push(cost/2);
		m--;
	}

	while(!Q.empty()){
		ll cost = Q.top();
		//cout << cost << " ans " << ans << endl;
		Q.pop();
		ans += cost;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1912
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll n,s=0,sum=0;
  cin>>n;
  
ll a[n];
for(int i=0;i<n;i++)
{
  cin>>a[i];
  s+=a[i];
}
ll avg=round(s/double(n));
for(int i=0;i<n;i++)
{
sum+=((avg-a[i])*(avg-a[i]));
}
cout<<sum<<endl;
  
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdbool.h>
#define N 8
#define FREE -1
#define NOT_FREE 1

int row[N], col[N], dpos[2 * N - 1], dneg[2 * N - 1];
bool X[N][N];

void initialize() {
	int  i;
	for(i = 0; i < N;i++) {
		row[i] = FREE;
		col[i] = FREE;
	}
	for(i = 0; i < 2 * N -1; i++) {
		dpos[i] = FREE;
		dneg[i] = FREE;
	}
}

void printBoard() {
	int i,j;
	for(i = 0; i < N; i++) {
		for(j = 0; j < N; j++) {
			if(X[i][j]) {
				if(row[i] != j) return;
			}
		}
	}
    
	for(i = 0; i < N; i++) {
		for(j = 0;j < N; j++) {
			printf("%s", row[i] == j ? "Q" : ".");
		}
        printf("\n");
    }
}

void recursive(int i) {
    int j;
	
	if(i == N) {
		printBoard();
		return;
	}

	for(j = 0;j < N; j++) {
		if(NOT_FREE == col[j] || NOT_FREE == dpos[i + j] 
			|| NOT_FREE == dneg[ i - j+ N -1])  continue;

		row[i] = j;
		col[j] = dpos[i + j] = dneg[i - j + N -1] = NOT_FREE;
		recursive(i + 1);
		row[i] = col[j] = dpos[i + j] = dneg[i - j + N -1] = FREE;
	}
}

int main() {
	int i,j,k,r,c;
	initialize();

	for(i = 0; i < N; i++){
		for(j =0; j < N; j++) {
			X[i][j] = false;
		}
	}

	scanf("%d", &k);
	for(i = 0; i < k; i++) {
		scanf("%d %d", &r, &c);
		X[r][c] = true;
	}

	recursive(0);
	
	return 0;
}



Measured memory_bytes: 2112
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <queue>

using namespace std;

int main() {
    
    
    int n, q;
    cin >> n >> q;
    string f;
    cin >> f;
    vector<pair<char, char>> qq;
    
    for (int i = 0; i < q; ++i)
    {
        char t, d;
        cin >> t >> d;
        qq.push_back(make_pair(t, d));
    }
    
    int ls = -1;
    int le = n;
    int rs = -1;
    int re = n;
    
    while (le - ls > 1)
    {
        int m = (le + ls) / 2;
        int pos = m;
        for (int i = 0; i < q; ++i)
        {
            char t = qq[i].first;
            char d = qq[i].second;
            if (f[pos] == t)
            {
                if (d == 'L')
                {
                    pos--;
                }
                else
                {
                    pos++;
                }
            }
            if (pos < 0)
            {
                ls = m;
                break;
            }
            else if (pos > n - 1)
            {
                le = m;
                break;
            }
            if (i == q - 1)
            {
                le = m;
            }
        }
    }
    
    while (re - rs > 1)
    {
        int m = (re + rs) / 2;
        int pos = m;
        for (int i = 0; i < q; ++i)
        {
            char t = qq[i].first;
            char d = qq[i].second;
            if (f[pos] == t)
            {
                if (d == 'L')
                {
                    pos--;
                }
                else
                {
                    pos++;
                }
            }
            if (pos < 0)
            {
                rs = m;
                break;
            }
            else if (pos > n - 1)
            {
                re = m;
                break;
            }
            if (i == q - 1)
            {
                rs = m;
            }
        }
    }
    
    int ret = rs - le + 1;
    ret = max(ret, 0);
    cout << ret << endl;
    
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
long long i,n,m=-1,N;
char s[110];
int main()
{
	scanf("%d%s",&n,&s);
	for (i=0;i<n;i++) s[i]==73?N++:N--,m=max(N,m);
	m<0?puts("0"):printf("%lld",m);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int cnt = 0;
		for(int i = 0; i < N; i++) {
			if(isPrime(scan.nextInt())) {
				cnt++;
			}
		}
		scan.close();
		System.out.println(cnt);
	}
	static boolean isPrime(int n) {
		if(n == 2) {
			return true;
		}
		if(n % 2 == 0) {
			return false;
		}
		for(int i = 3; i <= (int)Math.sqrt(n); i+= 2) {
			if(n % i == 0) {
				return false;
			}
		}
		return true;
	}
}


Measured memory_bytes: 41412
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

using namespace std;

typedef int long long;

const int q = 10000000000 + 7;

int main() {
	
	int a, b, c;
	cin >> a >> b >> c;
	int s = min(b + c, a);
	cout << (c - (s - b)) << endl;
	
	return 0;
}

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

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

    int len = 100;

    for(ll i = 1; i * i <= n; i++){
        ll a;
        if(n % i == 0){
            a = n / i;
            string s, t;
            s = to_string(i);
            t = to_string(a);
            int len_a, len_i;
            len_a = t.length();
            len_i = s.length();
            if(len_a >= len_i){
                if(len >= len_a){
                    len = len_a;
                }
            }else{
                if(len >= len_i){
                    len = len_i;
                }
            }
        }
    }

    cout << len << endl;
}

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

using namespace std;

#define ll long long 
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ff first
#define ss second
#define endl "\n"
#define MOD 1000000007
#define MOD1 998244353
#define inf 1e18

ll GCD(ll x,ll y){if(y==0)return x;return GCD(y,x%y);}
ll LCM(ll x,ll y){return (x*y)/(GCD(x,y));}
ll LOGK(ll x,ll k){if(x>=k)return 1+LOGK(x/k,k);return 0;}
ll MPOW( ll a, ll b, ll m) { if(b==0) return 1; ll x=MPOW(a,b/2,m); x=(x*x)%m; if(b%2==1) x=(x*a)%m; return x;}
ll MINV(ll a,ll m) {return MPOW(a,m-2,m);}

class pnc{
  ll FACT_MAX,MODU;
  vector<ll> fact;
public:
  pnc( ll n, ll m) { FACT_MAX = n; fact.resize(FACT_MAX); MODU = m; MFACT_INIT(MODU);}
  void MFACT_INIT( ll m) { fact[0]=1; for(ll i=1;i<FACT_MAX;++i) fact[i]=(i*fact[i-1])%MODU;}
  ll MFACT( ll n) { return fact[n];}
  ll PERM( ll n, ll r) { return (fact[n]*::MINV(fact[n-r],MODU))%MODU;}
  ll COMB( ll n , ll r) { return (PERM(n,r)*::MINV(fact[r],MODU))%MODU;}
};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);    

    ll test=1;
    // cin>>test;
    while(test--)
    {
        string a,b;
        cin>>a>>b;

        ll ans=0;

        for(ll i=0;i<a.length();i++)
        {
            if(a[i]!=b[i])
            ans++;
        }

        cout<<ans;
    }
}

Measured memory_bytes: 3884
import java.util.*;

public class Main{
    
    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());
        int k = Integer.parseInt(sc.next());
        long[] a = new long[n];
        for(int i=0; i<n; i++){
            a[i] = Long.parseLong(sc.next());
        }
        Arrays.sort(a);
        long ans = 1;
        if(a[n-1]<=0){
            if(k%2==1){
                for(int i=0; i<k-1; i+=2){
                    long tmp = a[n-1-i]*a[n-2-i]%MOD;
                    ans = ans*tmp%MOD;
                }
                ans = ans*a[n-k]%MOD;
            }else{
                for(int i=0; i<k; i+=2){
                    long tmp = a[i]*a[i+1]%MOD;
                    ans = ans*tmp%MOD;
                }
            }
        }else{
            int l = 0;
            int r = n-1;
            if(k%2==1){
                ans = ans*a[r]%MOD;
                r--;
            }
            while(k>1){
                long m = a[l]*a[l+1];
                long p = a[r]*a[r-1];
                if(m >= p){
                    ans = ans*(m%MOD)%MOD;
                    l+=2;
                }else{
                    ans = ans*(p%MOD)%MOD;
                    r-=2;
                }
                k-=2;
            }
        }
        System.out.println((ans+MOD)%MOD);
    }
}


Measured memory_bytes: 61700
n=int(input())
a=list(map(int,input().split()))
def partition(A,p,r):
	x=A[r]
	i=p-1
	for j in range(p,r):
		if A[j]<=x:
			i+=1
			A[i],A[j]=A[j],A[i]
	A[i+1],A[r]=A[r],A[i+1]
	return i+1
r=""
q=partition(a,0,n-1)
for i in range(n):
	if i:
		r+=(" ")
	if i==q:
		r+=("[")
	r+=str(a[i])
	if i==q:
		r+=("]")
print(r)


Measured memory_bytes: 16384
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
int main() {
	int n, m; cin >> n >> m;
	//从上往下找,在m的质因数里面只要找到一个大于m的就可以了
	if (n == 1)cout << m << endl;
	else {
		for (int i = m / 2 + 1; i > 0; i--) {
			if (m%i == 0)
			{
				if (m / i >= n) {
					cout << i << endl;
					break;
				}
			}
		}
	}
	return 0;
}


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

using namespace std;



int main(){
    int A,B,C,D,E,F;
    cin >> A >> B >> C >> D >> E >> F;

    vector<int> water;
    vector<int> sugar;

    for(int i = 0; i < (F/100); i++){
        for(int j = 0; j<(F/100); j++){
            water.push_back(100*A*i + 100*B*j);
        }
    }

    for(int i = 0; i < F/C; i++){
        for(int j = 0; j<F/D; j++){
            sugar.push_back(C*i + D*j);
        }
    }

    double result_con = 0.0;
    int result_sugar = 0;
    int result_weight = 0;

    for(unsigned int i=0; i<water.size(); i++){
        for(unsigned int j=0; j<sugar.size(); j++){
            //printf("water : %d, sugar : %d\n",water[i], sugar[j]);
            if(water[i]+sugar[j] > F){
                continue;
            }
            if(water[i]/100 * E < sugar[j]){
                continue;
            }
            double con = (double)sugar[j]/(double)(water[i]+sugar[j]);
            if(result_con <= con){
                result_con = con;
                result_sugar = sugar[j];
                result_weight = sugar[j] + water[i];
            }
        }
    }


    cout << result_weight << " " << result_sugar << endl;

    return 0;
}


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

int main() {
    ios_base::sync_with_stdio(false);	
    cin.tie(0);
	ll h, w;
	cin >> h >> w;
	if (h == 1 || w == 1) cout << "1" << "\n";
	else {
		ll ans = h * w;
		if (ans % 2 == 0) cout << ans / 2 << "\n";
		else cout << ans / 2 + 1 << "\n";
	}
	return 0;
}


Measured memory_bytes: 256
h,w=map(int,input().split())
l=[]
for i in range(h):
    d=list(map(str,input()))
    d=['.']+d+['.']
    l.append(d)
l=[['.']*(w+2)]+l+[['.']*(w+2)]
#print(l)
for i in range(1,h+1):
    for j in range(1,w+1):
        if l[i][j]=='#':
            continue
        else:
            ans=0
            ans+=l[i-1][j-1:j+2].count('#')
            ans+=l[i+1][j-1:j+2].count('#')
            if l[i][j-1]=='#':ans+=1
            if l[i][j+1]=='#':ans+=1
            l[i][j]=ans
for i in range(1,h+1):
    print("".join(map(str,l[i][1:-1])))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
/*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
int main() {
  int a,b;
  cin >> a >> b;
  double pi = 3.141592653589793238;
int n,m;
cin >> n >> m;
n%=12;
double time = n*60+m;
double naga = 0.5*time;
int mizi=6*time;
mizi%=360;
double ans = abs(naga-double(mizi));
if(ans>180.0)ans =360-ans;
double nizyo= pow(a,2)+pow(b,2)-2*a*b*cos(ans/180.0*pi);
  double res = pow(nizyo,0.5);
  cout<< fixed<<setprecision(20);
  cout<<res<<endl;
}


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

using namespace std;

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

    long long int cnt[5] = {0};
    for(int i = 0; i < N; i++) {
        string s;
        cin >> s;
        switch (s[0]) {
        case 'M':
            cnt[0]++;
            break;
        case 'A':
            cnt[1]++;
            break;
        case 'R':
            cnt[2]++;
            break;
        case 'C':
            cnt[3]++;
            break;
        case 'H':
            cnt[4]++;
            break;
        }
    }

    long long int ans = 0;
    for (int i = 0; i < 5; i++) {
        for(int j = i+1; j < 5; j++) {
            for(int k = j+1; k < 5; k++) {
                ans += cnt[i]*cnt[j]*cnt[k];
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    int n;
    cin >> n;
    if(n%2){
        cout << (n-1) / 2 << endl;
    }else{
        cout << n/2 - 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(n,a) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

int N,W;
int dp[110000]={};
int v[1000],w[1000];

int main(){
  cin>>N>>W;
  rep(i,N){
    cin>>v[i]>>w[i];
  }

  int ans = 0;

  rep(i,W+1){
    rep(j,N){
      if(i-w[j]<0)continue;
      dp[i] = max(dp[i],dp[i-w[j]]+v[j]);
      ans = max(ans,dp[i]);
    }
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 3148
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a: String = read();
    let b: String = read();
    let mut a = a.chars().collect::<Vec<char>>();
    let mut b = b.chars().collect::<Vec<char>>();
    a.sort();
    b.sort();
    b.reverse();
    println!("{}", if a < b { "Yes" } else { "No" });
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

// ------------------------------------------------------------------------------------------

const int INF = 1e18;

int N, A, B, C;
vec<int> l;

int calc2(vec<int> v, int val) {
  int ret = INF;
  int n = v.size();

  for (int mask = 0; mask < (1LL << n); mask++) {
    int cnt = 0;
    int sum = 0;
    for (int i = 0; i < n; i++) {
      if (mask & (1LL << i)) {
        sum += v[i];
        cnt++;
      }
    }
    if (cnt == 0) continue;
    chmin(ret, (cnt-1)*10 + abs(sum - val));
  }

  return ret;
}

int calc(vec<int> a, vec<int> b, vec<int> c) {
  return calc2(a, A) + calc2(b, B) + calc2(c, C);
}

int rec(int idx, vec<int> a, vec<int> b, vec<int> c) {
  if (idx >= N) {
    if (a.size() == 0 || b.size() == 0 || c.size() == 0) return INF;
    return calc(a, b, c);
  }

  int ret = INF;

  a.push_back(l[idx]);
  chmin(ret, rec(idx+1, a, b, c));
  a.pop_back();

  b.push_back(l[idx]);
  chmin(ret, rec(idx+1, a, b, c));
  b.pop_back();

  c.push_back(l[idx]);
  chmin(ret, rec(idx+1, a, b, c));
  c.pop_back();

  return ret;
}

signed main() {
  cin >> N >> A >> B >> C;
  l.resize(N);
  rep (i, N) {
    cin >> l[i];
  }

  vec<int> a;
  vec<int> b;
  vec<int> c;
  int ans = rec(0, a, b, c);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
// ConsoleApplication1.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
using namespace std;
#define rep(i, n) for(long i = 0; i < n; i++)
#define erep(i, n) for(long i = 1; i <= n; i++)
#define show(ans) cout << ans << endl
const long MOD = 1000000007;



int main() {
	long long N;
	vector<long long> n(5);
	cin >> N;
	rep(i, 5) cin >> n[i];
	sort(n.begin(), n.end());
	if (N % n[0] == 0) {
		show(N / n[0] + 4);
		}
	else {
		show(N / n[0] + 5);
	}


	return 0;

}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const LL N = 1000000007;

LL ec = 0,nxt[200005],to[200005],hed[100005] = {0};
void add_edge(LL f,LL t){
	++ ec; nxt[ec] = hed[f]; to[ec] = t; hed[f] = ec;
}

LL n,a,b;
LL dp[100005][2] = {0};

void dfs(LL u,LL f){
	dp[u][0] = 1;
	dp[u][1] = 1;
	for(LL i = hed[u];i;i = nxt[i]){
		LL v = to[i];
		if(v == f) continue;
		dfs(v,u);
		dp[u][0] *= (dp[v][0] + dp[v][1]); dp[u][0] %= N;
		dp[u][1] *= dp[v][0]; dp[u][1] %= N;
	}
}

int main(){
	scanf("%lld",&n);
	for(LL i = 1;i < n;i ++){
		scanf("%lld %lld",&a,&b);
		add_edge(a,b);
		add_edge(b,a);
	}
	dfs(1,0);
	printf("%lld\n",(dp[1][0] + dp[1][1]) % N);
	return 0;
}
//

Measured memory_bytes: 11264
#include<iostream>
#include<string>
#include<math.h>

using namespace std;

int main(){
    
    int x,y;
    cin>>x>>y;
    
    int ans=-1;
    int a,b;
    for(int i=0;i<=x;i++){
        a=i; b=x-i;
        if(2*a+4*b==y){
            ans=1;
            break;
        }
    }
    if(ans==1){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }
    return 0;
}

Measured memory_bytes: 3624
import { readFileSync } from "fs";

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { cin, nCin, biCin } = (() => {
  const inputs = readFileSync("/dev/stdin", "utf-8").split(/[\n|\s]+/);
  let count = 0;
  const cin = () => inputs[count++];
  return { cin: cin, nCin: () => Number(cin()), biCin: () => BigInt(cin()) };
})();

const range = (n: number | bigint) => [...Array(Number(n))].map((_, i) => i);

type Color = "Black" | "White";
type Grid = Color[][] & {
  height: number;
  width: number;
};
type PickData = {
  index: number;
  isPicked: boolean;
};

const getBlackCnt = (hPicks: PickData[], wPicks: PickData[], grid: Grid) =>
  hPicks
    .filter(({ isPicked }) => isPicked)
    .map(({ index }) => {
      const cs = grid[index];
      return wPicks
        .filter(({ isPicked }) => isPicked)
        .map(({ index }) => (cs[index] === "Black" ? 1 : 0) as number)
        .reduce((acc, x) => acc + x, 0);
    })
    .reduce((acc, x) => acc + x, 0);

const wPickFn = (K: number, grid: Grid, hPicks: PickData[]) => {
  const initialBlackCnt = getBlackCnt(
    range(grid.height).map((i) => ({ index: i, isPicked: true })),
    range(grid.width).map((j) => ({ index: j, isPicked: true })),
    grid
  );
  const wPickFn = (n: number, wPicks: PickData[]): number =>
    n >= grid.width
      ? (() => {
          const hCnt = getBlackCnt(
            range(grid.height).map((i) => ({ index: i, isPicked: true })),
            wPicks,
            grid
          );
          const wCnt = getBlackCnt(
            hPicks,
            range(grid.width).map((j) => ({ index: j, isPicked: true })),
            grid
          );
          const hwCnt = getBlackCnt(hPicks, wPicks, grid);
          return initialBlackCnt - (hCnt + wCnt - hwCnt);
        })() === K
        ? 1
        : 0
      : wPickFn(n + 1, wPicks) +
        wPickFn(
          n + 1,
          wPicks.map(({ index, isPicked }) =>
            index === n ? { index: index, isPicked: true } : { index: index, isPicked: isPicked }
          )
        );
  return wPickFn(
    0,
    range(grid.width).map((j) => ({ index: j, isPicked: false }))
  );
};

const hPickFn = (grid: Grid, K: number) => {
  const hPickFn = (n: number, hPicks: PickData[]): number =>
    n >= grid.height
      ? wPickFn(K, grid, hPicks)
      : hPickFn(n + 1, hPicks) +
        hPickFn(
          n + 1,
          hPicks.map(({ index, isPicked }) =>
            index === n ? { index: index, isPicked: true } : { index: index, isPicked: isPicked }
          )
        );
  return hPickFn(
    0,
    range(grid.height).map((i) => ({ index: i, isPicked: false }))
  );
};

const getCnt = (K: number, grid: Grid) => hPickFn(grid, K);

{
  const [H, W, K] = [nCin(), nCin(), nCin()];
  const grid: Grid = (() => {
    const grid: Color[][] = range(H).map(() =>
      cin()
        .split("")
        .map((c) => (c === "#" ? "Black" : "White") as Color)
    );
    return { ...grid, height: H, width: W };
  })();
  const cnt = getCnt(K, grid);
  console.log(cnt);
}


Measured memory_bytes: 41584
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>

using namespace std;

using ll = long long int;

int result[100010] = {};

int main(void) {

	int n;
	cin >> n;

	for (int i = 0; i < n; i ++) {
		cin >> result[i];
	}

	int answer = 0;

	for (int i = 0; i < 100010; i++) {
		if (result[i] == i+1) {
			answer++;
			i++;
		}
	}

	cout << answer << endl;

	return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int n = (int) s.size();
  vector<int> a(n + 1);
  for (int i = 0; i < n; i++) {
    if (s[i] == '<') {
      a[i + 1] = max(a[i + 1], a[i] + 1);
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == '>') {
      a[i] = max(a[i], a[i + 1] + 1);
    }
  }
  long long ans = 0;
  for (int i = 0; i <= n; i++) {
    ans += a[i];
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 2844
#include<iostream>
#include<cmath>
using namespace std;
bool prime(int a) {
	for (int i = 2;i <= sqrt(a);i++) {
		if (a%i == 0)return false;
	}
	return true;
}
int f(int a, int b) {
	int Ans = 0;
	while (a) {
		Ans += a / b;
		a /= b;
	}
	return Ans;
}
int main() {
	int n;
	cin >> n;
	int x = 0;
	int y = 0;
	int ans = 0;
	for (int i = 2;i <= n;i++) {
		if (prime(i)) {
			if (f(n, i) >= 74)x++;
		}
	}
	ans += x;
	x = 0;
	for (int i = 2;i <= n;i++) {
		if (prime(i)){
			if (f(n, i) >= 4)x++;
			if (f(n, i) >= 14)y++;
		}
	}
	ans += y * (x - 1);
	x = 0, y = 0;
	for (int i = 2;i <= n;i++) {
		if (prime(i)) {
			if (f(n, i) >= 2)x++;
			if (f(n, i) >= 24)y++;
		}
	}
	ans += y * (x - 1);
	x = 0, y = 0;
	for (int i = 2;i <= n;i++) {
		if (prime(i)) {
			if (f(n, i) >= 4)x++;
			if (f(n, i) >= 2)y++;
		}
	}
	ans += x * (x - 1)*(y - 2)/2;
	cout << ans << endl;
	return 0;
}

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

def num2alpha(N):
    if N <= 26:
        return chr(64+N)
    elif N%26 == 0:
        return num2alpha(N//26-1) + chr(90)
    else:
        return num2alpha(N//26) + chr(64+N%26)
print(str.lower(num2alpha(N)))

Measured memory_bytes: 61676
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int &i : a) cin >> i;
  long long ans = 0, sum = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
    sum %= mod;
  }
  for (int i = 0; i < n; i++) {
    sum += mod;
    sum -= a[i];
    sum %= mod;
    ans += (a[i] * sum) % mod;
  }
  cout << ans % mod << endl;
  return 0;
}

Measured memory_bytes: 4056
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007LL;
const int INF = LLONG_MAX;

signed main(){
    
    vector<int> a(3);
    for(int i = 0; i < 3; i++) cin >> a[i];
    sort(a.begin(), a.end());
    int k; cin >> k;
    for(int i = 0; i < k; i++){
        a[2] = a[2] * 2;
    }

    cout << a[0] + a[1] + a[2] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;



int main()
{
int m,d;
cin >> m >>d;
  
  int ans;
for(int i=2;i<=m;i++){
	for(int j=20;j<=d;j++){
      int	dsq=(j/10)*(j%10);
  //   cout << dsq<<endl;
      if(i == dsq&&(j/10)>=2&&(j%10)>=2){
      ans++;
      }
    }
}
  cout <<ans <<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String args[]){
      Scanner scan = new Scanner(System.in);
      int X = scan.nextInt();
      int Y = scan.nextInt();
      String ans = "No";
      for(int i = 0;i < 101;i++){
          for(int j = 0;j < 101;j++){
              if(i + j == X)
                if(i * 2 + j * 4 == Y){
                    ans = "Yes";
                    break;
                }
          }
        }
      System.out.println(ans);
    }
}

Measured memory_bytes: 35692
#include<stdio.h>
#define MOD 998244353
long int SUM(long int a,long int b){return (a%MOD+b%MOD+MOD)%MOD;}
long int PROD(long int a,long int b){return a%MOD*(b%MOD)%MOD;}//a*b
int main(){
  long int dp[3001][3001];
  int n,s,a,i,j;
  scanf("%d%d",&n,&s);
  for(i=0;i<3001;i++)dp[i][0]=0;dp[0][0]=1;
  for(i=1;i<=n;i++){
    scanf("%d",&a);
    for(j=0;j<3001;j++){dp[i][j]=PROD(dp[i-1][j],2);if(j-a>=0)dp[i][j]=SUM(dp[i][j],dp[i-1][j-a]);}
  }
  printf("%ld",dp[n][s]);
}


Measured memory_bytes: 72064