akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
// #define ll long long int
#define int long long int
int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	string s;
	cin >> s;
	int n = s.size();

	int ans = 0, last = 0;
	for (int i = 0; i < n - 2; ++i)
	{
		if(s[i] == 'A')
		{
			last++;
			if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
			{
				int j = i;
				j = i - last + 1;
				ans += last;
		

				s[j] = 'B', s[j + 1] = 'C', s[j + 2] = 'A';
				if(j != i)
				{
					s[i + 2] = 'A', s[i + 1] = 'A';
				}
				// cout << i << " " << j << " ";
				// cout << s << "\n";
				last -= 1;
				i++;
			}
		}
		else
			last = 0;
	}
	cout << ans;
	return 0;
}	

Measured memory_bytes: 720
N,X,Y = map(int,input().split())
Ans = [0]*(N+1000)

for i in range(1,N):
    for j in range(i+1,N+1):
        D = min(j-i, abs(i-X)+1+abs(j-Y),abs(Y-i)+1+abs(j-X))
        Ans[D] += 1
        
for i in range(1,N):
    print(Ans[i])

Measured memory_bytes: 48860
def main(): 
  H, W = list(map(int, input().split()))
  a = []
  for i in range(H):
    a.append(list(input()))
    
  DP = [[0 for i in range(W)] for j in range(H)]
  
  DP[0][0] = 1
  for i in range(1, W):
    if a[0][i] == ".":
      DP[0][i] = 1
    else:
      break
  for i in range(1, H):
    if a[i][0] == ".":
      DP[i][0] = DP[i - 1][0]
    for j in range(1, W):
      if a[i][j] == ".":
        DP[i][j] = int((DP[i - 1][j] + DP[i][j - 1]) % (1e9 + 7))
  print(DP[-1][-1]) 
main()

Measured memory_bytes: 90972
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(x) for(auto it=(x).begin();it!=(x).end();it++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
//#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

int main(){
    string s;
    while(cin>>s){
        vector<int> v(10);
        rep(i,0,10){
            v[i]=s[i]-'0';
        }
    
        rep(i,0,9){
            rep(j,0,9){
                v[j]=(v[j]+v[j+1])%10;
            }
        }
        cout<<v[0]<<endl;
    }
    
    return 0;
}



Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define fr(i,n) for(int i=0;i<(n);i++)
#define Fr(i,n) for(int i=0;i++<(n);)
#define ifr(i,n) for(int i=(n)-1;i>=0;i--)
#define iFr(i,n) for(int i=(n);i>0;i--)

const ll MOD=1e9+7;

ll ad(ll x,ll y=0){
  return (x+y)%MOD;
}

ll mlt(ll x,ll y=1){
  return (x*y)%MOD;
}

ll pwr(ll x,ll y){
  ll pw[32]={},w=1;
  pw[0]=x;
  fr(i,31) pw[i+1]=mlt(pw[i],pw[i]);
  fr(i,32){
    w=mlt(w,1+(y%2)*(pw[i]-1));
    y/=2;
  }
  return w;
}

ll inv(ll x){
  return pwr(x,MOD-2);
}

int main(){
    ll n,s=0,ans=0;
    cin>>n;
    vector<ll> dp1(n+3),t(n+3);
    dp1[0]=1;
    t[0]=t[1]=t[2]=1;
    ll m=mlt(n-1,n-1);
    fr(i,n){
        s=ad(s,dp1[i]);
        dp1[i+3]=ad(dp1[i+2],s);
        t[i+3]=ad(t[i+2],dp1[i+3]);
    }
    fr(i,n-1){
        ans=ad(ans,mlt(ad(m,i+1),t[i]));
    }
    ans=ad(ans,mlt(t[n-1],n-1));
    ans=ad(ans,t[n]);
    cout<<ans<<endl;
}

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

int M;
ll d_sum, c_sum;

int main() {
    cin >> M;
    d_sum = c_sum = 0;
    rep(i, M) {
        ll d, c;
        cin >> d >> c;
        c_sum += c;
        d_sum += d * c;
    }
    ll ans = c_sum - 1 + (d_sum - 1) / 9;
    cout << ans << endl;
}


Measured memory_bytes: 256
/* 
 * Project: AtCoder Beginners Contest 095 B - Bitter Alchemy
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/06/12
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <algorithm>
#include <numeric>
using namespace std;

int n, x;
int m[1000];

void solve() {

    int min_m = *min_element(m, m+n);
    int last = x - accumulate(m, m+n, 0);
    int sum = last / min_m + n;
    printf("%d\n", sum);

}

int main() {

    scanf("%d", &n);
    scanf("%d", &x);
    for (int i=0;i<n;i++) {
        scanf("%d", &m[i]);
    }

    solve();

}

Measured memory_bytes: 256
import bisect
import sys
input = sys.stdin.readline

a,b,q = map(int,input().split())
s = []
t = []
s1 = []
t1 = []

for _ in range(a):
    s.append(int(input()))
for _ in range(b):
    t.append(int(input()))

for i in range(a-1):
    s1.append((s[i]+s[i+1])/2)
for i in range(b-1):
    t1.append((t[i]+t[i+1])/2)

for _ in range(q):
    x = int(input())
    s_index = bisect.bisect_left(s1, x)
    t_index = bisect.bisect_left(t1, x)
    xs = []
    xt = []
    for i in range(-2, 3):
        if 0 <= s_index + i < a:
            xs.append(s[s_index+i])
        if 0 <= t_index + i < b:
            xt.append(t[t_index+i])
    ans = 10**20
    for i in xs:
        for j in xt:
            ans = min(ans, abs(x-i) + abs(i-j), abs(x-j) + abs(j-i))

    print(ans)


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

using namespace std;

int main(){
  vector< int > num( 3 );

  for ( int i = 0; i < 3; i++ ){
    cin >> num.at( i );
  }

  sort( num.begin(), num.end(), greater< int >() );

  cout << num.at( 0 ) * 10 + num.at( 1 ) + num.at( 2 ) << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define faster ios_base::sync_with_stdio(0);
#define faster_tie cin.tie(0);
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define NL cout<<'\n'

ll n,k,x;
vector<ll>height;
ll sol[110000];

ll solve(ll x)
{
    if(x==1)
    {
        sol[x]=0;
        return 0;
    }
    if(sol[x]!=-1)return sol[x];
    ll a=INT_MAX;

    for(ll i=x-1;i>x-1-k;i--)
    {
        if(i==0)break;
        a=min(a,solve(i)+abs(height[i]-height[x]));
    }
    sol[x]=a;
    return a;

}


int main()
{
    cin>>n>>k;
    height.push_back(-1);
    for(ll i=0;i<=n;i++)
    {
        sol[i]=-1;
    }
    for(int i=0;i<n;i++)
    {
        cin>>x;
        height.push_back(x);
    }

    ll ans=solve(n);
    cout<<ans;



    return 0;
}


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

int main() {
  int a[3];
  for(int i=0;i<3;i++) cin>>a[i];
  sort(a,a+3);
  if(a[0]==5 && a[1]==5 && a[2]==7) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, X, T):
    return -(-N//X)*T


def main():
    N, X, T = read_int_n()
    print(slv(N, X, T))


if __name__ == '__main__':
    main()


Measured memory_bytes: 83424
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0)
//#define MULTI_TEST
//#define GOOGLE
#ifdef LOCAL
#include "debugger.h"
#else
#define db(...)
#endif
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
const ll MOD = 1e9 + 7;
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }

void solve()
{

	string s;
	cin >> s;
	if (s == "ABC")
		cout << "ARC" << ln;
	else
		cout << "ABC" << ln;
	return;
}

int main()
{
#ifndef LOCAL
	FASTIO;
#endif
	int t = 1;
#ifdef LOCAL
	clock_t start, stop;
	start = clock();
#endif
#ifdef MULTI_TEST
	cin >> t;
#endif
	for (int tc = 1; tc < t + 1; tc++)
	{
#ifdef GOOGLE
		cout << "Case #" << tc << ": ";
#endif
		solve();
	}
#ifdef LOCAL
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


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

using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;


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

    bool can = false;
    for(int i=0; i<=N; i++){
        int num = i*1.08;
        if(num==N){
            cout << i << endl;
            can =true;
            break;
        }
    }
    if(!can) cout << ":(" << endl;



}

Measured memory_bytes: 384
import sys
input = sys.stdin.readline


def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [0] + [float("inf")] * (n-1)
    for i in range(1, n):
        for j in range(max(0, i-k), i):
            dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]))
    
    print(dp[-1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 55132
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys

def s():
    return raw_input().strip()
def n():
    return int(raw_input())
def d():
    return float(raw_input())

def ls():
    return raw_input().strip().split()
def ln():
    return map(int, raw_input().strip().split())
def ld():
    return map(float, raw_input().strip().split())

def fs():
    return [raw_input().strip() for i in xrange(input())]
def fn():
    return [int(raw_input().strip()) for i in xrange(input())]
def fd():
    return [float(raw_input().strip()) for i in xrange(input())]

N, M = ln()

XY = []
for i in xrange(M):
    XY.append(ln())

candidate = set([1])
num = [0] + [1] * N
for x, y in XY:
    num[x] -= 1
    num[y] += 1
    if x in candidate:
        candidate.add(y)
    if num[x] == 0:
        candidate.discard(x)

print len(candidate)

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

const int dh[] = {1, 0, -1, 0};
const int dw[] = {0, 1, 0, -1};

const int NOT_VISITED = -1;

int main() {
  int h, w;
  cin >> h >> w;

  vector<string> v(h);
  rep(i, h) cin >> v[i];

  vector<vector<int>> dist(h, vector<int>(w, NOT_VISITED));
  queue<pair<int, int>> q;

  rep(i, h) rep(j, w) {
    if (v[i][j] == '.')
      continue;
    dist[i][j] = 0;
    q.emplace(i, j);
  }

  while (!q.empty()) {
    auto curr = q.front();
    q.pop();

    for (int k = 0; k < 4; ++k) {
      int nh = curr.first + dh[k], nw = curr.second + dw[k];

      if (nh < 0 || h <= nh || nw < 0 || w <= nw)
        continue;
      if (dist[nh][nw] != NOT_VISITED)
        continue;

      q.emplace(nh, nw);
      dist[nh][nw] = dist[curr.first][curr.second] + 1;
    }
  }

  int ans = 0;
  rep(i, h) rep(j, w) ans = max(ans, dist[i][j]);
  cout << ans << endl;
}

Measured memory_bytes: 13456
import scala.io.StdIn.{readLine,readInt}

object Main {
  def merge(a: Array[Int], left: Int, mid: Int, right: Int) = {
    val l = new Array[Int](mid-left+1)
    val r = new Array[Int](right-mid+1)
    Array.copy(a,left,l,0,l.length-1)
    Array.copy(a,mid,r,0,r.length-1)
    l(mid-left) = Int.MaxValue
    r(right-mid) = Int.MaxValue

    def loop(a: Array[Int], i: Int, j: Int, k: Int, cnt: Int):Int = {
      if(k==right) cnt
      else if( l(i) <= r(j) ) {
        a(k) = l(i)
        loop(a, i+1, j, k+1, cnt+1)
      } else {
        a(k) = r(j)
        loop(a, i, j+1, k+1, cnt+1)
      }
    }
    loop(a, 0, 0, left, 0)
  }

  def mergeSort(a: Array[Int], left: Int, right: Int):Int = {
    if(left+1<right) {
      val mid = (left + right) / 2
      val x = mergeSort(a, left, mid)
      val y = mergeSort(a, mid, right)
      x + y + merge(a,left,mid,right)
    } else 0
  }

  def main(args:Array[String]) = {
    val n = readInt
    val a = readLine.split(" ").map(_.toInt)
    val cnt = mergeSort(a,0,a.length)
    println(a.mkString(" "))
    println(cnt)
  }
}


Measured memory_bytes: 282204
#include <iostream>
#include <string>
#include <stack>

using namespace std;

int main() {
  string s;
  stack<int> st;

  while (cin >> s) {
    if ( s[0] == '+' ) {
      int o1 = st.top(); st.pop();
      int o2 = st.top(); st.pop();
      st.push(o1 + o2);
    } else if ( s[0] == '-' ){
      int o2 = st.top(); st.pop();
      int o1 = st.top(); st.pop();
      st.push(o1 - o2);
    } else if ( s[0] == '*' ){
      int o1 = st.top(); st.pop();
      int o2 = st.top(); st.pop();
      st.push(o1 * o2);
    } else {
      st.push(stoi(s));
    }
  }
  cout << st.top() << endl;
  return 0;
}


Measured memory_bytes: 3208
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	string s[3];
  rep(i, 3) cin>>s[i];
  rep(i, 3) reverse(all(s[i]));
  int p = 0;
  while(!s[p].empty()){
    int p2 = s[p].back()-'a';
    s[p].erase(s[p].end()-1);
    p = p2;
  }
  cout<<(char)('A'+p)<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.BitSet;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), m = scanner.nextInt();
			BitSet routeTo1 = new BitSet(n), routeToN = new BitSet(n);
			IntStream.range(0, m).forEach(i -> {
				int a = scanner.nextInt() - 1, b = scanner.nextInt() - 1;
				if (0 == Math.min(a, b)) {
					routeTo1.set(Math.max(a, b), true);
				}
				if (n - 1 == Math.max(a, b)) {
					routeToN.set(Math.min(a, b), true);
				}
			});
			int count = (int) IntStream.range(1, n - 1).filter(i -> routeTo1.get(i) && routeToN.get(i)).count();
			System.out.println((count > 0) ? "POSSIBLE" : "IMPOSSIBLE");
		}
	}
}


Measured memory_bytes: 59992
// Aizu Vol-10 1042: Yes, I have a number
// 2017.8.17

#include <stdio.h>
#include <ctype.h>
#include <string.h>

char *gets();
char buf[1000], *p;

int main(void)
{
	int w;
	
	while (1) {
		gets(p = buf);
		if (!strcmp(buf, "END OF INPUT")) break;
		while (*p) {
			w = 0;  while (isspace(*p)) w++, p++;
			while (w > 1) putchar('0'), w--;
			if (!*p) break;
			w = 0;	while (isalpha(*p)) w++, p++;
			putchar('0' + w);
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 524
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string.h>
#include <stdlib.h>
using namespace std;

int main(){

    int N;
    cin >> N;
    bool b_ans = 0;


    for(int i = 1 ; i < 10 ; i++){
        for(int j = 1 ; j < 10 ; j++){
            if( i*j == N ) b_ans = 1;
        }
    }

    if( b_ans ) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;

int n;
LL T;

int main()
{
	while (~scanf("%d%lld", &n, &T)) {
		LL L = 0, R = 0, ans = 0;
		for (int i = 1; i <= n; i++) {
			LL t;
			scanf("%lld", &t);
			if (t > R) ans += R - L, L = t;
			R = t + T;
		}
		ans += R - L;
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
typedef pair<int,int> pii;

int main()
{
    int a,b;
    cin>>a>>b;
    for(int i=1;i<=2000;i++){
        if(i*8/100==a&&i*1/10==b){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}

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

int n,a[3];
vector<int> lv;

int dfs(vector<int> fv){
	if(fv.size() >= n){
		int score = 0;
		for(int i=0;i<3;++i){
			int cnt = -1;
			int tmp = 0;
			for(int j=0;j<n;++j){
				if(fv[j] == i){
					cnt++;
					tmp += lv[j];
				}
			}
			if(cnt == -1) return 9999999;
			score += (abs(tmp-a[i]) + cnt * 10);
		}
//		cout << score << endl;
//		for(int j=0;j<n;++j){cout << fv[j] << " ";}cout << endl;

		return score;
	}else{
		int res = 99999999;
		for(int i=0;i<4;++i){
			vector<int> ffv = fv;
			ffv.push_back(i);
			res = min(res,dfs(ffv));
		}
		return res;
	}
}

int main(){
	cin >> n >> a[0] >> a[1] >> a[2];
	for(int i=0;i<n;++i){
		int tmp;
		cin >> tmp;
		lv.push_back(tmp);
	}
	
	cout << dfs(vector<int>()) << endl;
	
	
	
	return 0;
}


Measured memory_bytes: 256
n = int(input())
trump = []
for i in range(n):
    str, num = input().split()
    num = int(num)
    trump.append((str, num, i))

def partition(a, p, r):
    x = a[r-1][1]
    i = p-1
    for j in range(p,r-1):
        if a[j][1] <= x:
            i = i+1
            a[i], a[j] = a[j], a[i]
    a[i+1], a[r-1] = a[r-1], a[i+1]
    return i+1

def quick_sort(a, p, r):
    if(p < r):
        q = partition(a, p, r)
        quick_sort(a, p, q)
        quick_sort(a, q+1, r)

def isStable(a):
    for i in range(1,len(a)):
        if a[i-1][1] == a[i][1]:
            if a[i-1][2] > a[i][2]:
                return False
    return True


quick_sort(trump,0,n)
if(isStable(trump)):
    print('Stable')
else:
    print('Not stable')
for i in trump:
    print('{} {}'.format(i[0], i[1]))



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

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

  int ans=0;
  rep(i,N-2){
   if(S.at(i) == 'A' && S.at(i+1) == 'B' && S.at(i+2) == 'C'){
     ans++;
   } 
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <math.h>
#include <time.h>
using namespace std;
const long long mod = 1000000007;
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
bool dbg = false;
long long gcd(long long a, long long b){
   if (a % b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a % b));
   }
}
long long lcm(long long a, long long b){
   return (a / gcd(a, b))* b;
}
//---------------------------------------------------------------------------------------------------
/*ここからいじる*/
//---------------------------------------------------------------------------------------------------
int n, m, cnt;
vector<pair<int, int> >p(100);
vector<vector<bool> >data(9, vector<bool>(9));
void solve(){
    vector<int>array(n);
    for(int i = 0; i < n; i++){
        array.at(i) = i;
    }
    do{
        for(int i = 0; i < n - 1; i++){
            if(i == 0){
                if(array.at(i) != 0){
                    break;
                }
            }
            if(!data.at(array.at(i)).at(array.at(i + 1))){
                break;
            }
            if(i == n - 2){
                cnt++;
            }
        }
    }while(next_permutation(array.begin(), array.end()));
    cout << cnt << endl;
}
int main(){
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        cin >> p.at(i).first >> p.at(i).second;
        p.at(i).first--;
        p.at(i).second--;
    }
    for(int i = 0; i < m; i++){
        data.at(p.at(i).first).at(p.at(i).second) = true;
        data.at(p.at(i).second).at(p.at(i).first) = true;
    }
    cnt = 0;
    solve();
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

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

		int r = sc.nextInt();

		System.out.println(r < 1200 ? "ABC" : r < 2800 ? "ARC" : "AGC");

		sc.close();

	}
}



Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const int MOD = 1000000007;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")




int main() {


    ll n,a,Max = -1,sum = 0; cin >> n;

    rep(i,n){
        cin >> a;
        sum += a;
        Max = max(a,Max);
    }

    if(sum-Max > Max) cout << "Yes";
    else cout << "No";



    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include<vector>
#include<set>
#include<algorithm>

using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
#define T int t, q=0; scanf("%d", &t); while(q++<t)
#define ll long long
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
ll x,y,z,a=0,b=0,c=0,d=0,sum,ans,total,cnt,n,m,k,p,kase,i,t;
string s1,s2;
#define N 100001
#define MX 1000000001
vector <ll> v;
map<ll,ll> mp;
set<ll> s;
map<ll,ll> :: iterator itr1, ptr1;
set<ll> :: iterator itr, ptr;


int main()
{


        cin>>n;

        int ar[n];

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


        sum=0;
        for(int i=0;i<n-1;i++)
        {
            if(ar[i]>ar[i+1])
            {
                a=ar[i]-ar[i+1];
                sum+=a;

                ar[i+1]=ar[i+1]+a;
            }
        }

        cout<<sum<<endl;




    return 0;
}
// Happy Coding  (:



Measured memory_bytes: 4416
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
ll sp[maxn];
ll ri,le;
ll a,b,n;
bool check(ll x)
{
    ll how=0;
    for(int i=1;i<=n;++i)
    {
        if(sp[i]>x*b)
        {
            ll kk=sp[i]-x*b;
            if(kk%(a-b)==0)
            {
                how+=(kk/(a-b));
            }
            else how+=(kk/(a-b))+1;
        }
    }
    if(how>x)return 1;
    else return 0;
}
int main()
{
    ri=0;
    le=1;
    cin>>n>>a>>b;
    for(int i=1;i<=n;++i)
    {
        cin>>sp[i];
    }
    sort(sp+1,sp+1+n);
    for(int i=1;i<=n;++i)
    {
        ri=ri+sp[i]/b+1;
    }
    ll mid;
    while(le<ri)
    {
        mid=(le+ri)/2;
        if(check(mid)==1)
        {
            le=mid+1;
        }
        else ri=mid;
    }
    cout<<le<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i,a,b) for(ll i=a;i<b;i++)
using namespace std;
typedef long long ll;
std::vector<int> adj[200005];
ll arr[200005];
void FAST() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

int main(int argc, char const *argv[])
{
	   FAST();
 ll n; cin>>n;
 REP(i,0,n){
 	cin>>arr[i];
 }	

 ll max=arr[0]; ll count=0;
  REP(i,1,n){
  	if(arr[i]<max){
  		count=count+abs(arr[i]-max);
  	}
  	else
  		max=arr[i];
  }

  cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 9896
#include <iostream>
#include<string>
#include<math.h>
using namespace std;


int main(){
    int H,W;
    cin >> H >>W;
    bool ans=true;
    char s[H+2][W+2];
    for(int i=1;i<H+1;i++){
        for(int j=1;j<W+1;j++){
            cin >> s[i][j];
        }
    }
    for(int i=1;i<H+1;i++){
        for(int j=1;j<W+1;j++){
            if(s[i][j]=='#'){
                if(s[i-1][j]!='#'&&s[i+1][j]!='#'&&s[i][j-1]!='#'&&s[i][j+1]!='#'){
                    ans=false;
                }
            }
        }
    }
    if(ans){
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn

object Main extends App {

  val n = StdIn.readLine().trim.toInt
  class Point(val x: Double, val y: Double){
    override def toString: String = {
      f"$x%.8f $y%.8f"
    }
  }
  
  final val start = new Point(0, 0)
  final val end   = new Point(100, 0)
  final val th = scala.math.Pi * 60.0 / 180.0

  def calcuPoint(p1: Point, p2: Point, a: Double, b: Double) = new Point((a*p1.x+b*p2.x)/3.0, (a*p1.y+b*p2.y)/3.0)
  
  
  def koch(d: Double, p1: Point, p2: Point): Unit = {
    if(d != 0){
      val s = calcuPoint(p1, p2, 2.0, 1.0) 
      val t = calcuPoint(p1, p2, 1.0, 2.0)
      val u = new Point((t.x - s.x)*math.cos(th) - (t.y - s.y)*math.sin(th) + s.x,
                        (t.x - s.x)*math.sin(th) + (t.y - s.y)*math.cos(th) + s.y)
      koch(d-1, p1, s)
      // print s
      println(s)
      
      koch(d-1, s, u)
      // print u
      println(u)
      
      koch(d-1, u, t)
      // print t
      println(t)

      koch(d-1, t, p2)

    }
  }

  println(start)
  koch(n, start, end)
  println(end)
}




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

int main(){
    int w1,w2,s1,s2,e,f;
    cin >> w1 >> w2 >> s1 >> s2 >> e >> f;
    double max_p=0;
    int max_water=w1;
    int max_sugar=0;
    for(int i=0; w1*100*i<f; i++){
        for(int j=0; w2*100*j<f; j++){
            int w=w1*100*i+w2*100*j;
            if(w >= f) continue;
            int possible_s=min(f-w,w*e/100);
            int max_s=0;
            for(int k=0; s1*k<=possible_s; k++){
                for(int l=0; s2*l<=possible_s; l++){
                    int s=s1*k+s2*l;
                    if(s>possible_s) continue;
                    max_s=max(max_s,s);
                }
            }
            if((double)max_s/(w+max_s) >= max_p){
                max_p=(double) max_s/(w+max_s);
                max_sugar=max_s;
                max_water=w;
            }
        }
    }
    cout << max_sugar+max_water << " " << max_sugar << endl;
}

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

int main()
{
  int N ;
  cin>>N ;
  vector<int>A(N) ;
  vector<int>B(N) ;
  vector<int>C(N-1) ;
  for(int i=0;i<N;i++) cin>>A.at(i) ;
  for(int i=0;i<N;i++) cin>>B.at(i) ;
  for(int i=0;i<N-1;i++) cin>>C.at(i) ;
  
  int satisfaction=B.at(A.at(0)-1) ;
  for(int i=1;i<N;i++){
    satisfaction+=B.at(A.at(i)-1) ;
    if(A.at(i)-A.at(i-1)==1) satisfaction+=C.at(A.at(i-1)-1) ;
  }
  cout<<satisfaction<<endl ;
  
  return 0 ;
}

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

int main() {
  int n,alice=0,bob=0;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    int ai;
    cin>>ai;
    a[i]=ai;
  }

  while(true){
    int change=0;
    for(int j=0;j<n-1;j++){
      if(a[j]<a[j+1]){
        swap(a[j],a[j+1]);
        change=1;
      }
    }
    if(change==0){
      break;
    }
  }

  for(int i;i<n;i++){
    if(i%2==0){
      alice+=a[i];
    }else{
      bob+=a[i];
    }
  }

  cout<<alice-bob<<endl;

}

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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

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

map<ll,ll> mp;

int main(void)
{
  ll n;
  cin >> n;
  REP(i, n) {
    ll a1;
    cin >> a1;
    mp[a1]++;
  }
  ll l1 = 0, l2 = 0;
  for(auto v:mp) {
    //    cout << v.first  << " " << v.second<< endl;
    if(v.second >= 4) {
      l1 = l2 = v.first;
    } else if(v.second >= 2) {
      l2 = l1;
      l1 = v.first;
    }
  }
  //  cout << l1 << " " << l2 << endl;
  cout << (l1 * l2) << endl;
}


Measured memory_bytes: 6528
import sys
import numpy as np
from math import ceil
from collections import defaultdict as D

def S(): return sys.stdin.readline().rstrip().split(' ')
def Ss(): return list(S())
def I(): return _I(Ss())
def Is(): return list(I())
def _I(ss): return map(int, ss) if len(ss) > 1 else int(ss[0])

c = S()[0]
print('A' if c in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' else 'a')

Measured memory_bytes: 27076
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m,s,c,a[5];
	cin>>n>>m;
	for(int i=0;i<=5;i++){
		a[i]=10;
	}
	for(int i=0;i<m;i++){
		cin>>s>>c;
		if(a[s-1]!=c && a[s-1]!=10){
			cout<<"-1"<<endl;
			return(0);
		}
		else{
			a[s-1]=c;
		}
	}
	if(a[0]==0 && n!=1){
		cout<<"-1"<<endl;
		return(0);
	}
	else{
		for(int i=0;i<n;i++){
			if(a[i]!=10)
			cout<<a[i];
			else if(i==0 && n!=1)
				cout<<"1";
			else
				cout<<"0";
		}
	}
	cout<<endl;
  return(0);
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  ll Q; cin >> Q; ll c, d;
  rep(i, Q){
    ll a, b; cin >> a >> b; c = a*b-1; d= sqrtl(c);
    //cout << c << " " << d << endl;
    ll ans = 2*d-1; if(d*d<=c && c<d*(d+1)) ans--;
    if(a==b) ans++;
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<vector>
#include<map>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  cout << setprecision(10);
  const long M = 1e9+7;
  long N, K;
  cin >> N >> K;
  vector<long> A(N);
  for(long &ai: A) cin >> ai;
  long ret = 0;
  for(int i=0; i<N; i++){
    for(int j=0; j<i; j++){
      if(A[i]<A[j]) ret=(ret+K)%M;
    }
    for(int j=0; j<N; j++){
      if(A[i]<A[j]) ret=(ret+(K-1)*K/2)%M;
    }
  }
  cout << ret << endl;
  return 0;
}

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

using namespace std;

long long calc(const vector<int>& X, int P){
    long long res = 0;
    for(auto& t : X) res += (P-t)*(P-t);
    return res;
}

int main(){
    int N;
    while(cin >> N){
        vector<int> X(N);
        for(auto& t : X) cin >> t;
        long long res = (1LL << 60);
        for(int i=0;i<=100;i++) res = min(res, calc(X, i));
        cout << res << endl;
    }
}

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

using namespace std;

typedef long long ll;

int main(){
  ll a[3],f=0,s=0;
  
  cin>>a[0]>>a[1]>>a[2];
  
  for(int i=0; i<3; i++){
    if(a[i]==5){
      f++;
    }
    if(a[i]==7){
      s++;
    }
  }
  if(f==2&&s==1){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
  return 0;
}

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

class Dice{
public:
    int n[6];

    Dice(){
      for(int i=0;i<6;i++){
        cin >> n[i];
      }
    }
    int N(){
      int x;
      x=n[0];
      n[0]=n[1];
      n[1]=n[5];
      n[5]=n[4];
      n[4]=x;
      return n[0];
    }
    int E(){
      int x;
      x=n[0];
      n[0]=n[3];
      n[3]=n[5];
      n[5]=n[2];
      n[2]=x;
      return n[0];
    }
    int W(){
      int x;
      x=n[0];
      n[0]=n[2];
      n[2]=n[5];
      n[5]=n[3];
      n[3]=x;
      return n[0];
    }
    int S(){
      int x;
      x=n[0];
      n[0]=n[4];
      n[4]=n[5];
      n[5]=n[1];
      n[1]=x;
      return n[0];
    }
};

int main(){
  Dice d;
  string m;
  cin >> m;

  int j=0,roof;
  while(j<=m.size()){
    if(m[j]=='N'){
      roof = d.N();
    }else if(m[j]=='E'){
      roof = d.E();
    }else if(m[j]=='W'){
      roof = d.W();
    }else if(m[j]=='S'){
      roof = d.S();
    }
    j++;
  }

  cout << roof << endl;
  return 0;
}



Measured memory_bytes: 3212
#include<iostream>

using namespace std;

int main(){
    int n;
    cin >> n;
    int x[101], y[101];
    int h[101];
    int X,Y,H;
    for(int i=0;i<n;i++) {
        cin >> x[i] >> y[i] >> h[i];
        if(h[i] >= 1) {
            X = x[i];
            Y = y[i];
            H = h[i];
        }
    }
    for(int i=0;i<=100;i++){
        for(int j=0;j<=100;j++){
            int tmp = H+abs(X-i)+abs(Y-j);
            bool flag = true;
            for(int l=0;l<n;l++){
                int H2=tmp-abs(x[l]-i)-abs(y[l]-j);
                if(h[l] > 0 && h[l] != H2) flag = false;
                if(h[l] == 0 && H2 > 0) flag = false;
            }
            if(flag) {
                cout << i << " " << j << " " << tmp << endl;
            }
        }
    }
}


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

using namespace std;


int main(){
    int k, x;
    cin >> k >> x;

    int a = x;
    for(int i = k-1; i > 0; i--){
        a = x-i;
        //if(a >= -100 && a <= 100){
            cout << a << " ";
        //}
    }

    for(int i = 0; i < k; i++){
        a = x+i;
        //if(a >= -100 && a <= 100){
            cout << a << " ";
        //}
    }
    

    cout << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {

	var a float64

	fmt.Scan(&a)

	riding2 := math.Pow(a, 2)
	riding3 := math.Pow(a, 3)

	sum := a + riding2 + riding3

	fmt.Print(sum)
}


Measured memory_bytes: 1836
#include <iostream>
#include <vector>
using namespace std;
const int MOD = (int)1e8 + 7;


//---------------------------------------------------------------
template<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long 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); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& os, const ModInt<MOD>& mi) { return os << mi.get(); }
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
template<typename T, int FAC_MAX> struct Comb { vector<T> fac, ifac;
    Comb() { fac.resize(FAC_MAX + 1, 1); ifac.resize(FAC_MAX + 1, 1);
        for (int i = 1; i <= FAC_MAX; i++) fac[i] = fac[i - 1] * i;
        for (int i = 1; i <= FAC_MAX; i++) ifac[i] = T(1) / fac[i]; }
    T aPb(int a, int b) { if (b < 0 || a < b) return T(0); return fac[a] * ifac[a - b]; }
    T aCb(int a, int b) { if (b < 0 || a < b) return T(0); return fac[a] * ifac[a - b] * ifac[b]; }
    T nHk(int n, int k) { if (n == 0 && k == 0) return T(1); if (n <= 0 || k < 0) return 0;
        return aCb(n + k - 1, k); }
    T fact(int n) { if (n < 0) return T(0); return fac[n]; }
};
typedef ModInt<MOD> mint;
//---------------------------------------------------------------


int main() {
    Comb<mint, 2000> com;
    int r, c, sx, sy, tx, ty;
    cin >> r >> c >> sx >> sy >> tx >> ty;

    int x = min(abs(sx - tx), r - abs(sx - tx));
    int y = min(abs(sy - ty), c - abs(sy - ty));

    mint k = 1;
    if (abs(sx - tx) == r - abs(sx - tx)) k *= 2;
    if (abs(sy - ty) == c - abs(sy - ty)) k *= 2;

    mint ans = com.aCb(x + y, x);

    cout << ans * k << endl;
}


Measured memory_bytes: 3124
s1 = input()

r1 = 999
t1 = 0
for i1 in range(len(s1) - 2):
    t1 =  abs(753 - int((int(s1[i1]) * 100) + (int(s1[i1 + 1]) * 10) + int(s1[i1 + 2])))
    if r1 > t1:
        r1 = t1

print(r1)

Measured memory_bytes: 3060
import math

n, m = map(int, input().split())
s = input()
t = input()

gcd = math.gcd(n, m)
N = n // gcd
M = m // gcd
ans = n * m // gcd
for i in range(gcd):
    if s[i*N] != t[i*M] :
        ans = -1
        break
print(ans)

Measured memory_bytes: 9280
#include <stdio.h>

int check_wall(int x, int y);

int h, w;

int main(int argc, char const *argv[])
{
	int i, j;
	while(1){
		scanf("%d %d", &h, &w);
		if(h == 0 && w == 0)
			break;
		for(i = 0; i < h; i++){
			for(j = 0; j < w; j++){
				if(check_wall(j, i)){
					printf("#");
				}else{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

int check_wall(int x, int y){
	if((x == 0) || (x == (w -1)) || (y == 0) || (y == (h - 1))){
		return 1;
	}
	return 0;
}

Measured memory_bytes: 572
/************************************************
 * Au: Hany01
 * Prob: agc001c
 * Email: hany01dxx@gmail.com & hany01@foxmail.com
 * Inst: Yali High School
************************************************/

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
#define Rep(i, j) for (register int i = 0, i##_end_ = (j); i < i##_end_; ++ i)
#define For(i, j, k) for (register int i = (j), i##_end_ = (k); i <= i##_end_; ++ i)
#define Fordown(i, j, k) for (register int i = (j), i##_end_ = (k); i >= i##_end_; -- i)
#define Set(a, b) memset(a, b, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define X first
#define Y second
#define PB(a) push_back(a)
#define MP(a, b) make_pair(a, b)
#define SZ(a) ((int)(a).size())
#define ALL(a) a.begin(), a.end()
#define INF (0x3f3f3f3f)
#define INF1 (2139062143)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define y1 wozenmezhemecaia

template <typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }

template <typename T> inline T read() {
	static T _, __; static char c_;
    for (_ = 0, __ = 1, c_ = getchar(); c_ < '0' || c_ > '9'; c_ = getchar()) if (c_ == '-') __ = -1;
    for ( ; c_ >= '0' && c_ <= '9'; c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
    return _ * __;
}
//EOT


const int maxn = 2005;


int n, k;


int e = 1, beg[maxn], nex[maxn << 1], v[maxn << 1];
inline void add(int uu, int vv) { v[++ e] = vv, nex[e] = beg[uu], beg[uu] = e; }

inline void input() {
	static int u, v;
	n = read<int>(), k = read<int>();
	For(i, 2, n) u = read<int>(), v = read<int>(), add(u, v), add(v, u);
}

int res;

void DFS(int u, int pa, int dep) {
	-- res;
	if (dep == (k >> 1)) return;
	for (register int i = beg[u]; i; i = nex[i]) if(v[i]!=pa) DFS(v[i], u, dep + 1);
}

inline void solve() {
	int ans = INF;
	if (k & 1) For(i, 1, n - 1) res = n, DFS(v[i << 1], v[i << 1 | 1], 0), DFS(v[i << 1 | 1], v[i << 1], 0), chkmin(ans, res);
	else For(i, 1, n) res = n, DFS(i, 0, 0), chkmin(ans, res);
	printf("%d\n", ans);
}

int main()
{
#ifdef hany01
	freopen("agc001c.in", "r", stdin);
	freopen("agc001c.out", "w", stdout);
#endif

	input();
	solve();

	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	static long[] mai;
	static long[] paty;
	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int N=gi();
	    long X=gl();
	    mai=new long[N+1];
	    paty=new long[N+1];
        mai[0]=1;
        paty[0]=1;
	    for(int i=1; i<N+1;i++) {
	    	mai[i]=mai[i-1]*2+3;
	    	paty[i]=paty[i-1]*2+1;
	    }
	    System.out.print(f(N,X));
	}

	public static long f(int n, long x) {
        if(x==0)return 0;
		if(n==0) {
			if(x==0) {
				return 0;
			} else {
				return 1;
			}
		}
		long half=(mai[n]-1)/2;
		if (half<x) {
			return paty[n-1] + 1 + f(n-1, x-half-1);
		} else {
			return f(n-1, x-1);
		}
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n+1);
  for(int i=1;i<=n;i++){
    cin >> a.at(i);
  }
  
  int ans=0;
  for(int i=1;i<=n;i=i+2){
    if(a.at(i)%2==1){
      ans++;
    }
  }
  
  cout << ans << endl;
}

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

int main(void){
  string s,t; cin >> s >> t;

  int n = 26;
  vector<int> start(n,-1);
  vector<int> to(n,-1);

  rep(i,s.size()){
    int a = s[i]-'a';
    int b = t[i]-'a';

    if(start[a] != -1 && start[a] != b){      
      cout << "No" << endl;
      return 0;
    }
    if(to[b] != -1 && to[b] != a){
      cout << "No" << endl;
      return 0;
    }
    else{
      start[a] = b;
      to[b] = a;
    }
  }
  cout << "Yes" << endl;
  
  return 0;
}


Measured memory_bytes: 776
//g++  5.4.0

#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long a, b, c, k;
    cin>>a>>b>>c>>k;
    if(k <= a){
        cout<<k<<endl;
    }
    else{
        k -= a;
        if(k <= b){
            cout<<a<<endl;
        }
        else{
            k -= b;
            cout<<(a - k)<<endl;
        }
    }
}

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

int main() {
  int n, k;
  cin >> n >> k;
  if (!k) return cout << 1ll * n * n << endl, 0;
  ll res = 0;
  for (int x = k; x <= n; x++) {
    ll cnt = n / x;
    res += cnt * (x - k) + max(n % x - k + 1, 0);
    // cout << x << " " << res << endl;
  }
  cout << res << endl;
  return 0;
}

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

int main(){
  int N;
  int L;
  cin >> N;
  cin >> L;
  
  int plan = 0;
  for(int i=1;i<=N;i++){
    plan = plan + L + i - 1;
  }
  
  int d = abs(L + 1 - 1);
  int c = 1;
  int dd;
  
  for(int i=2;i<=N;i++){
    dd = abs(L + i - 1);
    if(dd < d){
      d = dd;
      c = i;
    }
  }
  
  cout << plan - (L + c - 1) << endl;
  return 0;
}
  
  
  
  
  
  

Measured memory_bytes: 256
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
import numpy as np

sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    N = I()
    L = LI()

    max_line = np.argmax(L)
    if L[max_line] < sum([i for idx, i in enumerate(L) if idx != max_line]):
        print("Yes")
    else:
        print('No')



main()


Measured memory_bytes: 15396
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int A = scan.nextInt();
		int B = scan.nextInt();
		int f = 0;

		for (int price = B*10; price < (B+1)*10; price++) {
			if ((int)((double)price*0.08 + 0.01) == A) {
				System.out.println(price);
				f++;
				break;
			}
		}

		if (f == 0) {
			System.out.println(-1);
		}

	}

}

Measured memory_bytes: 35664
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	ll n, k;
	ll a=0,aa=0,sum = 0LL,tmp=0LL;
	ll mod = 1e9+7LL;
	cin >> n >> k;
	vector<ll>arr(n);
	rep(i, n) cin >> arr[i];
	rep(i, n-1)for (int j = i + 1; j < n;j++) if (arr[j] < arr[i])a++;
	rep(i, n)for (int j = 0; j < n; j++)if (arr[j] < arr[i])aa++;
	sum = a * k;
	tmp = aa * (((k * (k - 1LL)) / 2LL)%mod);
	tmp %= mod;
	sum += tmp;
	sum %= mod;
	cout << sum << endl;
	return 0;
}



Measured memory_bytes: 3632
#include <iostream>

#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include <cstdlib>
#include <typeinfo>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << N); bit++)
using namespace std;

template<class T>
void print(const T &value) {
    std::cout << value << std::endl;
}

void yesno(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }

void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

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

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

//ll INF = 10000000;
//ll mod = 1000000007;//10^9+7

//using Graph = vector<vector<pair<int, int>>>;
//Graph G(100100);


//番号ズレ注意！！
int main() {
    int c[3][3];
    int d[3][2];
    bool ans = true;
    REP(i, 3) {
        cin >> c[i][0] >> c[i][1] >> c[i][2];
        d[i][0] = c[i][1] - c[i][0];
        d[i][1] = c[i][2] - c[i][1];
    }
    REP(i, 3) {
        REP(j, 3) {
            if (d[i][0] != d[j][0]) {
                ans = false;
                break;
            }
            if (d[i][1] != d[j][1]) {
                ans = false;
                break;
            }
        }
    }

    REP(i, 3) {
        REP(j, 3) {
            if ((c[1][i] - c[0][i]) != (c[1][j] - c[0][j])) {
                ans = false;
                break;
            }
            if ((c[2][i] - c[1][i]) != (c[2][j] - c[1][j])) {
                ans = false;
                break;
            }
        }
    }
    yesno(ans);
}


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

#define CIN1(a) long long a;cin >> a;
#define CIN2(a,b) long long a,b;cin >> a >> b;
#define CIN3(a,b,c) long long a,b,c;cin >> a >> b >> c;
#define rep(i,n) for(int i=0,i##_len=(n); i<i##_len; ++i)

int main(){
    CIN2(n,m)
    int left,right;
    rep(i,m){
        CIN2(l,r)
        if(!i){
            left=l;right=r;
        }else{
            if(left<l) left = l;
            if(r<right) right = r;
        }   
    }
    int ans = (left<=right)?right-left+1:0;
    cout << ans << endl;
}

Measured memory_bytes: 256