akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        OutputStream outputStream = System.out;
    	PrintWriter out = new PrintWriter(outputStream);

        int i, n, m, k;
		
      StringTokenizer st = new StringTokenizer(br.readLine());
		n = Integer.parseInt(st.nextToken());
      	m = Integer.parseInt(st.nextToken());
      	
        PriorityQueue<Integer> q = new PriorityQueue<>(Collections.reverseOrder());
        st = new StringTokenizer(br.readLine());
      for(int j=1;j<=n;j++)
      {
        int tmp=Integer.parseInt(st.nextToken());
        q.offer(tmp);
      }
      for(i=1;i<=m;i++)
      {
        int tm=q.poll();
        q.offer(tm/2);
      }
      long sum=0;
      while(!q.isEmpty())
      {
        sum+=q.poll();
      }
      out.print(sum);
	out.flush();
	out.close();
	}
}

Measured memory_bytes: 44884
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n, m;
  cin >> n >> m;
  vector<string> D(m);
  for(int i = 0; i < m; ++i) cin >> D[i];
  vector<int> E(n+2,0), W(n+2,0);
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < m; ++j){
      if(D[j][i] == 'E') ++E[i+1];
      if(D[j][n-1-i] == 'W') ++W[n-i];
    }
    if(i < n){
      E[i+2] += E[i+1];
      W[n-1-i] += W[n-i];
    }
  }
  /*
  for(int i = 0; i < n+2; ++i) cout << E[i] << " ";
  cout << endl;
  for(int i = 0; i < n+2; ++i) cout << W[i] << " ";
  cout << endl;
  */
  int ans = 1000000000, l = -1, r = -1;
  for(int i = 1; i < n+2; ++i){
    if(E[i-1]+W[i] < ans){
      l = i-1;
      r = i;
      ans = E[i-1]+W[i];
    }
  }
  cout << l << " " << r << endl;
  return 0;
}



Measured memory_bytes: 4508
#include <iostream>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  int sum = 0;
  for (int i = 0; i < m; ++i) {
    int a;
    cin >> a;
    sum += a;
  }
  int sur = n - sum;
  cout << (sur < 0 ? -1 : sur) << endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string N; cin >> N;
  int sum = 0;
  for(char C:N) {
    sum += (int)(C-'0');
  }
  cout << ((sum%9)?"No":"Yes") << endl;
}



Measured memory_bytes: 3716
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
#include <iomanip>
#define M_PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;

const int MAX = 200000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
struct edge {
	int t;
	ll cost;
	edge(int _t, ll _cost) : t(_t)
		, cost(_cost) {
	}
};
bool isPrime(int n) {

	if (n == 1) return false;
	for (ll i = 2; i * i <= n; i++)
	{
		if (n % i == 0) return false;
	}
	return true;
}
void Solve() {
	
	int n,m;
	cin >> n >> m;
	bool t[100010];
	fill(t, t + n + 1, 0);
	t[1] = true;
	int box[100010];
	fill(box, box + n + 1, 1);
	for (size_t i = 0; i < m; i++)
	{
		int x, y;
		cin >> x >> y;
		box[x]--;
		box[y]++;
		if (t[x]) {
			t[y] = true;
		}
		if (box[x] == 0) {
			t[x] = false;
		}
	}
	int count = 0;
	for (size_t i = 1; i <= n; i++)
	{
		count += t[i];
	}
	cout << count << endl;
}
int main() {
	Solve();
	return 0;
}



Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i=1; i < (int)(n); i++)
#define rrep(i, n) for (int i=((int)(n)-1); i>=0; i--)
#define rreps(i, n) for (int i=((int)(n)-1); i>0; i--)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using lint = long long;
using p = pair<int, int>;
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; }
#define alpha 26

int main() {
  int N; cin >> N;
  map<vector<int>, lint> mp;
  vector<string> s(N);
  rep (i, N) {
    string str;
    cin >> str;
    vector<int> a(alpha, 0);
    rep (j, str.size()) a[str[j] - 'a'] ++;
    mp[a] ++;
  }

  lint ans = 0;
  for (auto ite=mp.begin(); ite != mp.end(); ite++) {
    lint sec = ite->second;
    ans += sec * (sec - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 19840
package main

import "fmt"

func main() {
	var n, a, b int
	fmt.Scan(&n, &a, &b)
	hs := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&hs[i])
	}

	ng, ok := 0, int(1e9)
	for ok-ng > 1 {
		mid := (ok + ng) / 2
		if check(hs, mid, a, b) {
			ok = mid
		} else {
			ng = mid
		}
	}

	fmt.Println(ok)
}

func check(hs []int, k, a, b int) bool {
	cnt := 0
	for _, h := range hs {
		h -= b * k
		if h <= 0 {
			continue
		}

		d := a - b
		c := (h + (d - 1)) / d
		cnt += c
	}
	return cnt <= k
}


Measured memory_bytes: 6312
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#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;

#define SORT(c) sort((c).begin(),(c).end())
#define ANS(ans) cout<<(ans)<<endl;
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
typedef vector<int> VI;


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



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

	if (n == 1) {
		ANS("Hello World");
	}
	else {
		cin >> a >> b;
		ANS(a + b);
	}


	return 0;
}



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

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

    vector<long long> A(N);
    vector<long long> B(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> B[i];
    }

    long long sumA, sumB;
    sumA = 0;
    sumB = 0;
    for (int i = 0; i < N; i++) {
        sumA += A[i];
        sumB += B[i];
    }

    if (sumA < sumB) {
        cout << "-1" << endl;
    }
    else {
        vector<long long> sa(N);
        long long res = 0;
        long long cnt = 0;
        for (int i = 0; i < N; i++) {
            sa[i] = A[i] - B[i];
            if (sa[i] < 0) {
                res += abs(sa[i]);
                cnt++;
            }
        }
        sort(sa.begin(), sa.end());
        reverse(sa.begin(), sa.end());

        if (cnt == 0) {
            cout << 0 << endl;
        }
        else {
            long long add = 0;
            for (int i = 0; i < N; i++) {
                add += sa[i];
                cnt++;
                if (add >= res) {
                    cout << cnt << endl;
                    break;
                }
            }
        }
    }
}

Measured memory_bytes: 2560
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
using namespace std;

int main(){
    int n;
    cin >> n;
    int mini = 1000000;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        int cnt = 0;
        while(a%2 == 0){
            a /= 2;
            cnt++;
        }
        mini = min(mini,cnt);
    }
    cout << mini << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        boolean[] ac = new boolean[n];
        int[] wa = new int[n];
        for(int i=0; i<n; i++) {
            ac[i] = false;
            wa[i] = 0;
        }
        for(int i=0; i<m; i++) {
            int p = in.nextInt()-1;
            boolean isAC = (in.next().equals("AC"));
            if(ac[p]) {
                // 既にAC
                continue;
            }
            if(isAC) {
                ac[p] = true;
            }
            else {
                wa[p]++;
            }
        }
        int account = 0;
        int wacount = 0;
        for(int i=0; i<n; i++) {
            if(ac[i]) {
                account++;
                wacount += wa[i];
            }
        }
        System.out.print(account);
        System.out.print(' ');
        System.out.println(wacount);
    }
}


Measured memory_bytes: 63352
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include <string>
#include <math.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;
int main(){
  int n,p; cin >>n>>p;
  vector<int> a(n);
  cinf(n,a);
  int odd=0;
  for(int i=0;i<n;i++){
    if(a[i]%2==1)odd++;
  }
  if(odd==0&&p==1){
    cout << 0 << endl;
  }
  else if(odd==0&&p==0){
    ll ans=pow(2,n);
    cout << ans << endl;
  }
  else{
    ll ans=pow(2,n-1);
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static class C implements Comparable<C>{
		int num;
		int length;
		
		C(int num, int a, int b) {
			this.num = num;
			this.length = a + b;
		}

		public int compareTo(C o) {
			return o.length - this.length;
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n;
		C c[];
		
		while (true) {
			n = sc.nextInt();
			if (n == 0) {
				break;
			}
			
			c = new C[n];
			for (int i = 0; i < n; i++) {
				c[i] = new C(sc.nextInt(), sc.nextInt(), sc.nextInt());
			}
			
			Arrays.sort(c);
			System.out.println(c[0].num + " " + c[0].length);
		}
	}
}

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

using namespace std;

#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second

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

ll modpow(ll a, ll b){

    ll ans=1;
    while(b){
        if(b&1){
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b=b/2;
    }
    return ans;
}

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    
    int n;
    cin>>n;

    vector<int> inp;

    for(int i = 0; i < n; i++) {
        int l;
        cin>>l;
        inp.push_back(l);
    }

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

    int ans = 0;

    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            int x = inp[i] + inp[j];

            int ind = int((inp.end())-(lower_bound(inp.begin(), inp.end(), x)));
            ind = (n-1-j-ind);
            ans += ind;
        }
    }

    cout<<ans<<endl;


}


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

using namespace std;
int main() {
  int n;
  cin >> n;
  int x1 = ceil(n / 1.08);
  int x2 = floor(n / 1.08);

  int new_n1 = x1 * 1.08;
  int new_n2 = x2 * 1.08;
  if (new_n1 == n) {
    cout << x1 << endl;
  } else if (new_n2 == n) {
    cout << x2 << endl;
  } else {
    cout << ":(" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let mut seq = vec![0; n];
    for i in 0..n {
        seq[i] = read::<usize>();
    }
    let mut ans = 0;
    for i in 0..n {
        while seq[i] > 0 {
            ans += 1;
            for j in i..n {
                if seq[j] == 0 {
                    break;
                }
                seq[j] -= 1;
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
def main():
    from fractions import gcd
    from functools import reduce
    def lcm(c,d):
        return c//gcd(c,d)*d
    mod=1000000000+7
    n=int(input())
    a=[int(i) for i in input().split()]
    l=reduce(lcm,a)
    ans=sum(map(lambda x:l//x,a))
    print(ans%mod)
main()


Measured memory_bytes: 6100
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
	int n;
	cin >> n;
	long t;
	cin >> t;
	long a[n];
	rep(i,0,n)
		cin >> a[i];
	
	long l = a[0] ,r,d = -1;
	int c=1;
	
	rep(i,1,n){
		r = a[i];
		long td = r-l;
		if( td >= 0 ){
			if( td > d ){
				c = 1;
				d = td;
			}
			else if( td == d ){
				c++;
			}
		}
		else{
			l = r;
		}

	}
	
	P(c);

	ret 0;
}

Measured memory_bytes: 1024
package main

import (
	"math"
	"fmt"
	"strconv"
)

func main() {

	var a, b string
	fmt.Scan(&a, &b)
	c, _ := strconv.ParseFloat(a+b, 64)
	s := math.Sqrt(c)
	if math.Trunc(s) == s {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}


Measured memory_bytes: 512
a=gets.chomp
b=gets.chomp
if a.size<b.size
  puts "LESS"
  exit
elsif a.size>b.size
  puts "GREATER"
  exit
end
a.size.times do |i|
  if a[i].to_i<b[i].to_i
    puts "LESS"
    exit
  elsif a[i].to_i>b[i].to_i
      puts "GREATER"
      exit
  end
end
puts "EQUAL"

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

typedef long long int llint;

int main()
{
  int n;
  int a[2][101] = {};
  int mx = 0;

  cin>> n;
  for(int i = 0; i < 2; i++) {
    for(int j = 1; j <= n; j++) {
      cin>> a[i][j];
      a[i][j] += a[i][j - 1];
    }
  }
   
  for(int i = 1; i <= n; i++) {

    mx = max(mx, a[0][i] + a[1][n] - a[1][i - 1]);
  
  }
  
  cout<< mx <<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int h, w;
char a[1005][1005];

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

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

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

    vector<vector<long long>> dp(h + 1, vector<long long>(w + 1));
    int i = 0;
    while (a[i][0] == '.') {
        dp[i][0] = 1;
        i++;
    }
    i = 0;
    while (a[0][i] == '.') {
        dp[0][i] = 1;
        i++;
    }

    for (int i = 1; i < h; i++) {
        for (int j = 1; j < w; j++) {
            if (a[i][j] == '#') continue;
            dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
            dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
        }
    }

    cout << dp[h - 1][w - 1] << '\n';

}


Measured memory_bytes: 9088
#include<stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main(){
	
	int n[47];
	n[0]=0;
	n[1]=1;n[2]=2;

	for(int i=3;i<=45;i++)
		n[i]=n[i-1]+n[i-2];
	int x;
	cin>>x;
	cout<<n[x]<<endl;
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <utility>
#include <cstdio>
using namespace std;

void insertionSort(int A[], const int n, const int g, int *cnt)
{
    for( int i = g; i < n; ++i ){
        int tmp = A[i];
        int j = i - g;
        while( -1 < j && tmp < A[j] ){
            //cout << A[j+g] << "<-->" << A[j] << endl;
            A[j+g] = A[j];
            j = j - g;
            ++*cnt;
        }
        A[j+g] = tmp;
    }
}

void shellSort(int A[], const int n)
{
    int cnt = 0;
    int m;
    int G[100];
    for( int i = 0; i < 100; ++i ){
        if( i == 0 ) G[i] = n / 2 + 1;
        else G[i] = G[i-1] / 2 - 1;
        if( G[i] < 0 ){
            G[i-1] = 1;
            G[i] = 0;
            m = i;
            break;
        }
    }

    for( int i = 0; i < m; ++i )
        insertionSort(A, n, G[i], &cnt);

    //??????
    printf("%d\n", m);
    for( int i = 0; i < m; ++i ){
        if( i ) printf(" ");
        printf("%d", G[i]);
    }
    printf("\n%d\n", cnt);
    for( int i = 0; i < n; ++i )
        printf("%d\n", A[i]);
}

int main()
{
    //??\???
    int n;
    scanf("%d", &n);
    int A[n];
    for( int i = 0; i < n; ++i )
        scanf("%d", &A[i]);

    //?????§????????????
    shellSort(A, n);

    return 0;
}

Measured memory_bytes: 7108
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

#define INF 1e9+7

int main() {
    int N, K;
    string S;
    cin >> N >> K >> S;

    S[K-1]=tolower(S[K-1]);
    cout << S;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;
const int INF=1e9;

int main(){
    int a, b, c, d;
    cin>>a>>b>>c>>d;
    cout<<(a-c)*(b-d)<<endl;
    
}


Measured memory_bytes: 256
k = int(input())

from collections import *
arr = deque(list(range(1,10)))

x = 0
for i in range(k):
    x = arr.popleft()
    if x % 10 != 0:
        arr.append(10*x - 1 + x%10)
    arr.append(10*x + x%10)
    if x % 10 != 9:
        arr.append(10*x + 1 + x%10)

print(x)


Measured memory_bytes: 40816
#include <bits/stdc++.h>
using namespace std;
void debug() {cout<<endl;}
template<typename T,typename... Args>
void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}
#define forn(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
#define F first
#define S second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;

const int N = 1e5+5;
int dp[N], ans[N], n, M;
vector<int> g[N];

int add(int a, int b){
  if(1ll*a + b >= M)return 1ll*a+b-M;
  return a+b;
}

int mult(int a, int b){
  if(1ll*a*b >= M)return (1ll*a*b) % M;
  return a*b;
}

int f(int u, int p){
    int &ans = dp[u];
    if(ans != -1)return ans;
    ans = 1;
    for(int v: g[u]){
        if(v == p)continue;
        int aux = add(f(v, u), 1);
        ans = mult(ans, aux);
    }
    return ans;
}


void reroot(int u, int p, int upch){
  dp[u] = mult(dp[u], add(upch, 1));
  int sz = g[u].size();
  vector<int> PRE(sz), SUF(sz);
  forn(i, 0, sz){
    int v = g[u][i];
    if(v != p)PRE[i] = dp[v];
    PRE[i] = add(PRE[i], 1);
    if(i) PRE[i] = mult(PRE[i-1], PRE[i]);
  }
  for(int i = sz-1; i >= 0; i--){
    int v = g[u][i];
    if(v != p)SUF[i] = dp[v];
    SUF[i] = add(SUF[i], 1);
    if(i+1 < sz)SUF[i] = mult(SUF[i+1], SUF[i]);
  }
  forn(i, 0, sz){
    int v = g[u][i];
    if(v == p)continue;
    int nxt = add(upch, 1);
    if(i)nxt = mult(nxt, PRE[i-1]);
    if(i+1 < sz) nxt = mult(nxt, SUF[i+1]);
    reroot(v, u, nxt);
  }
}

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

  int u, v;
  cin >> n >> M;

  forn(i, 0, n-1){
    cin >> u >> v;
    u--, v--;
    g[u].pb(v);
    g[v].pb(u);
  }
  memset(dp, -1, sizeof dp);
  f(0, -1);
  reroot(0, -1, 0);

  forn(i, 0, n)cout << dp[i] << endl;

}





Measured memory_bytes: 20808
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<iomanip>

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
const int INF = numeric_limits<int>::max();
const ll LLINF = numeric_limits<ll>::max();
const double PI = acos(-1.0);

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, a, n) for (int i = a; i <= (n); ++i)

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

    if (N % K == 0) cout << 0 << endl;
    else cout << 1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<stack>
#include<set>
using namespace std;
#define pb push_back
#define POP pop_back()
#define ll long long
#define db double
#define POP pop_back()
#define endl '\n'
#define PII pair<int,int>
#define FI first
#define SE second
#define VI vector<int>
#define QI queue<int>
#define SI stack<int>
#define debug cout<<"debug"<<endl;
#define PLL pair<LL,LL>
#define PDD pair<double,double>
#define ULL unsigned long long
#define fo(i,a,b) for (int i=a;i<=b;++i)
#define fd(i,a,b) for (int i=a;i>=b;--i)
#define mem(x,a) memset(x,a,sizeof(x))
const int maxn = 2e5 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int main(){
	int a , b , c;
	cin >> a >> b >> c;
	swap(a , b) , swap(a , c);
	cout << a << " " << b << " " << c << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for (int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for (int (i) = (a) - 1; (i) >= (b); (i)--)
#define PI acos(-1.0)
#define DEBUG(C) cout<< C <<endl;
#define VI vector <int>
#define VII vector <VI>
#define VL vector <LL>
#define VLL vector <VL>
#define VD vector <double>
#define VDD vector <VD>
#define PII pair <int, int>
#define PDD pair <double, double>
#define PLL pair <LL, LL>
#define VPII vector <PII>
#define ALL(a) ((a).begin(), (a).end())
#define SORT(a) sort(ALL(a))
#define REVERSE(a) reverse(ALL(a))
#define MP make_pair
#define EP emplace_back
#define FORE(a, b) for (auto &&a:b)
#define FIND(s, n) (s.find(n) != s.end())

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 1e9;
const int MOD = INF + 7;

VI a;

int main(void) {
    int N; cin >> N;
    a.resize(N + 1);
    REP(i, N) cin >> a[i + 1];
    int cnt = 0;
    REP(i, N) {
        if (i + 1 == a[a[i  + 1]]) {
            cnt++;

        }
    }
    cout << cnt/ 2 << endl;
}


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

namespace AtCoder_Cs
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] line = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            string ans = "No";
                if(line[2] >= line[0] && line[2] <= line[1])
            {
                ans = "Yes";
            }

            Console.WriteLine($"{ans}");
            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

//monoid,結合律が成り立ち,単位元が存在するものに対しての演算をクエリに対してO(logn)で
//1-indexed  n(親)->2n,2n+1(子)  k(子)->k/2(親)
template<typename Monoid>
struct SegmentTree{
    using F = function< Monoid(Monoid, Monoid) >;
    //sz:size->完全二分木なのでszはnよりも大きい最小の2のべき乗数
    int sz;
    vector<Monoid> seg;
 
    const F f;
    const Monoid M1;
    SegmentTree(int n,const F f,const Monoid &M1) : f(f), M1(M1) {

    sz=1;
    while(sz<n) sz<<=1;
    seg.assign(2*sz, M1);
    }
 
    void set(int k, const Monoid &x){
        seg[k+sz] = x;
    }
 
    void build(){
        for(int k=sz-1;k>0;k--){
        seg[k]=f(seg[2*k+0], seg[2*k+1]);
        }
    }
 
    void update(int k,const Monoid &x){
        k+=sz;
        seg[k]=x;
        
    while(k>>=1){
        seg[k]=f(seg[2*k+0],seg[2*k+1]);
        }
    }
    //query聞くときは区間は[a,b)で(a<=x<b)
    Monoid query(int a, int b) {
        Monoid L=M1,R=M1;
        for(a+=sz,b+=sz;a<b;a>>=1,b>>=1){
            if(a&1) L=f(L, seg[a++]);
            if(b&1) R=f(seg[--b], R);
        }
        return f(L,R);
    }   
    Monoid operator[](const int &k) const{
        return seg[k+sz];
    }
};
//RMQ
ll f(ll a,ll b){if(a>b) return b;else return a;}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    ll n,m;cin>>n>>m;
    vector<pair<pair<ll,ll>,ll>> v;
    rep(i,m){
        ll l,r,c;cin>>l>>r>>c;l--,r--;
        v.push_back( make_pair(make_pair(l,r),c ));
    }
    sort(ALL(v));//左端ソート

    SegmentTree<ll> seg(n,f,LINF);
    seg.set(0,0ll);
    seg.build();
    vector<ll> dp(n,INF);
    //左から埋まるに決まってるんだからそのindexを持つ．
    dp[0]=0;
    rep(i,m){
        auto now=v[i];
        ll l=now.first.first,r=now.first.second,cost=now.second;
        ll mini=seg.query(l,r+1);
        if(mini==LINF) continue;
        if(seg[r]>mini+cost) seg.update(r,mini+cost);
    }
    cout<<(seg[n-1]>=LINF?-1:seg[n-1])<<endl;
    return 0;
}


Measured memory_bytes: 5872
#include <bits/stdc++.h>
using namespace std;
signed main(){
    int k , n , a[1000005] , m;
    cin >> k >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    
    m = 0;
    
    for(int i=1;i<n;i++){
        m = max(m , a[i] - a[i-1]);
    }
    
    m = max(m , k - a[n-1] + a[0]);
    
    cout << k - m << endl;
    return(0);
}

Measured memory_bytes: 3072
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }

#define INF 1 << 30
int t[100][100];
int main() {
	ll X, l, r, k, m;
	cin >> X;
	k = (ll)sqrt(X);
	rep(i, 1ll, k + 1) {
		if (X % i == 0) {
			rep(l, 0ll, X) {
				r = power(l, 5) - power(l - i, 5);
				if (l >= i && r > X)break;
				if (r == X) {
					printf("%lld %lld\n", l, l - i);
					return 0;
				}
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3716
#include<iostream>
#include <stdio.h>
using namespace std;
  
int main(){
	while(1){
	int n;
	cin>>n;
	int counta=0;
	int countb=0;
	int a[10000],b[10000];
	if(n==0)break;
	for(int i=0;i<n;i++){
	cin>>a[i]>>b[i];
	if(a[i]>b[i]){
		counta+=a[i]+b[i];}else
			if(a[i]==b[i]){counta+=a[i];
		countb+=a[i];}else{countb+=a[i]+b[i];}}
	cout<<counta<<" "<<countb<<endl;}
	return 0;}


Measured memory_bytes: 1236
#include<iostream>

#include<cmath>
#include<string>
#include <algorithm> 

using namespace std;

# define p(s) cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) cout << (j ? "Yes" : "No") << endl;

string lpad(string l,int s,int n){
    string temp = to_string(n);
    string res = "";
    int loop = s - temp.size();
    while(loop--) res+=l;

    return res+temp;
}

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

    if (r < 1200) p("ABC")
    else if (r < 2800) p("ARC")
    else p("AGC")
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()

#define endl "\n"
#define pb push_back
#define elif else if
#define cout_db cout << fixed

#define MOD 1000000007
#define PI 3.1415926
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};

typedef long long ll;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	string s;
	cin >> s;

	/*
	int cnt[26] = {0};
	for (int i = 0; i < s.size(); i++) {
		cnt[s[i]-97]++;
	}

	int max = -1;

	for (int i = 0; i < 26; i++) {
		if(cnt[i] > max){
			max = cnt[i];
		}
	}

	if(max == 1){
		cout << s.size() / 2 << endl;
		return 0;
	}
	*/

	int ans = 114514;
	for (char i = 'a'; i <= 'z'; i++) {
		int count = 0, mxcnt = -1;
		for (int j = 0; j < s.size(); j++) {
			if(s[j] == i){
				if(count > mxcnt) mxcnt = count;
				count = 0;
			} else {
				count++;
			}
		}
		if(count > mxcnt) mxcnt = count;

		if(mxcnt < ans) ans = mxcnt;
	}

	cout << ans << endl;

	/*

	int cnta = 0, mxcnt = -1;
	bool find = 0;
	for (int i = 0; i < s.size(); i++) {
		if(!find and s[i] == max.first){
			cnta = 0;
			find = 1;
			continue;
		}
		if(s[i] == max.first){
			if(cnta > mxcnt) mxcnt = cnta;
			cnta = 0;
		} else {
			cnta++;
		}
	}

	cout << mxcnt << endl;

	*/

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>

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

	std::vector<int> d(n);
	for(int i = 0; i < n; ++i){
		std::cin >> d.at(i);
	}

	std::set<int> values;
	for(int i = 0; i < n; ++i){
		values.insert(d.at(i));
	}

	std::cout << values.size() << std::endl;

	return 0;
}


Measured memory_bytes: 256
import sys
n = int(input())

for i in range(1, 3501):
    for j in range(1, 3501):
        if 4*i*j-n*i-n*j > 0:
            if (n*i*j)%(4*i*j-n*i-n*j) == 0:
                print(i, j, n*i*j//(4*i*j-n*i-n*j))
                sys.exit()

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


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    int k,t;
    cin>>k>>t;
    int a[t];
    int ma =0;
    for(int i=0;i<t;i++){
        cin>>a[i];
        ma = max(ma,a[i]);
    }
    if(ma<=k/2){
        cout << 0 << endl;
        return 0;
    }
    ma -= k-ma;
    cout << ma-1 << endl;

    
}

Measured memory_bytes: 256
#include <iostream>
#include "string"
#define REP(i, n) for(int i=0;i<n;++i)

typedef long long ll;
using namespace std;
int main(){
    string s;
    cin >> s;

    for(int i=0;i<s.length();i++){
        cout << "x";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main () {
  int N;
  cin >> N;
  vector<ll>A(N);
  vector<ll>B(N);
  vector<pair<ll, int>>C(N);
  for (int i = 0; i < N; i ++) {
    cin >> A[i] >> B[i];
    C[i] = make_pair(A[i] + B[i], i);
  }
  sort(C.begin(), C.end());
  ll ans = 0;
  for (int i = 0; i < N; i ++) {
    int k = N - i - 1;
    int j = C[k].second;
    if (i % 2 == 0) {
      ans += A[j];
    }
    else {
      ans -= B[j];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 6408
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdint>
using namespace std;

int main() {
    uint32_t n, m, k;
    cin >> n >> m >> k;

    vector<uint64_t> a(n + 1), b(m + 1);
    for (auto it = a.begin() + 1; it != a.end(); ++it) {
        uint64_t in; cin >> in;
        *it = *(it - 1) + in;
    }
    for (auto it = b.begin() + 1; it != b.end(); ++it) {
        uint64_t in; cin >> in;
        *it = *(it - 1) + in;
    }

    uint32_t ans = 0;
    uint32_t best = m;
    for (uint32_t i = 0; i <= n; ++i) {
        if (k < a[i]) break;

        uint32_t j = best;
        do {
            if (b[j] <= k - a[i])break;
        } while (j-- != 0);
        best = j;
        ans = max(ans, i + j);
    }

    cout << ans << endl;
}



Measured memory_bytes: 6428
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 666666
int n,m; pii ps[SZ];
int M=262144,M2=M+M,ls[SZ],rs[SZ];
int mi[SZ],tag[SZ];
void build()
{
    for(int i=M+1;i<=M+M;i++) ls[i]=rs[i]=i-M;
    for(int i=M-1;i;i--) ls[i]=ls[i+i], rs[i]=rs[i+i+1],
	mi[i]=min(mi[i+i],mi[i+i+1]);
}
void pd(int x)
{
    if(tag[x])
    {
    	mi[x]+=tag[x];
        if(x+x<=M2) tag[x+x]+=tag[x], tag[x+x+1]+=tag[x];
        tag[x]=0;
    }
}
void upd(int x)
{
    pd(x+x); pd(x+x+1);
    mi[x]=min(mi[x+x],mi[x+x+1]);
}
void edit(int x,int ql,int qr,int v)
{
    if(x>M2||ql>qr) return;
    pd(x);
    if(ql==ls[x]&&qr==rs[x]) {tag[x]+=v; return;}
    int mid=ls[x]+rs[x]>>1;
    edit(x+x,ql,min(qr,mid),v);
    edit(x+x+1,max(mid+1,ql),qr,v);
    upd(x);
}
int qmin(int x,int ql,int qr)
{
    if(x>M2||ql>qr) return 1e9;
    pd(x);
    if(ql==ls[x]&&qr==rs[x]) return mi[x];
    int mid=ls[x]+rs[x]>>1;
    int ans=min(qmin(x+x,ql,min(qr,mid)),
	qmin(x+x+1,max(mid+1,ql),qr));
    upd(x); return ans;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		int l,r;
		scanf("%d%d",&l,&r);
		ps[i].fi=l; ps[i].se=r;
	}
	sort(ps+1,ps+1+n);
	memset(mi,127/3,sizeof mi);
	for(int i=1;i<=m+1;i++)
		mi[i+M]=m-i+1;
	build(); int ans=min(n,m);
	for(int i=1;i<=n;i++)
	{
		edit(1,ps[i].se+1,m+1,1);
		ans=min(ans,n-i+ps[i].fi+qmin(1,1,m+1));
	}
	printf("%d\n",n-ans);
}

Measured memory_bytes: 12032
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

int di[4] = { 1,0,-1,0 };
int dj[4] = { 0,1,0,-1 };

signed main() {
	cout << fixed << setprecision(8);
	for (int n; cin >> n&&n;) {
		char s, t, b; cin >> s >> t >> b;
		double f[3][3] = {};
		double g[3][3] = {};
		pii S, T, B;
		S = pii((s - 'A') / 3, (s - 'A') % 3);
		T = pii((t - 'A') / 3, (t - 'A') % 3);
		B = pii((b - 'A') / 3, (b - 'A') % 3);
		f[S.first][S.second] = 1;
		while (n--) {
			rep(i, 0, 3)rep(j, 0, 3)g[i][j] = 0;
			swap(f, g);
			rep(a, 0, 3) rep(b, 0, 3) {
				int cnt = 0;
				rep(i, 0, 4) {
					if (a + di[i] == B.first&&b + dj[i] == B.second) continue;
					if (0 > a + di[i] || a + di[i] > 2)continue;
					if (0 > b + dj[i] || b + dj[i] > 2)continue;
					f[a + di[i]][b + dj[i]] += g[a][b] / 4;
					cnt++;
				}
				f[a][b] += (g[a][b] / 4)*(4 - cnt);
			}
		}
		cout << f[T.first][T.second] << endl;
	}
	return 0;
}

Measured memory_bytes: 3268
n = int(input())
l = list(map(int, input().split()))
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        for k in range(j + 1, n):
            x, y, z = sorted([l[i], l[j], l[k]])[::-1]
            if x != y and y != z and z != x and y + z > x:
                ans += 1
print(ans)

Measured memory_bytes: 9200
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

vector<ll> sil(3000000);

ll Pot(ll p, ll w)
{
    if (w == 0)
        return 1;
    if (w % 2 == 0)
    {
        ll pol = Pot(p, w / 2);
        return pol * pol % MOD;
    }
    return Pot(p, w - 1) * p % MOD;
}

ll Inv(ll x)
{
    return Pot(x, MOD - 2);
}

ll C(ll n, ll k)
{
    return ((sil[n] * Inv(sil[k])) % MOD * Inv(sil[n - k])) % MOD;
}

int main()
{
    ios_base::sync_with_stdio(0);
    sil[0] = 1;
    for (ll i = 1; i < 3000000; ++i)
        sil[i] = (sil[i - 1] * i) % MOD;
    ll a, b;
    cin >> a >> b;
    ll odp = 0;
    for (ll dw = 0; 2 * dw <= a; ++dw)
    {
        ll je = a - 2 * dw;
        if (dw + 2 * je != b)
            continue;
        odp = (odp + C(je + dw, dw)) % MOD;
    }
    cout << odp;
    return 0;
}


Measured memory_bytes: 23680
#include <iostream>

using namespace std;

#define MAX 100005
#define NIL -1


//采用左子右兄弟表示法
struct Node {
    int p, l, r;
};

Node T[MAX];

int n, D[MAX];

void printNode(int u) {
    int i, c;
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "depth = " << D[u] << ", ";

    if (T[u].p == NIL) cout << "root, ";
    else if (T[u].l == NIL) cout << "leaf, ";
    else cout << "internal node, ";

    cout << "[";
    for (i = 0, c = T[u].l; c != NIL; i++, c = T[c].r) {
        if (i) cout << ", ";
        cout << c;
    }
    cout << "]" << endl;
}

void rec(int u, int p) {
    D[u] = p;
    if (T[u].r != NIL) rec(T[u].r, p);
    if (T[u].l != NIL) rec(T[u].l, p + 1);
}

int main() {
    int d, v, c, l, r;

    cin >> n;
    for (int i = 0; i < n; i++) {
        T[i].p = T[i].l = T[i].r = NIL;
    }

    for (int i = 0; i < n; i++) {
        cin >> v >> d;
        for (int j = 0; j < d; j++) {
            cin >> c;
            if (j == 0) {
                T[v].l = c;
            } else T[l].r = c;
            l = c;
            T[c].p = v;
        }
    }
    for (int i = 0; i < n; i++) {
        if (T[i].p == NIL) r = i;
    }
    rec(r, 0);
    for (int i = 0; i < n; i++) {
        printNode(i);
    }
    return 0;
}


Measured memory_bytes: 7736
n = int(input())

cnt = 0
for i in range(1, n+1):
    i_str = str(i)
    if len(i_str) == 1:
        cnt += 1
        continue
    if len(i_str) == 2:
        if int(i_str[0]) == int(i_str[1]):
            cnt += 3
        elif int(i_str[1]) != 0 and int(i_str[0]) > int(i_str[1]):
            cnt += 2
        continue
    if len(i_str) == 3:
        if int(i_str[0]) == int(i_str[2]):
            cnt += 4 + (2 * (int(i_str[1])+1) - 1)
        elif int(i_str[2]) != 0 and int(i_str[0]) > int(i_str[2]):
            cnt += 22
        elif int(i_str[0]) < int(i_str[2]):
            cnt += 2
        continue
    if len(i_str) == 4:
        if int(i_str[0]) == int(i_str[3]):
            cnt += 24 + 20 * int(i_str[1]) + 2 * (int(i_str[2])+1) - 1
        elif int(i_str[3]) != 0 and int(i_str[0]) > int(i_str[3]):
            cnt += 222
        elif int(i_str[0]) < int(i_str[3]):
            cnt += 22
        continue
    if len(i_str) == 5:
        if int(i_str[0]) == int(i_str[4]):
            cnt += 224 + 200 * int(i_str[1]) + 20 * int(i_str[2]) + 2 * (int(i_str[3])+1) - 1
        elif int(i_str[4]) != 0 and int(i_str[0]) > int(i_str[4]):
            cnt += 2222
        elif int(i_str[0]) < int(i_str[4]):
            cnt += 222
        continue
    if len(i_str) == 6:
        if int(i_str[0]) == int(i_str[5]):
            cnt += 2224 + 2000 * int(i_str[1]) + 200 * int(i_str[2]) + 20 * int(i_str[3]) + 2 * (int(i_str[4])+1) - 1
        elif int(i_str[5]) != 0 and int(i_str[0]) > int(i_str[5]):
            cnt += 22222
        elif int(i_str[0]) < int(i_str[5]):
            cnt += 2222
        continue

print(cnt)

Measured memory_bytes: 46468
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mod=1e9+7;

/*
Codeforces 766A
Codeforces 766B
ATCODER A
Codeforces 766C
HDU 3001
HDU 3007
*/


/*
题意：
求最长非公共字串，满足公共子串的要求就是保证一个串出现的顺序和在另一个串相同。
思路：
那么你要构成这个肯定是要这么来！
两个串不相等。
|s1|=|s2|：只要他们不一样，就是长度。
|s1|≠|s2|，在大的里面看小的在不在，
***s1***

题意：
给你n条线段，问能否取三个线段得一个三角形。
两边之和大于第三边。
枚举最大边，看能不能产生比他大的组合。
那其实sort完以后a<b<c只要看a+b是不是>c就好了
题意：
输出大的面积？
思路：
max(A*B,C*D);
*/

int main()
{
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    printf("%d\n",max(a*b,c*d));
    return 0;
}









Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, n) ;for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) ;for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF (922337203685477587+1)
#define sosuu 1000000007

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  cout <<a*b/2 << endl;
}

Measured memory_bytes: 256
function move(x,arr){
   var d1=arr[0];
   var d2=arr[1];
   var d3=arr[2];
   var d4=arr[3];
   var d5=arr[4];
   var d6=arr[5];
   var after=[];
   if(x=="N")after=[d2,d6,d3,d4,d1,d5];
   if(x=="S")after=[d5,d1,d3,d4,d6,d2];
   if(x=="E")after=[d4,d2,d1,d6,d5,d3];
   if(x=="W")after=[d3,d2,d6,d1,d5,d4];
   return after;
}

function roll(arr){
   var d1=arr[0];
   var d2=arr[1];
   var d3=arr[2];
   var d4=arr[3];
   var d5=arr[4];
   var d6=arr[5];
   var after=[];
   after=[d1,d3,d5,d2,d4,d6];
   return after;
}

function rolls(arr){
   for(var i=0;i<4;i++){
      var str=arr.join(",");
      if(!obj.hasOwnProperty(str))obj[str]=true;
      arr=roll(arr);
   }
}

var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var n=Arr.shift()-0;
var OBJ={};
var result="Yes";
for(var i=0;i<n;i++){
   var obj={};
   var dice=Arr[i].split(" ").map(Number);
   for(var j=0;j<4;j++){
      rolls(dice);
      dice=move("N",dice);
   }
   dice=move("E",dice);
   rolls(dice);
   dice=move("S",dice);
   dice=move("S",dice);
   rolls(dice);
   for(var k in obj){
      if(OBJ.hasOwnProperty(k))result= "No";
      else OBJ[k]=true;
   }
   if(result=="No")break;
}
console.log(result);

Measured memory_bytes: 10764
#include <bits/stdc++.h>
#define X first
#define Y second

using namespace std;
typedef long long llint;

const int maxn = 1010;
const int base = 31337;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
const int logo = 20;
const int off = 1 << logo;
const int treesiz = off << 1;

int n;
int x[maxn], y[maxn], r[maxn];
long double tc[maxn][maxn];
long double dist[maxn];
set< pair<long double, int> > s;

long double dis(int a, int b) {
	llint dx = x[a] - x[b];
	llint dy = y[a] - y[b];
	return sqrt((long double)dx * dx + (long double)dy * dy);
}

int main() {
	scanf("%d%d%d%d", x, y, x + 1, y + 1);
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d%d%d", x+i+2, y+i+2, r+i+2);
	}

	n += 2;
	for (int i = 0; i < n; i++) dist[i] = (llint)(4e9) * (long double)1.0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			long double tren = max((long double)0.0, dis(i, j) - r[i] - r[j]);
			tc[i][j] = tc[j][i] = tren;
		}
	}

	dist[0] = 0;
	s.insert(make_pair(dist[0], 0));
	while (!s.empty()) {
		long double dis = s.begin()->first;
		int x = s.begin()->second;
		s.erase(s.begin());

		for (int i = 0; i < n; i++) {
			long double cost = tc[x][i];
			if (dist[i] > cost + dis) {
				s.erase(make_pair(dist[i], i));
				dist[i] = cost + dis;
				s.insert(make_pair(dist[i], i));
			}
		}
	}
	cout << fixed << setprecision(10) << dist[1] << endl;
	return 0;
}

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

int main(){
  ll n,x,t; cin>>n>>x;
  vector<ll>v(n);
    rep(i,n){ 
       cin>>t;  v.at(i)=abs(x-t);
            }
  sort(v.begin(),v.end());
  for(ll i=v.at(0); i>=1;i--){
    bool flag=true;
    rep(k,n){
       if(v.at(k)%i!=0){ flag=false; break; }
            }
    if(flag){ cout<<i<<endl; break; }
                              }
           }

Measured memory_bytes: 1024
N,M = map(int,input().split())
S = str(input())
SA = list(S)
D = ["a" , "b" , "c"]

if SA[M-1] == "A":
    SA[M-1] = D[0]
elif SA[M-1] == "B":
    SA[M-1] = D[1]
elif SA[M-1] == "C":
    SA[M-1] = D[2]

M = ''.join(SA)

print(M)

Measured memory_bytes: 3060