akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
const int INF = 1001001001;
const ll LINF = 1e18;
const string endstr = "\n";

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    T r;
    while((r=a%b)) {
        a = b; b = r;
    }
    return b;
}
bool p_comp_fs(const P p1, const P p2){ return p1.first < p2.first;};
bool p_comp_fg(const P p1, const P p2){ return p1.first > p2.first;};
bool p_comp_ss(const P p1, const P p2){ return p1.second < p2.second;};
bool p_comp_sg(const P p1, const P p2){ return p1.second > p2.second;};
    
int main(){
    ll N; cin >> N;
    vl as(N, 0), bs(N, 0), cs(N, 0);
    for (ll i = 0; i < N; i++) cin >> as[i];
    for (ll i = 0; i < N; i++) cin >> bs[i];
    for (ll i = 0; i < N; i++) cin >> cs[i];
    
    sort(as.begin(), as.end());
    sort(bs.begin(), bs.end());
    sort(cs.begin(), cs.end());
    
    map<ll, ll> ab, bc, mul_c;
    for (int i = 0; i < N; i++) {
        auto it = upper_bound(bs.begin(), bs.end(), as[i]);
        if(it == bs.end()){
            ab[as[i]] = 0;
        }
        else{
            ab[as[i]] = *it;
        }
    }
    
    ll acc_c = 0;
    for (ll i = N - 1; i >= 0; i--) {
        auto it = upper_bound(cs.begin(), cs.end(), bs[i]);
        if (it == cs.end()) {
            mul_c[bs[i]] = 0;
        }
        ll dist = distance(cs.begin(), it);
        acc_c += N - dist;
        mul_c[bs[i]] = acc_c;
    }
    
    ll ret = 0;
    for (int i = 0; i < N; i++) {
        ret += mul_c[ab[as[i]]];
    }
    
    cout << ret << endstr;
    
    return 0;
}


Measured memory_bytes: 15104
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void solve(){
	int x,n;cin>>x>>n;
	if(n==0) {cout<<x;return;}
	vector<int>p(n);for(int i=0;i<n;i++) cin>>p[i];
	map<int,bool>mp;int diff=INT_MAX;int val;
	for(int i=0;i<n;i++) mp[p[i]]=true;
	for(int i=-1;i<=101;i++){
		if(mp[i]==0){
			if(abs(i-x)<diff) {diff=abs(i-x);val = i;}
		}
	}
	cout<<val;
}	
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	int T=1;
	//cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


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

typedef long long lli;

int main() {
  for(double d; cin >> d; ) {
    double res = d*sqrt(2);
    for(double k = 1; k <= d; ++k) {
      if(k <= d && d*d <= k*k + 1) {
        res = max(res, k+1);
      }
    }
    printf("%.10f\n", res);
  }
  return 0;
}

Measured memory_bytes: 1236
S = input()
if S == 'SUN': print(7)
elif S == 'MON': print(6)
elif S == 'TUE': print(5)
elif S == 'WED': print(4)
elif S == 'THU': print(3)
elif S == 'FRI': print(2)
elif S == 'SAT': print(1) 

Measured memory_bytes: 9092
program sample
    implicit none
  
    integer(8) :: i,j,m,n,a,b,c,d,e,k
    
    integer(8),allocatable :: x(:),y(:)
  
    
    read(*,*) a
    read(*,*) b
    read(*,*) c
    read(*,*) d
    read(*,*) e
    read(*,*) k
    if (e-a>k)then
        write(*,*) ':('
    else
        write(*,*) 'Yay!'
    end if

  
    stop
end program sample
  



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

int main() {
  int N;
  double S;
  cin >> N;
  vector<vector<int>> T(N, vector<int>(2,0));
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < 2; j++) {
      cin >> T.at(i).at(j);
    }
  }
  int d;
  for(int i = 0; i < N - 1; i++) {
    for(int j = i + 1; j < N; j++) {
      d = (T.at(i).at(0) - T.at(j).at(0)) * (T.at(i).at(0) - T.at(j).at(0)) + (T.at(i).at(1) - T.at(j).at(1)) * (T.at(i).at(1) - T.at(j).at(1));
      S += sqrt(d);
    }
  }
  cout << fixed << setprecision(10);
  cout << S * 2 / N << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define ALL(c) (c).begin(), (c).end()
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;cin>>n;
    if (n%2==0)
    {
        cout << n/2-1 << endl;
    }
    else
    {
        cout << n/2 << endl;
    }
    
    
}




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

int main() {
    int c[26];
    for (int i=0;i<26;i++)
        c[i]=1e9;
    int n;cin>>n;
    for (int i=0;i<n;i++) {
        string s;cin>>s;
        int cc[26]{};
        for (auto c:s)
            cc[c-'a']++;
        for (int i=0;i<26;i++)
            c[i]=min(c[i],cc[i]);
    }
    for (int i=0;i<26;i++)
        for (int j=0;j<c[i];j++)
            putchar('a'+i);
    cout<<endl;
    return 0;
}

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

#define FOR(i, a, b) for(i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define comp(a, b) comp(const void *a, const void *b)
#define MOD  1000000007

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;

void TF_print(char boolean, char T[], char F[]){
    if(boolean){
        printf("%s\n", T);
    }else{
        printf("%s\n", F);
    }
}

void count_char(uint alpha[26], char S[50], uint len){
    int i;
    REP(i, 26){
        alpha[i] = 0;
    }
    REP(i, len){
        alpha[S[i] - 'a']++;
    }
}

int main(){
    uint alpha[26], minAlpha[26];
    char S[50];
    uint n, i, j;

    REP(i, 26){
        minAlpha[i] = 51;

    }
    scanf("%d", &n);
    REP(i, n){
        scanf("%s", S);
        uint len = strlen(S);
        count_char(alpha, S, len);
        REP(j, 26){
            if(minAlpha[j] > alpha[j]){
                minAlpha[j] = alpha[j];
            }
        }
    }
    REP(i, 26){
        REP(j, minAlpha[i]){
            printf("%c", i + 'a');
        }
    }
    printf("\n");
    return 0;
}

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

using namespace std;


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

    int n , m;
    cin >> n >> m;

    priority_queue<int> pq;
    for (int i = 0 ;i < n ;i++) {
        int x;
        cin >> x;
        pq.push(x);
    }

    while (m--) {
        int t = pq.top();
        pq.pop();
        pq.push(t / 2);
    }

    long long ans = 0;
    while (pq.size()) {
        ans += pq.top();
        pq.pop();
    }

    cout << ans;
}

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

// syntax sugar: `for (int i = 0; i < N; ++i)`
#define rep(i, N) for (int i = 0; i < (int)(N); ++i)
#define rep2(i, startValue, N) for (int i = (int)(startValue); i < (int)(N); ++i)
// syntax sugar: `for (int i = 0; i < N; ++i)`
#define REP(type, name, beginValue, endCondValue) \
  for (type name = beginValue; name < endCondValue; ++name)
// syntax sugar: 多次元vector
#define VECTOR_DIM3(T, name, d1, d2, d3, initValue) \
    std::vector<std::vector<std::vector<T>>> name(d1, std::vector<std::vector<T>>(d2, std::vector<int>(d3, initValue)));
#define VECTOR_DIM2(T, name, d1, d2, initValue) \
    std::vector<std::vector<T>> name(d1, std::vector<T>(d2, initValue));
#define VECTOR_DIM1(T, name, d1, initValue) \
    std::vector<T> name(d1, initValue);
#define ll long long
#define ld long double

// ARC091 C - Flip,Flip, and Flip......
int main(){
  ll n, m;
  cin >> n >> m;

  ll ans = 0;
  if (n == 1 || m == 1) {
    if (n < m) { swap(n,m); }
    // 以下、n >= 1
    if (n == 1) {
      ans = 1;
    } else {
      ans = n - 2;
    }
  } else {
    ans = (n - 2) * (m - 2);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int H,W,K;
    cin >> H>>W>>K;
    // std::vector<vector<char>> c(H,vector<char>(W));
    // for(int i=0;i<H;i++){
    //     for(int j=0;j<W;j++){
    //         cin >> c.at(i).at(j);
    //     }
    // }
    // for(int 1=0;i<pow(2,H);i++){
    //     c.erase(c.begin)
    //     for(int j=0;j<pow(2,W);j++){
        
    //     }
    // }
    
    vector<vector<char>> c(H,vector<char>(W));
    int H2=1;
    int W2=1;
    for(int i=0;i<H;i++){
        W2 = 1;
        H2 *=2;
        for(int j=0;j<W;j++){
            cin >> c.at(i).at(j);
            W2 *= 2;
        }
    }
    int ans=0;
    
    for(int i=0;i<H2;i++){   
        vector<vector<char>> d(H,vector<char>(W));
        for(int i_2=0;i_2<H;i_2++){
            for(int j=0;j<W;j++)d[i_2][j]=c[i_2][j];
        }
        
        int k=0;
        int n=1;
        for(int i_2=0;i_2<H;i_2++){
            if((i&n)!=0){
                d.erase(d.begin()+i_2-k);
                k++;
            }
            n*=2;
        }
        
        if(H-k>0){
            for(int p=0;p<W2;p++){   
                vector<vector<char>> e(H-k,vector<char>(W));
                for(int i=0;i<H-k;i++){
                    for(int j=0;j<W;j++)e[i][j]=d[i][j];
                }
                
                int q=0;
                int n=1;
                for(int p_2=0;p_2<W;p_2++){
                    if((p&n)!=0){
                            // e[0].erase(e[0].begin()+p_2-q);
                        for(int i=0;i<H-k;i++){
                            e[i][p_2]='a';
                        }
                    }
                    n*=2;
                }
                
                int l=0;
                for(int i=0;i<H-k;i++){
                    for(int p=0;p<W;p++){
                        // cout << e.at(i).at(p);
                        if(e.at(i).at(p)=='#')l++;
                    }
                    // cout << endl;
                }
                if(l==K){
                    ans++;
                    // cout << " ans:"<<ans <<endl;
                }
                // cout << endl;
            }
        }else{
            if(K==0)ans += W2;
        }
    }
    cout << ans << endl;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()

int main()
{
	ll n = 0;
	cin >> n;
	string s; cin>>s;
	
	ll now = 0;
	REP(i,n)
	{
		if( s[i] == '.' ) { ++now; }
	}
	ll ans = now;
	REP(i,n)
	{
		if( s[i] == '.' ) --now;
		else ++now;
		ans = min( ans, now );
	}

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

Measured memory_bytes: 640
#include<stdio.h>
int main()
{
	int a,b,c,d,e;
	scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
	if(a<0&&b<=0){
		printf("%d\n",c*(b-a));
	}else if(a<0&&b>0){
		printf("%d\n",(-a)*c+d+b*e);
	}else{
		printf("%d\n",(b-a)*e);
	}
	return 0;
}

Measured memory_bytes: 2668
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;
int N;
vector<vector<int> > g;
vector<int> st; // 1->Nの最短で通る頂点
int num[100005];

bool dfs(int x, int par) {
  num[x] = 1;
  bool ret = false;
  for(int to : g[x]) {
    if(to == par) continue;
    ret |= dfs(to, x);
    num[x] += num[to];
  }
  if(x==N-1) ret = true;
  if(ret) st.push_back(x);
  return ret;
}

int main()
{
  cin>>N;
  g.resize(N);
  FOR(i,0,N-1) {
    int a, b;
    cin >> a >> b;
    a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  //st.push_back(N-1);
  bool ok = dfs(0,-1);
  int sunuke = num[st[st.size()/2-1]];
  int fenec = N - sunuke;
  cout << (sunuke >= fenec ? "Snuke" : "Fennec") << endl;
  return 0;
}


Measured memory_bytes: 13052
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n, m;
	cin >> n >> m;
	vector<int> c(n+1,0);
	for(int i=0; i<m; i++){
		int l, r;
		cin >> l >> r;
		c[l]++;
		c[r+1]--;
	}
	vector<int> s(n+1,0);
	for(int i=1; i<n+1; i++) s[i]=s[i-1]+c[i];
	int ans=0;
	for(int i=1; i<=n; i++){
		if(s[i]==m) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define LLINF (1e18)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n * a, b) << endl;
}

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

using namespace std;

void dfs(int index, vector<bool>& checked, int N, map<int, vector<int>>& edge, vector<int>& a, vector<int>& b, int elimEdge) {
	checked[index] = true;
	for (auto itr = edge[index].begin(); itr != edge[index].end(); itr++) {
		if (index == a[elimEdge] && *itr == b[elimEdge]) continue;
		if (index == b[elimEdge] && *itr == a[elimEdge]) continue;
		if(!checked[*itr]) dfs(*itr, checked, N, edge, a, b, elimEdge);
	}
}

bool isconn(int N, map<int, vector<int>>& edge, vector<int>& a, vector<int>& b, int elimEdge){
	vector<bool> checked(N, false);
	dfs(0, checked, N, edge, a, b, elimEdge);
	for (int i = 0; i < N; i++) if (!checked[i]) return false;
	return true;
}


int main(void) {
	int N, M;
	cin >> N >> M;
	vector<int> ord(N, -1), low(N, N + 1);
	vector<int> a(M), b(M);
	map<int, vector<int>> edge;
	for (int i = 0; i < M; i++) {
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
		edge[a[i]].push_back(b[i]);
		edge[b[i]].push_back(a[i]);
	}

	int ans = 0;
	for (int i = 0; i < M; i++) {
		if (!isconn(N, edge, a, b, i)) ans++;
	}

	cout << ans << endl;

	system("pause");
	return 0;
}

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

int main() {
    int N;
    cin >> N;
    long long l[90];

    l[0] = 2;
    l[1] = 1;
    for(int i = 2; i <= N; i++) {
        l[i] = l[i-1] + l[i-2];
    }

    cout << l[N] << endl;

    return 0;
}

Measured memory_bytes: 256
/*
貪欲
後ろから見る
DP
順位表をチェック
二分探索


*/
#pragma GCC optimize("Ofast")
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include<tuple>
using namespace std;
#define INF 3e18+7
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<double,int> P;
//typedef pair<pair<int,int>,int> p;
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());

ll A[310000];


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

    int N;
    cin>>N;
    for(int i=1;i<=N;i++){
        cin>>A[i];
    }

    ll t=1,ans=0;
    ll count0=0,count1=0;
    for(int i=0;i<=60;i++){
        t*=2;
    }
    //cout<<t<<endl;
    for(int i=0;i<62;i++,t/=2){
        count1=0; count0=0;
        for(int j=1;j<=N;j++){
            if(A[j]>=t){
                count1++;
                A[j]-=t;
            }else count0++;
        }
        //cout<<t<<endl;
        ll x=(count0*count1)%MOD*(t%MOD);
        x%=MOD;
        ans+=x;
        ans%=MOD;
    }
    cout<<ans<<endl;
}


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

int main(){
    long long money = 100, X, year=0;
    cin >> X;
    if (X == 100){
        cout << 0 << endl;
    }
    else {
        while (money < X) {
            long long kinri = money / 100;
            money += kinri;
            year++;
        }
        cout << year << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
n = int(input())
A = []
s = input()
A = list(map(int,s.split()))
for i in range(1,len(A)):
    v = A[i]
    j = i-1

    for k in range(0,len(A)-1):
        print(A[k],end=" ")
    print(A[len(A)-1])

    while(j >= 0 and A[j] > v):
        A[j+1] = A[j]
        j -= 1
        A[j+1] = v

for k in range(0,len(A)-1):
    print(A[k],end=" ")
print(A[len(A)-1])

Measured memory_bytes: 7928
N = int(input())
S = input()

def count_common(a, b):
    min_char = set(min(a, b))
    max_char = set(max(a, b))
    return len(max_char) - len(max_char - min_char)

rtn = 0
for i in range(N):
    a = S[:i]
    b = S[i:]
    tmp = count_common(a, b)
    if rtn < tmp:
        rtn = tmp

print(rtn)

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

int main(){
    int64_t N;
    int64_t T[100001],A[100001];
    cin >> N;
    for(int n=0;n<N;n++){
        cin >> T[n];
    }
    for(int n=0;n<N;n++){
        cin >> A[n];
    }
    int64_t left,right;
    for(int n=0;n<N;n++){
        if(T[n]==T[N-1]){ left = n; break;}
    }
    for(int n=N-1;n>=0;n--){
        if(A[n]==A[0]){ right = n; break;}
    }
    bool flag=true;
    if(A[0]!=T[N-1]) flag=false;
    if(A[left]!=T[left]) flag=false;
    if(A[right]!=T[right]) flag=false;
    if(flag){
        int64_t mod=1e9+7;
        int64_t r_tmp=A[N-1];
        int64_t r_ans=1;
        for(int n=N-2;n>=right;n--){
            if(r_tmp!=A[n]){
                r_tmp=A[n];
            }else{
                r_ans = (r_ans*r_tmp)%mod;
            }
        }
        int64_t l_tmp=T[0];
        int64_t l_ans=1;
        for(int n=1;n<=left;n++){
            if(l_tmp!=T[n]){
                l_tmp=T[n];
            }else{
                l_ans = (l_ans*l_tmp)%mod;
            }
        }
        int64_t ans=(l_ans*r_ans)%mod;
        for(int i=left+1;i<right;i++){
            ans = (ans*T[N-1])%mod;
        }
        cout << ans << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 1792
//ABC-139-E
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = INT_MAX;
const long long LINF = LLONG_MAX;
const long long MOD = 1e9 + 7;

const int MAX_V = 1000 *  (1000 - 1) / 2;

int dp[MAX_V];
int ans = 0;

vector<int> Tsort(vector<vector<int>> & G){
    vector<int> To; //トポロジカルソート後のグラフ
    // To.size() == V であればトポロジカルソートができた、そうでなければできなかったと判定できる
    int n = G.size();
    stack<int> st; //入次数が0の頂点の集合
    int indeg[n] = {}; //頂点の入次数を管理する配列
    for(int i = 0; i < n; i++){
        for(int j = 0; j < G[i].size(); j++){
            indeg[G[i][j]]++;
        }
    }
    for(int i = 0; i < n; i++){
        if(indeg[i] == 0){
            st.push(i);
        }
    }
    while(!st.empty()){
        int u = st.top();
        st.pop();
        To.push_back(u);
        for(int i = 0; i < G[u].size(); i++){
            indeg[G[u][i]]--; //隣接する頂点の入次数を1減らす
            dp[G[u][i]] = max(dp[G[u][i]], dp[u] + 1);
            ans = max(ans, dp[G[u][i]]);
            if(indeg[G[u][i]] == 0){
                st.push(G[u][i]); //入次数が0になればstに追加
            }
        }
    }
    return To;
}

signed main(){
    int n;
    cin >> n;
    int id[n][n];
    int cnt = 0;
    REP(i,n){
        for(int j = i + 1; j < n; j++){
            id[i][j] = cnt;
            cnt++;
        }
    }
    int num[n][n - 1];
    int a,b;
    REP(i,n){
        REP(j,n - 1){
            cin >> a;
            a--;
            b = i;
            if(a > b){
                swap(a, b);
            }
            num[i][j] = id[a][b];
        }
    }
    vector<vector<int>> G(cnt);
    REP(i,n){
        REP(j,n - 2){
            G[num[i][j]].push_back(num[i][j + 1]);
        }
    }
    vector<int> To = Tsort(G);
    if(To.size() != cnt){
        cout << -1 << endl;
        return 0;
    }
    cout << ans + 1 << endl;
    return 0;
}

Measured memory_bytes: 41464
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <bitset>
#include <iomanip>

#define ll long long
#define repp(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define repm(i,a,b) for(int i=(int)(a);i>(int)(b);--i)

using namespace std;

int main() {
    const ll MOD = 1e9+7;
    
    string S; cin >> S;
    int N = S.size();

    ll dp[N+1][13] = {0}; 
    dp[0][0] = 1;

    repp(i,0,N) {
        if (S[i] == '?') {
            repp(j,0,10) repp(k,0,13) dp[i+1][(k*10+j)%13] += dp[i][k];
        } else {
            repp(k,0,13) dp[i+1][(k*10+S[i] - '0')%13] += dp[i][k];
        }
        repp(j,0,13) dp[i+1][j] %= MOD;
    }
    cout << dp[N][5] << endl;
}


Measured memory_bytes: 10624
#include <iostream>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i <(int)n; i++)
#define brep(i, n) for (int i = n - 1; i >= 0; i--)
#define vec vector
#define ll long long

int main(void)
{
	int n;
	cin >> n;
	vec<ll> a(n);
	rep(i, n) {
		cin >> a[i];
	}

	rep(i, n) {
		if (!i && a[i]) {
			cout << - 1 << endl;
			return 0;
		}
		if (i && a[i] - a[i - 1] > 1) {
			cout << - 1 << endl;
			return 0;
		}
	}

	ll ans = 0;
	brep(i, n) {
		if (i != n - 1 && a[i + 1] == a[i] + 1) continue;

		ans += a[i];
	}

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


Measured memory_bytes: 1792
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
 
#[fastout]
fn main() {
    input! {
        x: isize,
    }
    let l = 125_isize;
    for i in -l..l {
        for j in -l..l {
            if i.pow(5) - j.pow(5) == x {
                println!("{} {}", i, j);
                return;
            }
        }
    }
}


Measured memory_bytes: 2160
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int N;
  cin >> N;
  string s;
  cin >> s;
  int ans = 0;
  for(int i=1;i<N;i++){
    string a="",b="";
    for(int j=0;j<N;j++){
      if(j < i) a += s[j];
      else b += s[j];
    }
    //cout << a << " " << b << endl;

    vector<bool> ab(26,false);
    vector<bool> bb(26,false);
    for(int i=0;i<(int)a.size();i++){
      ab[a[i]-'a'] = true;

    }
    for(int i=0;i<(int)b.size();i++){
      bb[b[i]-'a'] = true;
    }
    int cnt=0;
    rep(i,26){
      if(ab[i] && bb[i]){
        cnt++;
      }
    }
    ans = max(ans,cnt);

  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
tempwithindex = []
for i in range(0, N):
	tempwithindex.append([i+1, T-0.006*H[i]])
tempwithindex.sort(key = lambda v: abs(A-v[1]))
print(tempwithindex[0][0])

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

// BEGIN CUT HERE
// using R = long double;
using R = double;
constexpr R pi = acos((R)-1), eps = 1e-10;

int sgn(R a) { return (a > eps) - (a < -eps); }
int sgn(R a, R b) { return sgn(a - b); }
using P = complex<R>;
istream& operator>>(istream& i, P& p) { R x, y; i >> x >> y; p = P(x, y); return i; }
bool cmp(P p, P q) { return 2 * sgn(real(p), real(q)) + sgn(imag(p), imag(q)) < 0; }
bool eql(P p, P q) { return !cmp(p, q) and !cmp(q, p); }
R dot(P p, P q) { return real(conj(p) * q); }
R crs(P p, P q) { return imag(conj(p) * q); }
int ccw(P p, P q) {
  int s = sgn(crs(p, q));
  if (s) return s;
  if (dot(p, q) < 0) return -2;
  if (dot(p, q - p) > 0) return 2;
  return 0;
}
int ccw(P o, P p, P q) { return ccw(p - o, q - o); }
struct L {
  P s, t;
  P vec() const { return t - s; }
  R abs() const { return std::abs(vec()); }
  R arg() const { return std::arg(vec()); }
};
int ccw(L l, P p) { return ccw(l.s, l.t, p); }
// END CUT HERE

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  P o, p; cin >> o >> p;
  int Q; cin >> Q;
  while (Q--) {
    P q; cin >> q;
    switch (ccw(o, p, q)) {
      case +1: cout << "COUNTER_CLOCKWISE\n"; break;
      case -1: cout << "CLOCKWISE\n"; break;
      case +2: cout << "ONLINE_FRONT\n"; break;
      case -2: cout << "ONLINE_BACK\n"; break;
      case 0: cout << "ON_SEGMENT\n"; break;
    }
  }
}


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

int main(){
	
	int n,m ;
	while( cin >> n >> m , n ){
		int y[n+1] , x[m+1] ;
		y[0] = 0 ;
		x[0] = 0 ;
		for( int i=1 ; i<=n ; i++ ){
			cin >> y[i] ;
			y[i] += y[i-1] ;
		}
		for( int i=1 ; i<=m ; i++ ){
			cin >> x[i] ;
			x[i] += x[i-1] ;
		}
		
		map<int,int> cnt ;
		for( int i=1 ; i<=n ; i++ ){
			for( int j=0 ; j+i<=n ; j++ ){
				cnt[y[j+i]-y[j]]++ ;
			}
		}
		
		int ans=0 ;
		for( int i=1 ; i<=m ; i++ ){
			for( int j=0 ; j+i<=m ; j++ ){
				ans += cnt[x[j+i]-x[j]] ;
			}
		}
		
		cout << ans << endl ;
	}
	
return 0;
}

Measured memory_bytes: 19044
#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 n;
	while (cin >> n, ~n) {
		string ans;
		while (n) {
			ans += to_string(n % 4);
			n >>= 2;
		}
		reverse(ans.begin(), ans.end());
		if (ans == "")ans = "0";
		cout << ans << endl;
	}
}

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

int main(void){
	int N, i, ans, sum = 1;
	scanf("%d", &N);
	int a[N];
	
	for(i = 0; i < N; i++){
		scanf("%d", &a[i]);
		if(a[i] % 2 == 0)
			sum *= 2;
	}

ans = pow(3, N) - sum;
printf("%d",ans);
return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define pb push_back
#define xx first
#define yy second
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define repp(i,k,n) for(int i=k;i<n;i++)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> iv;
typedef pair<int,int> iip;
typedef map<int,int> mii;
template <typename T>
void dbg(T t){cerr<<t<<endl ;}
template<typename T, typename... Args>
void dbg(T t, Args... args) {cerr << t <<" ";dbg(args...) ;}
int main(){	
	int n,b,ans =0;
	cin>>n;
	int v[n];
	rep(i,n)cin>>v[i];
	rep(i,n-1){
		if(i+1==v[i]){
			swap(v[i],v[i+1]);
			ans++;
		}
	}
	if(v[n-1]==n){
		swap(v[n-1],v[n-2]);
		ans++;
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define ll long long
#define eps 1e-7
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
using pii = pair<int, int>;

int main()
{
	int n;
	cin >> n;
	cout << n* n* 3;
}

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

long long Gcd(long long m,long long n);
long long Lcm(long long m,long long n);

int main(){
    double ans;
    int N;
    cin >> N;
    long long A[N];
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    long long temp=A[0];
    for(int i=1;i<N;i++){
        A[0]=Lcm(A[0],A[i]);
    }
    for(int i=1;i<N;i++){
        A[i]=A[0]/A[i];
    }
    ans=A[0]/temp;
    for(int i=1;i<N;i++){
        ans+=A[i];
    }
    ans=A[0]/ans;
    cout << setprecision(16) << ans << endl;

    return 0;
}

long long Gcd(long long m,long long n){
    long temp;
    while(m%n!=0){
        temp=n;
        n=m%n;
        m=temp;
    }
    return n;
}

long long Lcm(long long m,long long n){
    return (m*n)/Gcd(m,n);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=1000000000000000;
typedef pair<ll,ll> l_l;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back


ll min(ll a,ll b){
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    return b;
}

int main(){
    ll x,y;cin>>x>>y;
    ll ans=1;
    while(x*2<=y){
        ans++;
        x=x*2;
    }
    cout<<ans<<endl;
    return 0;
}


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

int64_t N, M, V, P;
vector<int64_t> A, S;

bool check(int x){
    int X = upper_bound(A.begin(), A.end(), A[x]) - A.begin() - 1;
    if(X+P >= V){
        return (A[X] + M) >= A[N-P];
    }
    int l = X+1, r = N-P;
    int64_t gain = A[X] + M;
    int64_t rest = M*(V-X-P);
    int64_t pool = 0;
    for(int i=l; i<=r; i++){
        if(A[i] > gain) return false;
        pool += min(M, gain - A[i]);
    }
    return (rest <= pool);
}

int main(){
    cin >> N >> M >> V >> P;
    A.resize(N);
    S.resize(N+1);
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    for(int i=0; i<N; i++){
        S[i+1] = S[i] + A[i];
    }
    int ok = N-1, ng = -1;
    while(ok-ng>1){
        int mid = (ok+ng)/2;
        (check(mid) ? ok : ng) = mid;
    }
    cout << N-ok << endl;
    return 0;
}


Measured memory_bytes: 1792
a,b = map(int,input().split())
def gcd(x,y):
  r=x%y
  return gcd(y,r) if r else y
#最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

#リスト内最小公倍数
print(lcm(a,b))

Measured memory_bytes: 2940
N=int(input())
*A,=map(int,input().split())
*B,=map(int,input().split())
*C,=map(int,input().split())

A.sort()
C.sort()
from bisect import*
ans=0
for b in B:
    x=bisect_left(A,b)
    y=N-bisect_right(C,b)
    ans+=x*y
print(ans)

Measured memory_bytes: 29232
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>

int A, P;

int main(int argc, char **argv) {
    std::cin >> A >> P;

    P += A * 3;

    std::cout << P / 2 << std::endl;

    return 0;
}

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

int main()
{
    int a,b;
    while(scanf("%d%d",&a,&b)==2)
    {
        if(a>8||b>8)
            printf(":(\n");
        else
            printf("Yay!\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};

int N;
int p[100010];
int d[100010];

signed main(){
  cin>>N;
  for(int t=1;t<=N;t++){
    cin>>p[t];
    d[p[t]]=abs(p[t]-t);
  }

  int cont=0;
  for(int t=1;t<=N;t++){
    if(d[p[t]]==0){
      if(d[p[t+1]]==0){
        cont++;
        t++;
        continue;
      }
      cont++;
      t++;
    }
  }

  cout<<cont<<"\n";
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
#define cpy(a,b) tront[a-1] = temp[b-1]
class dice {
public:
	int tront[6];
	int flag;

	dice() {
		flag = 0;
	}
	void ini() {
		for (int i = 0; i < 6; i++) {
			cin >> tront[i];
		}
	}
	void rotation(char c) {
		int temp[6], i;
		for (i = 0; i < 6; i++)
			temp[i] = tront[i];
		switch (c) {
		case 'E':
			cpy(1, 4);
			cpy(4, 6);
			cpy(6, 3);
			cpy(3, 1);
			break;
		case 'N':
			cpy(5, 1);
			cpy(1, 2);
			cpy(2, 6);
			cpy(6, 5);
			break;
		case 'S':
			cpy(2, 1);
			cpy(1, 5);
			cpy(5, 6);
			cpy(6, 2);
			break;
		case 'W':
			cpy(1, 3);
			cpy(3, 6);
			cpy(6, 4);
			cpy(4, 1);
			break;
		}
	}
	void print(int x) {
		cout << tront[x-1] << endl;
	}

	void check(dice d1) {
		for (int j = 0; j < 6; j++) {
			if (d1.tront[j] != tront[j])
				return;
		}
		flag = 1;
	}
};

int main() {
	int i, j, k, l, a, b;
	int ans[7][7] = {0};
	dice d1, d2;
	ans[5][4]=1;ans[4][2]=1;ans[2][3]=1;ans[3][5]=1;
	ans[1][4]=2;ans[4][6]=2;ans[6][3]=2;ans[3][1]=2;
	ans[1][2]=3;ans[2][6]=3;ans[6][5]=3;ans[5][1]=3;
	ans[1][5]=4;ans[5][6]=4;ans[6][2]=4;ans[2][1]=4;
	ans[1][3]=5;ans[3][6]=5;ans[6][4]=5;ans[4][1]=5;
	ans[3][2]=6;ans[2][4]=6;ans[4][5]=6;ans[5][3]=6;
	d1.ini(); d2.ini();
	for (i = 0; i < 2; i++) {
		d2.rotation('N');
		d2.rotation('E');
		d2.rotation('S');
		for (j = 0; j < 4; j++) {
			d2.rotation('N');
			for (k = 0; k < 4; k++) {
				d2.rotation('E');
				d2.check(d1);
			}
		}
	}
	if (d2.flag)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}



Measured memory_bytes: 3100
n,m = map(int,input().split())
dis_lis = []
weth_lis = []

for i in range(n):
    dis_lis.append(int(input()))
for j in range(m):
    weth_lis.append(int(input()))
en_lis = [[100000000000 for i in range(n + 1)] for j in range(m + 1)]
for i in range(m + 1):
    en_lis[i][0] = 0
for i in range(m):
    for k in range(n):
        en_lis[i + 1][k + 1] = min([en_lis[i][k] + weth_lis[i]*dis_lis[k],en_lis[i][k + 1]])
print(en_lis[m][n])

Measured memory_bytes: 21228
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  int n,m;
  cin>>n>>m;

  vector<vector<int>> v(m);
  
  for(int i=0; i<m; i++){
    int k; cin>>k;
    v[i].resize(k);
    for(int j=0; j<k; j++){
      cin>>v[i][j];
      v[i][j]--;
    }
  }
  vector<int> p(m);
  for(int i=0; i<m; i++) cin>>p[i];

  int ans=0;
  for(int i=0; i<(1<<n); i++){
    bool ok=true;
    for(int j=0; j<m; j++){
      int c=0;
      for(int id:v[j]){
        if((i>>id)&1) c++;
      }
      c%=2;
      if(c!=p[j]) ok=false;
    }
    if(ok) ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    int m;
    cin >> m;
    vector<vector<int>> graph(n);
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    int rt = 0;
    vector<int> pars(n, -1);

    const int INF = 1 << 28;
    vector<int> dis(n, INF);
    queue<int> que;
    que.push(rt);
    dis[rt] = 0;

    while (!que.empty()) {
        int u = que.front();
        que.pop();
        for (auto v : graph[u]) {
            if (dis[v] > dis[u] + 1) {
                dis[v] = dis[u] + 1;
                pars[v] = u;
                que.push(v);
            }
        }
    }

    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        if (dis[i] >= INF) {
            ++cnt;
        }
    }
    if (cnt > 0) {
        cout << "No\n";
    } else {
        cout << "Yes\n";

        for (int i = 1; i < n; ++i) {
            cout << pars[i] + 1 << '\n';
            // cout << i << " " << dis[i] << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 10568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const long long INF = 1e18;
# define len(x) ((int)(x).size())
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define foreps(i, m, n) for(int i = m;i < n;i++)
# define ALL(x) (x).begin(), (x).end()
# define rall(x) (x).rbegin(), (x).rend()
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 GCD (ll X, ll Y) {
    return Y ? GCD(Y, X % Y) : X;
}

ll num(ll N, ll C, ll D) {
    ll G = GCD(C, D);
    ll L = C / G * D;
    return N - N / C - N / D + N / L;
}

int main() {
    ll A, B, C, D; cin >> A >> B >> C >> D;
    cout << num(B, C, D) - num(A - 1, C, D) << endl;
}

Measured memory_bytes: 3596
fn main() {
    let mut buf = String::new();

    // 標準入力から全部bufに読み込む
    std::io::stdin().read_line(&mut buf).unwrap();

    let mut iter = buf.trim().split_whitespace();
    let height: i32 = iter.next().unwrap().parse().unwrap();
    let width: i32 = iter.next().unwrap().parse().unwrap();
    println!("{} {}", height * width, 2 * (height + width) );
}


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

int main(){
    int h , w ;
    cin >> h >> w;

    string blank ;
    for ( int i = 0; i < w + 2; i++)
    {
     blank +=".";
    }

    string str = blank;

    for (int i = 0; i < h ; i++)
    {
        string s ;
        cin >> s ;
        str += "."+ s + ".";
        //strin =  "."+ s + ".";
        //cout << strin << endl;
    }
    //cout << blank << endl;

     str += blank;
     //cout << str << endl;
    for (int  i = 0; i < h; i++)
    {
        string yokoretu;
        for (int j = 0; j < w; j++)
        {
            if(str.at((w+2)*(i+1) + j+1 )== '#'){
                yokoretu += "#";
            }
            else{
                string what_does_exist ;
                what_does_exist = str.substr((w+2)*(i) + j,3)+
                                str.substr((w+2)*(i+1) + j,1)+str.substr((w+2)*(i+1) + j+2,1)+ 
                                str.substr((w+2)*(i+2) + j,3);
                //cout << "what does exist" <<  what_does_exist << endl;
                int how_many_bomb = 0;
                for (int k = 0; k < 8; k++)
                {
                    if(what_does_exist.at(k) == '#'){
                        how_many_bomb ++;
                    }
                }
                //cout << "how many bomb" << how_many_bomb << endl;
                

                yokoretu += to_string(how_many_bomb);   
            }
        }
        cout << yokoretu << endl;
        
    }
    

}

Measured memory_bytes: 3700
n = int(input())
a = ord('a')

def dfs(s, m):
    # print("dfs", s, chr(m))
    if len(s) == n:
        print(s)
    else:
        for i in range(m + 1 - a):
            dfs(s + chr(a + i), m + 1 if i == m - a else m)

dfs("", a)

Measured memory_bytes: 57048
N = int(input())
positions = []
for _ in range(N):
    positions.append(list(map(int, input().split())))

from itertools import permutations
from math import factorial

res = 0
for p in permutations(range(N)):
    for i, j in zip(p, p[1:]):
        x0, y0 = positions[i]
        x1, y1 = positions[j]
        res += ((x1-x0)**2 + (y1-y0)**2)**0.5
print(res/factorial(N))

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

using ll=long long;
#define int ll

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

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

signed main(){
	// your code goes here
	string a,b,c;
	cin >> a >> b >> c;
	a[0]=toupper(a[0]);
	b[0]=toupper(b[0]);
	c[0]=toupper(c[0]);
	cout << a[0] << b[0] << c[0] << endl;
}

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

const ll INF = 1LL << 60;

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

    string s;
    ll k;
    cin >> s >> k;
    ll n = s.size();
    if (n == 1){
        cout << k/2 << endl;
        return 0;
    }

    ll a = 0;
    for (ll i = 0; i < n; i++){
        if (s[0] == s[i]){
            a++;
        }
        else{
            break;
        }
    }

    if (a == n){
        cout << k*n/2 << endl;
        return 0;
    }

    ll b = 0;
    for (ll i = n-1; i >= 0; i--){
        if (s[n-1] == s[i]){
            b++;
        }
        else{
            break;
        }
    }

    ll d = 0;
    ll c = 1;
    for (ll i = a; i < n-b; i++){
        if (s[i] == s[i+1]){
            c++;
        }
        else{
            d += c/2;
            c = 1;
        }
    }
    d += c/2;

    ll ans = 0;

    if (s[0] == s[n-1]){
        ans += a/2;
        ans += b/2;
        ans += (a+b)/2 * (k-1);
        ans += d*k;
    }
    else{
        ans = ((a/2)+(b/2)+d)*k;
    }
    
    cout << ans << endl;


}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a,b;
int main()
{
    scanf("%lld%lld%lld",&n,&a,&b);
    if(a==b)
        if(n<1)
            printf("0\n");
        else
            printf("1\n");
    else if(n==1)
    {
        if(a==b)
            printf("1\n");
        else
            printf("0\n");
    }
    else if(a>b)
        printf("0\n");
    else
    {

        printf("%lld\n",(b*(n-2)-a*(n-2)+1));
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, s[110];
bool dp[110][10010];

signed main() {
    cin >> N;
    rep(i,0,N) cin >> s[i];
    dp[0][0] = true;
    rep(i,0,N) rep(j,0,10010) {
        dp[i+1][j] |= dp[i][j];
        if(j-s[i] < 0) continue;
        dp[i+1][j] |= dp[i][j-s[i]];
        // if(dp[i+1][j]) printf("i = %lld, j = %lld\n", i+1, j);
    }
    int ans = 0;
    rep(i,0,10010) if(i%10 && dp[N][i]) ans = max(ans, i);
    cout << ans << endl;
    return 0;
}

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

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

// chmax, chmin
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;
}

void solve(long long H, long long W, long long N) {
    long long x = max(H, W);
    cout << (N+x-1) / x << endl;
}

int main() {
  long long H;
  scanf("%lld", &H);
  long long W;
  scanf("%lld", &W);
  long long N;
  scanf("%lld", &N);
  solve(H, W, N);
  return 0;
}


Measured memory_bytes: 764
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int cnt[100010];
int check[30][100010];

vector<pair<int, int>> p[30];

int main() {
	int N, C;
	cin >> N >> C;
	for(int i = 0; i < N; i++) {
		int s, t, c;
		cin >> s >> t >> c;
		c--;
		for(int j = s; j <= t; j++) {
			check[c][j]++;
		}
		p[c].push_back({ s, t });
	}
	for(int i = 0; i < C; i++) {
		for(auto x : p[i]) {
			int s = x.first, t = x.second;
			if(check[i][s] == 2) {
				cnt[s + 1]++;
			}
			else {
				cnt[s]++;
			}
			cnt[t + 1]--;
		}
	}

	int ans = 0, sum = 0;
	for(int i = 0; i < 100010; i++) {
		sum += cnt[i];
		ans = max(ans, sum);
	}
	cout << ans << endl;
}

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

int64_t solve(int64_t n, int64_t c, int64_t d) {
  int64_t res = n;
  res -= n/c;
  res -= n/d;
  int64_t lcm = c/__gcd(c,d)*d;
  res += n/lcm;
  return res;
}

int inf = 2147483647;
int64_t inf64 = 9223372036854775807;
int MOD = 1e+7;

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

  int64_t a, b, c, d;
  cin >> a >> b >> c >> d;

  int64_t x = solve(b, c, d);
  int64_t y = solve(a-1, c, d);

  cout << x - y << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <stdarg.h>
#include <algorithm>
#include <iostream>
#include <iomanip>

using namespace std;

int
main() {
  double pi = 3.1415926535898;
  double a, b, x;
  cin>>a>>b>>x;
  x /= a;


  if (a*b/2 >= x) {
    double y = 2*x/b;
    double v = atan(b/y);
    double j = v/pi*180.;
    printf("%.10lf\n", j);
  }
  else {
    double area = a * b - x;
    double h = area * 2 / a;
    double v = atan(h/a);
    double j = v/pi*180.;
    printf("%.10lf\n", j);
  }

  return 0;
}
 


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(void){
    int n, a;
    cin >> n;
    int l[n];
    for(int i = 0; i < n; i++){
        cin >> a;
        l[i] = a;
    }
    for(int i = 0; i<n-1; i++){
        cout << l[n-i-1] << " ";
    }
    cout << l[0] << endl;
}



Measured memory_bytes: 3080
#include <math.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>
#include <climits>
using namespace std ;
#define ld long double
#define _ ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL);
#define inp(a) for(auto& i : a) cin >> i;
#define out(a) for(auto i : a){cout << i << ' ';}cout << endl;
#define dbg(x) cerr << #x << " is " << x << endl;
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pii pair<int,int>
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
#define LOCAL
#define int long long
const int N = 2e5+7 ;
const int INF = 1e9 ;
const int MOD = INF + 7 ;
string s ;

int32_t main(){_
	int n,m ;
	cin >> n >> m ;
	vi a(n) ;
	inp(a) ;
	priority_queue<int> Q ;
	for(int i = 0 ; i < n ; i++){
		Q.push(a[i]); 
	}
	for(int i= 0 ; i < m ; i++){
		int x = Q.top() ;
		Q.pop() ;
		x /= 2 ;
		Q.push(x) ;
	}
	int ans = 0 ;
	while(!Q.empty()){
		ans += Q.top() ;
		Q.pop() ;
	}
	cout << ans << endl ;
}





Measured memory_bytes: 2168
<?php

fscanf(STDIN, '%d', $N);

$ls = array_map(function ($i) {
    return intval($i);
}, explode(' ', trim(fgets(STDIN))));

rsort($ls);

if ($ls[0] < array_sum($ls)-$ls[0]) {
    echo 'Yes';
} else {
    echo 'No';
}

echo PHP_EOL;


Measured memory_bytes: 16204
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a[4],e,f;
    for(int i=0;i<4;i++){
        cin>>a[i];
    }
    
    cin>>f>>e;
    
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            if(a[j]<a[j+1]){
                swap(a[j],a[j+1]);
            }
        }
    }
    if(e<f){
        swap(e,f);
    }
    cout<<a[0]+a[2]+a[1]+e<<endl;
    return 0;
}

Measured memory_bytes: 3096