akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm> 
#include <queue>
#include <functional>
#include <map>
#include <string>
using namespace std;
typedef long long ll;

int n;
int a[100005];
int b[100005];
int c[100005];

int upper_bound(int k){
    int lb = -1, ub = n;

    while (ub - lb > 1){
        int mid = (lb + ub) / 2;
        if (a[mid] < b[k]){
            lb = mid;
        }
        else{
            ub = mid;
        }
    }
    return lb;
}

int lower_bound(int k){
    int lb = -1, ub = n;

    while (ub - lb > 1){
        int mid = (lb + ub) / 2;
        if (c[mid] > b[k]){
            ub = mid;
        }
        else{
            lb = mid;
        }
    }
    return ub;
}


int main(void){

    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    for (int i = 0; i < n; i++){
        cin >> b[i];
    }
    for (int i = 0; i < n; i++){
        cin >> c[i];
    }

    sort(a, a + n);
    sort(b, b + n);
    sort(c, c + n);

    ll ans = 0;
    for (int k = 0; k < n; k++){
        ll sa = upper_bound(k);
        ll sc = lower_bound(k);
        ans += (sa + 1)*(n - sc);
    }

    cout << ans << endl;

    

}

Measured memory_bytes: 1536
import numpy as np
import sys
from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

d = {b"U": 0, b"R": 1, b"D": 2, b"L": 3}


def f(x):
    if x in d.keys():
        return d[x]
    return int(x) - 100000


INF = 10 ** 18
n = int(readline())
inp = np.array(list(map(f, read().split())), np.int64)
x = inp[::3]
y = inp[1::3]
u = inp[2::3]


def ur(x, y, u):
    UX = x[u == 0]
    UY = y[u == 0]
    RX = x[u == 1]
    RY = y[u == 1]

    dct = defaultdict(list)
    for ex, ey in zip(UX, UY):
        dct[ex+ey].append([ey, 0])
    for ex, ey in zip(RX, RY):
        dct[ex+ey].append([ey, 1])

    ret = INF
    for v in dct.values():
        vv = sorted(v)
        for (e1, d1), (e2, d2) in zip(vv, vv[1:]):
            if d1 == 0 and d2 == 1:
                ret = min(ret, (e2 - e1) * 10)

    return ret


def ud(x, y, u):
    UX = x[u == 0]
    UY = y[u == 0]
    DX = x[u == 2]
    DY = y[u == 2]

    dct = defaultdict(list)
    for ex, ey in zip(UX, UY):
        dct[ex].append([ey, 0])
    for ex, ey in zip(DX, DY):
        dct[ex].append([ey, 2])

    ret = INF
    for v in dct.values():
        vv = sorted(v)
        for (e1, d1), (e2, d2) in zip(vv, vv[1:]):
            if d1 == 0 and d2 == 2:
                ret = min(ret, (e2 - e1) * 5)

    return ret


def transpose(x, y, u):
    x, y = y, -x
    u = (u + 1) % 4
    return x, y, u


ans = INF
for _ in range(4):
    ans = min(ans, ur(x, y, u), ud(x, y, u))
    x, y, u = transpose(x, y, u)

if ans == INF:
    print("SAFE")
else:
    print(ans)


Measured memory_bytes: 107108
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
//combination(Nが小さい時はこれを使う
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}

// 二項係数計算
long long COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

//繰り返し二乗法（Nが大きい時の場合のcombination)
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= (i % mod); res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
//UnionFind
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
int dight(int n) {
	int ans = 1;
	while (n >= 10) {
		n /= 10;
		ans++;
	}
	return ans;
}
int dight_sum(int n) {
	int sum = 0;
	rep(i, 20)sum += (n % (int)pow(10, i + 1)) / (pow(10, i));
	return sum;
}
int dight_min(int n) {
	int ans = 9;
	while (n >= 10) {
		ans = min(ans, n % 10);
		n /= 10;
	}
	ans = min(ans, n);
	return ans;
}
int dight_max(int n) {
	int ans = 0;
	while (n >= 10) {
		ans = max(ans, n % 10);
		n /= 10;
	}
	ans = max(ans, n);
	return ans;
}
signed main() {
	int s;
	cin >> s;
	cout << s / 3600 << ':' << (s % 3600) / 60 << ':' << (s % 60) << endl;
	ggr
}



Measured memory_bytes: 3096
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fr first
#define sc second
typedef long long ll;
const long long llinf=LLONG_MAX;
const int inf=INT_MAX;
const int nmax=1e5+5;
const int mod=1e9+7;
using namespace std;
int ans,n,a,b,mn=inf,mx=0,mns=inf,mxs=0,gmt;
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin>>n;
    for(int i=0;i<n;i++)
        {
            cin>>a>>b;
            if(a<mn) mn=a;
            if(a>mx) mx=a;
            if(b<mns) mns=b;
            if(b>mxs) mxs=b;
        }
    if(mns!=0) gmt=mns;
    ans=((mx-mn)+1)+(mn-1)+mns;
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int m,n,a,b;
char c[1005][1005];
int main()
{
    scanf("%d%d%d%d",&m,&n,&a,&b);
    for(int i=1; i<=m; i++)
        for(int j=1; j<=n; j++)c[i][j]='.';
    if(n&1)
    {
        for(int i=1; i<m&&b; i+=2)
            c[i][n]='^',c[i+1][n]='v',b--;
    }
    if((b&1)&&(m&1)&&n>2&&m>1)
        c[m-1][n-2]='^',c[m][n-2]='v',b--;
    for(int i=1; i<m; i++)
        for (int j=1; j<=n-(n&1)&&b; j++)
            if(c[i][j]=='.'&&c[i+1][j]=='.')
                c[i][j]='^',c[i+1][j]='v',b--;
    for(int i=1; i<=m; i++)
        for(int j=1; j<n&&a; j++)
            if(c[i][j]=='.'&&c[i][j+1]=='.')
                c[i][j]='<',c[i][j+1]='>',a--;
    if(a||b)
        puts("NO");
    else
    {
        puts("YES");
        for(int i=1; i<=m; i++)printf("%s\n",c[i]+1);
    }
    return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
  int a[3][3];
  for(int i=0;i<3;i++)
  {
    for(int j=0;j<3;j++)
    {
      cin>>a[i][j];
    }
  }
  int n;
  cin>>n;
  int b[n];
  for(int k=0;k<n;k++)
  {
    cin>>b[k];
    for(int i=0;i<3;i++)
  {
    for(int j=0;j<3;j++)
    {
      if(b[k]==a[i][j])
        a[i][j]=-1;         
    }
  }
  }
  for(int i=0;i<3;i++)
  {
    if((a[i][0]==-1 && a[i][1]==-1 && a[i][2]==-1) || (a[0][i]==-1 && a[1][i]==-1 && a[2][i]==-1))
    {
      cout<<"Yes";
      return 0;
    }
  }
  if((a[0][0]==-1 && a[1][1]==-1 && a[2][2]==-1)|| (a[0][2]==-1 && a[1][1]==-1 && a[2][0]==-1) )
  {
     cout<<"Yes";
     return 0;
      
  }
     cout<<"No";
     return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define Test int t;cin>>t;while(t--)
using namespace std;
const int dx[]={-1,-1,-1,0,0,0,1,1,1};
const int dy[]={-1,0,1,-1,0,1,-1,0,1};
void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int a[200001];
int main()
{
    fast();
    double r;
    cin>>r;
    const double PI=3.1415926535897931;
    cout<<fixed<<setprecision(9)<<PI*2*r;
    return 0;
}

Measured memory_bytes: 3800
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {
	public static void main(String[] args) { 
		/*First ever A, last ever Z */
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		int x = I.nextInt();
		O.pln(x<1200?"ABC":"ARC");
	}
	public static double max(double a, double b) {return Math.max(a, b);}
	public static double min(double a, double b) {return Math.min(a, b);}
	public static long min(long a, long b) {return Math.min(a,b);}
	public static long max(long a, long b) {return Math.max(a,b);}
	public static int min(int a, int b) {return Math.min(a,b);}
	public static int max(int a, int b) {return Math.max(a,b);}
	public static long abs(long x) {return Math.abs(x);}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return max(a,b);
		return GCD(min(a,b),max(a,b)%min(a,b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	public static int pop(long x) { //Returns number of bits within a number
		int cnt = 0;
		while (x>0) {
			if (x%2==1) cnt++;
			x/=2;
		}
		return cnt;
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
		double nextDouble() {return Double.parseDouble(next());}
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(double x) {w.println(x);w.flush();}
		void pln(boolean x) {w.println(x);w.flush();}
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void pln(BigInteger x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
		void p(BigInteger x) {w.print(x);w.flush();}
		void p(double x) {w.print(x);w.flush();}
		void p(boolean x) {w.print(x);w.flush();}
	}
}

Measured memory_bytes: 25552
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll ans,n,m;
    cin >>n>>m;
    bool a[n+1];//a[i]段目が壊れているならfalse
    for(int i=0;i<=n;i++){
        a[i]=true;
    }
    for(int i=0;i<m;i++){
        ll v;
        cin >>v;
        a[v]=false;
    }
    ll a_1=0;
    ll a_0=1;
    ll a_m1=0;
    for(int i=0;i<n;i++){
        a_1=(a[i+1])?((a_m1+a_0)%MAX):(0);//(((a[i-1])?(a_m1):(0))+((a[i])?(a_0):(0)))%MAX:0;
        a_m1=a_0;
        a_0=a_1;
//        cout <<a_1<<" "<<a_0<<" "<<a_m1;
//        if(!a[i])cout <<" broken";
//        cout <<endl;
    }

    ans=a_1;

    cout <<ans<<endl;

    return 0;

}

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod (int)(1e9 +7);

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef string ss;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

    ll n,k;
    vll a;

bool dfs(ll i,ll sum)
{
    cout << '(' << i << ',' << sum << ')' << endl;
    if(i == n)return sum == k;

    if(dfs(i+1,sum))return true;

    if(dfs(i+1,sum + a[i]))return true;

    return false;
}

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

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int a,b,c;
	
	scanf("%d %d %d",&a,&b,&c);
	
	if (a+b == c || a+c == b || b+c == a) {
		printf("Yes\n");
	} else{
		printf("No\n");
	}
	
	return 0;
}


Measured memory_bytes: 128
K=int(input())

if K==1:
    print(1)
    exit()
if K==7:
    print(1)
    exit()
ans=1
MOD=set()

cur=7
while True:
    if cur==0:
        print(ans)
        exit()
    else:
        r=cur%K
        if r in MOD:
            print(-1)
            exit()
        else:
            MOD.add(r)
        cur=(cur*10+7)%K
        ans+=1




Measured memory_bytes: 156424
N = int(input())
mod = 10**9+7

prime = []
for i in range(2, 1000) :
    flag = True
    for p in prime :
        if i%p == 0 :
            flag = False
    if flag == True :
        prime.append(i)

pcount = [0 for _ in range(len(prime))]

def bek(n, p) :
    temp = 0
    while n%p == 0 :
        temp += 1
        n //= p
    return temp

for i in range(len(prime)) :
    for j in range(1,N+1) :
        pcount[i] += bek(j, prime[i])

ans = 1
for i in range(len(prime)) :
    ans = (ans * (pcount[i]+1))%mod

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

int main()
{
  int n, m;
  cin >> n >> m;
  int sum = 0;
  vector<int> a(n);
  rep(i, n) {
    cin >> a[i];
    sum += a[i];
  }

  int num = 0;
  rep(i, n) {
    if (a[i] * 4 * m >= sum) num++;
  }

  if (num >= m) puts("Yes");
  else puts("No");

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
#include <math.h>
#include<cmath>
#include<map>
#include <limits>
# include <iomanip>
#include <queue>
#define INF 1000000009;

using namespace std;
int gcd(int a, int b) {
	while (a % b != 0) {
		int c = 0;
		c = a % b;
		a = b;
		b = c;
	}
	return  b;
}
int kaizyo(int a) {
	long long ans = 1;
	for (int i = a; i > 0; i--) {
		ans *= i;
		ans = ans % 1000000007;
		//cout << ans << endl;
	}
	ans = ans % 1000000007;
	return ans;
}

int main() {
	int a = 0;
	cin >> a;
	cout << abs(1-a) << endl;
	return 0;
}



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

int main(){
  int a,b,c;cin >> a >> b >> c;
  if(b-a == c-b)cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//modint
template<typename T> T modinv(T a, T m) {
	T b = m, u = 1, v = 0;
	while (b) {
		T t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

class modint {
public:
	ll val;
	ll mod;
	modint(ll a,ll m) {
		mod = m;
		val = a % mod;
	}
	modint operator+(const modint& r) {
		return modint((this->val + r.val) % mod,mod);
	}
	modint operator-(const modint& r) {
		return modint((this->val - r.val) % mod + ((this->val - r.val) % mod < 0) * mod,mod);
	}
	modint operator*(const modint& r) {
		return modint((((this->val % mod) * (r.val % mod))) % mod,mod);
	}
	modint& operator+=(const modint& r) {
		*this = *this + r;
		return *this;
	}
	modint& operator-=(const modint& r) {
		*this = *this - r;
		return *this;
	}
	modint& operator*=(const modint& r) {
		*this = *this * r;
		return *this;
	}
	modint operator/(const modint& r) {
		return modint(this->val * modinv(r.val, mod) % mod, mod);
	}
	modint& operator/=(const modint& r) {
		*this = *this / r;
		return *this;
	}
};

modint modpow(modint x, int k) {
	if (k == 0)return modint(1, x.mod);
	if (k % 2 == 0) return modpow(x * x, k / 2);
	else return x * modpow(x, k - 1);
}



int main() {
	int N, P;
	cin >> N >> P;
	string S;
	cin >> S;

	if (P != 2 && P != 5) {
		vector<modint> md(N, modint(0, P));
		md[0] = modint(S[0] - '0', P);
		for (int i = 1; i < N; i++) {
			md[i] = md[i - 1] + modint(S[i] - '0', P) / modpow(modint(10, P), i);
		}

		vector<int> cnt(P, 0);
		ll ans = 0;
		for (int i = 0; i < N; i++) {
			if (md[i].val == 0) {
				ans++;
			}
			ans += cnt[md[i].val];
			cnt[md[i].val]++;
		}
		cout << ans << endl;
	}
	else if(P == 2){
		ll ans = 0;
		for (int i = 0; i < N; i++) {
			if ((S[i] - '0') % 2 == 0) {
				ans += i + 1;
			}
		}
		cout << ans << endl;
	}
	else {
		ll ans = 0;
		for (int i = 0; i < N; i++) {
			if ((S[i] - '0') % 5 == 0) {
				ans += i + 1;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
long long MOD = 1e9+7;
int main()
{
    int n;
    cin >> n;
    vector<vector<int>> grid(n,vector<int>(n,0));
    for(int i =0;i<n;i++)
        for(int j = 0;j<n;j++)
        {
            cin >> grid[i][j];
        }
    
    vector<long long > dp(1<<n);
    dp[0] = 1;
    for(int mask = 0;mask < (1 << n) -1; mask++)
    {
        int  a = __builtin_popcount(mask);
        for(int b = 0;b < n;b++)
        {
            if(grid[a][b] && !(mask & (1 << b)))
            {
                int m = mask | (1 << b);
                dp[m] += (dp[mask]%MOD);
            }
        }
    }
    
    cout << dp[(1<<n)-1]%MOD << endl;
    return 0;
}

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

int main(){

    size_t n;
    std::cin >> n;

    std::map<std::string, size_t> m;

    for(size_t i = 0; i < n; i++){
        std::string s;
        std::cin >> s;

        if(m.find(s) != m.end()){
            m[s]++;
        }else{
            m.emplace(s, 0);
        }
    }

    size_t max = 0;

    for(const auto& e : m){
        max = std::max(max, e.second);
    }

    std::vector<std::string> v;

    for(const auto& e : m){
        if(e.second == max){
            v.emplace_back(e.first);
        }
    }

    std::sort(v.begin(), v.end());

    for(const auto& e : v){
        std::cout << e << std::endl;
    }

    return 0;
}


Measured memory_bytes: 26868
#include <iostream>
#include <bits/stdc++.h>
#define mod 1000000007
typedef long long ll;

using namespace std;

void Fastio(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

ll fact[1000006], inv[1000006];

ll fp(ll base, ll exp)
{
    if (exp == 0)
        return 1;
    ll ans = fp(base, exp / 2);
    ans = (ans * ans) % mod;
    if (exp % 2 != 0)
        ans = (ans * (base % mod)) % mod;
    return ans;
}

void calcFacAndInv(ll n)
{
    fact[0] = inv[0] = 1;
    for (ll i = 1; i <= n; i++)
    {
        fact[i] = (i * fact[i - 1]) ;
        inv[i] = fp(fact[i], mod - 2);
    }
}

ll ncr(ll n, ll r)
{
    return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}

ll npr(ll n, ll r)
{
    return (fact[n] * inv[n - r]) % mod;
}

long double  NCR(int n, int m){
    long double res = 1;
    m = min(m, n - m);
    for(int i = 0; i < m; i++){
        res = res * ( n - i) / (i + 1);
 }
    return res;
}
ll tol(string a){
    ll res=0;
    while(a[0]=='0'){
        a.erase(a.begin());
    }
    if(a=="")a="0";
    for(int i=0; i<a.size(); i++){
        res*=10; res+=a[i]-'0';
    }
    return res;
}
int check(string a, string b){
    for(int i=0; i<a.size(); i++){
        if(a[i]>b[i])return 1;
        if(b[i]>a[i])return -1;
    }
    return 0;
}
class data{
public:
    ll v,d,p;
    data(){}
    data(ll vv, ll dd, ll pp){
        v=vv;  d=dd; p=pp;
    }
};

int primeFactors(int n)
{
    ll c=0;
    while (n % 2 == 0)
    {
        c++;
        n = n/2;
    }
    for (int i = 3; i*i <= n; i = i + 2)
    {
        while (n % i == 0)
        {
            c++;
            n = n/i;
        }
    }
    if (n > 2)
        c++;
    return c;
}
int n,m;
vector<int>arr[100005];
int dp[100005];
int dfs(int node){
    if(dp[node])return dp[node];
    int res=0;
    for(int i=0; i<arr[node].size(); i++){
       res=max(res,1+dfs(arr[node][i]));
    }
    return dp[node]=res;
}
int main()
{
    Fastio();
    cin>>n>>m;
    set<int>s;
    for(int i=1; i<=n; i++){s.insert(i);}
    for(int i=0; i<m; i++){
        int x,y; cin>>x>>y;
        arr[x].push_back(y);
        auto it=s.find(y);
        if(it==s.end())continue;
        s.erase(it);
    }
    int res=0;
    while(!s.empty()){
        int node=*s.begin();
        s.erase(s.begin());
        res=max(res,dfs(node));
    }
    cout<<res<<'\n';


    return 0;
}


Measured memory_bytes: 13824
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    int pos = 0;
    string t[4] = {"resare", "esare", "remaerd", "maerd"};

    while (pos < s.size()) {
        int idx;
        for (int i = 0; i < 4; i++) {

            if (pos == (int)(s.find(t[i], pos))) {
                pos += t[i].size();
                break;
            }
            if (i == 3) {
                cout << "NO" << endl;
                return 0;
            }
        }
    }

    cout << "YES" << endl;


    return 0;
}


Measured memory_bytes: 512
/**
*
* Author: Mouhanad
* Lang: GNU C++14
*
**/
#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define ii pair < int , int >
#define LS pair < ll , string >
typedef long long ll;
const int inf = 1<<30;
const int N =302;
int n , m , l ;
ll FW[N][N];
ll cnt[N][N];

int main ( ){
  scanf("%d %d %d",&n,&m,&l);

  for  (int i =0 ; i < N ; i++ )
    for ( int j =0 ; j < N ; j++ )
      FW[i][j] = inf ;

  for ( int i =0 ; i < m ; i++ ){
    int a , b,  c; scanf("%d %d %d",&a,&b,&c);
    FW[a][b] = FW[b][a] = min (FW[a][b], (ll) c );
  }
  for  (int k = 1 ; k <= n ; k++ )
    for  (int i = 1 ; i <= n ; i++ )
     for  ( int j = 1 ; j <= n ; j++ )
      FW[i][j] = min ( FW[i][j] , FW[i][k] + FW[k][j] );

   for ( int i =1 ; i <= n ; i++)
    for ( int j = 1; j <= n ; j++ )
        cnt[i][j] = ( FW[i][j] > l ? inf : 1 );

   for  (int k = 1 ; k <= n ; k++ )
    for  (int i = 1 ; i <= n ; i++ )
     for  ( int j = 1 ; j <= n ; j++ )
      cnt[i][j] = min ( cnt[i][j] , cnt[i][k] + cnt[k][j] );

    int q ; scanf("%d",&q);
    while ( q-- ){
        int x , y ; scanf("%d %d",&x,&y);
        if ( cnt[x][y] == inf ) printf("-1\n");
        else printf("%lld\n",max ( cnt[x][y]-1 ,0LL) );
    }
return 0 ;
}


Measured memory_bytes: 1920
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

ll P = 1000000007;
ll mpow(ll a, ll b, ll p = -1){
  ll ret = 1, num = a;
  if(p==-1){
    while(b>0){
      if(b%2) ret *= num;
      num = num * num;
      b /= 2;
    }
  }else{
    while(b>0){
      if(b%2) ret = (ret*num)%p;
      num = (num*num)%p;
      b /= 2;
    }
  }
  return ret;
}
int main(int argc, char const *argv[]) {
  ll n, k;std::cin >> n >> k;
  ll ans = 0;
  vll num(k+1, 0);
  for(ll i=k;i>0;i--){
    ll tmp = mpow(k/i, n, P);
    num[i] = (num[i] + tmp)%P;

    for(ll j=2;j*j<=i;j++){
      if(i%j!=0) continue;
      num[j] = (num[j] - num[i] + P)%P;
      if(j*j!=i) num[i/j] = (num[i/j] - num[i] + P)%P;
    }
    if(i!=1) num[1] = (num[1] - num[i] + P)%P;
  }
  for(ll i=1;i<=k;i++){
    //std::cout << i << " " << num[i] << '\n';
    ans = (ans + (num[i]*i)%P)%P;
  }
  std::cout << ans << '\n';
  return 0;
}


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

int main(){

  int K;
  cin >> K;
  if(K % 2 == 1) cout << (K / 2) * ((K / 2) + 1) << endl;
  else cout << (K / 2) * (K / 2) << endl;

  return 0;
  
}

Measured memory_bytes: 256
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<fstream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

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

    // input
    ll H, W;
    cin >> H >> W;

    map<char, ll> mp;
    FOR(i, 0, H){
        string s;
        cin >> s;

        for(char c : s){
            mp[c]++;
        }
    }

    if(H%2==0 && W%2==0){
        for(auto p : mp){
            if(p.second % 4 != 0){
                p_no();
                return 0;
            }
        }
        p_yes();
        return 0;
    }
    else if(H%2==1 && W%2==1){
        ll four = (H-1)*(W-1);
        for(auto& p : mp){
            while(p.second>=4 && four>0){
                p.second -= 4;
                four -= 4;
            }
        }
        if(four>0){
            p_no();
            return 0;
        }

        ll two = (H-1) + (W-1);
        for(auto& p : mp){
            while(p.second>=2 && two>0){
                p.second -= 2;
                two -= 2;
            }
        }
        if(two>0){
            p_no();
            return 0;
        }
        else{
            p_yes();
            return 0;
        }
    } 
    else{
        // どちらかが奇数・どちらかが奇数
        // W : 奇数とする
        if(W%2==0){
            swap(H, W);
        }

        ll four = H*(W-1);
        for(auto& p : mp){
            while(p.second>=4 && four>0){
                p.second -= 4;
                four -= 4;
            }
        }
        if(four>0){
            p_no();
            return 0;
        }

        ll two = H;
        for(auto& p : mp){
            while(p.second>=2 && two>0){
                p.second -= 2;
                two -= 2;
            }
        }
        if(two>0){
            p_no();
            return 0;
        }
        else{
            p_yes();
            return 0;
        }
    }
    return 0;
}

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

using namespace std;

int main() {
    char s[212345];
    
    scanf("%s", s);

    int tam = strlen(s);

    int mod = 0;
    for (int i=0; i<tam; ++i) {
        mod += (s[i]-'0')%9;
    }
    mod%=9;

    if (mod == 0)
        puts("Yes");
    else
        puts("No");

    return 0;
}

Measured memory_bytes: 3892
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define MOD 1000000007
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(v) (v).begin() , (v).end()
#define sumof(v) accumulate(all(v), 0LL, plus<ll>())
#define maxof(v) max_element(all(v))
#define minof(v) min_element(all(v))
#define inf INT_MAX

ll power(ll x,  ll y, ll p)  
{  
    ll res = 1;     // Initialize result  
  
    x = x % p; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}  

int main(){
    FASTIO
    ll N; cin>>N;
    ll ans = ((power(10, N, MOD) - 2*power(9, N, MOD) + power(8, N, MOD))%MOD + MOD)%MOD;
    cout<<ans<<endl;
}

Measured memory_bytes: 3616
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int count = 0;
		while(N != 1){
			N /= 2;
			count++;
		}
		System.out.println(pow(count));
	}
	
	static int pow(int n){
		int pow = 1;
		for(int idx = 0; idx < n; idx++)
			pow *= 2;
		return pow;
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

int main()
{
    // (2n)^(2n+1)=1
    ll a, b;
    cin >> a >> b;

    ll ans = 0;
    if (a % 2 == 1)
    {
        ans ^= a;
        a++;
    }
    if (b % 2 == 0)
    {
        ans ^= b;
        b--;
    }

    if ((b - a + 1) % 4 != 0)
    {
        ans ^= 1;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 636
// #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0; i<n; i++)

int main() {
    ll a;
    float b;
    cin >> a >> b;

    ll c = b*100 + 0.5;

    cout << (ll)(a*c/100) << endl;

    return 0;
}

Measured memory_bytes: 3720
import std.algorithm;
import std.range;
import std.stdio;
import std.math;
import std.array;
import std.string;
import std.conv;

/// 数列の読み込み
auto readNums(T = int)() {
	return readln().chomp.split.map!(to!T).array;
}

/// 数の読み込み
auto readNum(T = int)() {
	return readNums!T.front;
}

/// 指定行数読み込み
auto readRows(size_t rows) {
	return generate(() => readln().chomp).take(rows).array;
}

/// 範囲の計算
auto range(T)(T a, T b, T c, T d) {
    auto start = max(a, c);
    auto end = max(b, d);
    return (start < end) ? tuple(start, end) : tuple(cast(T) 0, cast(T) 0);
}

auto maxElement(R)(R r) {
    return r.reduce!((a, b) => max(a, b));
}

auto minElement(R)(R r) {
    return r.reduce!((a, b) => min(a, b));
}

void main() {
    const rows = readRows(2);
    const s = rows[0];
    const k = rows[1].to!int;
    string[] subs;
    foreach(i; 0 .. s.length) {
        foreach(j; i .. s.length) {
            const ss = s[i .. j + 1];
            immutable pos = subs.count!("a < b")(ss);
            if(pos < subs.length) {
            	if(subs[pos] != ss) {
	            	subs.insertInPlace(pos, ss);
	            	subs = subs[0 .. min(subs.length, k)];
            	}
            } else if(pos < k) {
            	subs ~= ss;
            }
        }
    }
    writefln("%s", subs[k - 1]);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
  int h,w,c1,i,j;
  cin>>h>>w;
  string a;
  string temp;
    
  for(i=0;i<h;i++){
    cin >> temp;
    a+=temp;
  }
  
  for(i=0;i<h;i++){
    c1=0;
    for(j=0;j<w;j++){
      if(a.at(i*w+j)=='#')break;
      c1++;
    }
    if(c1==w){
      for(j=0;j<w;j++){
        a.at(i*w+j)='s';
      }
    }
  }
  
  for(i=0;i<w;i++){
    c1=0;
    for(j=0;j<h;j++){
      if(a.at(i+j*w)=='#')break;
      c1++;
    }
    if(c1==h){
      for(j=0;j<h;j++){
        a.at(i+j*w)='s';
      }
    }
  }
  
  for(i=0;i<h;i++){
    c1=0;
    for(j=0;j<w;j++){
      if(a.at(i*w+j)!='s'){
      cout<<a.at(i*w+j);
      }
      else c1++;
    }
    if(c1!=w){
      cout<<endl;
    }
  }
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;

int n,m,k,sum;
int u[10005],v[10005];
void Add(int x,int y) {
	m++;
	u[m]=x,v[m]=y;
}
int main() {
	scanf("%d %d",&n,&k);
	sum=(n-1)*(n-2)/2;
	if(k>sum) {
		printf("-1\n");
		return 0;
	}
	m=n-1;
	m+=sum-k;
	printf("%d\n",m);
	for(int i=2;i<=n;i++)
		printf("1 %d\n",i);
	for(int i=2;sum>k;i++)
		for(int j=i+1;j<=n&&sum>k;j++)
			sum--,printf("%d %d\n",i,j);
	return 0;
}

Measured memory_bytes: 128
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	final static int MOD = (int)1e9 + 7;
	int M,N;

	public long modPow(int x,int y){

		if(y == 0){
			return 1;
		}else if(y == 1){
			return x;
		}else if(y % 2 == 0){
			long z = modPow(x,y / 2) % MOD;
			return z * z % MOD;
		}else{
			return modPow(x,y - 1) * x % MOD;
		}
	}

	public void solve() {

		M = nextInt();
		N = nextInt();
		out.println(modPow(M,N));
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 24368
n = int(input())
sl = []
for i in range(n):
    sss= list(str(input()))
    onedict = {}
    for j in range(len(sss)):
        if sss[j] in onedict:
            onedict[sss[j]] = onedict[sss[j]] + 1
        else:
            onedict.update({sss[j]:1})
    sl.append(onedict)

ansdict = {}

for alphabet in sl[0].keys():
    flag = 0
    mins = []
    for j in sl:
        if alphabet in j:
            mins.append(j[alphabet])
        else:
            flag = 1
    if flag == 1:
        None
    else:
        minutes = min(mins)
        ansdict.update({alphabet:minutes})

goalkeys = list(sorted(ansdict.keys()))
                
moji = ''
for i in goalkeys:
    for j in range(ansdict[i]):
        moji = moji + i
        
print(moji)
            

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int main() {
  int A, B, M; cin >> A >> B >> M;
  vector<int> a(A);
  rep(i, A) cin >> a[i];
  vector<int> b(B);
  rep(i, B) cin >> b[i];
  vector<int> x(M), y(M), c(M);

  int ans = inf;
  rep(i, M) {
    cin >> x[i] >> y[i] >> c[i];
    x[i]--, y[i]--;
    ans = min(ans, a[x[i]] + b[y[i]] - c[i]);
  }

  ans = min(ans, *std::min_element(a.begin(), a.end()) + *std::min_element(b.begin(), b.end()));
  cout << ans << endl;
}


Measured memory_bytes: 2176
N = int(input())
A = [int(i) for i in input().split()]

for i in range(N):
    A[i] = A[i] - (i+1)

A.sort()

medium = A[int(N/2)]

s = 0
for i in range(N):
    s = s + abs(A[i]-medium)

print(s)

Measured memory_bytes: 26020
from itertools import permutations
n,m = map(int, input().split())
d = {}
for _ in range(m):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    if a not in d:
        d[a] = {}
    if b not in d:
        d[b] = {}
    d[a][b] = d[b][a] = 1

ans = 0
for route in permutations(range(1,n)):
    if route[0] not in d[0]:
        continue
    for j in range(n-2):
        if route[j+1] not in d[route[j]]:
            break
    else:
        ans += 1

print(ans)


Measured memory_bytes: 40432
<?php
$i = 0;
$result=0;
$NM = explode(" ",(fgets(STDIN)));
$M = $NM[1];
$array = array_fill(0,$M,0);

while($i < $NM[0]){
  $KA = explode(" ",(fgets(STDIN)));
  foreach($KA as $key => $value){
    if($key!=0){
    $array[$value-1]++;
    }
  }
  $i++;
}
foreach($array as $v){
  if($v == $NM[0]){
  $result++;
  }
}
print($result);

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


Measured memory_bytes: 5156
#include <bits/stdc++.h>
using namespace std;
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define prin(a) cout<<a<<"\n"
#define kaigyo cout<<"\n"
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define SORT(V) sort(ALL(V))
#define REV(V) reverse(ALL(V))
#define RSORT(V) SORT(V);REV(V)
#define mem(x) memset(x,0,sizeof(x))
#define mem1(x) memset(x,-1,sizeof(x))
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<string> vst;
typedef vector<char> vc;
typedef vector<long double> vd;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
typedef vector<vector<int>> vint2;
ll mod=1e9+7;
ll MOD=1e9+7;
#define int1(x) int x;cin>>x;
#define int2(x,y) int x,y;cin>>x>>y;
#define int3(x,y,z) int x,y,z;cin>>x>>y>>z;
#define int4(x,y,z,w) int x,y,z,w;cin>>x>>y>>z>>w;
#define ll1(x) ll x;cin>>x;
#define ll2(x,y) ll x,y;cin>>x>>y;
#define vint1(a,n) vint a(n);rep(i,n)cin>>a[i];
#define vint2(a,b,n) vint a(n),b(n);rep(i,n)cin>>a[i]>>b[i];
#define vll1(a,n) vll a(n);rep(i,n)cin>>a[i];
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;
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; }
#define F first
#define S second
const double pi=acos(-1.0);
const ll inf=1LL<<60;


bool isPrime(ll n){if(n<2)return false;for(ll x = 2;
x*x <=n;x++){if(n%x == 0)return false;}return true;}
ll kaizyo(ll k){ll sum=1;rep1(i,k){sum*=i;sum%=mod;}return sum;}
ll ncr(ll n,ll r){return kaizyo(n)/(kaizyo(r)*kaizyo(n-r));}
unsigned keta(unsigned num){
    return log10(num)+1;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
int1(n);

int d=modpow(10,n,MOD)-2*modpow(9,n,MOD)+modpow(8,n,MOD);
while(d<0)d+=MOD;
prin(d);
}


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

// iterator
#define REP(i,from, to) for(lli i=from;i<to;i++)
#define REPE(i,from, to) for(lli i=from;i<=to;i++)
#define REP_R(i,from, to) for(lli i=from;i>to;i--)
#define REPE_R(i,from, to) for(lli i=from;i>=to;i--)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;
typedef vector<lli> vlli;

int main() {
    lli n;
    cin1(n);
    lli start = ((lli)sqrt(n)) + 1;
    REP_R(i,start,0) {
        if (n % i == 0) {
            lli x = n / i;
            lli y = i;
            cout << x+y-2<<endl;
            return 0;
        }

    }

}


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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
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};

int N;
ll X;
ll berger[55];  //bn = 2*bn-1 + 3   層の数
ll patti[55];   //an = 2*an-1 + 1   パティの数

ll pattiX(int N, ll X){
    if(X < 0 || N < 0){
        return 0;
    }else if(berger[N] / 2 < X){
        return patti[N] - pattiX(N-1, berger[N] - X - 1);
    }else{
        return pattiX(N-1, X-1);
    }
}

int main(){

    cin >> N >> X;

    patti[0] = 1; berger[0] = 1;
    for(int i = 1; i <= N; i++){
        patti[i] = patti[i-1] * 2 + 1;
        berger[i] = berger[i-1] * 2 + 3;
    }


    cout << pattiX(N, X) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using namespace std;
using ll = long long;
const ll MOD = (ll)1e9+7;
//const ll MOD = 998244353;
//const ll MOD = 924844033;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
const double EPS = 1e-5;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

#ifdef DEBUG
#define OUTPUT(x) (output(x), outendl())
#else
#define OUTPUT(x) (void)0
#endif

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
	if(was_output)cout << " ";
	cout << a;
	was_output = true;
}
void outendl(){
	was_output = false;
	cout << endl;
}

int n;
vector<int> parent;
vector<int> children;
vvector<int> uses;

int main(){
    cin >> n;
    parent.resize(n,-1);
    children.resize(n,0);
    uses.resize(n);
    repa(i,n){
        int d;
        cin >> d;
        --d;
        ++children[d];
        parent[i] = d;
    }
    stack<int> st;
    repa(i,n){
        if(children[i]==0){
            st.push(i);
        }
    }

    int ans = 0;

    while(st.size()){
        int d = st.top();
        st.pop();
        if(uses[d].empty()){
            uses[parent[d]].push_back(1);
        }else{
            sort(all(uses[d]),greater<int>());
            int num = 0;
            rep(i,(int)uses[d].size()){
                chmax(num,uses[d][i] + 1 + i);
            }
            if(d==0){
                ans = num;
                break;
            }
            uses[parent[d]].push_back(num);
        }
        if(--children[parent[d]]==0){
            st.push(parent[d]);
        }
    }

    cout << ans - 1 << endl;

	return 0;
}


Measured memory_bytes: 6528