akhauriyash/Code-Regression huggingface dataset:
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_VAL_MAX		1000									// 最大値

// 内部構造体 - 値情報
typedef struct Val {
	int miVal;													// 値
	long long mlVal5;											// 値の５乗
} Val;

// 内部変数
static FILE *szpFpI;											// 入力
static Val sz1Val[D_VAL_MAX];									// 値
static int siVCnt;												// 値数
static long long slX;											// X

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// A, B - 取得
int
fGetAB(
	int *pipA					// <O> A
	, int *pipB					// <O> B
)
{
	int i;

	// 値でループ
	for (int liVal = 0; ; liVal++) {
		long long llVal5 = (long long)liVal * (long long)liVal * (long long)liVal * (long long)liVal * (long long)liVal;

		// 値 - 追加
		sz1Val[siVCnt].miVal = liVal;
		sz1Val[siVCnt].mlVal5 = llVal5;
		siVCnt++;

		// 値 - 検索
		for (i = 0; i < siVCnt; i++) {

			// 加算
			if (llVal5 + sz1Val[i].mlVal5 == slX) {
				*pipA = liVal;
				*pipB = -sz1Val[i].miVal;
				return 0;
			}

			// 減算
			if (llVal5 - sz1Val[i].mlVal5 == slX) {
				*pipA = liVal;
				*pipB = sz1Val[i].miVal;
				return 0;
			}
		}
	}

	return 0;
}

// 実行メイン
int
fMain(
)
{
	char lc1Buf[1024];

	// データ - 初期化
	siVCnt = 0;

	// X - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%lld", &slX);

	// A, B - 取得
	int liA, liB;
	fGetAB(&liA, &liB);

	// 出力
	sprintf(lc1Buf, "%d %d\n", liA, liB);
	fOutLine(lc1Buf);

	return 0;
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



Measured memory_bytes: 1780
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

class Program
{
    static void Main()
    {
        string s = Console.ReadLine();

        Console.WriteLine(s.Count(c => c == '+') - s.Count(c => c == '-'));
    }
}



static class MathUtil
{
    public static IEnumerable<IEnumerable<int>> GetPermutation(int n)
    {
        if (n == 0)
        {
            yield return Single(0);
            yield break;
        }

        for (int i = 0; i <= n; i++)
        {
            foreach (var x in GetPermutation(n - 1))
            {
                yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1));
            }
        }
    }

    private static IEnumerable<int> Single(int x)
    {
        yield return x;
    }

    public static IEnumerable<int> EnumeratePrimeNumbers()
    {
        List<int> primes = new List<int>() { 2 };
        yield return 2;

        for (int i = 3; i < int.MaxValue; i++)
        {
            bool isPrime = true;
            int Sqrt = (int)Math.Sqrt(i) + 1;

            foreach (var prime in primes)
            {
                if (prime > Sqrt)
                {
                    break;
                }
                if (i % prime == 0)
                {
                    isPrime = false;
                    break;
                }
            }

            if (isPrime)
            {
                primes.Add(i);
                yield return i;
            }
        }
    }
}



Measured memory_bytes: 11220
#include <cstdio>

int x, a, b;

int abs(int y)
{
    if (y > 0) return y;
    else return -y;
}

void solve()
{
    if (abs(x-a) < abs(x-b)) printf("A\n");
    else printf("B\n");
}

int main()
{
    scanf("%d%d%d", &x, &a, &b);
    solve();
    return 0;
}

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

int main(){
  int R,G,B,N;
  cin >> R >> G >> B >> N;
  int sum = 0;
  int count = 0;
  for(int i = 0; i <= 3000; i++){
    for(int j = 0; j <= 3000; j++){
      sum = i*R + j*G;
      if(sum == N){
          count++;
      }
       else if(sum < N){
          if((N - sum)%B == 0){
              count++;
          }
      }
      
            
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
double dp[101][101]={0},g[101][101],r;
int n,m,i,j,k;

int main()
{
	for(;scanf("%d%d",&n,&m),n;)
	{
		memset(dp,0,sizeof(dp));
		for(i=0;i<n*n;i++)
			scanf("%lf",&g[i/n][i%n]);
		for(i=0;i<n;i++)
			dp[0][i]=1.0;
		for(i=0;i<m;i++)
			for(j=0;j<n;j++)
				for(k=0;k<n;k++)
					dp[i+1][k]=dp[i+1][k]>dp[i][j]*g[j][k]?dp[i+1][k]:dp[i][j]*g[j][k];
		for(i=r=0;i<n;i++)
			r=r>dp[m-1][i]?r:dp[m-1][i];
		printf("%.2f\n",r);
	}
	return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)

struct edge{ int to, cost; };

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

    // グラフの構築の問題では X -> X+1 と X -> 2X の作り方を具体的に導くのが大事
    // 2^r <= L なる最大の r を求める
    int tmp = L, r = 0;
    while(tmp > 1){ 
        tmp /= 2;
        ++r;
    }

    int N = r+1, M = 0;
    vector<vector<edge>> G(N);
    // i -> i+1 に 0 と 2^i の辺を張ることで
    // 0 ~ 2^r-1 までの経路を作れる
    REP(i, N-1){
        G[i].push_back({i+1, 0});
        G[i].push_back({i+1, (int) pow(2, i)});
        M += 2;
    }

    // 残りの辺を張る
    for(int i = N-2; i >= 0; --i){
        int length = L - pow(2, i);
        if( length >= pow(2, r)){
            G[i].push_back({N-1, length});
            L -= pow(2, i);
            ++M;
        }
    }

    cout << N << " " << M << endl;
    REP(i, N){
        for(auto e: G[i]) cout << i+1 << " " << e.to+1 << " " << e.cost << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define PP pair<P,P>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	random_device rnd;
	mt19937_64 mt64(rnd());
	uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt64);
}
/*--------Library Zone!--------*/

int n, k;
int a[2005];
int cnt1[2005], cnt2[2005];
signed main() {
	cin >> n >> k;
	set<int>st1, st2;
	rep(i, n) {
		cin >> a[i];
		rep(j, i) {
			if (a[j] > a[i])cnt1[i]++;
		}
	}
	rep(i, n) {
		rep(j, n) {
			if (a[j] > a[i])cnt2[i]++;
		}
	}
	int kk = k - 1;
	int m = (1 + kk) * kk / 2 % mod;
	int ans = 0;
	rep(i, n) {
		int memo = cnt1[i] * k + cnt2[i] * m;
		ans += memo; ans %= mod;
	}
	cout << ans << endl;
}

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();

        int leng = s.length();
        String X = "x";

        for(int i=1; i<leng; i++){
            X = X + "x";
        }

        System.out.println(X);
    }
}

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

const ll MOD = pow(10,9) + 7;

// dp[i][0] : i文字目がA
// dp[i][1] : i文字目がG
// dp[i][2] : i文字目がC
// dp[i][3] : i文字目がT
ll dp[105][4][4][4];

// NG文字列
// AGC, GAC, ACG, A*GC. AG*C
int main() {
  int N;
  cin >> N;
  int A = 0;
  int G = 1;
  int C = 2;
  int T = 3;

  REP(j,4) REP(k,4) REP(l,4) {
    if ( j == A && k == G && l == C ) continue;
    if ( j == A && k == C && l == G ) continue;
    if ( j == G && k == A && l == C ) continue;
    dp[2][j][k][l] = 1;
  }
  
  for(int i=2;i<N-1;i++) {
    REP(j,4) REP(k,4) REP(l,4) REP(m,4) {
      if ( j == A && k == G && m == C ) continue;
      if ( j == A && l == G && m == C ) continue;
      if ( k == G && l == A && m == C ) continue;
      if ( k == A && l == G && m == C ) continue;
      if ( k == A && l == C && m == G ) continue;
      dp[i+1][k][l][m] = (dp[i+1][k][l][m] + dp[i][j][k][l]) % MOD;
    }
  }
  
  ll ans = 0;
  REP(j,4) REP(k,4) REP(l,4) {
    ans = (ans + dp[N-1][j][k][l]) % MOD;
  }
  cout << ans << endl;
}



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

int N,K;
int main () {
    cin >> N >> K;
    double ans = 0;
    for(int i=1; i<=N; i++) {
        double p = (double)1/N;
        for(int j=i; j<K; j*=2) p*=0.5;
        ans += p;
    }
    printf("%.12f\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>

int compare(const void *pa,const void *pb){
	const int *a = (const int*)pa;
	const int *b = (const int*)pb;
	return (*a) - (*b);
}

int main(void)
{
	int n,N;
	scanf("%d\n",&N);
	int s[N];
	for (n=0;n<N;n++){
		scanf("%d\n",&s[n]);
	}
	qsort(s,N,sizeof(int),compare);
	int sum=0;
	for (n=0;n<N;n++){
		//printf("%d\n",s[n]);
		sum+=s[n];
	}
	if ((sum%10)==0){
		for (n=0;n<N;n++){
			if ((s[n]%10) != 0){
				//printf("%d %d\n",n,s[n]);
				sum-=s[n];
				break;
			}
		}
	}
	if ((sum%10)==0){
		printf("0\n");
	}
	else{
		printf("%d\n",sum);
	}
	return 0;
}


Measured memory_bytes: 128
import string

n = int(input())
s = []
for _ in range(n):
    s.append(input())

az = string.ascii_lowercase
counts = {}
 
for v in az:

    counts[v] = float("inf")
    for i in range(n):
        counts[v] = min(counts[v], s[i].count(v))
 

ans = ""
for k, v in sorted(counts.items()):
    ans += k*v
print(ans)

Measured memory_bytes: 39024
let rec fix f x = f (fix f) x;;
Scanf.(Array.(scanf " %d" @@ fun n ->
  let a = make 2000000 false in
  let col n = if n mod 2 = 0 then n/2 else 3*n+1 in
  print_int @@ fix (fun f i x ->
    if a.(x) then i
    else (
      a.(x) <- true;
      f (i+1) (col x)
    )
  ) 1 n))

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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const long long INF = 2e18;
const long long MOD = 1e9+7;

#define sx(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i < n; i++)
#define ALL(a) begin(a),end(a)

int main(void) {
    int N;
    cin >> N;
    vector<int> a(N);
    REP(i, N) cin >> a[i];
    sort(ALL(a));
    cout << a[N-1] - a[0] << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using static MyIO;


public class B
{
	public static void Main()	
	{
		double A = GetDouble();
		double B = GetDouble();
		Console.WriteLine((A > B) ? "GREATER" : (A < B) ? "LESS" : "EQUAL");
	}

	private static long gcd(long x, long y)
	{
		return (y == 0) ? x : gcd(y, x % y);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
using namespace std;
vector<int> to[9];
int main(){
    int n,m;
    cin >> n >> m;
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    vector<int> v;
    rep(j,n-1){
        v.push_back(j+1);
    }
    int cnt = 0;
    do{
        int a = 0;
        bool flag = true;
        rep(i,n-1){
            int b=v[i];
            for(auto& p: to[a]){
                if(p == b){
                    flag = true;
                    a = b;
                }else{
                    flag = false;
                }
                if(flag) break;       
            }
            if(!flag) break;
        }
        if(flag){
            cnt++;
        }
    }while(next_permutation(v.begin(),v.end()));
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;

int DFS(int Node, vector< vector<int> >& adj, vector<int>& depth) {
	int& ret = depth[Node];
	if(ret)
		return ret;
	for(int i = 0; i < adj[Node].size(); ++i)
		ret = max(ret, 1 + DFS(adj[Node][i], adj, depth));
	return ret;
}
int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	vector< vector<int> > adj(n + 1);
	while(m--) {
		int f, t;
		scanf("%d %d", &f, &t);
		adj[f].push_back(t);
	}
	vector<int> mem(n + 1, 0);
	for(int i = 1; i <= n; ++i)
		DFS(i, adj, mem);
	int ans = -1;
	for(int& x : mem)
		ans = max(ans, x);
	printf("%d", ans);
}


Measured memory_bytes: 8192
n = int(input())
a = list(map(int, input().split()))
ok = True
a[0] -= 1
for i in range(1, n):
    if a[i - 1] < a[i]:
        a[i] -= 1
    if a[i - 1] > a[i]:
        ok = False

print("Yes" if ok else "No")


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

const int maxn = 3030;

int n;
int a[maxn];
std::vector<int> g[maxn];

int dfs(int u, int p = 0) {
	bool leaf = 1;
	for (int v: g[u]) {
		if(v == p) {
			continue;
		}
		leaf = 0;
		if(a[v] >= a[u]) {
			continue;
		}
		int x = dfs(v, u);
		if(x - 1) {
			return 1;
		}
	}
	return leaf ? -1 : 0;
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", a + i);
	}
	for (int i = 1; i < n; ++i) {
		int u, v;
		scanf("%d%d", &u, &v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	for (int i = 1; i <= n; ++i) {
		if(dfs(i)) {
			printf("%d ", i);
		}
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define ft first
#define sd second
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin, (x).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<long long,long long> pll;

int main(){
    ll n,temp,ctr=26;
    int legn=0;
    string rta="";
    cin >> n;
    temp=n;
    n--;
    while(temp>0){
        legn++;
        temp-=ctr;
        ctr*=26;
    }
    temp=26;
    for(int i=1;i<legn;i++){
        n-=temp;
        temp*=26;
    }
    ctr/=676;
    for(int i=0;i<legn;i++){
        if(i!=legn-1) rta+= 'a'+ (n/ctr);
        else{
            rta+='a'+(n%26);
        }
        n%=ctr;  
        ctr/=26;
    }
    cout << rta << endl;
  }



Measured memory_bytes: 3588
fn main() {
    let s = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    };

    let s = s.chars().collect::<Vec<char>>();
    if s.get(2) == s.get(3) && s.get(4) == s.get(5) {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int lcs(string X, string Y){
    int n = X.size(), m = Y.size();
    int lcsv[n+1][m+1];
    rep(i,n+1) lcsv[i][0] = 0;
    rep(j,m+1) lcsv[0][j] = 0;
    rep(i,n){
        rep(j,m){
            if(X[i] == Y[j]){
                lcsv[i+1][j+1] = lcsv[i][j]+1;
            }else{
                lcsv[i+1][j+1] = max(lcsv[i+1][j], lcsv[i][j+1]);
            }
        }
    }
    return lcsv[n][m];
}

int main()
{
    int n; cin >> n;
    rep(_,n){
        string X, Y; cin >> X >> Y;
        cout << lcs(X, Y) << endl;
    }
}


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

using namespace std;

#define ll long long
#define md 1000000007
#define loop(i,a,b) for(int i=a; i<b; i++)
#define lloop(i,a,b) for (long long i=a; i<b; i++)
#define loopr(i,a,b) for(int i = a; i>=b; i--)
#define iterate(it, v) for (auto it = v.begin(); it!= v.end(); it++)
#define mk make_pair
#define pb push_back

template <typename T>
void printArray(T *arr, int n){
    loop(i,0,n){
        cout << arr[i] << " ";
    } cout << endl;
}

template <typename T>
void printMatrix(T **arr, int m, int n){
    loop(i,0,m){
        loop(j,0,n) cout << arr[i][j] << " ";
    } cout << endl;
}

ll int getMinCost(int *arr, int n) {
	ll dp[n];
    dp[0] = 0;
    dp[1] = abs(arr[1]-arr[0]);

    loop(i,2,n) {
        dp[i] = min((ll)dp[i-1] + (ll)abs(arr[i] - arr[i-1]), (ll)dp[i-2] + (ll)abs(arr[i] - arr[i-2]));
    }

    return dp[n-1];
}

int main(){
    
	int n;
  	cin >> n;
  	int arr[n];
  	loop(i,0,n) cin >> arr[i];
  
  	cout << getMinCost(arr, n) << endl;
    
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    auto cmp = [](tuple<int, int, int> a, tuple<int, int, int> b){
        return get<0>(a) > get<0>(b);
    };
    priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, decltype(cmp)> pq(cmp);
    pq.emplace(-a[1], a[1], a[0]);
    pq.emplace(-a[1], a[1], a[0]);
    ll ans = a[0];
    for(int i = 2; i < n; i++){
        auto t = pq.top();
        //cout << get<0>(t) << " " << get<1>(t) << " " << get<2>(t) << endl;
        pq.pop();
        ans += -get<0>(t);
        pq.emplace(-min(get<1>(t), a[i]), get<1>(t), a[i]);
        pq.emplace(-min(get<2>(t), a[i]), get<2>(t), a[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7152
#include <bits/stdc++.h>
using namespace std;
#define INF 2e9
#define ll long long

int main(){
    ll n, k;
    cin>>n>>k;
    ll a[n];
    ll ans = 0;
    ll mod_num = 1000000007;
    for(int i=0; i<n; i++){
        cin>>a[i];
    }

    ll reverse_num = 0;
    ll small_num = 0;

    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(a[i]>a[j]){
                small_num++;
            }
            if(j > i && a[i]>a[j]){
                reverse_num++;
            }
        }
    }

    ans += (reverse_num * k)%mod_num;
    k = (k*(k-1)/2)%mod_num;
    ans += (small_num * k )% mod_num;
    ans = ans%mod_num;    

    //cout<<reverse_num<<endl;
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n,m;cin>>n>>m;
  ll x;cin>>x;
  vector<ll>c(n);
  auto a=vec(n,m,0LL);
  rep(i,0,n){
    cin>>c[i];
    rep(j,0,m)cin>>a[i][j];
  }
  res=INF;
  rep(i,0,1<<n){
    vector<ll>p(m);
    ll sum=0;
    rep(j,0,n){
      if(i&1<<j){
        rep(o,0,m)p[o]+=a[j][o];
        sum+=c[j];
      }
    }
    //debug(p,m);
    bool sw=true;
    rep(j,0,m)if(p[j]<x)sw=false;
    if(sw)chmin(res,sum);
  }
  ans(res==INF,-1,res);
  return 0;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    //freopen("out.txt","w",stdout);
    int T;
    scanf("%d",&T);
    while(T--)
    {
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        if(a<b) {puts("No");continue;}
        else if(d<b) {puts("No");continue;}
        else if(a%b>c) {puts("No");continue;}
        else
        {
            ll gcd=__gcd(b,d);
            //c-a //c-b
            ll tim=(a-c+gcd-1)/gcd;
            ll lhs=tim*gcd+c-a;
            ll rhs=tim*gcd+b-a;
            //cout<<lhs<<" "<<rhs<<"\n";
            ll lx=lhs/gcd+1;
            lx*=gcd;
            if(lx<rhs) puts("No");
            else puts("Yes");
        }
    }
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
dd = defaultdict(int)

N=int(input())
for i in range(N):
    s=input()
    dd[s]+=1
    
M=int(input())
for _ in range(M):
    t=input()
    dd[t]-=1
    
ans=0
for k,v in dd.items():
    ans=max(ans,v)
    
print(ans)
    

Measured memory_bytes: 38384
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct tagNode{
  int x;
  struct tagNode* prev;
  struct tagNode* next;
}node;
node* head;
node* tail;
node* makenode(int x){
  node* new_node;
  new_node=(node*)malloc(sizeof(node));
  new_node->x=x;
  new_node->prev=NULL;
  new_node->next=NULL;
  return new_node;
}
void insert(int x){
  node* add;
  add=makenode(x);
  add->next=head->next;
  add->prev=head;
  head->next->prev=add;
  head->next=add;
}
void delnode(node* del){
  del->prev->next=del->next;
  del->next->prev=del->prev;
  free(del);
}
void search(int x){
  node* list;
  for(list=head->next;list!=head;list=list->next){
    if(list->x==x){
      delnode(list);
      break;
    }
  }
}
void deleteFirst(){
  delnode(head->next);
}
void deleteLast(){
  delnode(tail->prev);
}
void Display(){
  node* list;
  int flag=0;
  for(list=head->next;list!=tail;list=list->next){
    if(flag!=0) printf(" ");
    printf("%d",list->x);
    flag=1;
  }
  printf("\n");
}
int main(){
  int i,n,data;
  char str[256];
  head=makenode(-1);
  tail=makenode(-1);
  head->next=head->prev=tail;
  tail->prev=tail->next=head;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",str);
    if(strcmp(str,"insert")==0){
      scanf("%d",&data);
      insert(data);
    }
    else if(strcmp(str,"delete")==0){
      scanf("%d",&data);
      search(data);
    }
    else if(strcmp(str,"deleteFirst")==0){
      deleteFirst();
    }
    else if(strcmp(str,"deleteLast")==0){
      deleteLast();
    }
  }
  Display();
  return 0;
}

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

int main() {
int N;
  cin >> N;
vector<int> data(N);
  for(int i=0;i<N;i++){
  cin >> data.at(i);
  }
sort(data.begin(), data.end());
  cout << data.at(N-1)-data.at(0);
}

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

int main() {
    int x;
    cin >> x;
    
    bool dp[100000] = {false};
    dp[0] = true;
    for(int p = 100; p <= 105; p++) {
        for(int i = 0; i + p <= 100000; i++) {
            dp[i + p] |= dp[i];
        }
    }

    if(dp[x]) cout << 1 << endl;
    else      cout << 0 << endl;

    return 0;
}

Measured memory_bytes: 384
n,m,v,p=map(int,input().split())
a=sorted(list(map(int,input().split())), reverse=True)
ps=0;ans=p
for i in range(p,n):
  ps+=a[i-1]
  if a[i]+m<a[p-1]: break
  hv = min(p-1+n-i, v)
  if (a[i]+m)*(i-p+1)<ps+m*(v-hv): break
  ans+=1
print(ans)

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

int n;
vector<int> to[100005];

vector<int> dist;
void dfs(int a, int d = 0, int p = -1) {
	dist[a] = d;
	for (auto& c : to[a]) {
		if (c == p) continue;
		dfs(c, d + 1, a);
	}
}

vector<int> makedist(int a) {
	dist = vector<int>(n);
	dfs(a);
	return dist;
}

int main() {
	cin >> n;
	int u, v;
	cin >> u >> v;
	u--; v--;
	rep(i, n - 1) {
		int a, b; cin >> a >> b;
		a--; b--;
		to[a].emplace_back(b);
		to[b].emplace_back(a);
	}

	vector<int> distT = makedist(u);
	vector<int> distA = makedist(v);

	int ans = 0;
	rep(i, n) {
		if (distT[i] < distA[i]) ans = max(ans, distA[i]);
	}

	cout << ans - 1 << endl;

	return 0;
}


Measured memory_bytes: 10744
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/

lint lcm(lint a, lint b) {
	//aとbの最小公倍数を返す
	if (a < b) return lcm(b, a);
	lint A = a;
	lint B = b;
	lint r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return (A/b) * B;
}

int main() {
	lint N;
	cin >> N;
	vector<lint>T(N);
	rep(i, N) {
		cin >> T[i];
	}
	lint ans = T[0];
	rep(i, N) {
		ans = lcm(ans, T[i]);
	}
	cout << ans << endl;
}




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

const int maxn = 50010;
const ll mod = 998244353;

ll fac[maxn], inv[maxn];
int m,e;
ll res[maxn], t[maxn];

ll qpow(ll a, ll b)
{
	ll t = a, ret = 1LL;
	while (b)
	{
		if (b&1) ret = ret * t % mod;
		t = t * t % mod;
		b >>= 1;
	}
	return ret;
}

bool hasInit = false;

int findroot(int p)
{
	for (int i=2;i<=p;i++)
	{
		int x = p-1;
		bool flg = false;
		for (int j=2;j*j<=x;j++)
		{
			if (x % j != 0) continue;
			if (qpow(i,(p-1)/j) == 1)
			{
				flg = true;
				break;
			}
			while (x % j == 0) x /= j;
		}
		if (x != 1)
		{
			if (qpow(i,(p-1)/x) == 1) flg = true;
		}
		if (!flg) return i;
	}
}

struct NumericTheoreticTransform
{
	ll omega[maxn], omegainverse[maxn];
	int rev[maxn];

	void init(const int n)
	{
		if (hasInit) return;
		hasInit = true;
		int d = 0;
		while ((1<<d) < n) d++;
		for (int i=0;i<n;i++)
		{
			int t = 0;
			for (int j=0;j<d;j++) if (i & (1<<j)) t |= (1<<(d-1-j));
			rev[i] = t;
		}

		ll g = findroot(mod);
		ll x = qpow(g,(mod-1)/n);
		for (int i=0;i<n;i++)
		{
			omega[i] = (i !=0 ? omega[i-1]*x%mod : 1LL);
			omegainverse[i] = qpow(omega[i],mod-2);
		}
	}

	void transform(ll *a, const int n, const ll *omega)
	{
		for (int i=0;i<n;i++)
		{
			if (rev[i] > i) swap(a[i],a[rev[i]]);
		}
		for (int l=2;l<=n;l<<=1)
		{
			int m = (l >> 1);
			for (ll *p = a; p<a+n;p+=l)
			{
				for (int i=0;i<m;i++)
				{
					ll t = omega[n/l*i] * p[i+m] % mod;
					p[i+m] = (p[i] - t + mod) % mod;
					p[i] = (p[i] + t) % mod;
				}
			}
		}
	}

	void dft(ll *a, const int n)
	{
		transform(a,n,omega);
	}

	void idft(ll *a, const int n)
	{
		transform(a,n,omegainverse);
		ll x = qpow(n,mod-2);
		for (int i=0;i<n;i++) a[i] = a[i] * x % mod;
	}
}ntt;

void multiply(ll *a1, const ll *a3, const int n1)
{
	ll a2[maxn];
	bool same = (a1 == a3);
	int n = 1;
	while (n < n1 + n1) n <<= 1;
	ntt.init(n);
	if (!same) for (int i=0;i<n;i++) a2[i] = a3[i];

	ntt.dft(a1,n); if (!same) ntt.dft(a2,n);
	for (int i=0;i<n;i++) a1[i] = a1[i] * (same ? a1[i] : a2[i]) % mod;
	ntt.idft(a1,n);
	for (int i=m+1;i<n;i++) a1[i] = 0;
}

void facqpow(int b)
{
	res[0] = 1;
	for (int i=0;i<=m;i++) t[i] = inv[i+1];
	while (b)
	{
		if (b&1) multiply(res,t,m+1);
		multiply(t,t,m+1);
		b >>= 1;
	}
}

int main()
{
	//freopen("E.in","r",stdin);
	string a,b;
	cin >> a >> b;
	int n = a.length();
	for (int i=0;i<a.length();i++)
	{
		if (a[i] != '1') continue;
		if (b[i] == '1') m++;
		else e++;
	}
	fac[0] = 1;
	for (int i=1;i<=n;i++)
	{
		fac[i] = fac[i-1] * i % mod;
		inv[i] = qpow(fac[i],mod-2);
	}
	facqpow(e);
	ll ans = 0;
	for (int i=0;i<=m;i++) (ans += res[i]) %= mod; //cout << res[i]<<" "; cout<<endl;
	ans = ans * fac[m] % mod * fac[e] % mod * fac[m+e] % mod;
	cout << ans << endl;
	return 0;
}



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

int main() {
    string S, T; cin >> S >> T;
    int A, B; cin >> A >> B;
    string U; cin >> U;
    if (U == S) { A--; }
    else if (U == T) { B--; }
    cout << A << " " << B << endl;
}

Measured memory_bytes: 256
//Robs Code

/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <iomanip>

/***********MACROS***************/
#define int long long int
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define pii pair<int,int>

using namespace std;

const int N = 1e5 + 1;
int n,m,i,j,k,l,x,y,z,cnt[3],sum[3];

/***********MAIN**************/
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int s,w;
	cin >> s >> w;
	if(w >= s){
		cout << "unsafe";
	}else{
		cout << "safe";
	}
}
//.........

Measured memory_bytes: 3552
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")

#include <bits/stdc++.h>
using namespace std;
 
#define len(x) (int)((x).size())
#define endl '\n'
#define int long long
#define x first 
#define y second
#define dbg(x) cout << #x << " = " << x << endl;

void solve(); signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(10);
    solve();
    return 0;
}
 
const int MOD = 998244353, MAXN = 1e6 + 10, INF = 1e18 + 10, BASE = 37;

void solve() {
    int n, k, c;
    cin >> n >> k >> c;
    string s;
    cin >> s;

    if (n == 1) { 
        if (s[0] == 'x') {
            cout << 0 << endl;
        }
        else {
            cout << 1 << endl;
        }
    }

    vector<int> a;
    for (int i = 0; i < len(s); ++i) {
        if (s[i] == 'o') { 
            a.push_back(i);
        }
    }

    vector<int> f1(len(a) + 1, INF), f2(len(a) + 1, -INF);
    f1[1] = a[0], f2[1] = a[len(a) - 1];
    f1[0] = -1, f2[0] = a.back() + 1;

    int j = 1;
    for (int i = 1; i < len(a); ++i) {
        while (j < len(a) && a[j] - f1[i] <= c) {
            j++;
        }
        if (j == len(a)) continue;

        f1[i + 1] = a[j];
    }

    int ll = 2;
    j = len(a) - 2;
    for (int i = 2; i <= len(a); ++i) {
        while (j >= 0 && f2[i - 1] - a[j] <= c) {
            j--;
        }
        if (j == -1) continue;

        f2[i] = a[j];
    }

    // for (int i = 0; i <= k; ++i) {
    //     cout << f1[i] << " ";
    // }
    // cout << endl;

    int ans = 0;
    
    vector<int> ps(MAXN);
    for (int i = 0; i <= k; ++i) {
        int l = f1[i] + 1, r = f2[k - i] - 1;
        // dbg(l << " " << r)
        if (i != 0 && i != k) {
            if (l <= r && l >= 0 && r - l + 1 >= c) {
                ps[l]++;
                ps[r + 1]--;
            }    
        }
        else {
            if (l <= r && l >= 0) {
                ps[l]++;
                ps[r + 1]--;
            }
        }
    }

    for (int i = 1; i < MAXN; ++i) {
        ps[i] = ps[i - 1] + ps[i];
    }

    vector<int> aans;
    for (auto it : a) {
        if (!ps[it]) {
            aans.push_back(it + 1);
            // cout << it + 1 << endl;
        }
    }

    if (len(aans) == k && len(a) == k) {
        if (k == 1) return;
    }

    if (len(aans) <= k) {
        for (auto it : aans) {
            cout << it << endl;
        }
    }
} 

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

using namespace std;
const long long MOD = 1e9+7;
const long long MAXN = 1e5+5;
long long arr[MAXN];
long long arr2[MAXN];
long long dp[MAXN];
long long dp2[MAXN];
int main(){
    long long n,m;
    cin>>n>>m;
    for(long long i=1;i<=n;i++){
        cin>>arr[i];
    }
    dp[1] = arr[2]-arr[1];
     dp[1]%=MOD;
    for(long long i=2;i<n;i++){
        long long diff= arr[i+1]-arr[i];
        dp[i] = (1LL*i*diff)+dp[i-1];
        dp[i]%=MOD;
    }
   
    for(long long i=1;i<=m;i++){
        cin>>arr[i];
    }
    dp2[1] = arr[2]-arr[1];
    dp2[1]%=MOD;
    for(long long i=2;i<m;i++){
        long long diff= arr[i+1]-arr[i];
        dp2[i] = (1LL*i*diff)+dp2[i-1];
        dp2[i]%=MOD;
    }
    for(long long i=1;i<m-1;i++){
        dp2[m-1]+=dp2[i];
        dp2[m-1]%=MOD;
    }
    for(long long i=1;i<n-1;i++){
        dp[n-1]+=dp[i];
        dp[n-1]%=MOD;
    }
    cout<<(1LL*dp2[m-1]*dp[n-1])%MOD<<endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>

using namespace std;


int main(){
int n,m,c;
cin>>n>>m>>c;
vector <int> v;
for(int i=0;i<m;i++){
    int a;cin>>a;
    v.push_back(a);
}
int ans=0;
while(n--){
    int yay=c;
for(int i=0;i<m;i++){
    int b;cin>>b;
    yay+=v[i]*b;
}
    if(yay>0)ans++;
}

cout<<ans;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo M
#define mod(mod_x) ((((long long)mod_x)+modulo)%modulo)
#define Inf 10000000000000000

int M;

//aのb乗
int beki(int a,int b,int M = modulo){
	int x = 1;
	while(b!=0){
		if(b&1){
			x=((long long)x*a)%M;
		}
		a=((long long)a*a)%M;
		b>>=1;
	}
	return x;
}


//aの逆元
int gyakugen(int a){
	return beki(a,modulo-2);
}

vector<int> dp1,dp2;

void dfs1(auto &E,int now,int parent){
	dp1[now] = 1;
	for(int i=0;i<E[now].size();i++){
		int to = E[now][i];
		if(to==parent)continue;
		dfs1(E,to,now);
		dp1[now] = mod(dp1[now] * (dp1[to] + 1));
	}
}

void dfs2(auto &E,int now,int parent,int X){
	vector<int> temp(E[now].size(),1);
	dp2[now] = 1;
	for(int i=0;i<E[now].size();i++){
		int to = E[now][i];
		if(to==parent)continue;
		temp[i] = mod(dp1[to]+1);
		dp2[now] = mod(dp2[now] * temp[i]);
	}
	
	dp2[now] = mod(dp2[now] * (X+1));
	
	vector<int> t1(E[now].size()+1,1),t2(E[now].size()+1,1);
	for(int i=0;i<E[now].size();i++){
		t1[i+1] = mod(t1[i] * temp[i]);
	}
	for(int i=E[now].size()-1;i>=0;i--){
		t2[i] = mod(t2[i+1] * temp[i]);
	}
	
	for(int i=0;i<E[now].size();i++){
		int to = E[now][i];
		if(to==parent)continue;
		int A = mod(t1[i] * t2[i+1]);
		dfs2(E,to,now,mod(A*(X+1)));
	}
}

int main(){
	
	int N;
	cin>>N>>M;
	
	vector<vector<int>> E(N,vector<int>());
	
	for(int i=0;i<N-1;i++){
		int u,v;
		cin>>u>>v;
		u--;v--;
		
		E[u].push_back(v);
		E[v].push_back(u);
	}
	
	dp1.resize(N,0);
	dfs1(E,0,-1);
	dp2.resize(N,1);
	dfs2(E,0,-1,0);
	
	for(int i=0;i<N;i++){
		cout<<dp2[i]<<endl;
	}
	
    return 0;
}


Measured memory_bytes: 20992
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		char[] s = scn.nextLine().toCharArray();
		char[] t = scn.nextLine().toCharArray();
		int N = s.length;
		boolean[] se = new boolean[26], te = new boolean[26];
		for(int i = 0;i < s.length;i++) {
			int a = 'a';
			se[s[i]-a] = true;
		}
		for(int i = 0;i < t.length;i++) {
			int a = 'a';
			te[t[i]-a] = true;
		}
		boolean can = true;
		for(int i = 0;i < 26;i++) {
			can = se[i] || !te[i];
			if(!can)break;
		}

		long[][] next = new long[N][26];

		if(can) {

			for(int i = 0;i < 26;i++) {
				int now = 'a'+i;
				int count = 0;
				boolean first = false;
				for(int j = 0;j < N;j++) {
					if(s[j] == now) {
						if(j == 0) {
							first = true;
							count++;
							continue;
						}else {
							for(int k = j-count;k < j;k++) {
								next[k][i] = j-k;
							}
							count=1;
						}
					}else {
						count++;
					}
				}
				if(first) {
					for(int k = N-count;k < N;k++) {
						next[k][i] = N-k;
					}
				}else {
					for(int k = N-count;k < N;k++) {
						next[k][i] = N-k+next[0][i];
					}
				}
			}
			long ans = 0;
			int i = 0;
			if(t[0]==s[0])i=1;
			for(;i < t.length;i++) {
				int a = 'a';
				ans += next[(int)((ans)%N)][t[i]-a];
			}

			System.out.println(ans+1);

		}else {
			System.out.println(-1);
		}
	}

}


Measured memory_bytes: 55244
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#include<stdio.h>
#include<functional>
#include<queue>

using ll = long long;

using namespace std;

ll mod = 1000000007;

ll n_pow(ll a, ll n) {
	if (n == 0)return 1;
	ll t = n_pow(a, n / 2);
	t *= t;
	t %= mod;
	if (n % 2 == 1)t *= a;
	return t % mod;
}

const int INF = 1001001001;


int main() {
	int n;
	cin >> n;
	vector<int>dp(n + 1);
	for (int i = 0; i < n + 1; i++) {
		dp[i] = i;
	}
	for (int i = 0; i < n + 1; i++) {
		int t = 6;
		while (i + t < n + 1) {
			if (dp[i + t] > dp[i] + 1) {
				dp[i + t] = dp[i] + 1;
			}
			t *= 6;
		}
	}
	for (int i = 0; i < n + 1; i++) {
		int t = 9;
		while (i + t < n + 1) {
			if (dp[i + t] > dp[i] + 1) {
				dp[i + t] = dp[i] + 1;
			}
			t *= 9;
		}
	}
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

class Main {
  public static void main(String[] args){
    Scanner input = new Scanner(System.in);
    String str = input.next();
    int n = str.length();
    for (int i = 0; i < n; i++){
      char c = str.charAt(i);
      if (c == 'A'){
        System.out.print('X');
      }
      else if (c == 'B'){
        System.out.print('Y');
      }
      else if (c == 'C'){
        System.out.print('Z');
      }
      else {
        System.out.print((char)(c - 3));
      }
    }
    System.out.println();
  }
}

Measured memory_bytes: 26536
#include <iostream>
using namespace std;
int main(void){
    int N;
    cin>>N;
    int c=0;
    for(int i=1;i<=N;i+=2){
        int t=0;
        for(int j=1;j<=i;++j){
            if(i%j==0)t++;
        }
        if(t==8)c++;
    }
    cout<<c<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <climits>
#include <math.h>
 
using namespace std;
typedef unsigned long ul;

int main() {
	int a,b;
	cin>>a>>b;
	cout<<(a+b==15?'+':(a*b==15?'*':'x'))<<endl;
}

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

using namespace std;

#define int long long

const int kMod = 1e9 + 7;
int add(int a, int b) {
	return (a + b) % kMod;
}

struct SegmTree {
	int T[1000000];
	int L[1000000];

	void lazy_update(int node, int b, int e) {
		if(L[node] == 0) return;

		T[node] = 0;
		L[node] = 0;
		if(b != e) 
			L[node * 2] = L[node * 2 + 1] = 1;
	}

	void assign(int node, int b, int e, int r) {
		lazy_update(node, b, e);

		if(b == e) {T[node] = 0;}
		else {
			int m = (b + e) / 2;
			if(r <= m) assign(node * 2, b, m, r);
			else {
				L[node * 2] = 1;
				assign(node * 2 + 1, m + 1, e, r);
			}
			lazy_update(node * 2, b, m);
			lazy_update(node * 2 + 1, m + 1, e);

			T[node] = add(T[node * 2], T[node * 2 + 1]);
		}
	}

	void setx(int node, int b, int e, int pos, int x) {
		lazy_update(node, b, e);
		if(b == e) {T[node] = x;}
		else {
			int m = (b + e) / 2;
			if(pos <= m) setx(node * 2, b, m, pos, x);
			else setx(node * 2 + 1, m + 1, e, pos, x);

			lazy_update(node * 2, b, m);
			lazy_update(node * 2 + 1, m + 1, e);

			T[node] = add(T[node * 2], T[node * 2 + 1]);
		}
	}

	int getp(int node, int b, int e, int r) {
		// if(r < b) return 0;
		lazy_update(node, b, e);

		if(b == e) return T[node];
		else {
			int m = (b + e) / 2;
			if(r <= m) return getp(node * 2, b, m, r);
			lazy_update(node * 2, b, m);
			lazy_update(node * 2 + 1, m + 1, e);

			return add(T[node * 2], getp(node * 2 + 1, m + 1, e, r));
		}
	}

	void dump(int node, int b, int e) {
		lazy_update(node, b, e);
		if(b == e) cerr << T[node] << " ";
		else {
			int m = (b + e) / 2;
			dump(node * 2, b, m);
			dump(node * 2 + 1, m + 1, e);
		}
	}
};
SegmTree TA, TB;

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n, a, b;
	cin >> n >> a >> b;


	vector<int> V(n + 1);
	for(int i = 1; i <= n; ++i)
		cin >> V[i];


	TA.setx(1, 0, n, 0, 1);
	TB.setx(1, 0, n, 0, 1);
	int ja = 0, jb = 0;

	for(int i = 2; i <= n; ++i) {

		// cerr << "Trees:\n";
		// TA.dump(1, 0, n);
		// cerr << endl;
		// TB.dump(1, 0, n);
		// cerr << endl;

		bool cha, chb;
		int xa, xb;
		if(V[i] - V[i - 1] >= a) {
			xa = TB.getp(1, 0, n, n);
			cha = false;
		} else {
			while(V[i] - V[ja + 1] >= a)
				++ja;
			xa = TB.getp(1, 0, n, ja);
			cha = true;
		}

		// cerr << xa << " " << xb << endl;

		if(V[i] - V[i - 1] >= b) {
			xb = TA.getp(1, 0, n, n);
			chb = false;
		} else {
			while(V[i] - V[jb + 1] >= b)
				++jb;
			xb = TA.getp(1, 0, n, jb);
			chb = true;
		}

		if(cha) TA.assign(1, 0, n, i - 2);
		if(chb) TB.assign(1, 0, n, i - 2);
		TA.setx(1, 0, n, i - 1, xa);
		TB.setx(1, 0, n, i - 1, xb);
	}

	cout << add(TA.getp(1, 0, n, n), TB.getp(1, 0, n, n)) << endl;

	return 0;
}

Measured memory_bytes: 9216
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		int a = 0;
		for (int from = 1; from < N; ++from) {
			
			for (int num = 2; num <= N; ++num) {
				int ans = (from + (from + num - 1))*num / 2;
				if (ans == N)a++;
			}
		}
		cout << a << endl;
	}
	return 0;
}

Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int top, S[1000];

void push(int x){
    S[++top]=x;
}

int pop(){
    top--;
    return S[top+1];
}

int main(){
    int a, b;
    top=0;
    char s[100];
    
    while(scanf("%s", s) != EOF){
        if(s[0]=='+'){
            a=pop();
            b=pop();
            push(a+b);
        }else if(s[0]=='-'){
            b=pop();
            a=pop();
            push(a-b);
        }else if(s[0]=='*'){
            a=pop();
            b=pop();
            push(a*b);
        }else{
            push(atoi(s));
        }
    }
    
    printf("%d\n", pop());
    
    return 0;
}



Measured memory_bytes: 2764
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n=I()
d,x=MI()
ans=0
for i in range(n):
    ans+=1+int((d-1)//I())
print(ans+x)

Measured memory_bytes: 3444
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <tuple>

using namespace std;

using int64 = long long;

const int64 INF = (1LL<<60);

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

    vector<int> v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    
    cout << v[K-1] << "\n";

    return 0;
}

Measured memory_bytes: 256
import math

def mycounter(d,i):
    if i in d:
        d[i]+=1
    else:
        d[i]=1
    return d
    
def ABC159D(a):
    if a<2:
        return 0
    else:
        return math.factorial(a)//math.factorial(a-2)//2

n=int(input())
a=list(map(int,input().split()))
d = dict()
for i in a:
    d=mycounter(d,i)
p=sum([ABC159D(i) for i in d.values()])
for i in a:
    print(p-d[i]+1)

Measured memory_bytes: 26140
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <cassert>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;


int main() {
    int64_t N;
    cin >> N;
    vector<int64_t> divnum;
    for(int64_t i=1; i*i <= N; ++i) {
        if(N % i == 0) {
            divnum.push_back(i);
            if( N / i != i) {
                divnum.push_back(N/i);
            }
        }
    }
    int64_t sum = 0;
    for(auto r : divnum) {
        int64_t x = (N/r) - 1;
        if( x > r)
            sum += x;
    }

    cout << sum << endl;

    return 0;
}



Measured memory_bytes: 3212
N = int(input())
x = input().split()
X = [(int(x[i]), i) for i in range(N)]
X.sort()
ans = [0]*N
for i in range(N // 2):
    ans[X[i][1]] = X[N // 2][0]
for i in range(N // 2, N):
    ans[X[i][1]] = X[N // 2 - 1][0]
for i in range(N):
    print(ans[i])

Measured memory_bytes: 99668