akhauriyash/Code-Regression huggingface dataset:
N,K=map(int,input().split())
def f(b):
  d=max(b-K,0)*(N//b)+max(N%b-K+1,0)
  return d
ans=0
if K==0:
  print(N**2)
  exit()
  
for i in range(1,N+1):
  ans+=(f(i))
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include "bits/stdc++.h"
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

int main(){
    int x,cnt=0;
    cin>>x;
    for(int i=1;;i++){
        cnt+=i;
        if(x<=cnt){
            cout<<i<<endl;
            return 0;
        }
        
    }
 }

Measured memory_bytes: 256
r, g, b = map(int, input().split())
k = int(input())

for i in range(k):
    if r < g < b:
        break
    else:
        if g <= r:
            g *= 2
        elif b <= g:
            b *= 2
        else:
            b *= 2

if r < g < b:
    print("Yes")
else:
    print("No")

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

using ull = unsigned long long;
using ll = long long;
using ld = long double;

const int mod = 1e9 + 7;
const int inf = INT_MAX;
const int N = 1e6;

int n, a[N];
bool mark[N + 1];

bool prime[N + 1];
vector<int> primes;

void sieve() {
    memset(prime, true, sizeof(prime));
    prime[1] = false;

    for (int i = 2; i * i <= N; i++) {
        if (prime[i]) {
            for (int j = i * i; j <= N; j += i) {
                prime[j] = false;
            }
        }
    }
    for (int i = 2; i <= N; i++) {
        if (prime[i])
            primes.push_back(i);
    }
}

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

    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];

    int g = a[0];
    for (int i = 1; i < n; i++) g = __gcd(g, a[i]);

    for (int i = 0; i < n; i++) {
        if (a[i] > 1 and mark[a[i]]) {
            if (g == 1)
                cout << "setwise coprime\n";
            else cout << "not coprime\n";
            return 0;
        }
        mark[a[i]] = true;
    }

    bool ok = true;
    sieve();

    for (int p : primes) {
        int c = 0;
        for (int j = p; j <= N; j += p) {
            c += mark[j];
        }
        ok &= c <= 1;
    }

    if (ok)
        cout << "pairwise coprime\n";
    else {
        if (g == 1)
            cout << "setwise coprime\n";
        else cout << "not coprime\n";
    }
    return 0;
}

Measured memory_bytes: 9684
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int A = 0;
		int B = 0;
		Scanner sc = new Scanner(System.in);
		A = Integer.parseInt(sc.next());
		B = Integer.parseInt(sc.next());
		int max = 0;
		int i;
		for (i = 0; i < 2; i++) {
			if (A > B) {
				max += A;
				A--;
			} else {
				max += B;
				B--;
			}
		}
		System.out.println(max);
	}
}


Measured memory_bytes: 22740
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main
{
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;
        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }
        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt()
        {
            return Integer.parseInt(next());
        }
 
        long nextLong()
        {
            return Long.parseLong(next());
        }
 
        double nextDouble()
        {
            return Double.parseDouble(next());
        }
 
        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
 
    public static void main(String[] args)
    {
        FastReader s=new FastReader();
        int d=s.nextInt();
        int count=0;
        boolean ans=false;
        for(int i=0;i<d;i++) {
        	int x=s.nextInt();
        	int y=s.nextInt();
        	
        	if(x==y) {
        		count++;
        		if(count==3) {
        			ans=true;
        			break;
        		}
        	}
        	else {
        		count=0;
        	}
        }
        if(ans==true) 
            System.out.println("Yes");
        else
        	System.out.println("No");
    }
}

Measured memory_bytes: 32828
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
#include<bitset>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define LONG_INF 9223372036854775807
#define INF 1000000000LL
#define EPS 1e-10
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define dump(a) rep(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define all(v) v.begin(),v.end()
#define pb push_back


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

    char c;
    cin >> c;
    cout << char(c+1) << endl;

    return 0;
}

Measured memory_bytes: 256
s = list(input())
flag = 0
for i in range(-(-len(s)//(2))):
    if s[i] != s[len(s)-1-i]:
        flag = 1
s1 = s[0:-(-len(s)//(2))-1]
s2 = s[-(-len(s)//(2)):len(s)]
for i in range(-(-len(s1)//(2))):
    if s1[i] != s1[len(s1)-1-i]:
        flag = 1
for i in range(-(-len(s2)//(2))):
    if s2[i] != s2[len(s2)-1-i]:
        flag = 1
if flag == 0:
    print('Yes')
else:
    print('No')


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

int main() {
  ll n;
  cin >> n;
  map<ll, ll> mp{};
  ll sum = 0;
  rep(i, n) {
    ll a;
    cin >> a;
    sum += a;
    mp[a]++;
  }

  ll q;
  cin >> q;
  rep(i, q) {
    ll b, c;
    cin >> b >> c;

    sum -= b * mp[b];
    sum -= c * mp[c];
    mp[c] += mp[b];
    mp[b] = 0;
    sum += b * mp[b];
    sum += c * mp[c];
    cout << sum << endl;
  }
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    switch (n % 10) {
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
            cout << "hon" << endl;
            break;
        case 0:
        case 1:
        case 6:
        case 8:
            cout << "pon" << endl;
            break;
        case 3:
            cout << "bon" << endl;
            break;
    }
    return 0;
}


Measured memory_bytes: 3624
a, b, c, d = map(int, input().split())
if a >= c:
    if b >= d:
        print(max(d-a, 0))
    else:
        print(max(b-a, 0))
else:
    if b >= d:
        print(max(d-c, 0))
    else:
        print(max(b-c, 0))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define int long long
#define pb emplace_back
#define mp make_pair
#define tci(v,i) for(auto i=v.begin();i!=v.end();i++)
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define revrep(i,n) for(long long i=n-1;i>=0;i--)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator<int> output (cout," ")
#define pv(x) copy(all(x),output)
#define pa(a) rep(i,0,sizeof(a)/sizeof(a[0]))cout<<a[i]<<" "
#define endl '\n'
#define f first
#define s second
#define PI 3.141592653589793
#define test int t;cin>>t; while(t--)
#define set0(x) memset(x,0,sizeof(x))
#define set1(x) memset(x,1,sizeof(x))
#define getarr(arr,n) int arr[n];rep(i,0,n)cin>>a[i]
#define getvec(vec,n) vi vec;int x;rep(i,0,n){cin>>x;vec.pb(x);}
#define dg(x) cout<<#x<<':'<<x<<endl;
#define dg2(x,y) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<endl;
#define dg3(x,y,z) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<endl;
#define dg4(x,y,z,zz) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<' '<<#zz<<':'<<zz<<endl;
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
int isPowerof2(int x) { return (x && !(x & x-1)); }

int32_t main(){
    boost;osit;
    int n;
    cin>>n;
    double p[n+1];
    rep(i,1,n+1)cin>>p[i];
    double dp[n+1][n+1];
    rep(i,0,n+1)rep(j,0,n+1)dp[i][j]=0.0;
    dp[0][0]=1;
    rep(i,1,n)dp[i][0]=dp[i-1][0]*(1.0-p[i]);
    rep(i,1,n+1){
        rep(j,1,n+1){
            dp[i][j]=dp[i-1][j-1]*p[i]+(1.0-p[i])*dp[i-1][j];
        }
    }
    double ans=0.0;
    rep(j,0,n+1){
        if(j>(n/2))ans+=dp[n][j];
    }
    cout<<fixed<<setprecision(15)<<ans;
    return 0;
}

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

#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
#endif
	int n,m,x;
	cin>>n>>m>>x;
	int c[n],a[n][m];
	for(int i=0;i<n;i++){
		cin>>c[i];
		for(int j=0;j<m;j++)
			cin>>a[i][j];
	}
    int tot=(1<<n);
    int cost=1e9;   
    for(int i=0;i<tot;i++){
        int pcost=0;
        int val[m];
        for(int l=0;l<m;l++)
            val[l]=0;
        for(int j=0;j<n;j++){
            if(i&(1<<j)){
                pcost+=c[j];
                for(int k=0;k<m;k++)
                    val[k]+=a[j][k];
            }
        }
        int flag=1;
        for(int j=0;j<m;j++){
            if(val[j]<x){
                flag=0;
                break;
            }
        }
        if(flag)
            cost=min(cost,pcost);
    }
    if(cost==1e9)  cout<<"-1\n";
    else cout<<cost<<endl;
 
	return 0;
}

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x%mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
	mint operator+(const mint a) const { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= a; }
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const { return pow(mod - 2); }
	mint& operator/=(const mint a) { return *this *= a.inv(); }
	mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

using namespace std;

int main() {
	int N, K;//1~ K 長さN
	cin >> N >> K;
	mint ans = 0;
	vector<mint>GCD(K + 1);
	for (int n = K; n > 0; --n) {
		mint anssub = 0;
		mint num = K / n;
		anssub = num.pow(N);
		for (int m = n * 2; m <= K; m += n) {
			anssub -= GCD[m];
		}
		GCD[n] = anssub;
		ans += (mint)n *anssub;
		//cout << (mint)n *anssub << endl;
	}
	//for (int n = 1;n<=K;++n) {
		//cout << GCD[n] << endl;
	//}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4020
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

class Solve{
    static void Main(string[] args){
        var N = int.Parse(Console.ReadLine());
        var P = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var Q = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int a = 1, b = 1;
        var list = new List<int>(8);
        static int Factorial(int n){
            int result = 1;
            for (; n > 1; n--) result *= n;
            return result;}
        for (int i = 0; i < N; i++){
            var pi = P[i];
            var x = pi - list.Where(d => d < pi).Count();
            a += i == N - 1 ? 0 : (x - 1) * Factorial(N - 1 - i);
            list.Add(pi);}
        list.Clear();
        for (int i = 0; i < N; i++){
            var qi = Q[i];
            var x = qi - list.Where(d => d < qi).Count();
            b += i == N - 1 ? 0 : (x - 1) * Factorial(N - 1 - i);
            list.Add(qi);}
        var answer = Math.Abs(a - b);
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();}}

Measured memory_bytes: 28328
#include <iostream>
#include <string>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <utility>
using namespace std;

int main() {
    long long N, M; cin >> N >> M;
	vector<pair<long long, long long>> vec(N);
	for (long long i = 0; i < N; i++){
		long long A, B; cin >> A >> B;
		vec[i].first = A;
		vec[i].second = B;
	}

	sort(vec.begin(), vec.end());

	long long res = 0;
	long long place = 0;

	while(M > 0){
		res += vec[place].first * min(M, vec[place].second);
		M -= min(M, vec[place].second);
        place++;
	}

	cout << res << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <sstream>

using namespace std;
typedef long long ll;

int main() {
	cin.sync_with_stdio(0); cin.tie(0); cout.tie(NULL);
	vector<int> v;
	int n; cin >> n;
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		int x; cin >> x; v.push_back(x);
	}
	sort(v.begin(), v.end());
	ans = v[v.size() - 1];
	int cnt = n - 2;
	for (int i = v.size() - 2; i >= 0; i--) {
		if (cnt <= 0)break;
		if (cnt == 1) {
			ans += v[i]; break;
		}
		ans += v[i] * (ll)2;
		cnt -= 2;
		if (cnt <= 0)break;	
	}
	cout << ans << '\n';


}


Measured memory_bytes: 3904
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    ll n;
    cin>>n;
    string s[n];
    rep(i,n){cin>>s[i];}
    ll cnt[26]={};
    ll cnts[26][11]={};
    unordered_map<string, ll> mp;
    rep(i,n){
        rep(j,26){cnt[j]=0;}
        rep(j,10){
            cnt[s[i][j]-'a']++;
        }
        string ss="";
        rep(j,26){
           ss += to_string(cnt[j]);
           ss += ","; 
        }
        DEBUG{cout << ss << endl;}
        mp[ss]++;
    }
    ll res = 0;
    for(auto x:mp){
        res += x.second * (x.second-1) / 2;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 23844
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<long> a(n), b(n), c(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  for(int i = 0; i < n; i++) cin >> b[i];
  for(int i = 0; i < n; i++) cin >> c[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());
  long long ans = 0;
  for(int j = 0; j < n; j++){
    long long A = lower_bound(a.begin(), a.end(), b[j]) - a.begin();
    long long C = n - (upper_bound(c.begin(), c.end(), b[j]) - c.begin());
    ans += A * C;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<queue>
#include<deque>
#include<string>
#include<utility>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#include<ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<pli> vpli;

inline ll read(){
    ll Hashimoto=0;
	bool Kanna=1;
    char I_Love=getchar();
    while(I_Love<'0'||I_Love>'9'){
        if(I_Love=='-')Kanna=0;
        I_Love=getchar();
    }
    while(I_Love>='0'&&I_Love<='9'){
        Hashimoto=Hashimoto*10+I_Love-'0';
        I_Love=getchar();
    }
    return (Kanna?Hashimoto:-Hashimoto);
}
template<typename T1,typename T2> inline void Umax(T1 &a,T2 b){
	if(a<b)a=b;
}
template<typename T1,typename T2> inline void Umin(T1 &a,T2 b){
	if(a>b)a=b;
}

#define I_Love_Hashimoto_Kanna main
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define filein(s) freopen(s,"r",stdin);
#define fileout(s) freopen(s,"w",stdout);
#define file freopen("I_Love_Hashimoto_Kanna.out","w",stdout);
#define RE cout<<"I_Love_Hashimoto_Kanna"<<endl;
#define Tone(Kanna) cout<<Kanna<<endl;
#define Tall(Hashimoto,Kanna) for(int I_Love=0;I_Love<(Kanna);++I_Love)cout<<Hashimoto[I_Love]<<(I_Love==(Kanna)-1?"\n":" ");
#define FOR(I_Love,Hashimoto,Kanna) for(int I_Love=Hashimoto;I_Love<(Kanna);++I_Love)
#define MP(Hashimoto,Kanna) make_pair(Hashimoto,Kanna)
#define REV(Kanna) reverse(Kanna.begin(),Kanna.end());
#define SORT(Kanna) sort(Kanna.begin(),Kanna.end());
#define UNIQUE(Kanna) Kanna.erase(unique(Kanna.begin(),Kanna.end()),Kanna.end());
#define inf (1000000000)
#define linf (1000000000000000000ll)
#define mod (1000000007)

int n,m;
int a[11][11];

int dis(int i,int j){
	int ret=0;
	FOR(k,0,m){
		ret+=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
	}
	return ret;
}
bool is(int x){
	int a=sqrt(x);
	FOR(k,-10,10){
		int b=a+k;
		if(b*b==x)return 1;
	}
	return 0;
	
}

int I_Love_Hashimoto_Kanna() {
	//完全想清楚了再开始写。
	//写不顺、不知道怎么写、很乱的时候，停下来好好想想。
	//做得慢总比做不出好。
	fastio;
	cin>>n>>m;
	FOR(i,0,n)FOR(j,0,m)cin>>a[i][j];
	int ans=0;
	FOR(i,0,n)FOR(j,i+1,n){
		if(is(dis(i,j))){
			ans++;
		}
	}
	Tone(ans);
	return 0;
}


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

a=list(map(int, input().split(' ')))
b=list(map(int, input().split(' ')))

ans=0

asums = [0]
asum=0
for i in a:
    asum+=i
    asums.append(asum)

bsums = [0]
bsum=0
for i in b:
    bsum+=i
    bsums.append(bsum)


j=m

i=0

while i<len(asums) and k>=asums[i]:
    while k-asums[i]<bsums[j]:
        j-=1
    ans = max(ans, i+j)
    i+=1
print(ans)
    


    
        
    


Measured memory_bytes: 141236
#include<bits/stdc++.h>
using namespace std;
     
#define ll long long
#define loop(i,a,n) for(ll i=a;i<n;++i)
#define revloop(i,a,b) for(ll i=a;i>=b;--i)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 1000000000000000000
#define MOD 998244353 

void func()
{
    ll n,k;
    cin>>n>>k;
    ll a[n];
    loop(i,0,n) cin>>a[i];
    loop(i,k,n){
        if(a[i]>a[i-k]){
            cout<<"Yes"<<"\n";
        }
        else{
            cout<<"No"<<"\n";
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w" , stdout);
    #endif
 
    ll t=1;
    //cin>>t;
    while(t--)
    {
        func();
    }

}

Measured memory_bytes: 5220
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 入力値を数値で返却する
def gets_i()
  gets.chomp.to_i
end
x = gets_i

mod = x % 11
ans = x / 11
if mod == 0
  puts ans * 2
elsif mod <= 6
  puts ans * 2 + 1
else
  puts ans * 2 + 2
end


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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<unsigned long> a(N);
    for(auto&& i : a)cin >> i;
    vector edge(N, vector(0, 0UL));
    for(unsigned long i{1}, u, v; i < N; ++i){
        cin >> u >> v;
        edge[--u].push_back(--v);
        edge[v].push_back(u);
    }
    vector<unsigned long> lis;
    vector<unsigned long> ans(N);
    [dfs_impl = [&a, &edge, &lis, &ans](auto f, unsigned long now, unsigned long prev) -> void {
        auto it = lower_bound(lis.begin(), lis.end(), a[now]);
        pair<unsigned long, unsigned long> move;
        if(it == lis.end()){
            move = {lis.size(), 0};
            lis.push_back(a[now]);
        }else{
            move = {it - lis.begin(), *it};
            *it = a[now];
        }
        ans[now] = lis.size();
        for(const auto& i : edge[now])if(i != prev)f(f, i, now);
        if(move.second == 0)lis.pop_back();
        else lis[move.first] = move.second;
    }]{dfs_impl(dfs_impl, 0, 0);}();
    for(const auto& i : ans)cout << i << endl;
    return 0;
}

Measured memory_bytes: 37500
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String T = sc.next();

        int min = 1005;
        for (int i = 0; i <= S.length() - T.length(); i++) {
            int tmp = 0;
            for (int j = 0; j < T.length(); j++) {
                if (S.charAt(i+j) != T.charAt(j)) tmp++;
            }
            min = Math.min(min,tmp);
        }

        System.out.println(min);
    }
}


Measured memory_bytes: 35556
#include <iostream>

using namespace std;

struct Card {
	char suit, value;
};

void bubble(struct Card A[], int N) {
	for (int i = 0; i < N; i++) {
		for (int j = N - 1; j >= i + 1; j--) {
			if (A[j].value < A[j - 1].value) {
				Card t = A[j];
				A[j] = A[j - 1];
				A[j - 1] = t;
			}
		}
	}
}

void selection(struct Card A[], int N) {
	for (int i = 0; i < N; i++) {
		int minj = i;
		for (int j = i; j < N; j++) {
			if (A[j].value < A[minj].value)
				minj = j;
		}
		Card t = A[i];
		A[i] = A[minj];
		A[minj] = t;
	}
}

void print(struct Card A[], int N) {
	for (int i = 0; i < N; i++) {
		if (i > 0)
			cout << " ";
		cout << A[i].suit << A[i].value;
	}
	cout << endl;
}

bool isStabele(struct Card C1[], struct Card C2[], int N) {
	for (int i = 0; i < N; i++) {
		if (C1[i].suit != C2[i].suit)
			return false;
	}
	return true;
}

int main() {
	Card C1[100], C2[100];
	int N;
	char ch;

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> C1[i].suit >> C1[i].value;
		C2[i] = C1[i];
	}

	bubble(C1, N);
	selection(C2, N);

	print(C1, N);
	cout << "Stable\n";

	print(C2, N);
	if (isStabele(C1, C2, N))
		cout << "Stable\n";
	else
		cout << "Not stable\n";

	return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std; 
#define int long long
#define ff first
#define ss second
#define f(i,x,n) for(int i=x;i<n;++i)
int32_t main() 
{ 
	int a,b,c;
//	cin>>a;
	cin>>b; cin>>c;
	cout<<b*c;
	return 0; 
} 




Measured memory_bytes: 3632
N,M = map(int,input().split())
a = set([int(input()) for _ in range(M)])
mod = 10**9+7
dp=[0]*(N+1)
dp[0]=1


for i in range(N):
  if i+1 not in a:
    dp[i+1]+=dp[i]
    dp[i+1] %= mod
  if i+2 <= N and i+2 not in a:
    dp[i+2]+=dp[i]
    dp[i+2]%=mod
  
print(dp[-1])


Measured memory_bytes: 13192
#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>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; 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)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
#define mp make_pair
#define IP pair<int,int>
#define enld endl


int main() {
	int S, W;
	cin >> S >> W;
	if (S <= W) {
		cout << "unsafe" << endl;
	}
	else {
		cout << "safe" << endl;
	}
}

Measured memory_bytes: 3636
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <cstdio>
#include<iomanip>
typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif
using namespace std;
int main() {
  int a,b;
  cin >> a >> b;
  int c=0;
  for (int i = 0; i < b; i++) {
    cin >> c;
    a-=c;
  }
  if (a < 0) {
    cout << -1;
    return 0;
  }
  cout << a;
  return 0;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
sort(all(list));
sort(all(list), greater<int>());
//配列の内容表示
dout << "====listの内容====\n";
for (int i = 0; i < N; i++) dout << list[i] << endl;
dout << "====ここまで====\n";
*/


Measured memory_bytes: 3624
package main
 
import "fmt"
 
func main() {
	var n, k int
	start := 0
	fmt.Scan(&n, &k)
	a := make([]int, n)
	state := make([]int, n)
	tmp := make([]int, 1000000)
	tmp[0] = 0
	loopLength := 0
 
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
 
	for i := 0; i < k; i++ {
		start = a[start] - 1
		tmp[i+1] = start
		if state[start] == 1 {
			for j := 0; j < len(tmp); j++ {
				if tmp[j] == start {
					tmp = tmp[j : i+1]
					loopLength = len(tmp)
					break
				}
			}
			fmt.Println(tmp[(k-i-1)%loopLength] + 1)
			return
		} else {
			state[start] = 1
		}
	}
	fmt.Println(start + 1)
}

Measured memory_bytes: 14092
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int q = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < q; i++) {
			a[sc.nextInt() - 1]++;
		}

		for (int i = 0; i < n; i++) {
			if (k + a[i] - q <= 0) System.out.println("No");
			else System.out.println("Yes");
		}
	}
}


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

int main(){
	char a, b;
  cin >> a >> b;
  
  if(a == 'H' && b == 'H'){
  	cout << 'H' << endl;
  }
  if(a == 'H' && b == 'D'){
  	cout << 'D' << endl;
  }
  if(a == 'D' && b == 'H'){
  	cout << 'D' << endl;
  }
  if(a == 'D' && b == 'D'){
  	cout << 'H' << endl;
  }
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll a, b, q;
    cin >> a >> b >> q;

    vl s(a+2), t(b+2);
    s[0] = t[0] = -INF;
    exrep(i, 1, a) {
        cin >> s[i];
    }
    exrep(i, 1, b) {
        cin >> t[i];
    }
    s[a+1] = INF;
    t[b+1] = INF; 

    vl ans(q);
    rep(loop, q) {
        ll x;
        cin >> x;
        ll kamiRpos = lower_bound(all(s), x) - s.begin();
        ll teraRpos = lower_bound(all(t), x) - t.begin();
        ll kamiLpos = kamiRpos - 1;
        ll teraLpos = teraRpos - 1;
        vvl v(2, vl(2));  // v[i][j] : i = 0 のとき神社、i = 1 のとき寺。j = 0 のとき左、j = 1 のとき右 
        v[0][0] = s[kamiLpos];
        v[0][1] = s[kamiRpos];
        v[1][0] = t[teraLpos];
        v[1][1] = t[teraRpos];
        ll res = INF;
        rep(i, 2) {  // i = 0 のとき神社から、 i = 1 のとき寺から訪れる
            rep(j, 2) {  // j = 0 のとき左、j = 1 のとき右 
                rep(k, 2) {  // k = 0 のとき左、k = 1 のとき右 
                    chmin(res, abs(x - v[i][j]) + abs(v[i][j] - v[1-i][k]));
                }
            }
        }
        ans[loop] = res;
    }

    rep(i, q) {
        out(ans[i]);
    }
    
    re0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1000000000
#define  pow(x) pow(10,(x)) 
typedef long long int LL;
const int MOD = 1000000007;
//sort(all(x))とするとソートできるよ

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

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>
#include<deque>
#include<random>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl
#define CE cout<<endl

ll n,m,a,b,c,x,y,z,aa[200010],ab[200010],ac[1010][1010];
bool r,ra,rb,rc;
string s,sa,sb,sc;
char ca,cb,cc,cd[1010][1010];
vector<ll> va,vb,vc;

int main(){
    cin>>n>>a>>b;
    C (abs(a-b)%2 ? "Borys":"Alice") E;
}

Measured memory_bytes: 256
N = int(input())
dp = [[0, 0, 0] for _ in range(N+1)]

for i in range(N):
    a, b, c = map(int, input().split())
    
    dp[i+1][0] = max(dp[i][1], dp[i][2]) + a
    dp[i+1][1] = max(dp[i][0], dp[i][2]) + b
    dp[i+1][2] = max(dp[i][0], dp[i][1]) + c
    
print(max(dp[-1]))
    

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

using namespace std;
#define ll long long
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define PRINT(item) cout << (item) << endl;
#define PRINT_VEC(V)                     \
    for (auto v : (V)) cout << v << ' '; \
    cout << endl;
#define PRINT_ENTER() cout << endl;
/* cout << fixed << setprecision(10) << decimal << endl; */

int main() {
    /* code */
    int N, M;
    cin >> N >> M;
    vector<int> gate(N + 1, 0);
    REP(i, M) {
        int L, R;
        cin >> L >> R;
        gate[L - 1]++, gate[R]--;
    }
    REP(i, gate.size()) { gate[i + 1] += gate[i]; }
    cout << count(gate.begin(), gate.end(), M) << endl;
    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1 << 30;

using namespace std;

using ll = long long;
using P = tuple<int, int>;
using iarr = valarray<int>;

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

    vector<int> v(N);
    for(int i = 0; i < N; ++i) cin >> v[i];

    ll cnt = 0;
    ll t = v[0] + v[1];
    if(t > x){
        ll s = t - x;
        if(v[1] - s < 0){
            v[1] = 0;
        }else{
            v[1] -= s;
        }
        cnt += s;
    }

    ll pre = v[1];
    for(int i = 2; i < N; ++i){
        ll total = pre + v[i];
        if(total > x){
            v[i] -= total - x;
            cnt += total - x;
        }
        pre = v[i];
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair

#define REP(i, n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,h) for(int i=(int)(l);i<=(int)(h);++i)
#define FORD(i,h,l) for(int i=(int)(h);i>=(int)(l);--i)

#define max(a,b) a>b?a:b
#define min(a,b) a>b?b:a

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define ALL(t) (t).begin(),(t).end()

using namespace std;



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;cin>>n>>k;
    string s;
    cin>>s;
    ll int cnt = 0;
    ll int a[n+2];
    ll int mul = 1;
    if(k == 2 || k == 5){
        for (size_t i = 0; i < n; i++) {
            if((s[i] - '0') % k == 0) {
                cnt += (i+1);
            }
        }
        cout<<cnt<<"\n";
    }
    else{
        reverse(s.begin(),s.end());
           for (size_t i = 0; i < n; i++) {
               a[i] = ((s[i] - '0')*mul) % k;
               mul = (mul*10) % k;
           }
           ll int mod[k+2];
           memset(mod , 0, sizeof(mod));
           ll int prefix = 0;
           for (size_t i = 0; i < n; i++) {
               prefix += a[n-(i+1)];
               mod[ ((prefix % k) + k) % k ]++;
           }
           for (size_t i = 0; i < k; i++) {
               if(mod[i] > 1){
                   cnt += ((ll)mod[i]*(mod[i]-1))/2;
               }
           }
           cnt += mod[0];
           cout<<cnt<<"\n";
       }

    return 0;

}


Measured memory_bytes: 5348
import java.util.*;
import java.util.Map.Entry;
 
class MyComparator implements Comparator {
    @Override
    public int compare (Object arg0, Object arg1) {
        int x = (int) arg0;
        int y = (int) arg1;

        if (x < y) {
            return 1;
        } else if (x > y) {
            return -1;
        } else{
            return 0;
        }
    }
}

class Main {
	 static int mod =  (int) (Math.pow(10,9)+7);
   public static void main(String[] args) {
	   
       Scanner sc = new Scanner(System.in);
       int N = sc.nextInt();
       int M = sc.nextInt();

       int[] a = new int[(int)N];
       int[] b = new int[(int)N];
       List<ArrayList<Integer>> list= new ArrayList<ArrayList<Integer>>();
       for(long i=0;i<M+1;i++)list.add(new ArrayList<Integer>());
       for (int i=0 ; i<N; i++) {
           a[i] = sc.nextInt();
           b[i] = sc.nextInt();
           if(a[i]>M)continue;
           list.get(a[i]).add(b[i]);
       }
       
       long cnt=0;
       Queue<Integer> pq = new PriorityQueue<>(new MyComparator ());
       for(int i=1;i<=M;i++) {
           for(int j:list.get(i)) {
        	   pq.add(j);
           }
           if(!pq.isEmpty()) {
        	   cnt=cnt+pq.poll();        	   
           }
       }

       
       System.out.println(cnt);
   }
      

}

Measured memory_bytes: 100736
import heapq
import sys
input=sys.stdin.readline

class SegmentTreeMin():
  def __init__(self,n,init):
    self.offset=2**((n-1).bit_length())
    self.tree=[init]*(2*self.offset)
    self.init=init
  def update(self,pos,val):
    pos+=self.offset
    self.tree[pos]=val
    while pos>1:
      pos=pos//2
      self.tree[pos]=min(self.tree[2*pos],self.tree[2*pos+1])
  def query(self,l,r):
    l+=self.offset
    r+=self.offset
    ret=self.init
    while l<=r:
      ret=min(ret,self.tree[r])
      r=(r-1)//2
      ret=min(ret,self.tree[l])
      l=(l+1)//2
    return ret

n=int(input())
arr=list(map(int,input().split()))
odds=SegmentTreeMin(n//2,10**18)
evens=SegmentTreeMin(n//2,10**18)
dic={}
for i in range(n):
  dic[arr[i]]=i
  if i%2==0:
    odds.update(i//2,arr[i])
  else:
    evens.update(i//2,arr[i])
q=[]
heapq.heappush(q,(odds.query(0,(n-1)//2),0,n-1))
ans=[]
while len(q)!=0:
  _,l,r=heapq.heappop(q)
  if l%2==0:
    a=odds.query(l//2,r//2)
    odds.update(dic[a]//2,10**18)
    b=evens.query(dic[a]//2,r//2)
    evens.update(dic[b]//2,10**18)
    ans.append(a)
    ans.append(b)
    tl=dic[a]
    tr=dic[b]
    if tl!=l:
      heapq.heappush(q,(odds.query(l//2,(tl-1)//2),l,tl-1))
    if tl+1<tr-1:
      heapq.heappush(q,(evens.query((tl+1)//2,(tr-1)//2),tl+1,tr-1))
    if tr!=r:
      heapq.heappush(q,(odds.query((tr+1)//2,r//2),tr+1,r))
  else:
    a=evens.query(l//2,r//2)
    evens.update(dic[a]//2,10**18)
    b=odds.query((dic[a]+1)//2,r//2)
    odds.update(dic[b]//2,10**18)
    ans.append(a)
    ans.append(b)
    tl=dic[a]
    tr=dic[b]
    if tl!=l:
      heapq.heappush(q,(evens.query(l//2,(tl-1)//2),l,tl-1))
    if tl+1<tr-1:
      heapq.heappush(q,(odds.query((tl+1)//2,(tr-1)//2),tl+1,tr-1))
    if tr!=r:
      heapq.heappush(q,(evens.query((tr+1)//2,r//2),tr+1,r))
print(*ans)

Measured memory_bytes: 176936
/**
*   @Author : MeGaCrazy
*   @InitTime : Thu Jul 18 03:14:33 2019
*   @Idea :
*
*
*
*
*
*  Happy Solving :)
**/
#include <bits/stdc++.h>
using namespace std;

const int N=3e5+7;
int l[N],r[N];
int main(){
#ifndef ONLINE_JUDGE
   //freopen("in","r",stdin);
   //freopen("out","w",stdout);
#endif
    int n;

    cin>>n;
    string a;
    cin>>a;
    for(int i=0,j=n-1;i<n;i++,j--){
    	if(a[i]=='E')l[i]++;
    	if(a[j]=='W')r[j]++;
    	l[i]+=l[i-1];
    	r[j]+=r[j+1];
   
    }
    int best=1e9;
    for(int i=0;i<n;i++){
    		
        int value=(n-(l[i]+r[i]));
//	cerr<<l[i]<<" "<<r[i]<<" "<<value<<endl;

    	best=min(best,value);
    }
    cout<<best<<endl;

	
   	







}

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

#define PB              push_back
#define EB              emplace_back
#define MP              make_pair
#define F               first
#define S               second
#define all(a)          (a).begin(),(a).end()
#define sz(x)           (ll)(x).size()
#define IOS             ios::sync_with_stdio(false);cin.tie(NULL)
#define IN_REP          int tt; cin >> tt; while(tt--)
#define sim             template<class T
#define ris 			return * this
#define dor 			> debug & operator <<
#define eni(x) 			sim > typename enable_if<sizeof dud<T>(0) x 1, debug&>::type operator<<(T i)
sim > struct rge { T b, e; };
sim > rge<T> range(T i, T j) { return rge<T>{i, j}; }
sim > auto dud(T* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
  ~debug() { cerr << endl; }
	eni(!=) { cerr << boolalpha << i; ris;}
	eni(==) { ris << range(begin(i), end(i)); }
	sim, class U dor(pair<U,T> d) { ris << "(" << d.first << ", " << d.second << ")"; }
	sim dor(rge<T> d) {
		*this << "[";
		for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it;
		ris << "]";
	}
#else
  sim dor(const T&) { ris; }
#endif
};
#define pr(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;

const ld eps = (ld) 1e-9;
const ll MOD = (ll) 1e9 + 7;
const ld PI = acos(-1);
const int N = (int) 5e5 + 5;

sim>T gcd(T x, T y) {return (y==0) ? x : gcd(y, x % y);}
sim>void mini(T &a, T b) { a = min(a, b); }
sim>void maxi(T &a, T b) { a = max(a, b); }
sim>T mul(T x, T y) {return (x * y) % MOD;}
sim>inline T power(T a, T b) {T res = 1;while (b > 0) {if (b&1) { res = mul(res, a); }a = mul(a, a);b >>= 1;}return res%MOD;}
sim>inline T modInverse(T n) { return power(n, MOD - 2, MOD) % MOD; }
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
sim, class U>string to_string(pair<T, U> p) {return to_string(p.F) + " " + to_string(p.S);}


vi g[N];
ll ans[N];

void dfs(int v, int p){
    for(auto to : g[v]){
        if(to == p) continue;
        ans[to] += ans[v];
        dfs(to, v);
    }
}

int main(int argc, char** argv){
    IOS;
    int n ,q ;
    cin >> n >> q;
    for(int i = 1; i < n; ++i){
        int u , v;
        cin >> u >> v;
        g[u].PB(v);
        g[v].PB(u);
    }
    while(q--){
        int i , x;
        cin >> i >> x;
        ans[i] += x;
    }
    dfs(1,1);
    for(int i = 1; i <= n; ++i){
        cout << ans[i] << " " ;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 33152
#include<bits/stdc++.h>
using namespace std;
 
#define       pb(a)             push_back((a))
#define       mp(a,b)           make_pair((a),(b))
#define       REP(a,b)          for(ll i=(a);i<(b);i++)
#define       REP2(a,b)         for(ll j=(a);j<(b);j++)
#define       REPE(a,b,c,d)     REP(a,b)for(ll j=(c);j<(d);j++)
#define       REPV(a,b,c)       for(ll (a)=b;(a)<(c);(a)++)
#define       IREP(a,b)         for(ll i=(a);i>=(b);i--)
#define       IREP2(a,b)        for(ll j=(a);j>=(b);j--)
#define       IREPV(a,b,c)      for(ll (a)=b;(a)>=(c);(a)--)
#define       all(v)            (v).begin(),(v).end()
#define       Trvs(c)           for (auto it = (c).begin(); it != (c).end(); it++)
#define       INF               INT_MAX
#define       sz(x)             x.size()
#define       flash             ios_base::sync_with_stdio(false);cin.tie(NULL);
#define       F                 first
#define       S                 second
#define       MOD               1000000007
 
using         ll     = long long;
using         vi     = vector<int>;
using         vvi    = vector<vi>;
using         vll    = vector<ll>;
using         vvll   = vector<vll>;
using         vb     = vector<bool>;
using         vd     = vector<double>;
using         vs     = vector<string>;
using         pii    = pair<int, int>;
using         pll    = pair<ll, ll>;
using         pdd    = pair<double, double>;
using         vpii   = vector<pii>;
using         vvpii  = vector<vpii>;
using         vpll   = vector<pll>;
using         vvpll  = vector<vpll>;
using         vpdd   = vector<pdd>;
using         vvpdd  = vector<vpdd>;
 
 
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}

void solve(){
    ll a,b;
    cin>>a>>b;
    cout<<lcm(a,b);
}
 
 
int main(){
 
	flash
	/*
    #ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("output.txt","w",stderr);
	#endif
 	*/
   
	//ll t;cin>>t;while(t--)
	solve();
 
 
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

typedef vector<ll> vec;
typedef vector<vec> mat;
const ll MOD = 1000000007;
mat mul(mat &A, mat &B){
  mat C(A.size(), vec(B[0].size()));
  rep(i,A.size()) rep(k,B.size()){
    rep(j,B[0].size()){
      C[i][j] = (C[i][j]+A[i][k]*B[k][j])%MOD;
    }
  }
  return C;
}
mat pow(mat A, ll n){
  mat B(A.size(), vec(A.size()));
  rep(i,A.size()) B[i][i] = 1;
  while(n>0){
    if(n&1) B=mul(B,A);
    A=mul(A,A);
    n>>=1;
  }
  return B;
}
vector<ll> mulv(mat &A, vector<ll> v){
  vector<ll> ret = v;
  rep(i,v.size()){
    ll res = 0;
    rep(j,v.size()){ res += A[i][j]*v[j]; res = res%MOD; }
    ret[i] = res%MOD;
  }
  return ret;
}

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

  mat A(N, vec(N, 0));
  rep(i,N){
    rep(j,N){
      cin >> A[j][i];
    }
  }
  vec v(N, 1);
  mat B = pow(A, K);
  vec ret = mulv(B, v);

  ll sum = 0;
  rep(i,N){
    sum += ret[i];
    sum %= MOD;
  }
  
  cout << sum << endl;
  
  return 0;
}

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

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define CONTAINS(a, x) (a.find(x) != a.end())
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#define nl cout << endl
#define F first
#define S second

#define what_is(x) cout << #x << " = " << x << endl
#define boost ios::sync_with_stdio(false);cin.tie(NULL)
#define CASET int ___T, case_n = 1; cin >> ___T; while (___T-- > 0) 


#define rep(it, st, en) for(ll it = st; it < en; it++)
#define rep1(it, st, en) for(ll it = st; it <= en; it++)
#define per(it, st, en) for(ll it = en - 1; it >= st; it--)

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll,ll> pll;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<ii> vii;
typedef vector<vi> vvi;

ll INF = 1E9;
ll M = 1E9 + 7;

inline ll max_(ll a, ll b) { return (a>b)?a:b; }
inline ll min_(ll a, ll b) { return (a<b)?a:b; }

inline ll power (ll a,ll p){
    ll res = 1, x = a;
    while ( p ) {
        if ( p & 1 ) res = ( res * x );
        x = ( x * x ); p >>= 1;
    }
    return res;
}

template <typename T> ostream& operator<<(ostream& os, const vector<T> &p){os << "[ "; for (T x: p) os << x << " "; os << "]" << endl; return os;}
template <typename T> ostream& operator<<(ostream& os, const set<T> &p){os << "{ "; for (T x: p) os << x << " "; os << "}" << endl; return os;}
template <typename Tk, typename Tv> ostream& operator<<(ostream& os, const map<Tk, Tv> &p){os << "{ "; for (pair<Tk, Tv> x: p) os << x << " "; os << "}" << endl; return os;}
template <typename Tk, typename Tv> ostream& operator<<(ostream& os, const pair<Tk, Tv> &p){os << "{" << p.first << ',' << p.second << "}";return os;}

int main() {
    boost;
    if(fopen("inp.txt", "r")){
      freopen("inp.txt", "r", stdin);
      freopen("outp.txt", "w", stdout);
    }

    ll i;
    string s;
    cin>>s;

    for (i=0;i<s.length();i+=2)
        cout<<s[i];


    return 0;
}

Measured memory_bytes: 592
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

	long long power(long long x, long long n){
		long long ans = 1;
		for(;n;n >>= 1, x *= x, ans %= MOD, x %= MOD)
			if(n&1)ans*=x;
		return ans % MOD;
	}

signed main(){
	cout<<fixed<<setprecision(10);
	
	const int MAX = 2100;
	int N, K;
	int sum = 0;
	vector<int> A, con(MAX);
	
	cin>>N>>K;
	
	A.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>A[i];
		con[A[i]]++;
	}
	
	for(int i = 0; i < N; i++){
		
		for(int j = A[i]+1; j < MAX; j++){
			// cout<<"j = "<<j<<" con  "<<con[j]<<endl;
			sum += con[j] * (K - 1) %MOD* K %MOD * power(2,MOD-2);
			
			sum %= MOD;
		}
		
		for(int j = 0; j < i; j++){
			if(A[j] > A[i]) sum += K;
			
			sum %= MOD;
		}
		sum %= MOD;
		// cout<<sum<<endl;
	}
	
	cout<<sum<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(void){
 int num[100],i,x,n,p[100];
 for(i=0;i<100;i++){
   num[i]=0;
 }
 scanf("%d %d",&x,&n);
 for(i=0;i<n;i++){
   scanf("%d",&p[i]);
 }
 
 for(i=0;i<n;i++){
   if(x>p[i]){
     num[x-p[i]] += 1;
   }else if(x<p[i]){
     num[p[i]-x] += 2;
   }else{
     num[0] = 3;
   }
 }
 
 for(i=0;i<100;i++){
   if(num[i]!=3){
     if(i==0){
       printf("%d",x);
       break;
     }else if(num[i]==1){
       printf("%d",x+i);
       break;
     }else if(num[i]==2 || num[i]==0){
       printf("%d",x-i);
       break;
     }
   }
 }
 return 0; 
}


Measured memory_bytes: 1728
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    
    int n; cin >> n;
    string s; cin >> s;
    int cnt = 0;
    
    rep(i,n-2) if(s.substr(i,3)=="ABC") cnt++;

    cout << cnt << ln;
    return 0;
 }

Measured memory_bytes: 256