akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int a[220000];
int ans[220000];
vector<int> dp(220000, INF);
vector<int> edge[220000];

void dfs(int x, int last = -1){
  int changed_index = lower_bound(dp.begin(), dp.end(), a[x]) - dp.begin();
  int last_value = dp[changed_index];
  dp[changed_index] = a[x];
  /*cout << "## " << x << endl;
  for (int i = 0; i < 10; i++) cout << dp[i] << " ";
  cout << endl;*/

  ans[x] = lower_bound(dp.begin(), dp.end(), INF) - dp.begin();
  for (auto to: edge[x]){
    if (to == last) continue;
    dfs(to, x);
  }
  dp[changed_index] = last_value;
}

int main(){
  int n, u, v;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n -1; ++i){
    cin >> u >> v; u--, v--;
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  dfs(0);

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


Measured memory_bytes: 28432
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
const int INF = 100000000;

int solve(vector<vector<int> > dist,int s,int g1,int g2){
    int n = dist.size();
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);
            }
        }
    }
    int ret = INF;
    for(int k=0;k<n;k++){
        ret = min(ret,dist[s][k]+dist[k][g1]+dist[k][g2]);
    }
    return ret;
}
int main(){
    while(true){
        int n,m,s,g1,g2;
        cin >> n >> m >> s >> g1 >> g2;
        if(n == 0) break;
        s--;g1--;g2--;
        vector<vector<int> > dist(n,vector<int>(n,INF));
        for(int i=0;i<m;i++){
            int a,b,c;
            cin >> a >> b >> c;
            a--;b--;
            dist[a][b] = c;
        }
        for(int i=0;i<n;i++){
            dist[i][i] = 0;
        }
        cout << solve(dist,s,g1,g2) << endl;
    }
    return 0;
}

Measured memory_bytes: 1304
import sys
input = sys.stdin.readline

class UnionFind:
    def __init__(self, size):
        self.parent = [-1 for i in range(size)]#非負なら親ノード，負ならグループの要素数

    def root(self, x): #root(x): xの根ノードを返す．
        if self.parent[x] < 0:
            return x
        elif self.parent[self.parent[x]] < 0:
            return self.parent[x]
        else:
            self.parent[x] = self.root(self.parent[self.parent[x]]) #xをxの根に直接つなぐ
            return self.parent[x]

    def merge(self, x, y): #merge(x,y): xのいるグループと$y$のいるグループをまとめる
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        if self.parent[x] > self.parent[y]: #xの要素数がyの要素数より「小さい」とき入れ替える
            x,y=y,x
        self.parent[x] += self.parent[y] #xの要素数を更新
        self.parent[y] = x #yをxにつなぐ
        return True

    def issame(self, x, y): #same(x,y): xとyが同じグループにあるならTrue
        return self.root(x) == self.root(y)
        
    def size(self,x): #size(x): xのいるグループの要素数を返す
        return -self.parent[self.root(x)]


n,m=[int(i) for i in input().split()]

A=[[int(i)-1 for i in input().split()] for _ in range(m)]

ans = [0]*(m+1)
a = n*(n-1)//2
ans[0] = a

uf = UnionFind(n)
for i in range(m):
    j = m-i-1
    v1 = A[j][0]
    v2 = A[j][1]
#    print(v1,v2)
    if not uf.issame(v1,v2):
#        print(uf.parent)
        a -= uf.size(v1) * uf.size(v2)
        uf.merge(v1,v2)

    ans[i+1]=a

for i in range(m):
    print(ans[m-i-1])
    
    
    
    
    
    





Measured memory_bytes: 27192
#include<iostream>
#include<cmath>
#include<numeric>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define int64 long long
#define yokuwaruprime (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  string s;
  cin>>s;
  int k,l=s.length();
  cin>>k;
  if(l==1){
    cout<<s;
  }else{
  vector<string> v;
  rep1(i,k+1){
    rep(j,l-i+1){
      v.push_back(s.substr(j,i));
    }
  }
  sort(v.begin(),v.end());
  int count=1,ans;
  rep1(i,30000){
    if(v[i-1]!=v[i]){
      count++;
    }
    if(count==k){
      ans=i;
      break;
    }
  }
  cout<<v[ans];
}
}


Measured memory_bytes: 1660
N = int(input())
List = []

for i in range(1,N+1):
  List.append(int(input()))
list1 = List.copy()
List.sort(reverse=True)
MAX = List[0]
SEC_MAX = List[1]
for i in list1:
  if i != MAX:
    print(MAX)
  else:
    print(SEC_MAX)

Measured memory_bytes: 14112
#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 PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int antena[5],k;
    cin >>antena[0] >> antena[1] >> antena[2] >> antena[3] >> antena[4] >> k;
    for(int i=0;i<5;i++){
        for(int j=i+1;j<5;j++){
            if(abs(antena[i] - antena[j]) > k){
                cout << ":(" << endl;
                return 0;
            }
        }
    }
    cout << "Yay!" << endl;
}

Measured memory_bytes: 256
#include <cstdio>

const int maxn = 410;

int n, m;
int in[maxn], out[maxn], par[maxn];
bool f[maxn];

int F(int u) {
	return par[u] == u ? u : par[u] = F(par[u]);
}

int main() {
	scanf("%d%d", &m, &n);
	for (int i = 1; i <= n + n; ++i) {
		par[i] = i;
	}
	for (int i = 1; i <= m; ++i) {
		int a, b, c, d, x, y;
		scanf("%d%d%d%d", &a, &b, &c, &d);
		x = c == 0 ? a : c + n;
		y = d == 0 ? b + n : d;
		par[F(x)] = F(y);
		++in[y];
		++out[x];
	}
	for (int i = 1; i <= n; ++i) {
		if(out[i] < in[i]) {
			return !puts("NO");
		}
		if(in[i] < out[i]) {
			f[F(i)] = 1;
		}
	}
	for (int i = 1; i <= n; ++i) {
		if(out[n + i] > in[n + i]) {
			return !puts("NO");
		}
	}
	for (int i = 1; i <= n + n; ++i) {
		if(F(i) == i && in[i] + out[i] && !f[i]) {
			return !puts("NO");
		}
	}
	return !puts("YES");
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    string s;
    cin >> s;
    bool ans = s[0] != s[1] || s[1] != s[2];
    cout << (ans? "Yes" : "No") << endl;
}

Measured memory_bytes: 760
#include <bits/stdc++.h>
using namespace std;
int main(){
    int W, H, x, y, r;
    cin>>W>>H>>x>>y>>r;
    
    if(x+r<=W && y+r<=H && x-r>=0 && y-r>=0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

void pfact(ll n, map<ll,ll> &mp) {
  while(n%2==0) { mp[2]++; n /= 2;}
  for(ll i=3;i*i<=n;i+=2) {
    while(n%i==0) { mp[i]++; n/=i;}
  }
  if (n!=1) mp[n]+=1;
  return;
}

/*
    75= 1*75
      = 3*25
      = 5*15
      = 3*5*5
*/

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N,ans=0,ans_=0;cin>>N;
  map<ll,ll> mp;
  for(ll i=1;i<=N;++i) pfact(i,mp);
  ll num1=mp.size(),num2=0,num4=0,num14=0,num24=0,num74=0;
  for(auto i:mp) {
    if(2<=i.second &&i.second<=3) num2++;
    if(4<=i.second &&i.second<=13) num4++;
    if(14<=i.second&&i.second<=23) num14++;
    if(24<=i.second&&i.second<=73) num24++;
    if(74<=i.second) num74++; 
  }
  // 1*75
  ans_=num74;
  ans+=ans_;
  // 3*25
  ans_=0;
  ans_+=(num2+num4+num14+num74)*num24;
  ans_+=(num24-1)*num24;
  ans_+=(num2+num4+num14+num24)*num74;
  ans_+=(num74-1)*num74;
  ans+=ans_;
  //5*15
  ans_=0;
  ans_+=(num4+num24+num74)*num14;
  ans_+=(num14-1)*num14;
  ans_+=(num4+num14+num74)*num24;
  ans_+=(num24-1)*num24;
  ans_+=(num4+num14+num24)*num74;
  ans_+=(num74-1)*num74;
  ans+=ans_;
  //3*5*5
  ans_=0;
  ans_+=num2*(num4*(num4-1)+num14*(num14-1)+num24*(num24-1)+num74*(num74-1))/2;
  ans_+=num2*(num4*num14+num4*num24+num4*num74+num14*num24+num14*num74+num24*num74);
  ans_+=num4*(num4-1)*(num4-2)/2;
  ans_+=num4*(num14*(num14-1)+num24*(num24-1)+num74*(num74-1))/2;
  ans_+=num4*((num4-1)*num14+(num4-1)*num24+(num4-1)*num74);
  ans_+=num4*(num14*num24+num14*num74+num24*num74);
  ans_+=num14*(num14-1)*(num14-2)/2;
  ans_+=num14*(num4*(num4-1)+num24*(num24-1)+num74*(num74-1))/2;
  ans_+=num14*((num14-1)*num4+(num14-1)*num24+(num14-1)*num74);
  ans_+=num14*(num4*num24+num4*num74+num24*num74);
  ans_+=num24*(num24-1)*(num24-2)/2;  
  ans_+=num24*(num4*(num4-1)+num14*(num14-1)+num74*(num74-1))/2;
  ans_+=num24*((num24-1)*num4+(num24-1)*num14+(num24-1)*num74);
  ans_+=num24*(num4*num14+num4*num74+num14*num74);
  ans_+=num74*(num74-1)*(num74-2)/2;  
  ans_+=num74*(num4*(num4-1)+num14*(num14-1)+num24*(num24-1))/2;
  ans_+=num74*((num74-1)*num4+(num74-1)*num14+(num74-1)*num24);
  ans_+=num74*(num4*num14+num4*num24+num14*num24);
  ans+=ans_;
  print(ans);
  return 0;
}

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

int main(){
int a,b,c,n;
    
    
    cin>>a>>b>>c;
    
    
    if(a>b){
    n=b;
    b=a;
    a=n;
    }
    if(b>c){
    n=c;
    c=b;
    b=n;
    }
    if(a>b){
    n=b;
    b=a;
    a=n;
    }
    cout<<a<<" "<<b<<" "<<c<<"\n";
}


Measured memory_bytes: 3104
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
typedef long long ll;
const int MAXN=1e5+5,MAXM=2e5+5,P=1e9+7;
 
int N,M,S,T;
 
struct E{int next,to,val;} e[MAXM<<1];int ecnt,G[MAXN];
void addEdge(int u,int v,int w){e[++ecnt]=(E){G[u],v,w};G[u]=ecnt;}
void addEdge2(int u,int v,int w){addEdge(u,v,w);addEdge(v,u,w);}
 
ll fS[MAXN],dS[MAXN],fT[MAXN],dT[MAXN];
 
struct HN{int id;ll v;};
bool operator <(const HN &a,const HN &b){return a.v>b.v;}
std::priority_queue<HN> heap;
bool inS[MAXN];
void dijkstra(int v0,ll *f,ll *d)
{
	memset(inS,0,sizeof inS);
	memset(d,0x3f,sizeof dS);
	d[v0]=0,f[v0]=1;heap.push((HN){v0,0});
	while(!heap.empty())
	{
		int u=heap.top().id;heap.pop();
		if(inS[u]) continue;inS[u]=true;
		for(int i=G[u];i;i=e[i].next)
		{
			int v=e[i].to;
			if(inS[v]) continue;
			if(d[v]>d[u]+e[i].val)
			{
				f[v]=f[u];
				d[v]=d[u]+e[i].val;
				heap.push((HN){v,d[v]});
			}
			else if(d[v]==d[u]+e[i].val) f[v]=(f[v]+f[u])%P;
		}
	}
}
 
struct A{int u,v,w;} a[MAXM];
int main()
{
	int i;scanf("%d%d%d%d",&N,&M,&S,&T);
	for(i=1;i<=M;i++)
	{
		int u,v,w;scanf("%d%d%d",&u,&v,&w);
		addEdge2(u,v,w);a[i]=(A){u,v,w};
	}
	dijkstra(S,fS,dS);
	dijkstra(T,fT,dT);
	int ans=(ll)fS[T]*fS[T]%P;
	for(i=1;i<=N;i++)
		if(dS[i]==dT[i]&&dS[i]+dT[i]==dS[T])
			ans=(ans+P-fS[i]*fS[i]%P*fT[i]%P*fT[i]%P)%P;
	for(i=1;i<=M;i++)
	{
		int u=a[i].u,v=a[i].v,w=a[i].w;
		if(dS[u]>dS[v]) std::swap(u,v);
		if(dS[u]<dS[T]>>1&&dT[v]<dT[S]>>1&&dS[u]+dT[v]+w==dS[T])
		//if(dS[u]+dT[v]+w==dS[T]&&std::max(dS[u],dT[v])<std::min(dS[u],dT[v])+w)
			ans=(ans+P-fS[u]*fS[u]%P*fT[v]%P*fT[v]%P)%P;
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 13044
def modpow(a,n,p):
    if n==0:
        return 1
    x=modpow(a,n//2,p)
    x=(x*x)%p
    if (n%2)==1:
        x=(x*a)%p
    return x%p
def modinv(a,p):
    return modpow(a,p-2,p)
from fractions import gcd
N=int(input())
A=list(map(int,input().split()))
new=[0]*N
A.sort()
insuu=[0]*(A[N-1]+1)
pf={}
l=[]
ans=1
cnt=0
p=(10**9)+7

for i in range(N):
    m = A[i]
    for j in range(2,int(m**0.5)+1):
        while m%j==0:
            pf[j]=pf.get(j,0)+1
            m//=j
    if m>1:pf[m]=1
    #print(pf)
    keys=list(pf.keys())
    values=list(pf.values())
    pf={}
    for j in range(len(keys)):
        if insuu[keys[j]]<values[j]:
            insuu[keys[j]]=values[j]
        #print(insuu)
    #print(l)
for i in range(1,A[N-1]+1,1):
    if insuu[i]>0:
        ans=ans*pow(i,insuu[i])
#print(ans)
for i in range(N):
    #print((ans*modinv(A[i],p))%p)
    cnt=(cnt+(ans*modinv(A[i],p))%p)%p
print(cnt%p)



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

int binarySearch( int l, int r, int k, int* a )
{
    int cnt = 0;
    while( l <= r )
    {
        cnt++;
        int mid = ( l + r ) / 2;
        if( k < a[mid] )
            r = mid - 1;
        else if( k > a[mid] )
            l = mid + 1;
        else
            return cnt;
    }
    return cnt;
}

int main()
{
    int n, a[100], key;

    while( cin >> n )
    {
        if( n == 0 )
            break;

        for( int i = 0; i < 100; i++ )
            a[i] = 0;

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

        int left = 0, right = n - 1;
        cout << binarySearch( left, right, key, a ) << endl;
    }
    return 0;
}



Measured memory_bytes: 3092
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define INF 1000000000000000

vector<ll> graph[1000000];
vector<ll> topo;
ll dist[1000000];
ll color[1000000];
bool loop = false;

void dfs(ll now){
  color[now] = 1;
  for(int i=0;i<graph[now].size();i++){
    if(color[graph[now][i]] == 0){
      dfs(graph[now][i]);
    }
    if(color[graph[now][i]] == 1) loop = true;
  }
  color[now] = 2;
  topo.push_back(now);
}


int main(){
  ll n;
  cin >> n;
  ll a[n][n-1];
  for(int i=0;i<n;i++){
    for(int j=0;j<n-1;j++){
      cin >> a[i][j];
      a[i][j] -= 1;
    }
  }

  ll ij2v[n][n];
  ll v_num = 0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      ij2v[i][j] = v_num;
      ij2v[j][i] = v_num;
      v_num += 1;
    }
  }

  for(int i=0;i<v_num;i++){
    color[i] = 0;
  }
  ll s,t;
  for(int i=0;i<n;i++){
    for(int j=1;j<n-1;j++){
      s = ij2v[i][a[i][j-1]];
      t = ij2v[i][a[i][j]];
      graph[s].push_back(t);
    }
  }

  for(int i=0;i<v_num;i++){
    if(color[i] == 0) dfs(i);
    if(loop){
      cout << -1 << endl;
      return 0;
    }
  }

  ll dist[v_num];
  for(int i=0;i<v_num;i++){
    dist[i] = 1;
  }
  for(int i=0;i<v_num;i++){
    ll now = topo[i];
    for(int j=0;j<graph[now].size();j++){
      dist[now] = max(dist[now],dist[graph[now][j]]+1);
    }
  }
  ll ans = 0;
  for(int i=0;i<v_num;i++){
    ans = max(ans,dist[i]);
  }
  cout << ans << endl;


  return 0;
}


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

 
int main() {
  int x,a,b;
  cin>>x>>a>>b;
  
  if(b<=a){
    cout <<"delicious"<<endl;
  }
  else{
    if(b<=a+x){
      cout<<"safe"<<endl;
    }
    else{
      cout<<"dangerous"<<endl;
    }
  }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n;
ll k, h[200010];

int main() {
    cin >> n >> k;
    rep(i, n) cin >> h[i];
    sort(h, h+n);
    ll ans = 0;

    if (n <= k) {
        cout << ans << endl;
        return 0;
    } else {
        for (int i = 0; i < n-k; i++) {
            ans += h[i];
        }
        cout << ans << endl;
    }
}


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

int mod = 1e9 + 7;

long long dp[61][2][2][2];

int main(){
    long long l, r;
    cin >> l >> r;
    //dp[桁(i)][L(j)][R(k)][最上位(s)]
    dp[60][0][0][0] = 1;
    for (int i = 59; i >= 0; i--){
        int lb = (l >> i) & 1;
        int rb = (r >> i) & 1;
        for (int j = 0; j < 2; j++){
            for (int k = 0; k < 2; k++){
                for (int s = 0; s < 2; s++){
                    for (int x = 0; x < 2; x++){
                        for (int y = 0; y < 2; y++){
                            if (x && !y) continue;
                            int nj = j; int nk = k; int ns = s;
                            if (!s && x != y) continue;
                            if (x && y) ns = 1;
                            if (!j && lb && !x) continue;
                            if (!lb && x) nj = 1;
                            if (!k && !rb && y) continue;
                            if (rb && !y) nk = 1;
                            dp[i][nj][nk][ns] += dp[i + 1][j][k][s];
                            dp[i][nj][nk][ns] %= mod;
                        }
                    }
                }
            }
        }
    }
    long long ans = 0;
    for (int j = 0; j < 2; j++){
        for (int k = 0; k < 2; k++){
            for (int s = 0; s < 2; s++) {
                ans += dp[0][j][k][s];
                ans %= mod;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
from collections import Counter


N = int(input())
lstA = list(map(int, input().split()))
mod = 10**9 + 7
countA = Counter(lstA)
ans = 0

if N % 2:
    if countA[0] == 1 and all(countA[i] == 2 for i in range(2, N, 2)):
        ans = pow(2, N//2, mod)
else:
    if all(countA[i] == 2 for i in range(1, N, 2)):
        ans = pow(2, N//2, mod)


print(ans)


Measured memory_bytes: 14820
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int n;
    double k;
    cin >> n >> k;

    double res = 0;
    for (double i = 1; i <= n; i++)
    {
        int time = ceil(log2(k / i));

        double p = (double)1 / n;

        for (int j = 0; j < time; j++)
            p /= 2;

        res += p;
    }

    cout << setprecision(20) << res << endl;

    return 0;
}

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

#define INF (2e9)
#define FOR(i, a, b) for (ll (i) = (a); (i) < (b); ++(i))
#define REP(i, n) FOR(i, 0, n)

using namespace std;

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

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

using ll = long long;
using ld = long double;

#define ALL(x) (x).begin(), (x).end()
template<class T>
using vc = vector<T>;
using vi = vc<ll>;
using vvi = vc<vi>;

template<class T>
using va = valarray<T>;
using vad = va<ld>;
using vai = va<ll>;

vi Read(ll n) {
    auto      v = vi(n);
    for (auto i = std::size_t(0); i < n; ++i) {
        cin >> v[i];
    }
    return v;
}

template<class T>
void Dump(const T& A) {
    REP(i, A.size() - 1) cout << A[i] << " ";
    cout << A[A.size() - 1] << "\n";
}

template<class T>
void PushBack(T& v) {
    auto x = 0;
    cin >> x;
    v.push_back(x);
}

template<class T>
void RandomAccess(const T& v) {
    auto x = 0;
    cin >> x;
    cout << v[x] << endl;
}

template<class T>
void PopBack(T& v) {
    v.pop_back();
}

int main() {
    ll p;
    cin >> p;

    deque<ll> dq;
    REP(i, p) {
        int query;
        cin >> query;
        if (query == 0) {
            int d, x;
            cin >> d >> x;
            if (d == 0) dq.push_front(x);
            else dq.push_back(x);
        } else if (query == 1) {
            auto x = 0;
            cin >> x;
            cout << dq[x] << endl;
        } else if (query == 2) {
            int d;
            cin >> d;
            if (d == 0) dq.pop_front();
            else dq.pop_back();
        } else cout << "Error: query is not correct\n";
    }

    return 0;
}



Measured memory_bytes: 6196
#include<stdio.h>

int main ()
{
   int t, h, m, s;

   scanf ("%d", &t);

   h = t / 3600;

   m = (t - h*3600) / 60;

   s = t - h*3600 - m*60;

   printf("%d:%d:%d\n", h, m, s);

   return 0;

}

Measured memory_bytes: 1844
N = int(input())
a = list(map(int, input().split()))

# dp[i][j] = a[i:j] を考えたときの X-Y の最大値
dp = [[0]*(N+1) for _ in range(N+1)]
for l in range(1, N+1):
    for i in range(N-l+1):
        j = i+l
        if (N-l)%2 == 0:
            dp[i][j] = max(dp[i+1][j]+a[i], dp[i][j-1]+a[j-1])
        else:
            dp[i][j] = min(dp[i+1][j]-a[i], dp[i][j-1]-a[j-1])
        
print(dp[0][N])

Measured memory_bytes: 114780
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		
		while(input.hasNext()){
			int x = input.nextInt();
			int a = input.nextInt();
			int b = input.nextInt();
			
			if(Math.abs(x - a) < Math.abs(x - b)){
				System.out.println("A");
			} else {
				System.out.println("B");
			}
		}

	}

}


Measured memory_bytes: 20820
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int a = 0;
	int b = 0;
	int c = 0;
	int x = 0;
	int y = 0;
	int payments;
	scanf("%d %d %d %d %d", &a, &b, &c, &x, &y);
	
	if (a < c && b < c) {
		payments = a * x + b * y;
	}
	else {
		if (x == y) {
			payments = 2 * c * x;
		}
		else {
			if (x > y) {
				payments = 2 * c * y + a * (x - y);
				if (payments > 2 * c * x) {
					payments = 2 * c * x;
				}
				if (payments > a * x + b * y) {
					payments = a * x + b * y;
				}
			}
			else {
				payments = 2 * c * x + b * (y - x);
				if (payments > 2 * c * y) {
					payments = 2 * c * y;
				}
				if (payments > a * x + b * y) {
					payments = a * x + b * y;
				}
			} 
		}
	}
	
	printf("%d\n", payments);
	
	return 0;
}

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

int main() {
    int n, x, y;
    cin >> n >> x >> y;
    int dp[n+1][n+1];

    for (int j=1; j<n+1; j++) {
        for (int i=j+1; i<n+1; i++) {
            dp[j][i] = i-j;
        }
    }
    //for (int j=1; j<n+1; j++) {
    //    for (int i=j+1; i<n+1; i++) {
    //        cout << dp[j][i] << " ";
    //    }
    //    cout << endl;
    //}
    for (int j=1; j<n+1; j++) {
        for (int i=j+1; i<n+1; i++) {
            if (j<=x && i>=y) {
                dp[j][i] = min(dp[j][i], i-j-(y-x)+1);
            }
        }
    }
    for (int j=x; j<y; j++) {
        for (int i=y; i>x; i--) {
            int dtmp = (j-x) + (y-i)+1;
            dp[j][i] = min(dp[j][i], dtmp);
        }
    }
    for (int j=1; j<x; j++) {
        for (int i=y; i>x; i--) {
            int dtmp = (x-j) + (y-i)+1;
            dp[j][i] = min(dp[j][i], dtmp);
        }
    }
    for (int j=x; j<y; j++) {
        for (int i=n; i>y; i--) {
            int dtmp = (j-x) + (i-y)+1;
            dp[j][i] = min(dp[j][i], dtmp);
        }
    }
    //for (int j=1; j<n+1; j++) {
    //    for (int i=j+1; i<n+1; i++) {
    //        cout << dp[j][i] << " ";
    //    }
    //    cout << endl;
    //}
    int cnt[n];
    for (int i=0; i<n; i++) {
        cnt[i] = 0;
    }
    for (int j=1; j<n+1; j++) {
        for (int i=j+1; i<n+1; i++) {
            cnt[dp[j][i]]++;
        }
    }
    for(int i=1; i<n; i++){
        cout << cnt[i] << endl;
    }
}

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

int main(){
    int n,t=0;
    cin>>n;
    int a[n][2];
    for(int i=0;i<n;i++)
        cin>>a[i][1]>>a[i][0];
    sort((pair<int,int>*)a[0], (pair<int,int>*)a[n], []( pair<int,int> x, pair<int,int> y ) { return x.first < y.first; });
    for(int i=0;i<n;i++){
        t += a[i][1];
        if(t>a[i][0]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>
using namespace std;

int main()
{
    int num, k;
    cin >> num >> k;
    int box[60];
    for(int i=1;i<=num;i++){
        cin >> box[i];
    }

    int ans = 0;
    for(int ire=0;ire<=k/2;ire++){
        int sum = 0;
        for(int mae = 0;mae<=k-ire;mae++){
            sum = 0;
            int count = 0;
            vector<int> v;
            for(int i=1;i<=mae;i++){
                if(count >= num){
                    break;
                }
                sum += box[i];
                v.push_back(box[i]);
                count ++;
            }
            for(int i=num;i>num+mae+ire-k;i--){
                if(count >= num){
                    break;
                }
                sum += box[i];
                v.push_back(box[i]);
                count ++;
            }
            sort(v.begin(),v.end());
            for(int i=0;i<ire;i++){
                if(v[i]<0){
                    sum -= v[i];
                }else{
                    break;
                }
            }
            if(sum >ans ){
                ans = sum;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

class ModTools:
    """ 階乗たくさん使う時用のテーブル準備 """

    def __init__(self, MAX, MOD):
        """ MAX：階乗に使う数値の最大以上まで作る """
        
        MAX += 1
        self.MAX = MAX
        self.MOD = MOD
        # 階乗テーブル
        factorial = [1] * MAX
        factorial[0] = factorial[1] = 1
        for i in range(2, MAX):
            factorial[i] = factorial[i-1] * i % MOD
        # 階乗の逆元テーブル
        inverse = [1] * MAX
        # powに第三引数入れると冪乗のmod付計算を高速にやってくれる
        inverse[MAX-1] = pow(factorial[MAX-1], MOD-2, MOD)
        for i in range(MAX-2, 0, -1):
            # 最後から戻っていくこのループならMAX回powするより処理が速い
            inverse[i] = inverse[i+1] * (i+1) % MOD
        self.fact = factorial
        self.inv = inverse
    
    def nCr(self, n, r):
        """ 組み合わせの数 (必要な階乗と逆元のテーブルを事前に作っておく) """

        if n < r: return 0
        # 10C7 = 10C3
        r = min(r, n-r)
        # 分子の計算
        numerator = self.fact[n]
        # 分母の計算
        denominator = self.inv[r] * self.inv[n-r] % self.MOD
        return numerator * denominator % self.MOD

    def nPr(self, n, r):
        """ 順列 """

        if n < r: return 0
        return self.fact[n] * self.inv[n-r] % self.MOD

    def nHr(self, n, r):
        """ 重複組み合わせ """

        # r個選ぶところにN-1個の仕切りを入れる
        return self.nCr(r+n-1, r)

x, y = MAP()

x, y = min(x, y), max(x, y)
sm = x + y
if sm % 3 != 0:
    print(0)
    exit()
if y - x > sm // 3:
    print(0)
    exit()

# 連立方程式から式変形
a = (2*y-x) // 3
b = (2*x-y) // 3

mt = ModTools(a+b, MOD)
print(mt.nCr(a+b, a))


Measured memory_bytes: 57844
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
int main() {
//input
// std::vector<std::string> S; 
string S;  
cin>>S;
int n=S.length();
int num=0;
//compute
for(int i=0;i<n/2;i++){
if(S[i]!=S[n-i-1])num++;
}
//output
   cout<<num<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func next() string {
	sc.Scan()
	return sc.Text()
}
func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}
func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

//var done []bool = make([]bool, 10)
//var memo []int = make([]int, 10)

//func fib(n int) int {
//	fmt.Println(n)
//	if n == 0 {
//		return 0
//	}
//	if n == 1 {
//		return 1
//	}
//	if done[n] {
//		fmt.Println("done" + fmt.Sprint(n))
//		return memo[n]
//	}
//	done[n] = true
//	memo[n] = fib(n-1) + fib(n-2)
//	return memo[n]
//}

var dp []int = make([]int, 10)

func fib(n int) int {
	dp[0] = 0
	dp[1] = 1
	for i := 2; i <= n; i++ {
		dp[i] = dp[i-1] + dp[i-2]
	}
	return dp[n]
}

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	a := next()
	b := next()
	aCnt := nextInt()
	bCnt := nextInt()
	waist := next()
	if waist == a {
		aCnt--
	} else if waist == b {
		bCnt--
	}
	fmt.Fprint(out, fmt.Sprint(aCnt) + " " + fmt.Sprint(bCnt))
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (auto& e : a) cin >> e;

  for (int i = 0; i < k; i++) {
    vector<int> b(n);
    for (int j = 0; j < n; j++) {
      b[max(0, j - a[j])]++;
      if (j + a[j] + 1 < n) b[j + a[j] + 1]--;
    }
    bool f = b[0] == n;
    for (int j = 0; j + 1 < n; j++) b[j + 1] += b[j];
    a = b;
    if (f) break;
  }

  for (auto e : a) cout << e << ' ';
  cout << endl;
}


Measured memory_bytes: 4844
while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break

    ans = 0
    for a in range(1, n + 1):
        for b in range(a + 1, n + 1):
            tmp = x - a - b
            if b < tmp and tmp <= n:
                ans += 1

    print(ans)


Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int> data(N);
  vector<int> odd;
  for(int i=0;i<N;i++)cin>>data[i];
  int cnt=0;
  for(int i=0;i<N;i++){
    if(data[i]%2==0&&data[i]%3!=0&&data[i]%5!=0){
      cout<<"DENIED"<<endl;
      return 0;
    }
  }
  cout<<"APPROVED"<<endl;
}

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

int main(){
    int x,y;
    cin >> x >> y;
    vector<int> a={0,1,3,1,2,1,2,1,1,2,1,2,1};
    cout << (a[x]==a[y]?"Yes":"No") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long int
#define ii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
#define output(x) for (auto a:x) cout<<a<<" ";cout<<endl;
#define output2(x) for (auto a:x) cout<<a.fi<<" "<<a.se<<endl;
#define PI 3.14159265
#define all(x) x.begin(),x.end()

// DEBUG TEMPLATE
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
  *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
  
// DEBUG TEMPLATE ENDS

#define MOD 1000000007
int power(int x,int y,int mod = MOD) 
{ 
  int ret = 1;
  x = x % mod;
  while (y){
    if(y&1) ret = (ret*x)%mod;
    y = y>>1;
    x = (x*x)%mod;
    } 
    return ret%mod; 
}

void solve()
{ 
  int n,m,k;
  cin>>n>>m>>k;
  int ans = 0;
  vector<string> grid(n);
  for (auto &x:grid) cin>>x;
  for (int i=0;i<(1<<n);i++){
    for (int j=0;j<(1<<m);j++){
      vector<string> grid2 = grid;
      for (int r = 0 ; r < n ; r++){
        if ((1<<r)&i){
          for (int cell = 0 ; cell < m ; cell++){
            grid2[r][cell] = 'r';
          }
        }
      }
      for (int c = 0 ; c < m ; c++){
        if ((1<<c)&j){
          for (int cell = 0 ; cell < n ; cell++){
            grid2[cell][c] = 'r';
          }
        }
      }
      int cnt = 0;
      for (int a = 0 ; a < n ; a++){
        for (int b = 0 ; b < m ; b++){
          if (grid2[a][b] == '#') cnt++;
        }
      }
      if (cnt == k) {
        ans++;
        // debug() << imie(grid2);
        // debug() << imie(i) imie(j);
      }
      // debug() << imie(grid2);
    }
  }
  cout<<ans<<endl;
}


/*
  
*/
signed main(){
  int t = 1;
  // cin>>t;
  while (t--)
  solve();
}
// Check MOD values plox :(


Measured memory_bytes: 3624
import * as fs from 'fs';

const input = fs.readFileSync('/dev/stdin', 'utf8');

_c(input);

function _c(input: string) {
  let N = BigInt(input);
  const a = 'a'.charCodeAt(0);

  let name = '';

  while (N > 0n) {
    let place = N % 26n;
    if (place === 0n) {
      place = 26n; // 0 は存在しない
    }
    name = String.fromCharCode(a + Number(place) - 1) + name;

    N -= place;
    N /= 26n;
  }

  console.log(name);
}


Measured memory_bytes: 29664
N = int(input())
H = [int(h) for h in input().split()]
H.insert(0, 0)
H[0] = H[1]
dp =[0 for _ in range(N + 1)]
dp[0] = H[0]

for i in range(2, N + 1):
    dp[i] = min(dp[i-2] + abs(H[i-2] - H[i]), dp[i-1] + abs(H[i-1]- H[i]))
print(dp[N])


Measured memory_bytes: 53880
#include<queue>
#include<cstdio>
#include<algorithm>

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

using namespace std;

struct edge{
	int u,v,cost;
	bool operator <(const edge &e)const{ return cost<e.cost; }
	bool operator==(const edge &e)const{ return u==e.u && v==e.v && cost==e.cost; }
};

int n,nt;
bool term[10000];
vector<edge> G[10000];

bool bfs(int u0,int pre0){
	queue< pair<int,int> > Q;
	Q.push(make_pair(u0,pre0));
	while(!Q.empty()){
		int u=Q.front().first,pre=Q.front().second; Q.pop();
		if(term[u]) return true;
		rep(i,G[u].size()){
			int v=G[u][i].v;
			if(v!=pre) Q.push(make_pair(v,u));
		}
	}
	return false;
}

int main(){
	for(int T=1,cut;scanf("%d%d%d",&n,&nt,&cut),n;T++){
		rep(u,n){
			G[u].clear();
			term[u]=false;
		}

		edge E[9999];
		rep(i,n-1){
			int u,v,cost; scanf("%d%d%d",&u,&v,&cost); u--; v--;
			G[u].push_back((edge){u,v,cost});
			G[v].push_back((edge){v,u,cost});
			E[i]=(edge){u,v,cost};
		}
		rep(i,nt){
			int u; scanf("%d",&u); u--;
			term[u]=true;
		}

		sort(E,E+n-1);

		int ans=0;
		rep(i,n-1){
			if(cut==0) break;
			const edge &e=E[i];
			if(bfs(e.u,e.v) && bfs(e.v,e.u)){
				G[e.u].erase(find(G[e.u].begin(),G[e.u].end(),(edge){e.u,e.v,e.cost}));
				G[e.v].erase(find(G[e.v].begin(),G[e.v].end(),(edge){e.v,e.u,e.cost}));
				ans+=e.cost;
				cut--;
			}
		}

		printf("Case %d: %d\n",T,ans);
	}

	return 0;
}

Measured memory_bytes: 1740
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
const lli mod=1e9+7;
const lli pINF=100000000000000000;
const lli nINF=-LLONG_MAX;
void fast() {std::ios::sync_with_stdio(false);cin.tie(NULL);}
lli power(lli a,lli b){lli ans=1;while(b!=0){ if(b%2==1){ans*=a;}b/=2;a*=a;} return ans;}
lli invmod(lli a) {return pow(a,mod-2);}
#define vi vector<int>
#define vlli vector<lli>
#define pb push_back
#define mp make_pair
#define F first
const int INF = 0x3f3f3f3f ;
#define PII pair<int,int>
#define S second
#define si(n) scanf("%d",&n)
#define sli(n) scanf("%lld",&n)
#define printi(n) printf("%d\n",n)
#define printli(n) printf("%lld\n",n)
#define all(v) v.begin(),v.end()
#define forn(i,n) for(int i=0;i<n;i++)
void print(int a[],int n){for(int i=0;i<n;i++) cout<<a[i]<<" ";}
 
int main() 
{
    int x,ans=0;
    si(x);
    
    for(int i=1;i<=x;i++){
        for(int j=2;j<=10;j++){
            int p = power(i,j);
            if(p<=x) ans=max(ans,p);
            else break;
        }
    }
    cout<<ans<<endl;
    return 0;
} 

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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pf printf
#define sc scanf
#define sf(n) scanf("%d",&n)
#define sff(n1,n2) scanf("%d %d",&n1,&n2)
#define sfff(n1,n2,n3) scanf("%d %d %d",&n1,&n2,&n3)
#define sl(n) scanf("%lld",&n)
#define sll(n1,n2) scanf("%lld %lld",&n1,&n2)
#define slll(n1,n2,n3) scanf("%lld %lld %lld",&n1,&n2,&n3)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(i=1;i<=n;i++)
#define reps(i,a,n) for(i=a;i<=n;i++)
#define nl puts("");
#define pb push_back
#define MOD 1000000007
#define fi first
#define se second
#define N 100005
#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define sz(x) x.size()
#define pi pair<int,int>
#define pii pair<pair<int,int>,pair<int,int> >
#define line puts("-------");
#define db(x) cout<<#x<<" :: "<<x<<"\n";
#define dbb(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define fr freopen("input.txt","r",stdin);
#define fw freopen("output.txt","w",stdout);
typedef long long int ll;
using namespace std;
int main()
{
    int i,n,k,mn=1e9,cnt=0;
    sf(n);
    rep0(i,n)
    {
        sf(k);
        if(k<=mn)
            cnt++;
        mn=min(mn,k);
    }
    cout<<cnt;
}


Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        Scanner sc = new Scanner(is);
        /* read */
        int n = sc.nextInt();

        Map<Integer, Set<Integer>> lists = new HashMap<>();

        for (int i = 0; i < n; i++) {
            String s = sc.next();
            Set<Integer> list = new HashSet<>();

            for (int j = 0; j < n; j++) {
                if (s.charAt(j) == '1') {
                    // matrix[i][j] = true;
                    list.add(j);
                }
            }
            lists.put(i, list);
        }

        int max = -1;
        for (int i = 0; i < n; i++) {
            max = Math.max(depth(i, lists, n), max);
        }

        os.println(max);
    }

    private static class Node {
        int node;
        Set<Integer> parents = new HashSet<>();
    }

    private static int depth(int start, Map<Integer, Set<Integer>> lists, int N) {
        HashMap<Integer, HashSet<Integer>> tempLists = new HashMap<>();
        for (int j = 0 ; j < N ; j++) {
            tempLists.put(j, new HashSet<>(lists.get(j)));
        }
        Set<Integer> visited = new HashSet<>();
        Set<Node> curr = new HashSet<>();
        Node s = new Node();
        s.node = start;
        curr.add(s);

        int count = 0;
        while (0 < curr.size()) {
            count++;
            Map<Integer, Node> next = new HashMap<>();
            for (Node n : curr) {
                Set<Integer> nexts = tempLists.get(n.node);
                for (int nx : nexts) {
//                    if (n.parents.contains(nx)) {
//                        // parent. ignore
//                        continue;
//                    }
                    if (visited.contains(nx)) {
                        // visiting again
                        return -1;
                    }
                    Node node;
                    if (next.containsKey(nx)) {
                        node = next.get(nx);
                    } else {
                        node = new Node();
                        node.node = nx;
                        next.put(nx, node);
                    }
//                    node.parents.add(n.node);
                }
                visited.add(n.node);
            }
            for (Node n : curr) {
                for(Integer child : next.keySet()) {
                    tempLists.get(child).remove(n.node);
                }
            }
            curr = new HashSet<>(next.values());
        }
        return count;
    }
}

Measured memory_bytes: 162712
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

template <typename T> inline void voutput(T &v){
    rep(i, v.size()){
        if (i) cout << " " << v[i];
        else cout << v[i];
    }
    cout << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    deque<int> dq;
    rep(i, N){
        if(i % 2 == 0){
            dq.push_front(A[i]);
        }
        else{
            dq.push_back(A[i]);
        }
        
    }
    vector<int> B;
    while(!dq.empty()){
        B.push_back(dq.front());
        dq.pop_front();
    }
    if(N % 2 == 0){
        reverse(all(B));
    }
    
    voutput(B);
    
    return 0;
}

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

Measured memory_bytes: 128
import numpy as np
import sys

def main():
    input = sys.stdin.readline
    A, B = map(int, input().split())
    if A >= 13:
        return B
    elif A >= 6 and A < 13:
        return B // 2
    else:
        return 0


if __name__ == '__main__':
    print(main())


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

typedef long long ll;
using namespace std;

int main(){
     string a,b;
     cin >> a >> b;
     int n = a.size(),m = b.size();
     ll dp[n+1][m+1];
     for(int i=0;i<=n;i++) for(int j=0;j<=m;j++) dp[i][j] = 0;
     for(int i=1;i<=n;i++)
          for(int j=1;j<=m;j++)
               if(a[i-1] == b[j-1]) dp[i][j] = dp[i-1][j-1] + 1;
               else dp[i][j] = max({dp[i][j],dp[i-1][j],dp[i][j-1]});
     string ans = "";
     int i = n ,j = m;
     while(i > 0 && j > 0){
          if(dp[i][j] == dp[i-1][j-1] + 1 && dp[i][j] == dp[i-1][j] +1 && dp[i][j] == dp[i][j-1] + 1){
            ans += a[i-1];
            i--;
            j--;
          }
          else if(dp[i][j-1] > dp[i-1][j]) j--;
          else i--;
          
     }
     reverse(ans.begin(),ans.end());
     cout << ans << endl;
     return 0;
}

Measured memory_bytes: 74004
class Array
  def gcd
    self.inject{|a,b| a.gcd(b)}
  end
end
N,X=gets.split.map(&:to_i)
x=gets.split.map(&:to_i)
x=x.map{|i|i-X}
p x.gcd<0 ? -x.gcd : x.gcd

Measured memory_bytes: 9220
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var x = cin.nextInt();

            var ans = 0L;
            for (int b = 1 ; b < 1000; b++)
            {
                for (int p = 2; p < 1000; p++)
                {
                    var tmp = (long)Math.Pow(b, p);
                    if (tmp <= x) ans = Math.Max(ans, tmp);
                }                
            }

            Console.WriteLine(ans);
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 11604
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	N %= 1000;
	int ans = N > 0 ? 1000 - N : 0;
	cout << ans << endl;
	return 0;
}


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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007
typedef long long ll;

int main() {
    ll n,m,k;cin>>n>>m>>k;
    bool jdg=false;

    for(ll i=0;i<=n;i++){
       for(ll j=0;j<=m;j++){
           
            if(i*(m-j)+j*(n-i)==k){
                cout<<"Yes"<<endl;
                jdg=true;
                break;
            }
        }
        if(jdg){
            break;
        }
    }
    if(jdg==false){
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256