akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define int long long

struct BiMatch{
  int n;
  vector<vector<int> > G;
  vector<int> match,used;
  
  BiMatch(){}
  BiMatch(int sz):n(sz),G(sz),match(sz),used(sz){}
  
  void add_edge(int u,int v){
    G[u].push_back(v);
    G[v].push_back(u);
  }

  bool dfs(int v){
    used[v]=true;
    for(int i=0;i<(int)G[v].size();i++){
      int u=G[v][i],w=match[u];
      if(w<0||(!used[w]&&dfs(w))){
        match[v]=u;
        match[u]=v;
        return true;
      }
    }
    return false;
  }

  int build(){
    int res=0;
    fill(match.begin(),match.end(),-1);
    for(int v=0;v<n;v++){
      if(match[v]<0){
        fill(used.begin(),used.end(),0);
        if(dfs(v)){
          res++;
        }
      }
    }
    return res;
  }
};

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, M;
  while ( cin >> N >> M, N ) {

    BiMatch bm(N+M+2);
    vector<int> a(N), b(M);
    for ( int i = 0; i < N; i++ ) cin >> a[i];
    for ( int i = 0; i < M; i++ ) cin >> b[i];

    for ( int i = 0; i < N; i++ ) {
      for ( int j = 0; j < M; j++ ) {
	if ( __gcd(a[i], b[j]) > 1 ) bm.add_edge(i, N+j);      
      }
    }

    cout << bm.build() << endl;
  }
  
  return 0;
}



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

#define rep(i, n) for(int i=0; i < n; i++)
#define REP(i, n, m) for(int i=n; i < m; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

ll mod=2019;

const ll INF = 1LL << 60;

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;}

// a^n mod を計算 再帰
ll modpow(ll a,ll n,ll &mod){
  if(!n) return 1;
  ll x = modpow(a,n/2,mod)%mod;
  x *=x;
  if(n%2==1)x*=a;
  return x%mod;
}



int main(){
  int a,b,c,d;cin>>a>>b>>c>>d;
  int x=abs(a-b);
  int y=abs(b-c);
  int z=abs(c-a);
  if(z<=d)cout<<"Yes";
  else if(x<=d && y<=d)cout<<"Yes";
  else cout <<"No";
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	int N;
	string S;
	cin >> N >> S;
	int count[26] = { 0 };
	for (int i = 0; i < N; i++)
	{
		count[S[i] - 'a']++;
	}
	ll an = 1;
	for (int i = 0; i < 26; i++) {
		if (count[i] != 0) {
			an *= count[i] + 1;
		}
		an %= mod;
	}
	cout << an - 1 << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  COMinit();
  int n;
  cin >> n;
  ll a[n+1]={},cnt[n]={};
  int mul=inf;
  rep(i,n+1){
    cin >> a[i];
    cnt[a[i]]++;
    if(cnt[a[i]]==2)mul=a[i];
  }
  ll left=inf,right=inf;
  for(int i=0;i<=n;i++){
    if(left==inf && a[i]==mul)left=i;
    else if(left!=inf && a[i]==mul)right=i;
  }
  right=n-right;
  ll ans[n+2]={};
  for(int i=1;i<=n;i++){
    if(i==1){
      ans[i]=n;
      continue;
    }
    ans[i]=COM(n,i);
    ans[i]+=COM(n-1,i-2);
    ans[i]%=mod;
    ans[i]+=(mod+COM(n-1,i-1)-COM(left+right,i-1))%mod;
    ans[i]%=mod;
  }
  rep(i,n)cout << ans[i+1] << endl;
  cout << 1 << endl;
  return 0;
}

Measured memory_bytes: 15488
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    int x;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        x = sc.nextInt();
        solve();
    }

    void solve() {
        int sqrtX = (int)Math.sqrt(x);
        int ans = 1;
        for (int i = 2; i <= sqrtX; i++) {
            int temp = i;
            while (temp <= x) {
                temp *= i;
            }
            temp /= i;
            if (ans < temp) {
                ans = temp;
            }
        }
        System.out.println(ans);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 21332
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
#define endl "\n"
using namespace std;
const ll N=500010;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll n;
    cin>>n;
    vector<ll> ar(N,0);
    ll ans=0;
    for(ll i=0;i<n;++i){
        ll x;
        cin>>x;
        ar[x]+=1;
        ans+=x;
    }
    ll q;
    cin>>q;
    while(q--)
    {
        ll b,c;
        cin>>b>>c;
        ans+=(c-b)*ar[b];
        ar[c]+=ar[b];
        ar[b]=0;
        cout<<ans<<endl;
    }

    return (0);
}


Measured memory_bytes: 7152
N = int(input())
L = []

for i in range(N):
    s, p = input().split()
    p = int(p)
    L.append((s,p,i))

for i in range(N):
    for j in range(N-1):
        if L[j][0] > L[j+1][0] or (L[j][0] == L[j+1][0] and L[j][1] < L[j+1][1]):
            L[j],L[j+1] = L[j+1],L[j]

for i in range(N):
    print(L[i][2]+1)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <vector>
#include <string>
using namespace std;

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")

#define DEBUG(x) cout << ">> " << #x << ": " << x << endl;
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
typedef long long ll;
typedef long double ld;

int main() { _
  int n; cin >> n;
  vector<int> a(n, 0);
  vector<int> b(n, 0);
  vector<int> c(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }
  vector<vector<int> > dp(n, vector<int>(3, 0));
  dp[0][0] = a[0]; dp[0][1] = b[0]; dp[0][2] = c[0];
  for (int i = 1; i < n; i++) {
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i];
    dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b[i];
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c[i];
  }

  cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])) << endl;
  
  return 0;
}

Measured memory_bytes: 6912
const inputs = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n');

const input = inputs[0];

const a = (input.length - 1) / 2;

const b = input.substring(0, a);
const c = input.substring(input.length - a, input.length);

if (isPalindrome(input) && isPalindrome(b) && isPalindrome(c)) {
  console.log('Yes');
} else {
  console.log('No');
}

function isPalindrome(value) {
  return value === value.split('').reverse().join('');
}

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

int main()
{
    int n;
    ll k;
    std::cin >> n >> k;

    std::vector<int> towns(n);
    for (auto &item : towns)
    {
        std::cin >> item;
    }

    int currentTown = 0;
    ll steps = 0;
    unordered_set<int> visitedTown;
    deque<int> historyTown;
    while (k > 0)
    {
        if (visitedTown.find(currentTown) != visitedTown.end())
            break;

        --k;
        visitedTown.insert(currentTown);
        historyTown.push_back(currentTown);

        currentTown = towns[currentTown] - 1;
    }

    if (k > 0)
    {
        const auto size = historyTown.size();
        for (size_t i = 0; i < size; ++i)
        {
            if (currentTown != historyTown[0])
                historyTown.pop_front();
            else
                break;
        }
        currentTown = historyTown[k % historyTown.size()];
    }
    std::cout << (currentTown + 1) << std::endl;

    return 0;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
const LL INF = 1e17;

class SegT{
private:
  LL dat[2 * (1 << 18) - 1];
  int NN;

public:
  SegT(int n_){
	NN = 1;
	while(NN < n_) NN <<= 1;
	for(int i=0;i<2*NN-1;++i) dat[i] = -INF;
  }

  void update(int idx, LL a){
	idx += NN - 1;
	dat[idx] = a;
	while(idx > 0){
	  idx = (idx - 1) / 2;
	  dat[idx] = max(dat[idx*2+1], dat[idx*2+2]);
	}
  }

  LL query(int a, int b, int k, int l, int r){
	if(r <= a || b <= l) return -INF;
	if(a <= l && r <= b) return dat[k];
	else{
	  LL vl = query(a, b, k*2+1, l, (l+r)/2);
	  LL vr = query(a, b, k*2+2, (l+r)/2, r);
	  return max(vl, vr);
	}
  }
  LL query(int a, int b){
	return query(a, b, 0, 0, NN);
  }
};

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

  int N;
  cin >> N;
  VL xs(N), ss(N);
  SegT seg(N+10);
  VL acc(N+1);

  LL ans = -INF;
  REP(i,N){
	cin >> xs[i] >> ss[i];
	acc[i+1] = acc[i] + ss[i] - (i? xs[i] - xs[i-1]: 0);
	maxi(ans, ss[i]);
	seg.update(i, acc[i]);
  }
  seg.update(N, acc[N]);

  FOR(i,1,N+1){
	maxi(ans, seg.query(i, N+1) - acc[i] + ss[i-1]);
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  string s;
  cin>>s;
  string a=s.substr(0,2);
  string b=s.substr(2,2);
  int A=0,B=0;
  A+=a[1]-'0';
  A+=(a[0]-'0')*10;
  B+=b[1]-'0';
  B+=(b[0]-'0')*10;
  bool aMM,bMM;
  aMM=(1<=A&&A<=12);
  bMM=(1<=B&&B<=12);
  if(aMM&&bMM)cout<<"AMBIGUOUS"<<endl;
  else if(aMM)cout<<"MMYY"<<endl;
  else if(bMM)cout<<"YYMM"<<endl;
  else cout<<"NA"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	while (1)
	{
		int a = 0;
		int x = 0;
		int d = 0;
		int aa[10001];
		for (int i = 0; i < 10001; i++)
		{
			aa[i] = 0;
		}
		cin >> x;
		cin >> a;
		if (x == 0 && a == 0)
		{
			break;
		}
		int b[10000];
		int c[10000];
		for (int i = 0; i < a; i++)
		{
			cin >> b[i];
			cin >> c[i];
		}
		for (int i = 0; i < a; i++)
		{
			if (b[i] == 1)
			{
				aa[c[i]] = 1;
				for (int j = 0; j < a; j++)
				{
					if (c[i] == b[j])
					{
						aa[c[j]] = 1;
					}
					if (c[i] == c[j])
					{
						aa[b[j]] = 1;
					}
				}
			}
		}
		for (int i = 2; i <= x; i++)
		{
			if (aa[i] == 1)
			{
				d++;
			}
		}
		cout << d << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
int add(int a,int b){a+=b;return a>=mod?a-mod:a;}
int sub(int a,int b){a-=b;return a<0?a+mod:a;}
int mul(int a,int b){return (ll)a*b%mod;}
int qpow(int a,int b){int ret=1;for(;b;b>>=1,a=mul(a,a))if(b&1)ret=mul(ret,a);return ret;}
/* math */
int n,m;
const int N=5e5+5;
int deg[N];
int hed[N],cnt=1,to[N],nxt[N];
bool del[N];
vector<int> l[N];
inline void adde(int u,int v){
	++cnt;to[cnt]=v,nxt[cnt]=hed[u];hed[u]=cnt;
}
int stk[N],top;
int pre[N],lst[N];
inline void dfs(int x){
	for(int i=hed[x];i;i=nxt[i])if(!del[i]){
		int v=to[i];
		del[i]=del[i^1]=1;
		dfs(v);
	}
	stk[++top]=x;
	pre[top]=lst[x];
	lst[x]=top;
}
typedef pair<int,int> pii;
pii seg[N];int scnt;

int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int u,v;scanf("%d%d",&u,&v);
		adde(u,v),adde(v,u);
		deg[u]++,deg[v]++;
	}
	for(int i=1;i<=n;i++)if(deg[i]%2){
		puts("No");
		return 0;
	}
	dfs(1);
	for(int i=1;i<=top;i++){
		if(i!=top&&pre[i])seg[++scnt]=pii(pre[i],i);
	}
	sort(seg+1,seg+scnt+1);
	int Max=0;
	for(int i=1;i<=scnt;i++){
		if(seg[i].second<=Max){
			puts("Yes");return 0;
		}
		Max=max(Max,seg[i].second);
	}
	for(int i=1;i<=scnt;i++){
		if(seg[i].second<=seg[scnt].first){
			puts("Yes");return 0;
		}
	}
	puts("No");return 0;
	
}

Measured memory_bytes: 29184
h,w=(int(i) for i in input().strip().split(" "))
ar=[]
s=[]
for j in range(h):
    k=[i for i in input().strip()]
    if k==["."]*w:
        pass
    else:
        ar.append(k)

fin=[]
for j in range(w):
    t=[]
    for i in range(len(ar)):
        t.append(ar[i][j])
    if t==["."]*len(t):
        pass
    else:
        fin.append(t)


for j in range(len(fin[0])):
    for i in range(len(fin)):
        print(fin[i][j],end="")
    print()

Measured memory_bytes: 74704
#include<iostream>
#include<algorithm>
using namespace std;
int main (void)
{
   
  int x,i,j,k;
  cin>>x;
  i=x/500;
  x=x-i*500;
  j=x/5;
  cout<<i*1000+j*5;
  
  return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <climits>
#include <cmath>
#include <vector>
#include <string>

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

using namespace std;


vector<int> G[100002];
int d1[100002];
int dN[100002];

void dfs1(int u, int d)
{
    d1[u] = d;
    for (auto itr=G[u].begin(); itr!=G[u].end(); ++itr) {
        int v = *itr;
        if (d1[v]==-1)
            dfs1(v, d+1);
    }
}

void dfsN(int u, int d)
{
    dN[u] = d;
    for (auto itr=G[u].begin(); itr!=G[u].end(); ++itr) {
        int v = *itr;
        if (dN[v]==-1)
            dfsN(v, d+1);
    }
}

int main()
{
    int N;
    int a;
    int b;

    scanf("%d ", &N);
    REP(i, N) {
        scanf("%d ", &a);
        scanf("%d ", &b);
        G[a].push_back(b);
        G[b].push_back(a);
    }
    REP(i, N+1) {
        d1[i] = -1;
        dN[i] = -1;
    }
    dfs1(1, 0);
    dfsN(N, 0);
    int cnt = 0;
    FOR(i, 1, N+1) {
        if (d1[i]<=dN[i])
            cnt++;
        else
            cnt--;
    }

    printf(cnt>0 ? "Fennec\n" : "Snuke\n");
    return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using vint = vector<int>;
using vvint = vector<vint>;
using ll = long long;
using vll = vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }


void solve(long long N, std::vector<long long> A){
    vint ans(N);
    rep(i, N) {
        ans[A[i]-1] = i+1;
    }
    rep(i, N-1) {
        cout << ans[i] << " ";
    }
    cout << ans.back() << endl;
}

// Generated by atcoder-tools ver.1.1.6
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 2048
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const ll mod = 1e9 + 7;
ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}
const int IMAX = 1001;
ll fac[IMAX + 1], ifac[IMAX + 1];
int dp[1001];

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


	fac[0] = 1;
	rep1(i, IMAX) fac[i] = fac[i - 1] * i % mod;
	ifac[IMAX] = modpow(fac[IMAX], mod - 2);
	for (int i = IMAX; i > 0; i--) ifac[i - 1] = ifac[i] * i % mod;

	int N, A, B, C, D;
	scanf("%d %d %d %d %d", &N, &A, &B, &C, &D);
	dp[0] = fac[N];
	for (int i = A; i <= B; i++) {
		ll ic = modpow(ifac[i], C);
		for (int j = N - i * C; j >= 0; j--) {
			int tmp = dp[j] * ic % mod;
			int p = C;
			for (int k = j + i * C; k <= min(j + i * D, N); k += i) {
				dp[k] = (dp[k] + tmp * ifac[p++]) % mod;
				tmp = tmp * ifac[i] % mod;
			}
		}
	}
	printf("%lld", dp[N]);

	Would you please return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC126_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var NK = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var N = NK[0];
            var K = NK[1];

            decimal ans = 0;
            for (decimal i = N; i >= 1; i--)
            {
                var n = i;
                var b = 0;
                while (n < K)
                {
                    n *= 2;
                    b++;
                }
                ans += (decimal)Math.Pow(0.5, b) / N;
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11348
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
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;
}
int main(){
string s;
cin >> s;
if (s[0] == 'R' and s[1] == 'R' and s[2] == 'R') cout << 3 << endl;
else{
    ll cnt = 0;
    for (ll i = 0; i < 3; i++){
        if (s[i] == 'R') cnt++;
    }
    if (s[0] == 'R' and s[2] == 'R') cout << 1 << endl;
    else
        cout << cnt << endl;
}
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const ll INF = 1LL<<60;
/////////////////////////////////
ll mo = 1000000007;
ll dp[2010];

int main(){
    int S;
    cin >> S;
    for (int i = 1; i <= S;i++){
        if(i==1 || i==2)
            dp[i] = 0;
        else if(i==3)
            dp[i] = 1;
        else
        {
            dp[i] = dp[i - 3] + dp[i - 1];
            dp[i] %= mo;
        }
        
    }
    cout << dp[S] << endl;
}

Measured memory_bytes: 3652
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using ll = long long;
using namespace std;

int main(void) {
    int n, k;
    cin >> n >> k;

    vector<ll> x(n);

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

    // exhaustive search
    ll minv = 1LL<<60;
    // cout << "init" << minv << endl;
    for(int i = 0; i + k - 1 < n; ++i) {

        // cout << i << endl;

        ll left = x[i];
        ll right = x[i+k-1];

        // cout << "l:" << left  << endl;
        // cout << "r:" << right << endl;

        if (left < 0 && right < 0) {
            // minv = min({minv, left});
            minv = min (minv, min(abs(left),abs(right))+right-left);
            
        } else if (left >=0 && right >= 0) {
            // minv = min({minv, right});
            minv = min (minv, min(abs(left),abs(right))+right-left);

        } else {
        //    minv = min({minv, min({2*abs(left)+abs(right), 2*abs(right)+abs(left)})});
            minv = min (minv, min(abs(left),abs(right))+right-left);
        }

//        minv = min (minv, min(abs(left),abs(right))+right-left);
        // cout << "ans:" << (left < 0 && right >= 0 ? 2 * llabs(left)+llabs(right) : right) << endl;
        // cout << "minv:" << minv << endl;
    }

    cout << minv << endl;

    return 0;
}

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

typedef long long ll;
const ll mod=1e9+7;
const int N=200000;

void Run()
{
     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
//ll s[N],c[N];
ll h=1000000000000000000;
ll a[N],b[N];
vector<string>v;
map<string,int>mp;
int main()
{
    Run();
    unsigned long long x=1;
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]==0)
        {
            cout<<0;
            return 0;
        }
    }
    for(int i=0;i<n;i++)
    {
        if(x<=h/a[i])
        x*=a[i];
        else
        {
            cout<<-1;
            return 0;
        }
    }
        cout<<x;
}


Measured memory_bytes: 4332
import bisect,collections,copy,heapq,itertools,math,string
from collections import defaultdict as D
from functools import reduce
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353    

n = I()
a = [I() for _ in range(n)]

def max_index(l, value):
    return [i for i, x in enumerate(l) if x == value]

a_sort = sorted(a,reverse=True)
# print(a_sort)

max_indexs = max_index(a,a_sort[0])
max_indexs = set(max_indexs)

for i in range(n):
    if i in max_indexs:
        print(a_sort[1])
    else:
        print(a_sort[0])

#Ap = np.array(A)
#C = np.zeros(N + 1)

# if ans:
#     print('Yes')
# else:
#     print('No')

Measured memory_bytes: 56744
/* 
chirag11032000
Chirag Thakur
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;

template < typename T > using OrderedSet = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

const db PI = acos(-1);
const ll LINF = LLONG_MAX;
const int INF = INT_MAX, MOD = 1e9 + 7, N = 50 + 10;

int n, k;
int v[N];
ll dp[N][N][2 * N];
bool seen[N][N][2 * N];

void testCase();
ll solve(int l, int r, int rem);

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	testCase();
	cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
	return 0;
}

void testCase() {
	cin >> n >> k;
	memset(seen, false, sizeof(seen));
	for (int i = 1; i <= n; ++i) {
		cin >> v[i];
	}
	cout << max(0ll, solve(1, n, k)) << "\n";
}

ll solve(int l, int r, int rem) {
	if (rem == 0 || l > r) {
		return 0;
	}
	auto &ans = dp[l][r][rem];
	auto &vis = seen[l][r][rem];
	if (!vis) {
		vis = true;
		ans = 0;
		ans = max(ans, v[l] + solve(l + 1, r, rem - 1));
		ans = max(ans, v[r] + solve(l, r - 1, rem - 1));
		if (rem >= 2) {
			ans = max(ans, solve(l + 1, r, rem - 2));
			ans = max(ans, solve(l, r - 1, rem - 2));
		}
	}
	return ans;
}

Measured memory_bytes: 2048
N,A,B,C,D = map(int,input().split())
S = input()

flag = True

#search '##'
if "##" in S[A-1:C] or "##" in S[B-1:D]:
    flag = False

#search '...'
if C > D and flag:
    flag = False
    if "..." in S[B-2:D+1]:
        flag = True

if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 40816
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
long long dp[100010];
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;}
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a)  (a).begin(),(a).end()
//bitset<64>(x).count()
//fixed << setprecision(15) << 

int binary_search(vector<int> a, int key) {
    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int ok = (int)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (a[mid] >= key) ok = mid;
        else ng = mid;
    }
    return ng;
}

int main (){
  int n, tmp;
  cin >> n;
  vector<int> a, b, c;
  rep(i,n){
    cin >> tmp;
    a.push_back(tmp);
  }
  rep(i,n){
    cin >> tmp;
    b.push_back(tmp);
  }
  rep(i,n){
    cin >> tmp;
    c.push_back(tmp);
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());
  long long ans = 0;
  rep(i,n){
    ans += (lower_bound(all(a), b[i]) - a.begin())*(c.end() -upper_bound(all(c), b[i]) );
    //cout << (lower_bound(all(a), b[i]) - a.begin())<< " " << (c.end() -upper_bound(all(c), b[i]) )<< endl;
  }
  cout << ans << endl;
}

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

if K % 7 == 0:
    K //= 7

L = 9 * K

ans = -1

r = 10

for i in range(L):
    r %= L
    if r == 1:
        ans = i + 1
        break
    else:
        r = 10 * r

print(ans)

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

int main(){
  int n;
  cin >> n;
  vector<int> v(n);
  rep (i, n) cin >> v[i];
  int next = 1;
  int ans = 0;
  set<int> s;
  s.insert(1);
  while (1){
    next = v[next - 1];
    ++ans;
    if (next == 2) break;
    if (s.count(next) == 1) break;
    s.insert(next);
  }
  if (next == 2) cout << ans << endl;
  else cout << -1<< endl;
  return 0;
}

Measured memory_bytes: 8148
(defun input (n)
  (let ((a (make-array n)))
    (loop for i below n do (setf (aref a i) (read)))
    a)) 

(defun solve (k a)
  (let ((max-a (reduce #'max a))
        (gcd-a (reduce #'gcd a)))
    (if (and (= (mod k gcd-a) 0) (<= k max-a))
      'POSSIBLE
      'IMPOSSIBLE)))

(let ((n (read)))
  (princ (solve (read) (input n))))

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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int k,x;
    cin >> k >> x;
    if(x<=k*500) cout << "Yes" << endl;
    else cout << "No" << endl; 
 }

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int a,b,c;
  cin >> a>>b>>c;
  if(a==b&&a!=c){
    cout<<"Yes"<<endl;
  }else if(a==c&&a!=b){
    cout<<"Yes"<<endl;
  }else if(b==c&&a!=b){
    cout<<"Yes"<<endl;
  }else{
    cout << "No"<<endl;
  }
}


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

int main() {    
    int n;
    cin >> n;
    double odd = (double)((n / 2) + 1) / n;
    double even = (double)(n / 2) / n;
    if (n % 2 == 0) cout <<fixed << setprecision(6) << even << endl;
    else if (n % 2 != 0) cout <<fixed << setprecision(6) << odd << endl;
}


Measured memory_bytes: 256
import java.util.*;

 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] p = new int[N];
		for(int i = 0; i < N; i ++){
			p[i] = sc.nextInt();
		}
		int sum = 0;

		Arrays.sort(p);

		for(int i = 0; i < K; i ++){
			sum += p[i];
		}
		System.out.println(sum);
	}
}

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

int main(void){
    int n = 0, k = 0, d = 0, a = 0;
    int sunuke[101] = {0};
    int ans = 0;

    scanf("%d%d", &n, &k);
    for(int i = 0; i < k; i++){
        scanf("%d", &d);
        for(int j = 0; j < d; j++){
            scanf("%d", &a);
            sunuke[a]++;
        }

    }

    for(int i = 1; i <= n; i++){
        if(sunuke[i] == 0){
            ans++;
        }
    }
    printf("%d\n", ans);

    return 0;

} 


Measured memory_bytes: 3832
#include <stdio.h>

int main(void){
	int n,i,cnt=0,cont=1;

	scanf("%d",&n);

	int a[n];

	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	
	while(cont==1){
		for(i=0;i<n && cont==1;i++){
			if(a[i]%2==0){
				a[i]/=2;
			}else{
				cont=0;
			}
		}
		if(cont==1){
			cnt++;
		}
	}

	printf("%d",cnt);

	return 0;

}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>

#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

template<typename T>inline void upmin(T &x,T y) { y<x?x=y:0; }
template<typename T>inline void upmax(T &x,T y) { x<y?x=y:0; }

typedef unsigned int u32;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod pi=acos(-1);
const int oo=1<<30;
const LL OO=1e18;

const int L=14,N=1<<L;
const int mod=998244353;

int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}

inline int qpow(int x,int y) {
	int ans=1;
	while (y) {
		if (y&1) ans=1LL*ans*x%mod;
		x=1LL*x*x%mod;y>>=1;
	}
	return ans;
}

int W[N*2],*w0[L],*w1[L],R[N];
inline void DFT(int *a,int n,int f) {
	int i,o,k,t,*wn,*w,x,y;
	for (i=0;i<n;i++)
		if (R[i]>i) swap(a[i],a[R[i]]);
	for (i=1,t=0;i<n;i<<=1,t++)
		for (o=0,wn=f==1?w0[t]:w1[t];o<n;o+=i<<1)
			for (k=0,w=wn;k<i;k++,w++) {
				x=a[o+k],y=1LL*a[o+k+i]**w%mod;
				a[o+k]=(x+y)%mod;
				a[o+k+i]=(x-y+mod)%mod;
			}
}

int f[210][N],g[N],h[N];
int fac[N],inv[N];
int main()
{
	int n=gi(),m=gi(),i,j,len,t,*cur=W,LEN,G;
	for (i=fac[0]=1;i<=n+2;i++) fac[i]=1LL*fac[i-1]*i%mod;
	for (i=2,inv[0]=inv[1]=1;i<=n+2;i++) inv[i]=mod-1LL*(mod/i)*inv[mod%i]%mod;
	for (i=3;i<=n+2;i++) inv[i]=1LL*inv[i-1]*inv[i]%mod;
	
	for (len=1,t=0;len<=n*2;len<<=1,t++) {
		G=qpow(3,(mod-1)/(len<<1));w0[t]=cur;
		for (i=cur[0]=1;i<len;i++) cur[i]=1LL*cur[i-1]*G%mod;
		cur+=len;
		G=qpow(G,mod-2);w1[t]=cur;
		for (i=cur[0]=1;i<len;i++) cur[i]=1LL*cur[i-1]*G%mod;
		cur+=len;
	}
	for (i=0,t--;i<len;i++)
		R[i]=R[i>>1]>>1|(i&1)<<t;
	LEN=qpow(len,mod-2);

	f[0][0]=1;
	for (i=1;i<=n;i++) g[i]=inv[i+2];DFT(g,len,1);
	for (i=0;i<m;i++) {
		for (j=0;j<=n;j++) {
			f[i+1][j]=(1LL*(j+1)*j/2+1)%mod*f[i][j]%mod;
			f[i][j]=1LL*f[i][j]*inv[j]%mod;
		}
		DFT(f[i],len,1);
		for (j=0;j<len;j++)
			f[i][j]=1LL*f[i][j]*g[j]%mod;
		DFT(f[i],len,-1);
		for (j=0;j<=n;j++)
			f[i+1][j]=(f[i+1][j]+1LL*f[i][j]*LEN%mod*fac[j+2])%mod;
	}
	int ans=0;
	for (j=0;j<=n;j++)
		ans=(ans+1LL*fac[n]*inv[j]%mod*inv[n-j]%mod*f[m][j])%mod;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 13440
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    lint H, W;
    cin >> H >> W;
    vec<string> grid(H);
    range(i, 0, H) cin >> grid.at(i);
    assert(grid.at(0).size() == W);
    vec<vec<lint>> num_bombs_neighborhood(H, vec<lint>(W, -1));
    vec<lint> dx = {-1, -1, -1, 0, 0, 1, 1, 1};
    vec<lint> dy = {-1, 0, 1, -1, 1, -1, 0, 1};
    range(i, 0, H) {
        range(j, 0, W) {
            if (grid.at(i).at(j) == '#') continue;
            lint n = 0;
            range(k, 0, 8) {
                lint nx = i + dx.at(k);
                lint ny = j + dy.at(k);
                if (0 <= nx && nx < H && 0 <= ny && ny < W && grid.at(nx).at(ny) == '#')
                    n++;
            }
            num_bombs_neighborhood.at(i).at(j) = n;
        }
    }
    range(i, 0, H) {
        range(j, 0, W) {
            cout << (num_bombs_neighborhood.at(i).at(j) == -1 ? "#" : to_string(num_bombs_neighborhood.at(i).at(j)));
        }
        cout << "\n";
    }
}

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

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

    std::vector<int> nums;
    nums.push_back(1);

    for (int i = 6; i <= 100000; i *= 6) {
        nums.push_back(i);
    } 

    for (int i = 9; i <= 100000; i *= 9) {
        nums.push_back(i);
    } 

    int dp[N+1] = {0};
    dp[N] = 0;
    for (int i = N - 1; i >= 0; --i) {
        int m = INT32_MAX; 
        for (int num : nums) {
            if ((i + num) <= N) {
                m = std::min(m, dp[i + num]);
            }
        }
        dp[i] = m + 1;
    }

    std::printf("%d\n", dp[0]);

    return 0;
}


Measured memory_bytes: 640
n, m = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(m)]


def binary_search(num_list, target):
    # 「値が何番目にあるか」を確認するための変数
    ans_counter = 0
    while True:
        # 配列の中心にある値を取り出す
        middle = num_list[len(num_list) // 2]
        # 配列の左側
        left = num_list[:len(num_list) // 2]
        # 配列の右側
        right = num_list[len(num_list) // 2:]
        # 中心の値が探索値と一致したら探索終了(探索値発見)
        if middle == target:
            ans_counter += len(left) + 1
            print("{}は{}番目にありました。".format(target, ans_counter))
            break
        # 値が最後の1個になっても一致しなかったら探索終了(探索値不存在1)
        # 左の最大値 < 探索値 < 右の最小値となった場合探索終了(探索値不存在2)
        elif len(num_list) == 1 and num_list[0] != target\
                or left[-1] < target < right[0]:
            print("{}はありませんでした。".format(target))
            break
        # 左の最大値より探索値が小さい場合、探索範囲を左側に絞る
        elif target <= left[-1]:
            num_list = left
        # 右の最小値より探索値が大きい場合、探索範囲を右側に絞る
        elif right[0] < target:
            ans_counter += len(left)
            num_list = right


first_hune = [False for _ in range(n + 1)]
second_hune = [False for _ in range(n + 1)]

AB.sort(key=lambda x: [x[0], x[1]])
totyu = []
for a, b in AB:
    if a == 1:
        first_hune[b] = True
    if b == n:
        if first_hune[a] is True:
            print('POSSIBLE')
            exit()


print('IMPOSSIBLE')


Measured memory_bytes: 131312
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;

int modd=1e9+7;

int main(){
  string a,b; cin>>a>>b;
  int alen,blen; alen=a.size(); blen=b.size();

  vector<vector<int> > tab(alen+1);
  vector<int> temp(blen+1);
  for(int i=0; i<=alen; i++) tab[i]=temp;

  for(int i=1; i<=alen; i++){
    for(int j=1; j<=blen; j++){
        if(a[i-1]==b[j-1]){
            tab[i][j]=tab[i-1][j-1]+1;
        }

        else{
            tab[i][j]=max(tab[i-1][j],tab[i][j-1]);
        }
    }
  }
    int lcslen=tab[alen][blen]; //cout<<lcslen<<endl;
  string ans; ans.resize(lcslen); int ind=lcslen-1;

  int i=alen,j=blen;
  while(i>0 && j>0){
    if(a[i-1]==b[j-1]){ ans[ind--]=a[i-1]; i--; j--; }
    else{
        if(tab[i-1][j]>tab[i][j-1]){ i--; }
        else j--;
    }
  }

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


Measured memory_bytes: 35584
fun main(args: Array<String>) {
    val str = readLine()!!

    if (isHitachiString(str)) {
        println("Yes")
    } else {
        println("No")
    }
}

fun isHitachiString(str: String): Boolean {
    if (!str.contains("hi") || str.length % 2 != 0) return false

    for (i in (str.indices) step 2) {
        if (str.substring(i, i + 2) != "hi") return false
    }

    return true
}

Measured memory_bytes: 33408
def solve(x, y):
    candidates = []
    for u, p in [(y, 0), (-y, 1)]:
        for v, q in [(x, 0), (-x, 1)]:
            z = u-v
            if z >= 0:
                candidates.append(z+p+q)
    return min(candidates)

assert solve(10, 20) == 10
assert solve(10, -10) == 1
assert solve(-10, -20) == 12

x, y = map(int, input().split())
print(solve(x, y))

Measured memory_bytes: 3064
#include <stdio.h>
 
int main(void) {
	int N, K;
	int i;
	int ans = 0;
 
	scanf("%d %d", &N, &K);
	for(i = 0; i < N; i++) {
		int x;
		scanf("%d", &x);
		if(x < K - x) ans += 2 * x;
		else ans += 2 * (K - x);
	}
 
	printf("%d\n", ans);
 
	return 0;
}
 

Measured memory_bytes: 128
n,ais = int(raw_input()),map(int, raw_input().split(' '))
total,cumul,j = sum(ais),0,0
m = abs(total)
while(j< len(ais)):
	cumul += ais[j]
	j +=1
	m = min(m, abs(2 *cumul - total))
print m

Measured memory_bytes: 28012
int_n = int(input())
blue_card_ar = [input() for i in range(int_n)]

int_m = int(input())
red_card_ar = [input() for i in range(int_m)]

result_ar = []
for x in blue_card_ar:
    result_ar.append(blue_card_ar.count(x) - red_card_ar.count(x))

print(max(result_ar) if max(result_ar) > 0 else 0)




Measured memory_bytes: 3060
#include<cassert>
#include<cstdio>
#include<map>
#include<iostream>
#include<cctype>
#include<cstdlib>
#include<cstring>

using namespace std;

char *p;
map<string,int> atomtbl;

int number() {
    int res = atoi(p);
    while(isdigit(*p)) p++;
    return res;
}
int atom() {
    string name;
    int n=1;
    name += *p++;
    if(islower(*p)) name += *p++;
    if(isdigit(*p)) n = number();

    return atomtbl.at(name) * n;
}
int molecule() {
    int res = 0;
    while(*p && *p != ')') {
        if(*p == '(') {
            p++;
            int w = molecule();
            assert(*p == ')');
            p++;
            assert(isdigit(*p));
            res += w * number();
        }else{
            res += atom();
        }
    }
    return res;
}

int main(void) {
    while(true) {
        char s[5];
        int n;
        scanf("%s",s);
        if(!strcmp(s, "END_OF_FIRST_PART")) break;

        scanf("%d",&n);
        string str = s;
        atomtbl[str] = n;
    }

    while(true) {
        char in[1000];
        scanf("%s", in);
        if(!strcmp(in, "0")) break;

        p = in;
        try {
            printf("%d\n",molecule());
        }
        catch(const out_of_range& oor) {
            printf("UNKNOWN\n");
        }
    }
    return 0;
}

Measured memory_bytes: 3436
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define rrep(i, a, b) for (int i = (a); i < (b); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using tl = tuple<ll, ll, ll>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n; cin>>n;
    vector<P> vw(n); cin>>vw;
    vvi dp((1ll<<10) + 1, vi(1e5 + 10, 0));
    dp[0][0] = 0;
    rrep(i, 1, min(n, 1ll<<10) + 1) {
        rep(j, 1e5 + 5) {
            chmax(dp[i][j], dp[i / 2][j]);
            if (j - vw[i - 1].se >= 0)
                chmax(dp[i][j], dp[i / 2][j - vw[i - 1].se] + vw[i - 1].fi);
        }
    }

    ll Q; cin>>Q;
    rep(q, Q) {
        ll u, l; cin>>u>>l;
        if (u <= 1ll<<10) {
            cout<<dp[u][l]<<endl;
            continue;
        }

        ll r = u;
        vi tr;
        while (r > 1ll<<10) {
            tr.push_back(r);
            r /= 2;
        }
        ll m = sz(tr);
        ll ans = 0;
        rep(i, 1ll<<m) {
            ll v = 0;
            ll w = 0;
            rep(j, m) {
                if (i>>j&1) {
                    v += vw[tr[j] - 1].fi;
                    w += vw[tr[j] - 1].se;
                }
            }
            if (l - w < 0) continue;
            chmax(ans, dp[r][l - w] + v);
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 407344
#include "bits/stdc++.h"
#include <set>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

int dp[11000];

signed main(void) {
	int H, N;
	cin >> H >> N;
	
	if (H <= N)print("unsafe");
	else print("safe");
}


Measured memory_bytes: 3588
#include <iostream>

using namespace std;

void printArray(int a[], int N){
    for(int i=0; i<N-1; ++i)
    {
        cout<<a[i]<<" ";
    }
    cout<<a[N-1]<<endl;
}
int main(){
    int n;
    int a[100];
    cin>>n;
    for(int i=0; i<n; ++i)
    {
        cin>>a[i];
    }

    printArray(a,n);

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

        printArray(a,n);
    }

    return 0;

}



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

Measured memory_bytes: 580
import java.util.*;
import java.io.*;

class Main {
	public static void main(String[] args) {
		//long cur = System.currentTimeMillis();
		new Main().run();
		//System.out.println(System.currentTimeMillis() - cur);
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long A = sc.nextLong();
		long B = sc.nextLong();
		--A;
		--B;
		System.out.println(solve(A, B, N));
	}

	long solve(long A, long B, long N) {
		if (A > B) {
			A ^= B;
			B ^= A;
			A ^= B;
		}
		A = Math.max(A, 0);
		B = Math.max(B, 0);
		A = Math.min(A, N - 1);
		B = Math.min(B, N - 1);
		if ((B - A) % 2 == 0) {
			return (B - A) / 2;
		} else {
			long left, right;
			left = A + 1 + solve(0, B - (A + 1), N);
			right = (N - B) + solve(A + (N - B), N - 1, N);
			return Math.min(left, right);
		}

	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


Measured memory_bytes: 21844
def func(a):
    if a % 2 == 0:
        return a / 2
    else:
        return 3 * a + 1

def judge(a, numbers):
    for i in range(len(numbers)):
        if a == numbers[i]:
            return False

    return True

s = int(input())
number = s
numbers = []
count = 1

while judge(number, numbers):
    numbers.append(number)
    count += 1
    number = func(number)

print(count)

Measured memory_bytes: 3064