akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef vector<int> vi;
typedef vector<vi> vvi;

/*{
  }*/

signed main(){
  int n;
  cin >> n;

  vi a(n);
  int sum = 0;
  rep(i, 0, n){
    cin >> a[i];
    sum += a[i];
  }

  int ans = 1LL<<60;
  int s = 0;
  rep(i, 0, n){
    s += a[i];
    int t = sum - s;
    chmin(ans, abs(s-t));
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	string s,t;
	cin >> s;
	REP(i, s.size()) {
		if (s[i] == 'B') {
			if(!t.empty()) 
				t.pop_back();
		}
		else {
			t.push_back(s[i]);
		}
	}
	cout << t << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
#define rep(i, n)  for (int i = 0; i <  (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const ll INF = ll(1e18)+1;

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

    ll a;
    cin >> a;
    ll result = a + a*a + a*a*a;
    cout << result;
}

Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <queue>
#include <utility>
#include <vector>
using namespace std;

typedef pair<int, int> P;

const int MAX_N = 400;

const int di[] = {1, 0, -1, 0};
const int dj[] = {0, 1, 0, -1};

bool color[MAX_N][MAX_N];
int H, W;

string s;

void input() {
    cin >> H >> W;
    for (int i = 0; i < H; i++) {
        cin >> s;
        for (int j = 0; j < W; j++) {
            color[i][j] = (s[j] == '#');
        }
    }
}

bool isin_(int i, int j) {
    return 0 <= i && i < H && 0 <= j && j < W;
}

bool check_(int i, int j, int d) {
    int ni = i + di[d];
    int nj = j + dj[d];
    if (!isin_(ni, nj)) return false;
    if (color[i][j] == color[ni][nj]) return false;
    return true;
}

bool used[MAX_N][MAX_N];

long long solve() {
    long long ans = 0;
    long long b = 0, w = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (used[i][j]) continue;
            b = 0;
            w = 0;
            queue<P> que;
            used[i][j] = true;
            que.push(P(i, j));
            while (!que.empty()) {
                P p = que.front();
                que.pop();
                int ci = p.first, cj = p.second;
                if (color[ci][cj]) b++;
                else w++;
                for (int d = 0; d < 4; d++) {
                    if (!check_(ci, cj, d)) continue;
                    int ni = ci + di[d], nj = cj + dj[d];
                    if (used[ni][nj]) continue;
                    used[ni][nj] = true;
                    que.push(P(ni, nj));
                 }
            }
            ans += b * w;
        }
    }
    return ans;
}

int main() {
    input();
    long long ans = solve();
    printf("%lld\n", ans);
    return 0;
}

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

int main(){
  int ans;
  char a;
  ans = 700;
  for(int i =0;i < 3;i++){
    cin >> a;
    if(a == 'o'){
      ans += 100;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;

const int maxn=1e5+5;
int a[maxn],f[maxn],n,len;

int main()
{
    //freopen("input.txt","r",stdin);
    cin>>n;
    for(int i=0;i<n;i++) scanf("%d",&a[n-i-1]);
    fill(f,f+n+2,1e9+5);
    for(int i=0;i<n;i++) *upper_bound(f,f+n,a[i])=a[i];
    cout<<lower_bound(f,f+n,1e9+5)-f;

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////

const ll inf = 1LL<<60;

int main()
{
  ll n; cin >> n;
  ll m; cin >> m;
  ll k; cin >> k;
  ll ans = 0;
  vector<ll> a(n);
  for (int i=0; i<n; i++){
    cin >> a[i];
  }
  vector<ll> b(m);
  for (int i=0; i<m; i++){
    cin >> b[i];
  }
  vector<ll> aa(n+1);
  vector<ll> bb(m+1);
  for (int i=0; i<n; i++) {
    aa[i+1] = aa[i] + a[i];
    if (aa[i+1] <= k) ans = max(ans, (ll)i+1);
  }
  for (int i=0; i<m; i++) {
    bb[i+1] = bb[i] + b[i];
    if (bb[i+1] <= k) ans = max(ans, (ll)i+1);
  }
  for (int i=0; i<=n; i++) {
    int t = upper_bound(bb.begin(), bb.end(), k-aa[i]) - bb.begin() - 1;
    if (aa[i] + bb[t] <= k) ans = max(ans, (ll)i+t);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 9596
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int dig(int x){
	int res=0;
	while(x>=1){
		res+=(x%10);
		x/=10;
	}
	return res;
}
int main(){
    //~ freopen("file.in", "r", stdin);
    int n;
    scanf("%d",&n);
    if(n%dig(n)==0)
		puts("Yes");
	else
		puts("No");
	return 0;
}


Measured memory_bytes: 256
from collections import deque
from heapq import heappush,heappop
import re
def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int, ss_raw()))

INF = 1<<29

def getDeci(tree):
    def saiki(v):
        root = [0,v,-1]
        cur = None
        qu = deque()
        qu.append(root)
        while len(qu)!=0:
            cur = qu.popleft()
            for e in tree[cur[1]]:
                if e ==cur[2]:
                    continue
                qu.append([cur[0]+1,e,cur[1]])
        return cur
    leaf = saiki(0)
    ans = saiki(leaf[1])
    return ans

    
N = int_raw()
tree = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = ints_raw()
    a = a-1
    b = b-1
    tree[a].append(b)
    tree[b].append(a)



def main():
    ans = getDeci(tree)
    if (ans[0]+2)%3==0:
        return "Second"
    else:
        return "First"

print(main())


Measured memory_bytes: 122188
#include <iostream>                                             
#include <string>                                               
using namespace std;                                            
                                                                
int main(void) {                                                
  int n;                                                        
  cin >> n;                                                     
  string t_cards, h_cards;                                      
  int t_point = 0;                                              
  int h_point = 0;                                              
  for (int i=0; i<n; i++) {                                     
    cin >> t_cards >> h_cards;                                  
    if (t_cards > h_cards) {                                    
      t_point += 3;                                             
    } else if (t_cards< h_cards) {                              
      h_point += 3;                                             
    } else {                                                    
      t_point += 1;                                             
      h_point += 1;                                             
    }                                                           
  }                                                             
  cout << t_point << " " << h_point << endl;                    
                                                                
  return 0;                                                     
}                                                               
                                                                
                                                                
                                                                
                                                                
                                  

Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

struct Graph {
    struct Edge { int from; int to; lint cost; };
    struct Node {
        Node() : par(-1), done(false), dist(INF) {}
        int index;
        int par;
        bool done;
        lint dist;
        vector<Edge> edge;
    };

    int n;
    vector<Node> nodes;
    vector<Edge> edges;
    const static lint INF = 1e18;

    Graph(int n) : n(n) {
        nodes.resize(n);
        for(int i=0; i<n; i++)  nodes[i].index = i;
    }

    void add_edge(int from, int to, lint cost) {
        nodes[from].edge.push_back(Edge{from, to, cost});
        edges.push_back(Edge{from, to, cost});
    }

    void dijkstra(int s) {
        using Cand = tuple<lint, int, int>; // (dist, index, from)
        priority_queue<Cand, vector<Cand>, greater<Cand>> que;
        que.emplace(0, s, -1);

        while(!que.empty()) {
            lint dist; int index, from;
            tie(dist, index, from) = que.top(); que.pop();
            if(dist >= nodes[index].dist)  continue;
            
            nodes[index].dist = dist;
            nodes[index].par = from;
            for(auto& e : nodes[index].edge) {
                que.emplace(dist + e.cost, e.to, e.from);
            }
        }
    }

    bool bellman_ford(int s) {
        bool negative_cycle;
        nodes[s].dist = 0;
        for(int step=1; step<=n; step++) {
            bool update = false;
            for(auto& e : edges) {
                if(nodes[e.from].dist == INF)  continue;

                lint next_cost = nodes[e.from].dist + e.cost;
                if(nodes[e.to].dist > next_cost) {
                    nodes[e.to].dist = next_cost;
                    nodes[e.to].par = e.from;
                    update = true;
                }
            }
            negative_cycle = (step == n && update);
        }
        return negative_cycle;
    }

    void bfs(int s) {
        queue<int> que;
        nodes[s].dist = 0;
        que.push(s);

        while(!que.empty()) {
            int index = que.front(); que.pop();
            for(auto& e : nodes[index].edge) {
                if(nodes[e.to].dist != INF)  continue;
                nodes[e.to].dist = nodes[index].dist + 1;
                nodes[e.to].par = index;
                que.push(e.to);
            }
        }
    }

    lint shortest_dist(int to) { return nodes[to].dist; }

    vector<int> shortest_path(int to) {
        vector<int> path;
        int index = to;
        while(index != -1) {
            path.push_back(index);
            index = nodes[index].par;
        }
        reverse(path.begin(), path.end());
        return path;
    }
};

int main() {
    lint N, M;
    cin >> N >> M;

    Graph G(N);
    for(int i=0; i<M; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;

        G.add_edge(a, b, 1);
        G.add_edge(b, a, 1);
    }

    G.bfs(0);
    cout << "Yes" << endl;
    for(int i=1; i<N; i++) {
        cout << G.nodes[i].par+1 << endl;
    }
}

Measured memory_bytes: 24744
from collections import defaultdict
import re
from itertools import product

atcg = ['A', 'T', 'C', 'G']
num = int(input())

def validate(tpl):
    string = tpl[0] + tpl[1] + tpl[2] + tpl[3]
    for pat in [r'A.GC', r'AG.C', 'ACG', 'AGC', 'GAC']:
         if re.search(pat, string):
                return False
    return True

def transition(dic):
    new_dic = defaultdict(int)
    for k, v in dic.items():
        for c in atcg:
            tpl = k[1], k[2], k[3], c
            if validate(tpl):
                new_dic[tpl] += v
    return new_dic

it = product(atcg, atcg, atcg, atcg)
dic = {}
for s in it:
    if validate(s):
        dic[s] = 1

if num == 3:
    print(61)
elif num == 4:
    print(230)
else:
    for n in range(num - 4):
        dic = transition(dic)
    print(sum(dic.values()) % 1000000007)

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

int main() {
  long N;
  string result;
  long count = 0;
  vector<long> A(N);
  cin >> N;
  for(long i = 0; i < N; i++){
    cin >> A.at(i);
    if(A.at(i)%2 == 0){
      if(A.at(i)%6 != 0 && A.at(i)%10 != 0){
        count++;
      }
    }
  }
    if(count != 0){
      result = "DENIED";
    }else{
      result = "APPROVED";
    }
  cout << result << endl;
} 

Measured memory_bytes: 33024
(defun classifier (n)
  (let ((m (mod n 10)))
    (cond ((= m 3) "bon")
          ((or (= m 0)
               (= m 1)
               (= m 6)
               (= m 8)) "pon")
          (t "hon"))))

(defun main ()
  (let ((n (read)))
    (princ (classifier n)))
)
(main)

Measured memory_bytes: 23600
#include<bits/stdc++.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
int n,m;
int X[1000],Y[1000];

int check(int x,int y){
	for(int i=0;i<n;i++) if(X[i]==x&&Y[i]==y) return 1;
	return 0;
}

int main(){
	while(scanf("%d",&m),m){
		int x[200],y[200];
		for(int i=0;i<m;i++) scanf("%d%d",&x[i],&y[i]);
		for(int i=1;i<m;i++) x[i]-=x[0],y[i]-=y[0];
		scanf("%d",&n);
		for(int i=0;i<n;i++) scanf("%d%d",&X[i],&Y[i]);
		for(int i=0;i<n;i++){
			int res=1;
			for(int j=1;j<m;j++) if(!check(X[i]+x[j],Y[i]+y[j])){ res=0; break; }
			if(res){ printf("%d %d\n",X[i]-x[0],Y[i]-y[0]); break; }
		}
	}
}

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

int main() {
  int n, l, r, ans;
  cin >> n;
  ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> l >> r;
    ans += r - l + 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
n = int(input())

s = input()

A = []
for i in range(10):
    A.append([])
for i in range(n):
    A[int(s[i])].append(i)

total = 0
for i in range(1000):
    a = "{0:03d}".format(i)
    B = []
    for j in a:
        B.append(int(j))
    c = -1
    check = 0
    for j in B:
        check = 0
        if len(A[j]) > 0:
            for k in A[j]:
                if k > c:
                    c = k
                    check = 1
                    break
        else:
            break
        if check == 0:
            break
    if check == 1:
        total += 1
print(total)

Measured memory_bytes: 42480
#include <iostream>
//#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1

int main() {
    LL a;
    LL b;
    LL x;
    cin >> a >> b >> x;
    if(a+b>=x && a<=x){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 3492
def bitter_alchemy(N: int, X: int, M: list) -> int:
    return N + (X - sum(M))//min(M)


if __name__ == "__main__":
    N = 0
    N, X = map(int, input().split())
    M = [int(input()) for _ in range(N)]
    ans = bitter_alchemy(N, X, M)
    print(ans)


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

signed main(){
  int A,V,C,W,T;
  cin>>A>>V>>C>>W>>T;
  string ans="NO";
  if(W<V){
    int DI=abs(A-C);
    int DC=(V-W)*T;
    if(DI<=DC)ans="YES";
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3592
// ------------------------------------
// Date:2018/ 3/ 5
// Problem:ABC 082 FTRobot d.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

// dpx[num][pos], dpy[num][pos] : 2.56*10^8Byte
bool dpx[8080][16010];
bool dpy[8080][16010];

inline int p(int n) { return n + 8000; }

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

  memset(dpx, false, sizeof(dpx));
  memset(dpy, false, sizeof(dpy));
  
  bool ok = false;
  string S;
  cin >> S;
  int x, y, cnt = 0, tmp;
  cin >> x >> y;
  while (S[cnt] == 'F') ++cnt;
  // cout << cnt << endl;
  tmp = cnt;
  dpx[tmp][p(tmp)] = true;
  dpy[tmp][p(0)] = true;

  
  // dist: true(x方向), false(y方向)
  bool dist = true;
  cnt = 0;
  if (tmp == 0) {
    // 1文字目がTのとき
    dist = false;
  }
  FOR(si, (tmp==0 ? 1 : tmp), S.size() + 1) {
    if (S[si] == 'T' or si == S.size()) {
      if (dist) {
	// x方向
	FOR(i, 1+abs(cnt), 16000-abs(cnt)) {
	  if (dpx[si - cnt - 1][i]) {
	    dpx[si][i + cnt] = true;
	    dpx[si][i - cnt] = true;
	    //cout << si << "," << i + cnt << (dpx[si][p(i + cnt)] ? "T" : "F") << endl;
	  }
	  if (dpy[si - cnt - 1][i]) dpy[si][i] = true;
	}
      } else {
	// y方向
	FOR(i, 1+abs(cnt), 16000-abs(cnt)) {
	  if (dpx[si - cnt - 1][i]) dpx[si][i] = true;
	  if (dpy[si - cnt - 1][i]) {
	    dpy[si][i + cnt] = true;
	    dpy[si][i - cnt] = true;
	    //cout << si << "," << i + cnt << (dpy[si][p(i + cnt)] ? "T" : "F") << endl;
	  }
	}
      }
      dist = !dist;
      cnt = 0;
    } else {
      ++cnt;
    }
  }

  /*
  REP(i, S.size() + 1) {
    FOR(j, -3, 3) {
      FOR(k, -3, 3) {
	if (dpx[i][p(j)] and dpy[i][p(k)]) cout << j << "," << k << (dpx[i][p(j)] ? "XT" : "XF") << (dpy[i][p(k)] ? "YT" : "YF") << endl;
      }
    }
    cout << i << "END" << endl;
  }
  */

  if (dpx[S.size()][p(x)] and dpy[S.size()][p(y)]) ok = true;
  
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}



Measured memory_bytes: 252928
#include<stdio.h>

int main(void){
  int N;
  int A[100];
  int i;
  
  scanf("%d", &N);
  for(i = 0; i < N; i++){
    scanf("%d", &A[i]);
  }
  
  for(i = 0; i < N; i++){
  if(A[i] % 2 == 0 && A[i] % 3 != 0 && A[i] % 5 != 0){
    puts("DENIED");
    return 0;}
  }
  
  puts("APPROVED");
 
  return 0;
}

Measured memory_bytes: 1640
#include<stdio.h>
#include<iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>

using namespace std;



int main() {

	int n, d;

	cin >> n >> d;

	double temp[10][10];

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < d; j++) {
			cin >> temp[i][j];
		}
	}
	
	int count = 0;

	for (int i = 0; i < n - 1; i++) {
		for (int j = i + 1; j < n; j++) {
			double t = 0;
			for (int k = 0; k < d; k++) {
				t += fabs((temp[i][k] - temp[j][k])*(temp[i][k] - temp[j][k]));
			}
			t = sqrt(t);
			if (ceil(t) == floor(t) && i<j) {
				count++;
			}

		}
	}

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



Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int t, a, b;
    cin >> a >> b >> t;
    cout << (t / a) * b << endl;
    return 0;
};


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;

vector<int> G[2000];
int dfs(int v, int p, int rem){
	int res = 1;
	if(rem >= 1){
		for(int u : G[v]){
			if(u != p){
				res += dfs(u, v, rem - 1);
			}
		}
	}
	return res;
}

int main(){
	int N, K;
	cin >> N >> K;
	for(int i=0;i<N-1;i++){
		int u, v;
		cin >> u >> v;
		--u;
		--v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	int maxRemain = 0;
	for(int v=0;v<N;v++){
		maxRemain = max(maxRemain, dfs(v, -1, K / 2));
	}
	for(int v=0;v<N;v++){
		for(int u : G[v]){
			maxRemain = max(maxRemain, dfs(v, u, (K - 1) / 2) + dfs(u, v, (K - 1) / 2));
		}
	}
	int res = N - maxRemain;
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int N;
string s[10010];
string t;
int main(void){
	cin >> N;
	rep(i, N)cin >> s[i];
	cin >> t;
	string tmp = t;
	while(t.size() < 20){
		t += 'A';
	}

	int mae = 0, usi = 0;
	rep(k, N){
		string d = s[k];
		bool fmae = false, fusi = false;

		if(d != tmp){
			rep(i, t.size()){
				if(d[i] != '?' && d[i] < t[i]){
					fmae = true;
					break;
				}else if(d[i] != '?' && d[i] > t[i]){
					fusi = true;
					break;
				}else if(d[i] == '?' && t[i] != 'a' && t[i] != 'z'){
					// printf("k\n");
					fmae = true; fusi = true;
					break;
				}else if(d[i] == '?' && t[i] != 'z'){
					fusi = true;
				}else if(d[i] == '?' && t[i] != 'a'){
					fmae = true;
				}
			}
		}else{
			fmae = true; fusi = true;
		}

		if(fmae) mae++;
		if(fusi) usi++;
	}

	// printf("%d %d\n", mae, usi);
	int r = mae + 1;
	int l = N - usi + 1;
	// printf("%d\n", r - l);
	reps(i, l, r + 1){
		if(i != r)printf("%d ", i);
		else printf("%d\n", i);
	}
	return 0;
}

Measured memory_bytes: 896
#b
import sys
N = int(input())
inf = 10**18
a = list(map(int, input().split()))
ans = a[0]
if 0 in a:
    print("0")
    sys.exit()
for i in range(1,len(a)):
    ans = ans * a[i]

    if ans > inf:
        print("-1")
        sys.exit()
print(ans)

Measured memory_bytes: 21644
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
    string strr;
    cin >> strr;
    if(strr.size()>0 && strr.size()<11)
    {
        string answer;
        int i = 0;
        while(i<strr.size())
        {
            if(strr[i]!='B')
            {
                answer+=strr[i];
                i++;
            }
            else
            {
                if(answer.size()==0){
                    i++;
                }
                else {
                    answer.erase(answer.size()-1);
                    i++;
                }
            }
        }
        cout << answer << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <algorithm> 
#include <cstring>
using namespace std;
int x, y, z, w;
int main(){
	scanf("%1d%1d%1d%1d", &x, &y, &z, &w);
	if(x + y + z + w == 7){printf("%d+%d+%d+%d=7", x, y, z, w); return 0;}
	if(x + y + z - w == 7){printf("%d+%d+%d-%d=7", x, y, z, w); return 0;}
	if(x + y - z + w == 7){printf("%d+%d-%d+%d=7", x, y, z, w); return 0;}
	if(x + y - z - w == 7){printf("%d+%d-%d-%d=7", x, y, z, w); return 0;}
	if(x - y + z + w == 7){printf("%d-%d+%d+%d=7", x, y, z, w); return 0;}
	if(x - y + z - w == 7){printf("%d-%d+%d-%d=7", x, y, z, w); return 0;}
	if(x - y - z + w == 7){printf("%d-%d-%d+%d=7", x, y, z, w); return 0;}
	if(x - y - z - w == 7){printf("%d-%d-%d-%d=7", x, y, z, w); return 0;}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repin(Array,i,n) for(int i=0;i<n;i++){cin>>Array[i];}
using namespace std;

using ll = long long;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;
using Graph = vector<vector<int>>;

int main() {

	int N, Y;
	cin >> N >> Y;

	int ans = 0;
	bool flag = true;

	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= N - i; j++) {
			int k = N - i - j;
			if (k < 0)
				continue;

			if (i * 10000 + j * 5000 + k * 1000 == Y) {
				cout << i << " " << j << " " << k << endl;
				flag = false;
				break;
			}
		}
		if (!flag)
			break;
	}

	if (flag)
		cout << "-1 -1 -1" << endl;

	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {
	static Scanner sc;
	static PrintWriter out;
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		String s = sc.nextLine();
		int l = s.length();
		String s1 = s.substring(0,(l-1)/2);
		String s2 = s.substring((l+3)/2-1,l);
		boolean f = isPalindrome(s) && isPalindrome(s1) && isPalindrome(s2);
		if(f)
			out.println("Yes");
		else
			out.println("No");
		
		out.flush();
	} 
	static boolean isPalindrome(String s) {
		int l = s.length();
		char[] sa = s.toCharArray();
		for(int i=0;i<l/2;i++) {
			if(sa[i] != sa[l-i-1])
				return false;
		}
		return true;
	}
	static class Scanner{
		private BufferedReader br;
		private StringTokenizer st;
		public Scanner(InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}
		public String next() throws IOException{
			while(st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
		public int nextInt() throws IOException{
			return Integer.parseInt(next());
		}
		public long nextLong() throws IOException{
			return Long.parseLong(next());
		}
		public double nextDouble() throws IOException{
			return Double.parseDouble(next());
		}
		public int[] inArr(int n) throws Exception{
			int a [] = new int[n];
			st = new StringTokenizer(br.readLine());
			for(int i=0;i<n;i++) {
				a[i] = Integer.parseInt(st.nextToken());
			}
			return a;
		}
	}
}

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

int main() {
  int H,W;
  cin >> H >> W;
  
  vector<vector<char>> data(H+2,vector<char>(W+2,'#'));
  
  for(int i=1;i<H+1;i++){
    for(int j=1;j<W+1;j++){
      cin >> data.at(i).at(j);
    }
  }
  
  for(int i=0;i<H+2;i++){
    for(int j=0;j<W+2;j++){
      cout << data.at(i).at(j);
      if(j == W+1){
        cout << endl;
      }
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int N;
int K;
int a[64][64];
int bx[64];
int by[64];
bool used[64][64];
int rest;
bool dfs(int k, int sum, int sx, int sy){
  //printf("dfs : k = %d sum = %d sx = %d sy = %d\n", k, sum, sx, sy);
  if(k == K){
    return rest == 0;
  }
  REP(r, 4){
    int nx = sx + dx[r];
    int ny = sy + dy[r];
    if(valid(nx, ny, N, N) && !used[ny][nx] && a[ny][nx] > 0){
      used[ny][nx] = true;
      rest--;
      if(sum - a[ny][nx] < 0){
      }else if(sum - a[ny][nx] == 0){
        if(k + 1 == K) {
          if(dfs(k + 1, 0, 0, 0)) return true;
        }else{
          if(dfs(k + 1, -a[by[k + 1]][bx[k + 1]], bx[k + 1], by[k + 1])) return true;
        }
      }else if(sum - a[ny][nx] > 0){
        if(dfs(k, sum - a[ny][nx], nx, ny)) return true;
      }
      used[ny][nx] = false;
      rest++;
    }
  }
  return false;
}
int main(){
  while(cin>>N && N){
    REP(i, N)REP(j, N) cin>>a[i][j];
    K = 0;
    REP(i, N)REP(j, N)if(a[i][j] < 0){
      by[K] = i;
      bx[K] = j;
      K++;
    }
    memset(used, 0, sizeof(used));
    rest = N * N - K;
    bool ans = dfs(0, -a[by[0]][bx[0]], bx[0], by[0]);
    if(ans) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	string a,b;
	cin>>a>>b;
	a+=a;
	bool s=false;
	for(int d=0;d<a.length()/2;d++){
		for(int c=0;c<b.length();c++){
			if(a[d+c]!=b[c])break;
			if(b.length()-1==c)s=true;
			}
		}
		if(s)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
}

Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define MOD 1000000007
ll check(ll x,ll l,ll r)
{
	if(x>=l && x<=r)
	{
		return 1;
	}
	else
	return 0;
}
ll mod(ll x,ll h)
{
	return (x+h)%h;
}
int main()
{
ll n;
cin>>n;
ll a[n],b[n];
for(ll i=0;i<n;i++)
{
	cin>>a[i];
	b[i]=a[i];
}
ll ans[n+1]={0};
sort(a,a+n);
vector <ll> len;
for(ll i=0;i<n;i++)
{
  ll start=a[i],count=0,prev=i;
  while(a[i]==start)
  {
  	count++;  	
  	i++;
  }
  if(a[i]!=start)
  i--;
  ans[start]=count;
  len.push_back(count);
}
ll answer=0,siz=len.size(),s=0;
for(ll i=0;i<siz;i++)
{
	ll s1 =0;
	//cout<<len[i]<<endl;
s1= (len[i]*(len[i]-1));
s=s+ (s1/2);
}
//cout<<s<<endl;
for(ll i=0;i<n;i++)
{
	cout<<(s-ans[b[i]]+1)<<endl;
}
}


Measured memory_bytes: 7412
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = Integer.parseInt(scan.nextLine());
		int A[] = new int[N];
		int max_1 = 0, max_2 = 0;
		int kai;
		
		for(int i = 0; i < N; i++) {
			A[i] = Integer.parseInt(scan.nextLine());
			if (max_1 < A[i] && max_2 < A[i]) {
				max_2 = max_1;
				max_1 = A[i];
				
			} else if (max_2 < A[i]) {
				max_2 = A[i];
			}
		}
		
		for (int i = 0; i < N; i++ ) {
			kai = max_1;
			if (max_1 == A[i]) {
				kai = max_2;
			}
			System.out.println(kai);
		}
				 
		scan.close();
	}

}


Measured memory_bytes: 154012
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define REP(i, n) for (LL i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (LL i = m; i n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()
#define int long long
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
signed main() {
  int n;
  cin >> n;
  vector<int> a(200010);
  vector<int> ans(200010);
  REP(i,200010){
    a[i] = 0;
    ans[i] = 0;
  }
  for(int i=2;i<=n;i++)cin >> a[i];
  for(int i=2;i<=n;i++)ans[a[i]]++;
  for(int i=1;i<=n;i++)cout <<ans[i]<<endl;
  
}


Measured memory_bytes: 6384
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <limits>
#include <string>
#include <vector>

using namespace std;

const long long INF = 1LL << 60;

//各桁の和を出力
long long Sum(long long n) {
  long long m = 0;
  while (n) {
    m += n % 10;
    n /= 10;
  }
  return m;
}

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void Comuse() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

#define comuse Comuse()
// nCk(comuseを使え)
long long combi(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// pCk(comuseを使え)
long long perm(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] % MOD) % MOD;
}

//最小公倍数(aとbの)
long long lcm(long long a, long long b) {
  long long n;
  n = a / __gcd(a, b) * b;
  return n;
}

// auto A = div(n)
vector<long long> div(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) {
        ret.push_back(n / i);
      }
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}

//(aのn乗をmodで割ったあまり)
long long modpow(long long a, long long n, long long mod) {
  long long ans = 1;
  while (n > 0) {
    if (n & 1) {
      ans = ans * a % mod;
    }

    a = a * a % mod;

    n >>= 1;
  }

  return ans;
}

void solve();

const int MAX_N = 131072;
// segment tree
int NN;
int seg[MAX_N * 2 - 1];
void seguse() {
  for (int i = 0; i < 2 * NN - 1; i++) {
    seg[i] = INT_MAX;
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << fixed;
  solve();
}

///////////////////////////////////////////////////////////

int N;
string S;

void solve() {
  cin >> N >> S;
  bool A;
  bool B;
  int ans = 0;
  for(int i = 0; i < N; i++){
    if(S[i] == 'A'){
      A = true;
      B = false;
      continue;
    } else if(S[i] == 'B' && A){
      A = false;
      B = true;
      continue;
    } else if(S[i] == 'C' && B){
      ans++;
    }
    A = false;
    B = false;
  }
  cout << ans <<endl;
}

Measured memory_bytes: 256
_,*a=map(str.split,open(0))
U,R,D,L=S="URDL"
d={i:[]for i in S}
for *z,u in a:d[u]+=[*map(int,z)],
N,P,M=9e9,"x+y,","x-y,"
for A,B,S in(U,D,"x,y,"),(R,L,"y,x,"),(R,U,P+M),(D,L,P+M),(U,L,M+P),(R,D,M+P):
 n=p=-9e9
 for x,y,r in sorted(eval(f"[({S}Q)for P,Q in[(A,1),(B,0)]for x,y in d[P]]")):
  if r:n,p=x,y
  elif x==n:N=min(N,(y-p)*5)
print(["SAFE",N][N<9e9])

Measured memory_bytes: 131244
#include <iostream>
#include <vector>
using namespace std;
int main(void){
   int N;
   cin >> N;
   vector<int> a(N);
   int count = 0;
   for(int i = 0;i < N;i++){
       cin >> a[i];
       if(i + 1 != a[i]){
           count++;
       }
   }
   if(count >= 3){
       cout << "NO" << endl;
   }else{
       cout << "YES" << endl;
   }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define f(i,x,n) for(int i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
const int MOD = 1e9 + 7, N = 1e6 + 10;
const int LINF = LLONG_MAX;
int maps[N];
int mapa[N];
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int>q(n);
    f(i,0,n){
        cin >> q[i];
        maps[q[i]]++;
    }    
    sort(all(q));
    int ans = 0;
    f(I,0,n){
        if(maps[q[I]] > 1){
            mapa[q[I]] = 1;
            continue;
        }
        int r = q[I];
        int c = 1;
        for (int i=1; i<=sqrt(r); i++){   
            if (r%i==0) { 
                if(mapa[r/i] == 1 or mapa[i] == 1){
                    c = 0;
                }
            } 
        } 
        if(c == 1){
           ans++;
        }
        mapa[q[I]] = 1;
    }
    cout << ans << "\n";
    return 0;
}
 

Measured memory_bytes: 20332
#include <bits/stdc++.h>
#define nl "\n"
#define ll long long int
#define MOD 1000000007
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,c;
    cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    cout<<a<<" "<<b<<" "<<c<<nl;

}


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

#define ll long long

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

	long long x, k, d;
	cin >> x >> k >> d;
	if (x < 0) x = abs(x);
	long long y = x / d;
	x -= min(y, k) * d;
	k -= min(y, k);
	if (k % 2 == 0) {
		cout << abs(x);
	}
	else {
		cout << abs(x - d);
	}
	

	return 0;
}

Measured memory_bytes: 3556
//Abhinav ---IIIT_A
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define f(i,x,n) for(int i=x;i<(int)n;++i)
#define vpii vector<pair<int,int>>
#define vi vector<int>
#define mpii map<pair<int,int>,int>
#define mpivpii map<int,vector<pair<int,int>>>
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define mpi map<int,int>
#define vvi vector<vector<int>>
#define vvvi vector<vvi>
ld pie=3.141592653589;
int mod=1e9+7;

bool Compare(int a, int b)
{
   return a < b;
}
priority_queue<int, vector<int>, function<bool(int, int)>> pq(Compare);

vi pr;
void seive(){
	int p[100005]={0};
	f(i,2,100005){
		if(p[i]==0){
			pr.pb(i);
			for(int j=i*2;j<100005;j+=i) p[j]=1;
		}
	}
}

// https://codeforces.com/blog/entry/79048



void solve(){
	string s; cin>>s;
	int t=0;
	for(auto it : s) t+=it-'0';
	if(t%9==0) cout<<"Yes";
	else cout<<"No";
}


int32_t main(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);
  int t=1; //cin>>t;
  while(t--) solve();
  return 0;
}
// check for overflows dummy !!!

Measured memory_bytes: 3772
import java.util.*;
import java.lang.Math;
import static java.lang.System.in;
import static java.lang.System.out;

public class Main{
    public static void main(String[] args){
	Scanner sc=new Scanner(in);
	String s=sc.next();
	String result="";
	for(int i=0;i<s.length();i++)
	    switch(s.substring(i,i+1)){
	    case "0":
		result+="0";
		break;
	    case "1":
		result+="1";
		break;
	    case "B":
        if(result.length()!=0)
		result=result.substring(0,result.length()-1);
		break;
	    }
	out.println(result);
    }
}


Measured memory_bytes: 21716
n, m = list(map(int, input().split()))

s = [0]*(m+1)
c = [0]*(m+1)

for k in range(m):
    s[k], c[k] = list(map(int, input().split()))

for l in range(m):
    if n == 1:
        if s[l] != 1:
            print(-1)
            exit()
    elif n == 2:
        if s[l] == 3 or (s[l] == 1 and c[l] == 0):
            print(-1)
            exit()
    elif n == 3:
        if s[l] == 1 and c[l] == 0:
            print(-1)
            exit()

if n == 1:
    for num in range(0, 10):
        seigo = 1
        for i in range(m):
            if num != c[i]:
                seigo = 0
        if seigo == 1:
            print(num)
            exit()
    print(-1)
    exit()
elif n == 2:
    for num in range(10, 100):
        seigo = 1
        for i in range(m):
            if s[i] == 1:
                if num//10 != c[i]:
                    seigo = 0
            if s[i] == 2:
                if num%10 != c[i]:
                    seigo = 0
        if seigo == 1:
            print(num)
            exit()
    print(-1)
    exit()
else:
    for num in range(100, 1000):
        seigo = 1
        for i in range(m):
            if s[i] == 1:
                if num//100 != c[i]:
                    seigo = 0
            elif s[i] == 2:
                if (num-100*(num//100))//10 != c[i]:
                    seigo = 0
            elif s[i] == 3:
                if num%10 != c[i]:
                    seigo = 0
        if seigo == 1:
            print(num)
            exit()
    print(-1)
    exit()


Measured memory_bytes: 3188
n=int(input())
t,x,y=map(int,input().split())
if t<x+y or (t-x-y)%2!=0:
    print("No")
    exit()
tmp_t=t
tmp_x=x
tmp_y=y
for i in range(n-1):
    t,x,y=map(int,input().split())
    if t-tmp_t<abs(tmp_x-x)+abs(tmp_y-y) or (t-tmp_t-abs(tmp_x-x)-abs(tmp_y-y))%2!=0:
        print("No")
        exit()
    else:
        tmp_t=t
        tmp_x=x
        tmp_y=y
else:
    print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const ll mod=1000000007;
int main(void){
    int k;
    string s;
    cin>>k>>s;
    int n=s.size();
    if(n<=k) cout<<s<<endl;
    else{
        for(int i=0;i<k;i++){
            cout<<s[i];
        }
        cout<<"..."<<endl;
    }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    vector<vector<int>> dist(h, vector<int>(w));
    rep(i, h) rep(j, w) dist[i][j] = -1;
    dist[0][0] = 0;
    queue<P> q;
    q.emplace(0, 0);
    while (!q.empty()) {
        P now = q.front();
        q.pop();
        int x = now.first;
        int y = now.second;
        int d = dist[x][y];
        rep(i, 4) {
            int ix = x + dx[i];
            int iy = y + dy[i];
            if (ix<0 || ix>=h || iy<0 || iy>=w) continue;
            if (s[ix][iy]=='#') continue;
            if (dist[ix][iy] != -1) continue;
            dist[ix][iy] = d + 1;
            q.emplace(ix, iy);
        }
    }
    
    int num = 0;
    rep(i, h) rep(j, w) {
        if (s[i][j]=='.') num++;
    }
    if (dist[h-1][w-1]==-1) {
        cout << "-1" << endl;
        return 0;
    }
    int ans = num - (dist[h-1][w-1]+1);
    
    cout << ans << endl;
    return 0;
}


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

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

    string A = to_string(A_);
    string B = to_string(B_);

    string A_cycle = "";
    A_cycle += A[0];
    A_cycle += A[1];
    A_cycle += A[2];
    A_cycle += A[1];
    A_cycle += A[0];
    int A_cycle_int = stoi(A_cycle);

    string B_cycle = "";
    B_cycle += B[0];
    B_cycle += B[1];
    B_cycle += B[2];
    B_cycle += B[1];
    B_cycle += B[0];
    int B_cycle_int = stoi(B_cycle);

    int ans = B_cycle_int / 100 - A_cycle_int / 100;
    if(A_ > A_cycle_int){
        ans -= 1;
    }
    if(B_ >= B_cycle_int){
        ans += 1;
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int n,ans;
void ksm(int a)
{
	int k=1,b=2;
	while(a)
	{
		if (a & 1) k*=b;
		b*=b;
		a>>=1;
	}
	cout<<k<<endl;
	return;
}
int main()
{
	cin>>n;
	while(n)
	{
		n>>=1;
		ans++;
	}
	ksm(ans-1);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;
    vector<int> P(N);
    REP (i, N) cin >> P[i];
    int mx = N + 1;
    int ans = 0;
    REP (i, N) {
        if (P[i] < mx) {
            mx = P[i];
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/



int N;
vector<int> ans[1010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;

    int K = -1;
    rep(k, 2, 1010) if (k * (k - 1) / 2 == N) K = k;
    if (K < 0) {
        printf("No\n");
        return;
    }

    int x = 1;
    rep(a, 0, K) rep(b, a + 1, K) {
        ans[a].push_back(x);
        ans[b].push_back(x);
        x++;
    }

    printf("Yes\n%d\n", K);
    rep(k, 0, K) {
        printf("%d", ans[k].size());
        fore(i, ans[k]) printf(" %d", i);
        printf("\n");
    }
}

Measured memory_bytes: 2304
N, u, v = map(int, input().split())
edges = [[] for _ in range(N)]

for _ in range(N - 1):
    fr, to = map(int, input().split())
    fr -= 1
    to -= 1
    edges[fr].append(to)
    edges[to].append(fr)

def calc(s):
    minDist = [10**18] * N
    st = [(s, 0)]
    while st:
        now, dist = st.pop()

        if minDist[now] < dist:
            continue
        minDist[now] = dist

        for to in edges[now]:
            if minDist[to] > dist + 1:
                st.append((to, dist + 1))
    return minDist

distTaka = calc(u - 1)
distAoki = calc(v - 1)

ans = 0
for i in range(N):
    if distTaka[i] < distAoki[i]:
        ans = max(ans, distAoki[i] - 1)
print(ans)


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

typedef long long   ll;
const ll mod = 1e9 + 7;

#define speedup_IO      ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n)     for(ll i = a; i < n; i++)
#define ford(i,n,a)     for(ll i = n-1; i >= a; i--)
#define pb              push_back
#define lb              lower_bound
#define ub              upper_bound
#define pll             pair<ll,ll>
#define all(a)          (a).begin(),(a).end()
#define reset(a,x)      memset(a,x,sizeof(a))

ll mypow(ll base, ll exp) {ll res = 1; while (exp) {if (exp & 1) res = (res * base) % mod; exp >>= 1, base = (base * base) % mod;} return res;}
ll gcd(ll a, ll b)  { return b ? gcd(b, a % b) : a;            }
ll mult(ll a, ll b) { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b)  { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return (a % mod + b % mod) % mod;        }
ll sub(ll a, ll b)  { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return (a % mod + mod - b % mod) % mod;  }

const ll inf = 1e18;
const int nax = 1e5 + 5;

int main()
{
	speedup_IO;
	ll h,a;
	cin>>h>>a;

	ll ans = (h+a-1)/a;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import re
S = str(input())
T = str(input())
S = S.replace("?",".")

for i in range(len(S)-len(T),-1,-1):
  if re.match(S[i:i+len(T)],T):
    S = S.replace('.','a')
    print(S[:i]+T+S[i+len(T):])
    exit()

print('UNRESTORABLE')

Measured memory_bytes: 3188