akhauriyash/Code-Regression huggingface dataset:
N = int(input())
A = [list(input().split()) for _ in range(N)]
A = [(A[i][0],int(A[i][1]),i+1) for i in range(N)]
A = sorted(A,key=lambda x:x[1],reverse=True)
A = sorted(A,key=lambda x:x[0])
for i in range(N):
    print(A[i][2])

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

#define REP(i, a, b) for (int i = a; i < b; ++i)
#define MOD 1000000007
#define nline cout << "\n";
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long int lli;
typedef vector<int> vi;
typedef vector<lli> vlli;

typedef pair<int, int> pi;
typedef pair<lli, lli> plli;

typedef vector<pi> vpii;
typedef vector<plli> vplli;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;

    while (t--)
    {

        int n;
        cin >> n;
        cout << (1000 - n % 1000) % 1000;
    }

    return 0;
}


Measured memory_bytes: 3688
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  int n;
  cin >> n;
  vector< pair<string, int>> s(n);
  
  for (int i = 0; i < n; i++){
    cin >> s[i].first;
  }
  //cout << endl;
  int count = 1, maxi = 0;
  
  //cout << endl;

  sort(s.begin(), s.end());
  
  for (int i = 0; i < n; i++)
  {
    s[i].second = count;
    while (i < n - 1 && s[i].first == s[i + 1].first)
    {
      count++;
      i++;
      s[i].second = count;
    }
    maxi = max(maxi, count);
    count = 1;
    }
  //cout << maxi << endl;
  for (int i = 0; i < n; i++)
  {
    if(s[i].second == maxi){
      cout << s[i].first << "\n";
    }
  }

    return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

//重みある時
using Edge = pair<int,int>;
using Graph = vector<vector<Edge> >;
vector<int> check;
int main() {
    int a,b,tmpa = 0,tmpb = 0,d = 0;
    cin >> a >> b;
    for (int i = 0; i < b; ++i) {
        tmpa += a*pow(10,d);
        d++;
    }
    d = 0;
    for (int i = 0; i < a; ++i) {
        tmpb += b*pow(10,d);
        d++;
    }
    tmpa /= 10;
    tmpa *= 10;
    tmpa += a;

    tmpb /= 10;
    tmpb *= 10;
    tmpb += b;

    string A = {},B = {};
    while(tmpa > 0){
        char c;
        if(tmpa % 10 == 0) c = '0';
        if(tmpa % 10 == 1) c = '1';
        if(tmpa % 10 == 2) c = '2';
        if(tmpa % 10 == 3) c = '3';
        if(tmpa % 10 == 4) c = '4';
        if(tmpa % 10 == 5) c = '5';
        if(tmpa % 10 == 6) c = '6';
        if(tmpa % 10 == 7) c = '7';
        if(tmpa % 10 == 8) c = '8';
        if(tmpa % 10 == 9) c = '9';

        A.push_back(c);
        tmpa /=10;
    }
    while(tmpb > 0){
        char c;
        if(tmpb % 10 == 0) c = '0';
        if(tmpb % 10 == 1) c = '1';
        if(tmpb % 10 == 2) c = '2';
        if(tmpb % 10 == 3) c = '3';
        if(tmpb % 10 == 4) c = '4';
        if(tmpb % 10 == 5) c = '5';
        if(tmpb % 10 == 6) c = '6';
        if(tmpb % 10 == 7) c = '7';
        if(tmpb % 10 == 8) c = '8';
        if(tmpb % 10 == 9) c = '9';

        B.push_back(c);
        tmpb /=10;
    }
    if(A < B) cout << A << endl;
    else cout << B << endl;
    return 0;
}


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

int main(){
  long long N, M;
  cin >> N >> M;
  long long L, S;
  L=max(N, M);
  S=min(N, M);
  long long ans;
  if(L==1 && S==1) ans=1;
  else if(S==1) ans=L-2;
  else if(S==2) ans=0;
  else{
    ans=(L-2)*(S-2);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int INF=0x3f3f3f3f;
int n,k,q;
int a[2004];
int b[2004];
int c[2004],pc;
int mint;
int ans=INF;
void init()
{
	scanf("%d%d%d",&n,&k,&q);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	a[0]=-INF,a[n+1]=-INF;
	return;
}
void check()
{
	int last=0;			//最后一个不可删去数字的位置 
	pc=0;
	for(int i=1;i<=n+1;i++)
	{
		if(a[i]<mint)
		{
			if(i==last+1)
			{
				last=i;
				continue;
			}
//			cout<<"A"<<last+1<<" "<<i-1<<endl;
			sort(b+last+1,b+i);
			for(int j=last+1;j<=i-k;j++)
				c[++pc]=b[j];
			last=i;
		}
/*		for(int i=1;i<=n;i++)
			cout<<b[i]<<" ";
		cout<<endl;*/
		
	}
//	cout<<endl;
//	cout<<pc<<endl;
	if(pc<q) return;
	sort(c+1,c+1+pc);
/*	for(int i=1;i<=pc;i++)
		cout<<c[i]<<" ";
	cout<<endl;*/
	ans=min(ans,c[q]-mint);
	return;
}
int main()
{
	init();
	for(int i=1;i<=n;i++)
	{
//		cout<<"test"<<i<<":"<<endl;
		mint=a[i];
		for(int i=1;i<=n;i++) b[i]=a[i];
		check();
//		cout<<endl;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
w, a, b = map(int, input().split())
if a <= b:
    if b - (a+w) > 0:
        print(b-(a+w))
    else:
        print(0)
else:
    if a - (b+w) > 0:
        print(a-(b+w))
    else:
        print(0)
    

Measured memory_bytes: 2940
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef pair<int,int> P;
map<int,int> m;
int n;
int a[100000],b[100000];
int main()
{
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		b[i]=a[i];
	}
	sort(b,b+n);
	for(int i=0;i<n;i++){
		if(i%2==0) m[b[i]]=0;
		else m[b[i]]=1;
	}
	int ans=0;
	for(int i=0;i<n;i++){
		if( (i%2) != m[a[i]] ) ans++;
	}
	cout<<ans/2<<endl;
}

Measured memory_bytes: 5760
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int n;
pii board[110][110];
int visit[110][110];

bool check(int px,int py,int level){
	int nx,ny;
	while(visit[py][px] == 0){
		visit[py][px] = level;
		nx = board[py][px].first;
		ny = board[py][px].second;
		px = nx;
		py = ny;
	}
	if(visit[py][px] == level)return true;
	return false;
}

int main(){
	while(cin>>n,n){

		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++){
				cin>>board[i][j].first>>board[i][j].second;
			}
		}
		memset(visit, 0, sizeof(visit));
		int level = 0;
		int ans = 0;
		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++){
				if(visit[i][j] == 0){
					level++;
					if(check(j, i, level)){
						ans++;
					}
				}
			}
		}
		cout <<ans<<endl;
	}

	return 0;
}

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

bool check(string s, string d){
	for(int i=0; i<(int)s.length(); i++){
		for(int j=0; j<(int)d.size(); j++){
			if(s[i] == d[j]) return false;
		}
	}
	return true;
}

int main(){
	int n,k;
	cin >> n >> k;
	string d="";
	for(int i=0; i<k; i++){
		char c;
		cin >> c;
		d += c;
	}
	for(int i=n; i<1000000; i++){
		if(check(to_string(i), d)){
			cout << i << endl;
			break;
		}
	}
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;

    for (int i = 0; i < n; i++) {
        cout << s.at(i) << t.at(i);
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
def solve(ls, debug=0):
    n = len(ls)
    ls = sorted(ls)
    result = 0
    # Pick once largest
    if n >= 2:
        result += ls[-1]
    # Pick twice for each next larger one
    for i in range(2, n):
        result += ls[-1 - i // 2]
    return result


def main(istr, ostr):
    n = int(istr.readline())
    ls = list(map(int, istr.readline().strip().split()))
    print(solve(ls), file=ostr)


if __name__ == "__main__":
    import sys

    main(sys.stdin, sys.stdout)


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

int main() {
  string s, t;
  cin >> s >> t;
  int l = s.size();
  int cnt = 0;
  rep(i, l){
    if(s.at(i) != t.at(i)) cnt++;
  }
  cout << cnt << endl;
}



Measured memory_bytes: 3848
#include<bits/stdc++.h>
using namespace std;
#define int long long int
/*typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef vector<pii> vii;*/


#define mod 1000000007
#define INF 1e9+100
#define ff first
#define ss second
#define cy cout<<"yes"<<endl;
#define cn cout<<"no"<<endl;
#define urs(r...)          typename decay<decltype(r)>::type
#define fi(i,n)                for(urs(n) i=0;i<n;i++)
#define rep(i,n)               for(urs(n) i=1;i<=n;i++)
#define pb push_back
#define gap ' '
#define endl '\n'
#define mex 600008
#define what_is(x)              cerr << #x << " is " << x << endl;

#define bintotalones(x)         __builtin_popcountll(x)
#define binleadingzeroes(x)     __builtin_clzll(x)
#define bintrailingzeroes(x)    __builtin_ctzll(x)
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;*/
//N%P=(N&(P-1)) where P is a power of 2
main()
{
	int i,j,n,m;
	int x,k,y;
	cin>>n>>k>>x>>y;
	int fir=min(n,k)*x;
	int sum=fir;
	if(n-k>0) sum+=(n-k)*y;
	cout<<sum<<endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "First" : "Second") << "\n";
}
struct Node;
vector<Node> V;
struct Node {
  int idx;
  vector<int> nbr;
  bool vst = false;
  int dist = 0;
  void dfs(int d) {
    dist = d+1;
    vst = true;
    for(int x : nbr) {
      if(!V[x].vst) {
        V[x].dfs(dist);
      }
    }
  };
};
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N;
  cin >> N;
  REP(i, N) V.emplace_back();
  REP(i, N-1) {
    int u, v;
    cin >> u >> v;
    u--; v--;
    V[u].nbr.push_back(v);
    V[v].nbr.push_back(u);
  }
  V[0].dfs(0);
  int maxd = 0;
  int idx = -1;
  REP(i, N) {
    if(V[i].dist > maxd) {
      maxd = V[i].dist;
      idx = i;
    }
    V[i].dist = 0;
    V[i].vst = false;
  }
  V[idx].dfs(0);
  maxd = 0;
  REP(i, N) if(V[i].dist > maxd) maxd = V[i].dist;
  //cout << maxd << endl;
  yes(maxd%3 != 2);
}

Measured memory_bytes: 19560
def main():
    S = input()
    N = len(S)
    idx = 0
    cur = 1
    pre = S[0]
    ans = [0]*N
    for i in range(1, N):
        #print(i, idx, cur, ans)
        if pre == S[i] == "R":
            idx += 1
            cur += 1
        elif pre == S[i] == "L":
            cur += 1
        elif pre != S[i] == "R":
            if 0 <= idx - 1:
                ans[idx-1] += cur // 2
                ans[idx] += (cur + 1)//2
            else:
                ans[idx] += cur
            idx = i
            cur = 1
        elif pre != S[i] == "L":
            ans[idx] += (cur + 1)//2
            ans[idx + 1] += cur // 2
            idx = i
            cur = 1
        pre = S[i]
    if pre == "L":
        ans[idx] += (cur+1)//2
        ans[idx-1] += cur//2
    else:
        ans[idx] += cur
    print(*ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 4e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int n, m;
	cin >> n >> m;
	int l;
	cin >> l;
	vector<vector<pair<int, int>>> graph(n);
	for (int i = 0; i < m; ++i) {
		int u, v, c;
		cin >> u >> v >> c;
		--u;
		--v;
		graph[u].push_back({v, c});
		graph[v].push_back({u, c});
	}
	vector<vector<ll>> dist(n, vector<ll>(n, inf64));
	for (int i = 0; i < n; ++i) {
		dist[i][i] = 0;
		for (auto x : graph[i]) {
			int u = x.first;
			int cost = x.second;
			dist[i][u] = cost;
		}
	}
	for (int k = 0; k < n; ++k) {
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}
	vector<vector<int>> answer(n, vector<int>(n, -1));
	for (int i = 0; i < n; ++i) {
		vector<int> ans(n, inf);
		queue<int> q;
		ans[i] = 0;
		q.push(i);
		while (!q.empty()) {
			int v = q.front();
			q.pop();
			for (int j = 0; j < n; ++j) {
				if (dist[v][j] <= l) {
					if (ans[j] > ans[v] + 1) {
						ans[j] = ans[v] + 1;
						q.push(j);
					}
				}
			}
		}
		answer[i] = ans;
	}
	int q;
	cin >> q;
	while (q--) {
		int u, v;
		cin >> u >> v;
		--u;
		--v;
		cout << (answer[u][v] == inf ? -1 : answer[u][v] - 1) << '\n';
	}
 	return 0;
}


Measured memory_bytes: 2688
//#include "stdafx.h"
#include<bits/stdc++.h> 
#include<iostream>
#include<queue>
#include<string>
#include<algorithm>
using namespace std;
int a,b,c,d;
int main()
{
	cin>>a>>b>>c>>d;
	if(a*b>c*d)
		cout<<a*b<<"\n";
	else 
		cout<<c*d<<"\n";

	
	
    return 0;
 
}



Measured memory_bytes: 3556
def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    A = map(int, input().split())

    def count(x):
        ret = 0
        while x % 2 == 0:
            x //= 2
            ret += 1
        return ret

    B = map(count, A)

    ctr = [0] * 3
    for x in B:
        ctr[min(x, 2)] += 1

    if ctr[1] == 0:
        cond = ctr[0] - ctr[2] <= 1
    else:
        cond = ctr[2] >= ctr[0]

    print('Yes' if cond else 'No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 11296
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
using namespace std;
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define OUT(a) cout << (a) << "\n"
#define ll long long
ll MOD = 10e9 + 7;

int main() {
    int n;
    cin >> n;
    int w[n];
    REP(i,n) scanf("%d", &w[i]);
    int m = 0;
    int mmm = 1000;
    for(int i=1; i<n; i++) {
        int im = 0, jm = 0;
        for(int j=0; j<n; j++) {
            if(j < i) im += w[j];
            else jm += w[j];
        }
        mmm = min(mmm, abs(im-jm));
    }
    OUT(mmm);
    return 0;
}

Measured memory_bytes: 256
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

void solve(){
    ll A,B,C;
    cin >> A >> B >> C;
    ll K;
    cin >> K;
    while(K > 0){
        if(B <= A){
            B *= 2;
            K--;
        }else{
            break;
        }
    }
    while(K > 0){
        if(C <= B){
            C *= 2;
            K--;
        }else{
            break;
        }
    }
    if(A < B && B < C){
        print("Yes");
    }else{
        print("No");
    }


}

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

Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a + b == c + d)
    cout << "Balanced" << endl;
  else if (a + b > c + d)
    cout << "Left" << endl;
  else
    cout << "Right" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define INF 1000000007
#define LINF 1000000000000000007
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
typedef long long ll;
typedef long double ld;
long long dx[] = {1,0,-1,0};
long long dy[] = {0,1,0,-1};
long long dx8[] = {1,1,0,-1,-1,-1,0,1};
long long dy8[] = {0,1,1,1,0,-1,-1,-1};
long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};

signed main(){
    ll A,B,C;
    cin >> A >> B >> C;
    if(A+B+1 >= C)cout << B+C << endl;
    else cout << A+B+1+B << endl;
}


Measured memory_bytes: 256
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_10_C
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
  int n;
  while(cin >> n){
    if(n == 0) break;
    double S[n];
    for(int i=0; i<n; i++){
      cin >> S[i];
    }
    //??????????±???????
    double median = 0;
    for(int i=0; i<n; i++){
      median += S[i];
    }
    median /= n;
    //?¨??????????????±???????
    double stddev = 0;
    for(int i=0; i<n; i++){
      stddev += (S[i]-median)*(S[i]-median);
    }
    stddev /= n;
    stddev = sqrt(stddev);
    printf("%.9lf\n", stddev);
  }
}

Measured memory_bytes: 1252
#include<bits/stdc++.h>
using namespace std;
int getCost(int w) {
	int cost = 1150;
	for (int i = 11; i <= w; i++) {
		if (i <= 20)
			cost += 125;
		else if (30 < i)
			cost += 160;
		else
			cost += 140;
	}
	return cost;
}
int main() {
	for (int w; cin >> w && w >= 0;) {
		cout << 4280 - getCost(w) << endl;
	}
	return 0;
}

Measured memory_bytes: 2964
//============================================================================
// Name        : d.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include<vector>
#include<string>
using namespace std;

int main() {
	int n;cin>>n;
	int k;cin>>k;
	string s;cin>>s;
	vector<int> stand,hand;
	hand.push_back(0);
	hand.push_back(0);
	stand.push_back(0);

	int ex=1;
	for(int i=0;i<n;i++){
		s[i]-='0';
		if(ex==s[i]){
			if(ex==1){
				hand.back()++;
			}else{
				stand.back()++;
			}
		}else{
			if(ex==1){
				ex=0;
				stand.push_back(1);
			}else{
				ex=1;
				hand.push_back(1);
			}
		}
	}
	if(ex==0){
		hand.push_back(0);
	}

//	for(int i=0;i<stand.size();i++){
//		cout<<stand[i]<<' ';
//	}
//	cout<<endl;
//	for(int i=0;i<hand.size();i++){
//		cout<<hand[i]<<' ';
//	}
//
//	cout<<endl;
	for(int i=1;i<stand.size();i++){
		stand[i]+=stand[i-1];
//			cout<<stand[i]<<' ';
	}
//	cout<<endl;
	for(int i=1;i<hand.size();i++){
		hand[i]+=hand[i-1];
//		cout<<hand[i]<<' ';
	}
//	cout<<endl;
	int ans=0;
	for(int i=k;i<stand.size();i++){
		int temp=stand[i]-stand[i-k]+hand[i+1]-hand[i-k];
		ans=max(ans,temp);
	}
	if(ans==0){
		ans=n;
	}


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


Measured memory_bytes: 1020
//agc027_a.cpp
//Sat Nov 10 18:38:13 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

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

	sort(a,a+n);

	int ans = 0;
	int total = 0;
	int flag = 0;
	for (int i=0;i<n;i++){
		total += a[i];
		if (total > x){
			ans = i;
			flag = 1;
			break;
		}
	}


	if (flag == 0){
		if (total != x){
			ans = n-1;
		}else {
			ans = n;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
typedef long long ll;

struct K {
  int x, y;
  char c;
};

int n, k;
int Bs[2005][2005];
int Ws[2005][2005];

inline int get(int ss[][2005], int bi, int bj, int ei, int ej) {
  bi = max(bi, 0);
  ei = min(ei, k*2);
  bj = max(bj, 0);
  ej = min(ej, k*2);
  return ss[ei][ej] - ss[ei][bj] - ss[bi][ej] + ss[bi][bj];
}

int main(void) {
  scanf("%d%d", &n, &k);
  REP(i, n) {
    K v;
    scanf("%d%d %c", &v.x, &v.y, &v.c);
    v.x %= 2*k;
    v.y %= 2*k;
    (v.c == 'B' ? Bs : Ws)[v.y+1][v.x+1]++;
  }

  for(int i = 1; i <= 2*k; ++i) {
    for(int j = 1; j <= 2*k; ++j) {
      Bs[i][j] = Bs[i][j] + Bs[i][j-1] + Bs[i-1][j] - Bs[i-1][j-1];
      Ws[i][j] = Ws[i][j] + Ws[i][j-1] + Ws[i-1][j] - Ws[i-1][j-1];
    }
  }

  int res = 0;
  REP(i, k+1) {
    REP(j, k+1) {
      int cur = 0;
      cur += get(Bs,   i-k, j-k,     i,     j);
      cur += get(Ws,     i, j-k,   i+k,     j);
      cur += get(Bs,   i+k, j-k, i+2*k,     j);

      cur += get(Ws,   i-k,   j,     i,   j+k);
      cur += get(Bs,     i,   j,   i+k,   j+k);
      cur += get(Ws,   i+k,   j, i+2*k,   j+k);

      cur += get(Bs,   i-k, j+k,     i, j+2*k);
      cur += get(Ws,     i, j+k,   i+k, j+2*k);
      cur += get(Bs,   i+k, j+k, i+2*k, j+2*k);
      res = max(cur, res);

      cur = 0;
      cur += get(Ws,   i-k, j-k,     i,     j);
      cur += get(Bs,     i, j-k,   i+k,     j);
      cur += get(Ws,   i+k, j-k, i+2*k,     j);

      cur += get(Bs,   i-k,   j,     i,   j+k);
      cur += get(Ws,     i,   j,   i+k,   j+k);
      cur += get(Bs,   i+k,   j, i+2*k,   j+k);

      cur += get(Ws,   i-k, j+k,     i, j+2*k);
      cur += get(Bs,     i, j+k,   i+k, j+2*k);
      cur += get(Ws,   i+k, j+k, i+2*k, j+2*k);
      res = max(cur, res);

    }
  }
  printf("%d\n", res);
  
  return 0;
}


Measured memory_bytes: 31616
#include<bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

const ULL M = 1000000007;

ULL powm(ULL a, ULL i) {
    if (!i) return 1;
    if (i & 1) return powm(a * a % M, i >> 1) * a % M;
    return powm(a * a % M, i >> 1);
}

ULL F[10001], I[10001], iF[10001];

ULL C(ULL n, ULL r) { return F[n] * iF[r] % M * iF[n - r] % M; }
ULL P(ULL n, ULL r) { return F[n] * iF[n - r] % M; }
ULL H(ULL n, ULL r) { return C(r + n - 1, n - 1); }

struct Problem {

    void Solve() {
        F[0] = 1; for (UL i = 1; i <= 10000; i++) F[i] = F[i - 1] * i % M;
        I[1] = 1; for (UL i = 2; i <= 10000; i++) I[i] = M - M / i * I[M % i] % M;
        iF[0] = 1; for (UL i = 1; i <= 10000; i++) iF[i] = iF[i - 1] * I[i] % M;
        ULL N, K; cin >> N >> K;
        if (N < K) { cout << 0 << endl; return; }
        N -= K;
        cout << H(K, N) << endl;
    }
};
int main() {
    unique_ptr<Problem> p(new Problem());
    p->Solve();
    return 0;
}



Measured memory_bytes: 3336
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,y,w,h,t;
  cin>>t;
  while(t--){
    int n,a,b,ans=0;
    cin>>x>>y>>w>>h>>n;
    for(int i=0;i<n;i++){
      cin>>a>>b;
      if(x<=a&&a<=x+w&&y<=b&&b<=y+h)ans++;
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long int N;
  cin >> N;
  long long int a[N];
  long long int b[N];
  for (int i = 0; i < N; i++) cin >> a[N-i-1] >> b[N-i-1];
  long long int sum = 0;
  for (int i = 0; i < N; i++) {
    a[i] += sum;
    long long t = b[i] - a[i] % b[i];
    if (a[i] % b[i] != 0) {
      a[i] += t;
      sum += t;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> A(n); rep(i, n) cin >> A[i];
  map<int, int> mp;
  rep(i, n) {
    mp[A[i]-1]++;
    mp[A[i]]++;
    mp[A[i]+1]++;
  }
  int ans = 0;
  for(auto ele: mp) ans = max(ele.second, ans);
  cout << ans << "\n";
  return 0;
}


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!p)
#define until(p) while(!p)

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

int counter;

#ifndef DEBUG_FLAG
auto& in_stream = std::cin;
auto& out_stream = std::cout;
#else
ll trueNumber;
std::stringstream my_in_stream, my_out_stream;
std::iostream& in_stream = my_in_stream;
std::iostream& out_stream = my_out_stream;
#endif

void ask(std::string n){
    out_stream << "? " << n << std::endl;
}

char answer(){
    #ifdef DEBUG_FLAG
    ll n;
    out_stream.ignore(255, ' ');
    out_stream >> n;
    
    if(n <= trueNumber && to_string(n) <= to_string(trueNumber) ||
       n > trueNumber && to_string(n) > to_string(trueNumber)){
        in_stream << 'Y' << std::endl;
    }else{
        in_stream << 'N' << std::endl;
    }
    #endif
    
    char c;
    in_stream >> c;
    return c;
}

char findDigit(std::string s, int start, std::string suffix){
    int64_t lb = 9, ub = start - 1;

    while(std::abs(ub - lb) > 1){
        int64_t mid = (lb + ub) / 2;

        ask(s + (char)(mid + '0') + suffix);
        char ans = answer();
        if(ans == 'Y'){
            lb = mid;
        }else{
            ub = mid;
        }
    }

    return (char)(lb + '0');
}

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

    #ifdef DEBUG_FLAG
    trueNumber = stoll(argv[1]);
    #endif
    
    std::string res = "";    
    bool two = false;
    
    while(res.size() < 9 || (res.size() == 9 && !two)){
        char d = findDigit(res, res.size() == 0 ? 1 : 0, std::string(max<int>(0, 18 - 1 - res.size()), '9'));

        if(d > '0'){
            if(res.size() > 0){two = true;}
            res += d;
        }else{
            {
                ask(res + '9' + std::string(max<int>(0, 18 - 1 - 1 - res.size()), '0'));;
                char ans = answer();
                if(ans == 'N'){
                    res += '0';
                    continue;
                }
            }
            {
                ask(res + "1");
                char ans = answer();
                if(ans == 'N'){
                    res += '0';
                    continue;
                }
            }
            {
                ask(std::string(res.size(), '9'));
                char ans = answer();
                if(ans == 'N'){
                    res += '0';
                }
                break;
            }
        }
    }
    
    std::cout << "! " << res << std::endl;
}


Measured memory_bytes: 596
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod_) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod_;
		}
		x = x * x % mod_;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}
/*--------Library Zone!--------*/

int n, m;
int cnt[114514];
signed main() {
	cin >> n >> m;
	rep(i, m) {
		int a, b; cin >> a >> b;
		cnt[a - 1]++; cnt[b]--;
	}
	REP(i, n) {
		cnt[i] += cnt[i - 1];
	}
	int ans = 0;
	rep(i, n) {
		if (cnt[i] == m)ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
N = int(input())

count = 0
for i in range(N):
    d1,d2 = map(int,input().split())
    if d1==d2:
        count +=1
        if count>=3:
            break
    else:
        count = 0

if count>=3:
    print('Yes')
else:
    print('No')

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

#define ll int64_t
const long MOD = 1e9 + 7;


int main()
{

  double a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  //濃度e
  //ビーカーの容量f

  //水の量
  //w = ai + bj
  set<double> w;
  for (int i = 0; i <= 30; ++i) {
    for (int j = 0; j <= 30; ++j) {
      // if (i == 0 && j == 0)continue;
      // if (100 * a * i + 100 * b * j > f)continue;
      w.insert(100 * a * i + 100 * b * j);
    }
  }

  //砂糖の量
  //s = ci + dj
  set<double> s;
  for (int i = 0; i <= e*30; ++i) {
    for (int j = 0; j <= e*30; ++j) {
      // if (c * i + d * j > e*30 )continue;
      s.insert(c * i + d * j);
    }
  }


  //この組み合わせを出した後

  //<s,w>について全探索
  double NowBest = 0;
  double Max = e / 100;

  long ans_liquidSum, ans_sugerSum;

  // for (auto water : w) {
  //   cerr << "water:" <<water <<endl;
  // }
  // for (auto suger : s) {
  //   cerr << "suger:" <<suger <<endl;
  // // }

  double density_max = 0;
  double water_max = 0;
  double sugar_max = 0;


  for (auto water : w) {
    for (auto suger : s) {
      if (water + suger <= f && water + suger != 0 && water != 0) {
        double density = 100 * suger / (water + suger);
        double d_E = 100 * e / (100 + e);
        if (density <= d_E) {
          if (density >= density_max) {
            density_max = density;
            water_max = water;
            sugar_max = suger;
          }

        }
      }
    }
  }






  cout << water_max + sugar_max << " " << sugar_max << endl;

  return 0;
}


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

using namespace std;


int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> H(n);
	for (int& h: H) {
		cin >> h;
	}
	bool ok = 1;
	if (n == 1) {
		cout << "Yes";
	} else {
		--H[0];
		if (H[0] > H[1]) {
			ok = 0;
		}
		if (H[n - 1] < H[n - 2] - 1) {
			ok = 0;
		}
		for (int i = 1; ok &&  i < n - 1; ++i) {
			if (H[i] > H[i - 1]) {
				H[i] -= 1;		
			}
			if (H[i] < H[i - 1] || H[i] > H[i + 1]) {
				ok = 0;
			} 
		}
		if (ok) {
			cout << "Yes";
		} else {
			cout << "No";
		}
	}
	return 0;
}

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

int main() {
	
	double x1,x2,x3,y1,y2,y3,xp,yp;
	while(cin>>x1>>y1>>x2>>y2>>x3>>y3>>xp>>yp){
		
		double o1,o2,o3;
		o1=(x2-x1)*(yp-y2)-(y2-y1)*(xp-x2);
		o2=(x3-x2)*(yp-y3)-(y3-y2)*(xp-x3);
		o3=(x1-x3)*(yp-y1)-(y1-y3)*(xp-x1);
		if((o1>0 && o2>0 && o3>0)||(o1<0 && o2<0 && o3<0)){
			printf("YES\n");
		}else{
	 		printf("NO\n");
		}
	}
}

Measured memory_bytes: 3084
#include<iostream>
using namespace std;
int main(){
    int n;
    int v[50];
    int c[50];

    cin>>n;

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

    int ans;

    for(int i=0;i<n;i++){

        if(v[i]-c[i]>0){
            ans += v[i]-c[i];
        }
    }

cout<<ans;
}

Measured memory_bytes: 256
from itertools import product

N = int(input())
S = input()
S = [int(s) for s in S]


res = 0
for q in product(range(10), repeat=3):
    i = 0
    for s in S:
        if s==q[i]:
            if i==2:
                res += 1
                break
            else:
                i+=1
print (res)

Measured memory_bytes: 41836
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main()
{
    long long int n;
    long long int sum = 0;
    cin >> n;
    vector<long long int> data(n);
    for (int i = 0; i < n; i++) {
        cin >> data.at(i);
        sum += data.at(i);
    }
    sort(data.begin(), data.end());
    cout << data.at(0) << " " << data.at(n - 1) << " "
         << sum << endl;
}


Measured memory_bytes: 3200
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
typedef long long int ll;
using namespace std;

ll x, y;
ll MOD = 1000000000 + 7;
ll mod = 1000000000 + 7;

ll modpow(ll a, ll n, ll mod)
{
    ll res = 1;
    while (n > 0)
    {
        if (n & 1)
        {
            res = res * a % mod;
        }
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
// mod.m での a の逆元 a ^ { -1 } を計算する
ll modinv(ll a, ll mod)
{
    return modpow(a, mod - 2, mod);
}

ll combi(ll n, ll r)
{
    if (r * 2 > n)
        r = n - r;
    ll ret = 1;
    for (ll i = 1; i <= r; ++i)
    {
        ret = ret * (n - i + 1) % MOD;
        ret = ret * modinv(i, MOD) % MOD;
    }
    return ret;
}

ll nCr(ll n, ll r)
{
    ll ans = 1;
    for (ll i = n; i > n - r; --i)
    {
        ans = ans * i % mod;
    }
    for (ll i = 1; i < r + 1; ++i)
    {
        ans = ans * modinv(i, mod) % mod;
    }
    return ans;
}

void solve()
{
    ll n, ans, cx, cy;
    if ((x + y) % 3 != 0)
        ans = 0;
    else
    {
        n = (x + y) / 3;
        cx = x - n;
        cy = y - n;
        if (cx < 0 || cy < 0)
            ans = 0;
        else
            ans = combi(n, cx);
    }
    ans %= MOD;
    cout << ans;
}

int main()
{
    cin >> x >> y;

    solve();
}


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

#define MAXN 10007

int n ;
int f[ MAXN ] ;

void input ( ) {
    cin >> n ;
}

void solve ( ) {
    for ( int i = 1 ; i <= 100 ; ++ i ) {
        for ( int j = 1 ; j <= 100 ; ++ j ) {
            for ( int t = 1 ; t <= 100 ; ++ t ) {
                int aux = i * i + j * j + t * t ;
                aux += i * j + i * t + j * t ;
                if ( aux < MAXN ) { ++ f[ aux ] ; }
            }
        }
    }
    for ( int i = 1 ; i <= n ; ++ i ) {
        cout << f[ i ] << "\n" ;
    }
}


int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    input ( ) ;
    solve ( ) ;
    return 0 ;
}


Measured memory_bytes: 3680
#include<bits/stdc++.h>
#define pb push_back
#define fori(j,n) for(int i=j ; i<n ; i++)
#define forj(i,n) for(int j=i ; j<n ; j++)
#define fork(i,n) for(int k=i ; k<n ; k++)
#define ppb pop_back()
#define umap unordered_map
#define uset unordered_set
#define lli long long int
#define mod 1000000007

using namespace std;

void solve()
{
	string s;cin>>s;
	int sum=0;
	for(int i=0 ; i<s.size() ; i++)
	{
		sum = (sum+s[i]-'0')%9;
	}
	if(sum==0) cout<<"Yes";
	else cout<<"No";
	
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	// int t;cin>>t;
	// while(t--)
	// {
		solve();
		// cout<<endl;
	// }

	return 0;

}


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

int main()
{
    int N;
    cin >> N;
    vector<int> B(N-1);
    for (int i = 0; i < N-1; i++)
    {
        cin >> B.at(i);
    }

    vector<int> A(N);
    A.at(0) = B.at(0);
    int answer= 0;
    for (int i = 1; i < N-1; i++)
    {
        A.at(i) = min(B.at(i-1), B.at(i));
    }
    A.at(N-1) = B.at(N-2);

    for (int i = 0; i < N; i++)
    {
        answer += A.at(i);
    }

    cout << answer;
    
    
    
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
using namespace std;
const int maxn = 2e5 + 5;
int a[26];

char s[maxn];

int nxt[maxn][26];
int dp[maxn];
int n;

int main(){
    scanf("%s", s + 1);
    n = strlen(s + 1);
    memset(a, -1, sizeof(a));
    for(int i = n;i >= 1;i--){
        for(int j = 0;j < 26;j++){
            nxt[i][j] = a[j];
        }
        a[s[i] - 'a'] = i;
    }
    for(int i = 0;i < 26;i++){
        nxt[0][i] = a[i];
    }
    for(int i = n;i >= 0;i--){
        dp[i] = 1e9;
        for(int j = 0;j < 26;j++){
            if(nxt[i][j] == -1){
                dp[i] = 1;
            }else{
                dp[i] = min(dp[i], dp[nxt[i][j]] + 1);
            }
        }
    }
    int len = dp[0];
    int now = 0;
    string ans = "";
    for(int i = 1;i < len;i++){
        for(int j = 0;j < 26;j++){
            if(dp[nxt[now][j]] == len - i){
                ans.push_back('a' + j);
                now = nxt[now][j];
                break;
            }
        }
    }
    for(int j = 0;j < 26;j++){
        if(nxt[now][j] == -1){
            ans.push_back('a' + j);
            break;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 21504
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#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 FILL(Itr,n) fill((Itr).begin(),(Itr).end(),n)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;
#define MOD 1000000007

ll Nt,Mt;

bool judge(ll x){
    ll M = Mt, N = Nt;
    N -= x;
    if(N<0)M -= abs(N)*2;
    M -= x*2;
    N = 0;
    if(M>=0&&N>=0)return true;
    return false;
}

ll binary_search_lowest(ll r, ll l){
    ll low=r, high=l;
    while(high-low>1){
        ll mid=(low+high)/2;
        if(judge(mid))low = mid;
        else high = mid;
    }
    return low;
}

int main(){
    
    cin>>Nt>>Mt;
    cout<<binary_search_lowest(0,1e13)<<endl;
    
    return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  l2=[400,800,1200,1600,2000,2400,2800,3200]
  l3=[0]*9

  for x in l:
    l3[bisect.bisect_right(l2,x)]+=1

  # print(l3)

  sm=0
  for x in l3[:-1]:
    if x!=0:
      sm+=1

  if sm==0:
    print(1,l3[-1])
  else:
    print(sm,sm+l3[-1])

main()


Measured memory_bytes: 6592
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;
int a[]={1,2,6,5};
int b[]={1,3,6,4};
void mainmain(){
	int n;
	while(cin>>n,n){
		string s;
		int x=0,y=0;
		queue<int> q;
		vint c(4);
		vint d(4);
		rep(i,4){
			c[i]=a[i];
			d[i]=b[i];
		}
		rep(i,n){
			cin>>s;
			// rep(i,4){
				// cout<<c[i]<<" ";
			// }
			// cout<<endl;
			// rep(i,4){
				// cout<<d[i]<<" ";
			// }
			// cout<<endl;
			if(s=="north"){
				y=(0+3)%4;
				rep(i,4){
					q.push(c[(y+i)%4]);
				}
				rep(i,4){
					c[i]=q.front();
					q.pop();
				}
				d[0]=c[0];
				d[2]=c[2];
			}
			else if(s=="south"){
				y=(0+1)%4;
				rep(i,4){
					q.push(c[(y+i)%4]);
				}
				rep(i,4){
					c[i]=q.front();
					q.pop();
				}
				d[0]=c[0];
				d[2]=c[2];
			}
			else if(s=="east"){
				x=(0+1)%4;
				rep(i,4){
					q.push(d[(x+i)%4]);
				}
				rep(i,4){
					d[i]=q.front();
					q.pop();
				}
				c[0]=d[0];
				c[2]=d[2];
			}
			else if(s=="west"){
				x=(0+3)%4;
				rep(i,4){
					q.push(d[(x+i)%4]);
				}
				rep(i,4){
					d[i]=q.front();
					q.pop();
				}
				c[0]=d[0];
				c[2]=d[2];
			}
		}
		cout<<c[0]<<endl;
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

Measured memory_bytes: 1232
#include <stdio.h>

int main(){
  int n,cnt=1,ans=1;
  int n0=1;
  int n1=1;

  scanf("%d",&n);
  while(cnt!=n){
    ans=n0+n1;
    n0=n1;
    n1=ans;
    cnt++;
  }

  printf("%d\n",ans);

  return 0;
}

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

using namespace std;
using ll = long long;

template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_V(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_M(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}

int main() {
    int a, b;
    cin>>a>>b;
    for(int ans = 0; ans<1000000; ans++){
        if(ans * 8 / 100 == a && ans / 10 == b){
            cout<<ans<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;

    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000000)
n,k=map(int,input().split())
graph=[[] for i in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  graph[a-1].append(b-1)
  graph[b-1].append(a-1)
MOD=10**9+7
def coloring(node,pre):
  if len(graph[node])>k:
    return 0
  if pre==-1:
    color=k-1
  else:
    color=k-2
  ans=1
  for i in graph[node]:
    if i==pre:continue
    ans*=color
    ans%=MOD
    color-=1
  for i in graph[node]:
    if i==pre:continue
    ans*=coloring(i,node)
    ans%=MOD
  return ans
print((k*coloring(0,-1))%MOD)


Measured memory_bytes: 87340
//17571@nith.ac.in @Ankit Verma
#include <bits/stdc++.h>
using namespace std;
#define ff          first
#define ss          second
#define pb          push_back
#define MP          make_pair
#define int         long long
#define ll          long long
#define inf         0x3f3f3f3f
#define ld          long double
#define eb          emplace_back
#define pii         pair<int,int>
#define ull         unsigned long long
#define all(v)      v.begin(), v.end()
#define f(i,x,n)    for(int i=x;i<n;i++)
#define fr(i,x,n)   for(int i=x;i>=n;i--)
#define fastio      ios::sync_with_stdio(false)
const int C_SIZE = 2e5 + 10;
const int MOD = 998244353;
int fact[C_SIZE];
int finv[C_SIZE];

int Comb(int a, int b) {
	if (a < b || b < 0) return 0;
	return fact[a] * finv[b] % MOD * finv[a - b] % MOD;
}

void IO() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int fastModExp(int a, int b, int m)
{
	if (a < 0LL) return 0;
	if (b < 0LL) return 0;
	int res = 1;
	while (b > 0)
	{
		if (b & 1)
			res = (res * a) % m;

		a = (a * a) % m;
		b = b >> 1;
	}
	return res;
}
int32_t main() {
	//IO();
	fastio;
	cin.tie(nullptr);
	cout.tie(nullptr);
	fact[0] = 1;
	for (int i = 1; i <= C_SIZE; i++) {
		fact[i] = (i % MOD * fact[i - 1] % MOD) % MOD;
	}
	finv[0] = 1;
	for (int i = 1; i <= C_SIZE; i++) {
		finv[i] = fastModExp(fact[i], MOD - 2, MOD);
	}
	int n, m, k, res; cin >> n >> m >> k;
	res = 0;
	for (int p = n - k; p <= n; p++) {
		res = res % MOD + (Comb(n - 1, p - 1) % MOD * m % MOD * fastModExp(m - 1, p - 1, MOD)) % MOD;
		res %= MOD;
	}
	cout << res << endl;


	return 0;
}


Measured memory_bytes: 6788
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();

        double sum = 0;
        int start = 1;
        while(start <= N){
            int n = start;
            double count = 0;
            while(n < K) {
                n *= 2;
                count++;
            }
            sum += 1 / Math.pow(2, count);
            start++;
        }

        System.out.println(sum/N);
    }
}

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

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int h, w;
    cin >> h >> w;
    string G[h];
    for(int i=0;i<h;i++)
        cin >> G[i];

    char F[h+2][w+2];

    for(int i=0;i<h;i++)
        for(int j=0;j<w;j++)
            if( G[i][j] == '#' )
                F[i+1][j+1] = '*';
            else
                F[i+1][j+1] = '0';
    
    for(int i=1;i<=h;i++)
        for(int j=1;j<=w;j++)
            if( F[i][j] == '*' )
            {
                F[i][j] = '#';
                for(int k=-1;k<2;k++)
                    for(int m=-1;m<2;m++)
                        if( F[i+k][j+m]!='*' and F[i+k][j+m]!='#' )
                            F[i+k][j+m]++;
            }

    for(int i=1;i<=h;i++)
        for(int j=1;j<=w;j++)
            cout << F[i][j] << (j==w? "\n" : "");
}

Measured memory_bytes: 3600