akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<queue>

using namespace std;

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

const int N = 7;

int si, sj;
int H, W;
bool visited[N][N];
int im[N][N];
int path[N][N];
int zeroCnt;

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

void checkEnclosed(int ci, int cj, bool vis[][N]) {
	queue<pair<int, int> > q;
	pair<int, int> cur;
	q.push(make_pair(ci, cj));

	while( !q.empty() ){
		cur = q.front();
		q.pop();
		if (vis[cur.first][cur.second])continue;

		vis[cur.first][cur.second] = true;
		for (int k = 0; k < 4; ++k) {
			int ni = cur.first + di[k];
			int nj = cur.second + dj[k];
			if (inside(ni, nj) && im[ni][nj] == 0 && !visited[ni][nj]) {
				q.push(make_pair(ni, nj));
			}
		}
	}
	return;
}

void printVisited(){
	for (int x = 0; x < H; ++x){
		for (int y = 0; y < W; ++y){
			if (im[x][y] == 0){
				if (visited[x][y]){
					cout << "v";// << endl;
				}
				else{
					cout << "-";// << endl;
				}
			}
			else{
				cout << "X";// << endl;
			}
		}
		cout << endl;
	}
	cout << endl;
}

bool dfs(int step, int ci, int cj, int prei, int prej)
{
	static int cnt = 0;
	++cnt;
	if (cnt % 1000000 == 0) {
		//cout << cnt << endl;
	}

	if (visited[ci][cj] ) {
		if( step == zeroCnt && ci == si && cj == sj) {
			return true;
		}
		return false;
	}

	int tcnt = 0;
	for (int k = 0; k < 4; ++k){
		int ni = si + di[k];
		int nj = sj + dj[k];
		if (inside(ni,nj) && im[ni][nj] == 0 && !visited[ni][nj] ) {
			++tcnt;
		}
	}
	if (tcnt == 0) {
		return false;
	}

	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (im[i][j] == 0 && !visited[i][j]) {
				int cnt = 0;
				for (int k = 0; k < 4; ++k){
					int ni = i + di[k];
					int nj = j + dj[k];
					if (ni == si && nj == sj) {
						cnt = 900;
					}
					else if (ni == prei && nj == prej) {
						++cnt;
					}
					else if (inside(ni, nj) && im[ni][nj] == 0 && !visited[ni][nj]) {
						++cnt;
					}
				}
				if ( cnt <= 1 ) {
					return false;
				}
			}
		}
	}

	bool vis[N][N] = { false, };
	checkEnclosed(ci, cj, vis);

	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (im[i][j] == 0 && !vis[i][j] && !visited[i][j]) {
				return false;
			}
		}
	}


	visited[ci][cj] = true;
	path[ci][cj] = step;
	for (int k = 0; k < 4; ++k) {
		int ni = ci + di[k];
		int nj = cj + dj[k];
		if (inside(ni, nj) && im[ni][nj] == 0) {
			if (dfs(step + 1, ni, nj, ci, cj)) {
				return true;
			}
		}
	}
	visited[ci][cj] = false;

	return false;
}

int main()
{
	while (true) {
		cin >> W >> H;
		zeroCnt = 0;
		if (W == 0 && H == 0) {
			break;
		}
		for (int i = 0; i < H; ++i) {
			for (int j = 0; j < W; ++j) {
				cin >> im[i][j];
				visited[i][j] = false;
				if (im[i][j] == 0) {
					si = i;
					sj = j;
					++zeroCnt;
				}
			}
		}
		if (dfs(0, si, sj, -1, -1)) {
			cout << "Yes" << endl;
			//for (int i = 0; i < H; ++i){
			//	for (int j = 0; j < W; ++j){
			//		cout << setw(3) << path[i][j];
			//		//<< ' ';
			//	}
			//	cout << endl;
			//}
		}
		else {
			cout << "No" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  double ans = 0.0;
  for (int i = 1; i <= N; i++) {
	  int now     = i;
	  double prob = 1.0 / N;
	  while (now < K) {
		  now  *= 2;
		  prob /= 2.0;
		}
	  ans += prob;
	}
  cout << setprecision(10) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
int main(){
    int n,u,v; cin >> n >> u >> v; u--; v--;
    vector<vector<int>> g(n);
    rep(i, n-1){
        int a,b; cin >> a >> b; a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<int> dt(n, -1), da(n, -1);
    dt[u] = 0; da[v] = 0;
    queue<int> que;
    que.push(u);
    while(!que.empty()){
        int p = que.front(); que.pop();
        for(int q : g[p]){
            if(dt[q] != -1) continue;
            dt[q] = dt[p] + 1;
            que.push(q);
        }
    }
    que.push(v);
    while(!que.empty()){
        int p = que.front(); que.pop();
        for(int q : g[p]){
            if(da[q] != -1) continue;
            da[q] = da[p] + 1;
            que.push(q);
        }
    }
    int ans = -1;
    rep(i,n){
        if(dt[i] - da[i] > 0) continue;
        ans = max(ans, da[i]-1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 6784
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

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

  int n, m;
  cin >> n >> m;
  vector<vector<int> > edge(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    edge[a-1].push_back(b-1);
    edge[b-1].push_back(a-1);
  }

  vector<int> ans(n);
  vector<bool> visited(n);
  queue<Pii> que;
  que.emplace(0, 0);
  while (!que.empty()) {
    auto now = que.front();
    que.pop();
    if (visited[now.first]) continue;
    visited[now.first] = true;
    ans[now.first] = now.second + 1;
    for (auto &next: edge[now.first]) {
      if (!visited[next]) que.emplace(next, now.first);
    }
  }

  cout << "Yes" << endl;
  for (int i = 1; i < n; i++) cout << ans[i] << endl;

  return 0;
}


Measured memory_bytes: 10968
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<queue>
#include<set>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef string S;
typedef queue<int> qi;
typedef pair<int,int> P;
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mp make_pair
#define fr(i,n)for(ll i=0;i<(n);i++)
#define ifr(i,n)for(ll i=(n)-1;i>=0;i--)

int main(){
  int r,d,x;cin>>r>>d>>x;
  fr(i,10){
    x = r*x-d;
    cout << x << endl;
  }
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, M: int, a: "List[int]", b: "List[int]", c: "List[int]", d: "List[int]"):
    # 全探索で間に合う
    for aa, bb in zip(a, b):
        m, mi = INF, -1
        for i, (cc, dd) in enumerate(zip(c, d)):
            dist = abs(aa-cc)+abs(bb-dd)
            if m > dist:
                m = dist
                mi = i
        print(mi+1)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int()] * (N)  # type: "List[int]"
    b = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    c = [int()] * (M)  # type: "List[int]"
    d = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        c[i] = int(next(tokens))
        d[i] = int(next(tokens))
    solve(N, M, a, b, c, d)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
bool cmp(char a,char b)
{
	return a>b;
}
int main()
{
	string s,t;
	cin>>s>>t;
	sort(s.begin(),s.end());
	sort(t.begin(),t.end(),cmp);
	if(s<t)
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}

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

int main(){
    int n, a, b, c;
    cin >> n >> a >> b >> c;

    vector<string> s(n);
    for(int i=0; i<n; i++){
        cin >> s[i];
    }

    vector<char> ans(n);
    for(int i=0; i<n; i++){
        if(s[i] == "AB"){
                 if(a == 0 && b == 0){ cout << "No" << endl; return 0;}
            else if(a == 0){ a += 1; b -= 1; ans[i] = 'A';}
            else if(b == 0){ a -= 1; b += 1; ans[i] = 'B';}
            else if(a == 1 && b == 1 && c == 0 && i+1<n && s[i] != s[i+1]){
                 if(s[i+1] == "AC"){ a += 1; b -= 1; ans[i] = 'A';}
                 if(s[i+1] == "BC"){ a -= 1; b += 1; ans[i] = 'B';}
            }
            else{
                if(a < b){ a += 1; b -= 1; ans[i] = 'A';}
                else{      a -= 1; b += 1; ans[i] = 'B';}
            }
        }
        if(s[i] == "AC"){
                 if(a == 0 && c == 0){ cout << "No" << endl; return 0;}
            else if(a == 0){ a += 1; c -= 1; ans[i] = 'A';}
            else if(c == 0){ a -= 1; c += 1; ans[i] = 'C';}
            else if(a == 1 && b == 0 && c == 1 && i+1<n && s[i] != s[i+1]){
                 if(s[i+1] == "AB"){ a += 1; c -= 1; ans[i] = 'A';}
                 if(s[i+1] == "BC"){ a -= 1; c += 1; ans[i] = 'C';}
            }
            else{
                if(a < c){ a += 1; c -= 1; ans[i] = 'A';}
                else{      a -= 1; c += 1; ans[i] = 'C';}
            }
        }
        if(s[i] == "BC"){
                 if(b == 0 && c == 0){ cout << "No" << endl; return 0;}
            else if(b == 0){ b += 1; c -= 1; ans[i] = 'B';}
            else if(c == 0){ b -= 1; c += 1; ans[i] = 'C';}
            else if(a == 0 && b == 1 && c == 1 && i+1<n && s[i] != s[i+1]){
                 if(s[i+1] == "AB"){ b += 1; c -= 1; ans[i] = 'B';}
                 if(s[i+1] == "AC"){ b -= 1; c += 1; ans[i] = 'C';}
            }
            else{
                if(b < c){ b += 1; c -= 1; ans[i] = 'B';}
                else{      b -= 1; c += 1; ans[i] = 'C';}
            }
        }
    }

    cout << "Yes" << endl;
    for(int i=0; i<n; i++) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 6404
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long i,j,t,a,b,n,temp;
    t=1;
    // cin>>t;
    while(t--)
    {
        long arr[252525],ans[565656]={0};
        cin>>n;
        for(i=0;i<n;i++)
            cin>>arr[i];  
        long li=252525,ri;
        ri=li+1;
        for(i=0;i<n;i++)
        {
            if(i%2==(n-1)%2)
            {
                ans[li--]=arr[i];
            }
            else ans[ri++]=arr[i];
        }
        for(i=li+1;i<ri;i++)
            cout<<ans[i]<<" ";
    }
}

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

using namespace std;

bool N,S,W,E;
int main()
{
  string s;
  cin >> s;
  char ch[200];
  for(int i = 0; i < s.size(); i++){
    if(s[i] == 'W')
        W = true;
    else if(s[i] == 'E')
        E = true;
    else if(s[i] == 'N')
        N = true;
    else
        S = true;
  }
  if(N != S)
    cout << "No" << endl;
  else if(W != E)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
}


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

#define st              first
#define nd              second
#define pb              push_back
#define lwb             lower_bound
#define upb             upper_bound
#define all(a)          (a).begin(), (a).end()
#define Reset(s, n)     memset(s, n, sizeof(s))
#define Sz(a)           int((a).size())
#define Max(a, b, c)    max(max((ll)(a), (ll)(b)), (ll)(c))
#define Min(a, b, c)    min(min((ll)(a), (ll)(b)), (ll)(c))
#define Unique(a)       (a).resize(unique(all(a)) - (a).begin())
#define bit(n, i)       (((n) >> (i)) & 1)
#define cntbit(n)       __builtin_popcountll(n)

using namespace std;

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

const int MOD = 1e9 + 7;
const ll INF = 1e9;
const ld PI = acos((ld) -1);
const ld EPS = 1e-12;
inline bool isPrime (ll x){ if(x <= 1) return 0; if(x <= 3) return 1; if (!(x % 2) || !(x % 3)) return 0; ll s = sqrt(1.0 * x) + EPS; for(ll i = 5; i <= s; i += 6){if (!(x % i) || !(x % (i + 2))) return 0;}return 1;}
inline ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
inline int inv(int a, ll p = MOD) {return fpow(a, p - 2, p);}
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline void onbit(ll &a, int i){a |= 1LL << i;}
inline void offbit(ll &a, int i){onbit(a, i), a -= (1LL << i);}

const int N = 2e5 + 5;

int n, m, k;


void solve(){
   cin >> n;
   std::vector<int> v(n + 1, 0);
   for(int i = 1; i < n; i++){
    int x;
    cin >> x;
    v[x]++;
   }
   for(int i = 1; i <= n; i++) cout << v[i] << "\n";
}

int main(){
   ios_base::sync_with_stdio(0);
   cin.tie(0); cout.tie(0);
   cout << fixed << setprecision(10);
   //    freopen("input.txt", "r", stdin);
   //    freopen("output.txt", "w", stdout);
   int query = 1;
   // cin >> query;
   int start = 1000 * clock() / CLOCKS_PER_SEC;
   while(query--) solve();
   cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC  - start << "ms\n";
}


Measured memory_bytes: 4052
/*
Problem

Category
全探索・全列挙

URL
https://atcoder.jp/contests/abc122/tasks/abc122_b

Date: 2020/03/25
*/

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

/* ==== declarations ====== */
// functions
void solve();

// global variables
string S;

/* ======================== */


void solve() {
    int cnt = 0;
    int maxCnt = 0;
    for (auto c: S){
        bool flg = false;
        for (char cc: {'A', 'C', 'G', 'T'}) {
            if (cc == c) flg = true;
        }
        if (flg) cnt++;
        else cnt=0;
        maxCnt = max(cnt, maxCnt);
    }
    cout<<maxCnt<<endl;
}

int main() {
    cin>>S;
    solve();
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define ALL(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8
#define N 200000
bool sx[N+1], xe[N+1];
int n, m, a, b;
int main() {
    cin >> n >> m;
    rep(i, m) {
        cin >> a >> b;
        if (a == 1) {
            sx[b] = true;
        } else if (b == n) {
            xe[a] = true;
        }
    }
    string ans = "IMPOSSIBLE";
    rep(i, n) {
        if (sx[i] && xe[i]) {
            ans = "POSSIBLE";
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>

using namespace std;

int main(){
  int N;
  cin >> N;
  long long A[N];
  int i;
  long long min = 1000000000;
  long long max = 0;
  for(i = 0;i< N;i++){
    cin >> A[i] ;
    if(min > A[i]) min = A[i];
    if(max < A[i]) max = A[i];
  }

  cout << max-min << endl;
  return 0;
}


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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void ans(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

int main(){
  ll i,j,o;
  ll res=0,res1=INF,res2=-INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0,sum=0;
  ll l,r;
  bool judge = true;
  ll n,x;cin>>n>>x;
  vector<ll>a(n);
  for(i=0;i<n;i++)cin>>a[i];
  res=1;buf=0;
  for(i=0;i<n;i++){
    buf+=a[i];
    if(buf<=x)res++;
  }
  cout<<res<<endl;


  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define endl 		"\n"
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define fast_io     std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define trace(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1) {std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " : " << arg1;
	ZZ(comma, args...);
}

void solve() {
	ll n, d;
	cin >> n >> d;
	int cnt = 0;
	rep(i, 0, n) {
		ll x, y;
		cin >> x >> y;
		if ((x * x + y * y) <= d * d)cnt++;
	}
	cout << cnt;

}
int main() {
	fast_io;
	int t = 1;
	// cin>>t;
	while (t--) {
		solve();
	}
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 3660
#include<iostream>
#define MAX 1000001
#include<vector>
#include<set>
using namespace std;
int main(){
	int n,a,b;
	while(cin>>n>>a>>b,n){
		int ans=0;
		vector<int> tab(MAX);tab[0]=1;
		for(int i=min(a,b);i<=n;i++){
			if(i-a>=0&&tab[i-a]){
				tab[i]=1;
				ans++;
			}else if(i-b>=0&&tab[i-b]){
				tab[i]=1;
				ans++;
			}
		}
		cout<<n-ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
using System;

class Program
{
    static void Main(string[] args)
    {
        int i, j, k;

        int n = int.Parse(Console.ReadLine());

        int[] result = new int[10000];
        int eqans;

        for(i = 1; i <= 99; i++)
        {
            for(j = 1; j <= 99; j++)
            {
                for(k = 1; k <= 99; k++)
                {
                    eqans = i * i + j * j + k * k + i * j + i * k + k * j;
                    if(eqans <= n)
                    {
                        result[eqans - 1]++;
                    }
                }
            }
        }

        for(i = 0; i < n; i++)
        {
            Console.WriteLine(result[i]);
        }

        return;
    }
}

Measured memory_bytes: 27316
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H,K;
	string s;
	while(cin>>N>>K) {
		VI A(N);
		REP(i, N) cin>>A[i];
		ll ans=0;
		REP(i, N) ans+=2*min(A[i], K-A[i]);
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>

using namespace std;
using llong = long long;
int main(){

  map<char,llong> alpha;
  string str;
  cin >> str;
  for(int i=0;i<str.length();++i){
    alpha[str[i]]++;
  }

  llong pat=str.length()*(str.length()-1)/2+1;
  for(const auto &a:alpha){
    // cout << a.first << " " << a.second << endl;
    pat -= (a.second-1)*a.second/2;
  }

  cout << pat << endl;

  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  string S;
  cin>>N>>S;
  int count=0;
  for(int i=0;i<N-2;i++){
    if(S.at(i)=='A'){
      if(S.at(i+1)=='B'&&S.at(i+2)=='C'){
        count=count+1;
      }
    }
  }
  cout<<count<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int isprime(int n)
{
	for(int i = 2; i * i <= n; i++)
	{
		if(n % i == 0)
		{
			return 0;
		}
	}
	return 1;
}

int main()
{
	int p1[10000];
	int q1[10000];
	int n, i, cnt = 0;

	while(1)
	{
		scanf ("%d",&n);
		for(i=n; i!=0; i--)
		{
			if(isprime(i) == 1 && isprime(i-2) == 1)
			{
				p1[cnt] = i;
				q1[cnt] = i-2;
				break;
			}
		}
		if(n==0)
		{
			break;
		}
		cnt++;
	}
	for(i=0; i<cnt; i++)
	{
		printf("%d %d\n",q1[i],p1[i]);
	}
	return 0;
}

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

using namespace std;

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

	char ch;

	cin >> ch;

	if(ch>='a' && ch<='z')
	{
		cout << 'a' << '\n';
	}
	else
	{
		cout << 'A' << '\n';
	}

	return 0;
}	

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
  long d,t,s;
  cin >> d >> t >> s;
  if(d > t*s) NO;
  else YES; 
}

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


int main() {
  int N;
  cin >> N;
  
  vector<char> s(N);
  for (int i=0; i<N; i++) {
    cin >> s.at(i);
  }
  
  int p, w, g, y=0;
  for (auto x : s) {
    if (x=='P') p=1;
    else if (x=='W') w=1;
    else if (x=='G') g=1;
    else if (x=='Y') y=1;
  }
  
  if(p+w+g+y==4) cout << "Four" << endl;
  else cout << "Three" << endl;

  return 0;
}


Measured memory_bytes: 3592
S = input()
T = input()
dict1 = {}
dict2 = {}

for s,t in zip(S,T):
    if s in dict1:
        if dict1[s] == t:
            pass
        else:
            print('No')
            exit()
    else:
        dict1[s] = t
    if t in dict2:
        if dict2[t] == s:
            pass
        else:
            print('No')
            exit()
    else:
        dict2[t] = s
print('Yes')


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

using namespace std;

int main()
{
    int k,n,i;
    cin >> k>> n;
    int arr[n],x;
    for(i=0;i<n;i++){
        cin >> arr[i];
    }
    x=k-arr[n-1]+arr[0];
    for(i=1;i<n;i++){
        if((arr[i]-arr[i-1])>x)
        x=arr[i]-arr[i-1];
    }
    
    cout<<(k-x);

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    int N, X, Y; cin >> N >> X >> Y;
    vector<vector<int>> G(N);

    vector<vector<ll>> d(N);
    repp(i,0,N) {
        vector<ll> v(N, 1000000000);
        d[i] = v;
    }

    repp(i,0,N-1) {
        G[i].push_back(i+1);
        G[i+1].push_back(i);
        //d[i+1][i] = d[i][i+1] = 1; 
    }
    G[X-1].push_back(Y-1);
    G[Y-1].push_back(X-1);
    //d[X-1][Y-1] = d[Y-1][X-1] = 1;
    --X, --Y;
    repp(i,0,N) {
        repp(j,i+1,N) {
            if (i <= X) {
                if (j <= X) {
                    d[i][j] = d[j][i] = j - i;
                } else if (j <= Y) {
                    d[i][j] = d[j][i] = min(j - i, X-i+1+Y-j);
                } else {
                    d[i][j] = d[j][i] = X-i + 1 + j-Y;
                }
            } else if ( i <= Y ) {
                if (j <= Y) {
                    d[i][j] = d[j][i] = min(j - i, i-X + 1 + Y-j);
                } else {
                    d[i][j] = d[j][i] = min(j - i, i-X + 1 + j-Y);
                }
            } else {
                d[i][j] = d[j][i] = j - i;
            }
        }
    }
    map<long long, long long> res;

    repp(i,0,N) {
        repp(j,i+1,N) {
            ++res[d[j][i]];
        }
    }
    repp(i,1,N) cout << res[i] << endl;
}


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

using namespace std;

int main()
{
    string s;
    int k;
    cin >> s >> k;
    long long dp[s.size() + 1][k + 1][10];
    for(int i = 0; i <= s.size(); i++)
    {
        for(int j = 0; j <= k; j++)
        {
            for(int d = 0; d < 10; d++)
            {
                dp[i][j][d] = 0;
            }
        }
    }
    dp[1][0][0] = 1;
    for(int i = 1; i <= 9; i++)
    {
        dp[1][1][i] = 1;
    }
    for(int i = 2; i <= s.size(); i++)
    {
        for(int j = 0; j <= k; j++)
        {
            for(int d = 0; d < 10; d++)
            {
                if(d != 0)
                {
                    if(j == 0)
                        break;
                    for(int t = 0; t < 10; t++)
                    {
                        if(j > 0)
                        {
                            dp[i][j][d] += dp[i - 1][j - 1][t];
                        }
                    }
                }
                else
                {
                    for(int t = 0; t < 10; t++)
                    {
                        dp[i][j][d] += dp[i - 1][j][t];
                    }
                }
            }
        }
    }
    long long ans = 0, not_zero = 0;
    for(int i = 0; i <= s.size(); i++)
    {
        if(i > 0 && s[i - 1] != '0')
        {
            not_zero++;
        }
        if(k - not_zero >= 0)
        {
            for(int j = 0; j < s[i] - '0'; j++)
            {
                ans += dp[s.size() - i][k - not_zero][j];
            }
        }
    }
    if(not_zero == k)
        ans++;
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
my $s = <STDIN>;
my @s = split(/ /,$s);

my $max;

$max = $s[0] + $s[1];
if( $max < ($s[0] - $s[1])){
  $max = $s[0] - $s[1];
}
if( $max < ($s[0] * $s[1])){
  $max = $s[0] * $s[1];
}


print "$max\n";

Measured memory_bytes: 512
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;

ll count(vector<ll> a, ll n, ll k) {
    ll res = 0;
    for (ll i = 0; i < n; ++i) {
        auto iter = lower_bound(a.begin(), a.end(), k - a[i]);
        res += n - (iter - a.begin());
    }
    return res;
}

int main() {
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n,0);
    for (ll i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    vector<ll> s(n+1, 0); // 累積和
    for (ll i = 0; i < n; ++i) {
        s[i+1] = s[i] + a[n - 1 - i];
    }

    ll k = 0;
    for (ll mi = 40; mi >= 0; --mi) {
        if (count(a, n, k+(1LL<<mi)) >= m) {
            k += 1LL <<mi;
        }
    }

    ll sum = 0;
    ll p = 0;
    for (ll i = 0; i < n; ++i) {
        auto iter = lower_bound(a.begin(), a.end(), k - a[i]);
        auto idx = n - (iter - a.begin());
        sum += a[i] *idx + s[idx];
        p += idx;
    }

    sum -= k * (p-m);

    cout << sum << endl;
}


Measured memory_bytes: 2572
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstdlib>
#include <cmath>
#include <string.h>
#include <memory.h>
#include <algorithm>
#include <iomanip>
#include <string>
#include <bitset>

#define F first
#define S second
#define MP make_pair

typedef long long ll;

using namespace std;

int const PI = acos(-1);
int dx[] = { 0, 1, 0, -1 };
int dy[] = { 1, 0, -1, 0 };

long long gcd(long long a, long long b) {
	return b == 0 ? a : gcd(b, a % b);
}

long long lcm(long long a, long long b) {
	return a * (b / gcd(a, b));
}

vector<unsigned long long> a;

int main() {
	unsigned long long n, t;
	scanf("%llu%llu", &n, &t);
	a.resize(n);
	for(int i = 0; i < n; ++i)
	  scanf("%llu", &a[i]);
	
	unsigned long long res = t;
	for(int i = 1; i < n; ++i) {
	  if(a[i] - a[i-1] <= t)
      res += (a[i] - a[i-1]);
    else
      res += t;
	}
	
	printf("%llu\n", res);

  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,X=0;
  cin >> A >> B >> C;
  if(C > B && A+B < C){
   cout << A+B+B+1 << endl;
    return 0;
  }
 cout << B+C << endl;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define mem(a, b) memset(a, (b), sizeof(a))
#define fore(i,a) for(int i=0;i<a;i++)
#define fore1(i,j,a) for(int i=j;i<a;i++)
#define print(ar) for(int i=0;i<ar.size();i++)cout<<ar[i]<<" ";
#define END cout<<'\n'
const double pi=acos(-1.0);
 
typedef pair<int, int> PII;
 
typedef vector<long long int> VI;
 
typedef vector<string> VS;
 
typedef vector<PII> VII;
 
typedef vector<VI> VVI;
 
typedef map<int,int> MPII;
 
typedef set<int> SETI;
 
typedef multiset<int> MSETI;
 
typedef long int li;
 
typedef unsigned long int uli;
 
typedef long long int ll;
 
typedef unsigned long long int  ull;
const ll N = 1e4;



ll fastexp (ll a, ll b, ll n) {
  ll res = 1;
  while (b) {
      if (b & 1) res = res*a%n;
      a = a*a%n;
      b >>= 1;
  }
  return res;
}
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int diff(string a,string b){
    int dc=0;
    fore(i,a.length()){
        if(a[i]!=b[i])dc++;
    }
    return dc;
}

int n,k;
ll dp[50][50][3000];
int a[50];
ll solve(ll index,ll total,ll sum)
{
    if(index==n)
    {
        if(total!=0 && sum%total==0)
        {
            if(sum/total==k)  return 1;
            else return 0;
        }
        else   return 0;
    }
    ll ans = dp[index][total][sum];
    if(ans!=-1)   return ans;
    ans = 0;
    ans += solve(index+1,total+1,sum+a[index]);
    ans += solve(index+1,total,sum);
    return dp[index][total][sum] = ans;
}
int main() 
{
    fast();
    cin >> n >> k;
    fore(i,n)cin >> a[i];
    mem(dp,-1);
    ll ans = solve(0,0,0);
    cout<<ans;
    
}    

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

int solve(int x) {
	int count = 0;
	while (x >= 10) {
		int ma = 0;
		for (int s = 10; x / s > 0; s *= 10) {
			int d = x / s;
			int m = x % s;
			ma = max(ma, d * m);
		}
		x = ma;
		count++;
	}
	return count;
}

int main () {
	int n;
	for (cin >> n; n; n--) {
		int x;
		cin >> x;
		cout << solve(x) << endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
ll cnt = 0;

 ll gcd( ll x, ll y){
   return y ? gcd( y , x%y ) : x;
}
 ll lcm(ll x ,ll y ){/*gcdの呼び出し忘れない*/
    return (x / gcd( x , y ) )*y ;
}  
 ll nlcm(vector<ll> numbers){/*lcm呼ぶのを忘れない*/
 ll res;  res = numbers[0];
for(int i=0;i<numbers.size() ; i++){
   res = lcm( res , numbers[i] );
}
  return res;
}

int main(){
  ll n;  cin >> n;
  
  vector<ll>a(n);  
  rep(i,n){
     cin >> a[i];
   }
   cout << nlcm(a) << endl;

}

Measured memory_bytes: 256
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>
#include <climits>
#include <iomanip>

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

const long double PI = 3.141592653589793236L;

typedef long long int ll;
typedef long double ld;

using namespace std;

void solve()
{
	// Your code goes here.
	int n, r;
	cin>>r>>n;
	vector<int>v(n);
	set<int>s;

	for (int i=0; i<n; i++)
    {
        cin>>v[i];
        s.insert(v[i]);
    }
    if (n==0 || s.find(r)==s.end() )
    {
        cout<<r<<endl;
        return;
    }
    int i=1, check, nextt, g;
    check = r;
    while (i<=1000)
    {
        nextt=(pow((-1), i));
        g=nextt*i;
        check=(check+g);

        if (s.find(check)==s.end())
        {
            cout<<check<<endl;
            return;
        }else
        {
            //cout<<i<<endl;
            //cout<<check<<endl;
            i++;

        }
    }

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int T = 1;
    //cin >> T; // If only one test case then you can comment this line out.

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

    return 0;
}


Measured memory_bytes: 3916
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

int main() {
  ll A, B, C;
  cin >> A >> B >> C;
  vec<ll> v{A, B, C};
  if (any_of(ALL(v), [](ll u) { return (u & 1) == 0; })) {
    cout << 0 << endl;
    return 0;
  }
  sort(ALL(v));
  cout << v[0] * v[1] << endl;
  return 0;
}


Measured memory_bytes: 3584
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main(){
  ll r,D,x;
  cin>>r>>D>>x;
  rep(i,0,10){
    x = r*x-D;
    cout << x << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>


int main(void)
{
	int n, a;

	while(scanf("%d", &n)==1)
	{
		int ans=0;
		for(int i=0;i<n;i++)
		{
			scanf("%d", &a);
			for(;a>0 && a%2==0;a/=2)
			{
				ans++;
			}
		}
		printf("%d\n", ans);
	}

	return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[1000];
    int sum=0;
    for(int i=1;i<=n;i++)
      {
          cin>>a[i];
          sum+=a[i];
      }
    int x,y,z;
    x=sum/n;
    y=x+1;
    z=x-1;
    long long xs=0,ys=0,zs=0;
    for(int i=1;i<=n;i++)
    {
        xs+=(a[i]-x)*(a[i]-x);
        ys+=(a[i]-y)*(a[i]-y);
        zs+=(a[i]-z)*(a[i]-z);
    }
    cout<<min(min(xs,ys),zs)<<endl;
    return 0;
}


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

using namespace std;

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

int main(){

    ll a,b,c,x,y;

    cin >> a >> b >> c >> x >> y;

    ll ans=999999999999999;
    ll val;
    ll la,lb;
    ll bi=max(x,y);

    rep(i,bi+1){
        la=x-i;
        lb=y-i;
        if(la<=0) la=0;
        if(lb<=0) lb=0;
        val=i*2*c+la*a+lb*b;
        ans = min(ans,val);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
def main():
  x, y = list(map(int,input().split()))
  for t in range(0,101):
    if y == (t*2+(x-t)*4) and (x-t)>=0:
#      print(t,(x-t),y)
      ans =('Yes')
      break
    else:
      ans =('No')
  print(ans)     
  
if __name__ == '__main__':
    main()


Measured memory_bytes: 9080
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
const int MAXN = 1e5+7;
int n,x,y,depth[MAXN],maxdep[MAXN],ans,fa[MAXN];
vector<int> G[MAXN];
void dfs(int u, int f){
    fa[u] = f;
    depth[u] = depth[f] + 1;
    maxdep[u] = 1;
    for(int v : G[u]){
        if(v==f) continue;
        dfs(v,u);
        maxdep[u] = max(maxdep[u],maxdep[v]+1);
    }
}
int main(){
    ____();
    cin >> n >> x >> y;
    for(int i = 1; i < n; i++){
        int u, v;
         cin >> u >> v;
         G[u].push_back(v);
         G[v].push_back(u);
    }
    dfs(y,0);
    int d = depth[x] - depth[y];
    d--;
    ans += d/2;
    for(int i = 1; i <= d/2; i++) x = fa[x];
    ans += maxdep[x]-1+(d&1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12032
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <iterator>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(v) reverse((v).begin(),(v).end())
#define ANS(ans) cout<<(ans)<<endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for (int i = 0; i < (n); ++i)

struct MyStruct {
	int num, honsu;
};

bool comp(const MyStruct& s, const MyStruct& t) {
	if (s.honsu != t.honsu)
		return s.honsu < t.honsu; // 昇順
	return s.num > t.num;
}


int main() {
	string s;
	cin >> s;

	if (s[5] == '0') {
		if (s[6] <= '0' + 4) {
			ANS("Heisei");
		}
		else {
			ANS("TBD");
		}
	}
	else {
		ANS("TBD");
	}


	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int n;
	cin >> n;
	bool contains = false;
	while(n) {
  	int d = n % 10;
  	n = n / 10;
  	if(d == 7) {
    	contains = true;
    }
  }
	if(contains) {
    cout << "Yes \n";
  } else {
    cout << "No \n";
  }
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main() {
  int A,B,K;
  cin >> A >> B >> K;
  for (int i = 0; i != K; ++i) {
    if (i%2) {
      B /= 2;
      A += B;
    } else {
      A /= 2;
      B += A;
    } 
  }

  cout << A << " " << B << endl;
  return 0;
}


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

int main()
{
    int l, r, d, ans = 0;
    cin >> l >> r >> d;
    for (int i = l; i <= r; i++)
    {
        if (i % d == 0)
            ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int main () {

int a[3] = {0, 0, 0};
int n;

for (int i = 0; i < 10; i++) {
    cin >> n;

    if (n >= a[0]) {
        a[2] = a[1];
        a[1] = a[0];
        a[0] = n;

    }

    else if (n < a[0] && n >= a[1]) {
        a[2] = a[1];
        a[1] = n;
    }

    else if (n < a[1] && n >= a[2]) {
        a[2] = n;
    }

}



    for (int i = 0; i < 3; i++)
    cout << a[i] << endl;


    return 0;


}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int h, w;
vector<vector<char>> cmap;
vector<vector<int>> Lmap;
vector<vector<int>> Rmap;
vector<vector<int>> Umap;
vector<vector<int>> Dmap;

int main() {
    cin >> h >> w;
    cmap = vector<vector<char>>(h, vector<char>(w));
    Lmap = vector<vector<int>> (h, vector<int>(w, 0));
    Rmap = vector<vector<int>> (h, vector<int>(w, 0));
    Umap = vector<vector<int>> (h, vector<int>(w, 0));
    Dmap = vector<vector<int>> (h, vector<int>(w, 0));
    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            cin >> cmap.at(i).at(j);
        }
    }

    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            if(cmap.at(i).at(j) == '.') {
                if(j == 0) {
                    Lmap.at(i).at(j) = 1;
                }else {
                    Lmap.at(i).at(j) = Lmap.at(i).at(j-1) + 1;
                }
            }else {
                Lmap.at(i).at(j) = 0;
            }
        }
    }

    for(int i = 0; i < h; ++i) {
        for(int j = w-1; j >= 0; --j) {
            if(cmap.at(i).at(j) == '.') {
                if(j == w-1) {
                    Rmap.at(i).at(j) = 1;
                }else {
                    Rmap.at(i).at(j) = Rmap.at(i).at(j+1) + 1;
                }
            }else {
                Rmap.at(i).at(j) = 0;
            }
        }
    }

    for(int j = 0; j < w; ++j) {
        for(int i = 0; i < h; ++i) {
            if(cmap.at(i).at(j) == '.') {
                if(i == 0) {
                    Umap.at(i).at(j) = 1;
                }else {
                    Umap.at(i).at(j) = Umap.at(i-1).at(j) + 1;
                }
            }else {
                Umap.at(i).at(j) = 0;
            }
        }
    }

    for(int j = 0; j < w; ++j) {
        for(int i = h-1; i >= 0; --i) {
            if(cmap.at(i).at(j) == '.') {
                if(i == h-1) {
                    Dmap.at(i).at(j) = 1;
                }else {
                    Dmap.at(i).at(j) = Dmap.at(i+1).at(j) + 1;
                }
            }else {
                Dmap.at(i).at(j) = 0;
            }
        }
    }

    int light = 0;
    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            int clight = Lmap.at(i).at(j) + Rmap.at(i).at(j) + Umap.at(i).at(j) + Dmap.at(i).at(j) - 3;
            light = max(light, clight);
        }
    }

    cout << light << endl;
}

Measured memory_bytes: 69120
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
 
int main() {
    int N, T;
    cin >> N >> T;
    vector<pair<int,int>> vec(N);
    int mincost = 10000;
    for(int i=0; i<N; i++){
        cin >> vec.at(i).first;
        cin >> vec.at(i).second;
        if(vec.at(i).second <= T){
            mincost = min(mincost, vec.at(i).first);
        }
    }
    if(mincost != 10000){
        cout << mincost << endl;
    }
    else{
        cout << "TLE" << endl;
    }
}

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

void solve() 
{
    int n;string s;cin>>n>>s;
    int cntw=0,cntb=0;
    int ans=999999999;
    REP(i,n){
        if(s[i]=='.')cntw++;
    }
    REP(i,n){
        ans=min(cntw+cntb,ans);
        if(s[i]=='.'&&cntw>0)cntw--;
        if(s[i]=='#')cntb++;
    }ans=min(cntw+cntb,ans);
    cout<<ans<<endl;
    
}

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

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

int main() {

	int a, b, c;

	cin >> a >> b >> c;

	int dummy;
	if (a > b) {
		dummy = a;
		a = b;
		b = dummy;
	}
	if (b > c) {
		dummy = b;
		b = c;
		c = dummy;
	}
	if (a > b) {
		dummy = a;
		a = b;
		b = dummy;
	}

	b = b - a;
	c = c - a;

	int result = 0;

	if (b % 2 == 1) {
		b--;
		result++;
	}
	if (c % 2 == 1) {
		c--;
		result++;
	}

	result += c / 2;
	result += (c - b) / 2;

	cout << result << endl;

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define FI first
#define SE second
#define maxn 200000
#define mod 1000000007
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef double db;

vector<ll> fac;
ll ans;

ll exgcd(ll a,ll b,ll &x,ll &y)
{
    if(!b) {x=1;y=0;return a;}
    ll G=exgcd(b,a%b,x,y);
    ll tmp=x;
    x=y;y=tmp-a/b*y;
    return G;
}

void dfs(int dep,ll A,ll B)
{
    if(dep==-1)
    {
        ll x,y;
        exgcd(A,B,x,y);
        if(y>=0) x+=B,y-=A;
        ans=min(ans,-B*y);
        return;
    }
    dfs(dep-1,A*fac[dep],B);
    dfs(dep-1,A,B*fac[dep]);
}
int main()
{
    ll n; scanf("%lld",&n); n*=2;
    for(int i=2;1ll*i*i<=n;i++) if(n%i==0)
    {
        ll x=1;
        while(n%i==0) n/=i,x*=i;
        fac.pb(x);
    }
    if(n>1) fac.pb(n);
    ans=1ll<<60;
    int N=fac.size();
    dfs(N-1,1,1);
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 3832