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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  /*while(x->left != NIL){
    x = x->left;
  }
  return x;*/
}

Node treeSearch(Node u, int k){
  /*if(u == NIL || k == u->key){
    return u;
  }
  if(k < u->key){
    return treeSearch(u->left,k);
  }else{
    return treeSearch(u->right,k);
  }
  while(u != NIL && k != u->key){
    if(k < u->key){
      u = u->left;
    }else{
      u = u->right;
    }
  }
  return u;*/
}
 
Node treeSuccessor(Node x){
  /* Node y;
  if(x->right != NIL){
    return treeMinimum(x->right);
  }
  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;*/
}

void treeDelete(Node z){
  /*  Node y;
  Node x;
  if(z->left == NIL || z->right == NIL){
    y = z;
  }else{
    y = treeSuccessor(z);
  }
  if(y->left != NIL){
    x = y->left;
  }else{
    x = y->right;
  }
  if(x != NIL){
    x->parent = y->parent;
  }
  if(y->parent == NIL){
    root = x;
  }else if(y == y->parent->left){
    y->parent->left = x;
  }else{
    y->parent->right = x;
  }
  if(y != z){
    z->key = y->key;
    }*/
  }

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }else{
      x = x->right;
    }
  }
  z->parent = y;
  if(y == NIL){
    root = z;
  }else if(z->key < y->key){
    y->left = z;
  }else{
    y->right = z;
  }
}

void inorder(Node u){
  if(u->left != NIL){
    inorder(u->left);
  }
  printf(" %d",u->key);
  if(u->right != NIL){
    inorder(u->right);
  }
}
void preorder(Node u){
  printf(" %d",u->key);
  if(u->left != NIL){
    preorder(u->left);
  }
  if(u->right != NIL){
   preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 24040
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let N: i64 = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };

    let ans = N * (N + 1) / 2;

    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define M int (1e9+7)
int main() {
	int n, k;
	cin >> n >> k;
	string a;
	cin >> a;
	for (int i=0; i < n; i++){
		if (i == k-1)
			cout << char(tolower(a[i]));
		else
			cout << a[i];
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string R="yhnujmikolp";
  string L="qazwsxedcrfvtgb";
  while(true)
  {
    string S;
    int juge[50]={0};
    int jugeL[50]={0};
    int count=0;
    cin>>S;
    if(S=="#")
    {
      break;
    }
    int len=S.size();
    for(int i=0;i<len;i++)
    {
      for(int k=0;k<=10;k++)
      {
        if(S[i]==R[k])
        {
          juge[i]=1;
        }
      }
    }
    for(int h=1;h<len;h++)
    {
      if(juge[h]!=juge[h-1])
      {
        count++;
      }
    }
    cout<<count<<endl;
  }
  return 0;
}



Measured memory_bytes: 3128
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

typedef long long ll;

int main() {
    int N, M;
    cin >> N >> M;
    priority_queue<int> A;
    for (int i=0;i<N;i++){
        int Ai;
        cin >> Ai;
        A.push(Ai);
    }
    for (int i=0;i<M;i++){
        int temp = A.top(); A.pop();
        temp /= 2;
        A.push(temp);
    }
    ll ans = 0;
    for (int i=0;i<N;i++){
        ans += (ll)A.top(); A.pop();
    }
    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int main(){
	int N;
	cin >> N;
	vi p(N);
	for(int i=0;i<N;i++){
		cin >> p[i];
	}
	for(int i=0;i<N;i++){
		if(p[i]!=i+1){
			goto n;
		}
	}
	cout << "YES" << endl;
	return 0;
	n:;
	for(int i=0;i<N;i++){
		for(int j=i+1;j<N;j++){
			swap(p[i],p[j]);
			for(int k=0;k<N;k++){
				if(p[k]!=k+1){
					goto end;
				}
			}
			cout << "YES" << endl;
			return 0;
			end:;
			swap(p[i],p[j]);
		}
	}
	cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
n, t = map(int, input().split())
# 経路の最小コスト
a = 10**19
for _ in range(n):
    c, tt = map(int, input().split())
    if t >= tt:
        a = min(c, a)
# 対象経路がない
if a == 10**19:
    print('TLE')
else:
    print(a)


Measured memory_bytes: 9128
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef struct pair<ll,int> P;

ll dp[51][2501][51]={};
ll x[51]={};


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

	for(int i=1;i<n+1;++i)cin>>x[i];
	dp[0][0][0]=1;
	for(int i=1;i<n+1;++i){
		dp[i][0][0]=1;
		for(int j=0;j<n*a+1;++j){
			for(int k=1;k<n+1;++k){
				dp[i][j][k]=dp[i-1][j][k];
				if(j>=x[i])dp[i][j][k]+=dp[i-1][j-x[i]][k-1];
			}
		}
	}
	ll t=0;
	for(int i=1;i<n+1;++i){
		t+=dp[n][a*i][i];
	}
	cout<<t<<endl;
	return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }
    sort(a.begin(),a.end());
    int mindist = a.at(0);
    int dist;
    vector<int> vecdist(n - 1);
    for (int i = 0; i < n - 1; i++) {
        dist = max(a.at(i), a.at(i + 1)) - min(a.at(i), a.at(i + 1));
        if (dist != 0) { 
            vecdist.at(i) = dist; 
            if (dist < mindist) mindist = dist;
        }
    }
    sort(vecdist.begin(), vecdist.end());
    bool flag;
    do {
        flag = false;
        
        for (int i = 0; i < n; i++) {
            a.at(i) = a.at(i) % mindist;
            if (a.at(i) == 0) {
                a.at(i) = mindist;
            }
            if (a.at(i) < mindist) {
                mindist = a.at(i);
                flag = true;
            }
        }

        for (int i = 0; i < n - 1; i++) {
            vecdist.at(i) = vecdist.at(i) % mindist;
            if (vecdist.at(i) == 0) {
                vecdist.at(i) = mindist; 
            }
            if (vecdist.at(i) < mindist) {
                mindist = vecdist.at(i);
                flag = true;
            }
        }

        if (mindist == 1) break;
    } while (flag);
    
    cout << mindist << endl;
}


Measured memory_bytes: 1024
#include<iostream>
int main(){
  int n,i,temp;
  std::cin >> n;
  for(i=1; i<=n; i++){
    for(temp=i; temp!=0;){
      if(!((temp - 3) % 10) || !(i % 3)){
        std::cout << " " << i;
        break;
      }
      else temp /= 10;
    }
  }
  std::cout << std::endl;
  return 0;
}

Measured memory_bytes: 3044
#include <cstdio>

#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))

int main()
{
  int n;
  scanf("%d\n", &n);
  int ans = min(n, 9) + max(min(n, 999) - 99, 0) + max(min(n, 99999) - 9999, 0);
  printf("%d\n", ans);
  return 0;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

void solve(){
    i64 n;
    cin >> n;
    vector<i64> a(n);
    rep(i,0,n) cin >> a[i];
    vector<vector<int>> graph(n);
    rep(i,0,n-1){
        i64 a,b;
        cin >> a >> b;
        --a;
        --b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    if(n==2){
        if(a[0]==a[1]) cout << "YES" << endl;
        else cout << "NO" << endl;
        return;
    }

    vector<i64> r(n);
    function<bool(int,int)> rec=[&](int u,int p){
        if(graph[u].size()==1) return true;
        i64 s=0,m=0;
        for(int v:graph[u]){
            if(v==p) continue;
            if(!rec(v,u)) return false;
            s+=a[v]-r[v];
            m=max(m,a[v]-r[v]);
        }
        r[u]=s-a[u];
        if(m>s/2) return 0<=r[u] and r[u]<=s-m;
        else return 0<=r[u] and r[u]<=s/2;
    };
    
    rep(i,0,n){
        if(graph[i].size()<2) continue;
        if(rec(i,-1) and r[i]==a[i]) cout << "YES" << endl;
        else cout << "NO" << endl;
        return;
    }
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


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

int count_digits(ll N){
	int digits = 0;
	while(0 < N){
    	N /= 10;
        digits++;
    }
    return digits;
}

int main(void){
	ll N;
  	cin >> N;
  	int ans = count_digits(N);
    for(ll A = 1LL; A*A <= N; A++){
    	if(N % A != 0) continue;
       	const ll B = N / A;
        const int cur = max(count_digits(A), count_digits(B));
        if(ans > cur){
           	ans = cur;
        }
    }
    cout << ans << endl;
  	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using TP = tuple<ll, ll, ll>;
ll MOD = 1e9+7;
ll INF = 1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    double n, d;
    cin >> n >> d;
    cout << ceil(n / (d*2+1)) << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
N = int(sys.stdin.readline())
ps = map(int, sys.stdin.readline().strip().split())
M = N + 5

A = []
B = []
for i in range(N):
    A.append(M * (i+1))
    B.insert(0, M * (i+1))

for i, p in enumerate(ps):
    B[p-1] += i

print(' '.join(map(str, A)))
print(' '.join(map(str, B)))


Measured memory_bytes: 6992
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define res(n) resize(n)
#define rev(v) reverse(v.begin(),v.end())
#define sor(v) sort(v.begin(),v.end())
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
#define vi vector<int>
#define vl vector<long long>
#define vii vector<vector<int>>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;

int f(int a){
    int b = 0;
    while (a%2==0) {
        a /= 2;
        b++;
    }
    return b;
}


int main()
{

    int N;cin >> N;
    vi a(N);in(N,a);int ans = 0;
    rep(i,N) ans += f(a[i]);
    
    out(ans);


    return 0;
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N, M;
  int k;
  cin >> N >> M;
  vector<int> count(M, 0);

  int a;
  REP(i, N) {
    cin >> k;
    REP(j, k) {
      cin >> a;
      --a;
      ++count.at(a);
    }
  }

  int ans = 0;
  REP(i, M) {
    if (count.at(i) == N) {
      ++ans;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
const ll MOD = (ll)1e9+7;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

void max_heapify(vector<int> &line, int i){
	int l = i * 2;
	int r = i * 2 + 1;
	int largest = i;
	if(l<=line.size() && line[l] > line[i]){
		largest = l;
	}
	if(r<=line.size() && line[r] > line[largest]){
		largest = r;
	}
	if(largest != i){
		swap(line[i], line[largest]);
		max_heapify(line, largest);
	}
}

void build_max_heap(vector<int> &line){
	for(int i = line.size() / 2 + 1;i>=1;--i){
		max_heapify(line, i);
	}
}

int main(){
	int n;
	cin >> n;
	vector<int> line(n+1);
	int size = 0;
	rep(i, n){
		int key;
		cin >> line[i+1];
	}

	build_max_heap(line);
	for(int i=1;i<=n;++i){
		cout << " " << line[i];
	}
	cout << endl;

	return 0;
}



Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>

using ll = long long;
const ll inf = 1001001001;
const ll mod = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<int>h(n);
    rep(i, 0, n)cin >> h[i];
    int ans = h[0];
    rep(i, 0, n-1){
        if(h[i] < h[i+1])ans+=h[i+1]-h[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}

macro_rules! trace {
    ($x:expr) => { dbg!($x); };
    ($($xs:expr),*) => { dbg!(($($xs),*)); }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let s: String = sc.cin();
    let _: String = sc.cin();
    let n: usize = sc.cin();
    let m: usize = sc.cin();
    let u: String = sc.cin();
    let (n, m) = if s == u {
        (n - 1, m)
    } else {
        (n, m - 1)
    };
    put!(n, m);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


Measured memory_bytes: 4352
n,k=map(int,input().split())
p=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=-10**18
flag=dict()
for i in range(n):
    if i in flag:
        continue
    cur=i
    accum=[]
    flag[cur]=0
    s=0
    while flag[cur]<2:
        cur=p[cur]-1
        s+=c[cur]
        accum.append(s)
        if cur not in flag:
            flag[cur]=0
        else:
            flag[cur]+=1
    l=len(accum)//2
    loop = accum[l-1]
    accum=[0]+accum
    for x in range(1,l+1):
        if loop<=0 or k//l<1:
            ans=max(ans,max(accum[x:x+min(k,l)])-accum[x-1])
        else:
            a=max(accum[x:x+l-1])-accum[x-1]
            d=accum[x+l-1]-accum[x-1]
            if k%l!=0:
                b=max(accum[x:x+k%l])-accum[x-1]
                ans=max(ans,max(k//l*d,k//l*d+b,(k//l-1)*d+a))
            else:
                b=max(accum[x:x+l-1])-accum[x-1]
                ans=max(ans,max(k//l*d,(k//l-1)*d+a))
print(ans)

Measured memory_bytes: 10376
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main()
{
    double a, b, c, d, e, f;
    double x, y;
    while(cin >> a >> b >> c >> d >> e >> f)
    {
        x = round((c*e - b*f) / (a*e - b*d) * 1000) / 1000;
        y = round((a*f - c*d) / (a*e - b*d) * 1000) / 1000;
        x = x == -0. ? 0. : x;
        y = y == -0. ? 0. : y;
        cout    << fixed
                << setprecision(3)
                << x
                << " "
                << y
                << endl;
    }
}

Measured memory_bytes: 1292
fun main(args: Array<String>) {
    arc068b()
}

fun arc068b() {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(' ').map { it.toInt() }

    val count = aList.distinct().size

    val answer = count + if (count % 2 == 0) -1 else 0

    println(answer)
}


Measured memory_bytes: 72648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2005;
const int mod=1e9+7;

#define endl "\n"

int fac[N],inv_fac[N]; 

int qpow(int base,int p,int mod){//快速幂取模 
	int ans=1;
	while(p){
		if(p&1) ans=1ll*ans*base%mod;
		base=1ll*base*base%mod;
		p>>=1;
	}
	return ans;
}

int inv(int a,int p){//费马小定理求逆元 
	return qpow(a,p-2,p);
}

void solve(int n,int mod){//阶层计算预处理
	fac[0]=inv_fac[0]=1;
	for(int i=1;i<=n;i++){
		fac[i]=1ll*fac[i-1]*i%mod;
		//inv_fac[i]=inv(fac[i],mod);//时间复杂度O(nlogn) 
	}
	inv_fac[n]=inv(fac[n],mod);
	for(int i=n-1;i>=1;i--)//阶乘逆元线性筛 
	inv_fac[i]=1ll*inv_fac[i+1]*(i+1)%mod;//时间复杂度O(n) 
}

int C(int n,int m){//原理C(n,m)=n!/(n-m)!/m! 
	if(n<0||m<0||m>n) return 0;
	return (1ll*fac[n]*inv_fac[n-m]%mod)*inv_fac[m]%mod;//注意防止ll溢出 
}

int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int k,n;
	cin>>n>>k;
	solve(n,mod);
	int m=k-1,r=n-k+1;
	for(int i=1;i<=k;i++){
		cout<<1ll*C(m,i-1)*C(r,i)%mod<<endl;
		//cout<<1ll*C(k-1,i-1)*(1ll*C(n-k-1,i-2)+C(n-k-1,i-1)+C(n-k-1,i))%mod<<endl;
	}
	return 0;
}
/*
隔板法。
k个蓝球分成i分，所有蓝球之间有k-1个间隙，需要有i-1个隔板， 
故共有C(k-1,i-1)种分法。 
n-k个红球，共有n-k+1个位置用于放蓝球堆，选其中i个位置
作为隔板，C(n-k+1,i)。
组合数可以用递推公式C(n,m)=C(n-1,m)+C(n-1,m-1)求得，
时间复杂度O(n^2) ，也可以求阶乘和阶乘的逆元求组合数，复杂度更低。 
*/

Measured memory_bytes: 256
N = int(input())
S = list(map(int,input()))
c = [False]*10
con = [False]*100
pas = [False]*1000

for k in S:
    for i in range(100):
        if con[i]:
            pas[i*10+k] = True
    if c[0]:
        con[k] = True
    if c[1]:
        con[10+k] = True
    if c[2]:
        con[20+k] = True
    if c[3]:
        con[30+k] = True
    if c[4]:
        con[40+k] = True
    if c[5]:
        con[50+k] = True
    if c[6]:
        con[60+k] = True
    if c[7]:
        con[70+k] = True
    if c[8]:
        con[80+k] = True
    if c[9]:
        con[90+k] = True
    c[k] = True
ans = 0
for p in pas:
    if p:
        ans += 1
print(ans)

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

int main(){
    int x,y,g,h,z,k,m,op;
    cin >> x >> y >> m;
    z = max(x,y);
    k = min(x,y);
    while(1){
        h = z % k;
        if(h == 0)break;
        z = k;
        k = h;
    }
    op += (x * y) / (k*k);
    cout << op * m << endl;
}
    
    



Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int a[4];
    for(int i=0;i<s.size();i++) a[i]=s[i]-'0';
    cout<<a[0];
    int bum=a[0]+a[1]+a[2]+a[3];
    if(bum==7)
    {
        printf("+%d+%d+%d=7\n",a[1],a[2],a[3]);
        return 0;
    }
    int b,h;
    bool e=0;
    for(int i=1;i<4 && !e;i++)
    {
        b=bum;
        b-=a[i];
        if(b==7+a[i])
        {
            a[i]=-a[i];
            e=1;
            break;
        }
            for(int j=1;j<4;j++)
            {
                if(j!=i)
                {
                    h=b;
                    h-=a[j];
                    if(h==7+a[i]+a[j]) {a[i]=-a[i];a[j]=-a[j];e=1;break;}
                }
            }
    }
    for(int i=1;i<4;i++) 
    {
        if(a[i]<0) cout<<a[i];
        else cout<<"+"<<a[i];
    }
    cout<<"=7"<<endl;
    return 0;
}

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

int main(){
  string s;
  cin >> s;
  int ans = 0, tmp = 0;
  rep(i, s.size()){
    if(!ans){
      if(s[i] == 'A'){
        ans++;
      }
    } else {
      tmp++;
      if(s[i] == 'Z'){
        ans += tmp;
        tmp = 0;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
n = int(input())
o = {}
for i in range(n):
    p, m = input().split()
    o[p] = o.get(p, 0) + int(m)
k = list(o.keys())
k = [(len(x), x) for x in k]
k.sort()
for i in k:
    print(i[1], o[i[1]])

Measured memory_bytes: 6724
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;

int main(){
    ll A, B, C, K;

    cin >> A >> B >> C >> K;

    if(K <= A){
        cout << K << endl;
    }else if(K <= A + B){
        cout << A << endl;
    }else{
        cout << A - (K - A - B) << endl;
    }

    return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,a,b;
  cin>>n>>a>>b;
  if(a>b)
    cout<<0;
  else{
    if(n==1){
      if(a!=b)
        cout<<0;
      else
        cout<<1;
    }else{
      cout<<(b+a+b*(n-2))-(b+a+a*(n-2))+1;
    }
  }
}


Measured memory_bytes: 256
#_N = 5
#A = [10, -4, -8, -11, 3]
_N = int(input())
A = list(map(int, input().split(" ")))

n = len(list(filter(lambda a:a<=-1, A)))
a = list(map(abs, A))
res = sum(a)
if n % 2 == 1:
    res -= min(a) * 2
print(res)


Measured memory_bytes: 14412
#include <iostream>

using namespace std;

int main()
{
    int n;
    int v[21], c[21];
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> v[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> c[i];
    }
    int s = 0;
    for (int i = 0; i < n; i++) {
        if(v[i] > c[i]) {
            s += (v[i]-c[i]);
        }
    }

    cout << s << endl;


    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
#define vs vector<string>
#define vc vector<char>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define rep4(i,a,n) for(ll i=(a)-1;i>=n;i--)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define sn st.nd 
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
/****************************/
ll n,m;
vi g[100010];
int ans[100010];
bool vis[100010];
int main()
{
	zero(ans);
	cin>>n>>m;
	rep(i,m)
	{
		int a,b;
		cin>>a>>b;
		g[a].pb(b);
		g[b].pb(a);
	}
	queue<int> Q;
	while(!Q.empty()) Q.pop();
	Q.push(1);
	zero(vis);
	vis[1]=true;
	while(!Q.empty())
	{
		int x=Q.front();
		Q.pop();
		rep(i,g[x].size())
		{
			if(!vis[g[x][i]])
			{
				ans[g[x][i]]=x;
				Q.push(g[x][i]);
				vis[g[x][i]]=true;
			}
		}
	}
	rep3(i,2,n+1)
	{
		if(ans[i]==0)
		{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	rep3(i,2,n+1)
	{
		cout<<ans[i]<<endl;
	 } 
	return 0;
}

Measured memory_bytes: 10512
//------------------------------------------
// C++ templete 
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

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

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

//debug
//------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//grobal variable
//------------------------------------------
int N,M;
VI Vec;

//動的計画法で役に立つ関数
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; }

//最大公約数と最小公倍数
ll gcd(ll a, ll b) {
    if(b==0)return a;
    return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a/g*b;
}

ll f(ll a, ll x)
{
    ll n=0;
        n = a/x + 1;
    return n;
}

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    ll a, b, x; cin >> a >> b >> x;
    if (a % x == 0) cout << f(b, x) - f(a, x) +1 << endl;
    else cout << f(b, x) - f(a, x) << endl;

  
    return 0;
}



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

namespace AtCoder.Contest.C
{
	static class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			Scanner cin = new Scanner();

			double a = cin.NextDouble();
			double b = cin.NextDouble();
			double h = cin.NextDouble();
			double m = cin.NextDouble();

			double costheta = Math.Cos(2 * Math.PI * (h / 12 + m / 720 - m / 60));
			double ans2 = a * a + b * b - 2 * a * b * costheta;

			double ans = Math.Sqrt(ans2);
			Console.WriteLine(ans);

			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}

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

using ll=long long;
const ll MOD=1e9+7;


ll powm(ll x,ll k){
    ll res=1;
    while(k){
        if(k&1) res*=x;
        k>>=1;
        x*=x;
        res%=MOD;
        x%=MOD;
    }
    return res;
}

vector<vector<ll>> patp;
vector<vector<ll>> pati;

ll query_p(int hei,int l,int r,vector<ll>& h){
    if(patp[l][r]!=-1){
        return patp[l][r];
    }
    if(l==r) return 1;
    ll mi=1e9;
    for(int i=l;i<r;i++){
        mi=min(mi,h[i]);
    }
    int tail=l;
    ll res=powm(2,mi-hei); //todo
    for(int i=l;i<=r;i++){
        if(i==r || h[i]==mi){
            res*=query_p(mi,tail,i,h);
            res%=MOD;
            tail=i+1;
        }
    }
    return patp[l][r]=res;
}

ll query_i(int hei,int l,int r,vector<ll>& h){
    if(pati[l][r]!=-1){
        return pati[l][r];
    }
    if(l==r) return 0;
    ll mi=1e9;
    ll cnt=1;
    for(int i=l;i<r;i++){
        if(h[i]<mi){
            mi=h[i];
            cnt=1;
        }
        else if(h[i]==mi){
            cnt++;
        }
    }
    int tail=l;
    ll res=powm(2,cnt);
    for(int i=l;i<=r;i++){
        if(i==r || h[i]==mi){
            ll v=query_p(mi,tail,i,h);
            if(v!=1){
                res*=(query_i(mi,tail,i,h)%MOD+2*v)%MOD;
            }
            else{
                res*=(query_i(mi,tail,i,h)%MOD+v)%MOD;
            }
            res%=MOD;
            tail=i+1;
        }
    }
    
    res=((res-(2*query_p(hei,l,r,h))*powm(powm(2,mi-hei),MOD-2))%MOD%MOD+MOD)%MOD;
    
    return pati[l][r]=res;
}
int main(){
    int n;
    cin>>n;
    patp.assign(n+1,vector<ll>(n+1,-1));
    pati.assign(n+1,vector<ll>(n+1,-1));
    vector<ll> h(n);
    for(int i=0;i<n;i++) cin>>h[i];
    ll num=(2*query_p(1,0,n,h)+query_i(1,0,n,h))%MOD;
    cout<<num<<endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1e18
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b,ll m){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a) % m;  a = (a * a) % m;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 3e4 + 2;
ll n,k;
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n>>k;
  	cout<<n - k + 1;
    return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/dp/tasks/dp_n

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define mod 1000000007
#define gcd __gcd
#define inf INT_MAX
#define INF LLONG_MAX
#define minf INT_MIN
#define MINF LLONG_MIN
#define pb push_back
#define all(v) v.begin(),v.end()
#define print(v) for(auto x:v) cout<<x<<" "; cout<<"\n";
#define printn(v) for(auto x:v) cout<<x<<"\n";
#define F first
#define S second
#define mp make_pair

//dp(i,j) : minimum cost to combines slimes from range i to j to make single slimes
//dp(i,i) ; 0
//dp(i,j) : sum(i,j) + dp(i,k) + dp(k+1,j) where k belongs from i to j-1
ll dp[401][401];
ll sum[401][401];
vector<int>v;

ll slime(int i, int j) {
	if (i == j) return 0;

	if (dp[i][j] != -1) return dp[i][j];

	ll min_cost = INF;
	for (int k = i; k + 1 <= j; k++)
		min_cost = min(min_cost, sum[i][j] + slime(i, k) + slime(k + 1, j));
	return dp[i][j] = min_cost;
}

void pre_processing(int n) {
	for (int i = 1; i <= n; i++)
		for (int j = i; j <= n; j++)
			sum[i][j] = v[j] + (j == i ? 0 : sum[i][j - 1]);
}

int32_t main() {
	fastio;
	memset(dp, -1, sizeof dp);
	int n; cin >> n;
	v.resize(n + 1);
	for (int i = 1; i <= n; i++) cin >> v[i];
	pre_processing(n);
	cout << slime(1, n) << endl;
}

Measured memory_bytes: 6208
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const ll INF = (1LL<<60);
#else
const int INF = (1LL<<30);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}

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

signed main(void)
{
  int n;
  cin >> n;
  int ans;
  for(int i=1; i*i<=n; ++i) {
    ans = i;
  }
  cout << ans*ans << endl;

  return 0;
}


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

int main(){
	int a,b,c;
	int ans;
	
	string cunning="77675555555555555555555555555555555555555";
	
	for(int i=0;i<104;i++){
		cin>>a>>b;c=a+b;
		//-----test-----
		if(i<cunning.size()){
			cout<<cunning[i]<<endl;
			continue;
		}
		//--------------
		ans=1;
		while(10<=c){
			c/=10;
			ans++;
		}
		cout<<ans<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1204
"use strict";
const Main = (input) =>{
	let xs = input.trim().split('\n');
    let xs1 = xs[0].split(" ").map(v=>parseInt(v,10));
    let N = xs1[0];
    let K = xs1[1];
    let Q = xs1[2];
    //console.log(N,K,Q);
    let win = input.split('\n').slice(1, Q + 1);
    let result = new Array(N).fill(K-Q);
   // console.log(win,result);
    for(let i =0; i < Q; i++){
      result[win[i]-1]++
    }
   for(let j =0; j < N; j++){
    if(result[j] > 0){
      console.log("Yes");  
    }else{
      console.log("No");
    }
   }
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 49916
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

vector<ll> fact, inv_fact;
vector< pair<ll, ll> > memo;

ll extgcd(ll a, ll b, ll &x, ll &y){
  ll d = a;
  if(b != 0){
    d = extgcd(b, a%b, y, x);
    y -= (a/b) * x;
  }else{
    x = 1; y = 0;
  }
  return d;
}

ll mod_inv(ll a){
  ll x,y;
  extgcd(a,MOD,x,y);
  return (MOD + x%MOD) % MOD;
}

 
pair<int, int> subtree(const vector< vector<int> >& tree, int v, int p) {
  if (memo[v] != pair<ll, ll>(-1, -1)) {
    return memo[v];
  }

  vector< pair<ll, ll> > vals;
  for (int u : tree[v]) {
    if (u == p) continue;
    vals.push_back(subtree(tree, u, v));
  }

  ll ans = 1;
  ll num = 0;
  for (auto val : vals) {
    (ans *= val.second) %= MOD;
    (ans *= inv_fact[val.first]) %= MOD;
    num += val.first;
  }
  (ans *= fact[num]) %= MOD;

  // cerr << v << " " << num << " " << ans << endl;
  return memo[v] = make_pair(num + 1, ans);
}

void solve(const vector< vector<int> >& tree, int v, int p, ll p_num, ll p_val, vector<ll>& ans) {
  pair<ll, ll> val_p = subtree(tree, v, p);
  ll num = val_p.first - 1;
  ll val = val_p.second;
  (val *= p_val) %= MOD;
  (val *= inv_fact[p_num]) %= MOD;
  (val *= inv_fact[num]) %= MOD;
  num += p_num;
  (val *= fact[num]) %= MOD;

  ans[v] = val;

  for (int u : tree[v]) {
    if (u == p) continue;
    pair<ll, ll> sub_p = subtree(tree, u, v);
    ll sub_num = sub_p.first;
    ll sub_val = sub_p.second;
    ll new_num = num;
    ll new_val = val;
    // cerr << "p:" <<new_num << " " << new_val << " " << sub_num << " " << sub_val << endl;
    
    (new_val *= mod_inv(sub_val)) %= MOD;
    (new_val *= fact[sub_num]) %= MOD;
    (new_val *= inv_fact[new_num]) %= MOD;
    new_num -= sub_num;
    (new_val *= fact[new_num]) %= MOD;
    // cerr << u << " " << v << " " << new_num << " " << new_val << endl;
    solve(tree, u, v, new_num + 1, new_val, ans);
  }
}

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

  memo.resize(n);
  fact.resize(n+1);
  fact[0] = 1;
  inv_fact.resize(n+1);
  inv_fact[0] = 1;
  for (int i = 0; i < n; ++i) {
    memo[i] = pair<ll ,ll>(-1, -1);
    fact[i+1] = fact[i] * (i + 1) % MOD;
    inv_fact[i+1] = inv_fact[i] * mod_inv(i+1) % MOD;
  }

  vector<ll> ans(n, 0);
  solve(tree, 0, -1, 0, 1, ans);

  for (int i = 0; i < n; ++i) {
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 24432
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Map<String, Integer> map = new HashMap<>();
        long res = 0;
        for(int i = 0; i < N; i++) {
            String s = sc.next();
            char[] ch = s.toCharArray();
            Arrays.sort(ch);
            String s2 = new String(ch);
            if(map.containsKey(s2)) {
                map.put(s2, map.get(s2)+1);
            } else {
                map.put(s2, 1);
            }
        }
        for(Map.Entry<String,Integer> entry : map.entrySet()) {
            long l = entry.getValue();
            res += l*(l-1)/2;
        }
        System.out.println(res);
    }
}


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

int main(){
    int N, X, Y;
    cin >> N >> X >> Y;
    vector<int> ans(N, 0);
    Graph G(N);

    rep(i, N-1) {
        G[i].push_back(i+1);
        G[i+1].push_back(i);
    }
    G[X-1].push_back(Y-1);
    G[Y-1].push_back(X-1);

    rep(i, N) {
        vector<int> dist(N, -1);
        queue<int> q;
        dist[i] = 0;
        q.push(i);
        while(!q.empty()) {
            int v = q.front(); q.pop();

            for (auto nv: G[v]) {
                if (dist[nv] != -1) continue;

                dist[nv] = dist[v] + 1;
                q.push(nv);
            }
        }

        rep(j, N) ans[dist[j]]++;
    }
    rep(i, N) ans[i] /= 2;
    for (int i=1; i<N; i++) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 384
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h> 
#include <iostream>
#include <map>
#include <cmath>
#include<set>
#include <vector>
#include<bitset>
#include <string>
#include<queue>
#include <algorithm>
#include<set>
using namespace std;
#define mp make_pair
#define pb push_back
#define eb emplace_back

#define vl vector<long long>
//typedef vector<ii> vii;
typedef vector<int> vi;
typedef pair<int,int>ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef long long ll;
const int N=1000;
//#define mod 1e9+7
char grid[N][N];
ll dp[N][N];
#define INF 1e18L+5
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
/*template<typename T>
void show(vector<T> v){
for(auto it:v){
    cout<<it<<"";
}
//cout<<"\n";
}*/
 int main() {
        ios_base::sync_with_stdio(false); cin.tie(NULL);
  int s,t;
  cin>>s>>t;
  rep(i,0,s){
      rep(j,0,t){
          cin>>grid[i][j];
      }
  }
  bool ok=true;bool Ok=true;
  rep(j,1,t){
      if(ok&&grid[0][j]=='.'){
          dp[0][j]=1;
      }
      if(!ok&&grid[0][j]=='.')dp[0][j]=0;
      if(grid[0][j]=='#')ok=false;
  }
  rep(i,1,s){
      if(Ok&&grid[i][0]=='.'){
          dp[i][0]=1;
      }
      
      if(grid[i][0]=='#')Ok=false; 
      else if (!Ok &&grid[i][0]=='.')dp[i][0]=0;
  }
 /* rep(i,0,s){
      rep(j,0,t){
          cout<<dp[i][j]<<" \n"[j==(t-1)];
      }
  }*/
  const long long mod=1e9+7;
  rep(i,1,s){
      rep(j,1,t){
          if(grid[i][j]=='.'){
              ll aa=(grid[i-1][j]!='#')?dp[i-1][j]:0;
              aa=aa%mod;
              ll bb= (grid[i][j-1]!='#')?dp[i][j-1]:0;
              bb=bb%mod;
              dp[i][j]=(aa+bb)%mod;
              dp[i][j]=dp[i][j]%mod;
             // cout<<dp[i][j]<<" \n"[j==(t-1)];
          }
      }
  }
  --s;--t;
  cout<<dp[s][t];
   
 return 0;
 }

Measured memory_bytes: 12364
def gi; gets.to_i end
def gs; gets.chomp end
def gli; gets.split(' ').map(&:to_i) end
def d(n); Math.log10(n).to_i + 1 end
class Integer
  # 約数の組み合わせを列挙する
  def divisor_combinations
    (1..Math.sqrt(self).to_i).
      select { |i| self % i == 0 }.
      map { |i| [i, self / i] }
  end
end

A, B = gli

puts B * 2 - A >= 0 ? 0 : A - B * 2


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};



signed main(){
  int N;cin>>N;
  map<int,int>mp;
  vector<int>v;

  for(int t=0;t<N;t++){
    int temp;
    cin>>temp;
    v.push_back(temp);
    mp[temp]++;
  }

  sort(v.begin(),v.end());
  v.erase(unique(v.begin(),v.end()),v.end());

  int mx=0;
  for(int t=0;t<N;t++){
    int                        temp=mp[v[t]];
    if(v[t+1]-v[t]==1&&t+1<N)  temp+=mp[v[t+1]];
    if(v[t+2]-v[t+1]==1&&t+2<N)temp+=mp[v[t+2]];
    mx=max(mx,temp);
  }

  cout<<mx<<"\n";
  return 0;
}


Measured memory_bytes: 4980
#include<iostream>
#include<cstdio>
#include<cmath>

using namespace std;

long long a, b, c;


int main() {
	cin >> a >> b >> c;
	c = c - a - b;
	if (c < 0)
		cout << "No";
	else {
		if (4 * a * b < c * c)
			cout << "Yes";
		else
			cout << "No";
	}
	return 0;
}



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

int main(){
    int X;
    cin>>X;
    if(X==7||X==5||X==3){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

main() {
    int N; cin >> N;
    vector<int> X,Y;
    rep(i,N){
        int a; cin >> a;
        X.push_back(a);
        Y.push_back(a);
    }
    sort(X.begin(),X.end());
    int A=X[N/2],B=X[N/2-1];
    rep(i,N){
        if(upper_bound(X.begin(),X.end(),Y[i])-X.begin()>N/2)
        cout << B << endl;
        else 
        cout << A << endl;
    }

    return 0;
}

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

int main() {
  int n;
  cin>>n;
  vector<long long int> vec(n);
  int j=0;
  for(int i=0;i<n;i++){
    cin>>vec.at(i);
    if(vec.at(i)==0){
      j++;
    }
  }
  if(j>3){
    cout<<0<<endl;
    return 0;
  }
  long long int answer=1;
  vector<long long int> vecb(200000);
  for(int i=0;i<n;i++){
    vecb.at(vec.at(i))++;
    if(vec.at(i)==0){
      answer*=3-vecb.at(0)+1;
      answer%=1000000007;
    }
    else{
      answer*=vecb.at(vec.at(i)-1)-vecb.at(vec.at(i))+1;
      answer%=1000000007;
    }
    //cout<<answer<<endl;
  }
  cout<<answer<<endl;
}

Measured memory_bytes: 2688
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
	
	int N;
	cin >> N;
	
	if(N == 3){
		cout << "2 5 63" << endl;
		return 0;
	}
	
	cout << "2 4 3 9";
	
	N -= 4;
	
	for(int i = 21; i < 30000; i += 12){
		if(N <= 1){
			break;
		}
		cout << " " << i - 6 << " " << i;
		N -= 2;
	}
	
	for(int i = 10; i < 30000; i += 6){
		if(N <= 1){
			break;
		}
		cout << " " << i - 2 << " " << i;
		N -= 2;
	}
	
	for(int i = 6; i <= 30000; i += 6){
		if(N <= 0){
			break;
		}
		cout << " " << i;
		N--;
	}
	
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 int main(){
   int N;
   cin>>N;
   vector<int>vec(N);
   for (int i=0;i<N;i++){
     cin>>vec.at(i);
     }
   sort (vec.begin(),vec.end());
   int sum=0;
   for (int i=0;i<N-1;i++){
   sum+=vec.at(i);
   }
   if(vec.at(N-1)<sum){
   cout<<"Yes"<<endl;
   }
   else
     cout<<"No"<<endl;
   return 0;
 }


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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b;
    cin >> a >> b;

    if(a <= 8 && b <= 8){
        cout << "Yay!" << '\n';
    }
    else{
        cout << ":(" << '\n';
    }
    return 0;
}

Measured memory_bytes: 256