akhauriyash/Code-Regression huggingface dataset:
////////////////////////////////////////////////////////////////////
// This source code is for Visual Studio
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <stack>
#include <functional>
#include <iomanip>
#include <string>
#include <cstring>
#include <deque>
#include <math.h>
#include <assert.h>

#define	numberof(a)	(sizeof(a) / sizeof(a[0]))
#define	INF32		INT32_MAX
#define	INF64		INT64_MAX
#define Rep(i,n) for(int i = 0; i < (n); ++i )

using namespace std;

typedef vector< vector<int> > MAT;
typedef pair<int, int> PINT;
typedef long long ll;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int32_t s32;
typedef int64_t s64;

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

map<ll, ll> prime_factor(ll N)
{
	map<ll, ll> ret;
	for (ll i = 2; i * i <= N; i++) {
		while (N % i == 0) {
			ret[i]++;
			N /= i;
		}
	}
	if (N != 1) ret[N] = 1;
	return ret;
}

// エラトステネスの篩
// 0～Nまでの素数テーブルを作成
// retval : 素数テーブル(prime[i] = true: 数値iが素数)
vector<bool> eratosthenes_sieve(ll N)
{
	vector<bool> is_prime(N + 1, 1);
	is_prime[0] = false;
	is_prime[1] = false;

	for (ll i = 2; i <= N; i++) {
		if (is_prime[i]) {
			for (ll j = 2 * i; j <= N; j += i) {
				is_prime[j] = false;  // 素数の倍数は素数ではない
			}
		}
	}

	return is_prime;
}

// main function
int main()
{
	ll N = 0;
	ll cnt = 0;

	cin >> N;
	vector< ll > ans(N, 0);
	vector<bool> prime_table = eratosthenes_sieve(55555);

	for (ll num = 3; num <= 55555; ++num) {
		if (prime_table[num] && (num % 5 == 1)) {
			if(cnt < N) ans[cnt++] = num;
		}
	}

	Rep(i, N) {
		cout << ans[i];
		if (i == N - 1) cout << endl;
		else cout << " ";
	}

	return 0;
}

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

int main() {
    long n, t, a, voteT = 1, voteA = 1, temp, ans;
    cin >> n;
    rep(i, n) {
        cin >> t >> a;
        temp = max(voteT / t + ((voteT % t)? 1 : 0), voteA / a + ((voteA % a)? 1 : 0));
        voteT = temp * t;
        voteA = temp * a;
    }
    ans = voteT + voteA;
    cout << ans << endl;
}

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

int arr[10009];

int main ()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    sort(arr, arr + n);
    int ans = 0;
    for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++)
            for (int k = j + 1; k < n && arr[k] < (arr[i] + arr[j]); k++)
                    if (arr[i] + arr[k] > arr[j])
                        if (arr[j] + arr[k] > arr[i])
                            ans++;
    cout << ans << endl;
    return 0;
}


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

int gcd(int a, int b) {
  return b ? gcd(b, a % b) : a;
}

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

  vector<int> left(n+1), right(n+1);
  for (int i = 0; i < n; i ++) left[i+1] = gcd(left[i], a[i]);
  for (int i = n-1; i >= 0; i --) right[i] = gcd(right[i+1], a[i]);

  int ans = 0;
  for (int i = 0; i < n; i ++) {
    int l = left[i];
    int r = right[i+1];
    ans = max(ans, gcd(l, r));
  }

  cout << ans << endl;
}

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

int main() {
 int A,B,C;
 cin>>A>>B>>C;
 for(int i=1;i<=B;i++){
     int sum=A*i;
     if(sum%B==C){cout<<"YES"<<endl;return 0;}    
 }
 cout<<"NO"<<endl;
 return 0;}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int x[]  = new int[n];  
        	for (int i = 0; i<n; i++) {
           	 x[i]= sc.nextInt();  
        	}
            for (int i= n-1;i>=0; i--) {
            if(i!=0){
            	System.out.print(x[i]+" ");
            }else{
                    System.out.println(x[i]);
            }         
        }
        sc.close();
    }
}


Measured memory_bytes: 26236
import java.util.Scanner;

public class Main {
	
	public static int maxPDP(int[] values) {
		int maxp = values[1]-values[0];
		int minv = Math.min(values[1], values[0]);
		for(int i = 2; i < values.length; i ++) {
			maxp = Math.max(maxp, values[i] - minv);
			minv = Math.min(minv, values[i]);
		}
		return maxp;
	}
	
	public static int maxPQ(int[] values) {
		int maxp = Integer.MIN_VALUE;
		int n = values.length;
		for(int i = 0; i < n-1; i ++) {
			for(int j = i+1; j < n; j ++) {
				if (values[j]-values[i] > maxp) {
					maxp = values[j]-values[i];
				}
			}
		}
		return maxp;
	}

	public static void main(String[] args) {

		// Collect and store values
		Scanner in = new Scanner(System.in);
		int[] v = new int[in.nextInt()];
		
		for (int i = 0; i < v.length; i++) {
			v[i] = in.nextInt();
		}
		
		// Call appropriate method
		System.out.println(maxPDP(v));
	}

}



Measured memory_bytes: 69672
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<Int> a(N);
	for (int i = 0; i < N; ++i) { cin >> a[i]; }

	Int ans = a[0] / 2;
	a[0] %= 2;
	for (int i = 1; i < N; ++i) {
		if (a[i - 1] % 2 && a[i] > 0) {
			ans += 1;
			a[i] -= 1;
		}
		ans += a[i] / 2;
		a[i] %= 2;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
n = int(input())
a = list(map(int, input().split()))
d = dict()
for n in a:
    d[n] = d.get(n, 0) + 1

ans = 0
for k, v in d.items():
    if k < v:
        ans += v-k
    if k > v:
        ans += v

print(ans)

Measured memory_bytes: 17780
n=gets.to_i+1;q=[*1..x=n.to_s(2).size-1];n-=1<<x;x.downto(0){|i|n>=1<<i&&(q.insert(i,x+=1);n-=1<<i)};q+=[*1..q.size];p q.size;puts q*' '

Measured memory_bytes: 1788
def main():

    from bisect import bisect_left as bl, bisect_right as br, insort
    import sys
    import heapq
    # from math import *
    from collections import defaultdict as dd, deque
    def data(): return sys.stdin.readline().strip()
    def mdata(): return map(int, data().split())
    out = sys.stdout.write
    # sys.setrecursionlimit(100000)

    a,b,c,d=mdata()
    k1=a//d
    if a%d!=0:
        k1+=1
    k2=c//b
    if c%b!=0:
        k2+=1
    if k1>=k2:
        print("Yes")
    else:
        print("No")




if __name__ == '__main__':
    main()

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

const int N=17, M=1<<N, mod=1e9+7;
inline int add(int x,int y) {return (x+y>=mod) ? (x+y-mod) : (x+y);}
inline int dec(int x,int y) {return (x-y<0) ? (x-y+mod) : (x-y);}
inline int mul(int x,int y) {return (long long)x*y%mod;}
inline int power(int a,int b,int rs=1) {for(;b;b>>=1,a=mul(a,a)) if(b&1) rs=mul(rs,a); return rs;}

int n,m,L,a[N],f[M],fac[M],ifac[M],sum[M],bin[N];
inline int C(int a,int b) {if(a<b) return 0; return mul(fac[a],mul(ifac[b],ifac[a-b]));}

int main() {
	cin>>n>>m; L=1<<n;
	for(int i=0;i<=n;i++) bin[i]=1<<i;
	for(int i=1;i<=m;i++) cin>>a[i];
	fac[0]=1; for(int i=1;i<=L;i++) fac[i]=mul(fac[i-1],i);
	ifac[L]=power(fac[L],mod-2); for(int i=L-1;~i;i--) ifac[i]=mul(ifac[i+1],i+1);
	sort(a+1,a+m+1);
	f[0]=1;
	for(int i=m;i>=1;i--) 
		for(int sta=(1<<n)-1;~sta;--sta)
			for(int j=0;j<n;j++) if(sta&bin[j]) 
				f[sta]=add(f[sta],mul(mul(f[sta^bin[j]],C(L-a[i]-sta+bin[j],bin[j]-1)),fac[bin[j]]));
	int ans=0;
	for(int i=0;i<(1<<n);++i) {
		int cur=mul(f[i],fac[L-i-1]);
		if(__builtin_popcount(i)&1) ans=dec(ans,cur);
		else ans=add(ans,cur);
	} cout<<mul(ans,L)<<'\n';
}

Measured memory_bytes: 1024
#pragma GCC optimize("O3")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

#define mp make_pair
#define all(c) (c).begin() , (c).end()
#define sz(c) ((long long)((c).size()))
#define phb push_back
#define ppb pop_back
#define phf push_front
#define ppf pop_front

using namespace __gnu_pbds;
using namespace std;

#define int ll

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template
<
    class key,
    class val=null_type,
    class comp=less<key>
>
using ord_set=tree
<
    key,
    val,
    comp,
    rb_tree_tag,
    tree_order_statistics_node_update
>;

const int N=5e5+100;

int a[N];

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

    string s;
    cin>>s;
    int n=s.size()+1;
    for(int i=1;i<n;i++)
        if(s[i-1]=='<')
            a[i]=max(a[i],a[i-1]+1);
    for(int i=n-1;i>=0;i--)
        if(s[i]=='>')
            a[i]=max(a[i],a[i+1]+1);
    for(int i=1;i<n;i++)
        if(s[i-1]=='<')
            a[i]=max(a[i],a[i-1]+1);
    for(int i=n-1;i>=0;i--)
        if(s[i]=='>')
            a[i]=max(a[i],a[i+1]+1);
    cout<<accumulate(a,a+n,0ll);
}


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

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

int n,m,x,a[15][15],c[15],s=0,sum[15],mi=INT_MAX;
bool f[15];

void nhap()
{
    scanf("%d %d %d",&n,&m,&x);
    for (int i=1;i<=n;++i)
    {
        scanf("%d",&c[i]);
        for (int j=1;j<=m;++j)
        {
            scanf("%d",&a[i][j]);
        }
    }
}

void check()
{
    for (int i=1;i<=m;++i)
        sum[i]=0;
    for (int i=1;i<=n;++i)
    {
        if (f[i])
        {
            for (int j=1;j<=m;++j)
            {
                sum[j]+=a[i][j];
            }
        }
    }
    for (int i=1;i<=m;++i)
    {
        if (sum[i]<x) return;
    }
    mi=min(mi,s);
}

void solve(int i)
{
    for (int j=0;j<2;++j)
    {
        s+=j*c[i];
        f[i]=j;
        if (i<n) solve(i+1);
        else check();
        s-=j*c[i];
        f[i]=0;
    }
}

int main()
{
    nhap();
    solve(1);
    if (mi!=INT_MAX)
        cout<<mi;
    else cout<<-1;
    return 0;
}


Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0; i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    int N,ma,mb;cin>>N>>ma>>mb;
    vector<pair<pair<int,int>,int>> v;
    vector<pair<int,int>> v1,v2;
    int a,b,c;
    REP(i,N){
        cin>>a>>b>>c;
        v.push_back(make_pair(make_pair(a,b),c));
    }
    REP(i,1<<(N/2)){
        int ta=0,tb=0,tc=0;
        REP(j,(N/2)){
            if((i>>j)&1){
            ta+=v[j].first.first;
            tb+=v[j].first.second;
            tc+=v[j].second;
            }
        }
        v1.push_back(make_pair(mb*ta-ma*tb,tc));
    }
    REP(i,1<<(N-(N/2))){
        int ta=0,tb=0,tc=0;
        REP(j,(N-(N/2))){
            if((i>>j)&1){
            ta+=v[j+N/2].first.first;
            tb+=v[j+N/2].first.second;
            tc+=v[j+N/2].second; }           
        }
        v2.push_back(make_pair(ma*tb-mb*ta,tc));
    }
    sort(all(v1));
    sort(all(v2));
    int res=1<<30;
    pair<int,int> p=make_pair(0,1);
    int ind=lower_bound(all(v1),p)-v1.begin();
    if(ind != (int)v1.size() && v1[ind].first == 0) res= v1[ind].second;
    ind = (int)(lower_bound(all(v2),p)-v2.begin());
    if(ind != (int)v2.size() && v2[ind].first == 0) res= min(res,v2[ind].second);
    REP(i,(int)(v1.size())){
        ind = (int)(lower_bound(all(v2),make_pair(v1[i].first,1))-v2.begin());
        if(ind != (int)v2.size() && v2[ind].first==v1[i].first) res=min(res,v1[i].second+v2[ind].second);
    }

    cout<< (res==(1<<30)?-1:res )<<endl;
    return 0;
}

Measured memory_bytes: 22508
#include<bits/stdc++.h>
using namespace std;
int dp[1001][1001];


int main(){
	char a[1001][1001];
	
	int m,n;
	cin>>m>>n;
	for(int i=1;i<=m;i++)
		for(int j=1;j<=n;j++)
			cin>>a[i][j];
	for(int i=0;i<=m;i++)
		for(int j=0;j<=n;j++)
			dp[i][j]=0;
	dp[1][1]=1;
	for(int i=1;i<=m;i++){
		for(int j=1;j<=n;j++){
			if(a[i][j]=='.')
				dp[i][j]+=(dp[i-1][j]+dp[i][j-1])%1000000007;
		}
	}
	cout<<dp[m][n]<<endl;
	return 0;
}

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

int main() {
    long long N,K,a,b;
    cin >> N >> K;
    a = N % K;
    b = K - a;
    if(a > b){
        cout << b << endl;
    }
    else{
        cout << a << endl;
    }
}

Measured memory_bytes: 256
//hinagata.cpp
/*includes*/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <numeric>
#include <iomanip>
#include <limits>
/*namespace*/
using namespace std;
using ll= long long;
/*define macro*/
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPi(i,a,b) for(int i=(a);i<(b);i++)
#define REPRi(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(x) (x).begin(),(x).end()

int main(){
    int N;
    cin>>N;
    vector<int> H(N);
    REP(i,N){
        cin>>H[i];
    }
    //条件

    int loop=0;
    while(1){
    int start=0;
    int end=0;
    int maxlength=0;
    int count=0;
        REP(i,N){
            if(H[i]>=1){
                count+=1;
                if(i==N-1&&maxlength<count){
                    end=i;
                    start=i+1-count;
                    maxlength=count;
                }
            }else{
                if(maxlength<count){
                    end=i-1;
                    start=i-count;
                    maxlength=count;
                }
                count=0;
            }
        }
        if(maxlength==0){
            cout<<loop<<endl;
            break;
        }
        REP(i,N){
            if(i>=start&&i<=end){
                H[i]-=1;
            }
        }
    loop+=1;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int d,g;
    cin>>d>>g;
    g/=100;
    int p[d],c[d];
    for(int i=0;i<d;i++){
        cin>>p[i]>>c[i];
        c[i]/=100;
    }
    int D=1;
    for(int i=0;i<d;i++)D*=2;
    int m=1000;
    for(int i=0;i<D;i++){//どの難易度を全完するか全探索
        int solve[d]={};
        int x=0,score=0,I=i;
        for(int j=0;j<d;j++){
            if(I%2){
                solve[j]=1;
                score+=(j+1)*p[j]+c[j];
                x+=p[j];
            }
            I/=2;
        }
        if(score<g){
            bool br=0;
            for(int j=d-1;j>=0;j--){
                if(solve[j]==0){
                    for(int k=0;k<p[j];k++){
                        score+=j+1;
                        x++;
                        if(score>=g){
                            br=1;
                            break;
                        }
                    }
                    if(br)break;
                }
            }
        }
        m=min(m,x);
    }
    cout<<m<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int x, y, z;
	int i, n;
	
	scanf("%d", &n);

	for(i=0; i<n; i++)
	{
		scanf("%d%d%d", &x,&y,&z);

		if((x*x == (y*y+z*z)) || (y*y == (z*z+x*x)) || (z*z == (x*x+y*y)))
			printf("YES\n");
		else
			printf("NO\n");

	}

	return 0;
}

Measured memory_bytes: 580
#include<iostream>
#include<algorithm>
#include<climits>
using namespace std;
const int INF = INT_MAX/3;
const int MAXN = 1000;
const int TIME = 1,COST = 0;
int graph[2][MAXN][MAXN];

int n,m,a,b,c,t;
void solve();
void init(){
  for(int i = 0;i < m;i++)
    for(int j = 0;j < m;j++)
      graph[0][i][j] =graph[0][j][i] = graph[1][j][i] = graph[1][i][j] = INF;
}

int main(){
  while(1){
  cin >> n >> m;
  if(n == 0&& m == 0) break;
  init();

  for(int i = 0;i < n;i++){
    cin >> a >> b >> c >> t;
    graph[TIME][a-1][b-1] = graph[TIME][b-1][a-1] = t;
    graph[COST][a-1][b-1] = graph[COST][b-1][a-1] = c;
  }

  solve();

  int X;
  cin >> X;
  for(int i = 0;i < X;i++){
    cin >> a >> b >> c;
    cout << graph[c][a-1][b-1] << endl;
  }
  }
  return 0;
}

void solve(){
  for(int k = 0;k < m;k++){
    for(int i = 0;i < m;i++){
      for(int j = 0;j < m;j++){
	graph[0][i][j] = min(graph[0][i][j],graph[0][i][k] + graph[0][k][j]);
	graph[1][i][j] = min(graph[1][i][j],graph[1][i][k] + graph[1][k][j]);
      }
    }
  }
}

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

signed main(){
	long long n,m;	cin>>n>>m;
	vector<int> cards(n);	for(int i=0;i<n;i++)cin>>cards[i];

	vector< pair<int,int> > data(m);
	for(int i=0;i<m;i++){
		int b,c;	cin>>b>>c;
		data[i]={c,b};
	}
	sort(data.begin(), data.end(), greater<>());

	vector<int> tmp;
	for(int i=0;i<m;i++){
		int c=data[i].first, b=data[i].second;
		for(int j=0;j<b;j++){
			tmp.push_back(c);
			if(tmp.size()==n)break;
		}
		if(tmp.size()==n)break;
	}
	

	while(tmp.size()<n)tmp.push_back(0);
	sort(cards.begin(), cards.end());
	sort(tmp.begin(), tmp.end(), greater<>());
	//for(int i=0;i<n;i++)cout<<cards[i]<<" ";
	//cout<<endl;
	//for(int i=0;i<n;i++)cout<<tmp[i]<<" ";
	//cout<<endl;

	long long ans=0;
	for(int i=0;i<n;i++){
		ans+=max(tmp[i], cards[i]);
	}
	cout<<ans<<endl;

	return 0;
}


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

using namespace std;
 
int main(){
    long long n,p,r,t;
    cin>>n;
    string s;
    cin>>s;
    p=(int(s[0]-48))*n;
    r=(int(s[3]-48))*n;
    r=r/10;
    t=(int(s[2]-48))*n;
    t=t+r;
    t=t/10;
    p=p+t;
    cout<<p;


    return 0;
    }
 


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rrep(i, n) for(ll i = n - 1; i > -1; i--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
template <class X> void print(X x) { cout << x << endl; }
void print(vl x) {
    for(ll i : x) {
        cout << i << " ";
    }
    cout << endl;
}
const ll INF = (1LL << 61) - 1;
const ll MOD = 1000000007 /*998244353*/;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, h, x, y, z, p, q, n, t, r, k, w, l, ans, i, j, u, v, m;
ll codeforces = 1;
string S, T;
vl A, B;
void input() { cin >> n; }
void solve() { print((10000 - n) % 1000); }
int main() {
    // cout<<fixed<<setprecision(15);
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    while(codeforces--) {
        solve();
    }
}

Measured memory_bytes: 3652
#define _GLIBCXX_DEBUG
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;

int P[10010];
void init(int n){
    for(int i=0;i<n;++i)P[i]=i;
}
int root(int a) {
    if(P[a]==a)return a;
    return (P[a]=root(P[a]));
}
bool is_same_set(int a,int b){
    return root(a) == root(b);//代表元を求める
}
void unite(int a,int b){
    P[root(a)]=root(b);
}//対set,グラフ？

double dot_product(xy_t a, xy_t b) { return (conj(a)*b).real(); }//内積
double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }//外積
xy_t projection(xy_t p, xy_t b) { return b*dot_product(p,b)/norm(b); }//投影
//対図形


const ll mod=1e9+7;

ll dfs(int K,const vector<vector<int>>&graph, int now,int from){
    int can_use_color_num;
    if(from==-1){
        can_use_color_num=K-1;
    }else{
        can_use_color_num=K-2;
    }
    if(K<graph[now].size()){
        return 0;
    }else{
        ll case_num=1;
        for(auto e : graph[now]){
            if(e==from)continue;
            
            case_num*=can_use_color_num;
            can_use_color_num--;
            case_num%=mod;
        }
        for(auto e : graph[now]){
            if(e==from)continue;
            case_num *=dfs(K,graph,e,now);
            case_num %= mod;
        }
        return case_num;
    }
}
int main(){
    int N,K;cin >>N>>K;

    vector<vector<int>>graph(N);
    for(int i=0;i<N-1;++i){
        int a,b;cin>>a>>b;a--;b--;

        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    ll answer=K*dfs(K,graph,0,-1);
    answer%=mod;
    cout<<answer<<endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  int b[n-1];
  rep(i,n-1) cin >> b[i];
  int a[n];
  rep(i,n) a[i] = 100001;

  rep(i,n-1) {
    a[i] = min(a[i], b[i]);
    a[i+1] = min(a[i+1], b[i]);
  }

  int ans = 0;
  rep(i,n) ans += a[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
def solve(x):
    for i in a:
        x = i * (x // i)
    return x

def solve_min(c1, c2):
    m = (c1 + c2 + 1) // 2
    if abs(c1 - c2) <= 1:
        return m
    else:
        if solve(m) < 2:
            c1 = m
        else:
            c2 = m
        return solve_min(c1, c2)

def solve_max(c1, c2):
    m = (c1 + c2 + 1) // 2
    if abs(c1 - c2) <= 1:
        return m
    else:
        if solve(m) <= 2:
            c1 = m
        else:
            c2 = m
        return solve_max(c1, c2)

k = int(input())
a = list(map(int, input().split()))
maxa = max(a)
mi = solve_min(maxa - 1, pow(10, 18))
ma = solve_max(maxa - 1, pow(10, 18))
ans = [mi, ma - 1]
print(-1 if mi == ma else " ".join(map(str, ans)))

Measured memory_bytes: 84988
import java.util.Scanner;

class Main{
       public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
    	Dice[] dice;

    	dice = new Dice[2];

    	for(int i = 0; i < 2; i++){
    		dice[i] = new Dice();
    	}

    	for(int i = 0; i < 2; i++){
    		for(int j = 0; j < 6; j++){
    			dice[i].S[j] = scan.nextInt();
    		}
    	}

    	
		for(int i = 0; i < 4; i++){
			for(int j = 0; j < 4; j++){
			    for(int k = 0; k < 4; k++){
			   		dice[1].vRoll();
			    		if(dice[0].S[0] == dice[1].S[0] && dice[0].S[1] == dice[1].S[1] && dice[0].S[2] == dice[1].S[2] && dice[0].S[3] == dice[1].S[3] && dice[0].S[4] == dice[1].S[4] && dice[0].S[5] == dice[1].S[5]) {
			    			System.out.println("Yes");
			    			return;
			    		}
			        }
			    	dice[1].yRoll();
		    	}
		    	dice[1].v2Roll();				
		}
    	System.out.println("No");
     }
}

class Dice{
	int[] S = new int[6];
	
	public void vRoll(){
		int temp3 = S[0];
		S[0] = S[1];
		S[1] = S[5];
		S[5] = S[4];
		S[4] = temp3;
	}
	
	public void yRoll(){
		int temp2 = S[0];
		S[0] = S[3];
		S[3] = S[5];
		S[5] = S[2];
		S[2] = temp2;
	}
	
	public void v2Roll(){
		int temp = S[0];
		S[0] = S[1];
		S[1] = S[5];
		S[5] = S[4];
		S[4] = temp;
	}
}

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

typedef long int lint;
typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<long, long> pll;

#define EACH(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i, s, e) for (int i = (s); i < (int)(e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define endl '\n'
#define mod 1000000007
#define INF 100000000
#define fk first
#define sv second

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

template<typename T>
void print(const std::vector<T>& v, char sep=' ') {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i != 0) cout << sep;
    cout << v[i];
  }
  cout << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, x = 0, m = 0;
  string s;
  cin >> n >> s;
  REP(i, n){
    if (s[i] == 'I') x++;
    else x--;
    m = max(x, m);
  }

  cout << m << endl;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main{
	public static void main(String[] args) throws IOException{

		int[] H = new int[1000];
		int[] W = new int[1000];
		String[] Buffer = new String[10];
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;

		for(int n = 0; n<1000; n++){
			Buffer = br.readLine().split(" ");
			H[n] = Integer.parseInt(Buffer[0]);
			W[n] = Integer.parseInt(Buffer[1]);
			//System.out.println("your input is: "+n+" "+H[n]+" "+W[n]);
			if(H[n]==0 && W[n]==0){
				n = 1000;
			}
		}
		
 		int k = 0;
 		while(H[k]!=0 && W[k]!=0){
 			for(int n = 0; n< H[k]; n++){
 				for(int m = 0; m< W[k]; m++){
 					System.out.print("#");
 				}
 				System.out.print("\n");
 			}
 			k++;
 			System.out.print("\n");
 		}

	}
}

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

using namespace std;

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

    vector<int> mya(n), myb(n), myc(n);
    for(int i = 0; i < n; i++) cin >> mya[i];
    for(int i = 0; i < n; i++) cin >> myb[i];
    for(int i = 0; i < n-1; i++) cin >> myc[i];

    int total = 0;
    total += myb[mya[0]-1];
    for(int i = 1; i < n; i++) {
        if (mya[i-1]+1 == mya[i]) {
            total += myc[mya[i-1]-1];
        }
        total += myb[mya[i]-1];
    }
    cout << total << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int As, Ae;
int Bs, Be;

int main()
{
	cin >> As >> Ae >> Bs >> Be;

	int result = min(Ae, Be) - max(As, Bs);
	if (result < 0) result = 0;

	cout << result << endl;;
	
	return 0;
}

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

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#pragma GCC optimize("Ofast")
//1.0 * clock() / CLOCKS_PER_SEC

#define fi first
#define se second
#define ll long long
#define dl double long

using namespace std;

const int NN = 1e6 + 7;
const int N = 1e3 + 7;
const int M = 20;
const ll mod = 998244353;
const ll inf = 1e18 + 7;
const dl rf = 1e-14;

int n,m,k;
int a[N][N];

void solve1()
{
    cin >> n >> m >> k;
    int ans = 1e9;
    for( int i = 0; i < n; i++ ){
        string s;
        cin >> s;
        for( int j = 0; j < m; j++ ){
            a[i][j] = (s[j] - '0');
        }
    }
    for( int i = 0; i < (1 << (n - 1)); i++ ){
        vector < int > bl;
        vector < vector < int > > b(__builtin_popcount(i) + 1 , vector < int > (m));
        int x = 0;
        int y = 0;
        bool can = true;
        for( int j = 0; j < n; j++ ){
            if( ( i & (1 << j) ) == 0 && j < n - 1 ){
                continue;
            }
            for( int h = 0; h < m; h++ ){
                for( int g = x; g <= j; g++ ){
                    b[y][h] += a[g][h];
                    if( b[y][h] > k ){
                        can = false;
                    }
                }
            }
            y += 1;
            x = j + 1;
        }
        if( !can )continue;
        int cnt = y - 1;
        int s = 0;
        y -= 1;
        vector < int > f(y + 1);
        for( int j = 0; j < m; j++ ){
            for( int h = 0; h <= y; h++ ){
                if( f[h] + b[h][j] > k ){
                    cnt += 1;
                    for( int g = 0; g <= y; g++ ){
                        f[g] = b[g][j];
                    }
                    break;
                }
                f[h] += b[h][j];
            }
        }
        ans = min( ans , cnt );
    }
    cout << ans;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0); srand(time(0));
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}


Measured memory_bytes: 384