akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pi M_PI
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  string s;
  R s;
  int ans=0;
  for(int j=2; j<s.size()-1; j+=2) {
    if(s.substr(0,j/2)==s.substr(j/2,j/2)) ans=max(ans,j);
  }
  pr(ans);
}

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


Measured memory_bytes: 256
l=list(map(int,input().split()))
W=l[0]
H=l[1]
x=l[2]
y=l[3]
r=l[4]

if x+r<=W and x-r>=0 and y+r<=H and y-r>=0:
	print('Yes')
	
else:
	print('No')
	


Measured memory_bytes: 5596
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    string s; cin >> s;
    for(int i = 0; i < s.size(); i += 2)
    {
        string t = "";
        t += s[i];
        if(i + 1 > s.size())
        {
            cout << "No" << endl;
            return;
        }
        t += s[i + 1];
        if(t != "hi")
        {
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;
}

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

Measured memory_bytes: 256
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N = input()
T, A = map(int, raw_input().split())
H = map(int, raw_input().split())

ans = 0
cost = INF
for i in range(N):
    if abs(T - H[i] * 0.006 - A) < cost:
        cost = abs(T - H[i] * 0.006 - A)
        ans = i + 1

print ans

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

int N;
string A[100], B[100];

void BubbleSort(string A[], int N) {
	bool flag = true;
	while (flag) {
		flag = false;
		for (int i = 0; i < N - 1; i++) {
			if (A[i][1] > A[i + 1][1]) {
				flag = true;
				swap(A[i], A[i + 1]);
			}
		}
	}
}

void SelectionSort(string A[], int N) {
	for (int i = 0; i < N; i++) {
		int min_j = i;
		for (int j = i + 1; j < N; j++) {
			if (A[j][1] < A[min_j][1]) {
				min_j = j;
			}
		}
		if (i != min_j) {
			swap(A[i], A[min_j]);
		}
	}
}

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i], B[i] = A[i];
	BubbleSort(A, N);
	for (int i = 0; i < N; i++) {
		if (i) cout << " ";
		cout << A[i];
	}
	cout << endl;
	cout << "Stable" << endl;
	bool check = true;
	SelectionSort(B, N);
	for (int i = 0; i < N; i++) {
		if (i) cout << " ";
		cout << B[i];
		if (A[i] != B[i]) check = false;
	}
	cout << endl;
	if (check) cout << "Stable" << endl;
	else cout << "Not stable" << endl;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define int long long
using namespace std;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    char matrix[n][n], cp[n][n];
    for (int i=0; i < n; i++) for (int j=0; j < n; j++) cin >> matrix[i][j];
    int ans = 0;
    for (int i=0; i < n; i++){
        bool able = true;
        for (int j=0; j < n; j++) for (int k=0; k < n; k++) able &= (matrix[j][k] == matrix[k][j]);
        if (able) ans += n;
        for (int i=0; i < n; i++) for (int j=0; j < n; j++) cp[(i+1)%n][j] = matrix[i][j];
        for (int i=0; i < n; i++) for (int j=0; j < n; j++) matrix[i][j] = cp[i][j];
    }
    cout << ans;
}



Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <utility>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF=1<<29;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll N,Ans=0,tmp=0;
	cin>>N;
	ll A[N][N],B[N][N];
	bool check[N][N];
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			cin>>A[i][j];
			B[i][j]=A[i][j];
			Ans+=A[i][j];
			check[i][j]=false;
		}
	}
	for(int k=0;k<N;k++){
		for(int i=0;i<N;i++){
			for(int j=0;j<N;j++){
				if(k==i || i==j || j==k) continue;
				if(A[i][j]>A[i][k]+A[k][j]){
					A[i][j]=A[i][k]+A[k][j];
				}else if(A[i][j]==A[i][k]+A[k][j] && check[i][j]==false){
					check[i][j]=true;
					tmp+=B[i][j];
				}
			}
		}
	}
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			if(A[i][j]<B[i][j]){
				cout<<"-1\n";
				return 0;
			}
			if(B[i][j]>A[i][j]) Ans-=B[i][j];
		}
	}
	Ans-=tmp;
	cout<<Ans/2<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>
#include <iomanip>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int h, w;
	cin >> h >> w;
	
	vector< vector<int> > c(10, vector<int>(10, 0));
	for(int i = 0; i < 10; ++i) {
		for(int j = 0; j < 10; ++j) {
			cin >> c[i][j];
		}
	}
	
	for(int k = 0; k < 10; ++k) {
		for(int i = 0; i < 10; ++i) {
			for(int j = 0; j < 10; ++j) {
				c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
			}
		}
	}
	
	int a; 
	ll ans = 0;
	for(int i = 0; i < h; ++i) {
		for(int j = 0; j < w; ++j) {
			cin >> a;
			
			if( a == -1 ) continue;
			
			ans += c[a][1];
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
#define arrlen(arr) (sizeof(arr)/sizeof(arr[0]))
#define Sort(arr) sort(arr, arr+arrlen(arr))
#define For(i,n) for(int i=0;i<n;i++)
#define Foreach(i,arr) For(i,arrlen(arr))
#define Arrin(arr) Foreach(i,arr){cin>>arr[i];}
#define Arrin2(arr1,arr2) Foreach(i,arr1){cin>>arr1[i]>>arr2[i];}
#define Arrin3(arr1,arr2,arr3) Foreach(i,arr1){cin>>arr1[i]>>arr2[i]>>arr3[i];}
	
int main(){
	int N,K;
	cin >> N >> K;
	cout << N-K+1;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		sc.close();
		System.out.println(a + b + c - Math.max(a, Math.max(b, c)));
	}
}


Measured memory_bytes: 23508
W, H, N = map(int, input().split())
xya = [[int(i) for i in input().split()] for j in range(N)]
x_0, y_0 = 0, 0
x_1, y_1 = W, H
for i in range(N):
    if xya[i][2] == 1:
        x_0 = max(x_0, xya[i][0])
    elif xya[i][2] == 2:
        x_1 = min(x_1, xya[i][0])
    elif xya[i][2] == 3:
        y_0 = max(y_0, xya[i][1])
    elif xya[i][2] == 4:
        y_1 = min(y_1, xya[i][1])
if x_0 < x_1 and y_0 < y_1:
    print((x_1 - x_0) * (y_1 - y_0))
else:
    print(0)


Measured memory_bytes: 3064
import java.util.*;

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

   for(int i=0; i<=n/7; i++){
     for(int j=0; j<=(n-7*i)/4; j++){
       if(7*i + 4*j == n){
         System.out.println("Yes");
	 System.exit(0);
       }
     }
   }

   System.out.println("No");
  }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll n,m,ch[12],ans;
bool sw[12];
vector<vector<ll>>a(12);
void cal(){
	ll sum1=0;
	for(ll i=0;i<m;i++){
		ll sum=0;
		for(ll j=0;j<a[i].size();j++){
			ll now=a[i][j];
			if(sw[now]){
				sum++;
			}
		}
		if(sum%2==ch[i]){
			sum1++;
		}
	}
	if(sum1==m){
		ans++;
	}
}
void dep(ll now){
	if(now==n){
		cal();
		return;
	}
	sw[now]=0;dep(now+1);
	sw[now]=1;dep(now+1);
}
int main() {
	cin>>n>>m;
	for(ll i=0;i<m;i++){
		ll x;
		cin>>x;
		for(ll j=0;j<x;j++){
			ll y;
			cin>>y;
			y--;
			a[i].push_back(y);
		}
	}
	for(ll i=0;i<m;i++){
		cin>>ch[i];
	}
	dep(0);
	cout <<ans;
	// your code goes here
	return 0;
}

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

int main() {
	int N;
	long long answer = 0;
	cin >> N;

	for (int i = 1; i <= N; i++) {

		if (i % 3 == 0 || i % 5 == 0) {
			continue;
		}

		answer += i;
	}
	cout << answer << endl;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<algorithm>
using namespace std;
char str[1024];
int var[20];
int cur=0;
int form(){
	if(str[cur]=='T'){cur++;return 1;}
	if(str[cur]=='F'){cur++;return 0;}
	if(str[cur]>='a'&&str[cur]<='z'){cur++;return var[str[cur-1]-'a'];}
	
	if(str[cur]=='-'){
		cur++;
		int tmp=form();
		return !tmp;
	}
	if(str[cur]=='('){
		cur++;
		int L=form();
		int R;
		if(str[cur]=='+'){
			cur++;
			R=form();
			cur++;
			return L||R;
		}else if(str[cur]=='*'){
			cur++;R=form();
			cur++;
			return L&&R;
		}else{
			cur+=2;R=form();
			cur++;
			return (!L)||(L&&R);
		}
	}
}
int main(){
	while(1){
		scanf("%s",str);
		if(str[0]=='#')return 0;
		bool ok=true;
		for(int i=0;i<(1<<11);i++){
			cur=0;
			for(int j=0;j<11;j++){
				if(i&(1<<j))var[j]=1;
				else var[j]=0;
			}
			int L=form();
			cur++;
			int R=form();
			if(L!=R){ok=false;break;}
		}
		if(ok)printf("YES\n");
		else printf("NO\n");
	}
}

Measured memory_bytes: 960
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!

#include <bits/stdc++.h>
using namespace std;

#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;

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

const ll MOD = 1e9 + 7;

ll n, k;
vvll g;
ll ans;

void dfs(ll u, ll p = -1) {
    ll x = (p == -1)? k - 1 : k - 2;
    for (ll v : g[u]) {
        if (v == p) {
            continue;
        }
        ans *= x--; ans %= MOD;
        dfs(v, u);
    }
}

void func() {
    cin >> n >> k;
    ans = k;
    g.resize(n + 1);
    for (ll i = 0; i < n - 1; i++) {
        ll u, v; cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1);
    cout << ans << endl;
}

int main() {
    fast_io; cout.precision(32);
    ll t = 1; // cin >> t;
    for (ll i = 1; i <= t; i++) {
        func();
    }
}


Measured memory_bytes: 10368
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    a,b,c,d=INTM()
    cb=int((c+b-0.1)/b)
    ad=int((a+d-0.1)/d)
    if cb>ad:
        print('No')
    else:
        print('Yes')
if __name__ == '__main__':
    do()

Measured memory_bytes: 9200
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long
#define endl "\n"
#define print_array(name,n) for(ll o=0;o<n;o++) cout<<name[o]<<" "
#define fr(i,f,t) for(ll i=(f);i<t;i++)
#define fb(i,f,t) for(ll i=(f);i>=t;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 2e18
#define mod 1e9+7
bool sortbysecond(const pair<int,int> &a,const pair<int,int> &b){
	return (a.ss>b.ss);
}
template <typename T>
string NumberTostring(T Number )
{
	ostringstream ss;
	ss<<Number;
	return ss.str();
}\

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int n,k;
    cin>>n>>k;
    vector<ll> pfsum(n+1,0);
    for(int i=1;i<=n;i++){
    	pfsum[i] = pfsum[i-1]+i;
    }
    // cout<<pfsum<<endl;
    // print_array(pfsum,n+1);
    // cout<<endl;
    ll cnt = 0;
    // ll d = 0;
    for(int i=k-1;i<=n;i++){
    	int j = max(0,n-i-1);
    	ll mx = pfsum[n] - pfsum[j];
    	ll mn = pfsum[i];
    	// cout<<mx<<" "<<mn<<endl;
    	cnt+=mx-mn+1;
    }
    cout<<cnt%int(pow(10,9)+7)<<endl;
    // ll ot = pow(10,100)%(pow(10,9)+7)
    // cout<<p
    return 0;
}

Measured memory_bytes: 4776
#include<bits/stdc++.h>
#define int long long int 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 1000000007
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define pqmin priority_queue<int,vector<int>,greater<int>>
#define pqmax priority_queue<int>
using namespace std;
int32_t main()
{
    IOS;
   int n,k;
   cin>>n>>k;
   int a[n];
   for(int i=0;i<n;i++)
   {
       cin>>a[i];
   }
   sort(a,a+n);
   int check=0;
   for(int i=0;i<n;i++)
   {
       if(a[i]>=k)
       {check=1;
           cout<<n-i<<endl;
           break;
       }
   }
   if(check==0)
   cout<<0<<endl;
    return 0;
}

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

int main(){
  int a,k,p,i;
  cin >> a;
  for(i=0;i<a;i++){
    cin >> k >> p;
    if(k % p == 0)
      cout << p << endl;
    else 
      cout << k % p << endl;
  }
  return 0;
}

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

int main()
{
  int N;
  cin >> N;
  vector<int> X(N);
  vector<int> X2(N);
  for (int i = 0; i < N; i++)
  {
    cin >> X.at(i);
  }
  X2 = X;
  sort(X2.begin(), X2.end());
  int median_1 = X2.at(N / 2 - 1);
  int median_2 = X2.at(N / 2);
  for (int i = 0; i < N; i++)
  {
    if (X.at(i) >= median_2)
      cout << median_1 << endl;
    else
      cout << median_2 << endl;
  }
}

Measured memory_bytes: 3712
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;
typedef long long LL;
const int N = 1e5+100, M = 2*N,mod = 1e9+7;

LL dp[N][2];  //0是黑色， 1是白色
int n;
int h[N],e[M],ne[M],idx;

void add(int a,int b){
    e[idx] = b, ne[idx] = h[a],h[a] = idx++;
}

void dfs(int u,int fa = 0){   //，fa是u的父节点
    dp[u][0] = dp[u][1] = 1;
    for(int i = h[u]; ~i; i = ne[i]){
        int j = e[i];
        if(fa == j) continue;  //防止绕圈
        dfs(j,u);
        dp[u][0] = (dp[u][0] * dp[j][1])%mod;
        dp[u][1] = (dp[u][1] * (dp[j][0] + dp[j][1]))%mod;
    }
    
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>n;
    memset(h,-1,sizeof h);
    for(int i = 0; i<n-1; i++){
        int a,b;
        cin>>a>>b;
        add(a,b);
        add(b,a);
    }
    
    dfs(1);
    LL ans = (dp[1][0] + dp[1][1])%mod;
    
    cout<<ans;
    return 0;
}

Measured memory_bytes: 12240
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <cassert>
#include <set>
#include <queue>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int n, m, k;
	std::cin >> n >> m >> k;
	std::pair<int, int> st, en;
	std::cin >> st.first >> st.second >> en.first >> en.second;
	st.first--; st.second--;
	en.first--; en.second--;
	std::vector<std::string> mat(n);
	std::vector<std::set<int>> row(n), col(m);
	std::vector<std::vector<int>> right(n, std::vector<int>(m, 0));
	auto up = right;
	auto down = up;
	auto left = up;
	for(int i = 0; i < n; i++) {
		std::cin >> mat[i];
		for(int j = 0; j < m; j++) {
			if(mat[i][j] == '@') {
				right[i][j] = up[i][j] = down[i][j] = left[i][j] = -1;
			} else {
				row[i].insert(j);
				col[j].insert(i);
			}
		}
	}
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++) {
			if(mat[i][j] == '@') continue;
			left[i][j] = 0;
			if(j && mat[i][j-1] == '.') left[i][j] = 1 + left[i][j-1];
		}
		for(int j = m-1; j >= 0; j--) {
			if(mat[i][j] == '@') continue;
			right[i][j] = 0;
			if(j+1 < m && mat[i][j+1] == '.') right[i][j] = 1 + right[i][j+1];
		}
	}
	for(int j = 0; j < m; j++) {
		for(int i = 0; i < n; i++) {
			if(mat[i][j] == '@') continue;
			up[i][j] = 0;
			if(i && mat[i-1][j] == '.') up[i][j] = 1 + up[i-1][j];
		}
		for(int i = n-1; i >= 0; i--) {
			if(mat[i][j] == '@') continue;
			down[i][j] = 0;
			if(i+1 < n && mat[i+1][j] == '.') down[i][j] = 1 + down[i+1][j];
		}
	}
	std::vector<std::vector<int>> dist(n, std::vector<int>(m, 1e9));
	std::queue<std::pair<int, int>> q;
	auto goRow = [&](int i, int l, int r, int d) {
		auto itl = row[i].lower_bound(l);
		auto itr = row[i].upper_bound(r);
		for(auto it = itl; it != itr; it++) {
			if(dist[i][*it] > d + 1) {
				dist[i][*it] = d + 1;
				q.push(std::pair<int, int>(i, *it));
			}
		}
		row[i].erase(itl, itr);
	};
	auto goCol = [&](int j, int l, int r, int d) {
		auto itl = col[j].lower_bound(l);
		auto itr = col[j].upper_bound(r);
		for(auto it = itl; it != itr; it++) {
			if(dist[*it][j] > d + 1) {
				dist[*it][j] = d + 1;
				q.push(std::pair<int, int>(*it, j));
			}
		}
		col[j].erase(itl, itr);
	};
	dist[st.first][st.second] = 0;
	q.push(st);
	while(!q.empty()) {
		auto cur = q.front();
		q.pop();
		int d = dist[cur.first][cur.second];
		if(cur == en) {
			std::cout << d << '\n';
			return 0;
		}
		int i = cur.first, j = cur.second;
		goRow(i, j - std::min(k, left[i][j]), j + std::min(k, right[i][j]), d);
		goCol(j, i - std::min(k, up[i][j]), i + std::min(k, down[i][j]), d);
	}
	std::cout << "-1\n";
}

Measured memory_bytes: 167848
N, K = map(int, input().split())
s = input().split(' ')
p = 1
l = -1
dict = {}
for i in range(K):
	if s[p - 1] in dict:
		x = dict[s[p - 1]]
		l = i
		break
	else:
		dict[s[p - 1]] = i
	p = int(s[p - 1])
if l != -1:
	for i in range((K - (l)) % (l - x)):
		p = int(s[p - 1])
print(p)

Measured memory_bytes: 34864
#include <algorithm>
#include <string>
#include <iostream>

using namespace std;

/** Problem0015 : National Budget **/
int main()
{
	string a, b, s;
	int n, tmp, la, lb;
	bool up=false;
	
	cin >> n;
	for (int i=0; i<n; i++) {
		cin >> a >> b;
		s=""; up=0;
		
		reverse(a.begin(), a.end());
		reverse(b.begin(), b.end());
		la=(int)a.length();
		lb=(int)b.length();
		
		if (la < lb) {
			swap(la, lb);
			swap(a, b);
		}
		
		for (int i = 0; i<la-lb; i++) b+='0';
		
		for (int i=0; i<la; i++) {
			tmp = (a[i]-'0') + (b[i] - '0') + (up?1:0);
			if (tmp>=10) {
				s += '0'+tmp%10;
				up = true;
			} else {
				s += '0'+tmp;
				up = false;
			}
		}
		
		if (up)
			s+='1';
		reverse(s.begin(), s.end());
		if (s.length()>80)
			cout << "overflow" << endl;
		else
			cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 1208
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N,M = (int(_) for _ in input().split())
    
    print( (1900*M+100*(N-M))*(2**M) )
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
/*****************************************************/
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>

using namespace std;

#define   offcin        ios::sync_with_stdio(false)
#define   DEBUG         freopen("#.txt", "r", stdin)
#define   sigma_size    26
#define   lson          l,m,v<<1
#define   rson          m+1,r,v<<1|1
#define   slch          v<<1
#define   srch          v<<1|1
#define   ll            long long
#define   ull           unsigned long long
#define   lowbit(x)     (x&-x)

const int    INF    = 0x3f3f3f3f;
const ll     INFF   = 1e18;
const double pi     = acos(-1.0);
const double inf    = 1e18;
const double eps    = 1e-9;
const ll     mod    = 1e9+7;
const int    maxmat = 10;
const ull    BASE   = 133333331;

/*****************************************************/
inline void RI(int &x) {
      char c;
      while((c=getchar())<'0' || c>'9');
      x=c-'0';
      while((c=getchar())>='0' && c<='9') x=(x<<3)+(x<<1)+c-'0';
}
inline ll bits(ll x) {
      return !x ? x : bits(x - lowbit(x)) + 1;
}
/*****************************************************/

int main(int argc, char const *argv[]) {
    int X; cin>>X;
    int k = sqrt(2 * X);
    if (k * (k + 1) < 2 * X) k ++;
    cout<<k<<endl;
    return 0;
}

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

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define INF INT_MAX/3
#define N 3
typedef pair<int, int> P;

struct State {
    int g, h;
    string state;
    P blank;
    string path;
    bool operator<(const State &a) const {
        return g + h > a.g + a.h;
    }
};

int d[5] = {-1, 0, 1, 0, -1};
string r[4] = {"D", "R", "U", "L"};
string ans_str = "";
int ans[N][N], puzzle0[N][N], puzzle1[N][N];
set<string> s;
priority_queue<State> next_state;
string path;

bool range(int y, int x) {return 0 <= y && y < N && 0 <= x && x < N;}

int h1() {
    int find = -1;
    while(next_state.size()) {
        State state = next_state.top();
        next_state.pop();
        if (s.count(state.state)) continue; // already search
        s.insert(state.state); // visited

        P blank = state.blank;
        rep(i, 4) {
            int y = d[i] + blank.first, x = d[i + 1] + blank.second; // next blank position
            if (range(y, x)) { // can be replaced
                string tmp = state.state; // next state (string)
                int wrong_place = state.h, p = blank.first * N + blank.second, q = y * N + x;
                if (N < 4) {
                    swap(tmp[p], tmp[q]);
                    wrong_place = wrong_place - (state.state[q] != ans_str[q]) + (state.state[q] != ans_str[p]);
                } else {
                    swap(tmp[2 * p], tmp[2 * q]), swap(tmp[2 * p + 1], tmp[2 * q + 1]);
                    wrong_place = wrong_place - (state.state.substr(2 * q, 2) != ans_str.substr(2 * q, 2))
                    + (state.state.substr(2 * q, 2) != ans_str.substr(2 * p, 2));
                }
                if (s.count(tmp)) continue; // already search

                if (wrong_place == 0) { // answer
                    find = state.g + 1;
                    path = state.path + r[i];
                    break;
                }

                next_state.push(State{state.g + 1, wrong_place, tmp, P(y, x), state.path + r[i]});
            }
        }
        if (find != -1) break; // find an answer
    }
    return find;
}

int main(){
    // create answer's numbers
    iota(ans[0], ans[0] + N * N, 1);
    ans[N - 1][N - 1] = 0;
    // create number
    iota(puzzle0[0], puzzle0[0] + N * N, 0);
    rep(i, N)rep(j, N) cin >> puzzle0[i][j];

    string state = "";
    P blank;
    int manhattan = 0, wrong_place = 0;
    rep(i, N)rep(j, N) {
        state += to_string(puzzle0[i][j]);
        ans_str += to_string(ans[i][j]);

        if(puzzle0[i][j] == 0) blank = P(i, j);
        else {
            int num = puzzle0[i][j] - 1;
            manhattan += (abs(num / N - i) + abs(num % N - j));
            if (puzzle0[i][j] != ans[i][j]) wrong_place++;
        }
    }

    if (manhattan == 0) { // the answer
        cout << 0 << endl;
    } else {
        int steps;
        next_state.push(State{0, wrong_place, state, blank, ""});
        steps = h1();
        cout << steps << endl;
    }
    return 0;
}

Measured memory_bytes: 19800
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;

lli mod197 = 1000000007LL;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

lli L[100000] = {};

int main(void) {
	lli N, X, D = 0,ans = 0;
	cin >> N >> X;

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

	for (int i = 0; i < N; i++) {
		if (D <= X) {
			ans++;
			D += L[i];
		}
		else {
			break;
		}
	}

	if (D <= X) {
		ans++;
	}

	COUT(ans);

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int N,A[3][3],b[10],B[3][3],flag=0;
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            scanf("%d",&A[i][j]);
            B[i][j]=0;
        }
    }
    scanf("%d",&N);
    for(int k=0;k<N;k++)
    {
        scanf("%d",&b[k]);
        for(int i=0;i<3;i++)
        {
            for(int j=0;j<3;j++)
            {
            if(b[k]==A[i][j])B[i][j]=1;
            }
        }
    }
    for(int i=0;i<3;i++)
    {
    if(B[i][0]==1&&B[i][1]==1&&B[i][2]==1){printf("Yes");flag=1;break;}
    else if(B[0][i]==1&&B[1][i]==1&&B[2][i]==1){printf("Yes");flag=1;break;}
    else if(B[0][0]==1&&B[1][1]==1&&B[2][2]==1){printf("Yes");flag=1;break;}
    else if(B[0][2]==1&&B[1][1]==1&&B[2][0]==1){printf("Yes");flag=1;break;}
    }
     if(flag!=1)printf("No");
    
}


Measured memory_bytes: 128
n = input()
G = [[] for i in xrange(n)]
for i in xrange(n-1):
    a, b = map(int, raw_input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

from collections import deque
deq = deque()
deq.append((0, 0))
deq.append((n-1, 1))
C = [None]*n
C[0] = 0; C[n-1] = 1
while deq:
    v, col = deq.popleft()
    for t in G[v]:
        if C[t] is None:
            C[t] = col
            deq.append((t, col))
B = C.count(0)
W = C.count(1)
if B == W:
    print "Snuke"
elif B < W:
    print "Snuke"
elif B > W:
    print "Fennec"


Measured memory_bytes: 22392
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,sum=0;
	cin>>n;
	int t[n];
	for(int i=0;i<n;i++) cin>>t[i], sum+=t[i];
	int m;
	cin>>m;
	while(m--){
		int a,b;
		cin>>a>>b;
		cout<<sum-t[a-1]+b<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int N;

int fullsearch(vector<vector<pair<int, int> > > &testimony){
    int bit=(1<<N);
    int ans=0;
    bit--;
    for(; bit>0; bit--){
        int flag=1;
        for(int i=0; i<N; i++){
            if(bit&(1<<i)){
                for(int j=0; j<(int)testimony[i].size(); j++){
                    int x=testimony[i][j].first;
                    int y=testimony[i][j].second;
                    if((y==0 && ~bit&(1<<x))||(y==1 && bit&(1<<x))){
                        continue;
                    }else{
                        flag=0;
                        break;
                    }
                }
            }
            if(flag==0){
                break;
            }
        }
        if(flag==0)continue;
        int cnt=0;
        int tmp=bit;
        while(tmp>0){
            cnt+=(int) tmp&1;
            tmp>>=1;
        }
        ans=max(ans,cnt);
    }
    return ans;
}

int main(){
    cin >> N;
    vector<vector<pair<int, int> > > testimony(N,vector<pair<int, int> >(0));
    for(int i=0; i<N; i++){
        int A;
        cin >> A;
        for(int j=0; j<A; j++){
            int x, y;
            cin >> x >> y;
            x--;
            testimony[i].push_back(make_pair(x, y));
        }
    }
    cout << fullsearch(testimony) << endl;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            long[] ary = cin.ReadLongArray(3);
            long A = ary[0];
            long B = ary[1];
            long K = ary[2];
            if (K >= A)
            {
                K = K - A;
                A = 0;
 
                if (K >= B)
                {
                    B = 0;
                }
                else
                {
                    B = B - K;
                }
            }
            else
            {
                A = A - K;
            }
            Console.WriteLine(A.ToString()+" "+B.ToString());


        }

    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 13268
from collections import deque
import copy

h,w=map(int,input().split())
cy,cx=map(int,input().split())
gy,gx=map(int,input().split())
inf=float('inf')
maze=[]
for _ in range(h):
  s=list(input())
  for i in range(w):
    if s[i]=='.':
      s[i]=inf
  maze.append(s)
  
def solve(maze,cy,cx,gy,gx):
  maze1=copy.deepcopy(maze)
  [sy,sx]=[cy-1,cx-1]
  qu=deque([[sy,sx]])
  maze[sy][sx]=0
  T=0
  while qu:
    y,x=qu.popleft()
    t=maze[y][x]
    
    if maze1[y][x]!=1:
      
      for i in ([1,0],[0,1],[-1,0],[0,-1]):
        ny=y-i[0]
        nx=x-i[1]
        if 0<=ny<=h-1 and 0<=nx<=w-1 and maze[ny][nx]!='#':
          if maze[ny][nx]>t:
            maze[ny][nx]=t
            qu.appendleft([ny,nx])
          
      
      for j in range(-2,3):
        for k in range(-2,3):
          ny=y-j
          nx=x-k
          if 0<=ny<=h-1 and 0<=nx<=w-1 and maze[ny][nx]!='#':
            if maze[ny][nx]>t:
              maze[ny][nx]=t+1
              qu.append([ny,nx])
      maze1[y][x]=1
            
  return maze[gy-1][gx-1]
  
if solve(maze,cy,cx,gy,gx)==inf:
  print(-1)
  
else:
  print(solve(maze,cy,cx,gy,gx))

Measured memory_bytes: 228192
#include <algorithm>
#include <array>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifdef NEAL_DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

pair<int64_t, int64_t> extended_euclidean(int64_t a, int64_t b) {
    // https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm#Example
    int64_t g = b, r = a, x = 0, y = 1;

    while (r != 0) {
        int64_t q = g / r;
        g %= r; swap(g, r);
        x -= q * y; swap(x, y);
    }

    x = x < 0 ? x + b : x;
    // x * a == g mod b
    y = (x * a - g) / b;

    while (x <= 0 || y <= 0) {
        x += b;
        y += a;
    }

    dbg(a, b, x, y);
    return {x, y};
}


int main() {
    ios::sync_with_stdio(false);
#ifndef NEAL_DEBUG
    cin.tie(nullptr);
#endif

    int64_t N;
    cin >> N;
    N *= 2;
    int64_t best = 2 * N;

    auto consider_candidate = [&](int64_t candidate) {
        if (candidate > 0)
            best = min(best, candidate);
    };

    for (int64_t a = 1; a * a <= N; a++)
        if (N % a == 0) {
            int64_t b = N / a;

            if (__gcd(a, b) == 1) {
                consider_candidate(b * extended_euclidean(a, b).second);
                consider_candidate(a * extended_euclidean(b, a).second);
            }
        }

    cout << best << '\n';
}


Measured memory_bytes: 3656
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
  string s;
  cin >> s;
  int res = 0;
  for(int k = 0; k < (int)s.size(); k++){
    int j,o,i;
    if(s[k]!='O') continue;
    for(o = 0; k+o < (int)s.size() && s[k+o] == 'O'; o++);
    for(j = 0; 0 <= k-j-1 && s[k-j-1] == 'J'; j++);
    for(i = 0; k+o+i < (int)s.size() && s[k+o+i] == 'I'; i++);
    if(j >= o && i >= o){
      res = max(res,o);
    }
    k += o+i-1;
  }
  cout << res << endl;
}

Measured memory_bytes: 2052
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

string S;

int main(){
    cin>>S;

    for(int i=0;i<S.size();i++){
        if((i%2==0 && S[i]=='L') ||
            i%2==1 && S[i]=='R'){
            cout<<"No"<<endl;
            return 0;
        }
    }

    cout<<"Yes"<<endl;
}

Measured memory_bytes: 384
n = int(input())
al = list(map(int, input().split()))

min_abs = 10**9
abs_sum = 0
minus_cnt = 0
zero_cnt = 0
for a in al:
    if a < 0: minus_cnt+=1
    elif a == 0: zero_cnt+=1
    abs_sum += abs(a)
    min_abs = min(min_abs, abs(a))

if minus_cnt%2 == 0:
    print(abs_sum)
else:
    if zero_cnt > 0:
        print(abs_sum)
    else:
        print(abs_sum-min_abs*2)


Measured memory_bytes: 85164
using System;
using static System.Console;

namespace ChildrenAndCandies
{
    class Program
    {
        static void Main(string[] args)
        {
            int ans = 0;
            int s = int.Parse(ReadLine());
            for(int i = 0; i <= s; i++){
                ans += i;
            }

            WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
string T[101];

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

	
	for(int t = 0; t < y; t++){
		
		cin >> T[t];

	}	
	for(int t = 0; t <= x + 1; t++) cout << "#";
	cout << endl;
	
	for(int t = 0; t < y; t++){
		cout << "#" << T[t] << "#" <<endl;
	}
	for(int t = 0; t <= x + 1; t++) cout << "#";
	cout << endl;

}

Measured memory_bytes: 256
#include<stdio.h>


void selectionSort(int A[], int N){

  int i, j, k, min, count = 0;

  for( i = 0; i < N ; i++ ){

    min = i;

    for(j = i ; j < N; j++ ){

      if(A[j] < A[min]){
        min = j;
      }
    }
     k = A[i];
     A[i] = A[min];
     A[min] = k;
     if(i != min)count += 1;


  }

  space(A, N);

  printf("%d\n",count);

}


void space(int A[], int N){

  int i;

  for( i = 0; i < N; i++){

    if( i > 0 ){

      printf(" ");

    }

    printf("%d", A[i]);

  }

  printf("\n");

}


int main(void){

  int N, i, j;

  int A[100];

  

  scanf("%d", &N);

  for(i = 0; i < N; i++){

    scanf("%d", &A[i]);

  }

  selectionSort(A, N);

}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair
 
using namespace std;
 
const LL MOD=1e9+7;

int n;
char mx;
vector <string> dp[20];

int main()
{
	cin>>n;
	dp[1].pb("a");
	repn(i,n-1)
	{
		rep(j,dp[i].size())
		{
			//dp[i+1].pb(dp[i][j]+dp[i][j][dp[i][j].size()-1]);
			//dp[i+1].pb(dp[i][j]+(char)(dp[i][j][dp[i][j].size()-1]+1));
			
			mx='a';
			rep(k,dp[i][j].size()) mx=max(mx,dp[i][j][k]);
			for(char k='a';k<=mx+1;k++) dp[i+1].pb(dp[i][j]+k);
		}
	}
	rep(i,dp[n].size()) printf("%s\n",dp[n][i].c_str());
	return 0;
}

Measured memory_bytes: 11380
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Foreach(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define rof(i,a,b) for(int (i)=(a);(i) > (b); --(i))
#define rep(i, c) for(auto &(i) : (c))
#define x first
#define y second
#define pb push_back
#define PB pop_back()
#define iOS ios_base::sync_with_stdio(false)
#define sqr(a) (((a) * (a)))
#define all(a) a.begin() , a.end()
#define error(x) cerr << #x << " = " << (x) <<endl
#define Error(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define errop(a) cerr<<#a<<" = ( "<<((a).x)<<" , "<<((a).y)<<" )\n";
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)
#define L(x) ((x)<<1)
#define R(x) (((x)<<1)+1)
#define umap unordered_map
#define double long double
typedef long long ll;
typedef pair<int,int>pii;
typedef vector<int> vi;
typedef complex<double> point;
template <typename T> using os =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T>  inline void smax(T &x,T y){ x = max((x), (y));}
template <class T>  inline void smin(T &x,T y){ x = min((x), (y));}
const int maxn = 2100;
vi adj[maxn];
int cnt = 0, ans = 0;
int dp[maxn][maxn], sz[maxn], odp[maxn][maxn];
int n, k;
inline void dfs(int v = 0, int p = -1){
	sz[v] = 1;
	For(i,0,n+1)	smax(dp[v][i], 1);
	rep(u, adj[v])	if(u - p){
		dfs(u, v);
		For(i,0,sz[v] + 1)	odp[v][i] = dp[v][i];
		rof(i,sz[v],-1)
			For(j,0,sz[u]+1)if(i + j + 1 <= k)
				smax(dp[v][max(i, j+1)], odp[v][i] + dp[u][j]);
		sz[v] += sz[u];
	}
	For(i,1,n+1)	smax(dp[v][i], dp[v][i-1]);
}
int main(){
	iOS;
	cin >> n >> k;
	For(i,1,n){
		int v, u;
		cin >> v >> u;
		-- v, -- u;
		adj[v].pb(u), adj[u].pb(v);
	}
	dfs(0);
	For(i,0,n)	smax(ans, dp[i][k]);
	cout << n-ans << endl;
	return 0;
}

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

int main() {
	int n_in, a_in;
	double total=0, answ=0;
	cin >> n_in;
	for (int i = 0; i < n_in; ++i) {
		cin >> a_in;
		total += 1/((double)a_in );
	}
	answ=1/total;
	std::cout << std::setprecision(10) << answ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1001001001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

int main()
{
    int n, c, k;
    cin >> n >> c >> k;
    vector<ll> t(n);
    for (int i = 0; i < n; i++)
    {
        cin >> t[i];
    }
    sort(t.begin(), t.end());
    int ans = 0;
    int cnt = 0;  // 乗客数
    ll start = 0; // 出発時間
    for (int i = 0; i < n; i++)
    {
        if (start == 0)
        {
            start = t[i];
        }
        if (t[i] > start + k || cnt >= c)
        {
            ++ans;
            start = t[i];
            cnt = 1;
        }
        else
        {
            ++cnt;
        }
    }
    cout << ans + 1 << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
};

Measured memory_bytes: 3936
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rf = lambda: map(float, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(a[ri()-1])



Measured memory_bytes: 27192
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 160090;

int par[MAX_N], Rank[MAX_N], size[MAX_N];
const int dx[] = {0, 0, -1, 1};
const int dy[] = {-1, 1, 0, 0};
void init(int n)
{
    for (int i = 0; i < n; i++)
    {
        par[i] = i;
        Rank[i] = 0;
        size[i] = 1;
    }
}
int find(int x)
{
    if (par[x] == x)
    {
        return x;
    }
    else
    {
        return par[x] = find(par[x]);
    }
}
void unite(int x, int y)
{
    x = find(x);
    y = find(y);
    if (x == y)
        return;
    if (Rank[x] < Rank[y])
    {
        par[x] = y;
        size[y] += size[x];
    }
    else
    {
        par[y] = x;
        size[x] += size[y];
        if (Rank[x] == Rank[y])
            Rank[x]++;
    }
}

bool same(int x, int y)
{
    return find(x) == find(y);
}
int main()
{
    int H, W;
    cin >> H >> W;
    string S[H];
    init(MAX_N);
    for (int i = 0; i < H; i++)
    {
        cin >> S[i];
    }
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            for (int k = 0; k < 4; k++)
            {
                int nx = i + dx[k];
                int ny = j + dy[k];
                if (0 <= nx && nx < H && 0 <= ny && ny < W)
                {
                    if (S[i][j] != S[nx][ny])
                    {
                        unite(i * W + j, nx * W + ny);
                    }
                }
            }
        }
    }
    map<int, long long> white;
    map<int, long long> black;
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (S[i][j] == '#')
            {
                white[find(i * W + j)]++;
            }
            else
            {
                black[find(i * W + j)]++;
            }
        }
    }
    long long sum = 0;
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            sum += white[i * W + j] * black[i * W + j];
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 22400
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1 << 21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

// 0112c
int main(){
    int n;
    cin >> n;
    ll x[n], y[n], h[n];
    rep(i, n) cin >> x[i] >> y[i] >> h[i];
    ll H = 0;
    rep(cx, 101)rep(cy, 101){
        bool flag = true;
        H = -1;
        rep(i, n){
            ll tmp;
            if (h[i]!=0){
                tmp = h[i] + abs(x[i]-cx) + abs(y[i]-cy);
                if (H==-1){
                    H = tmp;
                    continue;
                }else{
                    if (H!=tmp) {
                        flag = false;
                        break;
                    }
                }
            }else{
                continue;
            }
        }
        if (flag){
            rep(i, n){
                ll tmp;
                tmp = max(H-abs(x[i]-cx)-abs(y[i]-cy), 0LL);
                if (tmp != h[i]){
                    flag = false;
                    break;
                }
            }
        }
        if (flag){
            cout << cx << ' ' << cy << ' ' << H << endl;
            return 0;
        }

    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <cstdio>
#include <vector>
#include <set>
#include <cassert>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <sstream>
#include <functional>
//#include <windows.h>  //Should be deleted when using AtCoder&POJ
using namespace std;
/**==Info==
*Program:A
*Problem:Palindromic Number
*Date:2017-8-11
*Algorithm:AtCoder
*Stats:Unknown*/
string toString(int num){
	string x="";
	bool negative=false;
	if(num==0) return "0";
	if(num<0) {
		negative=true;
		num=abs(num);
	}
	while(num!=0){
		char c='0'+num%10;
		num=num/10;
		x+=c;
	}
	reverse(x.begin(),x.end());
	if(negative) x="-"+x;
	return x;
}

int main(){
	int n;
	cin>>n;
	string s=toString(n);
	string ss=s;
	reverse(ss.begin(),ss.end());
	if(ss==s){
		cout<<"Yes";
	}else{
		cout<<"No";
	}
	return 0;
}


Measured memory_bytes: 256