akhauriyash/Code-Regression huggingface dataset:
# https://atcoder.jp/contests/abc152/submissions/9619555

import numpy as np
import sys
readline = sys.stdin.readline

N = int(readline())
graph = [[] for _ in range(N + 1)]
for i in range(N - 1):
    a, b = map(int, readline().split())
    lb = 1 << i
    graph[a].append((lb, b))
    graph[b].append((lb, a))

M = int(readline())


def get_path(U, V):
    visited = 0
    q = [(U, 0)]
    while q:
        v, used = q.pop()
        if v == V:
            return used
        visited |= used
        for lb, u in graph[v]:
            if lb & visited:
                continue
            q.append((u, used | lb))


condition_path = []
for i in range(M):
    u, v = map(int, readline().split())
    condition_path.append(get_path(u, v))


def popcnt(n):
    c = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c >> 2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c >> 4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c >> 8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c >> 16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c >> 32) & 0x00000000ffffffff)
    return c


sgn = np.where(popcnt(np.arange(1 << M)) % 2, -1, 1)
S = np.zeros(1 << M, np.int64)
for i in range(M):
    S[1 << i:1 << (i + 1)] = S[:1 << i] | condition_path[i]


n_edges = popcnt(S)
x = 1 << (N - 1 - n_edges)
answer = np.sum(x * sgn)
print(answer)

Measured memory_bytes: 62640
#include <stdio.h>


int n,A[20];

int sum(int , int );
int main()
{
  int q,m[200];
  int i;

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

  scanf("%d",&q);
  for(i=0;i<q;i++)
    {
      scanf("%d",&m[i]);
      if(sum(0,m[i])) printf("yes\n");
      else printf("no\n");
    }
  return 0;
}

int sum(int x,int y)
{
  if(x>=n)return 0;
  if(A[x]==y)return 1;
  if(sum(x+1,y)) return 1;
  if(sum(x+1,y-A[x]))return 1;
  return 0;
}



Measured memory_bytes: 2108
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>


using namespace std;

int main()  
{  
    long long a,b,ans=0;
    cin>>a>>b;
    int m=b-a;
    for(int i=1;i<=m;i++)
    ans+=i;
    cout<<ans-b;
    //system("pause");
    return 0;
}  

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

using namespace std;

int N, x[100001], L;
int r[22][100001];

int main()
{

  memset(r, -1, sizeof(r));

  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> x[i];
  }
  cin >> L;
  for(int i = 0; i < N; i++) {
    r[0][i] = upper_bound(x, x + N, x[i] + L) - x;
    --r[0][i];
  }
  r[0][N - 1] = N - 1;

  for(int k = 0; k < 21; k++) {
    for(int i = 0; i < N; i++) {
      if(r[k][i] < 0) r[k + 1][i] = -1;
      else r[k + 1][i] = r[k][r[k][i]];
    }
  }

  int Q;
  cin >> Q;
  while(Q--) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    if(v > u) swap(u, v);
    int ret = 0, j = v;

    bool f = false;
    for(int k = 21; k >= 0; k--) {
      int j2 = r[k][j];
      if(j2 >= 0 && j2 < u) {
        j = j2;
        ret += 1 << k;
        if(r[0][j2] >= u) {
          cout << ret + 1 << endl;
          f = true;
          break;
        }
      }
    }
    if(!f) cout << 1 << endl;
  }
}


Measured memory_bytes: 9856
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    int a,b,c,d;
    while(~scanf("%d %d %d %d",&a,&b,&c,&d))
    {
        if(a*b>c*d)
            printf("%d",a*b);
        else
            printf("%d",c*d);
    }
    return 0;
}


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

#define ll long long

int main()
{
    int N, M;
    std::cin >> N >> M;

    int sum1 = N * (N-1) / 2;
    int sum2 = M * (M-1) / 2;

    int sum = sum1 + sum2;

    std::cout << sum << std::endl;
}

Measured memory_bytes: 3576
#include<stdio.h>
int main()
{
int W, H, x, y, r, a, b;
scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
 
a=W-x;
b=H-y;
if(x<r || y<r){
printf("No\n");
} 
 
else if(a<r || b<r){
printf("No\n");
} 
else{
printf("Yes\n");
}
 
return 0;
}

Measured memory_bytes: 584
from collections import deque

n, m = map(int, input().split())
to = [[] for _ in range(n)]
INF = float('inf')
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)

# queue
q = deque()
q.append(0)
# 最初の部屋までの距離
dist = [INF] * n
# 直前の部屋
prev = [-1] * n

#### BFS ####
while len(q) != 0:
    # queueから値を取り出す
    v = q.popleft()

    # vに隣接する部屋について調べる
    for u in to[v]:
        if prev[u] == -1:
            dist[u] = dist[v] + 1
            prev[u] = v
            q.append(u)

# print(prev)
print("Yes")
for i in range(1, len(prev)):
    print(prev[i] + 1)

Measured memory_bytes: 38100
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll N=1e5+5,mod=1e9+7;
map< ll , ll >mp;
void calc(ll n){
    for(ll i=2;i*i<=n;i++){
        if(n%i)continue;
        while(n%i==0){
            mp[i]++;
            n/=i;
        }
    }
    if(n>1)mp[n]++;
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n;cin>>n;
    for(ll i=2;i<=n;i++)calc(i);
    ll ans = 1;
    for(auto &ele:mp)ans = ans * (ele.second + 1 ) , ans%=mod;
    cout<<ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <queue>
#include <deque>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <bitset>

#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define FILL(x, y) memset(x, y, sizeof(x))
#define pb push_back
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

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 (a > b) {
      a = b;
      return 1;
   }
   return 0;
}

using namespace std;
using ll = long long;

const int kInf = 2e9;
const ll kLInf = 2e18;

int gcd (int a, int b) {
   return b ? gcd(b, a % b) : a;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
set<int> bank1, bank2, bank3;
int N;
string S;
int main()
{
   cout << fixed << setprecision(10);
   cin >> N >> S;
   REP(i, N) {
      int num = S[i] - '0';
      for (auto val2 : bank2) {
         bank3.insert(10 * val2 + num);
      }
      for (auto val1 : bank1) {
         bank2.insert(10 * val1 + num);
      }
      bank1.insert(num);
   }
   cout << SZ(bank3) << endl;

   return 0;
}



Measured memory_bytes: 384
#include<iostream>
#include<cstring>

using namespace std;

int main()
{
	char s[101],t[101];
	cin>>s>>t;
	int len=strlen(s);
	bool flag=0;
	for (int i=0;i<len;i++)
	{
		char temp;
		temp=s[len-1];
		for (int i=len-2;i>=0;i--)
			s[i+1]=s[i];
		s[0]=temp;
		if (!strcmp(s,t))
		{
			flag=1;
			break;
		}
	}
	if (flag)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define VIN(v) for(auto&elem_: (v) )cin>>elem_
#define VOUT(v, sep) for(_loop_int idx=0; idx<(_loop_int)v.size(); idx++) {cout<<v[idx]; if(idx<(_loop_int)v.size()-1) cout<<sep;} cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(debugidx,v.size())cout<<" "<<v[debugidx];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(debugidx,n)cout<<" "<<v[debugidx];cout<<endl

const ll MOD = 1000000007ll;
const int IINF = numeric_limits<int>::max()/2-1;
const ll LINF = numeric_limits<ll>::max()/2-1;

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

#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    string s;
    cin>>s;
    int ans = 700;
    REP(i,3){
        if(s[i]=='o') ans+=100;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

ll n; 

bool check(ll k){
	if(k==1){
		return 0;
	}
	return (n/(k-1))==(n%(k-1));
}

int main(){
	cin >> n;
	long long ans=0;
	for(ll i=1;i*i<=n;i++){
		if(n%i==0){
			ans+=(i-1)*check(i);
			if(i!=n/i)
				ans+=(n/i-1)*check(n/i);
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    string T, W;
    int count =0;
    cin >> W;
    for (int i=0; i < W.size(); i++) {
        W[i] = toupper(W[i]);
    }
    while (1) {
        cin >> T;
        if (T == "END_OF_TEXT") break;
        for (int i=0; i < T.size(); i++){
            T[i] = toupper(T[i]);
            if (i == (T.size() - 1) && T[i] == '.'){
                T.erase(i, 1);
            }
        }
        if (T == W) {
            count++;
        }
    }
    cout << count << endl;;
}


Measured memory_bytes: 3144
//#pragma GCC optimize(2)
//#pragma GCC optimize("Ofast,unroll-loops")

#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define rep(i, beg, end) for (int i = (beg); i < (end); i++)
#define rrep(i, beg, end) for (int i = (beg); i >= (end); i--)
#define sp(i) setprecision(i) << fixed
typedef long long ll;
typedef pair<ll, ll> P;
typedef unsigned long long ull;
const int INF = 2e9;
const int mod = 1e9 + 7;
const int N = 1010;
ull p_hash(ull x, ull y) { return (x + y) * (x + y + 1) / 2 + y; } //NxN->N
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

int h, w, ch, cw, dh, dw;
char s[N][N];
bool mark[N][N];
int warp[N][N];
void dfs(int x, int y)
{
    //cout << x << " " << y << " " << warp[x][y] << '\n';

    if (x == dh && y == dw)
        return;

    int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
    bool flag = false;
    rep(i, 0, 4)
    {
        int xx = x + dx[i], yy = y + dy[i];
        if (xx >= 1 && xx <= h && yy >= 1 && yy <= w && s[xx][yy] == '.')
        {
            if (!mark[xx][yy])
            {
                flag = true;
                mark[xx][yy] = true;
                warp[xx][yy] = warp[x][y];
                dfs(xx, yy);
            }
            else
            {
                if (warp[x][y] < warp[xx][yy])
                {
                    warp[xx][yy] = warp[x][y];
                    dfs(xx, yy);
                }
            }
        }
    }

    int wx[] = {1, -1, 1, -1}, wy[] = {-1, 1, 1, -1};
    rep(i, 0, 3)
    {
        rep(j, 0, 3)
        {
            rep(k, 0, 4)
            {
                int xx = x + wx[i] * i, yy = y + wy[i] * j;
                if (xx >= 1 && xx <= h && yy >= 1 && yy <= w && s[xx][yy] == '.')
                {
                    if (!mark[xx][yy])
                    {
                        flag = true;
                        mark[xx][yy] = true;
                        warp[xx][yy] = warp[x][y] + 1;
                        dfs(xx, yy);
                    }
                    else
                    {
                        if (warp[x][y] + 1 < warp[xx][yy])
                        {
                            warp[xx][yy] = warp[x][y] + 1;
                            dfs(xx, yy);
                        }
                    }
                }
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    // cin >> h >> w;
    // cin >> ch >> cw;
    // cin >> dh >> dw;
    // rep(i, 1, h + 1)
    // {
    //     string in;
    //     cin >> in;
    //     rep(j, 1, w + 1)
    //     {
    //         s[i][j] = in[j - 1];
    //     }
    // }
    // mark[ch][cw] = true;
    // dfs(ch, cw);
    // if (mark[dh][dw])
    //     cout << warp[dh][dw] << endl;
    // else
    //     cout << -1 << endl;

    int n, x, t;
    cin >> n >> x >> t;
    cout << (int)ceil((double)n / x) * t << endl;

    return 0;
}

Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		int b = s.nextInt();
		int c = s.nextInt();
		
		if(a==(b+c) || b==(a+c) || c==(a+b)){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}	
}

Measured memory_bytes: 9684
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int h,w;
    cin >> h >> w;
    int c[10][10] = {};
    REP(i,0,10) REP(j,0,10) cin >> c[i][j];
    int cnt[10] = {};
    int in;
    REP(i,0,h*w) {
        cin >> in;
        if (in > -1) ++cnt[in];
    }
    REP(k,0,10) REP(i,0,10) REP(j,0,10) c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
    LL ans = 0;
    REP(i,0,10) ans += cnt[i] * c[i][1];
    cout << ans << endl;
    //REP(i,0,10) dump(cnt[i]);
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 256
ope = {"+": lambda a, b: b + a,
       "-": lambda a, b: b - a,
       "*": lambda a, b: b * a}

stack = list()

for c in input().split():
    if c in ope:
        stack.append(ope[c](stack.pop(), stack.pop()))
    else:
        stack.append(int(c))

print(stack[-1])


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	
	int v[n], c[n], sum=0, i;
	
	for(i=0; i<n; i++)
	{
		cin>>v[i];
	}
	
	for(i=0; i<=n; i++)
	{
		cin>>c[i];
	}
	
	for(i=0; i<n; i++)
	{
		if(v[i]-c[i]>0)
		{
			sum+=v[i]-c[i];
		}
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 384
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
#include <list>
#include <cassert>
 
using namespace std; 

int n;
string city[15];
string tmp[15];
int dp[1<<15][15];
int cost[15][15];
bool ng[15];
const int inf=512;

int main(){
	
	while(cin>>n,n){

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

		fill(&ng[0],&ng[n],false);
		//?????¨?????????????????????????????????
		for(int i=0;i<n;i++){
			if(ng[i]) continue;
			for(int j=0;j<n;j++){
				if(i==j) continue;

				if(tmp[i].find(tmp[j])!=string::npos) ng[j]=true;
			}
		}

		int m=0;
		for(int i=0;i<n;i++){
			if(!ng[i]) city[m++]=tmp[i];
		}

		n=m;
		const int N=1<<n;
		
		fill(&dp[0][0],&dp[N][n],inf);
		fill(&cost[0][0],&cost[n][n],inf);

		for(int i=0;i<n;i++){
			dp[1<<i][i]=city[i].size();
		}

		//city[i]????????????city[j]?????????????????????
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(i==j) cost[i][j]=0;
				//city[i]???????????????len????????¨city[j]????????????len??????????????????
				int li=city[i].size(),lj=city[j].size();
				for(int len=min(li,lj);len>=0;len--){
					if(city[i].substr(li-len,len)==city[j].substr(0,len)){
						cost[i][j]=lj-len;
						break;
					}
				}
			}
		}

		for(int bit=1;bit<N;bit++){
			for(int from=0;from<n;from++){
				if(!(bit&(1<<from))) continue;
				for(int to=0;to<n;to++){
					if(bit&(1<<to)) continue;
					dp[bit|(1<<to)][to]=min(dp[bit|(1<<to)][to],dp[bit][from]+cost[from][to]);
				}
			}
		}
		
		cout<<*min_element(dp[N-1],dp[N])<<endl;

	}

}

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

using namespace std;

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

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double pi = 3.14159265358979323846;

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
//

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

  int n;
  cin >> n;
  vector<int> P(n);
  rep(i, n) cin >> P[i];

  int m = P[0], ans = 0;
  rep(i, n) {
    if (P[i] <= m) {
      ans++;
    }
    m = min(m, P[i]);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr
#define INT_MAX_HALF (INT_MAX / 2)

typedef long long ll;

using namespace std;
//using namespace boost::multiprec

int main(){

    int n,d;
    cin >> n >> d;

    int k = 2 * d + 1;

    cout << (n + k - 1) / k << endl;
    return 0;
}

Measured memory_bytes: 256
def decomp(n):
    i = 2
    res = {}
    while i * i <= n:
        while n % i == 0:
            n //= i
            res[i] = res.get(i, 0) + 1
        i += 1
    if n > 1:
        res[n] = 1
    return res


N = int(input())
d = {}
for i in range(1, N + 1):
    res = decomp(i)
    for k, v in res.items():
        if k != 1:
            d[k] = d.get(k, 0) + v

ans = 1
MOD = int(1e9 + 7)
for e in d.values():
    ans *= (e + 1)
    ans %= MOD
print(ans)


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

#define ll long long
#define pb push_back
#define mp make_pair

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

	/*#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r+", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w+", stdout);
	#endif*/

    string s;
    cin >> s;

    cout << ((s[0] == '7' or s[1] == '7' or s[2] == '7') ? "Yes" : "No") << '\n';
}

Measured memory_bytes: 3652
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;

// 入力
int N;
string S;

// その他
int dp[1 << 18];
int power[1 << 18][3], s[3];

int popcnt(int x) {
	int cnt = 0;
	for (int i = 0; i < 30; i++) {
		if ((x / (1 << i)) % 2 == 1) cnt++;
	}
	return cnt;
}

void init() {
	for (int i = 1; i <= 200000; i++) {
		dp[i] = dp[i % popcnt(i)] + 1;
	}
}

int main() {
	// 入力など
	init();
	cin >> N >> S;

	// 前処理
	int wa = 0;
	for (int i = 0; i < S.size(); i++) wa += (S[i] - '0');
	for (int i = 0; i < 3; i++) {
		int md = (wa - 1) + i; if (md <= 0) continue;
		power[S.size() - 1][i] = 1;
		for (int j = (int)S.size() - 2; j >= 0; j--) {
			power[j][i] = 2 * power[j + 1][i];
			power[j][i] %= md;
		}
		for (int j = 0; j < S.size(); j++) {
			if (S[j] == '1') { s[i] += power[j][i]; s[i] %= md; }
		}
	}

	// 計算
	for (int i = 0; i < S.size(); i++) {
		int md = wa, idx = 1;
		if (S[i] == '0') { md += 1; idx = 2; }
		if (S[i] == '1') { md -= 1; idx = 0; }
		if (md == 0) { cout << "0" << endl; }
		else {
			int f = s[idx];
			if (S[i] == '0') { f += power[i][2]; f = (f + md) % md; }
			if (S[i] == '1') { f -= power[i][0]; f = (f + md) % md; }
			cout << dp[f] + 1 << endl;
		}
	}
	return 0;
}

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

using namespace std;

#define ll       long long

#define  sci(x)   scanf("%d", &x)
#define  scl(x)   scanf("%lld", &x)
#define  scd(x)   scanf("%lf", &x)

#define  pfi(x)   printf("%d", x)
#define  pfl(x)   printf("%lld", x)
#define  pfd(x)   printf("%lf", x)
#define  pfc(x)   printf("Case %d: ", x++)
#define  ps       printf(" ")
#define  pn       printf("\n")

#define  pb       push_back
#define  ppb      pop_back
#define  pf       push_front
#define  ppf      pop_front
#define  In       insert
#define  All(a)   a.begin(), a.end()

ll dp[100005][3];
ll inp[100005][3], n;

ll solve(int pos, int w)
{
	if(pos > n)
		return 0;

	ll ret = dp[pos][w];

	if(ret != -1)
		return ret;

	ret = 0;
	for(int i = 0; i < 3; i++)
		if(w != i || pos == 0)
			ret = max(ret, solve(pos + 1, i));
	//cout << pos << ' ' << w << ' ' << ret << endl;
	return dp[pos][w] = ret + inp[pos][w];
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    memset(dp, -1, sizeof dp);
    scl(n);

    for(int i = 1; i <= n; i++)
    	scl(inp[i][0]), scl(inp[i][1]), scl(inp[i][2]);

    cout << solve(0, 0);

    return 0;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(ll (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(ll (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define mp make_pair
const ll MOD=1e9+7;
using namespace std;

int main(){
  ll N,C,K;
  cin >> N >> C >> K;
  vector<pair<ll,ll> > t(N);
  rep(i,N){
    ll tmp;
    cin >> tmp;
    t[i] = mp(tmp,tmp+K);
  }
  sort(All(t));

  ll sum = 1,cnt = 1;
  ll f = t[0].first,l = t[0].second;
  for(ll i=1;i<N;i++){
    f = t[i].first;
    cnt++;
    if(l-f < 0 || cnt > C){
      sum++;
      f = t[i].first;
      l = t[i].second;
      cnt = 1;
      continue;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#define all(x) (x).begin(), (x).end()
using namespace std;

int main(void) {
    int N;cin>>N;
    vector<int> x(N);
    for (int i = 0; i < N; i++) cin>>x[i];
    sort(all(x));
    int tmp = x[0] + x[N-1];
    cout << max(tmp/2 - x[0], x[N-1] - tmp/2) << endl;
    return 0;
}


Measured memory_bytes: 3148
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);


	Int a, b, c;
	cin >> a >> b >> c;

	cout << min(b / a, c) << "\n";

}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc085/tasks/abc085_a
"use strict"
function Main(input) {
  const date = input.split(`\n`)[0].replace(/^.{4}/, 2018 );
  console.log(date);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 20552
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int count[] = new int[6];
		for(int i = 0 ; i < n ; i++){
			double h = scan.nextDouble();
			if(h < 165.0){
				count[0] +=1;
			}else if(h < 170.0){
				count[1] +=1;
			}else if(h < 175.0){
				count[2] +=1;
			}else if(h < 180.0){
				count[3] +=1;
			}else if(h < 185.0){
				count[4] +=1;
			}else{
				count[5] +=1;
			}
		}
		for(int i = 0 ; i < 6 ; i++){
			System.out.print((i+1)+":");
			for(int j = 0 ; j < count[i] ; ++j){
				System.out.print("*");
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 27996
# https://atcoder.jp/contests/abc171/tasks/abc171_b

N, K = map(int, input().split())
p_list = list(map(int, input().split()))

p_list = sorted(p_list)

total_val = 0

for i in range(K):
    total_val += p_list[i]

print(total_val)

Measured memory_bytes: 9128
#include<bits/stdc++.h>
  using namespace std;
  int main()
  {
      string s1;
      cin>>s1;
      for(int x=0;x<s1.length();x++)
      {
          if(s1[x]!=',')
         {
             cout<<s1[x];
         }
         else
         {
             cout<<" ";
         }
     }
 }

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int a, b, c, x, y;

signed main() {
	while (scanf("%d,%d,%d",&a,&b,&c)!=EOF) {
		if (a*a+b*b==c*c) x++;
		if (a==b) y++;
	}
	cout << x << endl << y << endl;
}



Measured memory_bytes: 3272
#include<stdio.h>
#include<math.h>

int isPrime(int x ,int y){
  int i;
  if(y < 2){
    return 0;
  }else if(y == 2){
    return 1;
  }
  if(y % 2 == 0){
    return 0;
  }
  
  
  for(i = 3;i <= x;i+=2){
    if(y % i == 0){
      return 0;
    }
  }
    return 1;
  }


int main(){
  int n;
  int result;
  int cnt=0;
  int i;
  int array[10001];
  int ary[10001];
  scanf("%d",&n);
  for(i = 0;i<n;i++){
    scanf("%d",&array[i]);
    
  }
  for(i=0;i<n;i++){
    ary[i] = ((int)sqrt(array[i]));
  result = isPrime(ary[i],array[i]); 
  cnt += result;
  }

  printf("%d\n",cnt);
    
  
  return 0;
}



Measured memory_bytes: 2144
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N,K,*A = map(int,read().split())

MOD = 10 ** 9 + 7

def cumprod(A, MOD = MOD):
    L = len(A); Lsq = int(L**.5+1)
    A = np.resize(A, Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        A[:,n] *= A[:,n-1]; A[:,n] %= MOD
    for n in range(1,Lsq):
        A[n] *= A[n-1,-1]; A[n] %= MOD
    return A.ravel()[:L]
def make_fact(U, MOD = MOD):
    x = np.arange(U, dtype = np.int64); x[0] = 1
    fact = cumprod(x, MOD)
    x = np.arange(U, 0, -1, dtype=np.int64); x[0] = pow(int(fact[-1]), MOD-2, MOD)
    fact_inv = cumprod(x, MOD)[::-1]
    return fact,fact_inv

def convolve(f, g, MOD=MOD):
    """
    数列 (多項式) f, g の畳み込みの計算．上下 15 bitずつ分けて計算することで，
    30 bit以下の整数，長さ 250000 程度の数列での計算が正確に行える．
    """
    Lf = len(f); Lg = len(g); L = Lf + Lg - 1
    fl = f & (1 << 15) - 1; fh = f >> 15
    gl = g & (1 << 15) - 1; gh = g >> 15
    if L < (1<<8):
        conv = lambda f,g: \
            np.convolve(f,g) % MOD
    else:
        fft = np.fft.rfft; ifft = np.fft.irfft; fft_len = 1 << L.bit_length()
        conv = lambda f,g: \
            np.rint(ifft(fft(f,fft_len) * fft(g,fft_len))[:L]).astype(np.int64) % MOD
    x = conv(fl, gl)
    z = conv(fh, gh)
    y = conv(fl+fh, gl+gh)
    return (x + ((y - x - z) << 15) + (z << 30)) % MOD

fact, fact_inv = make_fact(10 ** 5)

f = np.zeros(N+1,np.int64)
f[0] = 1
for a in A:
    g = fact[N-a:N+1] * fact_inv[0:a+1] % MOD * fact_inv[N-a] % MOD
    g = g[::-1]
    g *= fact_inv[:len(g)]; g %= MOD
    f = convolve(f,g)[:N+1]

f *= fact[:N+1]; f %= MOD

answer = f[N]
print(answer)


Measured memory_bytes: 16308
import time
startTimeProblem=time.time()

import fileinput, sys, itertools, functools
from math import *
from bisect import *
from heapq import *
from collections import *

def lcm(a, b):  
    return (a*b)/gcd(a, b)

class InputHelper:
    def __init__(self):
        self.myinput = fileinput.input()

    def isLocal(self):
        return not fileinput.isstdin()

    def int(self):
        return int(self.myinput.readline().rstrip())

    def ints(self):
        return [int(_) for _ in self.myinput.readline().rstrip().split()]

    def str(self):
        return self.myinput.readline().rstrip()

    def strs(self):
        return [_ for _ in self.myinput.readline().rstrip().split()]

class OutputHelper:
    def int(self, a):
        print(a)    

    def ints(self, a):  
        print(" ".join([str(_) for _ in a]))
    
    def intsNL(self, a):
        for _ in a:
            print(_)
    
    def str(self, s):
        print(s)

    def strs(self, s):
        print(" ".join([_ for _ in s]))

    def strsNL(self, s):
        for st in s:
            print(st)

class ListNode:
    def __init__(self, val):
        self.val = val
        self.next = None
        self.prev = None

In = InputHelper()
Out = OutputHelper()

######################################

A, B, N = In.ints()

if N<B-1:
    res = floor(A*N/B) - A*floor(N/B)
else:
    res = floor(A*(B-1)/B) - A*floor((B-1)/B)

Out.int(res)
        
######################################

if len(sys.argv)>2 and sys.argv[2]=="TIMEIT":
    fin = (time.time()-startTimeProblem)*1000
    print("{:.2f}".format(fin) + "ms")

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


int main(){

	int a, b, d, r;
	cin >> a >> b;

	d = a / b;
	r = a%b;
	double f;
	f = 1.0* a / b;

	printf("%d %d %.5lf\n", d,r,f);
	
	return 0;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define ALL(a)  (a).begin(),(a).end()
 
const ll mod = 1000000007;
const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;
 
template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}
 
template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}


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



  cout << 3 * pow(a,2);
}


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

using namespace std;
typedef long long ll;

int main() {
    string s;
    int n;
    cin >> s;
    n = (int)s.length();
    ll cnt = 0;
    ll ans = 0;
    for(int i=0; i<n; i++){
        if(s[i]=='A') cnt++;
        else if(s[i]=='B'&&s[i+1]=='C'){
            ans+=cnt;
            i++;
        }else{
            cnt=0;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, D;
    cin >> N >> D;
    vector<int> X(N), Y(N);
    for(int i=0; i<N; i++) cin >> X[i] >> Y[i];

    atcoder::two_sat ts(N);
    for(int i=0; i<N; i++)
    {
        for(int j=i+1; j<N; j++)
        {
            if(abs(X[i] - X[j]) < D) ts.add_clause(i, false, j, false);
            if(abs(X[i] - Y[j]) < D) ts.add_clause(i, false, j, true);
            if(abs(Y[i] - X[j]) < D) ts.add_clause(i, true, j, false);
            if(abs(Y[i] - Y[j]) < D) ts.add_clause(i, true, j, true);
        }
    }

    if(ts.satisfiable())
    {
        cout << "Yes\n";
        auto ans = ts.answer();
        for(int i=0; i<N; i++)
        {
            if(ans[i]) cout << X[i] << '\n';
            else cout << Y[i] << '\n';
        }
    }
    else cout << "No\n";

    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,n)  for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define deb(x) cerr << #x <<": " << x << '\n';
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
typedef long double ld;
typedef long long ll;

int main(){
    fast_io();
    int s, w;
    cin >> s >> w;
    if(w >= s) cout << "unsafe";
    else cout << "safe";
    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};


bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int N,H,W,a[501][501];
  vector<P> from(0),to(0);;
  cin >> H >> W;
  REP(i,H)REP(j,W)cin >> a[i][j];
  REP(i,H)REP(j,W){
    if(a[i][j] % 2){
      if(i == H-1){
        if(j == W-1)
          continue;
        from.push_back(P(i+1,j+1));
        to.push_back(P(i+1,j+1+1));
        a[i][j]--;
        a[i][j+1]++;
      }else{
        from.push_back(P(i+1,j+1));
        to.push_back(P(i+1+1,j+1));
        a[i][j]--;
        a[i+1][j]++;
      }
    }
  }
  cout << from.size() << endl;
  REP(i,from.size()){
    printf("%d %d %d %d\n",from[i].first,from[i].second,to[i].first,to[i].second);
  }
  
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
const int MOD = 1000000007;
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


Measured memory_bytes: 5228
// abc157_a
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(int argc, char *argv[])
{
  int n;
  cin>>n;
  if (n % 2 != 0) {
    cout<<n/2+1<<endl;
  } else {
    cout<<n/2<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;

int main(int argc, char *argv[]) {
	
	long X,Y; cin >> X >> Y;

	//double k = log2(Y/X) + 1;
	//cout << floor(k) << endl;

	int ans = 0;
	while(X <= Y) {
		X *= 2;
		ans++;
	}
	cout << ans << endl;
	return 0;
}


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

from collections import deque
import itertools as it
import sys

sys.setrecursionlimit(1000000)

while True:
    N = input()
    if N == 0:
        break
    p = map(int, raw_input().split())
    d = map(int, raw_input().split())
    E = [[] for i in range(N)]
    leaf = [False for i in range(N)]
    for i in range(N - 1):
        u = i + 1
        v = p[i] - 1
        cost = d[i]
        E[u].append((v, cost))
        E[v].append((u, cost))
    
    for i in range(N):
        leaf[i] = (len(E[i]) < 2)
    
    def func(num, pre, dist):
        if leaf[num]:
            return -1
        ret = (dist, num)
        for e in E[num]:
            if e[0] != pre:
                hoge = func(e[0], num, dist + e[1])
                if hoge != -1 and ret[0] < hoge[0]:
                    ret = hoge
        return ret

    for i in range(N):
        if not leaf[i]:
            ret = func(i, -1, 0)
            ret = func(ret[1], -1, 0)
            break
    ans = -2 * ret[0]
    for i in range(N):
        for e in E[i]:
            if leaf[i] or leaf[e[0]]:
                ans += e[1]
            else:
                ans += e[1] * 3
    print ans / 2


Measured memory_bytes: 6060
#include<iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node { int p, l, r; };

Node T[MAX];
int n, D[MAX];

void print(int u) {
  int i, c;
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].p << ", ";
  cout << "depth = " << D[u] << ", ";

  if ( T[u].p == NIL ) cout << "root, ";
  else if ( T[u].l == NIL ) cout << "leaf, ";
  else cout << "internal node, ";

  cout << "[";

  for ( i = 0, c = T[u].l; c != NIL; i++, c = T[c].r ) {
    if (i) cout << ", ";
    cout << c;
  }
  cout << "]" << endl;
}

int rec(int u, int p) {
  D[u] = p;
  if ( T[u].r != NIL ) rec(T[u].r, p);
  if ( T[u].l != NIL ) rec(T[u].l, p + 1);
}

int main() {
  int i, j, d, v, c, l, r;
  cin >> n;
  for ( i = 0; i < n; i++ ) T[i].p = T[i].l = T[i].r = NIL;

  for ( i = 0; i < n; i++ ) {
    cin >> v >> d;
    for ( j = 0; j < d; j++ ) {
      cin >> c;
      if ( j == 0 ) T[v].l = c;
      else T[l].r = c;
      l = c;
      T[c].p = v;
    }
  }
  for ( i = 0; i < n; i++ ) {
    if (T[i].p == NIL) r = i;
  }

  rec(r, 0);

  for ( i = 0; i < n; i++ ) print(i);

  return 0;
}


Measured memory_bytes: 7748
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

const int MOD = 1e9+7;
class mint {
    ll x;
public:
    mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
    
    mint operator -() const {
        return mint(-x);
    }
    
    mint &operator +=(const mint &a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }

    mint &operator -=(const mint &a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }

    mint &operator *=(const mint &a) {
        (x *= a.x) %= MOD;
        return *this;
    }

    mint operator +(const mint &a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint &a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator *(const mint &a) const {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(MOD - 2);
    }

    mint &operator /=(const mint &a) {
        return (*this) *= a.inv();
    }

    mint operator /(const mint &a) const {
        mint res(*this);
        return res /= a;
    }

    friend ostream &operator<<(ostream& os, const mint &m) {
        os << m.x;
        return os;
    }
};

const int MAX = 510000;
mint fac[MAX], finv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i-1] * mint(i);
        finv[i] = finv[i-1] * mint(i).inv();
    }
}

mint COM (int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    // o(k)
    if (k < MAX) {
        mint ret(1);
        Rep (i, k) {
            ret *= mint(n-i);
            ret /= mint(k-i);
        }
        return ret;
    }

    return fac[n] * finv[k] * finv[n-k];
}

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

    ll n, a, b;
    cin >> n >> a >> b;
    mint ans = mint(2).pow(n);
    COMinit();
    ans -= COM(n, a);
    ans -= COM(n, b);
    ans -= mint(1);

    cout << ans << endl;
}

Measured memory_bytes: 8320
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
 
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;
 
// debugger
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#define debug(stuff) cout << #stuff << ": " << stuff <<endl
#define debugc(stuff) cout << #stuff << ": "; for(auto x: stuff) cout << x << " "; cout << endl;
// 
 
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 
 
#define print(stuff) cout << stuff << endl
#define printc(stuff) for(auto x: stuff) cout << x << " "; cout << endl;
#define printPrec(stuff) cout << fixed << setprecision(15) << stuff << endl;
#define len length
#define ret0 return 0
#define ret return 
 
 
#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fill(ar, x) memset(ar, x, sizeof ar)
 
#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>
 
// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;
 
#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN (ll)2e5+5
#define N (1ll<<10)

void solve(){
    ll n;
    cin>>n;
    ll a[n];
    loop(i,0,n) cin>>a[i];
    ll f[n] = {0};
    ll ans = 1;
    ll cnt = 3;
    loop(i,0,n){
        if(a[i] == 0){
            ans = (ans * cnt)%mod;
            cnt--;
            f[0]++;
        }
        else {
            ans = (ans * f[a[i]-1])%mod;
            f[a[i]-1]--;
            f[a[i]]++;
        }
    }
    print(ans);
}
 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
 
    ll t = 1;
    // cin>>t;
    while(t--){
        solve();
    }
    
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n;
		int count;
		while(true){
			n=sc.nextInt();
			if(n==0) break;
			count=0;
			while(true){
				if(n==1) break;
				if(n%2==0){
					n/=2;
					count++;
				}
				else{
					n=n*3+1;
					count++;
				}
			}
			System.out.println(count);
		}	
	}
}

Measured memory_bytes: 11000
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = (int)1e9;
const long long mod = 998244353LL;
const double pi = acos(-1.0);

int main() {
	int n, s;
	while (cin >> n >> s && (n || s)) {
		int ans = 0;
		for (int bit = 0; bit < (1 << 10); bit++) {
			bitset<10> b = bit;
			if (b.count() == n) {
				int sum = 0;
				rep(i, 10)sum += i * b.test(i);
				ans += sum == s;
			}
		}
		Cout(ans);
	}
}


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

int main() {
 int n, d, x;
 cin >> n >> d >> x;
 vector<int> A(n);
 for(int i = 0; i < n; i++){
    cin >> A.at(i);
  }
  int chocolate = 0;
  for(int i = 0; i < n; i++){
    int c = 0;
    int b = 0;
  while(1){
    c = A.at(i)*b + 1;
    if(c > d) break;
    b++;
    chocolate++;
  }
  }
   cout << chocolate + x << endl;
}


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

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

  int year = stoi(S.substr(0, 4));
  int month = stoi(S.substr(5, 2));
  int day = stoi(S.substr(8, 2));

  if (year == 2019 && month >= 5 && day >= 1) {
    printf("TBD");
  } else if (year > 2019 ){
    printf("TBD");
  } else {
    printf("Heisei");
  }
  return 0;
}

Measured memory_bytes: 256