akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    public static void Main()
    {
        // Your code here!
        int N = int.Parse(Console.ReadLine());
        string S = Console.ReadLine();
        
        
        int max = 0;
        string alphabet = "abcdefghijklmnopqrstuvwxyz";
        
       for(int i = 1;i <= S.Length; i++)  //文字列を2つの配列に分割
       {
          
           int sum = 0;
           string X = S.Substring(0, i);
           string Y = S.Substring(i);
           foreach(char l in alphabet) //辞書は使わない
           {
               bool foundX = false;　　//あるかないかはtrue,falseを使う
               bool foundY = false;
               foreach(char x in X)
               {
                   if(x == l)
                   {
                       foundX = true;
                   }
               }
               foreach(char y in Y)
               {
                   if(y == l)
                   {
                       foundY = true;
                   }
               }
               if(foundX == true && foundY == true)
               {
                   sum++;
               }
           }
           if(sum > max)
           {
               max = sum;
           }
       }
       Console.WriteLine(max);
       
    }
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b; cin>>a>>b;
    if(b%a == 0){
        cout << a+b<<endl;
    }else{
        cout<<b-a<<endl;
    }
}

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

int main() {
    ll a;
    string b;
    cin >> a >> b;
    ll b2;
    b2 = (b[0]-'0')*100+(b[2]-'0')*10+(b[3]-'0');
    ll c = a*b2/100;
    cout << c << endl;
}

Measured memory_bytes: 3628
s = input()

def recursum(count, f, sum):
    if count == 3:
        if sum == 7:
            print(f+"=7")
            exit()
    else:
        recursum(count+1, f+"-"+s[count+1], sum-int(s[count+1]))
        recursum(count+1, f+"+"+s[count+1], sum+int(s[count+1]))

recursum(0,s[0], int(s[0]))


Measured memory_bytes: 9132
/*??????3-2*/
#include<stdio.h>
int main(void)
{
	int i,n;
	int number;
	long long int sum=0;
	int min=0;
	int max=0;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++)
	{
		scanf("%d",&number);
		
		if(i==0)
		{
			min = number;
			max = number;
		}
		if(number<min) min = number;
		if(number>max) max = number;
		
		sum += number;
	}
	
	printf("%d %d %lld\n",min,max,sum);
	
	return 0;
		
}

Measured memory_bytes: 1028
#include<iostream>
#include<algorithm>
#include<cmath>
using lint=long long;
using namespace std;

const int DGT=40;

lint N,K;
lint A[100010];

lint cnt[50][2];
lint Kbin[50];

lint calc(int n)
{
	lint ret=0;
	for(int i=0;i<40;i++)
	{
		lint cost[2]={};
		cost[0]=pow(2,i)*cnt[i][0];
		cost[1]=pow(2,i)*cnt[i][1];
		
		if(i<n && Kbin[n]==1)
			ret+=max(cost[0],cost[1]);
		else if(i==n)
			ret+=cost[0];
		else
		{
			if(Kbin[i]==1)
				ret+=max(cost[0],cost[1]);
			else
				ret+=cost[0];
		}
	}

	return ret;
}

int main()
{
	cin >> N >> K;
	for(int i=0;i<N;i++)
		cin >> A[i];
	
	for(int i=0;i<N;i++)
	{
		lint x=A[i];
		for(int j=0;j<=DGT;j++)
		{
			cnt[j][1-(x%2)]++;
			x/=2;
		}
	}
	
	for(int i=0;i<=DGT;i++)
	{
		Kbin[i]=K%2;
		K/=2;
	}

	lint ans=0;
	for(int i=0;i<=DGT;i++)
		ans=max(ans,calc(i));

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define mod 1000000007
#define endl "\n" 
#define p pair<int, int>
#define arrinp(i, a, start, end); for(ll i = start; i <= end; i++) cin >> a[i];
#define arrout(i, a, start, end); for(ll i = start; i <= end; i++) cout << a[i] << " ";
#define swap(a, b) {a = a + b; b = a - b; a = a - b;
#define forfront(i, start, end) for(ll i = start; i <= end; i++)
#define forback(i, start, end) for(ll i = start; i >= end; i--)
#define out(x) cout << x << " ";
#define outline(x) cout << x << endl;
#define sortvector(v) sort(v.begin(), v.end());
#define sortvectorrev(v) sort(v.rbegin(), v.rend());
#define inf INT64_MAX
int32_t main()
{
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int s;
    cin >> s;
    if(s <= 2)
    {
        outline(0)
        return 0;
    }
    vector<int> dp(s + 1, 0);
    dp[0] = 1;
    dp[1] = 0;
    dp[2] = 0;
    for(int i = 3; i <= s; i++)
    {
        for(int j = 3; j <= i; j++)
        {
            dp[i] += dp[i - j];
            dp[i] %= mod;
        }
    }
    // forfront(i, 3, s)
    // {
    //     out(dp[i])
    // }
    // cout << endl;
    outline(dp[s]);

    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <array>
#include <string>
using namespace std;

typedef long long int ll;

const ll MOD = 1e9 + 7;

ll fact(ll x){
	ll ans = 1;
	for(ll i=1; i<=x; i++)
		ans = (ans*i)%MOD;
	return ans;
}

int main(){
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll n, m;
	cin >> n >> m;
	if(abs(n-m) > 1)
		puts("0");
	else{
		if(n == m){
			ll ans = (fact(n)*fact(m))%MOD;
			cout << (ans<<1)%MOD;
		}
		else{
			ll ans = (fact(n)*fact(m))%MOD;
			cout << ans;
		}
	}
	return 0;
}

Measured memory_bytes: 3644
#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int long long i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 10000000000000007ll;

const double eps = 1e-10;

const i64 MAXN = 302;

i64 h, w, k;
char a[MAXN][MAXN];
i64 b[MAXN][MAXN];

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    cin >> h >> w >> k;

    for (i64 i = 1; i <= h; i++) {
        for (i64 j = 1; j <= w; j++) {
            cin >> a[i][j];
        }
    }


    vector<pair<pair<i64, i64>, pair<i64, i64>>> R;

    i64 t = 1;

    vector<pair<i64, i64>> lines;

    for (i64 i = 1; i <= h; i++) {
        bool meti = false;
        for (i64 j = 1; j <= w; j++) {
            if (a[i][j] == '#') {
                meti = true;
            }
        }
        if (meti) {
            lines.push_back({ t, i});
            t = i + 1;
        }
    }

    if (t <= h) {
        lines.back().second = h;
    }

    vector<vector<pair<i64, i64>>> vr;

    for (auto line : lines) {
        vr.push_back(vector<pair<i64, i64>>());

        i64 l = 1;
        for (i64 i = line.first; i <= line.second; i++) {
            bool meti = false;
            for (i64 j = 1; j <= w; j++) {
                if (a[i][j] == '#') {
                    meti = true;
                    vr.back().push_back({ l, j });
                    l = j + 1;
                }
            }
            if (meti) {
                break;
            }
        }
        if (l <= w) {
            vr.back().back().second = w;
        }
    }

    i64 cnt = 1;
    for (i64 i = 0; i < lines.size(); i++) {
        for (i64 j = 0; j < vr[i].size(); j++) {
            for (i64 ti = lines[i].first; ti <= lines[i].second; ti++) {
                for (i64 tj = vr[i][j].first; tj <= vr[i][j].second; tj++) {
                    b[ti][tj] = cnt;
                }
            }
            cnt++;
        }
    }

    stringstream ss;
    for (i64 i = 1; i <= h; i++) {
        for (i64 j = 1; j <= w; j++) {
            ss << b[i][j] << " ";
        }
        ss << endl;
    }
    cout << ss.str();

    return 0;
}

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

void MAIN() {
    int n;
    scanf("%d", &n);
    std::vector<int> arr(n);
    for(int &now: arr) {
        scanf("%d", &now);
        -- now;
    }
    std::sort(arr.begin(), arr.end(), std::greater<int>());
    int pos = 0;
    while(pos + 1 < n && pos + 1 <= arr[pos + 1]) {
        ++ pos;
    }
    int d = arr[pos] - pos;
    int e = 0;
    for(int i = pos + 1; i < n; ++ i) {
        if(arr[i] >= pos) {
            ++ e;
        }
    }
    puts((d %2 != 0 || e %2 != 0) ? "First" : "Second");

}

int main() {
    MAIN();
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main() {
    string a, b;
    cin >> a >> b;
    int n = stoi(a + b);

    cout << (pow(floor(sqrt(n)), 2) == n ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
(n,k,*h),*a=$<.map{|s|s.split.map &:to_i}
x=s=0
v=[9e9]*n
p a.sort_by{|t,d|-d}.map{|t,d|h[t]=s+=(0>k-=1)?h[t]?0:d-v.pop+x+x+=1:h[t]?(v<<d;d):d+x+x+=1}.max

Measured memory_bytes: 15040
K, N = gets.split.map(&:to_i)
A = gets.split.map(&:to_i).sort

list = []

(0..N-1).each do |i|
  if i < N-1
    list << A[i + 1] - A[i]
  else
    list << K - A[i] + A[0]
  end
end

ans = K - list.max
puts ans

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

int main(void){
	
	long long a, b;

	std::cin >> a >> b;

	if (a <= b) {
		std::cout << a << std::endl;
	}
	else {
		std::cout << a - 1 << std::endl;
	}


	return 0;
}

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

int main() {
    int N,M;
    cin>>N>>M;
    vector<int> H(N);
    int A[M],B[M];
    int ans=0;
    for(int i=0;i<N;i++){
        cin>>H[i];
    }
    for(int i=0;i<M;i++){
        cin>>A[i]>>B[i];
    }
    vector<pair<int,int>> road(M);
    for(int i=0;i<M;i++){
        if(A[i]<B[i]){
        road[i].first=A[i];
        road[i].second=B[i];
        }
        else{
            road[i].first=B[i];
            road[i].second=A[i];
        }        
    }
    vector<int> judge(N,1);
    for(int i=0;i<M;i++){
        if(H.at(road[i].first-1)<H.at(road[i].second-1)){
            judge.at(road[i].first-1)=0;
        }
        else if(H.at(road[i].first-1)==H.at(road[i].second-1)){
            judge.at(road[i].first-1)=0;
            judge.at(road[i].second-1)=0;
        }
    }
    for(int i=0;i<N;i++){
        if(judge[i]) ans++;
    }
    cout<<ans<<endl;
} */

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

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> h(100005);
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    vector<vector<int>> G(100005,vector<int>(0));
    set<pair<int,int>> data;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        if(a<b){
            data.insert(make_pair(a-1,b-1)); 
        }
        else{
            data.insert(make_pair(b-1,a-1)); 
        }      
    }
    for(auto p:data){
        G[p.first].emplace_back(p.second);
        G[p.second].emplace_back(p.first);
    }

    int ans=0;
    for(int i=0;i<n;i++){
        bool judge=true;
        for(int j=0;j<(int)G[i].size();j++){
            if(h[i]<=h[G[i][j]]){
                judge=false;
            }
        }
        if(judge){
            ans++;
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 13540
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let n = read::<i64>();
    let mut v:Vec<i64> = vec![];
    for _ in 0..n{
        v.push(read::<i64>());
    }
    let max_v = v.iter().max().unwrap();
    let sum:i64 = v.iter().sum();
    let ans = sum - max_v + (max_v/2);
    println!("{}",ans);
}

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

int x;

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

	cin >> x;
	for (int i = 1;; i++) {
		if (i * (i+1) / 2 >= x) {
			cout << i << '\n';
			return 0;
		}
	}

    return 0;
}

Measured memory_bytes: 256
//object A {
object Main {
  import InOut._
  def main(args: Array[String]): Unit = {

    val s = nextLine
    val res = s match {
      case "SSS" => 0
      case "RRS" | "SRR" => 2
      case "RSS" | "SRS" | "SSR" | "RSR" => 1
      case "RRR" => 3
    }

    out.println(res)

    out.flush()
  }
 
  final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _
    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }
    def nextInt = Integer.parseInt(nextToken)
    def nextLong = java.lang.Long.parseLong(nextToken)
    def nextBig = BigInt(nextToken)
    def nextInts(n: Int) = Array.fill(n) { nextInt }
    def nextLongs(n: Int) = Array.fill(n) { nextLong }
    def nextBigs(n: Int) = Array.fill(n) { nextBig }
    def nextLine = in.readLine
  }
}


Measured memory_bytes: 54616
#include<bits/stdc++.h>
using namespace std;
#define M_PI 3.1415926535
#define ll unsigned long long
#define ld long double
#define all(a) (a.begin(),a.end())
#define Summon_Tourist ios::sync_with_stdio(false);cin.tie(0);
ll gcd(ll a , ll b) { return b==0?a: gcd( b, a%b); }
ll lcm(ll a , ll b) { return a/gcd(a,b) * b ; }
ll inf = 998244353;
ll modexp( ll base ,ll power)
 {
     if( power == 0  ) return 1;
     if( power & 1) return base*modexp( base , power-1 )%inf;
     return modexp(base*base%inf,power/2);
 }
 ll a,b,c,d ;
 map<ll,ll> mp;
 ll solve(ll n)
 {
     if( n==0 ) return 0 ;
     if( n==1 ) return d ;
     if( mp.count(n) ) return mp[n];
     ll l1 = (n/2)*2;
     ll l2 = ((n+1)/2)*2 ;
     ll r1 = (n/3)*3;
     ll r2 =  ((n+2)/3)*3 ;
     ll s2 = ((n+4)/5)*5 ;
     ll s1 = (n/5)*5 ;
     ll res = 1e18 ;
     if( n < res/d ) res = n*d ;
     res = min( res, llabs(n-l1)*d + a + solve(l1/2)) ;
     res = min( res, llabs(n-l2)*d + a + solve(l2/2)) ;

     res = min( res, llabs(n-r1)*d + b + solve(r1/3)) ;
     res = min( res, llabs(n-r2)*d + b + solve(r2/3)) ;

     res = min( res, llabs(n-s1)*d + c + solve(s1/5)) ;
     res = min( res, llabs(n-s2)*d + c + solve(s2/5)) ;

     mp[n] = res ;
     return res ;
 }
 int main()
{
  Summon_Tourist
  //freopen("input.txt" , "r" , stdin ) ;
  ll t = 1 ;
  cin>>t ;
  while(t--)
  {
    ll n;
    cin>>n>>a>>b>>c>>d;
    mp.clear();
    ll ans  = solve(n);
    cout<<ans<<endl;
  }
  return 0;
  }


Measured memory_bytes: 4388
#include<stdio.h>
#include<math.h>

int main(void)
{
    double x1, y1, x2, y2;
    scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
    printf("%lf\n", sqrt( pow(x1-x2, 2.0) + pow(y1-y2, 2.0)) );
}


Measured memory_bytes: 2100
#include<iostream>

using namespace std;

int main(){
  int a,b,c,d,e,k;
  cin>>a>>b>>c>>d>>e>>k;
  
  int ans = e - a;
  
  if(ans<=k){
    cout<<"Yay!"<<endl;
  }else{
    cout<<":("<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
//nani?
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
#define pi acos(-1);
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define f(i,a,b) for( int i = a; i < b ; i++ ) 
#define sor(a) sort( a.begin(), a.end() )
#define rsor(a) sort( a.rbegin(), a.rend() )
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
//#define inf 1LL<<62
typedef long long ll;
typedef double ld;
using namespace std;
const int inf=1e7;
const ll MOD=1e9+7;
const ll mod=998244353;
// ac cmtr;
const int MAX_N = 1e5+5;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << endl;}
 
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1<<" | ";
  __f(comma+1, args...);}
#else
#define trace(...)
#endif
//---------------------------


int main(){
    fastio;
    ll a,b,c;
    cin>>a>>b>>c;
    cout<<c<<" "<<a<<" "<<b<<endl;
}



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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(6);
    /*start*/
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    bool flg = false;
    for (ll i : a)
    {
        if (i == 0)
            flg = true;
    }
    if (flg)
    {
        c(0);
        return 0;
    }
    ll prod = 1;
    for (int i = 0; i < n; i++)
    {
        if (a[i] <= 1000000000000000000 / prod)
        {
            prod *= a[i];
        }
        else
        {
            c(-1);
            return 0;
        }
    }
    c(prod);
}


Measured memory_bytes: 3976
#include<bits/stdc++.h>
using namespace std;
int main()
{
  	int x , y;
  	cin >> x >> y ;
  	int c = ( 4 * x ) - y;
  	int t = y - ( 2 * x );
  	if( c < 0 || t < 0 || c % 2 || t % 2 ) cout << "No";
  	else cout << "Yes";
}

Measured memory_bytes: 3536
#include <stdio.h>
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second

using namespace std;
//using namespace __gnu_pbds;

//typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 1000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 31;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MAX_INT = (1 << 31) - 1;
const double eps = 1e-6;
const double pi = atan2(0, -1);

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("battleship.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //int TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n, a, b;
    cin >> n >> a >> b;
    int x[n];
    rep(i, 0, n)
        cin >> x[i];
    ll ans = 0;
    rep(i, 0, n - 1)
        ans += min((ll)(x[i + 1] - x[i]) * a, (ll)b);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
# -*- coding: utf-8 -*-

#----------
N = int(input().strip())
A_list = [list(map(int, input().rstrip().split())) for _ in range(2)]
#----------

count_list=[]
for i in range(N):  # 下移動するタイミング(N通り)
    count_list += [ sum(A_list[0][0:i+1]) + sum(A_list[1][i:]) ]

print( max(count_list) )


Measured memory_bytes: 2940
#include <iostream> 
#include <iomanip> 
#include <vector> 
#include <algorithm> 
#include <numeric> 
#include <functional> 
#include <cmath> 
#include <queue> 
#include <stack> 

#define Ford(i,a,b) for (int i=(a);i<(b);i++) 
#define For(i,n) repd(i,0,n) 
typedef long long ll; 

using namespace std;

int main(){
  int s;
  int a[10000],i=1;
  cin>>s;
  a[0]=s;
  while(1){
    if(s%2==0) s /=2;
    else s = 3*s +1;
    
    i++;
    a[i]=s;
    for(int j=0;j<i;j++){
      if (a[j]==s) {
        cout << i << endl;
        return 0;
      }
     }
    
    if(i>=10000) return 0;
  }
  
}


Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * a.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

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

  if (a == b + c || b == c + a || c == a + b) puts("Yes");
  else puts("No");
  return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#pragma warning(disable : 4996)
#define EVEN(x) (mu[x] == x || (mu[x] != x && phi[mu[x]] != mu[x]))
#define ODD(x)  (mu[x] != x && phi[mu[x]] == mu[x] && phi[x] != x)
#define OUTER(x) (mu[x] != x && phi[mu[x]] == mu[x] && phi[x] == x)
using namespace std;
typedef int Weight;
struct Edge {
	int src, dst; Weight weight;
	Edge(int src, int dst, Weight weight) : src(src), dst(dst), weight(weight) { }
};
bool operator<(const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
int maximumMatching(const Graph &g) {
	int n = g.size();
	vector<int> mu(n), phi(n), rho(n), scanned(n);
	for (int v = 0; v < n; v++) mu[v] = phi[v] = rho[v] = v;
	for (int x = -1; ; ) {
		if (x < 0) {
			for (x = 0; x < n && (scanned[x] || !EVEN(x)); ++x);
			if (x == n) break;
		}
		int y = -1;
		for (int e = 0; e < (int)g[x].size(); e++) if (OUTER(g[x][e].dst) || (EVEN(g[x][e].dst) && rho[g[x][e].dst] != rho[x])) y = g[x][e].dst;
		if (y == -1) scanned[x] = true, x = -1;
		else if (OUTER(y)) phi[y] = x;
		else {
			vector<int> dx(n, -2), dy(n, -2);
			for (int k = 0, w = x; dx[w] < 0; w = k % 2 ? mu[w] : phi[w]) dx[w] = k++;
			for (int k = 0, w = y; dy[w] < 0; w = k % 2 ? mu[w] : phi[w]) dy[w] = k++;
			bool vertex_disjoint = true;
			for (int v = 0; v < n; v++) if (dx[v] >= 0 && dy[v] > 0) vertex_disjoint = false;
			if (vertex_disjoint) {
				for (int v = 0; v < n; v++) if (dx[v] % 2) mu[phi[v]] = v, mu[v] = phi[v];
				for (int v = 0; v < n; v++) if (dy[v] % 2) mu[phi[v]] = v, mu[v] = phi[v];
				mu[x] = y; mu[y] = x; x = -1;
				for (int v = 0; v < n; v++) phi[v] = rho[v] = v, scanned[v] = false;
			}
			else {
				int r = x, d = n;
				for (int v = 0; v < n; v++) if (dx[v] >= 0 && dy[v] >= 0 && rho[v] == v && d > dx[v]) d = dx[v], r = v;
				for (int v = 0; v < n; v++) if (dx[v] <= d && dx[v] % 2 && rho[phi[v]] != r) phi[phi[v]] = v;
				for (int v = 0; v < n; v++) if (dy[v] <= d && dy[v] % 2 && rho[phi[v]] != r) phi[phi[v]] = v;
				if (rho[x] != r) phi[x] = y;
				if (rho[y] != r) phi[y] = x;
				for (int v = 0; v < n; v++) if (dx[rho[v]] >= 0 || dy[rho[v]] >= 0) rho[v] = r;
			}
		}
	}
	int ret = 0; for (int u = 0; u < n; u++) if (u < mu[u]) ret++;
	return ret;
}
int X, Y, E, x, y; Graph G;
int main() {
	scanf("%d%d%d", &X, &Y, &E); G.resize(X + Y);
	for (int i = 0; i < E; i++) {
		scanf("%d%d", &x, &y);
		G[x].push_back(Edge(x, X + y, 1));
		G[X + y].push_back(Edge(X + y, x, 1));
	}
	printf("%d\n", maximumMatching(G));
}

Measured memory_bytes: 3284
module Main where

import           Control.Monad
import Control.Monad.Writer


newtype DiffList a = DiffList { getDiffList :: [a] -> [a] }  
toDiffList :: [a] -> DiffList a  
toDiffList xs = DiffList (xs++)  
  
fromDiffList :: DiffList a -> [a]  
fromDiffList (DiffList f) = f []  

instance Monoid (DiffList a) where  
    mempty = DiffList (\xs -> [] ++ xs)  
    (DiffList f) `mappend` (DiffList g) = DiffList (\xs -> f (g xs))  

main :: IO ()
main = do
    [h, _] <- (map read . words) <$> getLine
    list   <- map (map read . words) <$> (replicateM h) getLine
    let w=do
            res<-(sequence . map goRight . enumerate2d) list
            (goRight . map last) res
            return ()
    let (_,log)=runWriter w

    putStr
        $(unlines .((show . length .fromDiffList) log :) . map ((unwords . map show) . (\((a, b), (c, d)) -> [a, b, c, d])).fromDiffList)
        log

goRight
    :: [((Int, Int), Int)] -> Writer (DiffList ((Int, Int), (Int, Int))) [((Int, Int), Int)]
goRight []  = return []
goRight [x] = return [x]
goRight (a@(aPoint, aValue) : b@(bPoint, _) : xs) = do
    if even aValue then
        do
            res<-goRight (b : xs)
            return $ a:res
    else
        do
            res<-goRight (fmap (+ 1) b : xs)
            tell $ toDiffList [(aPoint, bPoint)]
            return $ fmap (subtract 1) a : res

enumerate :: [a] -> [(Int, a)]
enumerate = zip [1 ..]

enumerate2d :: [[a]] -> [[((Int, Int), a)]]
enumerate2d =
    (map (\(y, a) -> (map (\(x, b) -> ((y, x), b)) . enumerate) a) . enumerate)

    

Measured memory_bytes: 95356
#include <iostream>
using namespace std;
int main(){
	int yen,count=0;
	while(cin>>yen){
		if(yen==0) break;
		if(count!=0) cout<<endl;
		count++;
		int m10,m50,m100,m500;
		cin>>m10>>m50>>m100>>m500;
		int m=80,flg=1,d10,d50,d100,d500,o10,o50,o100,o500,otsuri;
		for(int a10=m10;a10>=0;a10--){
			for(int a50=m50;a50>=0;a50--){
				for(int a100=m100;a100>=0;a100--){
					for(int a500=m500;a500>=0;a500--){
						if(a10*10+a50*50+a100*100+a500*500>=yen){
							otsuri=a10*10+a50*50+a100*100+a500*500-yen;
							o500=otsuri/500;
							o100=(otsuri/100)%5;
							o50=(otsuri/50)%2;
							o10=(otsuri/10)%5;
							if(m500+m100+m50+m10-a500-a100-a50-a10+o500+o100+o50+o10<=m){
								m=m500+m100+m50+m10-a500-a100-a50-a10+o500+o100+o50+o10;
								d500=a500;
								d100=a100;
								d50=a50;
								d10=a10;
							}
						}
					}
				}
			}
		}
		if(d10!=0) cout<<10<<" "<<d10<<endl;
		if(d50!=0) cout<<50<<" "<<d50<<endl;
		if(d100!=0) cout<<100<<" "<<d100<<endl;
		if(d500!=0) cout<<500<<" "<<d500<<endl;
	}
    return 0;
}

Measured memory_bytes: 1164
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		boolean flag = true;
		char a = s.charAt(0);
		char b = s.charAt(0);
		int count = 0;
		for (int i = 0; i < s.length(); i++) {
			if (a == s.charAt(i)) {
				++count;
			}
			if (a == b && s.charAt(i) != b) {
				b = s.charAt(i);
			}
		}
		if (count != 2) {
			flag = false;
		}
		count = 0;
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == b) {
				++count;
			}
		}
		if (count != 2) {
			flag = false;
		}
		if (flag) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 21716
package main

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

type TupleInt struct {
	first  int
	second int
}

func main() {
	sc := NewScanner()
	A,B,C,D,E,k := sc.NextInt(),sc.NextInt(),sc.NextInt(),sc.NextInt(),sc.NextInt(),sc.NextInt()
	if abs(A-B) <= k &&
		abs(A-C)<= k &&
		abs(A-D)<= k &&
		abs(A-E)<= k &&
		abs(B-C)<= k &&
		abs(B-D)<= k &&
		abs(B-E)<= k &&
		abs(C-D)<= k &&
		abs(C-E)<= k &&
		abs(D-E)<= k {
		fmt.Println("Yay!")
	} else {
		fmt.Println(":(")
	}

}

func abs(a int ) int {
	if a < 0 {
		return -1*a
	}
	return a
}


func min(a int, b int) int {
	if a < b {
		return a
	}
	return b
}

func Max(a int, b int) int {
	if a < b {
		return b
	}
	return a
}

type SortInterFace []TupleInt

func (s SortInterFace) Len() int {
	return len(s)
}
func (s SortInterFace) Less(i, j int) bool {
	return s[i].first < s[j].first
}
func (s SortInterFace) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
import sys
import itertools

def main():
    input = sys.stdin.readline
    N, M, Q = map(int, input().split())
    data = range(1, M+1)
    A = list(itertools.combinations_with_replacement(range(1, M+1), N))
    l = []
    m = 0
    for _ in range(Q):
        a, b, c, d = map(int, input().split())
        l.append([a, b, c, d])
    for a_list in A:
        tmp = 0
        for i in l:
            if a_list[i[1] -1] - a_list[i[0] - 1] == i[2]:
                tmp += i[3]
        if tmp > m:
            m = tmp
    return m


if __name__ == '__main__':
    print(main())



Measured memory_bytes: 21612
import java.util.Scanner;

public class Main {
	public static Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		//A
		/*
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(b < a)
			System.out.println(a-1);
		else
			System.out.println(a);
			*/
		//B
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int k = sc.nextInt();
		for(int i = 0 ; i < k ; i++){
			int max = a;
			int max_index = 0;
			if(max < b){
				max = b;
				max_index = 1;
			}
			if(max < c){
				max = c;
				max_index = 2;
			}
			switch(max_index){
				case 0: a*=2;break;
				case 1: b*=2;break;
				case 2: c*=2;break;
			}
		}
		System.out.println(a+b+c);
		//C
		/*
		int h = sc.nextInt();
		int w = sc.nextInt();
		String[] s = new String[h];
		for(int i = 0 ; i < h ; i++){
			s[i] = sc.next();
		}
		boolean successflag = true;
		for(int i = 0 ; i < h ; i++){
			for(int j =0 ; j < w ; j++){
				boolean flag = false;
				if (s[i].charAt(j) == '#') {
					if (i > 0) {//上
						if (s[i - 1].charAt(j) == '#')
							flag = true;
					}
					if (i < h - 1) {//下
						if (s[i + 1].charAt(j) == '#')
							flag = true;
					}
					if (j > 0) {
						if (s[i].charAt(j - 1) == '#')
							flag = true;
					}
					if (j < w - 1) {
						if (s[i].charAt(j + 1) == '#')
							flag = true;
					}
					if (!flag)
						successflag = false;
				}
			}
		}
		if(successflag)
			System.out.println("Yes");
		else
			System.out.println("No");
			*/
	}
}


Measured memory_bytes: 20564
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

a,b =iim()
tb = 0
for i in range(1,b-a+1):
    tb += i
print(tb-b)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define mp make_pair
#define fi first
#define sd second
#define ll long long

using namespace std;

const int maxn = 3010;
const ll oo = 1e18;

ll x,y;
int res;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
   // freopen("in.txt","r",stdin);
    cin>>x>>y;
    res =0 ;
    while (1) {
        if (x<=y) res++;
        else break;
        x = 2*x;
    }
    cout<<res;

}


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

typedef long long int ll;
typedef unsigned long long ull;
typedef double db;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef map<int,int> MI;
typedef vector<vector<int,int>> VII;
typedef pair<int,pair<int,int>> PII;

#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define mp make_pair
#define repa(i,a,n) for(ll i=a;i<n;i++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define pera(i,a,n) for(ll i=a;i>=n;i--)
#define per(i,n) for(ll i=n;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define MS0(x) memset((x), 0, sizeof((x)))
#define MS1(x) memset((x), -1, sizeof((x)))
#define MEM(a, b) memset(a, b, sizeof(a))
#define SZ(x) ((ll)(x).size())
#define TIME    cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";

const ll mod=1e9+7;
const double pi=acos(-1);

ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
ll power(ll a,ll b,ll p) //log(n)
{
    if(b==0) return 1;
    ll c = power(a,b/2,p);
    if(b%2==0) return (c*c)%p;
    else return (((c*c)%p)*a)%p;
}
ll inv(ll n, ll p){ return power(n,p-2, p); }
bool isPrime(ll n) {
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (ll i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
            return false;
    return true;
}


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

    ll a,b,c,k,sum=0;
    cin>>a>>b>>c>>k;
    if(k>=a)
    {
        sum+=a;
        k-=a;
    }
    else
    {
        sum+=k;
        k=0;
    }
    if(k>=b) k-=b;
    else k-=k;
    if(k>0) sum-=k;
    cout<<sum;
    return 0;
}


Measured memory_bytes: 3652
/*author: hyperion_1724
  date: 
*/
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	

	int N,M;
	int l,r;
	cin>>N>>M>>l>>r;
	for (int i = 0; i < M-1; ++i)
	{
		int x,y;
		cin>>x>>y;
		l=max(x,l);
		r=min(r,y);
	}
	if(l>r)
	{
		cout<<0<<endl;
	}
	else
	{
		cout<<r-l+1<<endl;
	}
	

	return 0;
}

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

int main() {
    int n, cnt = 0, minv = 100000000;
    cin >> n;
    vector<int>p(n);
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
    }
    
    for (int i = 0; i < n; i++)
    {
        minv = min(p[i], minv);
        if (minv == p[i]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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

string s;

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

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

int main() {
    int N;
    string S;
    cin >> N >> S;
    vector<int> B(N), W(N);
    for (int i = 0; i < N; i++) {
        if (S[i] == '#') B[i]++;
        if (S[i] == '.') W[i]++;
    }

    for (int i = 1; i < N; i++) {
        B[i] += B[i - 1];
        W[i] += W[i - 1];
    }

    int res = 1000000000;
    for (int i = 0; i < N; i++) {
        int b = B[i];
        int w = W[N - 1] - W[i];

        res = min(res, b + w);
    }

    res = min(res, B[N - 1]);
    res = min(res, W[N - 1]);

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 2180
#include <iostream>
using namespace std;
long long n, ans, cnt, mi=1, a[1005], s[2], x[505], y[505], z;
int main() {
	int i, j;
	cin>>n;
	for(i=1; i<=n; i++) {
		cin>>a[i];
		s[i%2] += max(a[i], 0LL);
		if(a[i]>a[mi]) mi=i;
	}
	for(i=s[1]>s[0]; i<=n; i+=2) if(a[i]>0) {
		x[++z] = i;
		if(z>1) cnt += y[z-1] = (x[z] - x[z-1]) / 2;
	}
	if(z) {
		ans = max(s[0], s[1]);
		cnt += x[1]-1 + n-x[z];
	} else {
		ans = a[mi];
		cnt = n-1;
		x[++z] = mi;
	}
	cout<<ans<<endl<<cnt<<endl;
	for(i=n; i>x[z]; i--) cout<<i<<endl;
	for(i=1; i<x[1]; i++) cout<<1<<endl;
	for(i=1; i<z; i++) for(j=y[i]; j; j--) cout<<j+1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)


int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
    }
    vector<ll> s(3);
    ll res = 1;
    rep(i,n){
        ll p = 0;
        rep(j,3){
            if(s[j]==a[i]){
                p++;
            }
        }
        res *= p;
        res %= mod;
        rep(j,3){
            if(s[j]==a[i]){
                s[j]++;
                break;
            }
        }
        sort(s.begin(),s.end());
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int n;
int power(int k)
{
	int ans=1;
	for(int i=1;i<=k;i++)ans*=10;
	return ans;
}
int main()
{
	scanf("%d",&n);
	int m=n,sum=0;
	while(m)sum++,m/=10;
	int ans=0;
	for(int i=1;i<=sum;i++)
		if(i%2==0)ans+=power(i-2)*9;
	if(sum%2==1)ans+=n-power(sum-1)+1;
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;

const int mod = 1e9 + 7;
int N, M;
vector< pair< int, int > > ev[300];
int dp[301][301][301];

bool check(int r, int g, int b)
{
  for(auto &e : ev[max({r, g, b})]) {
    int sz = 0;
    sz += e.first <= r;
    sz += e.first <= g;
    sz += e.first <= b;
    if(sz != e.second) return (false);
  }
  return (true);
}

int rec(int r, int g, int b)
{
  int &ret = dp[r + 1][g + 1][b + 1];
  int nxt = max({r, g, b}) + 1;
  if(~ret) return (ret);
  if(nxt == N) return (ret = 1);
  ret = 0;
  if(check(nxt, g, b)) (ret += rec(nxt, g, b)) %= mod;
  if(check(r, nxt, b)) (ret += rec(r, nxt, b)) %= mod;
  if(check(r, g, nxt)) (ret += rec(r, g, nxt)) %= mod;
  return (ret);
}

int main()
{
  cin >> N >> M;
  for(int i = 0; i < M; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    --a, --b;
    ev[b].emplace_back(a, c);
  }
  memset(dp, -1, sizeof(dp));
  cout << rec(-1, -1, -1) << endl;
}


Measured memory_bytes: 106752
# coding: utf-8

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def dfs(v, p = -1):
    deg[v] = len(U[v])
    dp[v] = [0] * deg[v]
    ans = 1
    for i in range(deg[v]):
        u = U[v][i]
        if u == p:
            par[v] = i
            continue
        dp[v][i] = dfs(u, v)
        ans *= dp[v][i] + 1
        ans %= M
    return(ans)

def bfs(v, ans_p = 0, p = -1):
    if p != -1:
        dp[v][par[v]] = ans_p
    lmul = [1] * (deg[v] + 1)
    rmul = [1] * (deg[v] + 1)
    for i in range(1, deg[v] + 1):
        lmul[i] = lmul[i - 1] * (dp[v][i - 1] + 1) % M
        rmul[-i - 1] = rmul[-i] * (dp[v][-i] + 1) % M
    ans[v] = rmul[0]
    for i in range(deg[v]):
        u = U[v][i]
        if u == p:
            continue
        bfs(u, lmul[i] * rmul[i + 1] % M, v)

N, M = map(int, input().split()) # 1 <= N <= 10^5, 2 <= M <= 10^9
U = [list() for _ in range(N)]
for x, y in [map(int, input().split()) for _ in range(N - 1)]:
    U[x - 1].append(y - 1)
    U[y - 1].append(x - 1)
deg = [0] * N
par = [0] * N
dp = [None] * N
ans = [0] * N
dfs(0)
bfs(0)
print("\n".join([str(x) for x in ans]))


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

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1e9+7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

template<class T>
inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template<class T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
///////////////////////////////////////////////
/*🍈( '-'  🍈*/

int main(){
	int X,A;
	cin >> X >> A;
	if (X < A) cout << 0 << endl;
	else cout << 10 << endl;


	return 0;
}


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

int main(){
  int n;
  double t, a;
  cin >> n >> t >> a;
  vector<int> h(n);
  for(int i = 0; i < n; i++) cin >> h[i];
  double min = 100000;
  int min_index = 0;
  for(int i = 0; i < n; i++){
    double ans = abs((t - h[i] * 0.006) - a);
    if(ans < min){
      min = ans;
      min_index = i + 1;
    }
  }
  cout << min_index << endl;
  return 0;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n,m;
  cin >> n;
  ll a[n];
  rep(i,n) R a[i];
  ll M=-1,ans=0;
  rep(i,n) {
    if(M<=a[i]) ans++;
    M=max(M,a[i]);
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
 
int main(){
	long long int q,h,s,d;
	cin>>q>>h>>s>>d;
	long long int n;
	cin>>n;
	
	long long int a,b,c,e;
	a=q*4*n;
	b=h*2*n;
	c=s*n;
	if(n%2==0){
		e=d*(n/2);
	}else{
		long long int n2=n/2+1;
		e=min((n2-1)*d+4*q,min((n2-1)*d+2*h,(n2-1)*d+s));
	}
	
	long long int ans=min(a,min(b,min(c,e)));
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque
import numpy as np
import math
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def solve():
    f = math.ceil(n/1.08)
    if math.floor(f*1.08)==n:
        print(f)
    else:
        print(':(')
    return

if __name__=='__main__':
    n = I()
    solve()

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

int BinaryResearch(string s,int key,int n){
  int left = 0,right = n;
  int mid;
  while(left < right){
  	mid = (left+right)/2;
    if((int)s.at(mid) == key) return mid;
    else if(key < (int)s.at(mid)) right = mid+1;
    else if(key > (int)s.at(mid)) left = mid;
  }
  return -1;
}
int main()
{
  string S; cin >> S;
  
  bool Alldifferent = true;
  for(int i=0;i<S.size();i++){
  	for(int j=i+1;j<S.size();j++){
      if(S.at(i) == S.at(j)) Alldifferent = false;
    }
  }
  if(Alldifferent) cout << "yes" << endl;
  else cout << "no" << endl;
}

Measured memory_bytes: 256
def main():
    N, a, b, c, d = (int(i) for i in input().split())
    S = input()
    if "##" in S[a:c] or "##" in S[b:d]:
        return print("No")
    if c < d:
        return print("Yes")
    # d < c
    if "..." in S[b-2:d+1]:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


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

#define llint long long int

using namespace std;

int main()
{
    int N;

    cin >> N;

    vector<int> A(N);

    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    bool kau = true;
    llint kabu_num = 0;
    llint money = 1000;

    for (int i = 0; i < N - 1; i++)
    {
        if (kau == true && A[i] < A[i + 1])
        {
            kabu_num = money / A[i];
            money -= kabu_num * A[i];
            kau = false;
        }
        else if (kau == false && A[i] > A[i + 1])
        {
            money += kabu_num * A[i];
            kabu_num = 0;
            kau = true;
        }
    }
    money += kabu_num * A[N - 1];

    cout << money << endl;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int H,W,n,m,i,j,x;
int main(){
	scanf("%d%d%d%d",&H,&W,&n,&m);
	if(H%n==0&&W%m==0)return puts("No"),0;
	puts("Yes");
	x=(H/n)*(W/m)+1;
	for(i=1;i<=H;i++){
		for(j=1;j<=W;j++)if(i%n==0&&j%m==0)printf("%d ",-x*(n*m-1)-1);
		 else printf("%d ",x);
		puts("");
	}
}

Measured memory_bytes: 3800
import heapq
from collections import defaultdict, deque
from math import ceil, factorial
from fractions import gcd
import sys

sys.setrecursionlimit(10 ** 7)
INF = float("inf")
MOD = 10 ** 9 + 7

si = lambda: input().strip()
ii = lambda: int(input())
mii = lambda: map(int, input().split())
lmii = lambda: list(map(int, input().split()))
smii = lambda: sorted(map(int, input().split()))


A, B, C, K = mii()

if K % 2:
    print(B - A)
else:
    print(A - B)


Measured memory_bytes: 5056
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
using ll=long long;
using P=pair<int,int>;
const ll INF=1LL<<31;
const ll LINF=1LL<<60;
const double eps=1e-9;
const ll MOD=1000000007LL;
template<typename T>void chmin(T &a,T b){a=min(a,b);};
template<typename T>void chmax(T &a,T b){a=max(a,b);};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0}; 
ll mpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1){
            res=res*x%MOD;
        }
        n>>=1;
        x=x*x%MOD;
    }
    return res;
}
vector<ll> f,fi;
void comb(){
    f.resize(1010);
    fi.resize(1010);
    f[0]=1;
    for(ll i=1;i<=1000;i++){
        f[i]=f[i-1]*i;
        f[i]%=MOD;
    }
    fi[1000]=mpow(f[1000],MOD-2);
    for(ll i=999;i>=0;i--){
        fi[i]=fi[i+1]*(i+1LL);
        fi[i]%=MOD;
    }
}
ll ncr(ll n,ll r){
    return f[n]*fi[r]%MOD*fi[n-r]%MOD;
}
int main(){
    comb();
    ll n,k;cin>>n>>k;
    if(n>k){
        cout<<0<<endl;
    }else{
        cout<<ncr(k,n)*f[n]%MOD<<endl;
    }
}


Measured memory_bytes: 3156