akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main()
{
	long int A[101][101], B[101][101], C[101][101] = { 0 };
	int l, m, n;
	scanf("%d %d %d", &l, &m, &n);
	int h, i, j, k, g;
	for (i = 0; i <= l - 1; i++)
	{
		for (j = 0; j <= m - 2; j++)
		{
			scanf("%d ", &A[i][j]);
		}
		scanf("%d", &A[i][m - 1]);
	}
	for (i = 0; i <= m - 1; i++)
	{
		for (j = 0; j <= n - 2; j++)
		{
			scanf("%d ", &B[i][j]);
		}
		scanf("%d", &B[i][n - 1]);
	}
	for (h = 0; h <= l - 1; h++)
	{
		for (j = 0; j <= n - 1; j++)
		{
			for (k = 0; k <= m - 1; k++)
			{
				C[h][j] += A[h][k] * B[k][j];
			}
		}
	}
	for (i = 0; i <= l - 1; i++)
	{
		for (j = 0; j <= n - 2; j++)
		{
			printf("%ld ", C[i][j]);
		}
		printf("%ld\n", C[i][n - 1]);
	}
	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
signed main(){
  int N,X;
  cin>>N>>X;
  int ans=N;
  vi A(N);
  rep(i,0,N){
    cin>>A[i];
    X-=A[i];
    }
  sort(ALL(A));
  ans+=X/A[0];
  cout<<ans;
  }


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

const long long MOD = 2;

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    int n = 0, m = 0;
    cin >> n >> m;

    vector<int> k(m + 1, 0);

    vector<vector<int>> s(m + 1, vector<int>(n + 1, 0));
    for (int i = 1; i <= m; i++)
    {
        cin >> k[i];

        for (int j = 1; j <= k[i]; j++)
        {
            cin >> s[i][j];
        }
    }

    vector<int> p(m + 1, 0);
    for (int i = 1; i <= m; i++)
    {
        cin >> p[i];
    }

    int res = 0;
    for (int state = 0; state < (1 << n); state++)
    {
        bool ok = true;
        for (int i = 1; i <= m; i++)
        {
            int v = 0;
            for (int j = 1; j <= k[i]; j++)
            {
                v += (state >> (s[i][j] - 1) & 1);
            }
            if (v % 2 != p[i])
            {
                ok = false;
                break;
            }
        }
        if (ok)
        {
            res++;
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
from collections import Counter
input = sys.stdin.readline

S = input().strip()
check = ''
string = ''
ans = 0

for i in range(len(S)):
    string += S[i]
    if string == check:
        check = string
    else:
        check = string
        string = ''
        ans += 1
        
print(ans)

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

int main()
{
	int n, m = 0;
	int v[20], c[20];

	cin >> n;

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

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

	for (int i = 0; i < n; i++) {
		int u = v[i] - c[i];
		if (u > 0)
			m += u;
	}

	cout << m << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m;
long long int H[100005];
bool A[100015],B[100015];
int main(){
	scanf("%d%d",&n,&m);
	fill(A,A+n+4,true);
	for(int i=1;i<=n;i++) scanf("%ld",&H[i]);
	while(m--){
		int a,b;
		scanf("%d%d",&a,&b);
		B[a]=true,B[b]=true;
		if(H[a]>H[b]) A[b]=false;
		else A[a]=false;
		if(H[a]==H[b]) A[a]=A[b]=false;
	}
	int ans=0; 
	for(int i=1;i<=n;i++){
		if(A[i]==true ) ans++;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 4808
#include <bits/stdc++.h>
using namespace std;
template<class T> void read(T& x)
{
	char c = getchar(); T p = 1, n = 0;
	while(c < '0' || c > '9') {if(c == '-') p = -1; c = getchar();}
	while(c >= '0' && c <= '9'){n = n * 10 + c - '0'; c = getchar();}
	x = p * n;
}
template<class T,class U>void read(T&x,U&y){read(x),read(y);}
template<class T,class U,class V>void read(T&x,U&y,V&z){read(x),read(y),read(z);}
int main()
{
	int a, b, c, x, y; read(a, b, c); read(x, y);
	if(a + b <= 2 * c)
	{
		printf("%d\n", a * x + b * y);
		return 0;
	}
	if(x > y) swap(a, b), swap(x, y);
	int ret = x * 2 * c; y -= x;
	ret += min(y * b, y * 2 * c);
	printf("%d\n", ret);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int n = 0;
  cin >> n;
  
  int64_t l_0 = 2, l_1 = 1, l_i = 0;
  
  for (int i = 0; i < (int)(n - 1); i++) {
    l_i = l_1 + l_0;
    
    l_0 = l_1;
    l_1 = l_i;
  }
  
  if (n == 0) {
    l_i = l_0;
  }
  else if (n == 1) {
    l_i = l_1;
  }
  
  cout << l_i << endl;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

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

//組み合わせを線形で
//参考:https://drken1215.hatenablog.com/entry/2018/06/08/210000

const int MXN=1000001;//変更可
ll fac[MXN],inv[MXN],finv[MXN];

void COMinit(int M) {
    fac[0]=fac[1]=1;
    inv[1]=1;
    finv[0]=finv[1]=1;
    for(int i=2;i<MXN;i++){
        fac[i]=fac[i-1]*i%M;
        inv[i]=M-M/i*inv[M%i]%M;
        finv[i]=finv[i-1]*inv[i]%M;
    }
}

ll COMBI(int N,int K,int M){
    if(N<K){
        return 0;
    }
    if(N<0||K<0){
        return 0;
    }
    return fac[N]*finv[N-K]%M*finv[K]%M;
}

ll PERMU(int N,int K,int M){
    if(N<K){
        return 0;
    }
    if(N<0||K<0){
        return 0;
    }
    return fac[N]*finv[N-K]%M;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N,M,K;
    cin >> N >> M >> K;
    COMinit(MOD);
    ll ans=0;
    rep(d,N){
        ans+=((COMBI(N*M-2,K-2,MOD)*d)%MOD*((N-d)*M*M)%MOD)%MOD;
        ans%=MOD;
    }
    rep(d,M){
        ans+=((COMBI(N*M-2,K-2,MOD)*d)%MOD*((M-d)*N*N)%MOD)%MOD;
        ans%=MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 27040
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;
const int ny[4] = {-1,1,0,0}, nx[4] = {0,0,-1,1};
int sy,sx,gy,gx;

int main(){
  string s; cin >> s;
  while(true){
    s.pop_back();
    int len = s.size();
    if(len % 2 == 1)continue;
    int n = len/2;
    bool flg = true;
    for(int i = 0; i < n; i++){
      if(s[i] != s[i+n]) flg = false;
    }
    if(flg){
      cout << len << endl;
      return 0;
    }
  }
  return 0;
}


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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク

    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,m;
  cin >> n >> m;
  int x[m];
  int y[m];
  int z[m];
  UnionFind uf(n);
  rep(i,m){
    cin >> x[i] >> y[i] >> z[i];
    x[i]--,y[i]--;
    uf.merge(x[i],y[i]);
  }

  set<int> st;
  rep(i,n){
    st.insert(uf.root(i));
  }
  cout << st.size() << endl;
  return 0;
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)
#define EPS         (1e-10)
#define EQ(a, b)    (abs((a)-(b)) < EPS)

using P   = pair<int, int>;
using LL  = long long;
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    int n, m, k;cin >> n >> m >> k;
    string ans = "No";
    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            if(i*m + j*n - 2*i*j == k) ans = "Yes";
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <utility>
#include <cstdio>
#include <vector>
#define pb push_back
typedef long long ll;
template <typename T>
inline void merge(T &res, const T &va, const T &vb, ll wa, ll wb, ll lim)
{
	T tmp;
	auto cur = vb.begin();
	for (auto &it : va)
	{
		while (cur != vb.end() && cur->first <= lim - wa - wb - it.second)
			cur++;
		if (cur != vb.begin())
		{
			auto idx = cur;
			idx--;
			tmp.pb({it.first + wa, idx->second + wb});
			tmp.pb({idx->second + wb, it.first + wa});
		}
	}
	std::sort(tmp.begin(), tmp.end());
	res.clear();
	for (auto &it : tmp)
	{
		if (res.empty() || it.second < res.back().second)
			res.pb(it);
	}
}
std::vector<std::pair<ll, ll> > vec[200005], adj[200005];
int que[200005], n;
inline bool chk(ll lim)
{
	for (int i = n - 1; i >= 0; i--)
	{
		int u = que[i];
		if (adj[u].empty())
			vec[u] = {{0, 0}};
		else
			merge(vec[u], vec[adj[u][0].first], vec[adj[u][1].first], adj[u][0].second, adj[u][1].second, lim);
		if (vec[u].empty())
			return false;
	}
	return true;
}
int main()
{
	// freopen("AGC007-E.in", "r", stdin);
	scanf("%d", &n);
	for (int i = 1; i < n; i++)
	{
		int u, w;
		scanf("%d%d", &u, &w);
		adj[--u].pb({i, w});
	}
	int he = 0, ta = 0;
	que[ta++] = 0;
	while (he < ta)
	{
		int u = que[he++];
		for (auto &e : adj[u])
			que[ta++] = e.first;
	}
	ll l = 0, r = 1e18, ans = -1;
	while (l <= r)
	{
		ll m = l + r >> 1;
		if (chk(m))
		{
			ans = m;
			r = m - 1;
		}
		else
			l = m + 1;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 35084
#include <bits/stdc++.h>	
#define ll long long 
#define pb push_back
#define N 100005
using namespace std;

//ll A[N],ans;
ll n,k,a,b,c,d;
 
#pragma region
void ingresoInt(int A[]){
	for (int i = 0; i < n; ++i)scanf("%d",&A[i]);
}
void ingresoLL(ll A[]){
	for (int i = 0; i < n; ++i)scanf("%lld",&A[i]);
}
void mostrarInt(int A[]){
	for (int i = 0; i < n; ++i)printf("%d ",A[i]);printf("\n");
}
void mostrarLL(ll A[]){
	for (int i = 0; i < n; ++i)printf("%lld ",A[i]);printf("\n");
}
#pragma endregion




bool esIso(vector<int> a[],vector<int> b[],int u, int v){
	
	if(a[u].size()==0 && b[v].size()==0) return true;
	
	if(a[u].size() != b[v].size())return false;

	if(a[u].size()==1)
		return esIso(a,b,a[u][0],b[v][0]);

	return esIso(a,b,a[u][1],b[v][1])&&esIso(a,b,a[u][0],b[v][0]) || esIso(a,b,a[u][0],b[v][1])&&esIso(a,b,a[u][1],b[v][0]);

}


int main(){
	/*
	char P[100500];
	int j=0;
	scanf("%[^'\n']s",P);
	for (int i = 0; i < strlen(P); ++i)
	{	
		if(P[i]==' '){printf("%c.",P[j]);j=i+1;}
	}
	for (int i = j; i < strlen(P); ++i)
	{
		printf("%c",P[i]);
	}*/
	int n,m;
	char P[10000];
	map<string,int> mapa;
	set<string> S;
	scanf("%d",&n);
	int ma=0;
	while(n--){
		scanf("%s",P);
		mapa[P]++;
		S.insert(P);
	}	
	scanf("%d",&m);
	while(m--){
		scanf("%s",P);
		mapa[P]--;
	}

	for(auto i : S){
		if(mapa[i]>ma) ma=mapa[i];
	}
	printf("%d\n", ma);
	return 0; 

}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

#def shift(children, S):
#    for i, s in enumerate(S):
#        if children[i] > 0:
#            children[i] -= 1
#            if s == "R":
#                children[i+1] += 1
#            else:
#                children[i-1] += 1
#    return children

#def shift(children, S):
#    new_children = children.copy()
#    for i, s in enumerate(S):
#        if new_children[i] > 0:
#            if s == "R":
#                new_children[i+1] += children[i]
#            else:
#                new_children[i-1] += children[i]
#            new_children[i] -= 1
#    return new_children

#def solve(S: str):
#    N = len(S)
#    children = [1]*N
#    print(children)
#    for _ in range(N):
#        children = shift(children, S)
#        print(children)
#    if (10**100-N)%2==1:
#        children = shift(children, S)
#        print(children)
#
#    return " ".join([str(child) for child in children])

from itertools import groupby

def solve(S: str):
    lengths = [sum(1 for _ in g) for k, g in groupby(S)]
    cumsum=0
    a = [0]*len(S)
    for i in range(len(lengths)-1)[::2]:
        cumsum += lengths[i]
        a[cumsum-1]= lengths[i]//2 + lengths[i]%2   + lengths[i+1]//2
        a[cumsum]  = lengths[i]//2 + lengths[i+1]%2 + lengths[i+1]//2
        cumsum += lengths[i+1]

    return " ".join([str(child) for child in a])


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    print(solve(S))

if __name__ == '__main__':
    main()


Measured memory_bytes: 11372
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int X = sc.nextInt();

	int Aa = 0;
	int Ba = 0;
	while(true){
	    for(int A=-1000;A<1000;A++){
		for(int B=-1000;B<1000;B++){
		    if(Math.pow(A,5) - Math.pow(B,5) == X){
			Aa = A;
			Ba = B;
			break;
		    }
		}
	    }
	    break;
	}
	System.out.print(Aa+" "+Ba);
    }
}


Measured memory_bytes: 38856
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
 
priority_queue<ll> ret;
void divisor(long long n)
{
 
    for (long long i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            ret.push(i);
            if (i * i != n)
                ret.push(n / i);
        }
    }
    // sort(ret.begin(), ret.end()); // 昇順に並べる
}
 
int main()
{
    //最大公約数を求める。
    ll n, m;
    cin >> n >> m;
    divisor(m);
    ll k = 0;
    ll u=ret.size();
    while (1)//計算量1をn回
    {
      if (ret.top() < n){
      	break;
      }
        k = ret.top();
        ret.pop();//計算量logn
      if (ret.empty()){
           break;
      }
    }
  /*	rep(i,u){
       k = ret.top();
      if (k<n){
      break;
      }
      ret.pop();
    }*/
    cout << m/k  << endl;
    //公約数のうち、N以上となるもののうち最小値になるものを選択すれば良い。
    //Mが大きすぎるのでfor分で回すと死ぬ。
    //公約数と成り得る数をqueに格納していけば絶対にできる。(どうやる？)
}


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

#define ff        first
#define ss        second
#define int       long long
#define pb        push_back
#define mp        make_pair
#define vi        vector<int>
#define pii       pair<int,int>
#define mii       map<int,int>
#define w(x)      int x; cin>>x; while(x--)
#define all(x)      (x).begin(),(x).end()
#define rep(i,a,b)  for(int i=(a);i<(b);i++)
#define mod       1000000007

int dp[100001];

void c()
{
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
}

int Mincost(vi& h,int n,int k)
{
    if(n==0)
        return 0;
    if(dp[n]!=-1)
        return dp[n];

    int ans=INT_MAX;
    rep(i,1,k+1)
        if(n-i>=0)
            ans=min( ans, Mincost(h,n-i,k)+abs(h[n]-h[n-i]) );
    return dp[n]=ans;
}

int32_t main() {

    //c();
    memset(dp,-1,sizeof(dp));
    int n,k; cin>>n>>k;
    vi a(n);
    rep(i,0,n) cin>>a[i];

    cout<<Mincost(a,n-1,k);            
    return 0;
}

Measured memory_bytes: 9600
#include <vector>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
	int N;double d;
	scanf("%d%lf",&N,&d);
	vector<pair<double,double> >v={{d,d}};
	//????????????**2-??????(??????)??????**2 == ?¨?????????????**2
	for(int i=1;i<N;i++){
		scanf("%lf",&d);
		vector<double>a(i);
		transform(v.begin(),v.end(),a.begin(),[&](const pair<double,double> &e)->double{
			return sqrt((e.first+d)*(e.first+d) - (e.first-d)*(e.first-d)) + e.second;
		});
		v.emplace_back(d,max(d,*max_element(a.begin(),a.end())));
	}
	vector<double>a(N);
	transform(v.begin(),v.end(),a.begin(),[&](const pair<double,double> &e)->double{
		return e.first+e.second;
	});
	printf("%f\n",*max_element(a.begin(),a.end()));
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> P;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
	ll cost;
};
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 2.0 * asin(1.0);
const ll INF = 1L<<60;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = 10000000;
/****** define constant end ********/
/****** define variable start ******/
ll n;
vl a, b, c;
ll q, k;
vl x, y;
Graph G;
/******* define variable end *******/

std::vector<ll> d;

void dijkstra(ll s){
	std::priority_queue<P, std::vector<P>, std::greater<P>> que;
	for(ll i = 0; i < n; i++) d[i] = INF;
	d[s] = 0;
	que.push(P(0, s));

	while(!que.empty()){
		P p = que.top(); que.pop();
		ll v = p.second;
		if(d[v] < p.first) continue;
		for(ll i = 0; i < G[v].size(); i++){
			Edge e = G[v][i];
			if(d[e.to] > d[v] + e.cost){
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}
int solve() {
    cin >> n;
	G.resize(n);
	d.resize(n);
    a.resize(n-1);
    b.resize(n-1);
    c.resize(n-1);
    REP(i, n-1){
        cin >> a[i] >> b[i] >> c[i];
		Edge e = {b[i]-1, c[i]};
		G[a[i]-1].push_back(e);
		Edge e2 = {a[i]-1, c[i]};
		G[b[i]-1].push_back(e2);
    }
    cin >> q >> k;
	dijkstra(k-1);
    x.resize(q);
    y.resize(q);
    REP(i, q){
        cin >> x[i] >> y[i];
		cout << d[x[i]-1] + d[y[i]-1] << endl;
	}
	return 0;
}

int main() {
	//clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 13952
// Palindromic Number
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;


int main()
{
  int N,x, ans;
  cin >> N;
  vector<int> a;

  for (int i = 0; i < N; i++) {
    cin >> x;
    a.push_back(x);
  }

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

  for (int i = 0; i < N-1; i++) {
    ans+=abs(a[i]-a[i+1]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
n, d, a = gets.split.map(&:to_i)

xh = [[-1, 0, 0]] + n.times.map {gets.split.map(&:to_i) << 0}.sort_by{|e| e[0]}

j = ans = 0
1.upto(n) do |i|
    j += 1 while j < i-1 && xh[j][0] + 2 * d < xh[i][0]
    j -= 1 if j != 0 && xh[j][0] + 2 * d >= xh[i][0]
    x = xh[i][1] - xh[i-1][2] + xh[j][2]
    x = x < 0 ? 0 : x.fdiv(a).ceil
    ans += x
    xh[i][2] = xh[i-1][2] + x * a
end

p ans

Measured memory_bytes: 22520
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#include <bits/stdc++.h>
using namespace std;
inline void write(int x)
{
    if(x<0)
	{
    	putchar('-');
		x=-x;
	}
    if(x>9)
		write(x/10);
    putchar(x%10+'0');
}
int main()
{
	ios::sync_with_stdio(false);
	char c,a,b;
	int l=-2;
	c=getchar();
	a=c;
	while(c!='\n')
	{
		l++;
		b=c;
		c=getchar();
	}
	putchar(a);
	write(l);
	putchar(b);
	puts("");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <deque>

using namespace std;



int main(){
    long long K;
    cin >> K;
    deque<long long> d;

    //init 
    for(int i=1; i<=9; ++i){
        d.emplace_back(i);
    }

    long long cnt = 0;

    while(true){
        cnt++;
        if(cnt == K) break;
        long long f = d.front();
        d.pop_front();
        long long new_num = 10*f + (f%10);

        if(new_num%10 != 0){
            d.emplace_back(new_num - 1);
        }
        d.emplace_back(new_num );
        if(new_num % 10 != 9){
            d.emplace_back( new_num + 1 );
        }

    }

    cout << d.front() << endl;
}

Measured memory_bytes: 5144
#include <stdio.h>

int main(){
  int w,h;

  while(1) {
    scanf("%d %d", &w, &h);

    if(w == 0 && h == 0) break;

    for(int i = 0; i < w; i++) {
      for(int j = 0; j < h; j++) {
        if(i == 0 || i == w - 1 || j == 0 || j == h -1) {
          printf("#");
        } else {
          printf(".");
        }
      }
      printf("\n");
    }
    printf("\n");
  }
}



Measured memory_bytes: 2120
#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() {
  int n;
  cin >> n;
  int m = n % 10;
  if (m == 3)
    cout << "bon";
  else if (m == 0 || m == 1 || m == 6 || m == 8)
    cout << "pon";
  else
    cout << "hon";
  cout << endl;
  return 0;
}

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

namespace{
   constexpr int g1 = 1000 * 1000 * 1000, si = 1001 * 1002, si_log = 8 + 10, mod = static_cast<int>(1e9) + 7;
   constexpr long double eps = 1.0e-9;
   int n, m;
   char ar[si];
}

int64_t sol() {
   int64_t ret = 0 * numeric_limits<int64_t>::max();
   return ret;
}

int main() {
   ios_base::sync_with_stdio(0); cin.tie(0);
   
   while (1 == scanf("%d", &n))
   {
      //memset(ar, 0, sizeof ar);
      //for (int i = 0; i <= n; i++)  { gr[i].clear(); }
      //for (int i = 1; i < n; i++) {
      //   int a, b; cin >> a >> b; gr[a].push_back(b); gr[b].push_back(a);
      //}
      auto s =0
         //sol()
      ;
      set<int> se;
      for (int i = 0; i < n; i++)
      {
         int x; scanf("%d", &x);
         auto it = se.find(x);
         if (se.end() == it)
            se.insert(x);
         else
            se.erase(it);
      }
      s = (int)se.size();
      //cout << (s ? "Yes": "No") << '\n';
      cout << s << '\n';
#ifndef _DEBUG
      break;
#endif
   }
   return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long X,Y;
  cin >> X >> Y;
  if(X == 0){
    if(Y < 0){
      cout << 1+abs(Y) << endl;
      return 0;
    }
    else{
      cout << abs(Y) << endl;
      return 0;
    }
  }
  else if(Y == 0){
    if(X>0){
      cout << 1+abs(X) << endl;
      return 0;
    }
    else{
      cout << abs(X) << endl;
      return 0;
    }
  }
  else if(abs(X) == abs(Y)){
    if(X != Y){
      cout << 1 << endl;
      return 0;
    }
    else{
      cout << 0 << endl;
      return 0;
    } 
  }
  bool ok = false;
  if((X >= 0 && Y >= 0) || (X<0 && Y<0)) ok = true;
  if(ok && X <= Y){
    cout << abs(abs(Y)-abs(X)) << endl;
    return 0;
  }
  else if(ok){
    cout << 2+abs(Y-X) << endl;
    return 0;
  }
  else{
   int Z = abs(abs(X)-abs(Y));
    cout << Z+1 << endl;
    return 0;
  }
}


Measured memory_bytes: 3548
from collections import deque

k=int(input())
v=list(range(k))
stack=deque([1])
inf=float('inf')
visited=[0]*k
dist=[inf]*k
dist[1]=0
while stack:
  v=stack.pop()
  if not visited[v]:
    nv0=10*v%k
    nv1=(v+1)%k
    if dist[nv0]>dist[v]:
      dist[nv0]=dist[v]
      stack.append(nv0)
    if dist[nv1]>1+dist[v]:
      stack.appendleft(nv1)
      dist[nv1]=dist[v]+1
    visited[v]=1
print(dist[0]+1)

Measured memory_bytes: 14760
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<ctype.h>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<math.h>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<stdio.h>
#include<stdlib.h>
#include<streambuf>
#include<string.h>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
using namespace std;
int n;
int a[22];
int main(void){
	char c=getchar();
	while(c>='0'&&c<='9') a[++n]=c-'0',c=getchar();
	bool f=1;
	for (int i=2;i<=n;++i){
		if (a[i]!=9){
			f=0;
			break;
		}
	}
	if (f){
		printf("%d",(n-1)*9+a[1]);
	}
	else{
		printf("%d",(n-1)*9+a[1]-1);
	}
	return 0;
}

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

#define mem(a,n) memset(a,n,sizeof(a))
#define rep(i,a,n) for(int i=a;i<n;i++)

typedef long long ll;
const double eps=1e-5;
const int N=2e5+5;
const int INF=0x3f3f3f3f;
const int dir[4][2]= {1,0,-1,0,0,1,0,-1};

int a[N];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a+1,a+n+1);
    if(n==2)
    {
        printf("%d %d\n",a[n],a[1]);
    }
    else
    {
        int tmp=0;
        int t=0;
        for(int i=1; i<n; i++)
        {
            int tb=min(a[i],a[n]-a[i]);
            if(a[i]!=a[n])
            {
                if(tmp<tb)
                {
                    tmp=tb;
                    t=i;
                }
            }
        }
        printf("%d %d\n",a[n],a[t]);
    }
    return 0;
}


Measured memory_bytes: 640
// C++ program to print all  
// permutations with duplicates allowed  
#include <bits/stdc++.h> 
using namespace std;


// Function to print permutations of string  
// This function takes three parameters:  
// 1. String  
// 2. Starting index of the string  
// 3. Ending index of the string. 
vector<int> arr;
void permute(string a, int l, int r)
{
	
	// Base case  
	if (l == r) {
		int sg = 0;  stringstream aa(a);
		
		aa >> sg;
		arr.push_back(sg);
	}
	else
	{
		// Permutations made  
		for (int i = l; i <= r; i++)
		{

			// Swapping done  
			swap(a[l], a[i]);

			// Recursion called  
			permute(a, l + 1, r);

			//backtrack  
			swap(a[l], a[i]);
		}
	}
}

// Driver Code  
int main()
{
	string str;
	int n; cin >> n;
	for (int i = 1; i <= n; i++) {
		str.append(to_string(i));
	}
	permute(str, 0, n - 1);
	sort(arr.begin(), arr.end());
	int valA = 0; int valB = 0;
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		valA += (a * (int)pow(10, n - i - 1));
	}
	for (int i = 0; i < n; i++) {
		int b; cin >> b;
		valB += (b * (int)pow(10, n - i - 1));
	}
	int diff = find(arr.begin(), arr.end(), valA) - find(arr.begin(), arr.end(), valB);
	if (diff < 0) {
		diff *= -1;
	}
	cout << diff << endl;

	return 0;
}


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


int main()
{
    int t=1;
    //cin>>t;

    while( t-- )
    {
        char c;
        cin>>c;

        if( c>='A' && c<='Z' )
            cout<<"A";
        else
            cout<<"a";
    }
    return 0;
}


Measured memory_bytes: 3592
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<iomanip>
#include<queue>

using namespace std;
#define N 1010
struct node{
	int x,y;
};
char g[N][N];
int vis[N][N];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int n,m;
int bfs(){
	queue<node> Q;
	int i,j,k;
	int depth = 0, tot = 0;
	for(i = 1; i <= n; i++){
		for(j = 1; j <= m; j++){
			if(g[i][j] == '#'){
				node u = {i, j};
				vis[i][j] = 1;
				Q.push(u);
				tot++;
			}
		}
	}
	while(!Q.empty()){
		if(tot == n * m) return depth;
		int len = Q.size();
		while(len--){
			node u = Q.front();
			Q.pop();
			for(i = 0; i < 4; i++){
				int nx = u.x + dx[i];
				int ny = u.y + dy[i];
				if(nx < 1 || ny < 1 || nx > n || ny > m) continue;
				if(vis[nx][ny]) continue;
				node v = {nx, ny};
				Q.push(v);
				vis[nx][ny] = 1;
				tot++;
			}			
		}
		depth++;
	}
	return depth;
}


int main(){
	cin>>n>>m;
	int i,j,k;
	for(i = 1; i <= n; i++){
		scanf("%s", g[i] + 1);
	}
	printf("%d\n", bfs());
	
	return 0;
}


Measured memory_bytes: 13456
import sys, collections
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    N = I()
    A = LI()

    cnt = collections.Counter(A)
    A = list(set(A))
    A.sort()
    A_max = A[-1]
    divisible = [False] * (A_max + 1)

    for i in A:
        for j in range(2 * i, A_max+1, i):
            divisible[j] = True

    ans = 0
    for i in A:
        if not divisible[i] and cnt[i] == 1:
            ans += 1
        
    print(ans)

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 45304
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void solve() {
        string s;
        cin >> s;

        vector<int> lpt, rpt;
        for (int i = 0; i + 1 < s.size(); ++i) {
            if (s[i] == 'R' && s[i + 1] == 'L') {
                rpt.push_back(i);
                lpt.push_back(i + 1);
            }
        }

        vector<int> ans(s.size());

        for (int i = 0; i < s.size(); ++i) {
            if (s[i] == 'R') {
                int nl = *upper_bound(all(lpt), i) - i;
                if (nl % 2) {
                    ans[i + nl - 1]++;
                } else {
                    ans[i + nl]++;
                }
            } else {
                int br = i - *(lower_bound(all(rpt), i) - 1);
                if (br % 2) {
                    ans[i - br + 1]++;
                } else {
                    ans[i - br]++;
                }
            }
        }

        for (int i = 0; i < s.size(); ++i) {
            cout << ans[i] << " ";
        }
        cout << endl;

    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 1596
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] b = Console.ReadLine().Split();
            int A = int.Parse(b[0]); int B = int.Parse(b[1]);
            int an;
            an = A - B + 1;
            Console.Write(an);
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <ctype.h>
using namespace std;
int m,mmin,mmax,check;
int psa,sa;
vector<int> mem;

int main()  {
    while(1) {
        sa = 0;
        cin >> m >> mmin >> mmax;
        if(m==0) break;
        vector<int> mem(m,0);
        for(int i = 0;i < m;i++) {
            cin >> mem[i];
        }
        for(int i = mmin-1;i < mmax;i++) {
            //cout << i << endl;
            psa = mem[i] - mem[i+1];
            //cout << psa ;
            if(psa >= sa) {
                check = i;
                sa = psa;
            }
        }
        cout << check+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3088
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> ump;
typedef pair<ll, ll> P;

ump mp;

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = ump();
#pragma clang diagnostic pop
#endif
        ll a, b, c;
        cin >> a >> b >> c;
        cout << b + min(a + b + 1, c) << endl;


#ifdef MY_DEBUG
    }
#endif
    return 0;
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    int3(a, b, c);
    if (a % 2 + b % 2 + c % 2 >= 2) {
        std::cout << "Hom" << std::endl;
    } else {
        std::cout << "Tem" << std::endl;
    }

    // えすぱあー

    return 0;
}



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

bool is_bingo(vector<vector<bool>> bingo)
{
  for(int i = 0; i < 3; i++)
  {
    int count =  0;
    for(int j = 0; j < 3; j++)
    {
      if(bingo.at(i).at(j))
        count++;
    }
    if(count == 3)
      return true;
  }
  for(int j = 0; j < 3; j++)
  {
    int count = 0;
    for(int i = 0; i < 3; i++)
    {
      if(bingo.at(i).at(j))
        count++;
    }
    if(count == 3)
      return true;
  }
  if(bingo.at(1).at(1))
  {
    if(bingo.at(0).at(0) && bingo.at(2).at(2))
      return true;
    else if(bingo.at(0).at(2) && bingo.at(2).at(0))
      return true;
  }
  return false;
}
int main()
{
  vector<vector<int>> map(3,vector<int>(3));
  for(int i = 0; i < 3; i++)
  {
    for(int j = 0; j < 3; j++)
      cin >> map.at(i).at(j);
  }
  vector<vector<bool>> bingo(3, vector<bool>(3, false));
  int N;
  cin >> N;
  int x;
  bool check = false;
  for(int i = 0; i < N; i++)
  {
    cin >> x;
    for(int i = 0; i < 3; i++)
    {
      for(int j = 0; j < 3; j++)
      {
        if(x == map.at(i).at(j))
          bingo.at(i).at(j) = true;
      }
    }
    if(is_bingo(bingo))
    {
      check = true;
      break;
    }
  }
  if(check)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define ph push
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define btinpct(x) __builtin_popcountll((x))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?b:gcd(b%a,a); }

#define ll long long int 
#define ld long double
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
typedef pair <ll, ll> pi; typedef pair <ll, pi> spi; typedef pair <pi, pi> dpi;

// #define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
// #define cerr if(0)cout
#define MAXN (2006)

ll n, m, x, p[MAXN];
vector<pi> v[MAXN];
vector<spi> e;
void myassert(bool b) {
	if(!b) {
		cout<<945693<<'\n';
		exit(0);
	}
}
struct _ufds {
	int p[MAXN];
	_ufds () { FOR(i,0,MAXN-1) p[i] = i; }
	void merge(ll x,ll y) {
		x=find(x), y=find(y);
		myassert(x>=0&&x<MAXN), myassert(y>=0&&y<MAXN);
		p[x]=y;
	}
	ll find(ll x) { return (p[x]==x)?x:p[x]=find(p[x]); }
	bool same(ll a,ll b) { return find(a) == find(b); }
} ufds;
ll depth[MAXN], up[MAXN];
void dfs(ll x,ll par) {
	p[x]=par;
	for(auto i:v[x]) if(i.f^par) {
		depth[i.f]=depth[x]+1, up[i.f]=i.s, dfs(i.f, x);
	} 
}
ll mod = 1e9+7;
ll qexp(ll x,ll e) {
	if(e==0) return 1;
	ll half=qexp(x,e/2);
	half *= half, half %= mod;
	if(e&1) half*=x, half%=mod;
	return half;
}
int main()
{
	FAST
	cin>>n>>m>>x;
	FOR(i,0,m-1) {
		ll a, b, c; cin>>a>>b>>c;
		e.eb(c, pi(a, b));
	}
	sort(all(e));
	vector<bool> in(5000, 0);
	vector<ll> diff(5000, 0);
	ll mst = 0;
	for(int i=0;i<(int)e.size();++i) {
		ll a=e[i].s.f, b=e[i].s.s;
		if(ufds.same(a,b)) continue;
		ufds.merge(a, b);
		in[i]=1;
		v[a].eb(b, e[i].f);
		v[b].eb(a, e[i].f);
		mst += e[i].f;
	}
	dfs(1, 1);
	function<ll(ll, ll)> go_up=[&](ll x,ll y){
		ll ans = 0;
		while(x^y) {
			if(depth[x]<depth[y]) {
				swap(x,y);
			}
			ans = max(ans, up[x]);
			x=p[x];
		}
		return ans;
	};
	ll D = x-mst, equal=0, upper=0;
	FOR(i,0,siz(e)-1) if(!in[i]) {
		diff[i] = e[i].f-go_up(e[i].s.f, e[i].s.s), assert(diff[i] >= 0);
		if(D == diff[i]) {
			++ equal;
		} else if(D < diff[i]) {
			++ upper;
		}
	}
	if(D < 0) {
		cout<<0<<'\n'; return 0;
	} else if(D == 0) {
		cout << (qexp(2, n-1 + equal) - 2 + mod) % mod * qexp(2, upper) % mod<< '\n';
	} else {
		cout << (qexp(2, equal) - 1 + mod) % mod * qexp(2, upper) % mod * 2 % mod<< '\n';
	}
}
/*
lower, equal, upper
D = X - S
if(D < 0) cout<<0;
else if(D==0) {
	(qexp(2, n-1 + equal) - 1) * qexp(2, upper)  
} else  if(D > 0) {
	(qexp(2, equal) - 1) * qexp(2, upper) * 2
}
*/


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

int main(){
  int n;
  cin>>n;
  vector<int> a;
  int p=1;
  while(a.size()<n){
    bool ok=true;
    for(int i=2;i<=sqrt(10*p+1);i++) 
      if((10*p+1)%i==0) ok=false;
    if(ok) a.pb(10*p+1);
    p++;
  }
  rep(i,n) cout<<a[i]<<" ";
}

Measured memory_bytes: 256
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    reverse(all(s));
    ll n=s.size();
    VV dp(n+1,V(2,1e18));
    dp[0][0]=0;
    rep(i,n){
        ll temp=s[i]-'0';
        chmin(dp[i+1][0],dp[i][0]+temp);
        chmin(dp[i+1][1],dp[i][0]+(10-temp));
        if(temp!=9)chmin(dp[i+1][0],dp[i][1]+(temp+1));
        else chmin(dp[i+1][1],dp[i][1]);
        chmin(dp[i+1][1],dp[i][1]+(10-temp-1));
    }
    cout<<min(dp[n][1]+1,dp[n][0])<<endl;
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	
	int a, b, c; cin >> a >> b >> c;
	long long cnt = 0;
	while(a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
		int x = b / 2 + c / 2;
		int y = a / 2 + c / 2;
		int z = a / 2 + b / 2;
		a = x; b = y; c = z;
		cnt++;
		if(cnt > 1000000){
			cout << -1 << endl;
			return 0;
		}
	}
	cout << cnt << endl;
	return 0;	
}
  

Measured memory_bytes: 256
# include "iostream"
using namespace std;

int main()
{
	int a[10];
	int i, j;

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

	for (i = 1; i < 10; i++)
		for (j = 0; j < 10 - i; j++)
			if (a[j] > a[j + 1]) swap(a[j], a[j + 1]);

			cout << a[9] << endl << a[8] << endl << a[7] << endl;


	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef pair<int,int> pi;
const int MAXN = 1000005;
const int mod = 1e9 + 7;

int n,u,v,ans,has[MAXN],c[MAXN],d[MAXN],root=-1,w[MAXN],mxNode=-1,mxCost=-1,cur;
vector<int> g[MAXN];
string s;

void dfs(int u , int p){
	has[u] = c[u];
	int cnt = (p != -1);
	for(auto v : g[u]){
		if(v==p)continue;
		d[v] = d[u]+1;
		dfs(v,u);
		if(has[v])ans++,cnt^=1;
		has[u] |= has[v];
	}
	w[u] = (cnt!=c[u]);
}
void calc(int u , int p,int dist){
	dist += w[u];
	if(w[u])cur++;
	if(dist > mxCost){
		mxCost = dist;
		mxNode = u;
	}
	for(auto v : g[u]){
		if(v==p || !has[v])continue;
		calc(v,u,dist);
	}
}
int cnt = 0;

int main(){
	cin >> n;
	for (int i = 0; i < n-1; ++i){
		scanf("%d%d",&u,&v);
		g[u].pb(v),g[v].pb(u);
	}
	cin >> s;
	for(int i = 1 ; i <= n ; ++i){
		c[i] = s[i-1]=='W';
		cnt += c[i];
		if(c[i])root = i;
	}
	if(cnt <= 1){
		ans = (cnt == 1);
	}else if(root != -1){
		dfs(root,-1);
		ans *= 2;
		calc(root,-1,0);
		mxCost = -1;
		cur = 0;
		calc(mxNode,-1,0);
		ans -= mxCost;
		ans += (cur-mxCost);
	}
	cout << ans<< endl;
	return 0;
}

Measured memory_bytes: 42112
#include <cstdio>
#include <vector>

using namespace std;

int main() {
	vector <int> sequence;
	int number = 0;
	int size = 0;

	scanf("%d", &size);
	for (int i = 0; i < size; i++) {
		scanf("%d", &number);
		sequence.push_back(number);
	}
	for (int i = 0; i < size; i++) {
		int key = sequence[i];
		int j = i - 1;
		while (j >= 0 && sequence[j] > key) {
			number = sequence[j+1];
			sequence[j+1] = sequence[j];
			sequence[j] = number;
			j--;
		}
		for (int a = 0; a < size-1; a++) {
			printf("%d ", sequence[a]);
		}
		printf("%d\n", sequence[size-1]);
	}
}



Measured memory_bytes: 2720
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
    
def main():
    n, m = LI()
    x = sorted(LI())
    y = sorted(LI())
    ans = 0
    for i in range(len(x)):
        k = i + 1
        ans += (k - 1 - n + k) * x[i]
    ysum = 0
    for j in range(len(y)):
        k = j + 1
        ysum += (k - 1 - m + k) * y[j]
    ans *= ysum
    ans %= mod
    print(ans)

main()



Measured memory_bytes: 101216