akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
template<class T>

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

vvi adl_input(int N,int M){ //N頂点M辺
  vvi L(N);
  rep(i,M){
    int a,b;
    cin >> a >> b;
    //a--;b--;
    L[a].push_back(b);
    L[b].push_back(a);
  }
  return L;
}

ll gcd(ll a,ll b){
  if (a%b==0) return(b);
  else return(gcd(b,a%b));
}
ll lcm(ll a,ll b){
  return a*b/gcd(a,b);
}

vector<int> bfs(vvi L,int S){ //List,Start
  vector<int> v(L.size(),-1);
  v[S]=0;
  queue<int> q;
  q.push(S);
  while(!q.empty()){
    int a=q.front();
    q.pop();
    for(int x:L[a]){
      if (v[x]==-1){
        v[x]=v[a]+1;
        q.push(x);
      }
    }
  }
  return v;//startからの距離
}

void initialize(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout << fixed << setprecision(15);
}

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

int main(){
  initialize();
  int R;
  cin >> R;
  cout << R*R*3 << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

int main(void){
    lint N,H;
    cin >> N >> H;
    plint damage[2*N];
    rep(i,N){
        lint x,y;
        cin >> damage[2*i].first >> damage[2*i+1].first;
        damage[2*i].second=INF,damage[2*i+1].second=1;
    }
    sort(damage,damage+2*N,greater<plint>());
    lint ans=0,p=0;
    while(H>0){
        if(damage[p].second==1){
            ans++;
            H-=damage[p].first;
            p++;
        }
        else{
            lint atk=min((lint)ceil((double)H/damage[p].first),damage[p].second);
            ans+=atk;
            H-=atk*damage[p].first;
            p++;
        }
    }
    cout << ans << endl;
}

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

signed main()
{
    int h, w, k, cnt, ans=0;
    char c[6][7];

    cin >> h >> w >> k;
    for(int i=0; i<h ;i++ ){
        cin >> c[i];
    }

    for(int i=0 ;i<(1<<h) ;i++ ){
        for(int j=0 ;j<(1<<w) ;j++ ){
            cnt = 0;
            for(int x=0 ;x<h ;x++ ){
                for(int y=0 ;y<w ;y++ ){
                    if(i&(1<<x) && j&(1<<y)){
                        if(c[x][y] == '#'){
                            cnt ++;
                        }
                    }
                }
            }
            if(cnt == k){
                ans ++;
            }
        }
    }

    cout << ans << endl;  
    return (0);
}

Measured memory_bytes: 3504
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;

int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
	
	ll j,k,i,n,ans=0;
	cin>>n;
	ll march[5]={0};
	string s;
	rep(i,n){
		cin>>s;
		if(s[0]=='M')march[0]++;
		else if(s[0]=='A')march[1]++;
		else if(s[0]=='R')march[2]++;
		else if(s[0]=='C')march[3]++;
		else if(s[0]=='H')march[4]++;
	}
	for(i=0;i<3;i++){
		for(j=i+1;j<4;j++){
			for(k=j+1;k<5;k++){
				ans+=march[i]*march[j]*march[k];
			}
		}
	}
	fin(ans);
	
//////////////////////////////////////////////////////
	return 0;
}



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


int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> to(n);
    rep(i,m){
        int s, t;
        cin >> s >> t;
        --s; --t;
        to[s].push_back(t);
    }
    vector<double> dp(n);
    for(int v = n-2; v >= 0; --v){
        double now = 0;
        for(int u : to[v]){
            now += dp[u];
        }
        now /= to[v].size();
        now++;
        dp[v] = now;
    }
    double ans = dp[0];
    for(int nv = 0; nv < n-1; nv++){
        if(to[nv].size() == 1) continue;
        int nu = to[nv][0];
        for(int u : to[nv]){
            if(dp[nu] < dp[u]) nu = u;
        }
        double now = [&]{
            vector<double> dp(n);
            for(int v = n-2; v >= 0; --v){
                double now = 0;
                for(int u : to[v]){
                    if(v == nv && u == nu) continue;
                    now += dp[u];
                }
                int deg = to[v].size();
                if(v == nv) deg--;
                now /= deg;
                now++;
                dp[v] = now;
            }
            return dp[0];
        }();
        ans = min(ans, now);
    }
    printf("%.10f\n", ans);
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define SORT(n) sort((n).begin(),(n).end(),greater<int>())
#define SORTP sort((n).begin(),(n).end(),greater<pair<int,int>>());
#define D(x) for_each((x).begin(),(x).end(),[](auto&& x){cout<<x<<" ";});
#define ALL(n) begin(n),end(n)
#define rALL(n) rbegin(n),rend(n)
#define pb push_back
#define eb emplace_back
using LL=long long;
using ULL=unsigned long long;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const int INF = numeric_limits<int>::max();
int main()
{
    int n, m;
    cin >> n >> m;
    cout << ( n - 1 ) * ( m - 1 ) << endl;
    return 0;
}

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

typedef long long ll;

pair<char, int> c[4004];
int pb[2004], pw[2004];
int b[4004][2004], w[4004][2004];
int dp[2004][2004];

int main() {
	int n; cin >> n;
	for (int i = 1; i <= 2 * n; i++) {
		cin >> c[i].first >> c[i].second;
		(c[i].first == 'B' ? pb : pw)[c[i].second] = i;
	}

	for (int i = 2 * n; i >= 1; i--) {
		for (int j = 1; j <= n; j++) {
			b[i][j] = b[i + 1][j] + (c[i].first == 'B' && c[i].second <= j);
			w[i][j] = w[i + 1][j] + (c[i].first == 'W' && c[i].second <= j);
		}
	}

	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			if (i > 0 && j > 0) dp[i][j] = min(dp[i - 1][j] + b[pb[i]][i - 1] + w[pb[i]][j], dp[i][j - 1] + b[pw[j]][i] + w[pw[j]][j - 1]);
			else if (i > 0) dp[i][j] = dp[i - 1][j] + b[pb[i]][i - 1] + w[pb[i]][j];
			else if (j > 0) dp[i][j] = dp[i][j - 1] + b[pw[j]][i] + w[pw[j]][j - 1];
		}
	}

	cout << dp[n][n] << endl;
	return 0;
}

Measured memory_bytes: 78592
#include<stdio.h>
#define MAX 500000
#define INFTY 1000000000

int L[MAX/2+2];
int R[MAX/2+2];
int count;

void merge(int S[], int left, int mid, int right)
{
	int n1 = mid-left;
	int n2 = right-mid;
	
	for(int i=0; i<n1; i++)
	{
	
		L[i] = S[left+i];
	
	}
	for(int i=0; i<n2; i++)
	{
	
		R[i] = S[mid+i];
	
	}
	
	L[n1] = INFTY;
	R[n2] = INFTY;

	int i=0;
	int j=0;
	
	for(int k=left; k< right; k++)
	{
		
		count++;
		
		if(L[i] <= R[j])
		{
			S[k] = L[i];
			
			i++;
		}
		else
		{
			S[k] = R[j];
			
			j++;
		}
	}
}

void mergesort(int S[], int left, int right)
{

	if(left+1 < right)
	{
	
		int mid = (left+right)/2;
		
		mergesort(S,left, mid);
		mergesort(S, mid, right);
		merge(S,left, mid, right);
	}



}

int main(void)
{

int n;

scanf("%d", &n);

int S[MAX];

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

	mergesort(S, 0, n);
	
	for(int i=0; i<n; i++)
	{
		if(i>0)
		{
			printf(" ");
		}
		
			printf("%d", S[i]);
	
	}
	
	printf("\n");
	
	printf("%d\n", count);
	

return 0;

}


Measured memory_bytes: 5672
#include<stdio.h>

#define Max 200000
int main ()
{
  int j,max,min,num,number[Max];

  scanf("%d",&num);


  for(j=0;j<num;j++)
    {
      scanf("%d",&number[j]);
    }



  for(j=1;j<=num-1;j++)
    {

          max=number[1]-number[0];
          min=number[0];

          for(j=1;j<=num-1;j++)
        {

          if(max<number[j]-min)
            {
              max=number[j]-min;
            }

          if(min>number[j])
            {
              min=number[j];
            }

        }

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

     return 0;
   }

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

using ll = long long int;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

#define pi 3.14159265358979323846

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




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


ll gcd(ll a, ll b){
  ll resi, g, l;
  if(a > b){
    g = a; l = b;
  }else if(b > a){
    g = b; l = a;
  }else{
    return a;
  }
  resi = g % l;
  if(resi != 0){
    return gcd(l, resi);
  }else{
    return l;
  } 
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

int ans = 0;
int N, M, Q;

template<typename T>
void showall(vector<T> v){
  rep(i, 0, v.size()){
    cout << v[i] << " ";
  }
  cout << endl;
}

template<typename T>
ll com(T n, T m, T mod){
  ll a = 1, b = 1, ans;
  if(n == m || m == 0){
    ans = 1;
  }else{
    for(ll i = 0;i < m; i++){
      a *= n-i;
      a %= mod;
      b *= i+1;
      b %= mod;
    }
    ans = (a * powmod(b, mod-2, mod)) % mod;
  }
  
  return ans;
}

 
int main() {
  int A, B, H, M;

  cin >> A >> B >> H >> M;

  long double omega_h = (2 * pi) / (12 * 60), omega_m = 2 * pi / 60, ans;

  int time = H * 60 + M;

  long double h = time * omega_h, m = (time % 60) * omega_m;

  long double diff = abs(m - h);

  if(diff > pi) diff = 2 * pi - diff;
  

  if(diff == pi){
    ans = A + B;
  }else{
    ans = sqrt(A*A + B*B - 2 * A * B * cos(diff));
  }



  cout << setprecision(20) << ans << endl;  // For double
}

Measured memory_bytes: 4104
H, W = map(int, input().split())
ans = 10**18

if H%3==0:
    ans = min(ans, 0)
else:
    ans = min(ans, W)

for i in range(1, H):
    S1 = i*W
    
    if W%2==0:
        S2 = (H-i)*(W//2)
        S3 = S2
    else:
        S2 = (H-i)*(W//2+1)
        S3 = H*W-S1-S2
    
    ans = min(ans, max(S1, S2, S3)-min(S1, S2, S3))

H, W = W, H

if H%3==0:
    ans = min(ans, 0)
else:
    ans = min(ans, W)

for i in range(1, H):
    S1 = i*W
    
    if W%2==0:
        S2 = (H-i)*(W//2)
        S3 = S2
    else:
        S2 = (H-i)*(W//2+1)
        S3 = H*W-S1-S2
    
    ans = min(ans, max(S1, S2, S3)-min(S1, S2, S3))

print(ans)

Measured memory_bytes: 40304
#include <bits/stdc++.h>
 
#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned long long
#define rep(i,n,N) for(ll i=n;i<=N;++i)
#define rap(i,n,N) for(ll i=n;i>=N;--i)
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define ff fi.fi
#define fs fi.se
#define sf se.fi
#define ss se.se
#define lc (id<<1)
#define rc ((id<<1)|1)
#define db(x) cout << ">>>>>> " << #x << " -> " << x << endl;
#define all(x) x.begin(),x.end()
#define pii pair<int,int> 
#define pll pair<ll,ll>
#define piii pair<int,pii>
#define plll pair<ll,pii>
#define piiii pair<pii,pii>
#define psi pair<string,int>
//#define endl "\n"
const int MAX = 8e2+5;
const ll MAX2 = 11;
const ll MOD = 1000000007;
const ll INF = 1e18;
const int dr[]={1,0,-1,0,1,1,-1,-1,0};
const int dc[]={0,1,0,-1,1,-1,1,-1,0};
const double pi = acos(-1);
const double EPS = 1e-9;
const int block = 450;

int n,m,k,a,b,vis[MAX][MAX],nr,nc,gb;
char x[MAX][MAX];
queue<pii> q;

inline bool inside(int r,int c){
	return r>0&&c>0&&r<=n&&c<=m;
}

int main(){
//	cout<<fixed<<setprecision(15);
//    freopen("input.txt", "r", stdin);
//	freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n>>m>>k;
    rep(i,1,n)rep(j,1,m){
    	cin>>x[i][j];
    	if(x[i][j]=='S')a = i, b = j;
	}
	memset(vis,-1,sizeof vis);
	vis[a][b] = 0;
	q.push({a,b});
    while(!q.empty()){
    	a = q.front().fi, b = q.front().se; q.pop();
    	if(a==1||a==n||b==1||b==m)return cout<<(vis[a][b]+k-1)/k<<endl,0;
    	if(vis[a][b]==k)continue;
		rep(i,0,3){
			nr = a+dr[i], nc = b+dc[i];
			if(!inside(nr,nc))continue;
			if(vis[nr][nc]!=-1)continue;
			if(x[nr][nc]=='#')continue;
			vis[nr][nc] = vis[a][b]+1;
			q.push({nr,nc});
		}
	}
	rep(i,1,n)rep(j,1,m)if(vis[i][j]!=-1)vis[i][j] = k, q.push({i,j});
	
    while(!q.empty()){
    	a = q.front().fi, b = q.front().se; q.pop();
    	if(a==1||a==n||b==1||b==m)return cout<<(vis[a][b]+k-1)/k<<endl,0;
		rep(i,0,3){
			nr = a+dr[i], nc = b+dc[i];
			if(!inside(nr,nc))continue;
			if(vis[nr][nc]!=-1)continue;
			vis[nr][nc] = vis[a][b]+1;
			q.push({nr,nc});
		}
	}
	return 0;
}

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

using namespace std;

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

  int n, a;
  cin >> n;
  map<int, int> hash;
  for (int i = 0; i < n; ++i) {
    cin >> a;
    hash[a] = (hash[a] > 0 ? 0 : 1);
  }
  int res = 0;
  for (auto &h: hash) res += h.second;
  cout << res << endl;

  return 0;
}



Measured memory_bytes: 4992
import copy
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(b)]
s,t=map(int,input().split())
s=3*s
t=3*t
dd=[[]for i in range(a+1)]
for i in range(b):
  da=c[i][0]
  db=c[i][1]
  dd[da].append(db)
  

d=[[]for i in range(3*(a+1))]
for i in range(len(dd)):
  for j in dd[i]:
      d[3*i].append(3*j+1)
      d[3*i+1].append(3*j+2)
      d[3*i+2].append(3*j)
e=[-1 for i in range(3*a+3)]
f=[s]
h=0
for i in range(1,3*a+3):
  g=[]
  for j in f:
    for k in d[j]:
      if e[k]==-1:
        e[k]=1
        g.append(k)
        if k==t:
          print(i//3)
          h=1
          break
    if h==1:
      break
  if h==1:
    break
  if g==[]:
    print(-1)
    break
  f=copy.copy(g)

Measured memory_bytes: 82524
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 998244353
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
signed main(){
	int n;
	cin>>n;
	if( n % 2 == 1 ){
		cout<< n/2 << endl;
	}
	else{
		cout<< n/2 - 1 <<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		if(A <= 8 && B <= 8) {
			System.out.println("Yay!");
			return;
		}

		System.out.println(":(");

	}

}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;
const int MAXN = 500005;

int n, dp[27][MAXN];
int nxt[19][MAXN];
char str[MAXN];

int main(){
	scanf("%s", str + 1);
	n = strlen(str + 1);
	for(int i=0; i<27; i++) dp[i][n+1] = -1;
	for(int j=n; j; j--){
		for(int i=0; i<27; i++){
			if(str[j] == i + 'a') dp[i][j] = j+1;
			else if(i && dp[i-1][j] != -1) dp[i][j] = dp[i-1][dp[i-1][j]];
			else dp[i][j] = -1;
		}
		if(dp[26][j] != -1){
			for(int i=0; i<26; i++){
				if(dp[i][j] == -1) dp[i][j] = dp[i][dp[26][j]];
			}
		}
	}
	for(int i=1; i<=n+1; i++){
		if(dp[26][i] == -1) nxt[0][i] = i;
		else nxt[0][i] = dp[26][i];
	}
	for(int i=1; i<19; i++){
		for(int j=1; j<=n+1; j++){
			nxt[i][j] = nxt[i-1][nxt[i-1][j]];
		}
	}
	int q;
	scanf("%d",&q);
	while(q--){
		int l, r;
		scanf("%d %d",&l, &r);
		for(int i=18; i>=0; i--){
			if(nxt[i][l] <= r) l = nxt[i][l];
		}
		l = nxt[0][l];
		puts(l == r+1 ? "Yes" : "No");
	}
}


Measured memory_bytes: 91008
import java.util.Scanner;
public class Main {
	 public static void main(String[] args) {
		 Scanner sc = new Scanner(System.in);
	        while(true){
	        

	            int  a = sc.nextInt();
	            String op=sc.next();
	            int b=sc.nextInt();
	            
	            if(op.equals("?"))break;
	             int an=0;
	            switch(op) {
	            case"+":
	            	an=a+b;
	            	break;
	            case"-":
	            	an=a-b;
	            	break;
	            case"*":
	            	an=a*b;
	            	break;
	            case"/":
	            	an=a/b;
	            	break;
	            }
	            System.out.printf("%d\n",an);
	            }
	            sc.close();
	    }
	}


Measured memory_bytes: 26224
Option Strict On

Module Module1

    Sub Main()
        'let'
        Dim tmp() As Long = Array.ConvertAll(Of String, Long) _
            (Console.ReadLine().Split(), AddressOf Long.Parse)
        Dim A As Long = tmp(0)
        Dim B As Long = tmp(1)

        'var'
        Dim ans As Long = -1 * Long.MaxValue

        For Each v As Long In New Long() {A + B, A - B, A * B}
            ans = Math.Max(ans, v)
        Next

        Console.WriteLine(ans)

    End Sub
End Module

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

int main() {
  int n, z, w;
  cin >> n >> z >> w;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];

  if (n == 1) cout << abs(a[0] - w) << endl;
  else cout << max(abs(a[n - 1] - w), abs(a[n - 2] - a[n - 1])) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>

using namespace std;

typedef long long ll;

#ifdef iq
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

const int M = 1e9 + 7;

int mul(int a, int b) {
  return (a * (ll) b) % M;
}

int pw(int a, int n) {
  int ret = 1;
  while (n) {
    if (n % 2 == 0) {
      a = mul(a, a);
      n /= 2;
    } else {
      ret = mul(ret, a);
      n--;
    }
  }
  return ret;
}

int inv(int x) {
  return pw(x, M - 2);
}

void add(int &a, int b) {
  a += b;
  if (a >= M) a -= M;
}

const int N = (1 << 18) + 220;

vector <pair <int, int> > f[N][2];
int sum[N][2];

int main() {
#ifdef iq
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  int h = 18;
  cin >> h;
  int n = (1 << h) - 1;
  vector <int> par(n + 1);
  vector <int> x(n + 1);
  vector <int> ix(n + 1);
  int l = (1 << (h - 1));
  x[1] = 1;
  for (int v = 1; v <= n; v++) {
    if (2 * v <= n) {
      x[2 * v] = mul(x[v], 2 * v);
    }
    if (2 * v + 1 <= n) {
      x[2 * v + 1] = mul(x[v], 2 * v + 1);
    }
  }
  for (int v = 1; v <= n; v++) {
    int t = inv(x[v]);
    ix[v] = mul(mul(t, t), v);
  }
  vector <int> p(l);
  for (int i = 0; i < l; i++) {
    cin >> p[i];
    p[i]--;
  }
  auto gen_path = [&] (int v) {
    vector <pair <int, int> > path;
    int x = v / 2;
    int was = v;
    while (true) {
      path.push_back({x, was % 2});
      was = x;
      if (x == 1) break;
      x /= 2;
    }
    return path;
  };
  for (int i = 0; i < l; i++) {
    int a = l + i;
    int b = l + p[i];
    auto A = gen_path(a);
    for (auto c : A) {
      f[c.first][c.second].push_back({b, x[a]});
      /*
      for (auto t : B) {
        ll id = c.first * (ll) (n + 1) + t.first;
        add(f[c.second][t.second][id], mul(x[a], x[b]));
      }
      */
    }
  }
  int ans = 0;
  for (int i= 1; i <= n; i++) {
    for (auto c : f[i][0]) {
      int v = c.first, val = c.second;
      int was = v;
      int cur = v / 2;
      while (true) {
        add(sum[cur][was % 2], mul(x[v], val));
        if (cur == 1) break;
        was = cur;
        cur /= 2;
      }
    }
    int s = 0;
    for (auto c : f[i][1]) {
      int v = c.first, val = c.second;
      int was = v;
      int cur = v / 2;
      while (true) {
        add(s, mul(ix[cur], mul(sum[cur][(was % 2) ^ 1], mul(x[v], val))));
        if (cur == 1) break;
        was = cur;
        cur /= 2;
      }
    }
    for (auto c : f[i][0]) {
      int v = c.first;
      while (true) {
        sum[v][0] = sum[v][1] = 0;
        if (v == 1) break;
        v /= 2;
      }
    }
    add(ans, mul(s, ix[i]));
  }
  cout << ans << '\n';
}


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

using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define all(v) v.begin(),v.end()
#define ve vector
#define vi vector<int>
#define vi2 vector<vi>
#define vl vector<long long>
#define vl2 vector<vl>

template <class T> T maxAny(T a, T b){
    if(a > b) return a;
    else return b;
}

template <class T> T minAny(T a, T b){
    if(a > b) return b;
    else return a;
}

int main(){
    string s, t;
    int ans = 0;
    cin >> s >> t;
    rep(i, s.size()){
        if(s[i] != t[i]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3856
from math import *
from itertools import combinations

n = int(input())
s = [input() for _ in range(n)]
s = list(map(lambda x: x[0], s))
s = list(filter(lambda x: x in 'MARCH', s))
t = {}
for x in range(len(s)):
  if s[x] in t: t[s[x]] += 1
  else: t[s[x]] = 1
t = list(t.values())
a = 0
for c in combinations(t, 3):
  m = 1
  for e in c:
    m *= e
  a += m
print(a)


Measured memory_bytes: 10668
# https://misteer.hatenablog.com/entry/AGC004-B

def main():
    N, X = map(int, input().split())
    *A, = map(int, input().split())
    C = A.copy()

    ret = sum(A)
    for magic_count in range(N):
        for slime_idx in range(N):
            C[slime_idx] = min(C[slime_idx], A[slime_idx - magic_count])
            # -magic_countで遡るコストは、Cではなく、A
            # Cだと更に-magic_count程度さかのぼったコストになってしまう
        ret = min(ret, sum(C) + X * magic_count)
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
my $s = <STDIN>;
$s =~ s/[\x00-\x20]+$//ios;
my $q = scalar(<STDIN>) - 0;
my $dir = 0;
my @add = ('','');
for(my $i=0;$i<$q;$i++){
  my @a = split(/\s+/,scalar(<STDIN>));
  if( $a[0] - 0 == 1 ){
    $dir ^= 1;
  }
  if( $a[0] - 0 == 2 ){
    my $j = ( (( $dir == 0 and $a[1] - 0 == 1 ) or ( $dir == 1 and $a[1] - 0 == 2 )) ? 0 : 1 );
    $add[$j] .= $a[2];
  }
}
for(my $i=0;$i<length($add[$dir]);$i++){
  print substr($add[$dir],length($add[$dir])-$i-1,1);
}
my $ss = ($dir == 1 ? reverse $s : $s);
print "$ss";

for(my $i=0;$i<length($add[1 ^ $dir]);$i++){
  print substr($add[1 ^ $dir],$i,1);
}
print "\n";


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

struct nen {
	char c[7];
	int y,m,d;
};

int main() {
	nen n[4]={{"heisei",1989,1,8},{"showa",1926,12,25},{"taisho",1912,7,30},{"meiji",1868,9,8}};
    int y,m,d,i;
	while(cin >> y >> m >> d) {
		for (i=0;i<4;i++) if (n[i].y*100+n[i].m*10+n[i].d<=y*100+m*10+d) break;
		if (i<4) cout << n[i].c << ' ' << y-n[i].y+1 << ' ' << m << ' ' << d << endl; else cout << "pre-meiji" << endl;
	}
return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	string s; cin >> s;
	int n = s.size(), len;
	if(n % 2){
		int c = n / 2;
		for(len = 1; c - len >= 0 && s[c - len] == s[c] && s[c] == s[c + len]; len++);
		len = len * 2 - 1;
	}
	else{
		int r = n / 2, l = r - 1;
		for(len = 0; l >= len && s[r + len] == s[l - len]; len++);
		len *= 2;
	}
	dbg(len);
	cout << (n + len) / 2 << endl;
	
	return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;
const int pt = 1e9 + 7;
int n, m;
long long ans, ant, sum;
int main(){
	ans = ant = 1;
	scanf("%d%d", &n, &m);
	if(abs(n - m) >= 2)printf("0\n");
	else{
		for(int i = 1; i <= n; i++)ans = ans * i % pt;
		for(int i = 1; i <= m; i++)ant = ant * i % pt;
		if(n == m){
			sum = ((ans * ant) % pt * 2) % pt;
		}
		else sum = ans * ant % pt;
		printf("%lld\n", sum);
	}
}

Measured memory_bytes: 128
#include<stdio.h>

int main(){
	int s;
	
	scanf("%d",&s);
	
	if(s%10 == 2 || s%10 == 4 || s%10 == 5 || s%10 == 7 || s%10 == 9){
		printf("hon");
	}
	else if(s%10 == 0 || s%10 == 1 || s%10 == 6 || s%10 == 8){
		printf("pon");
	}
	else if(s%10 == 3){
		printf("bon");
	}
}

Measured memory_bytes: 1728
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main{



	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int n        = Integer.parseInt(scanner.nextLine());
		String[] tmp = scanner.nextLine().split(" ");
		int[] list   = new int[n];
		int ans    	 = 0;

		for(int i = 0; i < n; i++) {
			list[i] = Integer.parseInt(tmp[i]);
		}


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

			int r   = i;
			int min = Integer.MAX_VALUE;

			while(list[i] != 0) {
				while(r < n && list[r] != 0) {

					min = Math.min(min, list[r]);
					r++;
				}

				for(int k = i; k < r; k++) {

					list[k] -= min;
				}

				ans += min;
				r = i;
			}

		}

		System.out.println(ans);
	}
}


Measured memory_bytes: 35792
#include<stdio.h>
#include<string.h>
#define MAX(x,y) (((x)>(y))?(x):(y))

int count(int x,int y){
	int i,c=0;
	for(i=0;i<16;i++)if(((x>>i)&1)==1 && ((y>>i)&1)==1)c++;
	return c;
}
int dp[32][(1<<16)+1];
int a[33],b[33];
int main(){
	int i,j,n,c,k,f,cb;
	int ans;
	while(1){
		scanf("%d%d",&n,&c);
		if(n==0 && c==0)break;
		
		for(i=0;i<n;i++){
			a[i]=0;
			for(j=0;j<16;j++){
				scanf("%d",&f);
				a[i]|=(1<<j)*f;
			}
		}
		for(i=0;i<c;i++){
			b[i]=0;
			for(j=0;j<16;j++){
				scanf("%d",&f);
				b[i]|=(1<<j)*f;
			}
		}

		b[c]=0;c++;
		for(i=0;i<n+1;i++)for(j=0;j<(1<<16);j++)dp[i][j]=-1;
		
		dp[0][0]=0;
		for(i=0;i<n;i++){
			for(j=0;j<(1<<16);j++){
				if(dp[i][j]<0)continue;
				cb=j|a[i];
				for(k=0;k<c;k++){
                    dp[i+1][cb&(~b[k])]
						=MAX(dp[i+1][cb&(~b[k])],dp[i][j]+count(cb,b[k]));
				}
			}
		}

		ans=0;
		for(j=0;j<(1<<16);j++)ans=MAX(ans,dp[n][j]);
		printf("%d\n",ans);

	}
	return 0;
}

Measured memory_bytes: 8788
use std::cmp;
use std::fmt::Debug;
use std::str::FromStr;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where
    T: FromStr,
    <T as FromStr>::Err: Debug,
{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim()
        .split_whitespace()
        .map(|c| T::from_str(c).unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_as_string() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main() {
    let line = read_as_vec::<u64>();
    let (mut red, mut green, mut blue) = (line[0], line[1], line[2]);
    let k = read_as_vec::<usize>()[0];

    //red < green < blue
    let mut op_counter = 0;
    while red >= green {
        if op_counter == k {
            println!("No");
            return;
        }
        green *= 2;
        op_counter += 1;
    }
    //println!("{}, {}, {}", red, green, blue);
    while green >= blue {
        if op_counter == k {
            println!("No");
            return;
        }
        blue *= 2;
        op_counter += 1;
    }

    println!("Yes");
}


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

#define FOR(i,a,n) for (int i = a; i < (int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define whole(f,x,...) ([&](decltype((x)) whole) { \
    return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
template<typename T> bool chmin(T &a, const T &b) {if (a > b) { a = b; return true; }return false;}
template<typename T> bool chmax(T &a, const T &b) {if (a < b) { a = b; return true; }return false;}

using ll = int_fast64_t;

constexpr ll INF = (1e9);
constexpr ll MOD = (1e9+7);

int main() {
  int n; cin >> n;
  vector<int> a(n); REP(i,n) cin >> a[i];
  whole(sort, a);
  a.erase(whole(unique, a), a.end());
  if (a.size()%2 == 0) cout << a.size()-1 << endl;
  else cout << a.size() << endl;
  return 0;
}


Measured memory_bytes: 640
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 100000007
#define SIZE 10005
#define PI 	3.14159265358979323846


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int s;
    cin >> s;
    cout << 48-s << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;
constexpr long long int INF = std::numeric_limits<long long int>::max();
constexpr long long int NINF = std::numeric_limits<long long int>::min();
#define int long long int

int x[200], y[200], h[200];

void solve() {
  int N;
  cin >> N;

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

  for (int i = 0; i <= 100; i++) {
    for (int j = 0; j <= 100; j++) {
      int H;
      for (int p = 0; p < N; p++) {
        if (h[p] >= 1) {
          H = h[p] + abs(x[p] - i) + abs(y[p] - j);
          break;
        }
      }

      bool ok = true;
      for (int p = 0; p < N; p++) {
        int a = max(H - abs(x[p] - i) - abs(y[p] - j), (int)0);
        if (a != h[p]) {
          ok = false;
          break;
        }
      }

      if (ok) {
        printf("%lld %lld %lld\n", i, j, H);
        return;
      }
    }
  }
}

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


Measured memory_bytes: 256
a,b = map(int,input().split())

def search_cycle(k):
    return 1 << (k+1)

def func(x): #bitの性質上、x-1までのXORを求める
    if x == 0:
        return 0
    ans = 0
    for i in range(40):
        loop = search_cycle(i)
        count = (x//loop)*(loop//2)
        amari = max(0,x%loop-loop//2)
        count += amari

        if count %2 != 0:
            ans += 1 << i
    return ans

print(func(b+1)^func(a))

Measured memory_bytes: 38384
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn solve(n: i32) -> bool {
    for i in 0..26 {
        for j in 0..15 {
            if i*4 + j*7 == n{
                return true
            }
        }
    }
    false
}

fn main() {
    let n = read::<i32>();

    println!("{}", if solve(n) {"Yes"} else {"No"});
}


Measured memory_bytes: 4352
#include <stdio.h>

int main(void){
long double a,b,c,d;
scanf("%Lf %Lf %Lf",&a,&b,&c);
d = c - a - b;
if (d > 0 && d * d > 4 * a * b)
{
printf( "Yes" );
}
 else
{
printf( "No" );
}
 return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<algorithm>
using namespace std;

const int maxn=1000+10;
int a[maxn];

int main()
{
    int i,j,n,m,sum=0;
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++){
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    int cnt=0;
    for(i=1;i<=n;i++){
        if(a[i]*4*m>=sum)
            cnt++;
    }
    if(cnt>=m)
        puts("Yes");
    else
        puts("No");
    return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <cstring>
#include <cmath>
#include <iomanip>
using namespace std;

int main()
{
	int a[200]={0};
	int n;
	cin>>n;
	for(int i=0;i<2*n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<2*n;+i++)
	{
		for(int j=0;j<2*n;j++)
		{
			if(a[i]<a[j])
			{
				int b=0;
				b=a[i];
				a[i]=a[j];
				a[j]=b;		
			}		
		}
	}
	int add=0;
	for(int i=0;i<2*n;i++)
	{
		add+=a[i];
		i++;
	}
	cout <<add;
	return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<utility>
#include<cmath>
#include<assert.h>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<complex>

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound


signed main() {
    int N;
    cin >> N;
    if (N == 3) {
        cout << "2 5 63" << endl;
        return 0;
    } else if (N == 4) {
        cout << "2 5 20 63" << endl;
        return 0;
    }
    int cnt3 = 0;
    for (int i = 3; i <= 30000; i += 6) {
        cout << i << " ";
        cnt3++;
        if (cnt3 % 2 == 0 && cnt3 + 15000 >= N)break;
    }
    int cnt2 = 0;
    for (int i = 2; i <= 30000; i += 2) {
        if (i % 3 == 0)continue;
        cout << i << " ";
        cnt2++;
        if (cnt2 % 2 == 0 && cnt2 + cnt3 + 5000 >= N)break;
    }
    int cnt6 = 0;
    for (int i = 6; i <= 30000 && cnt2 + cnt3 + cnt6 <= N; i += 6) {
        cout << i;
        cnt6++;
        if (cnt2 + cnt3 + cnt6 < N)cout << " ";
        else {
            cout << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define ff first
#define ss second
#define pb push_back
#define N 505


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	string s;
	cin >> s;
	int n = s.size();
	int ans = 0;
	for (int i = 1; i < n; ++i)
	{
		if(s[i] == s[i - 1])
			s[i] = (s[i] == '0') ? '1' : '0', ans++;
	}
	cout << ans << "\n";
	return 0;
}

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

using namespace std;

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

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

typedef long long ll;
const double EPS = 1e-8;
const double INF = 1e48;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
double speed(double w){
  return 2000.0 / (70 + w);
}

int main(){
  int N;
  string ID[16];
  double dist[16];
  double weight[16];
  while(cin >> N){
    REP(i, N){
      cin >> ID[i] >> dist[i] >> weight[i];
      weight[i] *= 20;
    }
    static double dp[1 << 16][16] = {};
    static int prev[1 << 16][16] = {};
    REP(i, 1 << N) REP(j, N) dp[i][j] = INF;
    REP(i, 1 << N) REP(j, N) prev[i][j] = -1;
    REP(i, N) dp[1 << i][i] = dist[i] / speed(0);
    REP(S, 1 << N)REP(i, N) if(S >> i & 1) {
      double w = 0;
      REP(j, N) if(S >> j & 1) w += weight[j];
      REP(j, N) if(0 == (S >> j & 1)){
        if(dp[S | 1 << j][j] > dp[S][i] + abs(dist[i] - dist[j]) / speed(w)){
          dp[S | 1 << j][j] = dp[S][i] + abs(dist[i] - dist[j]) / speed(w);
          prev[S | 1 << j][j] = i;
        }
      }
    }
    int min_i = 0;
    REP(i, N) if(dp[(1 << N) - 1][min_i] > dp[(1 << N) - 1][i]) min_i = i;
    int cur_S = (1 << N) - 1;
    int cur_i = min_i;
    vector<string> ans;
    while(cur_i != -1){
      ans.push_back(ID[cur_i]);
      cur_S = cur_S & ~(1 << cur_i);
      cur_i = prev[cur_S | 1 << cur_i][cur_i];
    }
    reverse(ans.begin(), ans.end());
    REP(i, ans.size()){
      cout << ans[i];
      if(i != ans.size() - 1) cout << " ";
      else cout << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 11460
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const int MOD = 1000000007;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
void inline swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
void inline swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }

vector<vector<int>> g;
int n, m;
vector<pair<int, int>> bridge;
vector<int> articulation;

vector<bool> visited;
vector<int> ord;
vector<int> low;


void init()
{
	cin >> n >> m;

	g.resize(n);

	REP(i, m)
	{
		int a, b; cin >> a >> b; --a; --b;

		g[a].push_back(b);
		g[b].push_back(a);
	}

	visited.resize(n, false);
	ord.resize(n, -1);
	low.resize(n, -1);
}

template <class T>
void lowlink(const T v, const T par, int k = 0)
{
	ord[v] = low[v] = k;
	visited[v] = true;

	bool is_articulation = false;
	int cnt = 0;

	for (T adj : g[v])
	{
		if (!visited[adj])
		{
			++cnt;
			lowlink(adj, v, k + 1);
			low[v] = min(low[v], low[adj]);

			is_articulation |= (~par) && (ord[v] <= low[adj]);

			if (ord[v] < low[adj])
				bridge.emplace_back(minmax(v, adj));
		}
		else if (adj != par)
		{
			low[v] = min(low[v], ord[adj]);
		}
	}

	is_articulation |= (par == -1) && (cnt > 1);
	if (is_articulation)
		articulation.PB(v);
}

int main()
{
	init();

	lowlink(0, -1);

	cout << bridge.size() << endl;


}

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

using namespace std;

typedef long long int64;
const int64 INF = 1LL << 59;

struct edge
{
  int u, v, cost;
};

int main()
{
  int N, M;
  cin >> N >> M;
  vector< edge > edges(M);
  for(auto &e : edges) {
    cin >> e.u >> e.v >> e.cost;
    --e.u, --e.v;
  }
  vector< int64 > v(N, -INF), last(N, -1);
  v[0] = 0;
  for(int i = 0; i < 2 * N; i++) {
    for(auto &e : edges) {
      if(v[e.u] == -INF) continue;
      if(v[e.u] + e.cost > v[e.v]) {
        v[e.v] = v[e.u] + e.cost;
        last[e.v] = i;
      }
    }
  }
  if(last[N - 1] >= N) cout << "inf" << endl;
  else cout << v[N - 1] << endl;
  
}

Measured memory_bytes: 256
from sys import stdin


input = stdin.readline


class UnionFind:
  def __init__(self, n):
    self.par = [i for i in range(n)]
    self.size = [1] * n
    
  def unite(self, a, b):
    a = self.find(a)
    b = self.find(b)
    if a != b:
      if self.size[a] < self.size[b]:
        a, b = b, a
      self.size[a] += self.size[b]
      self.par[b] = a
      
  def is_same(self, a, b):
    return self.find(a) == self.find(b)
  
  def size_of(self, a):
    return self.size[self.find(a)]
    
  def find(self, a):
    if a == self.par[a]:
      return a
    self.par[a] = self.find(self.par[a])
    return self.par[a]
  
   
N, M, K = map(int, input().split())
relation = UnionFind(N)

num_friends = [0] * N

for _ in range(M):
  a, b = map(lambda x: int(x) - 1, input().split())
  relation.unite(a, b)
  num_friends[a] += 1
  num_friends[b] += 1
  
# 所属するグループ - 友達 - 自分
num_candidates = [
  relation.size_of(i) - num_friends[i] - 1 
  for i in range(N)
]
  
for _ in range(K):
  a, b = map(lambda x: int(x) - 1, input().split())
  # ブロック関係かつ同じグループなら友達候補から除く
  if relation.is_same(a, b):
    num_candidates[a] -= 1
    num_candidates[b] -= 1
  
print(' '.join(str(num) for num in num_candidates))


Measured memory_bytes: 19504
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

type pair struct {
	x int
	y int
}

func main() {
	nextReader = newScanner()
	h, w := nextInt(), nextInt()
	ss := make([][]string, h)
	for i := 0; i < h; i++ {
		ss[i] = strings.Split(nextString(), "")
	}
	ans := 0
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if ss[i][j] == "#" {
				continue
			}
			a := bfs(ss, i, j, w, h)
			if ans < a {
				ans = a
			}
		}
	}
	fmt.Println(ans)
}

func bfs(ss [][]string, x, y, w, h int) int {
	q := make([]pair, 0)
	q = append(q, pair{x: x, y: y})

	dist := make([][]int, h)
	for i := range dist {
		dist[i] = make([]int, w)
		for ii := range dist[i] {
			dist[i][ii] = -1
		}
	}
	dist[x][y] = 0

	max := 0
	for len(q) > 0 {
		current := q[0]
		q = q[1:] // pop

		for _, next := range []pair{pair{-1, 0}, pair{1, 0}, pair{0, -1}, pair{0, 1}} {
			xx := current.x + next.x
			yy := current.y + next.y
			if xx >= 0 && xx < h && yy >= 0 && yy < w {
				if dist[xx][yy] != -1 {
					continue
				}
				if ss[xx][yy] == "#" {
					continue
				}
				dist[xx][yy] = dist[current.x][current.y] + 1
				if dist[xx][yy] > max {
					max = dist[xx][yy]
				}
				q = append(q, pair{x: xx, y: yy})
			}
		}
	}
	return max
}

// ---------------------------------------------------------------
// I/O
// ---------------------------------------------------------------
var nextReader func() string

func newScanner() func() string {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, 1024), int(1e11))
	sc.Split(bufio.ScanWords)
	return func() string {
		sc.Scan()
		return sc.Text()
	}
}

func nextString() string { return nextReader() }

func nextInt() int { n, _ := strconv.Atoi(nextReader()); return n }

func nextInts(size int) []int {
	ns := make([]int, size)
	for i := 0; i < size; i++ {
		ns[i] = nextInt()
	}
	return ns
}


Measured memory_bytes: 5504
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &in, vector<T> &vec) {
    for (auto &e : vec) in >> e;
    return in;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

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

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

    int N;
    string s;
    read(N, s);

    int cnt[128] {};
    rep(i, N) {
        cnt[s[i]] += 1;
    }

    i64 ans = 1;
    reps(ch, 'a', 'z') {
        ans *= cnt[ch] + 1;
        ans %= MOD;
    }

    print(ans - 1);

    return 0;
}


Measured memory_bytes: 512