akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll LNF = 1e18+7;

constexpr int INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    vector<int> a(3);
    rep(i,0,3) cin >> a[i];
    sort(all(a));
    if(a[0]+a[1]==a[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
n = int(input())
ac = wa = tle = re = 0
for _ in range(n):
    x = input()
    if x == 'AC':
        ac += 1
    elif x == 'WA':
        wa += 1
    elif x == 'TLE':
        tle += 1
    elif x == 'RE':
        re += 1

for t, c in [('AC', ac), ('WA', wa), ('TLE', tle), ('RE', re)]:
    print('{0} x {1}'.format(t, c))

Measured memory_bytes: 9208
import sys
from pprint import pprint

n = int(sys.stdin.readline().strip())

red = []
for _ in range(n):
    a, b = map(int, sys.stdin.readline().strip().split())
    red.append((a, b))
red = sorted(red, reverse=True)
# pprint(red)

blue = []
for _ in range(n):
    c, d = map(int, sys.stdin.readline().strip().split())
    blue.append((c, d))
blue = sorted(blue)
# pprint(blue)

ans = 0
used = set()
for x, y in blue:
    # print("x,y:",x,y)
    # print("used")
    # pprint(used)
    tmp_red = red[:]
    cand = []
    max_j = -1
    while tmp_red:
        i, j = tmp_red.pop()
        # print("i,j:",i,j)
        if (i, j) in used:
            continue
        if i < x and j < y:
            if j > max_j:
                max_j = j
                cand = (i, j)
        if i > x:
            break
    if cand:
        ans += 1
        used.add(cand)
        # print("cand:", cand[0], cand[1])

print(ans)

Measured memory_bytes: 39152
#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define F first
#define S second
#define int long long
#define mod 1000000007
#define mmod 998244353
#define all(v) v.begin(), v.end()
using namespace std;
int mypow(int a, int b, int c) {
	if (b == 0)return 1;
	if (b % 2)return mypow(a, b - 1, c)*a%c;
	int z = mypow(a, b / 2, c);
	return z * z%c;
}
signed main() {
	int a, b;
	cin >> a >> b;
	if (a == 1 || b == 1)cout << 1 << endl;
	else {
		cout << (a*b + 1) / 2 << endl;
	}
}


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

typedef long long LL;
typedef long double LD;
typedef string ST;


#define REP(i,n) for(LL (i)=0;(i)<(n);(i)++)
#define ALL(v) v.begin(), v.end()

void func() {
  LL N, M;
  cin >> N >> M;
  vector<LL> X(M);
  REP(i, M) cin >> X[i];
  sort(ALL(X));
  /*
  for (auto a : X) {
    cerr << a << " ";
  }
  cerr << endl;
  */

  vector<LL> D(M-1);
  REP(i, M - 1) D[i] = abs(X[i] - X[i + 1]);
  sort(ALL(D));
  /*
  for (auto a : D) {
    cerr << a << " ";
  }
  cerr << endl;
  */
  LL cost = 0;
  REP(i, M - N) cost += D[i];
  cout << cost;

}





#ifdef CALC_TIME 
#include <windows.h>
int main()
{
  LARGE_INTEGER freq;
  QueryPerformanceFrequency(&freq);
  LARGE_INTEGER start, end;
  QueryPerformanceCounter(&start);
  // 何かの処理
  func();
  QueryPerformanceCounter(&end);
  double time = static_cast<double>(end.QuadPart - start.QuadPart) * 1000.0 / freq.QuadPart;
  fprintf(stderr, "\n%lf[ms]\n", time);
  return 0;
}
#else 
int main()
{
  func();
  return 0;
}
#endif





Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define For(i,a,b) for(int i=a;i<b;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
#define debug(x) cerr << x << endl
#define Complex complex<double>
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
ll mod = (int)1e9 + 7;

ll powmod(ll N, ll P){
    N%=mod;
    if(P==0) return 1;
    if(P%2==0){
        ll t = powmod(N, P/2);
        return t*t % mod;
    }
    return N*powmod(N, P-1)%mod;
}

int main() {
    int n,p;
    cin >> n >> p;
    mod=p;
    string s;
    cin >> s;
    map<int,int> ma;
    ma[0]++;
    int num=0;
    ll sum=0;
    rep(i,n){
        if(p==2 || p==5){
            if(!((s[i]-'0')%p)){
                sum+=i+1;
            }
            continue;
        }
        ll x=powmod(10,i);
        num=num+x*(s[n-i-1]-'0');
        num%=p;
        sum+=ma[num];
        ma[num]++;
    }
    cout << sum;
    


}

/*



 */



Measured memory_bytes: 900
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] arr = new int[N];
        for(int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
        }
 
        int res = 0;
        while(N > 0) {
            N = N - K;
            res++;
            if(N==0) {
                break;
            }
            N++;
        }
        System.out.println(res);
    }
}

Measured memory_bytes: 50776
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<cstdio>
#define curr(P, i) P[(i) % P.size()]
#define next(P, i) P[(i+1) % P.size()]
 
using namespace std;
 
struct point{ double x, y; };

//http://www004.upp.so-net.ne.jp/s_honma/urawaza/area2.htm
double areaPol(vector<point> t){
  double area=0;
  for(int i=0;i<t.size();i++)
    area+=(curr(t,i).x-next(t,i).x)*(curr(t,i).y+next(t,i).y);
   
  return abs(area)/2.0;
}
 
int main(void){
  int n,turn=1;
  point p;
  vector<point>t;
 
  while(cin >> n,n){
    t.clear();
    for(int i=0;i<n;i++){
      cin >> p.x >> p.y;
      t.push_back(p);
    }
    printf("%d %.1f\n",turn++,areaPol(t));
  }
 
  return 0;
}

Measured memory_bytes: 1264
class UnionFind(object):
    """Union find tree."""
    def __init__(self, nodes):
        self.par = [-1] * nodes

    def root(self, key):
        if self.par[key] < 0:
            return key
        self.par[key] = self.root(self.par[key])
        return self.par[key]

    def size(self, key):
        return -self.par[self.root(key)]

    def merge(self, a, b):
        a = self.root(a)
        b = self.root(b)
        if a == b:
            return
        if self.size(a) < self.size(b):
            a, b = b, a
        self.par[a] += self.par[b]
        self.par[b] = a

N, M = map(int, input().split())
AB = []
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    AB.append([a, b])

uni = UnionFind(N)
ans = [0] * M
ans[-1] = N * (N - 1) // 2
for i, (a, b) in enumerate(AB[-1:0:-1], 1):
    ans[-i - 1] = ans[-i]
    if uni.root(a) != uni.root(b):
        ans[-i - 1] -= uni.size(a) * uni.size(b)
        uni.merge(a, b)

print(*ans, sep='\n')

Measured memory_bytes: 27152
# Problem https://atcoder.jp/contests/abc053/tasks/abc053_b
# Python 3rd Try
import copy


def solver(givenstring):
    result = 0
    usestrA = copy.copy(givenstring)
    usestrZ = copy.copy(givenstring)
# a position
    apos = usestrA.index('A')+1
    usestrrevZ = usestrZ[::-1]
    zpos = len(givenstring) - usestrrevZ.index('Z')
    result = zpos - apos + 1
    return result


if __name__ == "__main__":
    s = input()
    print("{}".format(solver(s)))


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

int main()
{
	char ch[10];
	while(cin>>ch){
		if(ch[0]=='a'||ch[0]=='e'||ch[0]=='i'||ch[0]=='o'||ch[0]=='u')
		cout<<"vowel"<<endl;
		else
		cout<<"consonant"<<endl;
	}
	return 0;
}

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

#define pb push_back
#define mp make_pair
#define inside sl<=l&&r<=sr
#define outside r<sl||sr<l
#define INF 1000000009
using namespace std;
typedef long long ll;

int dp[100005][3];

int main(){
	//freopen("stl.gir", "r", stdin);
	
	int n;
	cin >> n;
	vector<int> a(n), b(n), c(n);
	for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];
	
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];
	
	for (int i = 1; i < n; i++){
		dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i];
		dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b[i];
		dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c[i];
	}
	
	cout << max(max(dp[n-1][0], dp[n-1][1]), dp[n-1][2]) << endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>

using namespace std;

long long kaijo[200000];

int main(){
	long long mod = 1000000007;
	int n,m;
	cin >> n >> m;
	if(abs(n-m)>=2){
		cout << 0 << endl;
		return 0;
	}
	kaijo[0]=1;
	for(long long i=1;i<200000;i++){
		kaijo[i] = kaijo[i-1]*i%mod;
	}
	long long ans;
	if(n!=m){
		cout << kaijo[n]*kaijo[m]%mod << endl;
	}else{
		ans = kaijo[n]*kaijo[m]%mod;
		ans = ans*2%mod;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0; i<(n); ++i)
#define rep1(i,n) for(ll i=1; i<=(n); ++i)
#define repi(i,a,b) for(ll i=a; i<=(b); ++i)
#define rrep(i,n) for(ll i=(n-1); i>=0; --i)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define print(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
using Edge = pair<ll,ll>;
using Graph = vector<vector<Edge>>;
typedef pair<ll,ll> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
ll MOD = 1e9 + 7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll devc(ll x, ll y){return 1 + (x-1)/y;}
ll modpow(ll x, ll y, ll m) {
    if (y == 0) return 1;
    ll res = modpow(x, y / 2, m);
    return res * res % m * (y & 1 ? x : 1) % m;
}
ll modinv(ll x) { return modpow(x, MOD - 2, MOD); }

int main(){
    ll N; cin >> N;
    bool flag = true;
    rep(i,N){
        ll a; cin >> a;
        if(a % 2 == 0 && a % 3 != 0 && a % 5 != 0) flag = false;
    }
    if(flag) print("APPROVED");
    else print("DENIED");
    return 0;
}

Measured memory_bytes: 256
x , n = map(int,input().split())
p_str = []
if n != 0 :
    p_str = input().split()#pはlist
    
list = []

for i in p_str :
    p = int(i)
    list.append(p)

if not x  in list :
    print(x)
else :
    for i  in range(101):
        y = x - i
        if not y in list :
            print(y)
            break
        z = x + i
        if not z in list :
            print(z)
            break

Measured memory_bytes: 9144
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#include<vector>
#define INF INT_MAX
using namespace std;

int N;
int L[110];
int ans;

int main(){
	cin >> N;
	for (int i = 0; i < N; i++){
		cin >> L[i];
	}
	sort(L, L + N);

	for (int i = 0; i < N; i++){
		for (int j = 0; j < i; j++){
			for (int k = 0; k < j; k++){
				if (L[k] != L[j] && L[i] != L[j] && L[k] + L[j]>L[i]){
					ans++;
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3640
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#include <random>
using namespace std;

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;

const int MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
const int INF = INT_MAX / 2;

int main() {
	int N; cin >> N;
	vector<int> a(N);
	rep(i, N) cin >> a[i];
	sort(a.begin(), a.end());
	cout << a.back() - a.front() << endl;
}


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

int main()
{
    string s;
    cin >> s;
    int a = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == 'o')
        {
            a += 100;
        }
    }
    cout << 700 + a << endl;
}

Measured memory_bytes: 256
// C++ 14
#include <bits/stdc++.h>
using namespace std;
template <typename T>  ostream& operator<<(ostream& os, const vector<T>& v)  {  os << "[";  for (int i = 0; i < v.size(); ++i) {  os << v[i];  if (i != v.size() - 1)  os << ", ";  }  os << "]";  return os;  }
template <typename T> void print(T v, string s = "\n") { cout << v << s; }
template <typename T> void in(T &v) { cin >> v; }
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

// i枚目まで考慮してk枚選んだ時に合計がsumである場合の数.
ll dp[60][60][3000];
int main() {
  int n, ave; in(n),in(ave);
  vector<int> A(n);
  loop(i,0,n) in(A[i]);
  dp[0][0][0] = 1;
  loop(i,0,n) {
    int a = A[i];
    loop(k,0,n) {
      loop(sum,0,3000) {
        if (dp[i][k][sum]==0) continue;
        dp[i+1][k][sum] += dp[i][k][sum];
        dp[i+1][k+1][sum+a] += dp[i][k][sum];
      }
    }
  }
  
  ll ans = 0;
  loop(k,1,n+1) {
    ans += dp[n][k][k*ave];
  }
  print(ans);
  return 0;
}


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

#define ll long long int
#define fi first
#define se second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define debug(a) cout << #a << " = " << a << " ";
#define endl "\n"
#define MOD (int) 1e9+7
#define inf (int) (1e18)

void solve(){
    string s;
    cin>>s;
    long int ans=0;
    for(int i=0;i<3;i++){
        if(s[i]=='R'){
            int j=i;
            long xx=0;
            while(j<3 && s[j]=='R'){
                j++; xx++;
            }
            ans=max(ans,xx);
            i=j;
        }
    }
    cout<<ans<<endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long int t=1;
    // cin >> t;
    for(long int tt=1;tt<=t;tt++){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>

using namespace std;

int main() {
    unsigned long long a, b, c, k;
    long long sum = 0;

    cin >> a >> b >> c >> k;

    if (k < a) {
        sum = k;
    } else {
        sum = a;
        k -= a;
        if (k > b) {
            k -= b;
            sum -= k;
        }
    }

    cout << sum;

    return 0;
}

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

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;

int main() {
  ll A, B, Q;
  cin >> A >> B >> Q;

  ll INF = 1e11;

  vector<ll> s(A + 2);
  vector<ll> t(B + 2);

  for (int i = 1; i <= A; i++) { cin >> s[i]; }
  for (int i = 1; i <= B; i++) { cin >> t[i]; }

  s[0] = -INF, t[0] = -INF;
  s[A+1] = INF, t[B+1] = INF;

  for (int i = 0; i < Q; i++) {
    ll x; cin >> x;
    int ra, la, rb, lb;

    ra = lower_bound(s.begin(), s.end(), x) - s.begin();
    la = ra - 1;

    rb = lower_bound(t.begin(), t.end(), x) - t.begin();
    lb = rb - 1;

    ll al = abs(x - s[la]), ar = abs(x - s[ra]);
    ll bl = abs(x - t[lb]), br = abs(x - t[rb]);

    ll ans = min(max(al, bl), max(ar, br));
    ans = min(ans, min(al, ar) * 2 + min(bl, br));
    ans = min(ans, min(al, ar) + min(bl, br) * 2);
    cout << ans << BR;
  }
  return 0;
}

Measured memory_bytes: 2944
s = int(input())
tmp = [False] * 1000001
i = 1
a = s
tmp[a] = True
while True:
    if a % 2 == 0:
        a //= 2
        i += 1
        if tmp[a]:
            print(i)
            exit()
        tmp[a] = True
    else:
        a = 3*a + 1
        i += 1
        if tmp[a]:
            print(i)
            exit()
        tmp[a] = True


Measured memory_bytes: 46192
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,n) for(int i=1;i<=n;i++)
#define ford(i,n) for(int i=n;i>=0;i--) 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define foreach(c,itr) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define re return
#define INF 1e9
#define LINF 1e18
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi > vpi; 
int main(){
	int m1,d1,m2,d2;
	cin>>m1>>d1>>m2>>d2;
	if(m1!=m2){
		cout<<1;
	}	
	else{
		cout<<0;
	}
	re 0;
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int W, H;
char B[30][30];

int dfs(int y, int x) {
   int ret = 1;
   B[y][x] = '#';
   rep (i, 4) {
      int nx = x + dx[i] , ny = y + dy[i];
      if (nx < 0 || nx >= W || ny < 0 || ny >= H || B[ny][nx] == '#') continue;
      ret += dfs(ny, nx);
   }
   return ret;
}

void solve() {
   rep (i, H) {
      cin >> B[i];
   }
   rep (i, H) {
      rep (j, W) {
         if (B[i][j] == '@') {
            cout << dfs(i, j) << endl;
            return;
         }
      }
   }
}

int main() {
   while (1) {
      cin >> W >> H;
      if (H*W == 0) break;
      solve();
   }

   return 0;
}


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

int main(void){
  int x,y;
  cin>>x>>y;
  
  bool flug=false;
  int a,b,tmp;
  
  for(int i=0;i<x+1;i++){
    a=i;
    b=x-a;
    tmp=4*x-2*a;
    if(tmp==y) flug=true;
  }
  if(flug) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}
    

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    string S, T;
    cin >> S >> T;
    for(int i = 0;i < N;i++) {
        cout << S.at(i) << T.at(i); 
    }
    cout << endl;
}

Measured memory_bytes: 256
use proconio::{input, marker::Usize1};

#[allow(dead_code)]
#[derive(Clone, Copy, Debug)]
enum ParentOrSize {
    Parent(usize),
    Size(usize),
}

#[allow(dead_code)]
#[derive(Clone, Debug)]
struct UnionFind(Vec<ParentOrSize>);

#[allow(dead_code)]
impl UnionFind {
    pub fn new(len: usize) -> Self {
        Self(vec![ParentOrSize::Size(1); len])
    }

    pub fn is_empty(&self) -> bool {
        self.0.is_empty()
    }

    pub fn len(&self) -> usize {
        self.0.len()
    }

    pub fn find(&mut self, i: usize) -> usize {
        self.find_and_size(i).0
    }

    fn find_and_size(&mut self, i: usize) -> (usize, usize) {
        assert!(i < self.len());
        match self.0[i] {
            ParentOrSize::Parent(p) => {
                let ret = self.find_and_size(p);
                self.0[i] = ParentOrSize::Parent(ret.0);
                ret
            }
            ParentOrSize::Size(si) => (i, si),
        }
    }

    pub fn unite(&mut self, u: usize, v: usize) {
        let (mut u, su) = self.find_and_size(u);
        let (mut v, sv) = self.find_and_size(v);
        if u == v {
            return;
        }
        if su > sv {
            std::mem::swap(&mut u, &mut v);
            std::mem::swap(&mut v, &mut u);
        }
        self.0[v] = ParentOrSize::Size(su + sv);
        self.0[u] = ParentOrSize::Parent(v);
    }

    pub fn same(&mut self, u: usize, v: usize) -> bool {
        self.find(u) == self.find(v)
    }
}

fn main() {
    input!(
        n: usize,
        m: usize,
        ab: [(i64, i64); n],
        uv: [(Usize1, Usize1); m]
    );
    let mut g = vec![vec![]; n];
    for (u, v) in uv {
        g[u].push(v);
        g[v].push(u);
    }
    let b: Vec<_> = ab.iter().map(|(_, b)| b).collect();
    let c: Vec<_> = ab.iter().map(|(a, b)| a - b).collect();

    let mut ord: Vec<_> = (0..n).collect();
    ord.sort_by_key(|&i| c[i]);

    let mut ckd = vec![false; n];
    let mut dp = vec![0; n];
    let mut sum_b_of_cmp = vec![0; n];
    let mut uf = UnionFind::new(n);
    for x in ord {
        let mut adj: Vec<_> = g[x]
            .iter()
            .copied()
            .map(|y| uf.find(y))
            .filter(|&y| ckd[y])
            .collect();
        adj.sort();
        adj.dedup();
        let sum_b_of_cmp_x = b[x] + adj.iter().map(|&y| sum_b_of_cmp[y]).sum::<i64>();
        let mut ans = c[x].max(0) + sum_b_of_cmp_x;
        for &y in &adj {
            let now = dp[y].max(c[x]) + sum_b_of_cmp_x - sum_b_of_cmp[y];
            if now < ans {
                ans = now;
            }
        }
        for y in adj {
            uf.unite(x, y);
        }
        let x = uf.find(x);
        sum_b_of_cmp[x] = sum_b_of_cmp_x;
        ckd[x] = true;
        dp[x] = ans;
    }
    println!("{}", dp[uf.find(0)]);
}


Measured memory_bytes: 18272
main = do
	cs <- getLine
	let ns = toIntList cs
	putStrLn $ showAnswer ns

toIntList :: String -> [Integer]
toIntList = map read . words

area :: [Integer] -> Integer
area = foldl1 (*)

circumference :: [Integer] -> Integer
circumference = (* 2) . foldl1 (+)

showAnswer :: [Integer] -> String
showAnswer ns = unwords $ map (show . ($ ns)) [area, circumference]


Measured memory_bytes: 3588
#define _GLIBCXX_DEBUG
#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;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
static const int INF = 2000000000;

int main(){
  int h, w;
  cin >> h >> w;
  vector<vector<char>> d(h+2, vector<char>(w+2));
  rep(i, h+2) rep(j, w+2) d[i][j] = '.';
  rep(i, h) rep(j, w) cin >> d[i+1][j+1];
  

  for (int i = 1; i <= h; i++){
    for (int j = 1; j <= w; j++){
      if (d[i][j] == '#'){
        if (d[i-1][j] == '.' && d[i+1][j] == '.' && d[i][j-1] == '.' && d[i][j+1] == '.'){
          cout << "No\n";
          return 0;
        }
      }
    }
  }
  cout << "Yes\n";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i, j;
    char c;
    cin >> c;
    if (c - 'a' >= 0 && 'z' - c >= 0) {
        cout << 'a' << endl;
    } else
        cout << 'A' << endl;
}

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

using namespace std;
#define ll long long
#define pb push_back

int main()
{
	string str;
	cin >> str;
	int n = str.size();
	if(str[n-1]=='s') str += "es";
	else str += "s";
	cout << str << endl;
	return 0;
}


Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back

#define B (ll)(101)
#define M (ll)(1LL<<30)

ll h(string s){
    ll ret = 0;
    rep(i,s.size()){
        ret *= B;
        ret += s[i]-'a'+1;
        ret %= M;
    }
    
    return ret;
}

int main(){
    string s;
    cin>>s;
    
    int n;
    cin>>n;
    vector<string> vs(n);
    rep(i,n)cin>>vs[i];
    
    map<ll,vector<ll>> hashes;
    rep(i,vs.size()){
        int l = vs[i].size();
        hashes[l].pb(h(vs[i]));
    }
    
    
    vector<ll> rhash(s.size()+1,0);
    rhash[1] = s[0]-'a'+1;
    for(int i=1;i<=s.size();i++){
        rhash[i] = (rhash[i-1]*B + (s[i-1]-'a'+1))%M;
    }
    
    vector<int> p(s.size(),0);
    p[0] = 1;
    for(int i=1;i<s.size();i++)p[i] = (p[i-1]*B)%M;
    
    vector<int> lside(s.size(),-1);
    for(auto emp:hashes){
        int l = emp.first;
        sort(all(emp.second));
        
        for(int i=0;i+l-1<s.size();i++){
            ll hash = (rhash[i+l] - rhash[i]*p[l]%M + M)%M;
            if(*lower_bound(all(emp.second),hash)==hash)lside[i+l-1] = max(lside[i+l-1],i);
        }
    }
    
    int used = -1;
    int ans = 0;
    rep(i,lside.size()){
        if(lside[i]==-1)continue;
        if(lside[i]>used){
            used = i;
            ans++;
        }
    }
    cout<<ans<<endl;
}



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

int main()
{
    ll n;cin>>n;
    ll rslt=0,k;
    k=n/500;
    rslt+=(k*1000);
    ll p=n%500;
    ll s=p/5;
    rslt+=(s*5);
    cout<<rslt<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define DEBUG_MODE
#define endl '\n'
#ifdef DEBUG_MODE
#define DEBUG(X) debug_func(X, #X)
#define DEBUG_ENDL endl << flush
#define DEBUG_SEPARATOR_LINE cout<<"=================\n"
#else
#define DEBUG(X) 0
#define DEBUG_ENDL 0
#define DEBUG_SEPARATOR_LINE 0
#endif
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
#define DEBUG_ENDL_S(S) ((S).size() ? "\n" : "") << flush;
template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename Head, typename... Tail> const Head& var_min(const Head &head, const Tail&... tail) { return min(head, var_min(tail...)); }
template <typename Head, typename... Tail> const Head& var_max(const Head &head, const Tail&... tail) { return max(head, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
void debug_func_preffix(const string &s) { if(s.size()) cout << s << " = "; }
template <typename T>
void debug_func(const T &t, const string &s = "") {
    debug_func_preffix(s);
    cout << t << DEBUG_ENDL_S(s);
}
template <typename T, typename U>
void debug_func(const P<T, U> &p, const string &s = "") {
    debug_func_preffix(s);
    cout << "(";
    debug_func(p.first);
    cout << ", ";
    debug_func(p.second);
    cout << ")" << DEBUG_ENDL_S(s);
}
template <typename T>
void debug_func(const V<T> &v, const string &s = "") {
    for(ll i = 0; i < v.size(); i++) {
        string t = s + "[" + to_string(i) + "]";
        debug_func(v[i], t);
    }
}

void init_io() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(30);
}

VV<ll> edges;

ll dfs(ll now, ll pre, ll start, ll goal) {
    if(pre >= 0 && now == start) return 0;
    if(now == goal) return 1;
    ll cnt = 0;
    for(ll nxt : edges[now]) {
        if(nxt == pre) continue;
        cnt += dfs(nxt, now, start, goal);
    }
    return cnt;
}

bool solve() {
    ll N, M;
    cin >> N >> M;
    V<ll> cntv(N);
    edges.resize(N);
    for(ll i = 0; i < M; i++) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
        cntv[a]++;
        cntv[b]++;
    }
    ll cnt_over_6 = 0;
    V<ll> fours;
    for(ll i = 0; i < N; i++) {
        ll e = cntv[i];
        DEBUG(e);
        if(e == 4) fours.push_back(i);
        if(e >= 6) cnt_over_6++;
        if(e & 1) return false;
    }
    if(cnt_over_6 > 0) return true;
    if(fours.size() == 2) {
        ll f = fours[0], t = fours[1];
        ll cnt = dfs(f, -1, f, t);
        if(cnt != 4) return true;
    }
    if(fours.size() > 2) return true;
    return false;
}

int main() {
    cout << (solve() ? "Yes" : "No") << endl;
    return 0;
}


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

int main() {
    long long A, B;
    cin >> A >> B;

    long long size = B - A + 1;
    if (A <= 0 && 0 <= B) {
        cout << "Zero" << endl;
    }
    else {
        if (A > 0) {
            cout << "Positive" << endl;
        }
        else {
            if (size % 2 == 0) {
                cout << "Positive" << endl;
            }
            else {
                cout << "Negative" << endl;
            }
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define FOR(i, N) for (long i = 0; i < (N); i++)

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int D, T, S;
    cin >> D >> T >> S;

    if (D <= T * S) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3664
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
#define endl '\n'
#define ld long double
#define all(a) a.begin(),a.end()
#define int long long
#define pb push_back
#define pii pair <int, int>
#define ff first
#define ss second
#define sz(v) (int)v.size()
#define UB upper_bound
#define LB lower_bound
#define BP(x) __builtin_popcountll(x)
#define PQS priority_queue <int, vector<int>, greater<int> >
#define OST tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int getRand(int l, int r) {
  uniform_int_distribution<int> uid(l, r);
  return uid(rng);
}

const int INF = 1e18 + 0;
const int mod = 1e9 + 7;
//const int mod = 998244353;

int mul(int a, int b) {
  a += mod; b += mod;
  a %= mod; b %= mod; return ((a * b) % mod);
}

void solve() {
  int n, k, ans = 1, K; cin >> n >> k;
  K = k;
  vector <int> p, neg, z;
  vector <pii> v;
  for(int i = 0; i < n; i++) {
    int x, s; cin >> x;
    if(x > 0) {
      p.pb(x);
      s = 1;
    }
    if(x < 0) {
      neg.pb(abs(x));
      s = -1;
    }
    if(x == 0) {
      z.pb(x);
      s = 1;
    }
    v.pb({abs(x), s});
  }
  sort(all(p)); sort(all(neg)); sort(all(z)); sort(all(v));
  int i = sz(p)-1, j = sz(neg)-1;

  if(k%2) {
    if(!p.empty()) {
      k--; ans = mul(ans, p[i]);
      i--;
    }
  }

  while(k && (i > 0 || j > 0)) {
     int a = -INF, b = -INF;
     if(i >= 1) {
       a = p[i] * p[i-1];
     }
     if(j >= 1) {
       b = neg[j] * neg[j-1];
     }
     if(a > b) {
       ans = mul(ans, a);
       k-=2; i-=2;
     }
     else {
       ans = mul(ans, b);
       k-=2; j-=2;
     }
  }
  if(k) {
    if(!z.empty()) {
      ans = 0;
    } else {
      ans = 1;
      for(int l = 0; l < K; l++) {
         ans = mul(ans, v[l].ss * v[l].ff);
      }
    }
  }
  cout << ans << '\n';
}

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

  #ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
  #endif
   int t = 1;  //cin >> t;
   for(int i = 1; i <= t; i++) {
     solve();
  }
}



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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());

            for (int i = N; i < 1000000; i++)
            {
                if (Sosu(i))
                {
                    Console.WriteLine(i);
                    break;
                }
            }

        }


        public static bool Sosu(int num)
        {
            if (num < 2) return false;
            else if (num == 2) return true;
            else if (num % 2 == 0) return false;

            double sqrtNum = Math.Sqrt(num);
            for (int i = 3; i <= sqrtNum; i += 2)
            {
                if (num % i == 0)
                {
                    return false;
                }
            }

            // 素数である
            return true;
        }
    }

}


Measured memory_bytes: 13140
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ull unsigned long long
#define repi(i,a) for(auto i = a.begin(); i!= a.end() ;++i) 
#define repdi(i,a) for(auto i = a.begin(); i!=a.end();++i) 
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0); 
#define nl "\n"
#define INF 1e18
#define sz(a) (ll)a.size() 
#define all(a) a.begin(),a.end()
#define M 998244353
#define limit 100000000

typedef vector<ll> vll;
typedef pair<ll,ll> pii;
typedef vector<pii> vpi;
typedef vector<vector<ll> > vv;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

const int block = 700 ;

bool cmp(tuple<int,int,int>& x,tuple<int,int,int>& y) {
	if (get<0>(x)/block != get<0>(y)/block) 
        return get<0>(x)/block < get<0>(y)/block; 
  
    return get<1>(x) < get<1>(y);
}

void solve() {
	
	double r; cin >> r;

	cout << fixed << setprecision(12) << (double) 2.0 * (22.0/7.0) * r ;
}


int main() {

    fast;
	int t=1;
	// cin>>t;
	rep(i,0,t) {
		solve() ;
	}
	return 0;
}

Measured memory_bytes: 3804
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        in.nextLine();
        String s = in.nextLine();
        int[] l = new int[26], r = new int[26];
        for(char ch : s.toCharArray()) {
            r[ch - 'a']++;
        }
        int ans = 0;
        for(char ch : s.toCharArray()) {
            r[ch - 'a']--; l[ch - 'a']++;
            ans = Math.max(ans, findSameChars(l, r));
        }
        System.out.println(ans);
    }

    public static int findSameChars(int[] a, int[] b) {
        int ans = 0;
        for(int i = 0; i < 26; i++) {
            if(a[i] > 0 && b[i] > 0) ans++;
        }
        return ans;
    }
}

Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
int main()
{

    long long int n,m;
  while(cin>>n>>m){
    long long int ans = 1;
    if(n==1 || m==1) {cout<<m<<endl; continue;}
    long long int maxx = sqrt(m);
    maxx+=2;
    for (long long int i=2;i<=maxx;i++){
        long long int c=0;
        while(m%i==0){
            m=m/i;
            c++;
            if(c==n)
            {ans = ans*i;c=0;}
        }


    }
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;

int main()
{
	char s[100000];
	int K;

	scanf("%s", s);

	int N=strlen(s);

	if(N%2==0){
		int i=N/2-1, i0=N/2-1;
		while(i>=0){
			if(s[i]==s[i0] && s[N-1-i]==s[i0]){
				i--;
			}else{
				break;
			}
		}
		K=N-i-1;
	}else{
		int i=N/2, i0=N/2;
		while(i>=0){
			if(s[i]==s[i0] && s[N-1-i]==s[i0]){
				i--;
			}else{
				break;
			}
		}
		K=N-i-1;
	}
	printf("%d\n", K);

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  using namespace std;
 
int main(){
  int n,k;
  cin>>n>>k;
  
  string s;
  cin>>s;
  if(s.at(k-1)=='A'){
    s.at(k-1)='a';
  }else if(s.at(k-1)=='B'){
    s.at(k-1)='b';
  }else{
    s.at(k-1)='c';
  }
  cout<<s<<endl;
}

Measured memory_bytes: 256
N = int(input())
b = list(map(int, input().split()))
flag = 1
for i in range(N):
    if b[i] > i+1:
        print(-1)
        flag = 0
        break
ans = []
if flag == 1:
    for i in range(N):
        for j in range(len(b), 0, -1):
            if b[j-1] == j:
                ans.append(b.pop(j-1))
                break
    for i in range(N):
        print(ans[-1-i])


Measured memory_bytes: 3060
#include <cstdio>

int const kMaxN = 100000;

int g_count[kMaxN];

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a, --b;
    ++g_count[a];
    ++g_count[b];
  }

  bool allEven = true;
  for (int i = 0; i < n && allEven; ++i)
    allEven = allEven && g_count[i] % 2 == 0;

  printf("%s\n", allEven ? "YES" : "NO");
  return 0;
}


Measured memory_bytes: 1272
// Why am I so dumb? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

const int MAXN = (int)2e3 + 5;
const int INF = (int)1e5;

vector<int> adj[MAXN];

int pref[MAXN][MAXN];

int dp[MAXN][MAXN];

int sub[MAXN];

int n, k;

int getDp(int v, int d, bool p) {	
	if (d == -1) {
		return sub[v];
	}
               
    return p ? pref[v][d] : dp[v][d];
}

void dfs(int v, int pr) {
	bool leaf = 1;
	sub[v] = 1;

	for (int to : adj[v]) {
		if (to == pr) {
			continue;
		}

		leaf = 0;
		dfs(to, v);
		sub[v] += sub[to];
	}

	if (leaf) {
		dp[v][0] = 0;

		for (int i = 0; i <= k; ++i) {
			pref[v][i] = 0;
		}

		return;
	}

	for (int mx = -1; mx <= k - 1; ++mx) {
		int mx2 = min(mx, k - 2 - mx);
		int sum = 0;

		for (int to : adj[v]) {
			if (to == pr) {
				continue;
			}

			sum += getDp(to, mx2, 1);
		}

		for (int to : adj[v]) {
			if (to == pr) {
				continue;
			}

			if (getDp(to, mx, 0) == INF) {
				continue;
			}

			dp[v][mx + 1] = min(dp[v][mx + 1], sum - getDp(to, mx2, 1) + getDp(to, mx, 0));
		}		
	}

	pref[v][0] = min(dp[v][0], sub[v]);

	for (int i = 1; i <= k; ++i) {
		pref[v][i] = min(pref[v][i - 1], dp[v][i]);
	}
}

void solve() {                   
	scanf("%d %d", &n, &k);

    for (int i = 1, u, v; i < n; ++i) {
		scanf("%d %d", &u, &v);
		adj[u].pb(v);
		adj[v].pb(u);    	
    }

    for (int i = 1; i <= n; ++i) {
    	for (int j = 0; j <= k; ++j) {
    		dp[i][j] = INF;
    		pref[i][j] = INF;
    	}
    }

    dfs(1, -1);
    int ans = n;    

    for (int v = 1; v <= n; ++v) {
    	ans = min(ans, pref[v][k] + n - sub[v]);
    }

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

int main() {    
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 31872
#include <stdio.h>

int main()
{
    char c[3][3] ;int i , j ;
     for(i = 0 ; i < 3 ; i++){
        for(j = 0 ; j< 3 ; j++){
            scanf(" %c",&c[i][j]);
        }
    }
    
    for(i = 0 ; i < 3 ; i++){
        for(j = i ; j<= i ; j++){
            printf("%c",c[i][j]);
          	break;
        }
    }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
using vec_int = vector<int>;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

signed main(){

    string alphabets = "abcdefghijklmnopqrstuvwxyz";

    int N;
    cin>>N;

    int index=1;
    int tot = 0;
    while(true){
        tot += pow(26,index);
        if(N<=tot){
            break;
        }
        index++;
    }

    string out_str = "";
    
        
    int aaaa = 26;
    int aaa = 0;
    for(int i=1;i<index+1;i++){
        int temp = (N-1-aaa) % aaaa;
        int temp2 = (temp)/(aaaa/26);
        out_str = alphabets.at(temp2)+out_str;
        aaa += aaaa;
        aaaa = aaaa*26;
    }

cout<<out_str<<endl;







    return 0;
}

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

int main(){
	int a,b,c,d;
	C4(a,b,c,d);
	if(a+b > c+d)
		P("Left");
	else if(a+b == c+d)
		P("Balanced");
	else
		P("Right");
	
	

	ret 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int i;
	int a[26]={0};
	string n;
	while(getline(cin,n)){
		for(i=0;i<n.size();i++){
			if('A'<=n[i]&&n[i]<='Z'){
				n[i]=n[i]+('a'-'A');
			}
		}
		for(i=0;i<n.size();i++){
			if('a'<=n[i]&&n[i]<='z'){
				a[n[i]-'a']++;
			}
		}
	}
	for(i=0;i<26;i++){
		printf("%c : %d\n",i+'a',a[i]);
	}
	return 0;
}


Measured memory_bytes: 3244
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1}; // 移動方向
const int MAX_S = 3010;
string s,t;
int dp[MAX_S][MAX_S] = {0};

void input(){
    cin >> s >> t;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    int n = s.size();
    int m = t.size();
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if (s[i] == t[j]) chmax(dp[i+1][j+1], dp[i][j]+1);
            chmax(dp[i+1][j+1], dp[i+1][j]);
            chmax(dp[i+1][j+1], dp[i][j+1]);
        }
    }

    string ans = "";
    while(n>0 && m>0){
        if(dp[n][m] == dp[n-1][m]) n--;
        else if(dp[n][m] == dp[n][m-1]) m--;
        else{
            ans = s[n-1] + ans;
            --n;
            --m;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 35584
import java.util.*;
public class Main {
  public static void main (String[] args){
	Scanner sc = new Scanner(System.in);
    boolean result = false;
    int trial_num = sc.nextInt();
    int[][] combi = new int[trial_num][2];
    for(int i = 0; i < trial_num; i++) {
		for(int j = 0; j < 2; j++){
        	combi[i][j] = sc.nextInt();
        }
    }
    for(int i = 0; i < trial_num - 2; i++) {
        if(combi[i][0] == combi[i][1] 
           && combi[i+1][0] == combi[i+1][1] && combi[i+2][0] == combi[i+2][1])
     		result = true;
    }
    if(result) System.out.println("Yes");
    else System.out.println("No");
  }
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

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

	ll n, k;cin >> n >> k;
	vector<ll> v(n);REP(i, n)cin >> v[i];

	ll ans = 0;
	REP(i, n){
		REP(j, n){
			if(v[j] > v[i]){
				if(i > j){
					ans = (ans + ((k) * (k + 1) / 2) % MOD) % MOD;
				}
				else {
					ans = (ans + ((k) * (k - 1) / 2) % MOD) % MOD;
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(void)
{
    int i,N,num,num_4=0,num_1=0,num_2=0;
    scanf("%d",&N);
    for(i=0;i<N;i++)
    {
        scanf("%d",&num);
        if(num%4==0)
            num_4+=1;
        else if(num%2==0)
            num_2+=1;
        else
            num_1+=1;
    }
        if(num_4+1>=num_1&&num_2==0)
            printf("Yes\n");
        else if(num_4>=num_1&&num_2!=0)
            printf("Yes\n");
        else    printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  map<string, int> count;
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    string S;
    cin >> S;
    count[S]++;
  }
  
  int mx = 0;
  for (auto x : count) {
    //string s = x.first;
    int cnt = x.second;
    mx = max(mx, cnt);
  }

  for (auto x : count) {
    string s = x.first;
    int cnt = x.second;
    if (cnt == mx) {
      cout << s << endl;
    }
  }
  
  return 0;
}


Measured memory_bytes: 18656