akhauriyash/Code-Regression huggingface dataset:
package main

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

func main() {
    var fp *os.File = os.Stdin
    reader := bufio.NewReaderSize(fp, 1024)

    _ = readLine(reader)
    S := readLine(reader)

    cnt := 0
    max := 0

    for _, s := range S {
        if s == 73 {
            cnt++

            if max < cnt {
                max = cnt
            }
        } else {
            cnt--
        }
    }

    fmt.Println(max)
}

func readLine(reader *bufio.Reader) string {
    buf := make([]byte, 0, 1024)

    for {
        l, p, _ := reader.ReadLine()

        buf = append(buf, l...)

        if !p {
            break
        }
    }

    return string(buf)
}

Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

int n, w, g, add;
long long ans = 0, sum[100005];

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

    for (int i = 1; i <= n; ++i) {
        cin >> g >> add;

        for (int i = w - g; i >= 0; --i) {
            sum[i + g] = max(sum[i] + add, sum[i + g]);

            ans = max(ans, sum[i + g]);
        }

    }

    cout << ans;
    return 0;
}


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

int main(){
	int N;
	int A[11];
	int cnt1=0;
	cin>>N;
	while(1){
		
		if(cnt1==N){
			break;
		}
		cnt1++;
		for(int i=1;i<=10;i++){
			cin>>A[i];
		}
		int B=A[1];
		int Z[11];
		for(int i=1;i<=10;i++){
			Z[i]=0;
		}
		int C=0;
		int cnt2=0;
		int su=0;
		for(int i=2;i<=10;i++){
			if((B+1==A[i])){
				B=A[i];
				cnt2++;
			}
			else if((C+1==A[i])){
				C=A[i];
				cnt2++;
				Z[i]=C;
				su=0;

			}
			else if(B<A[i]){
				B=A[i];
				
				cnt2++;

			}
			else if(C<A[i]){
				C=A[i];
				Z[i]=C;
				su=0;
				cnt2++;
			}
			for(int q=1;q<=10;q++){
				if(B+1==Z[q]){
					su=1;
				}
			}
			
		}
		if(cnt2==9){
			cout<<"YES"<<endl;
		}
		else{
			cout<<"NO"<<endl;
		}
	}
	return 0;	
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 1e5
#define INF 1<<30
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S;
ll ans = 0;
ll intceil(ll a, ll b) {
	return (a + (b - 1)) / b;
}
int main() {
	cin >> X >> Y >> Z >> K;
	vector<ll> A(X), B(Y), C(Z);
	for (int i = 0; i < X; i++)cin >> A[i];
	for (int i = 0; i < Y; i++)cin >> B[i];
	for (int i = 0; i < Z; i++)cin >> C[i];
	sort(A.rbegin(), A.rend());
	sort(B.rbegin(), B.rend());
	sort(C.rbegin(), C.rend());
	int a = 0, b = 0, c = 0;
	vector<ll> v = { 0,0,0 };
	pair<ll, vector<ll>> f = { A[0] + B[0] + C[0],v };
	priority_queue<pair<ll, vector<ll>>> pq;
	set<vector<ll>> set;
	pq.push(f);
	set.insert(f.second);
	int cnt = 0;
	while (cnt < K) {
		ll ans = pq.top().first;
		cout << ans << endl;
		cnt++;
		vector<ll> tmp = pq.top().second;
		//cout << tmp[0] << " " << tmp[1] << " " << tmp[2] << endl;
		pq.pop();
		tmp[0]++;
		if (tmp[0] < X) {
			if (set.count(tmp) == 0) {
				pq.push(make_pair(A[tmp[0]] + B[tmp[1]] + C[tmp[2]], tmp));
				set.insert(tmp);
			}
		}
		tmp[0]--;
		tmp[1]++;
		if (tmp[1] < Y) {
			if (set.count(tmp) == 0) {
				pq.push(make_pair(A[tmp[0]] + B[tmp[1]] + C[tmp[2]], tmp));
				set.insert(tmp);
			}
		}
		tmp[1]--;
		tmp[2]++;
		if (tmp[2] < Z) {
			if (set.count(tmp) == 0) {
				pq.push(make_pair(A[tmp[0]] + B[tmp[1]] + C[tmp[2]], tmp));
				set.insert(tmp);
			}
		}
	}
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  int INF = 100001;
  vector<int> A(INF, 0);
  for (int i=0; i<N; i++) {
    int a;
    cin >> a;
    if (a == 0) {
      A.at(0)++; A.at(1)++; 
    } else {
      A.at(a-1)++; A.at(a)++; A.at(a+1)++;
    }
  }
  
  sort(A.begin(), A.end(), greater<int>() );
  
  cout << A.at(0) << endl;
  
}

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

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

using ll = long long;
#define INF 1e9

int N, W;
vector<vector<int>> bg;

ll addbg(int a, int b, int c, int d){
  ll sum = 0;
  REP(i, a){
    sum += bg[0][i];
  }
  REP(i, b){
    sum += bg[1][i];
  }
  REP(i, c){
    sum += bg[2][i];
  }
  REP(i, d){
    sum += bg[3][i];
  }
  return sum;
}

int main(){
  cin >> N >> W;
  vector<ll> w(N), v(N);
  bg.resize(4);
  REP(i, N){
    cin >> w[i] >> v[i];
    bg[w[i]-w[0]].push_back(v[i]);
  }
  REP(i, 4){
    sort(bg[i].begin(), bg[i].end(), greater<int>());
  }
  ll ans = 0;
  REP(i, bg[0].size()+1){
    REP(j, bg[1].size()+1){
      REP(k, bg[2].size()+1){
        REP(l, bg[3].size()+1){
          ll weight = w[0]*i+(w[0]+1)*j+(w[0]+2)*k+(w[0]+3)*l;
          if(weight <= W){
            ans = max(ans, addbg(i, j, k, l));
          }
        }
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
x, y, z, k = gets.split.map(&:to_i)
A = gets.split.map(&:to_i).sort_by {|a| -a}
B = gets.split.map(&:to_i).sort_by {|b| -b}
C = gets.split.map(&:to_i).sort_by {|c| -c}

abc = []
0.upto(A.size - 1) do |a|
  0.upto(B.size - 1) do |b|
    if (a + 1) * (b + 1) > k
      break
    end
    0.upto(C.size - 1) do |c|
      if (a + 1) * (b + 1)  * (c + 1) > k
        break
      end

      abc << A[a] + B[b] + C[c]
    end
  end
end

abc = abc.sort_by {|a| -a}
0.upto(k-1) do |i|
  puts abc[i]
end


Measured memory_bytes: 6136
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

#define FOR(i,s,t) for(int i=s;i<t;i++)
#define REP(i,n) FOR(i,0,n)
#define PRINT(s) cout << s << "\n"
#define SORT(A) sort(A.begin(), A.end())
#define EACHPRINT(A, T) for_each(begin(A), end(A), [&](T i){ cout << i << " "; });cout << "\n"

typedef long lint;
typedef pair<lint, lint> P;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    lint N; cin >> N;
    lint M; cin >> M;

    lint res = N+M/2;
    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1000000010
#define N 100010
#define P 1000000007
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
int n,A,B,C,f[1000][1000],fac[N<<1],Inv[N<<1],ans;
int ksm(int a,int k)
{
	int s=1;
	for (;k;k>>=1,a=1ll*a*a%P) if (k&1) s=1ll*s*a%P;
	return s;
}
int inv(int a){return ksm(a,P-2);}
void inc(int &x,int y){x+=y;if (x>=P) x-=P;}
int calc(int n,int m){if (m>n) return 0;return 1ll*fac[n]*Inv[m]%P*Inv[n-m]%P;}
signed main()
{
	n=read(),A=read(),B=read(),C=read();A=1ll*A*inv(100-C)%P,B=1ll*B*inv(100-C)%P;
	fac[0]=1;for (int i=1;i<=2*n;i++) fac[i]=1ll*fac[i-1]*i%P;
	Inv[0]=Inv[1]=1;for (int i=2;i<=2*n;i++) Inv[i]=P-1ll*(P/i)*Inv[P%i]%P;
	for (int i=2;i<=2*n;i++) Inv[i]=1ll*Inv[i]*Inv[i-1]%P;
	for (int i=0;i<n;i++)
	{
		int p1=1ll*A%P*calc(n+i-1,n-1)%P*ksm(A,n-1)%P*ksm(B,i)%P;
		int p2=1ll*B%P*calc(n+i-1,n-1)%P*ksm(B,n-1)%P*ksm(A,i)%P;
		inc(ans,1ll*(n+i)*100%P*inv(100-C)%P*(p1+p2)%P);
	}
	cout<<ans;
	return 0;
	//NOTICE LONG LONG!!!!!
}
//f[i][j] 已经有i个A j个B 时 期望还要多少次结束  
//f[i][j]=100/(100-C)+f[i+1][j]*A/(A+B)+f[i][j+1]*B/(A+B)
//枚举结束时各自的数量
//平局期望数量可直接计算  
//考虑如何求该情况概率 
//前n+i-1场 A赢了n-1场的概率 

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
// using namespace __gnu_pbds;
// template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;



#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define in insert
#define ld long double


#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =998244353;
const ll MAX_NODES =200001;
const ll MAX_LOG =50;
const ll maxn = 3000000+10;
#define endl '\n'
#define int ll
ll power(ll x, ll n) {
	ll res = 1;
	for (; n > 0; n >>= 1) {
	if (n & 1) res = (res * x) % mod;
	x = (x * x) % mod;
	}
	return res;
}
const int ALPHA = 26;
vector<vector<int>> trie;
bool dfs(int u)
{	
	bool check =0;
	for(int i= 0;i<26;i++)
	{
		if(trie[u][i]!=-1)
		{	
			
			bool k = (!(dfs(trie[u][i])));
			check|=k;
		}
	}
	return check;
}
bool dfs1(int u)
{	
	bool check =0;
	bool child = false;
	for(int i= 0;i<26;i++)
	{
		if(trie[u][i]!=-1)
		{	
			child = true;
			bool k = (!(dfs1(trie[u][i])));
			check|=k;
		}
	}
	if(!child)
		return true;
	return check;
}
int32_t main()
{   


    IOS 
	int n;
	cin>>n;
	int a[n];
	map<int,int> m;
	int ans = 0;
	for(int i  = 0;i<n;i++)
	{
		cin>>a[i];
		ans+=(m[a[i]]);
		m[a[i]]++;
	}
	for(int i = 0;i<n;i++)
	{
		cout<<ans-(m[a[i]]-1)<<endl;
	}
   
		
	  


    
	
    
    
   
     
       
    

 
}






Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    double goukei=0.0;
    int x[n],y[n];
    for(int i=1;i<=n;i++)cin >> x[i] >> y[i];

    vector<int>a(n);
    for(int i=0;i<n;i++)a[i]=i+1;
    do{
        for(int i=0;i<n-1;i++){
            double dx = x[a[i]]-x[a[i+1]];
            double dy = y[a[i]]-y[a[i+1]];
            goukei += pow(dx*dx+dy*dy,0.5);
        }
    }while(next_permutation(a.begin(),a.end()));
    int Factorial=1;
    for(int i=2;i<=n;i++)Factorial*=i;//ｎの階上を作ってる
    cout << fixed << setprecision(10) << goukei / Factorial << endl;
}

Measured memory_bytes: 384
require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
a,b,c = gets.chomp.split.map(&:to_i)
k = gets.chomp.to_i

k.times do |i|
  if a >= b
    b *= 2
  elsif b >= c
    c *= 2
  end
end

if a<b && b < c
  puts 'Yes'
else
  puts 'No'
end




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

char island[12][13];

int dfs(int i, int j){
  if(island[i][j] == '0' || i > 12 || j > 12)return 0;
  
  island[i][j] = '0';
  dfs(i + 1, j);
  if(j < 11)dfs(i, j + 1);
  if(j > 0)dfs(i, j - 1);
  return 1;
}

int solve(){
  int cnt = 0;
  for(int i = 0; i < 12; i++){
    for(int j = 0; j < 12; j++){
      if(island[i][j] == '1'){
        cnt++;
        dfs(i, j);
      }
    }
  }
  return cnt;
}

int main(){
  while(cin >> island[0]){
    for(int i = 1; i < 12; i++){
      cin >> island[i];
    }
    cout << solve() << endl;
  }
}

Measured memory_bytes: 1140
#include<iostream>
int main() {
	int a, b;
	std::cin >> a >> b;
	bool flag[3] = {};
	flag[a-1]++;
	flag[b-1]++;
	int ans;
	for (int i = 0; i < 3; i++)if (!flag[i])ans = i+1;
	printf("%d\n", ans);
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    int a[101],b[101],n,i,j=0;
    scanf("%d",&n);
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
        if(a[i]%2==0)
        {
            b[j]=a[i];
            j++;
        }
    }
    b[j]='\0';
    int f=1;
    i=0;
    while(b[i]!='\0')
    {
        if(b[i]%3==0||b[i]%5==0) i++;
        else
        {
            f=0;
            break;
        }
    }
    if(f==1) printf("APPROVED");
    else printf("DENIED");
    return 0;
}


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

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

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

	long long int min = 1000000;
	long long int max = -1000000;
	long long int sum = 0;

	for(int i=0; i<n; i++){
		if(numbers[i] < min) min = numbers[i];
		if(max < numbers[i]) max = numbers[i];
		sum += numbers[i];
	}

	cout << min << " " << max << " " << sum << endl;
	//printf("%ld %ld %ld", min, max, sum);

	return 0;
}

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++)
        cin >> a[i];

    ll ans = 0;
    for(int i = 0; i < n-1; i++) {
        ans += max(0LL, a[i]-a[i+1]);
        a[i+1] = max(a[i+1], a[i]);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 4780
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////

const ll mod = 1e9+7;

int main() {
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];

    vector<ll> sum(n+1);
    sum[0] = 0;
    rep(i,n) sum[i+1] = (sum[i]+a[i]);

    ll ans = 0;
    rep(i,n) {
        ans += (a[i]%mod)*((sum[n]-sum[i+1])%mod);
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6368
#include<iostream>
using namespace std;
int main(){
	double a,b;
	cin>>a>>b;
	if(a<b){
		cout<<"a < b\n";
	}else if(a==b){
		cout<<"a == b\n";
	}else{
		cout<<"a > b\n";
	}
	return 0;
}


Measured memory_bytes: 3088
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

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


	ll kotae = 0;
	char c = '<';
	int kazu1 = -1, kazu2 = 0;
	while (c >= '<') {
		kazu1++;
		while ((c = getchar_unlocked()) == '<') kazu1++;
		if (c == '>') kazu2++;
		while ((c = getchar_unlocked()) == '>') kazu2++;
		if (kazu1 > kazu2) swap(kazu1, kazu2);
		kazu1--;
		kotae += ((ll)kazu1 * (kazu1 + 1) + (ll)kazu2 * (kazu2 + 1)) >> 1;
		kazu1 = 0;
		kazu2 = 0;
	}

	printf("%lld", kotae);

	Would you please return 0;
}

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

namespace Atc_0028
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();

            Int64 a = Int64.Parse(str.Split(' ')[0]);
            Int64 b = Int64.Parse(str.Split(' ')[1]);
            Int64 c = Int64.Parse(str.Split(' ')[2]);
            Int64 d = Int64.Parse(str.Split(' ')[3]);

            Int64 result = a * c;

            if (result <= (a * d))
            {
                result = a * d;
            }

            if (result <= (b * c))
            {
                result = b * c;
            }


            if (result <= (b * d))
            {
                result = b * d;
            }

            Console.WriteLine(result);

        }
    }
}


Measured memory_bytes: 27528
#include <iostream>
#include <string>
#include <algorithm>
int main() {
    std::string s, op;
    std::cin >> s;
    int q;
    std::cin >> q; // skip
    int a, b;
    while (std::cin >> op >> a >> b) {
        if (op == "print") {
            std::cout << s.substr(a, b - a + 1) << std::endl;
        } else if (op == "reverse") {
            std::reverse(s.begin() + a, s.begin() + b + 1);
        } else {
            std::string p;
            std::cin >> p;
            s.replace(a, b - a + 1, p);
        }
    }
}



Measured memory_bytes: 3232
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,f,g,h,x,y;
	scanf("%d %d %d %d %d %d %d %d",&a,&b,&c,&d,&e,&f,&g,&h);
	x=a+b+c+d;
	y=e+f+g+h;
	if(x>y){
		printf("%d\n",x);
	}
	else if(x=y){
		printf("%d\n",x=y);
	}
	else if(x<y){
		printf("%d\n",y);
	}
	return 0;
}

Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n;
  ll ans=1;
  cin >>n;
for(ll i=2;i<=n;i++){
  bool ok=true;
  for(ll j=2;j<=pow(i,0.5);j++){
    if(i%j==0)ok=false;
  }
  if(ok){
    ll count=0;
    for(ll j=2;j<=n;j++){
     ll s=j;
      while(s%i==0){
        s/=i;
      count++;
      }
    }
    ans=ans*(count+1)%1000000007;
  }
  cerr<<ans<<endl;
}
  cout <<ans <<endl;
}


Measured memory_bytes: 384
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
def lcm(a,b):
    return a*b//gcd(a,b)

n = int(input())
ans = 1
for i in range(n):
    ans = lcm(ans,int(input()))
print(ans)

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

typedef long long ll;
using namespace std;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

ll H, res;

int main() {
	cin >> H;
	while (H) {
		res = res * 2 + 1;
		H /= 2;
	}
	cout << res << endl;
}

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

const int vmax=100010;

int N,M;
struct node{ int to,cost;};
vector<node> graph[vmax];

int dist[vmax];

void dfs(int v,int p,int c){
	dist[v]=c;
	for(auto &e:graph[v]){
		if(e.to==p) continue;
		dfs(e.to,v,c+e.cost);
	}
}

int diameter() {
	dfs(0,-1,0);
	int root=max_element(dist,dist+N)-dist;
	dfs(root,-1,0);
	return *max_element(dist,dist+N);
}

int main(void){
	cin >> N;
	rep(i,N-1){
		int a,b,c;
		cin >> a >> b >> c;
		graph[a].push_back({b,c});
		graph[b].push_back({a,c});
	}
	cout << diameter() << endl;
	return 0;
}

Measured memory_bytes: 11748
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <math.h>
#include <array>
int a(void);
int b(void);

int main(void) {
	b();
	return 0;
}


int a(void) {
	int A1, A2, A3;
	std::cin >> A1 >> A2 >> A3;
	
	if (A1+A2+A3 >= 22) {

		std::cout << "bust";
	}
	else {
		std::cout << "win";
	}
	return 0;
}

int b(void) {
	std::string S;
	std::cin >> S;
	int len = S.length() / 2;
	
	int count = 0;
	for (int i = 0; i <len; i++) {
		if (S[i] != S[S.length() - i - 1]) {
			count++;
		}
	}
	std::cout << count;
	return 0;
}

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

int main(){
  lli N;
  cin >> N;
  vector<lli> max_n(5);
  for (int i = 0; i < 5; i++) {
    cin >> max_n.at(i);
  }
  lli min;
  min = *min_element(max_n.begin(), max_n.end());
  cout << setprecision(16) << ceil(N / double(min)) + 4 << endl;
}


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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

long long f(long long a, long long b);

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);

	long long int n;
	long long int x;

	cin >> n >> x;

	cout << n + f(n-x, x) << endl;

	return 0;
}

long long f(long long a, long long b){
	if(a > b){
		ll t;
		t = b;
		b = a;
		a = t;
	}
	
	if(b % a != 0){
		return 2*floor(b/a)*a + f(a, b%a);
	}else{
		return 2*b - a;
	}
}


Measured memory_bytes: 256
H, W, K = map(int, input().split())
MOD = 10**9 + 7

def check(bit):
  pre_b = '0'
  for b in bit:
    if b == '1' and pre_b == '1':
      return False
    pre_b = b
  return True

# dp[h][w]:上からh段目での操作を終了した時点でw番目のあみだにいる場合の数
dp = [[0]*(W+2) for h in range(H+1)]
dp[0][1] = 1

# ある段における横線の配置を全探索してw-1 <-> wに横線がある数
lines = [0] * (W+1)
c = 0
for i in range(2**(W-1)):
  if not check(bin(i)[2:]):
    continue
  c += 1
  for w in range(W-1):
    lines[w+1] += (i & 1<<w) > 0


# 配るDP
for h in range(H):
  for w in range(1, W+1):
    x, z = lines[w-1], lines[w]
    y = c - x - z
    dp[h+1][w-1] = (dp[h+1][w-1] + dp[h][w]*x % MOD) % MOD
    dp[h+1][w] = (dp[h+1][w] + dp[h][w]*y % MOD) % MOD
    dp[h+1][w+1] = (dp[h+1][w+1] + dp[h][w]*z % MOD) % MOD

print(dp[-1][K])

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

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

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n;
  cin >> n;

  for (int i = 0; i < n; i++) {
    string s, t;
    cin >> s;
    t = s;
    sort(s.begin(), s.end());
    sort(t.rbegin(), t.rend());
    cout << stoi(t) - stoi(s) << endl;
  }

  return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    };
}fastio;

int main(){


    int n;
    cin >> n;
    vector<ll> a(n), b(n), c(n);

    rep(i, n){
        cin >> a[i];
    }
    rep(i, n){
        cin >> b[i];
    }
    rep(i, n){
        cin >> c[i];
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());

    ll ans = 0ll;

    rep(i, n){
        ll anum = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
        ll cnum = n - (upper_bound(c.begin(), c.end(), b[i]) - c.begin());
        ans += anum*cnum;
    }
    ppp(ans);

    return 0;
}


Measured memory_bytes: 2560
#include "bits/stdc++.h"
#define all(x) x.begin(),x.end()
#define rep(i,N) for(int i=0;i<(int)N;++i)
using namespace std;
using ll = long long;
using vint = vector<int>;
using vll = vector<ll>;
using vll2 = vector<vector<ll>>;
const ll INF = (1LL << 30);
const ll LINF = (1LL << 60);
const ll MOD = 1e9 + 7;

int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   using P = pair<ll, ll>;

   ll W, H; cin >> W >> H;
   int N; cin >> N;
   vector<P> C(N);
   vll X(N), Y(N);
   rep(i, N) {
      cin >> X[i] >> Y[i];
      C[i] = P(X[i], Y[i]);
   }
   sort(all(X));
   sort(all(Y));

   auto f = [&](ll x, ll y) {
      ll res = 0, maxv = 0;
      rep(i, N) {
         ll sum = abs(x - C[i].first) + abs(y - C[i].second);
         maxv = max(maxv, sum);
         res += 2 * sum;
      }
      return res - maxv;
   };

   vll cx, cy;
   if (N % 2 == 0) {
      cx.emplace_back(X[N / 2 - 1]);
      cx.emplace_back(X[N / 2]);
      cy.emplace_back(Y[N / 2 - 1]);
      cy.emplace_back(Y[N / 2]);
   } else {
      cx.emplace_back(X[N / 2]);
      cy.emplace_back(Y[N / 2]);
   }

   ll ans = LINF;
   ll x, y;
   rep(i, cx.size()) rep(j, cy.size()) {
      ll res = f(cx[i], cy[j]);
      if (res < ans) {
         ans = res;
         x = cx[i], y = cy[j];
      }
   }

   cout << ans << endl;
   cout << x << " " << y << endl;
}


Measured memory_bytes: 6012
S = input()
N = len(S)
if N % 2 == 0:
    if S[N//2] != S[N//2-1]:
        print(N-N//2)
        exit()
    tmp = S[N//2]
    ans = N-N//2
    l = N//2-1
    r = N//2
    while S[l] == tmp and S[r] == tmp:
        ans += 1
        l -= 1
        r += 1
        if l < 0 or r > N-1:
            break
    print(ans)
else:
    tmp = S[N//2]
    ans = N-N//2-1
    l = N//2
    r = N//2
    while S[l] == tmp and S[r] == tmp:
        ans += 1
        l -= 1
        r += 1
        if l < 0 or r > N-1:
            break
    print(ans)


Measured memory_bytes: 3188
import Prelude hiding (getLine, getContents, words, lines)
import Data.ByteString.Char8 hiding (map)
import qualified Data.Vector as V
import Data.Vector ((!))
import Data.Maybe (fromJust)

readIntUnsafe :: ByteString -> Int
readIntUnsafe = fst . fromJust . readInt
timeDiff :: V.Vector Int -> ByteString -> Int
timeDiff v l = let [pI,xI] = map readIntUnsafe . words $ l
                   in xI - v ! (pI -1)

main = do
    _ <- getLine
    times <- V.fromList . map readIntUnsafe . words <$> getLine
    let normalTotal = V.sum times
    _ <- getLine
    getContents >>= mapM_ (print . (+ normalTotal) . timeDiff times ) . lines

Measured memory_bytes: 636
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<queue>
#include<list>
#include<stdio.h>
#include<stdlib.h>
#include<map>
#include<cstdio>
#include <iomanip>

#define rep(i,b) for(int i=0;i<b;i++)
#define rrep(i,a,b) for(int i=a;i<=b;i++)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

using namespace std;
typedef long long ll;

//差が最大になる区間を全て1減らすと、maxをとった結果が1下がる。
//前処理で区間ごとの最大値(最小値)を配列にいれる(公式解説)
//i<jにしか興味がないので、逐次更新する。解説ブログ等

int main() {

	//入力
	int n, t;
	cin >> n >> t;
	vector<int> a(n);
	for (auto& e : a) {
		cin >> e;
	}

	//ループ前の変数の初期化
	int max_diff = 0;
	int min_cost = 1<<30;
	int cnt = 0;

	//最小値の右しか関係ない。
	//その時々の最小値との差だけ考えればいい。

	//差が更新されたら、それ以前のカウントは意味がなくなるので
	//１からやりなおせばいい。

	//りんごの数は無制限なので、Tは実は使わくてもよい。

	for (int i = 0; i < n; ++i) {
		min_cost = min(min_cost, a[i]);
		int diff = a[i] - min_cost;
		if (max_diff < diff) {
			cnt = 1;
			max_diff = diff;
		}
		else if (diff == max_diff) {
			++cnt;
		}
	}
	cout << cnt << "\n";
}


Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    int n, x, t;
    cin >> n >> x >> t;
    cout << (n + x - 1) / x * t << endl;
    return 0;
}


Measured memory_bytes: 3632
from collections import deque, defaultdict
N, M = map(int, input().split())
D = defaultdict(list)
for i in range(M):
    s, t = map(int, input().split())
    D[s].append(t)
    D[t].append(s)

q = deque()
q.append(1)
d = defaultdict(lambda : float("inf"))
d[1] = 0
while q:
    u = q.popleft()
    for v in D[u]:
        if d[v] == float("inf"):
            d[v] = u
            q.append(v)

if len(d) == N:
    print("Yes")
else:
    print("No")
    exit()
for i in range(2, N+1):
    print(d[i])

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;

template<typename T>
static inline void chmin(T & ref, const T  value) {
    if (ref > value) ref = value;
}

template<typename T>
static inline void chmax(T & ref, const T value) {
    if (ref < value) ref = value;
}

const ll mod = 1000000007;

int main() {
    ll a, b, k;
    cin >> a >> b >> k;
    if (k <= a) {
        cout << a - k << " " << b << endl;
    }
    else {
        cout << 0 << " " << max(0LL, b - (k-a)) << endl;
    }
    return 0;
}



Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>

using namespace std;


int main(){
	queue<long long int>que;
	long long int n,a[200006],d,ireru[200006]={},count=0,mymax=-1,next=-1,wa=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		wa+=a[i];
		if(mymax<=a[i]){
			next=mymax;
			mymax=a[i];
		}else if(next<a[i]){
			next=a[i];
		}
	}
	for(int i=1;i<=n;i++){
		if(mymax==a[i])
		{
			cout<<next<<endl;
		}else
		{
			cout<<mymax<<endl;
		}
	}
}


Measured memory_bytes: 3200
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> 
#include <iomanip>
#include <unordered_map>
#include <memory.h>

using namespace std;

int main(void)
{
	int n;
	int t, a, b;
	int now = 0, x = 0, y = 0;
	bool possible = true;
	vector <vector<int>> v;
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> t >> a >> b;
		v.push_back({ t,a,b });
	}

	for (int i = 0; i < v.size(); i++)
	{
		int dt = v[i][0] - now;
		int diff = abs(v[i][1] - x) + abs(v[i][2] - y);
		if ((dt % 2 != diff % 2) || dt<diff)
		{
			possible = false;
			break;
		}
		now = v[i][0];
		x = v[i][1];
		y = v[i][2];
	}

	if (possible == true)
	{
		cout << "Yes" << '\n';
	}
	else
	{
		cout << "No" << '\n';
	}
	return 0;
}

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

int main() {
    string S;
    cin >> S;
    int N = S.length();

    for (int i = 0; i < (N - 1) / 2; i++)
    {
        if (S[i] != S[N - 1 - i] || S[i] != S[((N - 3) / 2) - i])
        {
            cout << "No" << endl;
            return 0;
        }
        
    }
    cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	vector<int> a(n);
	int sum=0;
	rep(i,n){
		cin>>a[i];
		sum+=a[i];
	}
	int cnt=0;
	rep(i,n){
		if(4*a[i]*m>=sum) cnt++;
	}
	if(cnt>=m) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(){
    int i;
    double n,D1=0,D2=0,D3=0,Dmax=0;
    double x[101],y[101];
    scanf("%lf",&n);
    for(i=0;i<n;i++){
        scanf("%lf",&x[i]);
    }
    for(i=0;i<n;i++){
        scanf("%lf",&y[i]);
    }
    for(i=0;i<n;i++){
        D1 += fabs(x[i]-y[i]);
        D2 += pow(fabs(x[i]-y[i]),2);
        D3 += pow(fabs(x[i]-y[i]),3);
        if(fabs(x[i]-y[i])>Dmax){
            Dmax=fabs(x[i]-y[i]);
        }
    }
    printf("%lf\n%lf\n%lf\n%lf\n",D1,pow(D2,0.5),pow(D3,0.333333333333),Dmax);
    return 0;
}


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

using namespace std;

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

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

#endif

void solve() {
    ll H, N;
    cin >> H >> N;
    vector<P> items(N);
    rep(i, N) cin >> items[i].first >> items[i].second;
    vector<ll> dp(H + 1, INF);
    dp[0] = 0;
    rep(i, H) {
        rep(j, N) {
            P p = items[j];
            dp[min(H, i + p.first)] = min(dp[min(H, i + p.first)], dp[i] + p.second);
        }
    }
    cout << dp[H] << '\n';
}

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


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define fill(x,v) memset(x, v, sizeof(x))
#define endl '\n' 
#define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 
#define IO freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
const ld eps=(ld)1e-9;
const ld PI=(ld)acos(-1.0);
const int inf=1e9+5;
const ll linf=1e18L+5;
const int mod=1e9+7;

void solve(){
	char a;
	cin>>a;
	set<char>s={'a','e','i','o','u'};
	if(s.count(a)){
		cout<<"vowel";
	}
	else cout<<"consonant";
}
int main(){fio;
int test=1;
// cin>>test;
while(test--){
	solve();
	cout<<endl;
}
return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MOD 1000000007

int n, X;
int num[233];
bool cmp(int a, int b){return a > b;}

int f[202][100010];

int C[202][202];
int S[202];

int main(){
	scanf("%d %d", &n, &X);
	for(int i = 1; i <= n; i++) scanf("%d", &num[i]);
	std::sort(num + 1, num + n + 1, cmp);
	C[0][0] = 1, S[0] = 1;
	for(int i = 1; i <= n; i++) S[i] = 1ll * S[i - 1] * i % MOD;
	for(int i = 1; i <= n; i++){
		C[i][0] = 1;
		for(int j = 1; j <= i; j++)
			C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD;
	}
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= i; j++)
			C[i][j] = 1ll * C[i][j] * S[j] % MOD;
	
	f[0][X] = 1;
	for(int i = 0, tmp; i <= n; i++){
		for(int j = 1; j <= X; j++){
			if(f[i][j] == 0) continue;
			for(int k = i + 1; k <= n; k++){
				tmp = j % num[k];
				f[k][tmp] = (f[k][tmp] + 1ll * f[i][j] * C[n - i - 1][k - i - 1]) % MOD;
			}
		}
	}
	
	int ans = 0;
	for(int i = 1; i <= X; i++)
		if(f[n][i] != 0) ans = (ans + 1ll * f[n][i] * i) % MOD;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 76160
#include <bits/stdc++.h>
#define int long long
using namespace std;

void print(const auto& v) {
    for (auto& x : v) {
        cerr << x << " ";
    }
    cerr << endl;
}
signed main() {
    string S;
    cin >> S;

    int N = S.size();

    vector<int> R(N);
    for (int i = 0, cnt = 0; i < N; i++) {
        if (S[i] == 'R') {
            cnt++;
        }
        else {
            R[i] += cnt / 2;
            R[i - 1] += max(0LL, cnt - R[i]);
            cnt = 0;
        }
        // print(R);
    }

    vector<int> L(N);
    for (int i = N - 1, cnt = 0; i >= 0; i--) {
        if (S[i] == 'L') {
            cnt++;
        }
        else {
            L[i] += cnt / 2;
            L[i + 1] += max(0LL, cnt - L[i]);
            cnt = 0;
        }
        // print(L);
    }

    for (int i = 0; i < N; i++) {
        cout << L[i] + R[i] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, n = N;
  cin >> N;
  
  for(int i = 0; i < N; i++){
    int A, a = 0;
    cin >> A;
    
    while(A % 2 == 0){
      a++;
      A /= 2;
    }
    
    if(n > a)
      n = a;
  }
  
  cout << n << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int m;
	static String input;
	static HashSet <String> set = new HashSet<String>();
	public static void main(String[] args) {
		while(read()){
			
		}
	}
	
	static boolean read(){
		if(!sc.hasNext())return false;
		m = sc.nextInt();
		for(int i = 0; i < m; i++){
			input = sc.next();
			solve();
		}
		return true;
	}
	
	static void solve(){
		for(int i = 1; i < input.length(); i++){
			String head = input.substring(0, i);
			String tail = input.substring(i);
			//System.out.println(head +" "+ tail);
			StringBuffer sh = new StringBuffer(head);
			StringBuffer st = new StringBuffer(tail);
			for(int j = 0; j < 2; j++){
				set.add(head + tail);
				set.add(head + st.reverse().toString());
				st.reverse();
				set.add(sh.reverse() + tail);
				sh.reverse();
				set.add(sh.reverse().toString() + st.reverse());
				sh.reverse();
				st.reverse();
				if(j == 0){
					StringBuffer sb = new StringBuffer(sh);
					String tmp = head;
					head = tail;
					tail = tmp;
					sh = st;
					st = sb;
				}
			}
		}
		System.out.println(set.size());
		String s = set.toString();
		//System.out.println(s);
		set.clear();
	}

}

Measured memory_bytes: 13000
n, m = map(int, input().split())

r = []
for _ in range(m):
    a, b = map(int, input().split())
    r.append([a, b-1])

r = sorted(r, key=lambda x: x[1])

current_end = r[0][1]
cnt = 1
for i in range(1, m):
    if not r[i][0] <= current_end <= r[i][1]:
        cnt += 1
        current_end = r[i][1]
print(cnt)

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


public class A
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public void Solve()
	{
		int N = GetInt();
		var data = new Tuple<int, int>[2 * N];
		for(int i = 0; i < N; i++)
			data[i] = Tuple.Create(0, GetInt());

		for(int i = 0; i < N; i++)
			data[N + i] = Tuple.Create(1, GetInt());

		Array.Sort(data, (x, y) => x.Item2 - y.Item2);

		long ans = 1;
		long mod = (long)(1e9 + 7);
		long[] cnt = new long[2];
		for(int i = 0, end = 2 * N; i < end; i++)
		{
			int type = data[i].Item1;
			if(cnt[type ^ 1] == 0)
			{
				cnt[type]++;
			}
			else
			{
				ans = (ans * cnt[type ^ 1]) % mod;
				cnt[type ^ 1]--;				
			}
		}

		Console.WriteLine(ans);
	}
}


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() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
	public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}


Measured memory_bytes: 25144
# coding: utf-8
import sys

stdin = sys.stdin
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))


def main():
    n,k = na()
    ps = na()
    ps.sort()
    print(sum(ps[:k]))
    return


if __name__ == '__main__':
    main()

Measured memory_bytes: 62268
N,U,V = map(int,input().split())
AB = [tuple(map(int,input().split())) for i in range(N-1)]
U,V = U-1,V-1

es = [[] for i in range(N)]
for a,b in AB:
    a,b = a-1,b-1
    es[a].append(b)
    es[b].append(a)

if len(es[U]) == 1 and es[U][0] == V:
    print(0)
    exit()

dv = [N] * N
dv[V] = 0
stack = [V]
while stack:
    v = stack.pop()
    for to in es[v]:
        if dv[to] != N: continue
        dv[to] = dv[v]+1
        stack.append(to)

ok = dv[U] - (dv[U]-1) // 2

visited = [0] * N
visited[U] = 1
stack = [U]
while stack:
    v = stack.pop()
    for to in es[v]:
        if visited[to]: continue
        if dv[to] < ok: continue
        visited[to] = 1
        stack.append(to)

mx = -1
for i in range(N):
    if not visited[i]: continue
    mx = max(mx, dv[i])
print(mx - 1)

Measured memory_bytes: 39376
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.System.arraycopy;
import static java.lang.System.exit;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static void solve() throws Exception {
		int tests = scanInt();
		test: for (int test = 0; test < tests; test++) {
			int n = scanInt();
			long a[] = new long[n];
			for (int i = 0; i < n; i++) {
				a[i] = scanLong();
			}
			String s = scanString();
			long sp[] = new long[n];
			int spLen = 0;
			for (int i = n - 1; i >= 0; i--) {
				long cur = a[i];
				for (int j = 0; j < spLen; j++) {
					if (Long.lowestOneBit(cur) == Long.lowestOneBit(sp[j])) {
						cur ^= sp[j];
					}
				}
				if (s.charAt(i) == '0') {
					if (cur != 0) {
						int j;
						for (j = 0; j < spLen && Long.lowestOneBit(sp[j]) < Long.lowestOneBit(cur); j++) { }
						arraycopy(sp, j, sp, j + 1, spLen - j);
						sp[j] = cur;
						++spLen;
					}
				} else {
					if (cur != 0) {
						out.println("1");
						continue test;
					}
				}
			}
			out.println("0");
		}
	}

	static int scanInt() throws IOException {
		return parseInt(scanString());
	}

	static long scanLong() throws IOException {
		return parseLong(scanString());
	}

	static String scanString() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	public static void main(String[] args) {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			exit(1);
		}
	}
}

Measured memory_bytes: 32992
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <math.h>
#include <utility>
#include <algorithm>
#include <functional>
#include <vector>
#include <numeric>
#include <bits/stdc++.h>

#define int long long

struct edge {
    int to;
    int cost;
};

using namespace std;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vb = vector<bool>;
using qi = queue<int>;
using P = pair<int, int>;
using graph = vector<vector<edge>>;

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

const int inf = 1LL << 60;
// const int inf = 100000000;
const int mod = 1000000007;

const int maxn = 100000;
int n, m, r;
// vii dist(maxn);
graph G(maxn);
vi mindist(maxn);

void dijkstra() {

    mindist.assign(n, inf);
    priority_queue<P, vector<P>, greater<P>> pq;
    mindist[r] = 0;
    pq.emplace(mindist[r], r);
    while (!pq.empty()) {
        P p = pq.top();
        pq.pop();
        int v = p.second;
        if (mindist[v] < p.first) continue;
        for (auto &e : G[v]) {
            if (mindist[e.to] > mindist[v] + e.cost) {
                mindist[e.to] = mindist[v] + e.cost;
                pq.emplace(mindist[e.to], e.to);
            }
        }
    }
}

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

    cin >> n >> m >> r;


    REP(i, m) {
        edge e;
        int s; cin >> s >> e.to >> e.cost;
        G[s].push_back(e);
        // dist[s][t] = d;
    }

    dijkstra();

    REP(i, n) {
        if (mindist[i] == inf) {
            cout << "INF\n";
        } else {
            cout << mindist[i] << "\n";
        }
    }
}



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

#define BTC_1 380000.0

using namespace std;

int main(int argc, char **argv) {
    int n;
    double sum = 0;
    double x;
    string u;

    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> x >> u;

        if (u == "JPY") {
            sum += x;
        }
        else if (u == "BTC") {
            sum += x * BTC_1;
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
//Reconstruction of a Tree

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define sc second
#define mp make_pair
typedef pair<int,int> pii;
#define MAX_N 40
pii g[MAX_N];
vector<int> p;

void f(vector<int> p,vector<int> m){
	vector<int> np[2],nm[2];
	int ind=0;
	for(int i=0;i<m.size();++i){
		if(p[0]==m[i]){
			++ind;
			continue;
		}
		nm[ind].pb(m[i]);
	}
	for(int i=1;i<=nm[0].size();++i) np[0].pb(p[i]);
	for(int i=nm[0].size()+1;i<p.size();++i) np[1].pb(p[i]);
	if(np[0].size()>0){
		g[p[0]].fi=np[0][0];
		f(np[0],nm[0]);
	}else g[p[0]].fi=-1;
	if(np[1].size()>0){
		g[p[0]].sc=np[1][0];
		f(np[1],nm[1]);
	}else g[p[0]].sc=-1;
}

void dfs(int u){
	int v=g[u].fi,w=g[u].sc;
	if(v>=0){
		dfs(v);
		cout<<v<<" ";
	}
	if(w>=0){
		dfs(w);
		cout<<w<<" ";
	}
}

int main(){
	int n;
	vector<int> m;
	cin>>n;
	for(int i=0;i<n;++i){
		int a;
		cin>>a;
		p.pb(a);
	}
	for(int i=0;i<n;++i){
		int a;
		cin>>a;
		m.pb(a);
	}
	f(p,m);
	dfs(p[0]);
	cout<<p[0]<<endl;
}

Measured memory_bytes: 3156