akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int D;
    cin >> D;
    ll c[26];
    rep(i, 26) cin >> c[i];
    ll s[D][26];
    rep(i, D){
        rep(j, 26) cin >> s[i][j];
    }
    int pre[26];
    fill(pre, pre+26, -1);
    int t[D];
    rep(i, D){
        ld tmp[26];
        rep(j, 26){
            tmp[j] = s[i][j] + c[j]*(i-pre[j])*((ld)(D-i)/(ld)(26));
        }
        int res = -1;
        ld m = -INF;
        rep(j, 26){
            if(chmax(m, tmp[j])) res = j;
        }
        pre[res] = i;
        t[i] = res;
        //cout << res+1 << endl;
    }
    ll tmp = 0;
    set<int> ids[26];
    rep(i, 26) ids[i].insert(-1);
    rep(i, D){
        //cin >> t[i]; t[i]--;
        tmp += s[i][t[i]];
        pre[t[i]] = i;
        ids[t[i]].insert(i);
        rep(j, 26){
            tmp -= c[j]*(i-pre[j]);
        }
    }
    rep(i, 26) ids[i].insert(D);
    rep(i, D){
        rep(j, 26){
            int d, q;
            //cin >> d >> q;
            d = i, q = j;
            int p = t[d];
            ll ans = tmp-s[d][p]+s[d][q];
            set<int>::iterator it1, it2;
            it1 = ids[p].upper_bound(d);
            it2 = ids[q].upper_bound(d);
            int a1, a2, b1, b2;
            b1 = *it1, b2 = *it2;
            it1--, it1--, it2--;
            a1 = *it1, a2 = *it2;
            ans -= c[p]*(b1-d)*(d-a1);
            ans += c[q]*(b2-d)*(d-a2);
            if(chmax(tmp, ans)){
                t[d] = q;
                ids[p].erase(d);
                ids[q].insert(d);
            }
        }
    }
    rep(i, D) cout << t[i]+1 << endl;
}

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

int main()
{
	int N,M;
	while(cin>>N>>M, N||M)
	{

		vector<int> v[500];
		for(int i=0; i<M; i++)
		{
			int a,b;
			cin>>a>>b;
			v[a-1].push_back(b-1);
			v[b-1].push_back(a-1);
		}

		bool f[500]={0};
		for(int i=0; i<v[0].size(); i++)
		{
			f[v[0][i]]=1;
			for(int j=0; j<v[v[0][i]].size(); j++)
			{
				f[v[v[0][i]][j]]=1;
			}
		}

		int ans=0;
		for(int i=1; i<N; i++)
		{
			if(f[i]) ans++;
		}
		
		cout << ans << endl;
	}
}

Measured memory_bytes: 0
#include<stdio.h>
#define ll long long
ll gcd(ll a,ll b)
{
  if(b==0)
  {
    return a;
  }
  return gcd(b,a%b);
}
int main()
{
  ll n,sum = 0;
  scanf("%lld",&n);
  for(ll i=1;i<=n;i++)
  {
    for(ll j=1;j<=n;j++)
    {
      for(ll k=1;k<=n;k++)
      {
        sum+=gcd(i,gcd(j,k));
      }
    }
  }
  printf("%lld\n",sum);
  return 0;
}


Measured memory_bytes: 1732
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds ;
#define ll long long
#define ld long double
#define pp pair<ll,ll>
#define rep(i,a,b) for(ll i=a;i<b;i+=1)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define sz(a) int((a).size())
#define hell 1000000007
#define f first
#define s second
#define sll(x) scanf("%lld",&x)
#define si(x) scanf("%d",&x)
typedef tree<ll , null_type , less<ll> , rb_tree_tag , tree_order_statistics_node_update > ordered_set ;
ll t = 1 ;
ll a[505][505] ;
bool isopp( ll x , ll y , ll xx , ll yy )
{
    if( a[x][y] == 0 )
        return a[xx][yy]==1;
    else
        return a[xx][yy]==0;
}
void solve()
{
    ll n , m , ans = 0 ;
    cin >> n >> m ;
    ll vis[n+5][m+5] ;
    memset(vis,0,sizeof(vis));
    rep( i , 0 , 505 )
        rep( j , 0 , 505 )
            a[i][j]=hell;
    rep( i , 1 , n + 1 )
    {
        rep( j , 1 , m + 1 )
        {
            char c ;
            cin >> c ;
            a[i][j] = (ll)( c == '#' ) ;
        }
    }
    rep( i , 1 , n + 1 )
    {
        rep( j , 1 , m + 1 )
        {
            if(vis[i][j]==0&&a[i][j]==1)
            {
                ll nb = 0 , nw = 0 ;
                queue<pair<ll,ll> > q ;
                q.push( {i,j} ) ;
                vis[i][j]=1;
                while(!q.empty())
                {
                    ll x , y ;
                    x = q.front().f;
                    y = q.front().s;
                    q.pop();
                    if(a[x][y])
                        nb++;
                    else
                        nw++;
                    if(isopp(x,y,x+1,y)&&vis[x+1][y]==0){
                        vis[x+1][y]=1;
                        q.push({x+1,y});
                    }
                    if(isopp(x,y,x-1,y)&&vis[x-1][y]==0){
                        vis[x-1][y]=1;
                        q.push({x-1,y});
                    }
                    if(isopp(x,y,x,y+1)&&vis[x][y+1]==0){
                        vis[x][y+1]=1;
                        q.push({x,y+1});
                    }
                    if(isopp(x,y,x,y-1)&&vis[x][y-1]==0){
                        vis[x][y-1]=1;
                        q.push({x,y-1});
                    }
                }
                //cout << "nb : " << nb << " nw : " << nw << "\n" ;
                ans+=nb*nw;
            }
        }
    }
    cout<< ans;

}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   // cin>>t;
    while(t--)
        solve() ;
    return 0 ;
}


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

int main () {
	int x;
	cin >> x;
	for (long long i = -500; i < 500; i++) {
		for (long long j = -500; j < 500; j++) {
			long long A = i*i*i*i*i;
			long long B = j*j*j*j*j;
			if (A-B == x) {
				cout << i << " " << j << endl;
				return 0;
			}
		}
	}
}


Measured memory_bytes: 3632
def readln():
    return list(map(int, input().split()))


N, M = readln()
AB = [readln() for _ in range(M)]
A = [ab[0]-1 for ab in AB[::-1]]
B = [ab[1]-1 for ab in AB[::-1]]


class UnionFind:
    def __init__(self, N):
        self.N = N  # ノード数
        # 親ノードをしめす。負は自身が親ということ。
        self.parent = [-1] * N  # idxが各ノードに対応。

    def root(self, A):
        # print(A)
        # ノード番号を受け取って一番上の親ノードの番号を帰す
        if (self.parent[A] < 0):
            return A
        self.parent[A] = self.root(self.parent[A])  # 経由したノードすべての親を上書き
        return self.parent[A]

    def size(self, A):
        # ノード番号を受け取って、そのノードが含まれている集合のサイズを返す。
        return -self.parent[self.root(A)]

    def concat(self, A, B):
        # ノード番号を2つ受け取って、そのノード同士をつなげる処理を行う。
        # 引数のノードを直接つなぐ代わりに、親同士を連結する処理にする。
        A = self.root(A)
        B = self.root(B)

        # すでにくっついている場合
        if (A == B):
            return False

        # 大きい方に小さい方をくっつけたほうが処理が軽いので大小比較
        if (self.size(A) < self.size(B)):
            A, B = B, A

        # くっつける
        self.parent[A] += self.parent[B]  # sizeの更新
        self.parent[B] = A  # self.rootが呼び出されればBにくっついてるノードもすべて親がAだと上書きされる

        return True


ans = [N * (N - 1) // 2]
uni = UnionFind(N)
for a, b in zip(A, B):
    if uni.root(a) == uni.root(b):
        ans.append(ans[-1])
    else:
        ans.append(ans[-1] - uni.size(a) * uni.size(b))
        uni.concat(a, b)

for a in ans[-2::-1]:
    print(a)


Measured memory_bytes: 42092
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int k = scan.nextInt();
		int a = 0;
		int b = 0;
		int minus = 0;
		int[] x = new int[n];
		for (int i = 0; i < n; i++) {
			x[i] = scan.nextInt();
		}
		for (int i = 0; i < n; i++) {
			a = Math.abs(x[i]-0)*2;
			b = Math.abs(x[i]-k)*2;
			minus += Math.min(a, b);
		}
		System.out.println(minus);
	}
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define DEBUG(x) cout << #x << " = " << x << endl
#define pb push_back
#define ff first
#define ss second
using namespace std;
typedef long long ll;


const int MAXN = 200005;

pair <ll, ll> a[MAXN];

int main()
{
    //freopen("input.txt", "r", stdin);

    int n;
    cin >> n;
    ll minr = 1e10;
    ll maxr = -1;
    for (int i = 0; i < n; i++)
    {
        ll x, y;
        cin >> x >> y;
        a[i].ff = min(x, y);
        a[i].ss = max(x, y);
        maxr = max(a[i].ss, maxr);
        minr = min(a[i].ss, minr);
    }

    sort(a, a + n);

    ll ans = ( maxr - minr ) * ( a[n-1].ff - a[0].ff );

    ll r = a[n-1].ff;
    for (int i = 1; i < n; i++)
    {
        r = max(r, a[i-1].ss);
        ans = min(ans, ( maxr - a[0].ff ) * ( r - min(minr, a[i].ff) ));
        if (a[i].ff >= minr) break;
    }

    cout << ans;

    return 0;
}



Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>

typedef long long ll;

using namespace std;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    int A,B,X;cin>>A>>B>>X;
    if(A<=X&&X<=A+B)cout <<"YES"<<endl;
    else cout << "NO"<< endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<bool> visited;
vector<int> ans;
int n;

vector<vector<int>>gr;

void dfs(int v) {
    visited[v] = true;
    for (int u : gr[v]) {
        if (!visited[u])
            dfs(u);
    }
    ans.push_back(v);
}

void topological_sort(vector<vector<int>>g) {
    visited.assign(n+1, false);
    ans.clear();
    gr=g;
    for (int i = 1; i <= n; ++i) {
        if (!visited[i])
            dfs(i);
    }
    reverse(ans.begin(), ans.end());
}

int main() {
	// your code goes here
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	
	int m;
	
	cin>>n>>m;
	int i,j,k;
	int a,b;
	
	vector<vector<int>>g(n+1);
	vector<vector<int>>an(n+1);
	
	int pn[n+1]={0};
	int p[n+1];
	
	for(i=1;i<n+m;i++)
	{
	    cin>>a>>b;
	        g[a].push_back(b);
	        an[b].push_back(a);
	}
	
	topological_sort(g);
	
	map<int,int>mp;
	for(i=0;i<n;i++)
	{
	    mp[ans[i]]=i;
	}
	
	for(i=1;i<=n;i++)
	{
	    a=-1;
	    //cout<<i<<endl;
	    for(int c : an[i])
	    {
	        if(a<mp[c])
	        a=mp[c];
	        
	        //cout<<c<<" : "<<mp[c]<<endl;
	    }
	    if(an[i].size()==0)
	    p[i]=0;
	    else
	    p[i]=ans[a];
	}
	
	
	for(i=1;i<=n;i++)
	{
	    cout<<p[i]<<endl;
	}
	return 0;
	
}


Measured memory_bytes: 26364
import java.util.*;

public class Main {
	public static void main(String[] orgs) {
		Scanner sc = new Scanner(System.in);
		
		String N = sc.next();

		if(N.charAt(0) == N.charAt(1) && N.charAt(1) == N.charAt(2)){
			System.out.println("Yes");
		}else if(N.charAt(1) == N.charAt(2) && N.charAt(2)  == N.charAt(3)){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}
	


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define ts cout<<"ok"<<endl
#define int long long
#define hh puts("")
using namespace std;

inline int read(){
    int ret=0,ff=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-') ff=-ff;ch=getchar();}
    while(isdigit(ch)){ret=(ret<<3)+(ret<<1)+ch-'0';ch=getchar();}
    return ret*ff;
}
signed main(){
	int a=read(),b=read(),c=read();
	printf("%lld",min(a*b,c));
    return 0;
}

Measured memory_bytes: 256
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn main() {
    input! {
        x: isize,
    }
    if x >= 30 {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2112
#include <iostream>
#include <iomanip>

using namespace std;

int main(void){
  int N, K;
  cin >> N >> K;

  int dice_n; // dice of number
  long double pro = 0; // probability
  int score;
  long double half_pro; // 1/2が連続して起こる確率を格納
  for(dice_n=1; dice_n<=N; dice_n++){
    half_pro = 1;
    score = dice_n;
    //scoreがK点以上になるまで2倍し続ける(表を出し続ける確率を考える)
    while(score < K){
      score *= 2;
      half_pro *= 0.5;
    }
    pro += (1/(long double)N)*half_pro;
  }

  cout << setprecision(10) << fixed << pro << endl;
    
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int n, d, min, max;
    long long sum;
    scanf("%d", &n);
    scanf("%d", &d);
    min = d;
    max = d;
    sum = d;
    for(int i = 1; i < n; i++){
        scanf("%d", &d);
        if(d < min){
            min = d;
        }
        if(d > max){
            max = d;
        }
        sum += d;
    }
    printf("%d %d %lld\n", min, max, sum);
    return 0;
}



Measured memory_bytes: 2100
L = sorted(map(int,input().split()))
if L[0] == L[2]:
    print(0)
    exit()
if L[0] == L[1]:
    print(L[2]-L[0])
    exit()
if L[1] == L[2]:
    t = L[2] - L[0]
    print(t//2 if t % 2 == 0 else 2 + t//2)
    exit()
count = L[2] - L[1]
t = L[2] - L[0] - count
print(count + t//2 if t % 2 == 0 else count + 2 + t//2)


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

int main() {
  string a;
  cin >> a;
  if (a[0] == a[1] && a[2] == a[3] && a[0] != a[2]) cout << "Yes" << endl;
  else if (a[0] == a[2] && a[1] == a[3] && a[0] != a[1]) cout << "Yes" << endl;
  else if (a[0] == a[3] && a[1] == a[2] && a[0] != a[1]) cout << "Yes" << endl;
  
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll dp[102][100002];
ll go(ll n,ll mw,vector<ll> &w,vector<ll> &v,ll pos=0)
{
	if(pos==n)
	return 0;
	if(pos>n or mw<0)
	return INT_MIN;
	if(dp[pos][mw]!=-1)
	return dp[pos][mw];
	if(w[pos]>mw)
	return dp[pos][mw]=go(n,mw,w,v,pos+1);
	return dp[pos][mw]=max(v[pos]+go(n,mw-w[pos],w,v,pos+1),go(n,mw,w,v,pos+1));
	
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ll n,s;
  cin>>n>>s;
  vector<ll> w(n),v(n);
  memset(dp,-1,sizeof(dp));
  for(int i=0;i<n;i++)
  {
  	cin>>w[i]>>v[i];
  }
  cout<<go(n,s,w,v)<<endl;
}

Measured memory_bytes: 80000
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

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

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

// {pos, a}, a == 0 for L, a == 1 for R 
vector<pair<int, int>> events;

int solve(const int N, const int M) {
    int ans = 0;
    int pos = 1;
    int i_e = 0;
    int acc = 0;

    while (pos <= N) {
        while (i_e < 2 * M && events[i_e].first == pos) {
            if (events[i_e].second == 0) {
                acc++;
            } else {
                acc--;
            }
            i_e++;
        }
        if (acc == M) {
            ans++;
        }
        // printf("pos: %d, i_e: %d, acc: %d, ans: %d\n", pos, i_e, acc, ans);
        pos++;
    }

    return ans;
}

int main(void) {
    int N, M;
    cin >> N >> M;

    for (int i = 0; i < M; i++) {
        int L, R;
        cin >> L >> R;
        events.push_back({L, 0});
        events.push_back({R + 1, 1});
    }
    sort(events.begin(), events.end());

    cout << solve(N, M) << endl;

    return 0;
}


Measured memory_bytes: 2420
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main(void){
    // Your code here!
    double x1,x2,y1,y2;
    
    scanf("%lf %lf %lf %lf",&x1 ,&y1, &x2, &y2);
    
    
    printf("%f",sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
    
}



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

using namespace std;

#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define mk make_pair

typedef long long LL;
typedef pair<int,int> Interval;

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {
    _for(i,0,v.size()) os << v[i] << " ";
    return os;
}

template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){
    for(typename set<T>::iterator it = v.begin();it != v.end();it++)
    os << *it <<" ";
    return os;
}

const int maxn = 1005;
LL INF = (1LL) << 60;
int N,M;

struct Bellman_ford{
    int n,m;
    struct Edge{
        int from,to,dist;
        Edge(int from,int to,int dist):from(from),to(to),dist(dist){;}
    };
    vector<int> G[maxn];
    //判断进行松弛操作的次数
    int cnt[maxn];
    LL d[maxn];
    int p[maxn];
    //判断是否在queue里
    bool inq[maxn];
    vector<Edge> edges;

    void init(int n){
        this->n = n;
        edges.clear();
        _for(i,0,n) G[i].clear();
    }

    void add_edge(int from,int to,int dist){
        edges.push_back(Edge(from,to,dist));
        m = edges.size();
        G[from].push_back(m-1);
    }

    bool bellman_ford(int s){
        queue<int> Q;
        memset(inq, 0 ,sizeof(inq));
        memset(cnt,0,sizeof(cnt));
        _for(i,0,n) d[i] = INF;
        d[s] = 0;
        inq[s] = true;
        Q.push(s);

        while(!Q.empty()){
            int u = Q.front();Q.pop();
            inq[u] = false;
            for(int i = 0;i < G[u].size();i++){
                Edge& e = edges[G[u][i]];
                if(d[u] < INF && d[e.to] > d[u] + e.dist){
                    d[e.to] = d[u] + e.dist;
                    p[e.to] = G[u][i];
                    if(!inq[e.to]){
                        Q.push(e.to);
                        inq[e.to] = true;
                        if(e.to == n-1 && ++cnt[e.to] > n) return false;
                        if(e.to != n-1 && ++cnt[e.to] > 2*n+1) return true;
                    }
                }
            }
        }
        return true;
    }
};
int main()
{
    cin >> N >> M;
    Bellman_ford bf;
    bf.init(N);

    _for(i,0,M){
        int a,b;
        LL c;
        scanf("%d %d %lld",&a,&b,&c);
        bf.add_edge(a-1,b-1,-c);
    }

    if(bf.bellman_ford(0)){
        printf("%lld\n",-bf.d[N-1]);
    }else{
        printf("inf\n");
    }

    return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;

void solve(ll n)
{
	if(!n) return;
	solve((n-1)/26);
	putchar((n-1)%26 + 'a');
}

int main(void)
{
	ll n;
	scanf("%lld",&n);
	solve(n);
	return 0;
}


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

using namespace std;

bool check(int a) {
  while (a > 9) {
    if (a % 10 - a / 10 % 10 != 1) return false;
    a /= 10;
  }
  return true;
}

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

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

  int ans = -1;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (!check(a[i] * a[j])) continue;
      ans = max(ans, a[i] * a[j]);
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3108
ss = input()
n = 1
w = 1
s = 1
e = 1

if "N" in ss:
  n = -1
if "W" in ss:
  w = -1
if "S" in ss:
  s = -1
if "E" in ss:
  e = -1
if n*s + w*e > 0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
N = int(input())

#隣接リスト
ad = {}
for n in range(N):
    ad[n+1]=[]
    
for n in range(N-1):
    a,b,c = list(map(int,input().split()))
    ad[a].append([b,c])
    ad[b].append([a,c])
    
Query = []
Q,K = list(map(int,input().split()))
for q in range(Q):
    x,y = list(map(int,input().split()))
    Query.append([x,y])

# ダイクストラ（優先度キュー）
import heapq
INF = 10 ** 20

color = {}
for n in range(N):
    color[n+1] = -1
    
dist = {}
for n in range(N):
    dist[n+1] = INF

def dijkstra(start, node_num): 
    HP = []
    dist[start] = 0

    heapq.heappush(HP,[start,0])

    while HP:
        u = heapq.heappop(HP)[0]

        color[u] = 1

        for to, cost in ad[u]:
            if color[to] == -1 and dist[u] + cost < dist[to]:
                dist[to] = dist[u] + cost
                heapq.heappush(HP, (to, dist[to]))
    return dist

start = K
node_num = N
dist = dijkstra(start, node_num)

for x,y in Query:
    print(dist[x]+dist[y])


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

#define int             long long int
#define ld              long double
#define ff              first
#define ss              second
#define mp              make_pair
#define pb              push_back
#define endl            "\n"

#define si              set <int>
#define vi              vector <int>
#define pii             pair <int, int>
#define vpii            vector <pii>
#define mii             map <int, int>
#define que_max         priority_queue <int>
#define que_min         priority_queue <int, vi, greater<int>>

#define loop(i,s,e)     for(int i=s;i<e;i++)
#define rloop(i,e,s)    for(int i=e;i>=s;i--)
#define mset(a,f)       memset(a,f,sizeof(a))


#define M               1000000007
#define sz(x)           ((int) x.size())
#define all(p)          p.begin(), p.end()

#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define Print(a,x,y)    for (int i=x; i<y; i++) cout<< a[i]<< " "; cout << endl

const int inf = INT_MAX;
const long long INF = LLONG_MAX;

inline int power(int a, int b)
{
	int x = 1;
	while (b)
	{
		if (b & 1) x *= a;
		a *= a;
		b >>= 1;
	}
	return x;
}

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...);
}

const int N = 3e5 + 7;
vector <vi > adj(N);

bool vis[N];

int dp[100005][2];
int n;


void solve()
{
	string s;
	cin >> s;
	int n = s.length();
	string ans = "";
	loop(i, 0, n)
	{
		ans += "x";
	}
	cout << ans << endl;
	return;
}

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

	cout << setprecision(9) << fixed;

	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}


	return 0;
}


Measured memory_bytes: 7424
#include<iostream>
#include<algorithm>
using namespace std;
const int mod=998244353;
long long a[100010];
long long n,x;
long long ksm(long long a,long long b){
	long long res=1;
	while(b){
		if(b&1){
			res*=a;
			res%=mod;
		}
		a*=a;
		a%=mod;
		b>>=1;
	}
	return res;
}
 
int main(){
	cin>>n;
	int flag=0;
	cin>>x;
	long long  ans=x;
	if(x!=0) flag=1;
	for(int i=1;i<n;i++){
		cin>>x;
		a[x]++;
		if(x==0) flag=1;
		ans=max(ans,x);
	}
	if(flag){
		cout<<0<<"\n";
	}
	else{
	long long sum=1;
		for(int i=2;i<=ans;i++){
			sum*=ksm(a[i-1],a[i]);
			sum%=mod;
		}
		cout<<sum<<"\n";//printf("%lld\n",sum);
	}
	return 0;
} 

Measured memory_bytes: 1024
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String []args) throws IOException {
    	FastScanner in  = new FastScanner(System.in);
    	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
    	solve(in, out);
    	in.close();
    	out.close();
    }
    static long gcd(long a, long b){ return (b==0) ? a : gcd(b, a%b); }
    static int gcd(int a, int b){ return (b==0) ? a : gcd(b, a%b); }
    static class FastScanner{
	BufferedReader reader;
	StringTokenizer st;
	FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}
	String next(){while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}
	     st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
	String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}
	int    nextInt()   {return Integer.parseInt(next());}
	long   nextLong()  {return Long.parseLong(next());}
	double nextDouble(){return Double.parseDouble(next());}
	char   nextChar()  {return next().charAt(0);}
	int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
	long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}
	int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}
	long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}
	void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}
    }
    
    /********* SOLUTION STARTS HERE ************/
    
    private static void solve(FastScanner in, PrintWriter out){
        int a = in.nextInt();
        int b = in.nextInt();
        
        out.println(Math.max(Math.max(a+b,a-b),a*b));
    }
    
    /************* SOLUTION ENDS HERE **********/
}

Measured memory_bytes: 21204
while 1:
	try:
		h=[input() for i in [1]*5]
		if 1 in h and 2 in h:w=1
		elif 1 in h:w=3
		else:w=2
		for i in h:
			if len(set(h))!=2:print 3
			else:print 1 if i==w else 2
	except:break

Measured memory_bytes: 4208
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using ll = long long;
const ll mod = 1e9+7; int INF=INT_MAX; ll LLINF = 1LL << 60;
const vector<int> d8x = {1, 0, -1, 0, 1, -1, -1, 1}; vector<int> d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<int> d4x = {1, 0, -1, 0}; vector<int> d4y = {0, 1, 0, -1};

//
int main(){
    int r,d,x;
    cin>>r>>d>>x;
    int now=x;
    rep(i,1,11){
        now=now*r-d;
        cout<<now<<endl;
    }
    return 0;
}

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

int main()
{
  int inputN;
  cin >> inputN;
  int i;

  for(i = 9; i > 1 ; i--)
    {
      if(inputN % i == 0)
	{
	  inputN /= i;
	  break;
	}
    }

  if(0 < inputN && inputN < 10)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
        Scanner sc = new Scanner(System.in);
        long X = sc.nextLong();
        sc.close();
        int ans = 0;
        long t = 100;
        double r = 0.01;
        while(t < X){
        	t = t+(long)(t * r);
        	ans++;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 35820
fun main(args: Array<String>) {
    Program().solve()
}

class Program {
    fun solve() {
        val sc = MyScanner()
        val n = sc.nextInt()
        val a = sc.intList()
        val all = n.toLong() * (n + 1) / 2
        // 中央値 m以下の値 M/2強 最小

        fun check(l: Long): Boolean {
            var res = 0L
            // l以下の値を1 以外 -1
            // いままでの累積和見る
            // 現在の累積和 - 累積和 > 0の数
            val bit = FenwickTree(2 * n + 1)
            bit.add(n, 1)
            var sum = 0
            for (i in 0 until n) {
                sum += if (a[i] <= l) 1 else -1
                res += bit.sum(sum + n)
                bit.add(sum + n, 1)
            }
            // println("$all $res $l")
            return res * 2 > all
        }

        var ok = 10000000000L
        var ng = 0L
        while (ok - ng > 1) {
            val mid = (ok + ng) / 2
            if (check(mid)) {
                ok = mid
            } else {
                ng = mid
            }
        }
        println(ok)
    }
}

class FenwickTree(private val size: Int) {
    private val tree = Array(size + 1) { 0 }

    // a[i]にnを加算
    fun add(i: Int, n: Int) {
        var t = i + 1
        while (t <= size) {
            tree[t] += n
            t += (t and (-t))
        }
    }

    // [0,i)の合計を求める
    fun sum(i: Int): Int {
        var result = 0
        var t = i
        while (t > 0) {
            result += tree[t]
            t -= (t and (-t))
        }
        return result
    }
}

class MyScanner() {
    private var index = 0
    private var line = listOf<String>()

    fun next(): String {
        while (line.size <= index) {
            line = readLine()!!.split(' ')
            index = 0
        }
        return line[index++]
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextDouble() = next().toDouble()
    fun nextCharArray() = next().toCharArray()
    fun nextChar() = next()[0]

    fun strList(): List<String> {
        index = line.size
        return readLine()!!.split(' ')
    }

    fun intList() = strList().map { it.toInt() }
    fun longList() = strList().map { it.toLong() }
    fun doubleList() = strList().map { it.toDouble() }
}

Measured memory_bytes: 119484
#include<bits/stdc++.h>
using namespace std;
int main(){
 int N;cin >> N;
 string S = "";
 while(N){
  if(N % 2){
     N--;
     S = '1' + S;
    }
    else{
     S = '0' + S;
    }
    N /= -2;
 }
 if(S == "") S = '0';
 cout << S << endl;
 return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){

    long long int n,a,b,x=0;
    scanf("%lld%lld%lld",&n,&a,&b);
    x+=(n/(a+b))*a;
    if(n%(a+b)>a)x+=a;
    else x+=n%(a+b);
    printf("%lld\n",x);

    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
int main(){
	int L,R,d;
	int a=0;
	scanf("%d %d %d",&L,&R,&d);
	
	for (L;L<=R;L++){
		if(L%d==0){
			a++;
		}
	}
	printf("%d",a);
	
	
	
	return 0;	
	}


Measured memory_bytes: 1704
module IntMap = Map.Make (struct
  type t = int
  let compare = compare
end)

let () = Scanf.scanf "%d %d\n" @@ fun n k ->
  let hs = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun h -> h in
  let dp = Array.make n None in
  let q = ref @@ IntMap.singleton 0 [0] in
  let rec dijkstra () =
    let (w, us) = IntMap.min_binding !q in
    match dp.(n - 1) with
    | Some w' when w' <= w -> w'
    | _ ->
        q := IntMap.remove w !q;
        List.iter (fun u ->
          for v = u + 1 to min (u + k) (n - 1) do
            let c = abs (hs.(u) - hs.(v)) in
            if
              match dp.(v) with
              | None -> true
              | Some w' -> w + c < w'
            then begin
              dp.(v) <- Some (w + c);
              q := IntMap.add (w + c) (v :: try IntMap.find (w + c) !q with Not_found -> []) !q
            end
          done) us;
        dijkstra () in
  Printf.printf "%d\n" @@ dijkstra ()



Measured memory_bytes: 11008
# A - Range Flip Find Route
H,W = map(int,input().split())
INF = 1000000
s = [input() for _ in range(H)]
a = [[INF]*(W+1) for _ in range(H+1)]
for i in range(1,H+1):
    for j in range(1,W+1):
        if (i,j)==(1,1):
            a[i][j] = int(s[0][0]=='#')
        elif i==1:
            a[i][j] = a[i][j-1]+int(s[i-1][j-2]=='.' and s[i-1][j-1]=='#')
        elif j==1:
            a[i][j] = a[i-1][j]+int(s[i-2][j-1]=='.' and s[i-1][j-1]=='#')
        else:
            a[i][j] = min(
                a[i][j-1]+int(s[i-1][j-2]=='.' and s[i-1][j-1]=='#'),
                a[i-1][j]+int(s[i-2][j-1]=='.' and s[i-1][j-1]=='#')
            )
print(a[H][W])

Measured memory_bytes: 3188
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>
 
#define lint long long
#define VI vector<int>
#define VL vector<lint>
#define VB vector<bool>
#define VC vector<char>
#define VS vector<string>
#define VVI vector<VI>
#define VVL vector<VL>
#define rep(i, n) for(int i = 0 ; i < n ; i++)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main(){
    int k, s;
    cin >> k >> s;
    int ans = 0;
    for(int i = 0 ; i <= k ; i++){
        for(int j = 0 ; j <= k ; j++){
            if(0 <= s - (i + j) && s - (i + j) <= k){
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
int32_t main() {
	fast_io();
	int n;
	cin >> n;
	int a[n];
	int sum = 0;
	map <int, int> freq;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		freq[a[i]]++;
		sum += a[i];
	}
	int q;
	cin >> q;
	while (q--)
	{
		int x, y;
		cin >> x >> y;
		if (freq[x] > 0)
		{
			sum -= (freq[x] * x);
			sum += (freq[x] * y);
			freq[y] += freq[x];
			freq[x] = 0;
		}
		cout << sum << "\n";
	}
	return 0;
}

Measured memory_bytes: 10148
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;
int main()
{
  int a, b;
  cin >> a >> b;
  int now = 1;
  int i = 0;
  while (now<b) {
    now += (a-1);
    i++;
  }
  cout << i << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int n,m;
	while(scanf("%d %d",&n,&m) != EOF)
	{
		int ans = 0;
		if(n == 0 && m == 0)
		{
			break;
		}
		for(int i = 1; i < n -1; i++)
		{
			for(int j = i + 1; j < n; j++)
			{
				for(int k = j + 1; k < n + 1; k++)
				{
					if(m == i + j + k)
					{
						ans++;
					}
				}
			}
			
		}
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 2036
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;

int main() {
    int h,w;
    char g[52][52];
    cin >> h >>w;
    for (int k = 0; k <=w+1 ; ++k) {
        g[0][k] = '.';
        g[h+1][k] = '.';
    }
    for (int k = 0; k <=h+1 ; ++k) {
        g[k][0] = '.';
        g[k][w+1] = '.';

    }
    for (int i = 1; i <= h; ++i) {
        for (int j = 1; j <= w; ++j) {
            cin >> g[i][j];
        }
    }
    int x[4] = {1,0,-1,0};
    int y[4] = {0,1,0,-1};
    bool poss = true;
    for (int i = 1; i <= h ; ++i) {
        for (int j = 1; j <= w ; ++j) {
            if(g[i][j] == '#') {
                bool f = false;
                for (int k = 0; k < 4; ++k) {
                    if(g[i+x[k]][j+y[k]] == '#') {
                        f=true; break;
                    }
                }
                if(!f) {
                    poss = false;
                    break;
                }
            }
        }
    }
    if(poss) cout << "Yes";
    else cout << "No";
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i];
    sort(whole(a));
    sort(whole(b));
    sort(whole(c));
    ll ans = 0;
    rep(i, n) {
        auto it1 = lower_bound(whole(a), b[i]);
        ll x1 = it1 - a.begin();
        auto it2 = upper_bound(whole(c), b[i]);
        ll x2 = c.end() - it2;
        ans += x1*x2;
    }
    
    cout << ans << endl;
    return 0;
}


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

int main(){
    int_fast64_t A, B, C;
    scanf("%lld%lld%lld", &A, &B, &C);
    if(A + B > C){
        return 0 & printf("%lld\n", B + C);
    }else{
        return 0 & printf("%lld\n", min(C, A + B + 1) + B);
    }
    return 0;
}

Measured memory_bytes: 256
<?php

while (true) {
	$input = trim(fgets(STDIN));
	$input = explode(" ", $input);
	foreach ($input as $value) {
		$args[] = $value;
		if (count($args) >= 2) {
			break;
		}
	}
	if (count($args) >= 2) {
		break;
	}
}

$s = (string)$args[0];
$k = (int)$args[1];

$result = 1;
$length = strlen($s);
for ($i=0; $i < $length; $i++) { 
	$char = $s[$i];
	if ($k-1 == $i && $char == "1") {
		break;
	}elseif ($char != "1") {
		$result = $char;
		break;
	}
}
echo $result;

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

int desc(const void *a, const void *b) {
  return *(int *)b - *(int *)a;
}

int main(void){
    int i,n,ans=1;
    scanf("%d",&n);
    int d[n];
    for(i=0;i<n;i++){
        scanf("%d",&d[i]);
    }
    qsort(d,sizeof(d)/sizeof(*d),sizeof(*d),desc);
    for(i=0;i<n-1;i++){
        if(d[i]>d[i+1]){
            ans++;
        }
    }
    printf("%d",ans);
    return 0;
}

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

using namespace std;

long long prime = 998244353;

long long pow(long long a, long long r) {
    if (r == 0) return 1LL;
    long long y = pow(a, r/2);
    long long z = (y * y) % prime;
    if (r % 2 == 1) {
        return (a * z) % prime;
    }
    return z;
}

long long inv(long long a) {
    return pow(a, prime-2);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<long long> xs(n+1);
    xs[0] = 1;
    for (int i = 1; i <= n; ++i) {
        xs[i] = ((n-i+1) * xs[i-1]) % prime;
    }
    vector<long long> twos(n+1);
    twos[0] = 1;
    for (int i = 1;i <= n; ++i) {
        twos[i] = (twos[i-1] * 2) % prime;
    }
    long long sum = 0;
    for (int k = n/2 + 1; k <= n; ++k) {
        sum += xs[k] * xs[n-k] % prime * twos[n-k+1];
        sum %= prime;
    }
    sum = (sum * inv(xs[n])) % prime;
    long long result = (pow(3LL, (long long) n) - sum + prime) % prime;
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 156544
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
using Graph = vector<vector<int>>;
using Graphl = vector<vector<ll>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define FOR(itr, v) for (auto itr = (v).begin(); itr != (v).end(); ++itr)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> void PrintVector(const vector<T> &vec) {for (auto val : vec) cout << val << " "; cout << endl;}
const long long INF = 1LL << 60;
const long long minusINF = -(1LL << 40);
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int d, n; cin >> d >> n;
    int ans = 0;
    if (d == 0)
    {
        ans = n;
        if (ans == 100) ans++;
    }
    else if (d == 1)
    {
        ans = n * 100;
        if (ans == 10000) ans += 100;
    }
    else
    {
        ans = n * 1e4;
        if (ans == 1000000) ans += 10000;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
inp = [[int(x) for x in input().split()] for _ in range(int(input()))]
inpsum = sum(map(lambda ij: abs(ij[0]+ij[1]) % 2, inp))
if not (inpsum == len(inp) or inpsum == 0):
    print(-1)
    exit(0)

seeds = ([] if inpsum == len(inp) else [1]) + [1 << i for i in range(0, 32)]
# print(inp)

print(len(seeds))
print(' '.join(map(str, reversed(seeds))))

for x, y in inp:
    for k in reversed(seeds):
        res = ''
        if abs(x) > abs(y):
            if x > 0:
                res = 'R'
                x -= k
            else:
                res = 'L'
                x += k
        else:
            if y > 0:
                res = 'U'
                y -= k
            else:
                res = 'D'
                y += k
        # print((x,y))
        print(res, end='')
    print('')


Measured memory_bytes: 4624
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

vector<int> tree[100001];
bool reached[100001];

ll prem(int x, int y){
	ll tmp = 1;
	for (int i = x; i > x - y; i--){
		tmp *= i;
		tmp %= MOD;
	}
	return tmp;
}

ll dfs(int now, int color, int depth){
	reached[now] = true;
	int coun = 0;
	for (auto x : tree[now]){
		if (reached[x] == false) coun++;
	}
	if (coun == 0) return 1;
	if (coun > color - depth) return 0;
	ll ans = prem(color - depth, coun);
	for (auto x : tree[now]){
		if (reached[x] == false){
			ans *= dfs(x, color, 2);
			ans %= MOD;
		}
	}
	return ans;
}


int main(){
	int n, k;
	cin >> n >> k;
	for (int i = 1; i < n; i++){
		int a, b;
		cin >> a >> b;
		tree[a].push_back(b);
		tree[b].push_back(a);
	}

	cout << k*dfs(1, k, 1)%MOD << endl;
	return 0;
}

Measured memory_bytes: 9344
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n,a,b;
  cin>>n>>a>>b;
  ll ab=a+b;
  ll cu=n/ab*a;
  ll no=n%ab;
  if(no>a){
    cu+=a;
  }
  else{
    cu+=no;
  }
  COUT(cu);
}


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

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<int>> R(H, vector<int>(W));
    vector<vector<int>> B(H, vector<int>(W));
    vector<vector<int>> A(H, vector<int>(W));
    rep(i, H) rep(j, W) cin >> R[i][j];
    rep(i, H) rep(j, W) cin >> B[i][j];
    rep(i, H) rep(j, W) A[i][j] = abs(R[i][j] - B[i][j]);
    bitset<40000> dp[H][W];
    int g = 20000;
    dp[0][0][A[0][0] + g] = 1;
    rep(y, H) rep(x, W) {
        if(y - 1 >= 0) {
            dp[y][x] |= dp[y - 1][x] << A[y][x];
            dp[y][x] |= dp[y - 1][x] >> A[y][x];
        }
        if(x - 1 >= 0) {
            dp[y][x] |= dp[y][x - 1] << A[y][x];
            dp[y][x] |= dp[y][x - 1] >> A[y][x];
        }
    }
    int ans = 1e9;
    for(int i = 0; i < 40000; ++i) {
        if(dp[H - 1][W - 1][i]) {
            ans = min(ans, abs(g - i));
        }
    }
    cout << ans << '\n';
    return 0;
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

template <typename T>
struct StarrySkyTree //calculateはmin(区間加算区間最小)
{
    int n;
    const T ex = 1ll << 60; //dat 初期値(minなので)
    const T em = 0; //lazy 初期値(加算するので)
    vector<T> dat, lazy; //tree本体
    StarrySkyTree(vector<T> v){
        int x = 1;
        int i;
        n = v.size();
        while(x < n) x <<= 1;
        n = x; 
        dat.resize(2*n-1, ex);
        lazy.resize(2*n-1, em);
        for(i = 0;i < v.size();++i){
            dat.at(i + n - 1) = v.at(i);
        }
        for(i = n-2;i >= 0;--i){
            dat.at(i) = calculate(dat.at(2*i+1), dat.at(2*i+2));
        }
    }
    
    T calculate(T a, T b){
        return min(a, b);
    }
    
    void eval(int now){
        if(lazy.at(now) == em) return;
        if(now < n - 1){ //区間最小なので同じ値を足す。
            lazy.at(2*now + 1) += lazy.at(now);
            lazy.at(2*now + 2) += lazy.at(now);
        }
        dat.at(now) += lazy.at(now); //区間最小なので同じ値を足す。
        lazy.at(now) = em;
    }
    
    void update(int a, int b, T x, int now, int l, int r){
        eval(now);
        if(a <= l && r<= b){
            lazy.at(now) += x; //上から書き換える。区間最小なので同じ値を足す。
            eval(now);
        }else if(a < r && l < b){
            update(a, b, x, 2*now + 1, l, (l + r)/2);
            update(a, b, x, 2*now + 2, (l + r)/2, r);
            dat.at(now) = calculate(dat.at(2*now + 1), dat.at(2*now + 2));
        }
    }
    void update(int a, int b, T x){update(a, b, x, 0, 0, n);}
    
    T query(int a, int b){return query_sub(a, b, 0, 0, n);}
    T query_sub(int a, int b, int now, int l, int r){
        eval(now);
        if(r <= a || b <= l) return ex;
        else if(a <= l && r <= b) return dat.at(now);
        else{
            T vl = query_sub(a, b, 2*now + 1, l, (l + r)/2);
            T vr = query_sub(a, b, 2*now + 2, (l + r)/2, r);
            return calculate(vl, vr);
        }
    }
    
    inline T operator[](int a) { return query(a, a + 1); }
    void print() {
        for (int i = 0; i < 2 * n - 1; ++i) {
            cout << (*this)[i];
            if (i != n) cout << ",";
        }
        cout << endl;
    }
};

int main()
{
    ll i,j;
    ll n,q;
    cin >> n >> q;
    vector<ll> a(n, 0);
    StarrySkyTree<ll> seg(a);
    for(i = 0;i < q;++i){
        ll com;
        cin >> com;
        if(com == 0){
            ll s,t,x;
            cin >> s >> t >> x;
            seg.update(s, t+1, x);
        }else{
            ll s,t;
            cin >> s >> t;
            cout << seg.query(s, t+1) << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 8440
#include <bits/stdc++.h>
 
#define itn int
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
 
#define random_shuffle(...) shuffle(__VA_ARGS__, rng)
#define rand() rng()
 
using namespace std;
 
inline int nxt() {
	int x;
	scanf("%d", &x);
	return x;
}
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
	
	int n = nxt();
	int k = nxt();

	int ans = 0;
	for (int i = 0; i < n; ++i) {
		int h = nxt();
		if (h >= k) {
			ans++;
		}
	}

	printf("%d\n", ans);
 
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cmath>
using namespace std;

#define ll long long int
#define ld long long double
#define reps(i,f,n) for(int i=f;i<n;i++)
#define rep(i,n) reps(i,0,n)
#define m1 cout<<"move1"<<endl
#define m2 cout<<"move2"<<endl
#define m3 cout<<"move3"<<endl
#define m4 cout<<"move4"<<endl


int main(){
  ll N,R;
  vector<int> v;
  ll a,b;
  vector<int> c;
  
  while(cin>>N,cin>>R,N != 0 && R != 0){
    rep(i,N)v.insert(v.begin(),i);
    rep(i,R){
      cin>>a>>b;
      for(int i=a-1;i< a+b-1;i++) c.push_back(v[i]);
      v.erase(v.begin() + a - 1, v.begin() + a - 1 + b);
      for(int i=0;i < c.size();i++)v.insert(v.begin()+ i,c[i]);
      c.clear();
    }
    cout<<v[0] + 1 <<endl;
    v.clear();
  }
  return 0;
}
   

Measured memory_bytes: 3116