akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>
 
using namespace std;
 
typedef long long int ll;
typedef pair<int,int> P;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) x.begin(),x.end()
 
const ll mod = 1e9+7;
const ll INF = 1e9;
 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
 
vector<vector<int>>g,rg;
vector<int> used,order,cmp;
 
void dfs(int x){
    used[x] = true;
    for(auto p:g[x]){
        if(!used[p]) dfs(p);
    }
    order.push_back(x);
}
 
void rdfs(int x,int cnt){
    used[x] = true;
    for(auto p:rg[x]){
        if(!used[p]) rdfs(p,cnt);
    }
    cmp[x]=cnt;
}
 
int main()
{
    int n,m;
    cin>>n>>m;
    g.resize(n);
    rg.resize(n);
    used.resize(n);
    cmp.resize(n,0);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        g[a].push_back(b);
        rg[b].push_back(a);
    }
 
    rep(i,n){
        if(!used[i])dfs(i);
    }
    used.assign(n,false);
    int cnt = 0;
	reverse(all(order));
    for(auto x:order){
        if(!used[x]){
            rdfs(x,cnt);
            cnt++;
        }
    }
 
    // rep(i,n)cout<<i<<" "<<cmp[i]<<endl;
    int q;
    cin>>q;
    rep(i,q){
        int a,b;
        cin>>a>>b;
         
        cout<<(cmp[a]==cmp[b]?1:0)<<endl;
    }
    return 0;
}


Measured memory_bytes: 4768
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

long long N, A[1 << 18], B[1 << 18];
long long ans;

int main() {
	cin >> N;
	for (int i = 1; i <= N - 1; i++) cin >> A[i] >> B[i];
	for (int i = 1; i <= N; i++) ans += 1LL * i * (N + 1LL - i);
	for (int i = 1; i <= N; i++) {
		if (A[i] > B[i]) swap(A[i], B[i]);
		long long T = A[i] * (N + 1LL - B[i]);
		ans -= T;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6768
y,x = [int(x) for x in input().split()]
while(x > 0 or y > 0):
    print('#' * x)
    st  = '#' 
    st += '.' * (x-2)
    st += '#'
    for i in range(1, y-1):
        print(st)
        
    print('#' * x)
    print()
    y,x = [int(x) for x in input().split()]

Measured memory_bytes: 7668
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase


def main():
    m=int(input())
    cnt=0
    n=100
    while n<m:
        cnt+=1
        n=n+n//100
    print(cnt)


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion

if __name__ == "__main__":
    main()

Measured memory_bytes: 63540
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
typedef vector<tint> vtint;
typedef vector<vint> vvint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=200050;
//↑templete

signed main(){

    ll N;
    cin>>N;
    vll A;
    for(int i=0;i<N;i++){
        ll a;
        cin>>a;
        A.pb(a);
    }

    unordered_map<ll, ll> num;
    ll ans=0;
    for(int i=0;i<N;i++){
        ans+=num[i-A[i]];
        num[i+A[i]]++;
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 20152
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
typedef long long llo;
#define a first
#define  b second
#define endl "\n"
vector<llo> adj[100001];
llo col[100001];
llo inf;
llo par[1000000];
pair<llo,llo> ran[100001];
void dfs(llo no,llo parr=-1,llo l=-1,llo r=-1){
	if(col[no]!=-1){
		l=col[no];
		r=col[no];
	}
	ran[no]=mp(l,r);
	par[no]=parr;
	for(auto j:adj[no]){
		if(j==parr){
			continue;
		}
		dfs(j,no,l-1,r+1);
	}
//	cout<<no<<" "<<ran[no].a<<" "<<ran[no].b<<endl;
}
pair<llo,llo> dfs2(llo no,llo parr){
	llo l,r;
	if(col[no]==-1){
		l=-inf;
		r=inf;
	}
	
	else{
		l=col[no];
		r=col[no];
	}
	//cout<<no<<" "<<l<<" "<<r<<endl;
	for(auto j:adj[no]){
		if(j==parr){
			continue;
		}
		pair<llo,llo> xx=dfs2(j,no);
	//	cout<<l<<"/"<<r<<endl;
		l=max(l,xx.a-1);
		r=min(r,xx.b+1);
	//	cout<<l<<"/"<<r<<endl;
	//	cout<<xx.a-1<<":"<<xx.b+1<<":"<<no<<endl;
	}

	
	ran[no].a=max(ran[no].a,l);
	ran[no].b=min(ran[no].b,r);
	if(col[no]>-1){
		ran[no].a=max(ran[no].a,col[no]);
		ran[no].b=min(ran[no].b,col[no]);
	}
//	cout<<no<<" "<<ran[no].a<<" "<<ran[no].b<<endl;
	return ran[no];
}
void dfs3(llo no,llo parr,llo co){
	if(col[no]==-1){
		col[no]=co;
	}
	else{
		co=col[no];
	}
	for(auto j:adj[no]){
		if(j==parr){
			continue;
		}
		
		if(co+1<=ran[j].b and co+1>=ran[j].a){
			dfs3(j,no,co+1);
		}
		else{
			dfs3(j,no,co-1);
		}

	}
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	inf=1000000;
	llo n,k;
	cin>>n;
	llo aa,bb;
	memset(col,-1,sizeof(col));
	for(llo i=0;i<n-1;i++){
		cin>>aa>>bb;
		adj[aa-1].pb(bb-1);
		adj[bb-1].pb(aa-1);
	}

	cin>>k;
	llo st;
	for(llo i=0;i<k;i++){
		cin>>aa>>bb;
		st=aa;
		col[aa-1]=bb;
	}
	aa-=1;
//	cout<<aa<<endl;
	dfs(aa);
	dfs2(aa,-1);
	llo ss=1;
	for(llo i=0;i<n;i++){
		if(ran[i].a>ran[i].b){
			ss=0;

		}
	}	
	if(ss==0){
		cout<<"No"<<endl;
	}
	else{
		//cout<<"Yes"<<endl;
		dfs3(aa,-1,col[aa]);
		for(int i=0;i<n;i++){
			if(abs(col[par[i]]-col[i])!=1 and par[i]!=-1){
				ss=0;
			}
		}
		if(ss==0){
			cout<<"No"<<endl;
			return 0;
		}
		cout<<"Yes"<<endl;
		for(llo i=0;i<n;i++){
			cout<<col[i]<<endl;
		}

	}















	return 0;
}

Measured memory_bytes: 20352
#include <iostream> // cin, cout
#include <algorithm> // sort
#include <vector> // vector
#include <cstdio> // printf
#include <cmath> // M_PI
#include <numeric> // accumulate
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)


int		main(void)
{
	int n;
	cin >> n;
	bool cards[4][13];
	char c;
	int num;
	rep(i, 4) {
		rep(k, 13) {
			cards[i][k] = 0;
		}
	}
	rep(i, n) {
		cin >> c >> num;
		if (c == 'S')
			cards[0][num - 1] = 1;
		else if (c == 'H')
			cards[1][num - 1] = 1;
		else if (c == 'C')
			cards[2][num - 1] = 1;
		else if (c == 'D')
			cards[3][num - 1] = 1;
	}
	rep(i, 4) {
		rep(k, 13) {
			if (!cards[i][k]) {
				switch (i) {
					case 0:
						cout << "S" << " " << k + 1 << endl;
						break;
					case 1:
						cout << "H" << " " << k + 1 << endl;
						break;
					case 2:
						cout << "C" << " " << k + 1 << endl;
						break;
					case 3:
						cout << "D" << " " << k + 1 << endl;
						break;
				}
			}
		}
	}
	return (0);
}



Measured memory_bytes: 3100
n,m,k = gets.chomp.split.map(&:to_i)
as = gets.chomp.split.map(&:to_i)
bs = gets.chomp.split.map(&:to_i)
ans = 0
as_sum = [0]
bs_sum = [0]

as.each do |a|
  as_sum << as_sum[-1] + a
end

bs.each do |b|
  bs_sum << bs_sum[-1] + b
end

as_sum.each_with_index do |a,i|
  break if a > k
  idx = bs_sum.bsearch_index{|x| x + a > k}
  if idx.nil?
    idx = m + 1
  end
  idx -= 1
  ans = idx + i if ans < idx + i
end

puts ans


Measured memory_bytes: 49464
import math
N,K = map(int,input().split())
ans = 0

for i in range(1,N+1):
    if i >= K:
        ans += (1/N)
        continue
    X = int(math.log((K/i), 2))
    if (K/i) % 2**X == 0:
        pass
    else:
        X += 1
    ans += (1/N) * (1/2) ** X
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define INF 2e18+99

string a, b;
vector<vector<int>> dp;
string backtrack(int i, int j)
{
    if(i == 0 || j == 0)
        return "";
    else if(a[i - 1] == b[j - 1])
        return backtrack(i-1, j-1)+a[i-1];
    else{
        if(dp[i][j-1] >= dp[i-1][j])
            return backtrack(i, j-1);
        else
            return backtrack(i-1, j);
    }
}
int main() {
    fast;
    cin>>a>>b;
    dp.resize(a.length()+1);
    for (int i = 0; i <= a.length(); ++i) {
        dp[i].resize(b.length()+1);
        for (int j = 0; j <= b.length(); ++j) {
            if(i == 0 || j == 0)
                dp[i][j] = 0;
            else if(a[i - 1] == b[j - 1]) {
                dp[i][j] = dp[i-1][j-1] + 1;
            }
            else {
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }
    cout<<backtrack(a.length(), b.length());
}

Measured memory_bytes: 35840
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
using namespace std;

int N;
int nos[200010];
bool possib(int x){
    // Unless otherwise specified all the characters are 0
    map<int,int> curr;
    for(int i=1;i<N;i++) if(nos[i] <= nos[i-1]){
        int idx = nos[i];
        while(idx > 0){
            curr[idx] += 1;
            if(curr[idx] == x){
                curr[idx] = 0;
                idx -= 1;
            }else break;
        }
        if(idx == 0) return false;
        for(auto it = --curr.end();it->first > nos[i];it = --curr.end()) curr.erase(it);
    }
    return true;
}


int main(){
    scanf("%d",&N);
    for(int i=0;i<N;i++) scanf("%d",&nos[i]);
    bool inc = true;
    for(int i=1;i<N && inc;i++) if(nos[i] <= nos[i-1]) inc = false;
    if(inc){
        printf("1\n");
        return 0;
    }
    int lo = 2, hi = 3e5;
    while(lo < hi){
        int mid = (lo + hi)>>1;
        if(possib(mid)) hi = mid;
        else lo = mid+1;
    }
    printf("%d\n",hi);
}

Measured memory_bytes: 1024
N,Q=map(int,input().split())
S=list(input())
C=[0]
for i in range(1,N):
  if S[i-1]=="A" and S[i]=="C":
    C.append(C[i-1]+1)
  else:
    C.append(C[i-1])

for _ in range(Q):
  l,r=map(int,input().split())
  print(C[r-1]-C[l-1])

Measured memory_bytes: 54776
#include <iostream>
#include <cstdint>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <cassert>

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

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

LL gcd(LL a, LL b) {
  if( b == 0 ) { return a; }
  return gcd(b, a % b);
}

template <LL MOD=1000000007> class MODLL {
public:
  LL x;
  MODLL(const LL _x) : x(_x % MOD) {};
  MODLL operator+(const MODLL rhs) const { return MODLL(*this) += rhs; }
  MODLL operator-(const MODLL rhs) const { return MODLL(*this) -= rhs; }
  MODLL operator*(const MODLL rhs) const { return MODLL(*this) *= rhs; }
  MODLL operator/(const MODLL rhs) const { return MODLL(*this) /= rhs; }
  MODLL& operator+=(const MODLL rhs) { x += rhs.x; x %= MOD; return *this; }
  MODLL& operator-=(const MODLL rhs) { x -= rhs.x; x %= MOD; if(x<0) x += MOD; return *this; }
  MODLL& operator*=(const MODLL rhs) { x *= rhs.x; x %= MOD; return *this; }
  MODLL inv() const {
    if(x == 0) { throw "does not have inverse"; }
    LL a = x, b = MOD, u = 1, v = 0;
    while (b) {
      long long t = a / b;
      a -= t * b; swap(a, b);
      u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return MODLL(u);
  }
  MODLL& operator/=(const MODLL rhs) { (*this) *= rhs.inv(); return *this; }
  MODLL pow(ULL n) const {
    MODLL res = 1;
    MODLL a = x;
    while (n > 0) {
      if (n & 1) res *= a;
      a = a * a;
      n >>= 1;
    }
    return res;
  }
};

typedef MODLL<> ML;

void test() {
  {
    ML x = 3;
    assert(x.pow(45).x == 644897553);
  }
  {
    for(int i=1; i<13; i++) {
      MODLL<13> x = i;
      assert( (x.inv().x * i) % 13 == 1 );
    }
  }
}

std::vector< std::vector<int> > get(int N) {
  std::vector< std::vector<int> > a(N);
  REP(i,N) { a[i].resize(N,0); }
  for(int i=0; i<N; i++) {
    for(int j=i+1; j<N; j+=2) { // odd-even
      a[i][j] = 1;
    }
  }
  if( N <= 2 ) { return std::move(a); }
  auto sub_e = (N%2==1) ? get(N/2+1) : get(N/2);
  for(int i=0; i<sub_e.size(); i++) {
    for(int j=i+1; j<sub_e.size(); j++) {
      int I = i*2;
      int J = j*2;
      a[I][J] = sub_e[i][j] + 1;
    }
  }
  auto sub_o = get(N/2);
  for(int i=0; i<sub_o.size(); i++) {
    for(int j=i+1; j<sub_o.size(); j++) {
      int I = i*2+1;
      int J = j*2+1;
      a[I][J] = sub_o[i][j] + 1;
    }
  }
  return std::move(a);
}


int main() {
  long N;
  std::cin >> N;

  auto ans = get(N);
  for(int i=0; i<N-1; i++) {
    for(int j=i+1; j<N-1; j++) {
      std::cout << ans[i][j] << ' ';
    }
    std::cout << ans[i][N-1] << std::endl;
  }

  return 0;
}



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

int main(){
    int n,m;
    cin >> n >> m;
    vector<pair<int,int>>stu(n);
    vector<pair<int,int>>che(m);
    rep(i,n)cin >> stu[i].first >> stu[i].second;
    rep(i,m)cin >> che[i].first >> che[i].second;
    
    rep(i,n){
        int dist = 300000000;
        int chenum = 0;
        rep(j,m){
            int d = abs(stu[i].first-che[j].first)+abs(stu[i].second-che[j].second);
            if(d<dist){
                dist = d;
                chenum = j;
            }
        }
        cout << chenum+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int K, T;
    cin >> K >> T;
    vector<int> a(T);
    for (int i = 0; i < T; i++) cin >> a[i];
    int mx = *max_element(a.begin(), a.end());
    int remain = K - mx;
    int ans = mx - remain - 1;
    cout << (ans > 0 ? ans : 0) << '\n';
}


Measured memory_bytes: 256
a;f(H,W){for(long long i=H,x,y,z,t;i--;)x=(H-i)*W,y=W/2*i,z=(W+1)/2*i,t=x>z?x-y:x<y?z-x:i,a=t<a?t:a;}main(H,W){scanf("%d%d",&H,&W);printf("%d\n",H%3&&W%3?a=H<W?H:W,f(H,W),f(W,H),a:0);}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <stdlib.h>

#define STK_SIZE 101

using namespace std;
class Stack{
private:
    int size = STK_SIZE;
    int item[STK_SIZE];
    int top;
public:
    Stack(){
        this->top=0;
        for(int i=0; i<this->size; i++){
            item[i]=0;
        }
    }
    
    int pop(){
        if(top > 0) top--;
        return item[top+1];
    }
    
    void push(int x){
        if(top+1<this->size){
            item[++top]=x;
        }
    }
    
};

int main(void){
   
    Stack stk;
    string str;
    vector <string> v;
    
    while (std::getline(cin, str, ' ')) {
      v.push_back(str);
    }

    
    for(int i=0; i < (int)v.size(); i++){
        string c=v[i];
        int a,b;
        if(c[0]=='+'){
            a=stk.pop();
            b=stk.pop();
            stk.push(a+b);
        }else if(c[0]=='-'){
            a=stk.pop();
            b=stk.pop();
            stk.push(b-a);
        }else if(c[0]=='*'){
            a=stk.pop();
            b=stk.pop();
            stk.push(a*b);
        }else{
            stk.push(atoi(c.c_str()));
        }
        
        
    }
    cout << stk.pop()<< endl;
    return 0;
    
    
}



Measured memory_bytes: 3180
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
  int N, M; cin >> N >> M;

  int A = -1;
  for (int i = 0; i < N; i++) {
    int K; cin >> K;
    int tmp = 0;
    for (int j = 0; j < K; j++) {
      int a; cin >> a;
      tmp |= (1 << a);
    }
    A &= tmp;
  }

  int cnt = 0;
  while (A) {
    if (A & 1) {
      cnt++;
    }
    A >>= 1;
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>
#include <cassert>

using namespace std;

#define int long long
#define double long double

typedef pair<int, int> P;
typedef tuple<int, int, int> T;

template<class T> string tostr(T x) { stringstream o; o << x; return o.str(); }
template<class T> T sqr(T x) { return x*x; }
template<class T> T mypow(T x, int n) { T r = 1; while (n > 0) { if (n & 1)r = r*x; x = x*x; n >>= 1; }return r; }

int toint(string s) { int v; stringstream i(s); i >> v; return v; }
bool check(int x, int y, int w, int h) { return x >= 0 && y >= 0 && w > x && h > y; }
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; }

#define REP(i,a,b)	for(int (i) = (a);i < (b);(i)++)
#define rep(i,n)	REP(i,0,n)
#define PER(i,a,b)	for(int (i) = (a-1);i >= (b);(i)--)
#define per(i,n)	PER(i,n,0)
#define each(i,n)	for(auto &i : n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define dump(val) 	cerr << #val " = " << val << endl;
#define dum(val)	cerr << #val " = " << val;
#define FILL(a,v)	fill(a,a+sizeof(a)/sizeof(*a),v)

const int dx[8] = { +1,+0,-1,+0,+1,+1,-1,-1 };
const int dy[8] = { +0,-1,+0,+1,-1,+1,-1,+1 };
const int mod = 1e9 + 7;
const int INF = 1e17 + 9;

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

	int n, k;
	cin >> n >> k;

	vector<P> e;
	vector<vector<int>> v(n);

	rep(i, n - 1) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		v[a].push_back(b);
		v[b].push_back(a);
		e.push_back(P(a, b));
	}

	int vis[2001];
	function<int(int, int, int)> dfs = [&](int now, int dist, int limit) {
		if (vis[now])return 0ll;
		vis[now] = 1;
		int ret = 0;
		each(to, v[now]) {
			if (vis[to] == 0) {
				ret += dfs(to, dist + 1, limit);
			}
		}
		if (limit < dist)ret++;
		return ret;
	};

	int ans = INF;
	if (k % 2 == 0) {
		rep(i, n) {
			clr(vis);
			ans = min(ans, dfs(i, 0, k / 2));
		}
	}
	else {
		each(i, e) {
			clr(vis);
			int sum = 0;
			vis[i.first] = 0; vis[i.second] = 1;
			sum += dfs(i.first,  0, k / 2);
			vis[i.first] = 1; vis[i.second] = 0;
			sum += dfs(i.second, 0, k / 2);
			ans = min(ans, sum);
		}
	}
	cout << ans << endl;

	return 0; 
}

Measured memory_bytes: 640
#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 M;
int K;
int main(){
	cin >> M >> K;
	if(K>=(1<<M)){
		cout << -1 << endl;
		return 0;
	}
	if(M==1&&K==0){
		cout << "0 0 1 1" << endl;
		return 0;
	}
	if(M==1&&K==1){
		cout << -1 << endl;
		return 0;
	}
	deque<int> q;
	q.pb(K);
	for(int i=0;i<(1<<M);i++){
		if(i==K)continue;
		q.push_front(i);
		q.push_back(i);
	}
	q.push_back(K);
	for(int i=0;i<q.size();i++){
		cout << q[i];
		if(i+1<q.size())cout << ' ';
		else cout << endl;
	}
	return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint N, K; cin >> N >> K;
    vec<lint> count_snacks(N, 0);
    range(_, 0, K) {
        lint d; cin >> d;
        range(_, 0, d) {
            lint A; cin >> A;
            A--;
            count_snacks.at(A) += 1;
        }
    }
    lint ans = 0;
    range(i, 0, N) ans += count_snacks.at(i) == 0;
    cout << ans << "\n";
}

Measured memory_bytes: 3660
# coding: utf-8
# Here your code !

q = int(raw_input())
for i in xrange(q):
    xp0, yp0, xp1, yp1, xp2, yp2, xp3, yp3 = map(float,raw_input().split())
    if xp1 - xp0 == 0:
        if xp3 - xp2 == 0:
            print 2
        elif yp3 - yp2 == 0:
            print 1
        else:
            print 0
    elif xp3 - xp2 == 0:
        if xp1 - xp0 == 0:
            print 2
        elif yp1 - yp0 == 0:
            print 1
        else:
            print 0
    
    else:
        s1 = (yp1 - yp0, xp1 - xp0)
        s2 = (yp3 - yp2, xp3 - xp2)
        if s1[0]/s1[1] == s2[0]/s2[1]:
            print 2
        elif s1[0]*s2[0] + s1[1]*s2[1] == 0:
            print 1
        else:
            print 0

Measured memory_bytes: 4260
#include<stdio.h>

int main(void){
        int h, w;
        scanf("%d %d", &h, &w);

        int A[h][w], b[w];
        for(int i=0; i<h; i++) for(int j=0; j<w; j++) scanf("%d", &A[i][j]);
        for(int i=0; i<w; i++) scanf("%d", &b[i]);

        for(int i=0; i<h; i++){
                int sm = 0;
                for(int j=0; j<w; j++) sm += A[i][j] * b[j];
                printf("%d\n", sm);
        }
        return 0;
}


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

using namespace std;

int a[21], num, m, q;

bool DFS (int n, int sum)
{
    bool ret;
    if (n==num && sum!=m) return false;
    if (sum==m) return true;
    if (sum>m) return false;
    if (sum<m)
    {
        for (int i=n+1; i<=num; i++)
        {
            ret=DFS(i,sum+a[i]);
            if (ret) return true;
        }
        return false;
    }
}

int main()
{
    cin>>num;
    for (int i=1; i<=num; i++) cin>>a[i];
    sort(a,a+num);
    cin>>q;
    bool ret[q];
    for (int i=0; i<q; i++)
    {
        cin>>m;
        ret[i]=DFS(0,0);
    }
    for (int i=0; i<q; i++) cout<<(ret[i] ? "yes\n" : "no\n");
    return 0;
}



Measured memory_bytes: 3076
#include<cstdio>
#include<algorithm>
#include<vector>
#include<deque>
#include<stack>
#include<queue>
#include<string>
#include<iostream>
#include<tuple>
#include<utility>
#include<set>
#include<queue>
#include<iomanip>
#include<iterator>
//#include<chrono>
//cout<<setprecision(12)
//fixed
#include<random>
using namespace std;
typedef long long int llint;
typedef long double lldo;
const int big=1e9+100000;
const int mod=1e9+7;
const lldo eps=1e-9;
const long double pai=3.141592653589793238462643;
#define mt make_tuple
#define mp make_pair
#define fir first
#define sec second
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define res resize
#define ins insert
#define era erase
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
int main(void){
	int i,j,c,n,gosa=0,ans=0;cin>>c>>n;
	vector<vector<char>>kor(n);//?????????????????????
	for(i=0;i<n;i++){
		kor[i].res(n);
		for(j=0;j<n;j++){cin>>kor[i][j];}
	}
	gosa=n*n/4;
	for(i=0;i<n/2;i++){
		for(j=0;j<n/2;j++){
			if(kor[i][j]==kor[n-i-1][j]&&kor[i][j]==kor[i][n-j-1]&&kor[i][j]==kor[n-i-1][n-j-1]){gosa--;}
		}
	}
	if(gosa==0){ans++;}
	for(i=0;i<c-1;i++){
		int d;cin>>d;
		while(d--){
			int x,y;cin>>y>>x;x--;y--;
			if(kor[y][x]==kor[n-y-1][x]&&kor[y][x]==kor[y][n-x-1]&&kor[y][x]==kor[n-y-1][n-x-1]){gosa++;}
			kor[y][x]='0'+'1'-kor[y][x];
			if(kor[y][x]==kor[n-y-1][x]&&kor[y][x]==kor[y][n-x-1]&&kor[y][x]==kor[n-y-1][n-x-1]){gosa--;}
		}
		if(gosa==0){ans++;}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3896
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file
#else

#endif



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); // Togliere nei problemi con query online

    string S;
    cin >> S;
    for (int i = 0; i < (int)S.size(); i++) if (S[i] == '?') S[i] = 'D';
    cout << S << "\n";
}


Measured memory_bytes: 3740
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
    int n,a[100];
    int i,j;
    cin>>n;
    for(i=0;i<n;i++)
        cin>>a[i];

    for(i=0;i<n;i++)
    {
        if(i==0)
        cout<<a[0];
        else
        cout<<' '<<a[i];
    }
    cout<<endl;

    for(i=1;i<n;i++)
        {
            if(a[i]<a[i-1])
            {
                int temp=a[i];

                for(j=i-1;j>=0&&a[j]>temp;j--)
                    a[j+1]=a[j];
                    a[j+1]=temp;

            }
              for(int k=0;k<n;k++)
              {
                  if(k==0)
                    cout<<a[0];
                  else
                    cout<<' '<<a[k];

              }
              cout<<endl;

        }

    return 0;
}


Measured memory_bytes: 3064
import static java.lang.Integer.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.TreeSet;

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
		st = new StringTokenizer(br.readLine());
		int N = parseInt(st.nextToken());
		int T = parseInt(st.nextToken());
//		int[] c = new int[N];
//		int[] t = new int[N];

		TreeSet<Integer> set = new TreeSet<Integer>();

		for(int i=0;i<N;i++) {
			st = new StringTokenizer(br.readLine());
			int c = parseInt(st.nextToken());
			int t = parseInt(st.nextToken());
			if(t <= T) {
				set.add(c);
			}
		}

		if(set.isEmpty()) {
			System.out.println("TLE");

		}else {
			System.out.println(set.first());

		}



	}




}

Measured memory_bytes: 24916
a = list(map(int, input().split()))

success_cases = [(a[0], a[1], a[2]), (a[1], a[2], a[0]), (a[2], a[0], a[1])]

for c in success_cases:
    if c == (5,7,5):
        print("YES")
        exit(0)
print("NO")



Measured memory_bytes: 9012
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
 
typedef long long ll;
const ll INF = LLONG_MAX - 100;
const ll mod = 1e9 + 7;
const int MAX_N = 2e5 + 5;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;
 
int fac[MAX_N], inv[MAX_N];
 
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b, bool usemod = true) {ll c = 1LL; while (b > 0) {if (b & 1LL) {if(!usemod)c*=a;else c = a * c%mod;}if (!usemod) a*=a;else a = a * a%mod; b >>= 1LL;}return c;}
void _nCr() {fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) {fac[i] = fac[i - 1LL] * i%mod;}for (int i = 0; i < MAX_N; i++) {inv[i] = POW(fac[i], mod - 2);}}
ll nCr(ll n, ll r) {return (fac[n] * inv[r] % mod)*inv[n - r] % mod;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}

int dp[2005][2005];
int sum[2005][2005];
//dpはi,jを同時に採用した時に増えるもの(不一致なら0) dp[i][j] = sum[i-1][j-1]
//sumはi,jまでの総和

bool solve() {
	int n,m; cin>>n>>m;
	vi s(n),t(m);
	REP (i,n) cin>>s[i];
	REP (i,m) cin>>t[i];
	REP (i,n+1) REP (j,m+1) sum[i][j] = 1;
	REP (i,n) {
		REP (j,m) {
			sum[i+1][j+1] = sum[i][j+1] + sum[i+1][j] - sum[i][j];
			if (s[i] == t[j]) dp[i+1][j+1] = sum[i][j];
			sum[i+1][j+1] += dp[i+1][j+1] + mod;
			sum[i+1][j+1] %= mod;
		}
	}
	cout << sum[n][m] << endl;
}

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

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

typedef long long ll;

int main()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = max(a * c, a * d);
    ans = max(ans, b * c);
    ans = max(ans, b * d);

    cout << ans << endl;
}


Measured memory_bytes: 3604
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <bitset>
#include <map>
#include <string>
#include <utility>

#define repd(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

int inputValue(){
	int a;
	cin >> a;
	return a;
}

void inputArray(int *p,int a){
	rep(i,a){
		cin >> p[i];
	}
}

void inputVector(vector<int> *p,int a){
	rep(i,a){
		int input;
		cin >> input;
		p -> push_back(input);
	}
}

template <typename T>
void output(T a,int precision){
	if(precision > 0){
		cout << setprecision(precision) << a << "\n";
	}else{
		cout << a << "\n";
	}
}

int main(){
	//source
	ll n,a[5],b[5];
	cin >> n;
	rep(i,5){
		cin >>a[i];
		if(n%a[i]==0){
			b[i]=n/a[i];
		}else{
			b[i]=n/a[i]+1;
		}
	}

	ll minimum=b[0];
	rep(i,5){
		minimum=max(minimum,b[i]);
	}
	cout << 5+minimum-1 << endl;
	return 0;
}


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

int main(){
    long long a, b, c, k;
    cin >> a >> b >> c >> k;
    long long limit = 1000000000000000000;

    long long a_temp, b_temp, c_temp;
    a_temp = a;
    b_temp = b;
    c_temp = c;
    
    if(k % 2 == 0){
        if(abs(a - b) > limit){
            cout << "Unfair" << endl;
            return 0;
        }
        cout << a - b << endl;
        return 0;
    }else{
        if(abs(a - b) > limit){
            cout << "Unfair" << endl;
            return 0;
        }
        cout << b - a << endl;
        return 0;
    }
}

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

using namespace std;

int main() {
  std::ios_base::sync_with_stdio(false);
  int n, Q;
  cin >> n >> Q;
  vector<tuple<int, int, int>> v1, v2;
  for (int i = 0; i < n; i++) {
    int s, t, x;
    cin >> s >> t >> x;
    s -= x, t -= x;
    v1.emplace_back(s, t, x);
    v2.emplace_back(t, s, x);
  }
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  int h1 = 0, h2 = 0;
  map<int, int> mp;
  auto add = [&](int x) {
    mp[x]++;
    if (mp[x] == 0) {
      mp.erase(x);
    }
  };
  auto del = [&](int x) {
    mp[x]--;
    if (mp[x] == 0) {
      mp.erase(x);
    }
  };
  while (Q--) {
    int d;
    cin >> d;
    while (h2 < v2.size() && get<0>(v2[h2]) <= d) del(get<2>(v2[h2++]));
    while (h1 < v1.size() && get<0>(v1[h1]) <= d) add(get<2>(v1[h1++]));
    if (!mp.empty()) {
      cout << mp.begin()->first << endl;
    } else {
      cout << -1 << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 15652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;
 
struct union_find{//1-origin
	vector<int> rnk, par;
 
	union_find(int n) {
		rnk.resize(n+1);
		par.resize(n+1);
		for(int i = 1; i <= n; i++){
			par[i] = i;
			rnk[i] = 0;
		}
	}
 
	int find(int x) {
		if (par[x] == x) return x;
		return par[x] = find(par[x]);
	}
 
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;
		if (rnk[x] < rnk[y]) {
			par[x] = y;
		}
		else {
			par[y] = x;
			if (rnk[x] == rnk[y])rnk[x]++;
		}
	}
 
	bool same(int x, int y) {
		return (find(x) == find(y));
	}
};
 
 
int main(){
	cin.tie(0); ios::sync_with_stdio(false);
 
	ll n, m, k, c, d;
	cin >> n >> m >> k;
	union_find uf(n);
	ll a[m], b[m];
 
	zep(i, 0, m){
		cin >> a[i] >> b[i];
		uf.unite(a[i], b[i]);
	}
 
	ll ans[n+1];
	memset(ans, 0, sizeof(ans));
	rep(i, 1, n){
		if(i != uf.find(i)){
			ans[uf.find(i)]++;
		}
	}
 
	rep(i, 1, n){
		ans[i] = ans[uf.find(i)];
	}
 
	zep(i, 0, m){
		if(uf.find(a[i]) == uf.find(b[i])){
			ans[a[i]]--;
			ans[b[i]]--;
		}
	}
 
	zep(i, 0, k){
		cin >> c >> d;
		if(uf.find(c) == uf.find(d)){
			ans[c]--;
			ans[d]--;
		}
	}
 
	rep(i, 1, n){
		cout << ans[i] << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3968
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <list>
using namespace std;

#define MOD 1000000007
#define p(x) cout << x << endl;
#define el cout << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    char s[n];
    rep(i, n) cin >> s[i];

    set<char> set;
    rep(i, n) set.insert(s[i]);

    if(set.size() == 4){
        p("Four");
    }else{
        p("Three");
    }
}


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

const int divisor = 1000000007;

int main(){
	vector<int> ansvec;

	// 100000!までの数をdivisorで割った余りを格納しておく
	long long* factmodary = new long long[100001];
	long long fact = 1;
	for (int i = 1; i <= 100000; i++){
		fact *= i;
		fact %= divisor;
		factmodary[i] = fact;
	}

	int* word = new int[100000] {0};

	for (;;){
		int N, R;
		cin >> N;
		if (N == 0) break;
		cin >> R;
		
		//まず0番目の単語を入れておく
		for (int i = 0; i < N; i++) word[i] = i + 1;

		for (int i = 0; i < R; i++){
			int s, t;
			cin >> s >> t;
			/* swap */
			int tmp = word[s - 1]; word[s - 1] = word[t - 1]; word[t - 1] = tmp;
		}

		//word[i]をkey, word[i]より小さい数がそれ以前にいくつ使われていたかをvalueとして格納するmap
		map<int, int> bubblehist;
		bubblehist[word[0]] = 0;

		long long ans = factmodary[N-1] * (word[0] - 1);

		for (int i = 1; i < N; i++){
			int facttime = word[i] - 1;
			int bubblenum;
			map<int, int>::iterator it = bubblehist.lower_bound(word[i]);

			if (it != bubblehist.end()){
				bubblenum = it->second;
				--it;
			}
			else {
				it--;
				bubblenum = it->second + 1;
			}
			pair<int, int> p;
			p.first = word[i];
			p.second = bubblenum;
			map<int, int>::iterator it2 = bubblehist.insert(it, p);
			//word[i]より大きい数はすべてvalueが1増える
			for (++it2; it2 != bubblehist.end(); it2++) ++(it2->second);

			facttime -= bubblenum;
			ans += factmodary[N - (i + 1)] * facttime;
			ans %= divisor;
		}
		ansvec.push_back((int)ans);
	}

	for (vector<int>::iterator it = ansvec.begin(); it != ansvec.end(); it++) cout << *it << "\n";

	delete[] word;
	delete[] factmodary;
	return 0;
}

Measured memory_bytes: 6816
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <cstring>
#include <stdlib.h>
#include <string.h>
#include <cmath>
using namespace std;

int main(void){
    int n,d,i,A;
    double x,y,z;
    cin >> n >> d;
    A = 0;
    for(i = 0;i < n;i++){
        cin >> x >> y;
        z = sqrt(x * x + y * y);
        if(z <= d){
            A++;
        }
    }
    cout << A << endl;
}

Measured memory_bytes: 3812
#include<bits/stdc++.h>
using namespace std;
long long mini(long long a,long long b)
{
    if(a<b) return a; return b;
}
int main()
{
    ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
    long long a,b,n,x;
    cin>>a>>b>>n;
    x=mini(n,b-1);
    cout<<(a*x)/b;
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N; ll x;
    cin >> N >> x;
    vector<ll> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];

    ll ans = 0;
    if (a[0] > x) {
        ans += a[0] - x;
        a[0] = x;
    }
    for (int i = 0; i < N - 1; i++) {
        if (a[i] + a[i+1] <= x) continue;
        ll diff = max(0LL, x - a[i]);
        ans += a[i+1] - diff;
        a[i+1] = diff;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void) {
	int N, D;
	int horieyui;
	if (scanf("%d%d", &N, &D) != 2) return 1;
	horieyui = D + 1 + D;
	printf("%d\n", (N + horieyui - 1) / horieyui);
	return 0;
}


Measured memory_bytes: 128
n = int(input())
a = list(map(int, input().split()))

avg = sum(a) / len(a)
diff = list(map(lambda x : abs(x - avg), a))
min_diff = min(diff)
for i in range(n):
    if abs(a[i] - avg) == min_diff:
        print(i)
        break

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    ll N;
    cin>>N;
    long long b[N-1];
    long long mi=0;
    long long ma=0;
    for(long long i=0;i<N-1;i++){
    cin>>b[i];}
    ma+=b[0]+b[N-2];
    for(long long i=0;i<N-2;i++){
    ma+=min(b[i],b[i+1]);}
    cout<<ma<<endl;}

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


int main()
{
	int t,c=0;
	cin>>t;
	int arr[t+10];
	for(int i=0;i<t;i++)
	{
		cin>>arr[i];
		if(arr[i]%2==0 && (arr[i]%3!=0 && arr[i]%5!=0))c++;
	}
	if(c>0)cout<<"DENIED";
	else cout<<"APPROVED";
}

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

typedef int64_t Int;
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << endl; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

int main() {
    Int a, b;
    cin >> a >> b;
    print(a * b);
    return 0;
}

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

int main() {
  int x,a,b; cin >> x >> a >> b;
  int s1 = abs(x-a);
  int s2 = abs(x-b);
  if(s1>s2) cout << "B" << endl;
  else cout << "A" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll n,k; 
ll h[100200];
ll dp[100200];
int main(){
    cin >> n >> k;
    rep(i,n) cin >> h[i];
    rep(i,100200) dp[i] = INFINITY;
    dp[0] = 0;

    rep(i,n){
        _rep(j,1,k + 1){
        dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
        }
    }
    cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1792
s=readline()

hantei1=false
hantei2=false
for i in 1:length(s)
    hantei1=hantei1?true:is(s[i],'C')
    hantei2=hantei1?(hantei2||is(s[i],'F')):false
end
answer=hantei2?"Yes":"No"
println(answer)

Measured memory_bytes: 95732
N,M = map(int,input().split())
a = [int(input()) for _ in range(M)]
a.sort(reverse=True)

if 1 in a:
  a.pop()
  fibs = [1,0]
else:
  fibs = [1,1]

for i in range(2,N+1):
  if len(a) > 0 and i == a[-1]:
    a.pop()
    fibs[0] = fibs[1]
    fibs[1] = 0
  else:
    next = fibs[1] + fibs[0]
    if next > 1000000007:
      next -= 1000000007
    fibs[0] = fibs[1]
    fibs[1] = next

print(fibs[-1])

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


int main() {
  string s, t; cin >> s >> t;
  int cnt = 0;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<char>());

  if(s<t) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
a = list(input()[::-1])
b = list(input()[::-1])
c = list(input()[::-1])
win = "a"
while (a or win != "a") and (b or win != "b") and (c or win != "c"):
    if win == "a":
        win = a.pop()
    elif win == "b":
        win = b.pop()
    else:
        win = c.pop()

if not (a or win != "a"):
    print("A")
elif not (b or win != "b"):
    print("B")
else:
    print("C")

Measured memory_bytes: 38256
#include<cstdio>

int a[200000];

int main(void) {
    int n;
    scanf("%d",&n);

    for(int i=0; i<n; i++)
        scanf("%d",&a[i]), a[i]--;

    int r = 0;
    for(int i=0; i<n; i++)
        if(a[a[i]] == i) r++;
    printf("%d\n", r/2);
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <stack>
using namespace std;

int main(){
    int n;
    int a;
    int ans = 0;
    vector<int> v;
    int i, j;
    cin >> n;
    for(i = 0; i < n; i++){
        cin >> a;
        v.push_back(a);
    }
    for(i = 0; i < n-1; i++){
        for(j = i+1; j < n; j++){
            ans = max(ans, abs(v[i] - v[j]));
        }
    }
    
    cout << ans << endl;
}

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

#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()
#define vec vector<int>
#define dead not_bad
#define bad gooood

#define left not_right
#define y1 what

using namespace std;

const int N = (int) 2e5 + 10;
const int M = (int) 20;
const ll LINF = (ll) 1e18;
const int INF = (int) 1e9 + 7;
const int ALPHA = 26;
const int mod = INF + 2;
const double PI = 3.14159265359;
const ld EPS = (ld) 1e-12;

const int nx[4] = {0, 0, -1, 1};
const int ny[4] = {1, -1, 0, 0};

string st;
set<int> v[26];

int t[N];
int n;

void upd(int x, int val) {
  for (; x < n; x |= x + 1)
    t[x] += val;
}

int get(int x) {
  int ans = 0;
  while (x >= 0) {
    ans += t[x];
    x = (x & (x + 1)) - 1;
  }
  return ans;
}

int get_sum(int l, int r) {
  return get(r) - get(l - 1);
}

int main() {
  #define fn "saddle"
  #ifdef witch
      freopen("input.txt", "r", stdin);
  //    freopen("output.txt", "w", stdout);
  #else
      //freopen(fn".in", "r", stdin);
      //freopen(fn".out", "w", stdout);
  #endif
  cin >> st;
  n = sz(st);
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    v[st[i] - 'a'].insert(i);
    upd(i, 1);
  }
  for (int i = 0; i < 26; i++) {
    cnt += sz(v[i]) % 2;
  }
  if ((sz(st) % 2 && cnt != 1) || (sz(st) % 2 == 0 && cnt != 0))
    return cout << -1, 0;
  ll ans = 0;
  while (true) {
    int cur = INF;
    for (int i = 0; i < 26; i++) {
      if (sz(v[i]) < 2)
        continue;
      int lo = *v[i].begin();
      int hi = *(--v[i].end());
      cur = min(cur, get_sum(0, lo - 1) + get_sum(hi + 1, n - 1));
    }
    if (cur == INF) break;
    for (int i = 0; i < 26; i++) {
      if (sz(v[i]) < 2)
        continue;
      int lo = *v[i].begin();
      int hi = *(--v[i].end());
      if (cur == get_sum(0, lo - 1) + get_sum(hi + 1, n - 1)) {
        upd(lo, -1);
        upd(hi, -1);
        v[i].erase(v[i].begin());
        v[i].erase(--v[i].end());
        break;
      }
    }
    ans += cur;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 10628