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

int main()
{
	int N, M;
	cin >> N >> M;
	vector<pair<int, int>> ab;
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		ab.emplace_back(a - 1, b - 1);
	}
	sort(ab.begin(), ab.end());
	int ma = N, res = 0;
	for (int i = 0, j = 0; i < N; i++) {
		if (ma == i) {
			++res;
			ma = N;
		}
		while (j < M && ab[j].first == i) {
			ma = min(ma, ab[j].second);
			j++;
		}
	}
	cout << res << endl;
	return 0;
}


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

#define ll          long long
#define endl        "\n"
#define inf         10000000002
#define pb          push_back
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define MAX         100
#define yes         cout<<"YES"<<endl
#define no          cout<<"NO"<<endl
#define bye         return 0

int main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      cout.tie(NULL);
      //freopen("inputNew.txt", "r", stdin);

      ll n;
      cin>>n;
      ll arr[n];
      for(int i=0; i<n; i++){
            cin>>arr[i];
      }
      vector<ll>V[2];
      ll mn,mx,temp;
      mx=arr[n-1];

      for(int i=n-2; i>=0; i--){
            if(arr[i]>=mx) mx=arr[i];
            else{
                  mn=arr[i];
                  while(i>0){
                        if(arr[i-1]<=mn){mn=arr[i-1]; i--;}
                        else{temp=arr[i-1];break;}
                  }
                  //cout<<mn<<"  "<<mx<<endl;
                  V[0].pb(mn);
                  V[1].pb(mx);
                  mx=temp;
            }

      }
      ll sz=V[0].size();
      reverse(V[0].begin(),V[0].end());
      reverse(V[1].begin(),V[1].end());

      ll money=1000;
      for(int i=0; i<sz; i++){
            ll s=(money/V[0][i]);
            money= (money%V[0][i]);

            money+= (s*V[1][i]);
      }
      cout<<money<<endl;


      bye;
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

signed main(){

	lli n;
	cin>>n;

	vector<lli> a(n),b(n);
	REP(i,0,n)cin>>a[i];
	REP(i,0,n)cin>>b[i];

	lli sum=0;

	lli aCnt=0;
	lli bCnt=0;

	REP(i,0,n){
		if(a[i]==b[i])continue;
		if(a[i]<b[i]) {
			aCnt += (b[i]-a[i])/2;
			if((b[i]-a[i])%2==1){
				aCnt++;
				bCnt++;
			}
		}
		else bCnt+=(a[i]-b[i]);
	}

	if(bCnt>aCnt)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;


	return 0;
}

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

#define MAX_V 300

ll dist[MAX_V][MAX_V];//辺が存在しない場合はINF、ただしdist[i][i] = 0とする
int V;

void warshall_floyd(){
    for(int k = 0; k < V; k++){
        for(int i = 0; i < V; i++){
            if(dist[i][k] == INF) continue;
            for(int j = 0; j < V; j++){
                if(dist[k][j] == INF) continue;
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
}
//負の閉路があるかないかは、dist[i][i]が負になる頂点iがあるかどうかで判別できる

signed main(){
    int m,l;
    cin >> V >> m >> l;
    REP(i,V){
        REP(j,V){
            if(i == j){
                dist[i][j] = 0;
            }else{
                dist[i][j] = INF;
            }
        }
    }
    int a,b;
    ll c;
    REP(i,m){
        cin >> a >> b >> c;
        a--;
        b--;
        dist[a][b] = dist[b][a] = c;
    }
    warshall_floyd();
    REP(i,V){
        REP(j,V){
            if(dist[i][j] == 0){
                dist[i][j] = 0;
            }else if(dist[i][j] <= l){
                dist[i][j] = 1;
            }else{
                dist[i][j] = INF;
            }
        }
    }
    warshall_floyd();
    int q;
    cin >> q;
    int s,t;
    REP(i,q){
        cin >> s >> t;
        s--;
        t--;
        if(dist[s][t] == INF){
            cout << -1 << endl;
        }else{
            cout << dist[s][t] - 1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1280
#pragma GCC optimize("O3", "unroll-loops")
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <sstream>
#include <deque>
#include <queue>
#include <complex>
#include <random>
#include <cassert>
#include <chrono>

using namespace std;

#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define FIXED cout << fixed << setprecision(12)
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define graph vector<vector<int>>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define f first
#define s second
#define hashmap unordered_map
#define hashset unordered_set
#define eps 1e-9
#define mod 1000000007
#define inf 3000000000000000007ll
#define sz(a) signed(a.size())
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#ifdef DEBUG
    mt19937 gen(857204);
#else
    mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

template<class T, class U> inline void checkmin(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void checkmax(T &x, U y) { if (y > x) x = y; }
template<class T, class U> inline bool ifmax(T &x, U y) { if (y > x) return x = y, true; return false; }
template<class T, class U> inline bool ifmin(T &x, U y) { if (y < x) return x = y, true; return false; }
template<class T> inline void sort(T &a) { sort(all(a)); }
template<class T> inline void rsort(T &a) { sort(rall(a)); }
template<class T> inline void reverse(T &a) { reverse(all(a)); }
template<class T, class U> inline istream& operator>>(istream& str, pair<T, U> &p) { return str >> p.f >> p.s; }
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }
template<class T> inline T sorted(T a) { sort(a); return a; }

signed main() {
    FAST; FIXED;
    int n, m;
    cin >> n >> m;
    cout << n * (n - 1) / 2 + m * (m - 1) / 2;
    #ifdef DEBUG
        cerr << "Runtime is: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
    #endif
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner scan = new Scanner(System.in);
        int coina = scan.nextInt();
        int coinb = scan.nextInt();
        int mane = scan.nextInt();
        
      	if(coina + coinb >= mane){
        	System.out.println("Yes");
        }else{
        	System.out.println("No");
        }
    }
}

Measured memory_bytes: 22484
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
int ans[200000] = {};
int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	s.push_back(s[0]);
	s.push_back(s[1]);
	//1がSのとき
	ans[0] = 0;
	ans[1] = 0;
	for (int i = 1;i < n+1;++i) {
		if (ans[i] == 1) {
			if (s[i] == 'o') {
				ans[i + 1] = (ans[i - 1] + 1) % 2;
			}else{
				ans[i + 1] = ans[i - 1];
			}
		}
		else {
			if (s[i] == 'o') {
				ans[i + 1] = ans[i - 1];
			}
			else {
				ans[i + 1] = (ans[i - 1] + 1) % 2;
			}
		}
	}
	if (ans[0] == ans[n] && ans[1] == ans[n + 1]) {
		for (int i = 0;i < n;++i) {
			if (ans[i] == 0) {
				cout << "S";
			}
			else {
				cout << "W";
			}
		}
		return 0;
	}
	ans[0] = 0;
	ans[1] = 1;
	for (int i = 1;i < n + 1;++i) {
		if (ans[i] == 1) {
			if (s[i] == 'o') {
				ans[i + 1] = (ans[i - 1] + 1) % 2;
			}
			else {
				ans[i + 1] = ans[i - 1];
			}
		}
		else {
			if (s[i] == 'o') {
				ans[i + 1] = ans[i - 1];
			}
			else {
				ans[i + 1] = (ans[i - 1] + 1) % 2;
			}
		}
	}
	if (ans[0] == ans[n] && ans[1] == ans[n + 1]) {
		for (int i = 0;i < n;++i) {
			if (ans[i] == 0) {
				cout << "S";
			}
			else {
				cout << "W";
			}
		}
		return 0;
	}
	ans[0] = 1;
	ans[1] = 0;
	for (int i = 1;i < n + 1;++i) {
		if (ans[i] == 1) {
			if (s[i] == 'o') {
				ans[i + 1] = (ans[i - 1] + 1) % 2;
			}
			else {
				ans[i + 1] = ans[i - 1];
			}
		}
		else {
			if (s[i] == 'o') {
				ans[i + 1] = ans[i - 1];
			}
			else {
				ans[i + 1] = (ans[i - 1] + 1) % 2;
			}
		}
	}
	if (ans[0] == ans[n] && ans[1] == ans[n + 1]) {
		for (int i = 0;i < n;++i) {
			if (ans[i] == 0) {
				cout << "S";
			}
			else {
				cout << "W";
			}
		}
		return 0;
	}
	ans[0] = 1;
	ans[1] = 1;
	for (int i = 1;i < n + 1;++i) {
		if (ans[i] == 1) {
			if (s[i] == 'o') {
				ans[i + 1] = (ans[i - 1] + 1) % 2;
			}
			else {
				ans[i + 1] = ans[i - 1];
			}
		}
		else {
			if (s[i] == 'o') {
				ans[i + 1] = ans[i - 1];
			}
			else {
				ans[i + 1] = (ans[i - 1] + 1) % 2;
			}
		}
	}
	if (ans[0] == ans[n] && ans[1] == ans[n + 1]) {
		for (int i = 0;i < n;++i) {
			if (ans[i] == 0) {
				cout << "S";
			}
			else {
				cout << "W";
			}
		}
		return 0;
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
const int mx=100010;
int a[mx],i,n,len,l,r;
bool cmp(int A,int B)
{
    return A>B;
}
int main()
{
    cin>>n;
    while (n--)
    {
        scanf("%d",&i);
        if (!a[i]) len++;
        r=max(r,i);
        a[i]++;
    }
    sort(a,a+r+1,cmp);
    //for (i=0;i<=r;++i) cout<<a[i]<<endl;
    l=0;
    r=len-1;
    while (l<r)
    {
        while (a[r]==1&&l<r) --r;
        if (l==r) break;
        if (a[r]>=3&&a[r]%2)
        {
            a[r]=1;
            r--;
        }
        else
        {
            while (a[l]==1&&l<r) l++;
            if (l-r){
                    a[l]--;
            a[r]=1;
            r--;}
            else a[r]=2;
        }
    }
    l=0;
    for (i=0;i<len;++i) if (a[i]%2==0) ++l;
    printf("%d\n",len-l);
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef long long ll;
const ll INF = 1e18L + 1;

int a[3][3];
int B[11];
bool isCalled[110];

int main()
{
  rep(i, 3) rep(j, 3)
  {
    cin >> a[i][j];
    // isCalled[A[i][j]] = true;
  }

  int n;
  cin >> n;
  rep(i, n)
  {
    int called;
    cin >> called;
    isCalled[called] = true;
  }

  bool diagLtoR = true;
  bool diagRtoL = true;

  rep(i, 3)
  {
    bool row = true;
    bool col = true;
    if (!isCalled[a[i][i]])
      diagLtoR = false;
    if (!isCalled[a[i][2 - i]])
      diagRtoL = false;
    rep(j, 3)
    {
      if (!isCalled[a[i][j]])
        row = false;
      if (!isCalled[a[j][i]])
        col = false;
    }
    if (row || col)
    {
      puts("Yes");
      return 0;
    }
  }
  if (diagLtoR || diagRtoL)
    puts("Yes");
  else
    puts("No");

  return 0;
}

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

    string str;
    int c=0,x;
    cin>>x;
    cin>>str;
    for(int i=0;i<x-2;i++)
    {
        if(str[i]=='A' && str[i+1]=='B' && str[i+2]=='C')
            c++;
    }
    cout << c << endl;

}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define rg register
#define ll long long 
inline ll read()
{
    ll x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-')
        {
            f=-1;
        }
        c=getchar();
    }
    while(c<='9'&&c>='0')
    {
        x=(x<<1)+(x<<3)+(c^48);
        c=getchar();
    }
    return x*f;
}
int n;
struct node
{
	ll num,id;
	ll tot;
}s[100503];
inline bool cmp(node a,node b)
{
	return a.num<b.num;
}
ll ji,ou;
int main()
{
	n=read();
	for(rg int i=1;i<=n;++i)
	{
		s[i].num=read();
		s[i].id=i;
	}
	stable_sort(s+1,s+1+n,cmp);
	for(rg int i=1;i<=n;++i)
	{
		if(s[i].id%2==0)//站的是偶数位置
		{
			if(i%2==0)
			{
				continue;
			}
			else//否则必将使用一次操作1 
			{
				ou++;
			}
		} 
		else 
		{
			if(i%2!=0)
			{
				continue;
			}
			else
			{
				ji++;
			}
		}
	}
//	ll ans=0;
//	for(rg int i=1;i<n;++i)
//	{
//		if(s[s[i].id].tot==0)
//		{
//			continue;
//		}
//		if(s[s[i].id].tot!=0&&s[s[i+1].id].tot!=0)
//		{
//			ans++;
//			s[s[i].id].tot=0;
//			s[s[i+1].id].tot=0;
//		}
//		else if(s[s[i].id].tot!=0&&s[s[i+1].id].tot==0)
//		{
//			ans++;
//		}
////		cout<<i<<" "<<ans<<endl;
//	}
//	cout<<ans;
	ll h=min(ou,ji);
	cout<<h+abs(ou-ji);
}

Measured memory_bytes: 4864
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,m = LI()
    a = LI()
    a.sort()
    l = 0
    r = 2*a[-1]
    while r-l > 1:
        x = (l+r) >> 1
        s = 0
        for i in a:
            j = bisect.bisect_left(a,x-i)
            s += n-j
        if s <= m:
            r = x
        else:
            l = x
    s = [0]*n
    s[-1] = a[-1]
    for i in range(n-1)[::-1]:
        s[i] = s[i+1]+a[i]
    res = m
    ans = 0
    for i in a:
        j = bisect.bisect_left(a,r-i)
        if res < n-j:
            j = n-res
        if j < n:
            ans += min(res,(n-j))*i
            ans += s[j]
            res -= n-j
            if res < 0:
                res = 0
    print(ans+res*l)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 55512
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl

using namespace std;

template<typename S,typename T>auto&operator<<(ostream&o,pair<S,T>p){return o<<"{"<<p.fi<<","<<p.se<<"}";}
template<typename T>auto&operator<<(ostream&o,set<T>s){for(auto&e:s)o<<e<<" ";return o;}
template<typename S,typename T,typename U>
auto&operator<<(ostream&o,priority_queue<S,T,U>q){while(!q.empty())o<<q.top()<<" ",q.pop();return o;}
template<typename K,typename T>auto&operator<<(ostream&o,map<K,T>m){for(auto&e:m)o<<e<<" ";return o;}
template<typename T>auto&operator<<(ostream&o,vector<T>v){for(auto&e:v)o<<e<<" ";return o;}
void ashow(){}template<typename T,typename...A>void ashow(T t,A...a){cout<<t<<endl;ashow(a...);}

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef vector<string> vs;

const int MAX_N = 200005;

inline int add(int x,int y)
{
    return (x + y)%MOD;
}

inline int sub(int x,int y)
{
    return (x+MOD-y)%MOD;
}

inline int mul(int x,int y)
{
    return (ll)x*y%MOD;
}

int c[MAX_N];
int wa[MAX_N];
int dp[MAX_N];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vi hoge;
    rep(i,n){
        cin >> c[i];
        c[i]--;
        if(len(hoge) == 0 || hoge.back() != c[i]){
            hoge.pb(c[i]);
        }
    }
    n = len(hoge);
    dp[0] = 1;
    rep(i,n){
        if(i > 0 && hoge[i] == hoge[i-1]){
            dp[i+1] = add(dp[i+1], wa[hoge[i]]);
        }else{
            dp[i+1] = add(dp[i+1], dp[i]);
            dp[i+1] = add(dp[i+1], wa[hoge[i]]);
        }
        wa[hoge[i]] = add(wa[hoge[i]], dp[i]);
    }
    cout << dp[n] << "\n";
    return 0;
}


Measured memory_bytes: 3572
while True:
    n = int(input())
    if n == 0:
        break
    lst=[0]*10
    for i in range (n):
        x=int(input())
        lst [x] += 1
    for m in range (10):
        if lst[m] > 0 :
            for k in range (lst[m]) :
                print('*',end='')
            print()
        else:
            print('-')



Measured memory_bytes: 7588
input = readlines()

n = input.shift.chomp.to_i
list = input.shift.chomp.split("\s").map{|x| x.to_i}

if list.join('') == list.sort().join('')
  puts 'YES'
  exit()
end

list.each_with_index do |l1, i1|
  list.each_with_index do |l2, i2|
    next if i1 == i2
    tmp = list.clone
    tmp[i1] = list[i2]
    tmp[i2] = list[i1]
    if tmp.join('') == tmp.sort().join('')
      puts 'YES'
      exit()
    end
  end
end

puts 'NO'

Measured memory_bytes: 14336
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;
using ll = long long;

const ll INFTY = 1LL * 1e19;

ll f(ll b, ll n){
    if(n < b) return n;
    else{
        return f(b, n/b) + n%b;
    }
}

int main(){
    ll N,S;
    cin >> N >> S;

    if(N == S){
        cout << N+1 << endl;
        return 0;
    }

    for(ll b=2;b*b <=N; b++){
        if(f(b,N) == S){
            cout << b << endl;
            return 0;
        }
    }

    ll ans = INFTY;
    for(ll p=1;p*p < N;p++){
        ll b = (N-S)/p + 1;
        if(b > 1){
            if(f(b,N) == S){
                ans = min(ans, b);
            }
        }
    }

    if(ans == INFTY){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }

    return 0;
}

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

int main() {
    int a, b, k; cin >> a >> b >> k;
    int abmin = min(a, b);

    vector<int> rtn;
    for (int i = 1; i <= abmin; ++i) {
        if (a % i == 0 && b % i == 0) {
            rtn.push_back(i);
        }
    }
    sort(rtn.begin(), rtn.end());
    reverse(rtn.begin(), rtn.end());
    cout << rtn[k-1] << endl;
}


Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

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

typedef long long ll;
int const inf = 1<<29;

namespace math { namespace prime {

constexpr int Max = 1e7+1;    // !!!INPUT MAX NUMBER!!!

int prime[Max];
bool is_prime[Max];

int sieve(int n) {
  int prime_count = 0;
  rep(i, n+1) is_prime[i] = 1;
  is_prime[0] = is_prime[1] = 0;
  REP(i, 2, n+1) {
    if(!is_prime[i]) { continue; }
    prime[prime_count++] = i;
    for(long long j=(long long)i*i; j<=n; j+=i) {
      is_prime[j] = 0;
    }
  }
  return prime_count;
}

#define USE_PRIME_SIEVE \
  using namespace math::prime;
}}

USE_PRIME_SIEVE

int main() {
  constexpr int sieve_max = 1145148;
  sieve(sieve_max);
  int N; cin >> N;
  REP(i, 11, sieve_max) {
    if (is_prime[i] && (i - 1) % 5 == 0) {
      if (i != 11) cout << " ";
      cout << i;
      if (--N == 0) {
        break;
      }
    }
  }
  cout << "\n";
}


Measured memory_bytes: 3456
#!/usr/bin/env pypy
from __future__ import division, print_function
from collections import defaultdict, Counter, deque
from future_builtins import ascii, filter, hex, map, oct, zip
from itertools import imap as map, izip as zip
from __builtin__ import xrange as range
from math import ceil
from _continuation import continulet
from cStringIO import StringIO
from io import IOBase
import __pypy__
from bisect import bisect, insort, bisect_left, bisect_right
import sys
import os
import re
inf = float('inf')
mod = int(1e9) + 7
mod_ = 998244353
 
'''
Check for special cases (n=1)
One wrong submission = 10 mins penalty!
do smth instead of nothing and stay organized
'''

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	dp = [0]*n
	dp[0] = 0
	dp[1] = abs(arr[1]-arr[0])
	for i in range(2, n):
		dp[i] = min(dp[i-1]+abs(arr[i]-arr[i-1]), dp[i-2]+abs(arr[i]-arr[i-2]))
	print(dp[-1])


BUFSIZE = 8192
class FastI(IOBase):
	def __init__(self, file):
		self._fd = file.fileno()
		self._buffer = StringIO()
		self.newlines = 0
 
	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
		self.newlines = 0
		return self.buffer.read()
 
	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count("\n") + (not b)
			ptr = self._buffer.tell()
			self._buffer.seek(0, 2), self._buffer.write(
				b), self._buffer.seek(ptr)
		self.newlines -= 1
		return self._buffer.readline()
class FastO(IOBase):
	def __init__(self, file):
		self._fd = file.fileno()
		self._buffer = __pypy__.builders.StringBuilder()
		self.write = lambda s: self._buffer.append(s)
 
	def flush(self):
		os.write(self._fd, self._buffer.build())
		self._buffer = __pypy__.builders.StringBuilder()
def print(*args, **kwargs):
	sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop("end", "\n"))
	if kwargs.pop("flush", False):
		file.flush()
def gcd(x, y):
	while y:
		x, y = y, x % y
	return x
sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
def input(): return sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
	def bootstrap(cont):
		call, arg = cont.switch()
		while True:
			call, arg = cont.switch(to=continulet(
				lambda _, f, args: f(*args), call, arg))
	cont = continulet(bootstrap)
	cont.switch()
	main()

Measured memory_bytes: 46516
//encoding:utf-8
#include <iostream> //c++
#include<time.h> //時間にかんして
#include<stack> //スタックに関して　最新のデータから捨てる
#include<queue> //キューに関して　最古のデータから捨てる

#define ll long long
using namespace std;

char s[3];
int ans;

int main(){
  cin>>s;
  ans = 700;
  for(int i=0;i<3;i++){
    if(s[i]=='o'){
      ans += 100;
    }
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    long long N, P;
    cin >> N >> P;
    if(1 == N)
    {
        cout << P << endl;
        return 0;
    }

    long long mx = pow(P, 1.0/N);
    int ans = mx;
    for(int i = mx + 1; i >= 1; i--)
    {
        long long temp = pow(i, N);
        if((P % temp) == 0)
        {
            ans = i;
            break;
        }
    }

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


Measured memory_bytes: 256
S = str(input())
mod = 10 ** 9 + 7
L = len(S)
d = "ABC".index
dp = [[0 for _ in range(4)] for _ in range(L+1)]
dp[0][0] = 1
for i in range(len(S)):
    if S[i] == '?':
        dp[i+1][0] = dp[i][0] * 3
        dp[i+1][1] = dp[i][1] * 3 + dp[i][0]
        dp[i+1][2] = dp[i][2] * 3 + dp[i][1]
        dp[i+1][3] = dp[i][3] * 3 + dp[i][2]
        for j in range(4):
            dp[i+1][j] %= mod
    else:
        dp[i+1] = dp[i]
        j = d(S[i])
        dp[i+1][j+1] += dp[i][j] % mod

print(dp[-1][-1]%mod)

Measured memory_bytes: 55388
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <set>
#include <tuple>
#include <algorithm>
#include <memory>
#include <numeric>
#include <queue>
#include <functional>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <sstream>
#include <iomanip>

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 ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;



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

	ll N, K;
	cin >> N >> K;

	string S;
	cin >> S;

	vector<P> d;

	P tmp(0, 0);
	d.push_back(tmp);

	bool flag = true;
	for (const auto& e : S)
	{
		if (flag)
		{
			if (e == '1')
			{
				tmp.first++;
			}
			else
			{
				flag = false;
				tmp.second++;
			}
		}
		else
		{
			if (e == '1')
			{
				d.push_back(tmp);
				tmp.first = 1;
				tmp.second = 0;
				flag = true;
			}
			else
			{
				tmp.second++;
			}
		}
	}

	d.push_back(tmp);
	d.push_back(P(0, 0));

	if (K > d.size() - 1) K = d.size() - 1;

	ll tmpsum = 0;
	for (ll i = 0; i < K + 1; ++i)
	{
		tmpsum += d[i].first + d[i].second;
	}
	tmpsum -= d[K].second;

	ll ans = tmpsum;

	for (ll i = K + 1; i < (ll)d.size(); ++i)
	{
		tmpsum -= d[i - K - 1].first;
		tmpsum -= d[i - K - 1].second;
		tmpsum += d[i - 1].second;
		tmpsum += d[i].first;

		chmax(ans, tmpsum);
	}

	cout << ans << endl;

	//system("pause");
}

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

int main(){
    string S;
    cin>>S;
    int ans[S.size()+1]={0};
    for(int i=0;i<S.size();i++){
        if(S[i]=='A'||S[i]=='T'||S[i]=='G'||S[i]=='C'){
            ans[i+1]=ans[i]+1;
        }
        else ans[i+1]=0;
    }
    sort(ans,ans+S.size()+1);
    cout<<ans[S.size()]<<endl;
}


Measured memory_bytes: 256
function main(lines) {
 const input = lines.split('')
 for(var i=0; i<input.length; i++){
     
     if(input[i].includes('A')){
     } else if(input[i].includes('T')){
         
     } else if(input[i].includes('C')){
         
     } else if(input[i].includes('G')){
         
     } else {
         input[i] = '\n'
     }
 }

  var lengthArray = input.join('').split('\n').map(function(val){return val.length})
  console.log( Math.max(...lengthArray) )
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

using namespace std;
int a[3], b[3], cnt[4];
int main()
{
    for (int i = 0; i < 3; i++)
    {
        int x, y;
        cin >> x >> y;
        x--,y--;
        a[i] = x, b[i] = y;
        cnt[x]++, cnt[y]++;
    }
    for (int i = 0; i < 3; i++)
    {
        for (int j = i + 1; j < 4; j++)
        {
            if (cnt[i] == 2 && cnt[j] == 2)
            {
                for (int k = 0; k < 3; k++)
                {
                    if (a[k] == i && b[k] == j || a[k] == j && b[k] == i)
                    {
                        cout << "YES" << endl;
                        return 0;
                    }
                }
            }
        }
    }
    cout << "NO" << endl;
    return 0;
}

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

void solve(){
    string S;
    cin >> S;
    string res;
    REP(i, S.size()) res += "x";
    cout << res << endl;
}

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

Measured memory_bytes: 256
// {{{ by shik
#include <bits/stdc++.h>
#include <unistd.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REP1(i, a, b) for (int i = (a); i <= int(b); i++)
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

namespace { namespace shik {

template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%" SCNd64, &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }

template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%" PRId64, x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }

#ifdef SHIK
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T, class F = less<T>> void sort_uniq(vector<T> &v, F f = F()) { sort(begin(v), end(v), f); v.resize(unique(begin(v), end(v)) - begin(v)); }
template<class T> inline T bit(T x, int i) { return (x >> i) & 1; }
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

// }}}

const int N=5010;
const LL INF=1e18;
int n,o[N];
LL h[N],p[N],dp[N];

bool cmp( int a, int b ) {
    return h[a]+p[a]<h[b]+p[b];
}

void main() {
    R(n);
    REP(i,n) R(h[i],p[i]);
    REP(i,n) o[i]=i;
    sort(o,o+n,cmp);
    dp[0]=0;
    REP1(i,1,n) dp[i]=INF;
    REP(ii,n) {
        int i=o[ii];
        for ( int j=ii; j>=0; j-- ) if ( dp[j]<=h[i] ) chkmin(dp[j+1],dp[j]+p[i]);
    }
    int ans=0;
    while ( ans<n && dp[ans+1]<INF ) ans++;
    W(ans);
}

// {{{ main
}}
int main() { shik::main(); return 0; }
// }}}


Measured memory_bytes: 384
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int T = 4;
const int E = 2;

int check(double d){
  if(d >= 1.1) return 0;
  else if(d >= 0.6) return 1;
  else if(d >= 0.2) return 2;
  return 3;
}

int main() {
  int ans[T][E];
  REP(i, T) REP(j, E) ans[i][j] = 0;
  double r, l;
  while(scanf("%lf %lf", &l, &r) != EOF){
    ++ans[check(l)][0];
    ++ans[check(r)][1];
  }
  REP(i, T) cout <<ans[i][0] <<" " <<ans[i][1] <<endl;
  return 0;
}

Measured memory_bytes: 1232
import { readFileSync } from "fs";

const { cin, nCin, biCin } = (() => {
  const inputs = readFileSync("/dev/stdin", "utf-8").split(/[\n|\s]+/);
  let count = 0;
  const cin = () => inputs[count++];
  return { cin: cin, nCin: () => Number(cin()), biCin: () => BigInt(cin()) };
})();

const range = (n: number | bigint) => [...Array(Number(n))].map((_, i) => i);

type Color = "Black" | "White";

{
  const [H, W, K] = [nCin(), nCin(), nCin()];

  const cnt = (() => {
    const css: Color[][] = range(H).map(() =>
      cin()
        .split("")
        .map((c) => (c === "#" ? "Black" : "White") as Color)
    );

    const initialBlackCnt = css
      .map((cs) => cs.reduce((acc, c) => (c === "Black" ? acc + 1 : acc), 0))
      .reduce((acc, x) => acc + x, 0);

    const hPickFn = (n: number, hPicks: [number, boolean][]): number => {
      const wPickFn = (hPicks: [number, boolean][]): number => {
        const wPickFn = (n: number, wPicks: [number, boolean][]): number =>
          n >= W
            ? initialBlackCnt -
                (hPicks
                  .filter(([, b]) => b)
                  .map(([i]) =>
                    wPicks.map(([j]) => (css[i][j] === "Black" ? 1 : 0)).reduce((acc: number, x) => acc + x, 0)
                  )
                  .reduce((acc: number, x) => acc + x, 0) +
                  hPicks
                    .map(([i]) =>
                      wPicks
                        .filter(([, b]) => b)
                        .map(([j]) => (css[i][j] === "Black" ? 1 : 0))
                        .reduce((acc: number, x) => acc + x, 0)
                    )
                    .reduce((acc: number, x) => acc + x, 0) -
                  hPicks
                    .filter(([, b]) => b)
                    .map(([i]) =>
                      wPicks
                        .filter(([, b]) => b)
                        .map(([j]) => (css[i][j] === "Black" ? 1 : 0))
                        .reduce((acc: number, x) => acc + x, 0)
                    )
                    .reduce((acc: number, x) => acc + x, 0)) ===
              K
              ? 1
              : 0
            : wPickFn(n + 1, wPicks) +
              wPickFn(
                n + 1,
                wPicks.map(([j, b]) => (j === n ? [j, true] : [j, b]))
              );

        return wPickFn(
          0,
          range(W).map((j) => [j, false] as [number, boolean])
        );
      };

      return n >= H
        ? wPickFn(hPicks)
        : hPickFn(n + 1, hPicks) +
            hPickFn(
              n + 1,
              hPicks.map(([i, b]) => (i === n ? [i, true] : [i, b]))
            );
    };

    return hPickFn(
      0,
      range(H).map((i) => [i, false] as [number, boolean])
    );
  })();

  console.log(cnt);
}


Measured memory_bytes: 38608
N = int(input())
A = list(map(int, input().split()))


def gcd(n, m):
    if m == 0:
        return n
    return gcd(m, n % m)


L = [0] * N
R = [0] * N
M = [0] * N

for i in range(0, N-1):
    L[i+1] = gcd(L[i], A[i])

for i in range(1, N):
    R[N-i-1] = gcd(R[N-i], A[N-i])

for i in range(0, N):
    M[i] = (gcd(L[i], R[i]))


print(max(M))


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

int main(){
    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a.at(i);
    }
    int ans = 0;
    for(int i = 0; i < n; i+=2){
        if(a.at(i) % 2 == 1) ans++;
    }
    cout << ans << endl;
}

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

using namespace std;

int main(void){
  string s;
  cin>>s;
  vector<char> v;
  for(int i = 0 ; i < s.size() ; i ++){
    if(s[i] == 'B'){
      if(v.size())
        v.pop_back();
    } else {
      v.push_back(s[i]);
    }
  }
  for(int i = 0 ; i < v.size() ; i ++){
    cout<<v[i];
  }cout<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<"\n"

const int MAX_N = 1e5;

string s;
string alphabet = "abcdefghijklmnopqrstuvwxyz";
map<char, int> occurrence[MAX_N+1];

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

  REP(i, s.length()) {
    REP(j, 26) {
      occurrence[i+1][alphabet[j]] = occurrence[i][alphabet[j]];
    }
    occurrence[i+1][s[i]] = occurrence[i][s[i]] + 1;
  }
  REP(a, s.length()) {
    if (a+1 < s.length() && s[a] == s[a+1]) {
      OUT(a + 1 << " " << a + 2);
      return 0;
    } else if (a+2 < s.length() && s[a] == s[a+2]) {
      OUT(a + 1 << " " << a + 3);
      return 0;
    }
  }
  OUT(-1 << " " << -1);

  return 0;
}


Measured memory_bytes: 126928
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;


int main(){
    string S;
    cin >> S;
    int len = S.size();
    int l = -1;
    int r = -1;
    rep(i,len - 1){
        if (S[i] == S[i + 1]){
            l = i + 1;
            r = i + 2;
        }
    }
    rep(i,len - 2){
        if (S[i] == S[i + 2]){
            l = i + 1;
            r = i + 3;
        }
    }
    cout << l << " " << r << endl;
}

Measured memory_bytes: 3764
#include <iostream>
using namespace std;
int main()
{
  int A, B;
  cin >> A >> B;
  if ((A%3==0) || (B%3==0) || ((A+B)%3==0)) {
    cout << "Possible" << endl;
  } else {
    cout << "Impossible" << endl;
  }
  return 0;
}


Measured memory_bytes: 3564
// C++(GCC 9.2.1)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
const LL MOD = 1e9 + 7;
LL ans[2020];

int main(){
    
    // 1. 入力情報取得.
    int S;
    scanf("%d", &S);
    
    // 2. 数列を更新.
    // ex.
    // ① すべての項が 1 以上 の 場合.
    //    1 -> 2 -> 4 -> 8 -> 16 -> ...
    // ② すべての項が 2 以上 の 場合(Fibonacci数列に見える).
    //    0 -> 1 -> 1 -> 2 -> 3 -> 5 -> 8 -> 13 -> ...
    // ③ すべての項が 3 以上 の 場合(Fibonacci数列と異なるが似ている数列に見える).
    //    0 -> 0 -> 1 -> 1 -> 1 -> 2 -> 3 -> 4 -> 6 -> 9 -> 13 -> 19 -> ...
    ans[0] = 0;
    ans[1] = 0;
    ans[2] = 1;
    ans[3] = 1;
    repx(i, 4, S) ans[i] = ans[i - 2] + ans[i - 3] + ans[i - 4], ans[i] %= MOD;
    
    // 3. 出力.
    printf("%lld\n", ans[S - 1]);
    return 0;
    
}

Measured memory_bytes: 3884
#!/bin/bash
''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 \
   /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/g.inp"
exit $?
'''
import sys

def _s(): return sys.stdin.readline().strip()

def main():
    a = set(c for c in _s())
    if len(a)==1: print("No")
    else: print("Yes")

if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C;
  cin>>A>>B>>C;
  if(A==B){
    cout<< C <<endl;
  }else if(A==C){
    cout<< B <<endl;
  }else if(B==C){
    cout<< A <<endl;
  }
}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

const ll INF = 1e15;

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

struct edge {
	ll to;
	ll dist;
	ll c;
	edge(ll to, ll dist, ll c) : to(to), dist(dist), c(c){}
};

struct Data {
	ll cv;
	ll from;
	ll to;
	double time;

	Data(ll cv, ll from, ll to, double time) : cv(cv), from(from), to(to), time(time){}

	bool operator < (const Data& data) const {
		return time > data.time;
	}
	bool operator > (const Data& data) const {
		return time < data.time;
	}
};

int main(void)
{
	vector<double> ans;
	while (true) {
		ll n, m;
		cin >> n >> m;
		if (n == 0 && m == 0) break;
		ll s, g;
		cin >> s >> g;
		s--; g--;
		vector<vector<edge>> graph(n);
		rep(i, m) {
			ll x, y, d, c;
			cin >> x >> y >> d >> c;
			x--; y--;
			graph[x].emplace_back(y, d, c);
			graph[y].emplace_back(x, d, c);
		}
		priority_queue<Data> q;
		const int max_v = 33;
		vector<vector<vector<double>>> dp(n, vector<vector<double>>(n, vector<double>(max_v, INF)));
		auto push = [&](ll cv, ll from, ll current, double time) {
			for (auto e : graph[current]) {
				if (from == e.to) continue;
				for (int i = -1; i < 2; i++) {
					double nv = cv + i;
					if (nv <= 0) continue;
					if (nv > e.c) continue;
					double nt = time + e.dist / nv;
					if (dp[current][e.to][nv] <= nt) continue;
					dp[current][e.to][nv] = nt;
					q.emplace(Data(nv, current, e.to, nt));
					//cout << "from=" << node << ",to=" << e.to << ",v=" << nv << ",time=" << nt << endl;
				}
			}
		};
		q.push(Data(0, -1, s, 0));

		while (q.size()) {
			auto t = q.top(); q.pop();
			push(t.cv, t.from, t.to, t.time);
		}
		double r = INF;
		rep(i, n) {
			r = min(dp[i][g][1], r);
		}
		ans.push_back(r);
	}
	for (auto a : ans) {
		if (a == INF) {
			cout << "unreachable" << endl;
		}
		else {
			cout << fixed << setprecision(10) << a << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3848
N = int(input())
X = input()
memo = {}
X_int = int(X, 2)


def popcount(n: int):
    x = bin(n)[2:]
    return x.count("1")


pcf = popcount(int(X, 2))
pcm = pcf - 1
pcp = pcf + 1
xm = X_int % pcm if pcm != 0 else 0
xp = X_int % pcp


def f(n: int, ops: int):

    while n != 0:
        n %= popcount(n)
        ops += 1
    return ops


def rev(x: str, i: int):
    if x == "1":
        if pcm == 0:
            return -1
        n = (xm - (pow(2, N-i-1, pcm))) % pcm
    else:
        n = (xp + (pow(2, N-i-1, pcp))) % pcp
    return n


if __name__ == "__main__":
    for i, x in enumerate(X):
        n = rev(x, i)
        if n == -1:
            print(0)
        else:
            print(f(n, 1))


Measured memory_bytes: 9676
#include<bits/stdc++.h> 
using namespace std; 
#define M int(1e9+7)
#define ll long long
#define lli long long int
#define I 10e5
#define H 1000
#define W 1000

int dp[H+1][W+1];
int countWays(vector<vector<char>> &matrix)
{
   int h = matrix.size();
   int w = matrix[0].size();
   dp[0][0] = 1;
   for(int i=1;i<h;i++)
   {
      if(matrix[i][0]=='.')
      {
         dp[i][0] = dp[i-1][0];

      }
   }
   for(int i=1;i<w;i++)
   {
      if(matrix[0][i]=='.')
      {
         dp[0][i] = dp[0][i-1];
      }
   }
   for(int i=1;i<h;i++)
   {
      for(int j=1;j<w;j++)
      {
         if(matrix[i][j]=='.')
         {
            dp[i][j] = (dp[i-1][j] + dp[i][j-1])%M;
         }
      }
   }
   return dp[h-1][w-1];
}

int32_t main() 
{ 
   ios_base::sync_with_stdio(false);cin.tie(NULL); 
   
   #ifndef ONLINE_JUDGE 
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout); 
   #endif
   int h, w;
   cin>>h>>w;
   vector<vector<char>> matrix(h, vector<char> (w));
   for(int i=0;i<h;i++)
   {
      for(int j=0;j<w;j++)
      {
         cin>>matrix[i][j];
      }
   }
   cout<<countWays(matrix);
   cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl; 
   return 0; 
}


Measured memory_bytes: 8192
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int n;
    scan(n);
    auto s = new string[](n);
    foreach (i ; 0 .. n) {
        scan(s[i]);
    }
    auto ss = s.sort().group.array.sort!"a[1] > b[1] || (a[1] == b[1] && a[0] < b[0])";
    auto m = ss.front[1];

    debug {
        writeln(ss);
        writeln(m);
    }

    foreach (si ; ss) {
        if (si[1] == m) {
            writeln(si[0]);
        }
    }
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


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

int main(){
  string A,B;
  cin>>A>>B;
  if(A.size()>B.size()){
    cout<<"GREATER"<<endl;
  }else if(A.size()<B.size()){
    cout<<"LESS"<<endl;
  }else{
    for(int i=0;i<A.size();i++){
      if(A.at(i)>B.at(i)){
        cout<<"GREATER"<<endl;
        break;
      }else if(A.at(i)<B.at(i)){
        cout<<"LESS"<<endl;
        break;
      }
      if(i==A.size()-1){
        cout<<"EQUAL"<<endl;
      }
    }
  }
}

Measured memory_bytes: 256
n, k = map(int, input().split())
h = [int(input()) for i in range(n)]
h.sort()
min = h[k - 1] - h[0]
for i in range(1, n - k + 1):
    if min > h[i + k - 1] - h[i]:
        min = h[i + k - 1] - h[i]
print(min)

Measured memory_bytes: 7384
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <bitset>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using lint = long long;
using namespace std;

const int MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    vector<int> H(N);
    for (int i = 0; i < N; i++) cin >> H[i];

    vector<int> H2(H);
    for (int i = N-2; i >= 0; --i) {
        if (H2[i+1] + 1 == H2[i]) {
            --H2[i];
        }
    }

    bool flag = true;

    for (int i = 1; i < N; i++) {
        int diff = H2[i] - H2[i-1];
        if (diff < 0) flag = false;
    }

    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 1024