akhauriyash/Code-Regression huggingface dataset:
import bisect

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

Attack = []
Throw = []
for _ in range(N):
    a, b = map(int, input().split())
    Attack.append(a)
    Throw.append(b)
attack = max(Attack)
Throw.sort()

Throw_num = bisect.bisect_left(Throw, attack)
Throw_sum = sum(Throw[Throw_num:])

if Throw_sum <= H:
    print((H - Throw_sum - 1) // attack + 1 + N - Throw_num)
else:
    Throw.sort(reverse=True)
    for i in range(N):
        H -= Throw[i]
        if H <= 0:
            print(i + 1)
            exit()



Measured memory_bytes: 62296
// Problem : C - Snack
// Contest : AtCoder - AtCoder Beginner Contest 148
// URL : https://atcoder.jp/contests/abc148/tasks/abc148_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

void solve(){
    int a,b;
    cin>>a>>b;
    cout<<a*b/__gcd(a,b)<<endl;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3640
import java.util.*;
public class Main {
   private static int h[];
   private static int dp[];
  public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
        h = new int[n];
        dp = new int[n];

        for (int i = 0; i < n; i++) {
          dp[i]=Integer.MAX_VALUE;
          h[i] = sc.nextInt();
        }

		// 30 10 60 10 60 50  
		dp[0] = 0;
		dp[1] = Math.abs(h[0] - h[1]);	//20
		for (int i=2; i < n; i++) {
			dp[i]=chmin(dp[i],dp[i-1]+Math.abs(h[i-1] - h[i]));
			dp[i]=chmin(dp[i],dp[i-2]+Math.abs(h[i-2] - h[i]));
		}
		System.out.println(dp[n-1]);
	}

	private static int chmin(int i, int j) {
		return Math.min(i, j);
	}
}






Measured memory_bytes: 60260
import math
def P(n, r):
    return math.factorial(n)//math.factorial(n-r)
def C(n, r):
    return P(n, r)//math.factorial(r)


class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)] #親
        self.rank = [0 for _ in range(n)] #根の深さ
        self.num = [1 for _ in range(n)]

    #xの属する木の根を求める
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    #xとyの属する集合のマージ
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.num[y] += self.num[x]
            self.num[x] = 0
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
                
            self.num[x] += self.num[y]
            self.num[y] = 0

    #xとyが同じ集合に属するかを判定
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def add(self, x, y):
        tmp = self.num[x]
        self.num[x] += self.num[y]
        self.num[y] += tmp
    
    
N, M = map(int, input().split()) 
L = [list(map(int, input().split())) for _ in range(M)]
L.reverse()


res = [C(N, 2)]
tmp = [0 for i in range(N)]
uf = UnionFind(N)

for i in range(M):
    L[i][0] -= 1
    L[i][1] -= 1
    if uf.same(L[i][0], L[i][1]) == False:
        res.append(res[-1] - uf.num[uf.find(L[i][0])] * uf.num[uf.find(L[i][1])])
        uf.unite(L[i][0], L[i][1])
    else:
        res.append(res[-1])
               
for i in range(1, M+1):
    print(res[-i - 1])

Measured memory_bytes: 35948
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;
int main()
{
	int N,c=0,count;
	string S[4];
	cin>>N;
	for(int i=0;i<3;i++)
		cin>>S[i];
	for(int i=0;i<N;i++)
	{
		count=0;
		for(int p=0;p<2;p++)
		{
			for(int q=p+1;q<3;q++)
			{
				if(S[p][i]==S[q][i])
					count+=2;
			}
		}
		if(count==6)
			count=3;
		if(count==0)
			count=1;
		c=c+(3-count);
	}
	cout<<c<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define pii pair<ll,ll>
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

bool eq(pair<ll,ll> a)
{
    return a.ff == a.ss;
}

int main()
{
  FAST/**/
   
   ll n;
   cin>>n;
   
   ll div[n+1];
   memset(div,0,sizeof(div));
   for(ll i=1;i<=n;i++)
   {
       for(ll j=i;j<=n;j+=i)
            div[j]++;
   }
   
   ll ans = 0;
   for(ll i=1;i<=(n-1);i++)
        ans+=div[i];
   
   cout<<ans;        
   
   
   return 0;        
}  

  
          
   

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

typedef long long ll;

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

}





///promy_pompom
//hello world


Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
  int h,w;
  cin>>h>>w;
  int _h=h;
  string tmp="";
  for (int i=0;i<_h;i++){
    string s;
    cin>>s;
    if (s.find('#')!=string::npos) {tmp+=s;}else{h-=1;}
  }
  //cout<<tmp<<endl;
  //cout<<h<<endl;
  string ans="";
  for (int i=0;i<w*h;i++){
    string t="";
    for (int j=0;j<h;j++) t+=tmp[j*w+i%(w)];
  //  cout<<t<<endl;
    if (t.find('#')!=string::npos) ans+=tmp[i];
    if (i%w==w-1 and i+w-1<=h*w) ans+="\n";
  }
  cout<<ans<<endl;
  return 0;
}


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

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int n;
    scan(n);
    auto a = new long[][](n, n);
    iota(n).each!(i => a[i] = readArr!(long));

    long ans;

    foreach (u ; 0 .. n) {
        foreach (v ; u + 1 .. n) {
            bool ok = true;
            foreach (w ; 0 .. n) if (w != u && w != v) {
                if (a[u][v] > a[u][w] + a[w][v]) {
                    writeln(-1);
                    return;
                }
                if (a[u][v] == a[u][w] + a[w][v]) {
                    ok = false;
                    break;
                }
            }
            if (ok) ans += a[u][v];
        }
    }

    writeln(ans);
}








int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new int[][](n, 0);

    foreach (i ; 0 .. m) {
        int u, v;
        scan(u, v);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= v;
        if (isUndirected) {
            adj[v] ~= u;
        }
    }

    return adj;
}

alias Edge = Tuple!(int, "to", int, "cost");

Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new Edge[][](n, 0);

    foreach (i ; 0 .. m) {
        int u, v, c;
        scan(u, v, c);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= Edge(v, c);
        if (isUndirected) {
            adj[v] ~= Edge(u, c);
        }
    }

    return adj;
}

void yes(bool b) {writeln(b ? "Yes" : "No");}
void YES(bool b) {writeln(b ? "YES" : "NO");}
T[] readArr(T)() {return readln.split.to!(T[]);}
T[] readArrLine(T)(int n) {return iota(n).map!(i => readln.chomp.to!T).array;}

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


Measured memory_bytes: 5116
// C++ Program for Floyd Warshall Algorithm 
#include <bits/stdc++.h> 
using namespace std; 

#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
#define INF 999999999


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, m;
	cin >> n >> m;
	int adj_matrix[n][n];
	REP(i, n){
		REP(j, n){
			if (i==j){ adj_matrix[i][j] = 0; }
			else { adj_matrix[i][j] = INF; }
		}
	}
	int ai[m];
	int bi[m];
	int ci[m];
	REP(i, m){
		ll a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		adj_matrix[a][b] = c;
		adj_matrix[b][a] = c;
		ai[i] = a; bi[i] = b; ci[i] = c;
	}

	int dist[n][n];

	REP(i, n){
		REP(j, n){
			 dist[i][j] = adj_matrix[i][j]; 
		}
	}



	REP(k, n){
		REP(i, n){ 
			REP(j, n){ dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); }
		}
	}

	int ans = m;
	REP(k, m){
		bool shortest = false;
		REP(i, n){
				if (dist[i][ai[k]] + ci[k] == dist[i][bi[k]]){
					shortest = true;
					break;
				}
		}
		if (shortest){ ans--; }
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
 
#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
 
#define int64 long long int 
 
using namespace std;
typedef pair<int, int> P;
 
void ink(P, int, int map[10][10]);
 
int main()
{
    int map[10][10] = {0};
    int x, y, s, count, max;
    while(scanf("%d,%d,%d", &x, &y, &s) != EOF){
        P p(x, y);
        ink(p, s, map);
    }
    count = max = 0;
    for(int i=0; i<10; i++){
        for(int j=0; j<10; j++){
            if(!map[i][j]) count++;
            if(max < map[i][j]) max = map[i][j];
        }
    }
    cout << count << '\n' << max << '\n';
    return 0;
}
 
void ink(P p, int s, int map[10][10])
{
    int dx1[4] = {1, 0, -1, 0};
    int dy1[4] = {0, 1, 0, -1};
    int dx2[8] = {1, 1, 0, -1, -1, -1, 0, 1};
    int dy2[8] = {0, 1, 1, 1, 0, -1, -1, -1};
    int dx3[12] = {1, 1, 0, -1, -1, -1, 0, 1, 2, 0, -2, 0};
    int dy3[12] = {0, 1, 1, 1, 0, -1, -1, -1, 0, 2, 0, -2};
    int nx, ny;
 
    if(s == 1){
        map[p.first][p.second]++;
        for(int i=0; i<4; i++){
            nx = p.first + dx1[i], ny = p.second + dy1[i];
            if(0 <= nx && nx < 10 && 0 <= ny && ny < 10)
                map[nx][ny]++;
        }
    }
    if(s == 2){
        map[p.first][p.second]++;
        for(int i=0; i<8; i++){
            nx = p.first + dx2[i], ny = p.second + dy2[i];
            if(0 <= nx && nx < 10 && 0 <= ny && ny < 10)
                map[nx][ny]++;
        }
    }
    if(s == 3){
        map[p.first][p.second]++;
        for(int i=0; i<12; i++){
            nx = p.first + dx3[i], ny = p.second + dy3[i];
            if(0 <= nx && nx < 10 && 0 <= ny && ny < 10)
                map[nx][ny]++;
        }
    }
    return;
}

Measured memory_bytes: 3244
#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[i];
    }
    sort(a.begin(), a.end());
    int c = 0;
    int p = 0;
    for (int i = 0; i < n; i++) {
        if (p == a[i]) {
            c++;
        } else {
            p = a[i];
        }
    }

    if (c % 2 == 0) {
        cout << (n - c) << endl;
    } else {
        cout << (n - c - 1) << endl;
    }
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

template<typename T>
void cout_vec(vector<T> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}

int bin_search(int l, int r, vector<vector<int> > &A){
    int mid=(l+r)/2+(l+r)%2;
    if(mid==r){
        return mid;
    }
    int N=A.size();
    int M=A[0].size();
    
    vector<int> index(N,0);
    vector<int> no(M,0);
    int flag=0;
    while(flag==0){
        vector<int> cnt(M,0);
        for(int i=0; i<N; i++){
            int j=index[i];

            while(j<M && no[A[i][j]]==1){
                index[i]++;
                j++;
            }
            if(j==M){
                return bin_search(mid, r, A);
            }

            int a=A[i][j];
            cnt[a]++;
        }

        flag=1;
        for(int i=0; i<M; i++){
            if(cnt[i]>mid){
                no[i]=1;
                flag=0;
            }
        }
        //cout << mid << ' ' << flag << endl;
        //cout_vec(cnt);
    }
    //cout << mid << endl;
    //cout_vec(no);

    if(flag==1){
        return bin_search(l, mid, A);
    }else{
        return bin_search(mid, r, A);
    }
}

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

    vector<vector<int> > A(N,vector<int>(M,0));
    for(int i=0; i<N; i++){
        for(int j=0; j<M; j++){
            int a;
            cin >> a;
            A[i][j]=a-1;
        }
    }

    cout << bin_search(0, N, A) << endl;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	
	public static void main(String[] args) {
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			
			String str = "";
			for (;;) {
				String input = reader.readLine();
				String[] array = input.split(" ");
				int m = Integer.parseInt(array[0]);
				int f = Integer.parseInt(array[1]);
				int r = Integer.parseInt(array[2]);
				int sum = m + f;
			
				if (m == -1 && f == -1 && r == -1) {
					break;
				} else if (m == -1 || f == -1) {
					System.out.print("F");
				} else if (sum >= 80 ) {
					System.out.print("A");
				} else if (sum >= 65 && sum < 80) {
					System.out.print("B");
				} else if (sum >= 50 && sum < 65) {
					System.out.print("C");
				} else if (sum >= 30 && sum < 50) {
					if (r >= 50) {
						System.out.print("C");
					} else {
						System.out.print("D");
					}
				} else if (sum < 30) {
					System.out.print("F");
				}
				System.out.println();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}

Measured memory_bytes: 24128
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define ll long long
using namespace std;
const int MOD = 1000000007;
const long long INF = 1LL << 60;
typedef pair<ll, ll> P;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, h;
  cin >> n >> h;
  vector<ll> a(n);
  vector<ll> b(n);
  for (ll i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  sort(a.rbegin(), a.rend());
  sort(b.rbegin(), b.rend());
  ll cnt = 0;
  for (ll j = 0; j < n; j++) {
    if (a[0] <= b[j]) {
      h -= b[j];
      cnt++;
      if (h <= 0) {
        cout << cnt << endl;
        return 0;
      }
    } else {
      break;
    }
  }
  while (1) {
    if (h <= 0) {
      cout << cnt << endl;
      return 0;
    }
    h -= a[0];
    cnt++;
  }
}

Measured memory_bytes: 4788
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;
typedef  long long int ll;
ll x[100005];

int main()
{
    ll n,a,b;
    ll i;
    ll cost = 0;

    scanf("%lld%lld%lld",&n,&a,&b);
    scanf("%lld",&x[1]);
    for(i = 2;i <= n;i++)
    {
        scanf("%lld",&x[i]);
        ll temp = (x[i] - x[i-1]) * a;
        if(temp > b) cost += b;
        else cost += temp;
    }
    printf("%lld\n",cost);

    return 0;
}


Measured memory_bytes: 1024
n, m, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
x.sort()
y.sort()
x_max = x[-1]
y_min = y[0]
if max(X, x_max) < min(Y, y_min):
    print('No War')
else:
    print('War')

Measured memory_bytes: 3060
#define R(i,n) for(i=0;i++<n;)
b[52][52],w,h,c;M(y,x){if(b[y][x]^1)return;b[y][x]++;M(y+1,x);M(y,x+1);M(y,x-1);M(y-1,x);M(y+1,x+1);M(y+1,x-1);M(y-1,x+1);M(y-1,x-1);}main(i,j){for(;scanf("%d%d",&w,&h),w;c=!printf("%d\n",c)){memset(b,-1,sizeof(b));R(i,h)R(j,w)scanf("%d",&b[i][j]);R(i,h)R(j,w)if(b[i][j]&1)c++,M(i,j);}}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int>vec(N);
  for (int i=0; i < N; i++){
  cin >> vec.at(i);
  }
  
  for (int i = 0; i < N; i++){
    bool a = true;
    
  for (int j = i+1; j < N;j++){
  if (vec.at(i) == vec.at(j)){
  vec.at(i) = 0;
    a = false;
    continue;
    
  }  
  }
   if(a){
   vec.at(i) = 1;
   }  
  }
  
  int b = 0;
  
  for (int i=0; i < N; i++){
  b = b + vec.at(i);
  }
  
  cout << b << endl;
  
}
 

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

using ll = long long int;

const int MAX_N = (int)1e5 + 5;

int n;
ll h;
ll a[MAX_N], b[MAX_N];

ll ma, mb;
ll thrdmg = 0;
ll attdmg = 0;
ll thrtimes = 0;

int main(void){
  // Here your code !
  scanf("%d %lld", &n, &h);
  for (int i = 0; i < n; ++i) {
    scanf("%lld %lld", &a[i], &b[i]);
  }

  sort(b, b + n);
  sort(a, a + n);

  ma = a[n - 1];
  mb = b[n - 1];

  for (int i = n - 1; i >= 0; --i) {
    if (ma < b[i]) {
      thrdmg += b[i];
      thrtimes += 1;
    }

    if (h <= thrdmg) {
      printf("%lld\n", thrtimes);
      return 0;
    }
  }

  attdmg = h - thrdmg;

  // printf("%lld\n", thrtimes + (ll)(ceil((double)attdmg / (double)ma)));


  if (attdmg < ma) {
    printf("%lld\n", thrtimes + 1);
  }
  else {
    if (attdmg % ma != 0) {
      printf("%lld\n", thrtimes + 1 + (attdmg / ma));
    }
    else {
      printf("%lld\n", thrtimes + (attdmg / ma));
    }
  }

  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstring>
#define N 100005
using namespace std;
typedef long long ll;
struct mat{
	ll a[15][15];
}dan;
int n,m,a[N],d[N],fa[N][65],now[N];
ll k,b[N];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),d[i]=a[i]-a[i-1],now[i]=i;
	scanf("%d%lld",&m,&k);
	for(int i=1,x;i<=m;i++){
		scanf("%d",&x);
		swap(now[x],now[x+1]);
	}
	for(int i=1;i<=n;i++) fa[i][0]=now[i];
	for(int i=1;i<=62;i++)
		for(int p=1;p<=n;p++) fa[p][i]=fa[fa[p][i-1]][i-1];
	for(int i=1;i<=n;i++){
		now[i]=i;
		for(int p=0;p<=62;p++){
			if(k&(1LL<<p)) now[i]=fa[now[i]][p];
		}
		b[i]=d[now[i]];
	}
	for(int i=1;i<=n;i++,b[i]+=b[i-1]) printf("%lld\n",b[i]);
	return 0;
}

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

int main(){
    ll n,k,q;
    cin>>n>>k>>q;
    vector<ll> a(q);
    rep(i,q) cin>>a[i];

    if(k>q){
        rep(i,n) cout<<"Yes"<<"\n";
        return 0;
    }
    else{
        //vector<ll> cnt(n+1,0);
        map<int,int> cnt;
        rep(i,q) cnt[a[i]]++;
        for(int i=1;i<=n;i++){
            if(cnt[i]>=q-k+1) cout<<"Yes"<<"\n";
            else cout<<"No"<<"\n";
        }
        return 0;
    }
}

Measured memory_bytes: 8752
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	int w, h, n;
	cin >> w >> h >> n;
	int minx = 0, maxx = w;
	int miny = 0, maxy = h;
	for(int i = 0; i < n; i++){
		int x, y, a;
		cin >> x >> y >> a;
		if(a == 1) minx = max(x, minx);
		else if(a == 2) maxx = min(x, maxx);
		else if(a == 3) miny = max(y, miny);
		else maxy = min(y, maxy);
	}
	cout << max(0, maxx - minx) * max(0, maxy - miny) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<=n;++i)
int map[501][501];
int main(){
  int h,w;cin>>h>>w;
  int sum=0;
  vector<vector<int>> ans;
  rep(i,501){
    rep(j,501){
      map[i][j]=0;
    }
  }
  rep1(i,h){
    rep1(j,w){
      cin>>map[i][j];
      sum+=map[i][j];
      if(map[i][j]%2==1){
        map[i][0]++;
        map[0][j]++;
      }
    }
  }

  int ansnum=0;
  rep1(i,h){
    int first=1000;
    rep1(j,w){
      if(map[i][j]%2==1){
        if(map[i][0]%2==1){
        if(j<first){
          first=j;
          if(i==h)continue;
          vector<int> buf;
          buf.push_back(i);
          buf.push_back(j);
          buf.push_back(i+1);
          buf.push_back(j);
          ans.push_back(buf);
          ansnum++;
          map[i+1][j]++;
          map[i+1][0]++;
        }
        if(j>first){
          vector<int> buf;
          buf.push_back(i);
          buf.push_back(j);
          buf.push_back(i);
          buf.push_back(j+1);
          ans.push_back(buf);
          ansnum++;
          map[i][j+1]++;
        }
        }
        else {
          vector<int> buf;
          buf.push_back(i);
          buf.push_back(j);
          buf.push_back(i);
          buf.push_back(j+1);
          ans.push_back(buf);
          ansnum++;
          map[i][j+1]++;
        }
      }
    }
  }
  cout<<ansnum<<endl;
  rep(i,ansnum){
    rep(j,4){
      cout<<ans[i][j];
      if(j<3)cout<<" ";
    }
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 10032
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
const double PI=acos(-1.0);
signed main(){
    ll n;cin>>n;
    vector<ll>x(n),y(n);
    rep(i,n){
        cin>>x[i]>>y[i];
    }
    rep(i,n){
        vector<double>a(0);
        rep(j,n){
            if(i==j)continue;
            a.pb(atan2(y[j]-y[i],x[j]-x[i]));
        }
        ll m=a.size();
        rep(i,m){
            a.pb(a[i]+2.0*PI);
        }
        sort(all(a));
        double ma=0.0;
        rep(i,m*2-1){
            ma=max(ma,a[i+1]-a[i]);
        }
        ma=max(0.0,ma-PI);
        cout<<fixed<<setprecision(10)<<ma/PI/2.0<<endl;
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;

int n = 100005,u,v;
vector<int> dis_u(n);
vector<int> dis_v(n);
vector<vector<int>> tree(n,vector<int>());

void dfs(int i,int before,int d,int par){
  if(par == u) dis_u.at(i) = d;
  else dis_v.at(i) = d;
  
  for(int p:tree.at(i)){
    if(p == before) continue;
    dfs(p,i,d+1,par);
  }
}
  
 
int main() {
  cin >> n >> u >> v;
  --u;--v;
  rep(i,n-1){
    int a,b;
    cin >> a >> b;
    --a;--b;
    tree.at(a).push_back(b);
    tree.at(b).push_back(a);
  }
  
  dfs(u,-1,0,u);
  dfs(v,-1,0,v);
  
  int ans = 0;
  rep(i,n){
    if(dis_u.at(i) < dis_v.at(i)){
      ans = max(ans,dis_v.at(i)-1);
    }
  }
  cout << ans << endl;
  
  return 0;
}





Measured memory_bytes: 11648
#include<stdio.h>
int main(void)
{
	int a,aa,b,bb,c,s,ss;
	while(scanf("%d %d",&a,&b)!=EOF){
		aa=a;  
		bb=b;
		if(a<b){
			c=a;
			a=b;
			b=c;
		}
		while(1)	{
			if(a%b==0)	{
				break;
			}
			else	{
				c=a%b;
				a=b;
				b=c;	
			}
		}
		s=b;
		ss=aa/b*bb;
		printf("%d %d\n",s,ss);
	}
	return 0;
}

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

pair <long long, long long> dis[310][310];

vector <pair<long long, long long>> ed[310];

void solve(long long v, long long l){
	
	priority_queue <pair<pair<long long, long long>, long long>> q;
	
	q.push(make_pair(make_pair(0, l), v));
	
	dis[v][v] = make_pair(0, l);
	
	while(!q.empty()){
		
		long long t = -q.top().first.first, c = q.top().first.second, x = q.top().second;
		
		q.pop();
		
		if(dis[v][x].first == t && dis[v][x].second == c){
			
			for(long long i = 0; i < (long long)ed[x].size(); i++){
				
				long long tx = t + (ed[x][i].second > c), cx = (ed[x][i].second > c) ? (l - ed[x][i].second) : (c - ed[x][i].second), xx = ed[x][i].first;
				
				if(cx < 0) continue;
				else if((dis[v][xx].first == -1) || ((dis[v][xx].first > tx) || ((dis[v][xx].first == tx) && (dis[v][xx].second < cx)))){
					q.push(make_pair(make_pair(-tx, cx), xx));
					dis[v][xx].first = tx;
					dis[v][xx].second = cx;
				}
			}
		}
	}
}
			
		
int main(){
	
	for(long long i = 0; i < 310; i++) for(long long j = 0; j < 310; j++) dis[i][j].first = -1;
	
	long long n, m, l;
	scanf("%lld %lld %lld", &n, &m, &l);
	
	for(long long i = 0; i < m; i++){
		long long u, v, x;
		scanf(" %lld %lld %lld", &u, &v, &x);
		
		ed[u].push_back(make_pair(v, x));
		ed[v].push_back(make_pair(u, x));
	}
	
	for(long long i = 0; i < n; i++) solve(i + 1, l);
	
	long long q;
	scanf(" %lld", &q);
	
	for(long long i = 0; i < q; i++){
		long long s, t;
		scanf(" %lld %lld", &s, &t);
		
		printf("%lld\n", dis[s][t].first);
	}
	
	return 0;
}


Measured memory_bytes: 5736
#include<iostream>
#include<string>

using namespace std;

string in;
int index;

int formula(int p,int q,int r);
int formula2(int p,int q,int r);

int formula(int p,int q,int r){
	int num;
	if(in[index]=='0'){
		index++;
		return 0;
	}
	if(in[index]=='1'){
		index++;
		return 1;
	}
	if(in[index]=='2'){
		index++;
		return 2;
	}
	if(in[index]=='P'){
		index++;
		return p;
	}
	if(in[index]=='Q'){
		index++;
		return q;
	}
	if(in[index]=='R'){
		index++;
		return r;
	}
	if(in[index]=='-'){
		index++;
		num=formula(p,q,r);
		if(num==0) num=2;
		else if(num==2) num=0;
		else num=1;
		return num;
	}
	if(in[index]=='('){
		index++;
		num=formula2(p,q,r);
		return num;
	}
}
int formula2(int p,int q, int r){
	int num1;
	if(in[index]=='('){
		index++;
		num1=formula2(p,q,r);
	}
	else num1=formula(p,q,r);

	char c=in[index];
	index++;

	int num2;
	if(in[index]=='('){
		index++;
		num2=formula2(p,q,r);
	}
	else num2=formula(p,q,r);

	index++;
	if(c=='*'){
		if(num1==0||num2==0) return 0;
		if(num1==1||num2==1) return 1;
		return 2;
	}
	else{
		if(num1==2||num2==2) return 2;
		else if(num1==1||num2==1) return 1;
		return 0;
	}
}


int main(){

	int pdata[]={0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2};
	int qdata[]={0,0,0,1,1,1,2,2,2,0,0,0,1,1,1,2,2,2,0,0,0,1,1,1,2,2,2};
	int rdata[]={0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2};
	int cnt;

	while(1){

		cin>>in;
		if(in==".") break;

		cnt=0;
		for(int i=0;i<27;i++){
			index=0;
			if(formula(pdata[i],qdata[i],rdata[i])==2) cnt++;
		}
		cout<<cnt<<endl;

	}

}

Measured memory_bytes: 1192
s = input()
n = int(input())
for i in range(n):
    command = input().split()
    a = int(command[1])
    b = int(command[2])
    if command[0] == 'print':
        print(s[a:b+1])
    elif command[0] == 'reverse':
        s = s[:a]+s[a:b+1][::-1]+s[b+1:]
    else:
        s = s[:a]+command[3]+s[b+1:]



Measured memory_bytes: 5616
from itertools import product
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    _ = int(readline())
    A = [(0, int(i)) for i in readline().split()]
    _ = int(readline())
    M = [int(i) for i in readline().split()]

    check_list = [0] * (2000+1)
    for a in product(*A):
        sum_a = sum(a)
        if sum_a > 2000:
            continue
        check_list[sum_a] = 1

    for m in M:
        print("yes" if check_list[m] else "no")


if __name__ == "__main__":
    main()


Measured memory_bytes: 5704
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <climits>
#include <math.h>
using namespace std;

typedef long long ll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) a.begin(),a.end()

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


Measured memory_bytes: 256
import java.util.*;

public class Main
{
    public static void main(String[] args) {
        //long start = System.currentTimeMillis();
        Scanner sc = new Scanner(System.in);
        long[] a = new long[2];
        long[] b = new long[2];
        a[0] = sc.nextLong();
        a[1] = sc.nextLong();
        b[0] = sc.nextLong();
        b[1] = sc.nextLong();

        long max = Long.MIN_VALUE;
        for (int i = 0;i<2;++i)
        {
            for (int j = 0;j<2;++j)
            {
                long tmp = a[i]*b[j];
                max = Math.max(tmp,max);
            }
        }
        System.out.println(max);
        sc.close();
//        long end = System.currentTimeMillis();
//        System.err.println((end-start)+"ms");
    }
}

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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)


typedef long long ll;
typedef unsigned long long int llt;

const int N = 1e5 + 10;

vector<int> g[N];
bool viss[N];
int vis[N];

void dfs(int curr, int par)
{
  for(auto x: g[curr])
    if(x != par)
      dfs(x, curr);
}

void dfs1(int curr, int par)
{
  viss[curr] = 1;
  for(auto x: g[curr])
    if(!viss[x])
      dfs1(x, curr);
}

void dfs2(int curr, int par, int num)
{
  vis[curr] = num;
  for(auto x: g[curr])
    if(vis[x] == 0)
      dfs2(x, curr, num);
}

ll fxor(ll n)
{
  if(n < 0) return 0;
  if(n % 4 == 3) return 0;
  else if(n % 4 == 0) return n;
  else if(n % 4 == 1) return n^(n-1);
  else if(n%4 == 2) return n^(n-1)^(n-2);
}

llt ppow(llt x, llt y)
{
  llt res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%M;
    y = y >> 1;
    x = (x * x)%M;
  }
  return res;
}

llt factdp[N];
llt fact(llt x)
{
  if(x == 0) return 1;
  if(x == 1) return 1;
  if(factdp[x] != -1) return factdp[x];
  return factdp[x] = (x*fact(x-1))%M;
}

string ans ="";
void convert10tob(llt N, int b)
{
     if (N == 0)
        return;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
     ans += to_string(x);
     return;
}

llt convertstrtob(string a, int b)
{
  llt aa = 0;
  llt mul = 1;
  for(int i=a.length()-1; i>=0; i--)
  {
    int curr = a[i] - '0';
    aa += (curr * mul);
    mul *= b;
  }
  return aa;
}


int main()
{
  string s;
  cin>>s;
  int n = s.length();
  if(s[0] == s[n-1])
  {
    if(n&1 == 1)
    {
      puts("Second");
    }
    else
    {
      puts("First");
    }
  }
  else
  {
    if(n&1 == 1)
    {
      puts("First");
    }
    else{
      puts("Second");
    }
  }
  return 0;
}


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

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

  for (int i = 0; i < (w + 2); i++) cout << '#';
  cout << endl;

  for (int i = 0; i < h; i++) {
    cout << '#';
    for (int j = 0; j < w; j++) {
      char a;
      cin >> a;
      cout << a;
    }
    cout << '#' << endl;
  }

  for (int i = 0; i < (w + 2); i++) cout << '#';
  cout << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stdio.h>
#include<cmath>
#include<string.h>

using namespace std;

int main(void)
{
	char o[51];
	char e[51];
	int i, len;
	cin >> o >> e;
	len = strlen(o);
	for (i = 0; i < len; i++)
	{
		cout << o[i];
		if (e[i] == '\0')
		{
			break;
	}
		cout << e[i];
	}
	cout << endl;
		return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int S, A, B, C;
	cin >> S;
	A = S % 10; // 一の桁の1の有無を確認
	B = S / 100; // 百の桁の1の有無を確認
	C = (S - (B * 100)) / 10; // 十の桁の1の有無を確認
	cout << A + B + C << endl;
}

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

int t;
/*
long long int ds(long long int val,int d){
	long long int go=val/d;
	go+=min(val%d,d-(val%d));
}*/

int a,b,c,d;
map<long long int,long long int> s;
void f(long long int &a,long long int b){
	if(b<0LL)return;
	if(a<0LL)a=b;
	a=min(a,b);
}
int ar[]={2,3,5};
long long int cs[]={0,0,0};
inline long long  dfs(long long int val){
	if(val==0)return 0;
	if(s.count(val)){
		return s[val];
	}
	s[val]=10000000000000000LL;
	if(10000000000000000LL/d>=val){
		s[val]=val*d;
	}
	for(int i=0;i<3;i++){
		f(s[val],dfs(val/ar[i])+cs[i]+(val%ar[i])*d);
		f(s[val],dfs(val/ar[i]+1)+cs[i]+(ar[i]-(val%ar[i]))*d);
	}
return s[val];
}

int main(){
	
//	cout<<s.size()<<endl;
	cin>>t;
	while(t--){
		long long int n;
		cin>>n>>a>>b>>c>>d;
		cs[0]=a;
		cs[1]=b;
		cs[2]=c;
		s.clear();
		cout<<dfs(n)<<endl;
		
	}
	return 0;
}


Measured memory_bytes: 4820
#https://atcoder.jp/contests/abc119/tasks/abc119_c
#2019-02-24
N, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(N)]


ans = []
# 00 なら使わない、 01 ならAをつくる、10 ならBをつくる、11ならCをつくる　
for i in range(1 << 2*N):
    A_hon = 0
    B_hon = 0
    C_hon = 0
    A_zai = 0
    B_zai = 0
    C_zai = 0
    for k in range(N):
        if i & (1<<(2*k)) and i & (1<< (2*k)+1):
            C_hon += 1
            C_zai += l[k]
        elif i & (1<<(2*k)+1):
            B_hon += 1
            B_zai += l[k]
        elif i & (1<<(2*k)):
            A_hon += 1
            A_zai += l[k]
    if A_hon * B_hon * C_hon >0:
       ans += [10*(A_hon - 1)+ abs(A_zai - A)+10*(B_hon - 1)+ abs(B_zai - B)+ 10*(C_hon - 1)+ abs(C_zai - C)]
print(min(ans))

Measured memory_bytes: 4996
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
using namespace std;

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

    int n;
    cin >> n;
    int u=n%10;
    if (u==2 or u==4 or u==5 or u==7 or u==9)
    {
        cout << "hon" << endl;
    } 
    else if (u==0 or u==1 or u==6 or u==8)
    {
        cout << "pon" << endl;
    }
    else
    {
        cout << "bon" << endl;
    }

    return 0;
}

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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    int n; cin >> n;
    vl a(n+2);
    rep1(i,n+1)cin >> a[i];
    vl s(n+2);
    rep(i,n+2)s[i+1] = s[i]+abs(a[i+1]-a[i]);
    ll res = s[n+1];
    rep1(i,n+1){ //1からnまで
        cout << res + abs(a[i+1]-a[i-1]) - abs(a[i]-a[i-1]) - abs(a[i]-a[i+1]) << endl;
    }
}


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

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

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

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

  ll N,M;
  cin>>N>>M;
  vector<pair<ll,ll>>A(N);
  for(int i=0;i<N;i++)cin>>A[i].first>>A[i].second;
  ll ans=0;
  sort(rng(A));
  for(int i=0;i<N;i++){
    ans+=min(M,A[i].second)*A[i].first;
    M-=min(M,A[i].second);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H & b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H & b) const { return x == b.x && y == b.y; }
	bool operator!=(const H & b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T & a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T & a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n, k;
string s;
int a[200000];
int b[200000];
signed main() {
	cin >> n >> k >> s;
	int m = 0;
	for (int i = 0; i < n;) {
		int j = i;
		while (j < n && s[i] == s[j]) {
			j++;
		}
		a[m] = j - i;
		b[m++] = !(int)(s[i] - '0');
		i = j;
	}
	for (int i = 1; i < m; i++) {
		a[i] += a[i - 1];
		b[i] += b[i - 1];
	}
	int r = m - 1;
	while (b[r] > k) {
		r--;
	}
	int ans = a[r];
	for (int i = 1; i < m; i++) {
		while (r + 1 < m && b[r + 1] - b[i - 1] <= k) {
			r++;
		}
		ans = max(ans, a[r] - a[i - 1]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 2048
# import math

s = [input() for i in range(2)]
n = int(s[0].split()[0])
m = int(s[0].split()[1])
a = list(map(int, s[1].split()))

for i in range(0, m):
    n = n - a[i]
    if n < 0:
        n = -1
        break

print(n)


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

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

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

    if(a > c){
        int tmp = a;
        a = c;
        c = tmp;
    }

    if(c - a <= d){
        cout << "Yes" << endl;
    }
    else if(b - a <= d && c - b <= d){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
//g++  5.4.0

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

#define ff first
#define ss second
#define int long long
#define ld long double
#define pb push_back
#define pii pair< int,int >
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;

const int mod = 1e9+7;

signed main()
{
    fast;
    int n;
    cin >> n;
    ld p[n+1],np[n+1];
    for(int i=1 ; i<=n ; i++ )  cin>>p[i] , np[i] = 1-p[i];
    ld dp[n+1];
    memset( dp,0,sizeof(dp));
    dp[0] = 1.00;
    
    for(int i=1 ; i<=n ; i++ )
    {
        for(int j=i ; j>0 ; j-- )
            dp[j] = dp[j-1]*p[i] + dp[j]*np[i];
        dp[0] *= np[i];
    }
    ld ans = 0;
    for(int i=n/2+1 ; i<=n ; i++ )
        ans += dp[i];
    cout << fixed << setprecision(9) << ans << "\n";
}





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

int b[1 << 21], *a;
int Max[1 << 20], __Max[1 << 20], ans[1 << 20];

int main() {
	
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	a = b + 10;
	int n; cin >> n;
	for (int i = 0; i < (1 << n); i++) cin >> a[i];
	for (int s = 0; s < (1 << n); s++) {
		Max[s] = s, __Max[s] = -1;
		for (int i = 0; i < n; i++) if (s >> i & 1) {
			auto t = s ^ (1 << i);
			if (a[Max[s]] == a[Max[t]]) {
				if (Max[s] == Max[t]) {
					if (a[__Max[s]] < a[__Max[t]]) __Max[s] = __Max[t];
				} else __Max[s] = Max[t];
			}
			if (a[Max[s]] > a[Max[t]]) {
				if (a[__Max[s]] < a[Max[t]]) __Max[s] = Max[t];
			}
			if (a[Max[s]] < a[Max[t]]) {
				if (a[Max[s]] < a[__Max[t]]) __Max[s] = __Max[t];
				else __Max[s] = Max[s];
				Max[s] = Max[t];
			}
		}
	}
	for (int s = 0; s < (1 << n); s++) {
		if (s == 0) ans[s] = a[Max[s]];
		else ans[s] = max(a[Max[s]] + a[__Max[s]], ans[s - 1]);
	}
	for (int s = 1; s < (1 << n); s++) cout << ans[s] << "\n";
	
	return 0;
}


Measured memory_bytes: 10240
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] H = new int[N];
        int cnt = 1;
        for (int i=0; i<N; i++) {
            H[i] = sc.nextInt();
            if (i == 0) {
                continue;
            }
            boolean isView = true;
            for (int j=0; j<H.length; j++) {
                if (H[j] > H[i]) {
                    isView = false;
                    break;
                }
            }
            if (isView)
                cnt++;
        }
        System.out.println(cnt);
    }
}

Measured memory_bytes: 21844
n=gets.to_i
aa = gets.chomp.split(" ").map{|a|a.to_i}
bb = gets.chomp.split(" ").map{|a|a.to_i}
#=======================

#=======================
def counttotaldeficit(n,a,b)
  deficit = 0
  j = 0
  for i in(0..n-1)
    if (a[i] - b[i]) <0
      j +=1
        deficit += a[i] - b[i]
    end
  end
  return [deficit,j]
end
#========================
def sort(n,a,b)
  ab =[]
  for i in (0..n-1)
    if a[i] - b[i] >0
      ab.push([a[i],b[i]])
  end
  end
  ab.sort_by!{|ary| -(ary[0]-ary[1])}
  return ab
end
#========================
def checker(n,a,b)
  answer = 0
  a.each_with_index{|item,index|
  if item < b[index]
    answer = -1
    break
  else
  end
  }
  if answer == 0
    return answer
  end
  ###
  array = counttotaldeficit(n,a,b)
  deficit = array[0]
  j = array[1]
  answer = j
  ###
  ###
  ab = sort(n,a,b)
  k=0
  while deficit < 0
    if k == ab.size
      return -1
    end
  dictance = ab[k][0] - ab[k][1]
  deficit = deficit + dictance
  answer +=1
  k +=1
  end

return answer


end
puts checker(n,aa,bb)


Measured memory_bytes: 21384
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<tuple>

#define DIV 1000000007
#define TE 2e5
using namespace std;
using ll = long long;
using ldb = long double;

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

	ll tot = 0;
	for (int i = 1; i < N; i++) {
		if (a[i - 1] > a[i]) {
			tot += a[i - 1] - a[i];
			a[i] = a[i - 1];
		}
	}
	cout << tot << endl;
}


Measured memory_bytes: 4760
#include<bits/stdc++.h>
using namespace std;
#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define pb push_back
#define int long long
#define ii pair<int, int>
#define fi first
#define se second

const int N = 1e5 + 10;
const int oo = 1e9;

int n, ans, dem, divn;
int a[N], prim[N], in[N], op[N];
map<int, int> f;
map<int, bool> square;
bool kt[N];
pair<int, int> di[N];

void prime()    {
    for(int i = 2; i <= 1e5; ++i)   if(!kt[i])  {
        prim[++dem] = i;
        for(int idem = 2; i*idem <= 1e5; ++idem) kt[i*idem] = true;
    }
}

int powe(int x, int y)  {
    if(!y) return 1LL;
    int mid = powe(x, y/2);
    if(y & 1) return mid * mid * x;
    else return mid * mid;
}

void decomp(int x, int pos){
    divn = 0;
    //cout << "?spm x=" << x << '\n';
    for(int i = 1; i <= 450; ++i) if(x % prim[i] == 0)   {
        int tmp = 0, v = prim[i];
        while(x % v == 0)   {
            tmp ++; x /= v;
        }
        di[++divn] = ii(v, tmp);
    }

    int maxl = 1ll, maxr = 1ll;
    FOR(i, 1, divn) {
        //cout << di[i].fi << ' ' << di[i].se << '\n';
        int tmpl = di[i].se % 3;
        int tmpr = 3 - (di[i].se % 3 == 0 ? 3 :(di[i].se % 3));
        maxl *= 1ll * powe(di[i].fi, tmpl);
        maxr *= 1ll * powe(di[i].fi, tmpr);
    }
    maxl *= x;
    if(square[x] == true) maxr *= 1ll * (long long)sqrt(x);
    else maxr *= 1ll * x * x;

    //cout << "en?? " << maxl << ' ' << maxr << '\n';
    f[maxl] ++;
    in[pos] = maxl, op[pos] = maxr;
}

signed main()
{
    //freopen("test.inp", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    prime();
    FOR(i, 1, dem) square[prim[i] * prim[i]] = true;

    cin >> n;
    FOR(i, 1, n) {
        cin >> a[i];
        decomp(a[i], i);

    }
    //FOR(i, 1, n) cout << in[i] << ' ' << op[i] << '\n';
    if(f.find(1) != f.end()) ans = 1;
    FOR(i, 1, n)    {
        if(in[i] != 1)    {
            ans += max(f[in[i]], f[op[i]]);
            f.erase(in[i]); f.erase(op[i]);
        }
    }
    cout << ans;
}
// 55340


Measured memory_bytes: 15232
n, a, b = map(int, input().split())
if (a - 1) >= (n - b):
    count = (n-b)
    a = a + (n - b)
    b = n
else:
    count = (a - 1)
    b = b - (a - 1)
    a = 1
#print(count)
if ((b - a) % 2 == 0):
    print(min(min(b-1,n-a),(b-a)//2))
elif a == 1 and (b - a) % 2 != 0:
    print(min(min(b - 1, n - a), (b - 1 - a) // 2 + 1) + count)
    #print(count)
elif b == n and (b - a) % 2 != 0:
    print(min(min(b - 1, n - a), (b - 1 - a) // 2 + 1)+count)
elif (b - a) == 3:
    print(min(b - 1, n - a) - 1+count)
elif (b - a) >= 5 and (b - a) % 2 != 0:
    print(min(b - 1, n - a) - 2+count)
else:
    print(min(b-1,n-a)+count)

Measured memory_bytes: 3064