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

using namespace std;

using ll = long long;

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

    vector<string> v(h);
    for (int i = 0; i < h; i++) {
        string s;
        cin >> s;
        v[i] = s;
    }

    vector<int> v1(h, 0);
    vector<int> v2(w, 0);
    int sumk = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (v[i][j] == '#') {
                v1[i]++;
                v2[j]++;
                sumk++;
            }
        }
    }

    int ans = 0;
    for (int bit1 = 0; bit1 < (1 << h); bit1++) {
        for (int bit2 = 0; bit2 < (1 << w); bit2++) {
            int sum = 0;
            for (int i = 0; i < h; i++) {
                if (bit1 & (1 << i)) {
                    sum += v1[i];
                }
            }
            for (int i = 0; i < w; i++) {
                if (bit2 & (1 << i)) {
                    for (int j = 0; j < h; j++) {
                        if (v[j][i] == '#' && !(bit1 & (1 << j))) sum++;
                    }
                }
            }
                    
            if (sumk - sum == k) ans++;
        }
    }


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

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

int main()
{
    int A, B, C, D;

    cin >> A>>B>>C>>D;
    
    if((A+B)>(C+D)){
        cout << "Left" << endl;
    }
    else if ((A + B) < (C + D)){
        cout << "Right" << endl;
    }
    else{
        cout << "Balanced" << endl;
    }
}

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

#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";


#define     SPEED     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define 	ll          long long int
#define 	pb          push_back
#define 	pii         pair<int,int>
#define 	vi          vector<int>
#define 	pll         pair<ll,ll>
#define 	vll         vector<ll>
#define 	ff          first
#define 	ss          second
#define 	all(a)      (a).begin(),(a).end()
#define 	sz(x)       (ll)x.size()
#define 	hell        1000000007
#define 	rep(i,n)    for(i=0;i<n;i++)
#define 	repe(i,a,b) for(i=a;i<b;i++)
#define 	lbnd        lower_bound
#define 	ubnd        upper_bound
#define 	bs          binary_search
#define 	mp          make_pair

ll power(ll a,ll b)
{
	if(b==0)
		return 1;
	if(b==1)
		return a;
	ll c=power(a,b/2);
	if(b%2==0)
		return((c%hell)*(c%hell))%hell;
	return ((((c%hell)*(c%hell))%hell)*(a%hell))%hell;
}

/********************************************************/

string s,p;
ll dp[3005][3005];
vll v;

ll f(ll x,ll y)
{
	if(x>=s.length() || y>=p.length()) return 0;
	if(dp[x][y]==-1)
	{
		if(s[x]==p[y]) dp[x][y]=f(x+1,y+1)+1;
		else
		{
			ll a=f(x+1,y),b=f(x,y+1);
			dp[x][y]=max(a,b);
		}
	}
	// debug3(x,y,dp[x][y]);
	return dp[x][y];
}

void path(ll x,ll y)
{
	if(x>=s.length() || y>=p.length()) return ;
	ll ans=dp[x][y];
	// debug3(x,y,ans);
	if(s[x]==p[y])
	{
		cout<<s[x];
		return path(x+1,y+1);
	}
	else if(ans==dp[x+1][y])
	{
		return path(x+1,y);
	}
	else return path(x,y+1);
}

int main()
{
	SPEED;
	ll n,k,t,c=0,i,j,m,cs=0;
	t=1;
	// cin>>t;
	while(t--)
	{
		cin>>s>>p;
		memset(dp,-1,sizeof(dp));
		// n=s.length();
		// ll a[n];
		c=f(0,0);
		path(0,0);
		if(t!=0)
	   		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 71168
N = int(input())
a = [int(input()) for _ in range(N)]
 
i = 0
m = 1
while(1):
    if a[i] == 2:
        ans = m
        break
 
    if m >= N:
        ans = -1
        break
 
    i = a[i] - 1 
    m += 1

print(ans)

Measured memory_bytes: 13048
#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];
  }

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

  vector<int> C(N - 1);
  for (int i = 0; i < N - 1; i++) {
    cin >> C[i];
  }

  int total = 0;
  int previous = 0;

  for (int i = 0; i < N; i++) {
    int Ai = A[i];
    int Bi = B[Ai - 1];

    total += Bi;

    if (previous + 1 == Ai) {
      int Ci = C[previous - 1];
      total += Ci;
    }

    previous = Ai;
  }

  cout << total << endl;
}

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

int main(){
  string S;
  cin >> S;
  bool yes=false;
  if (S[0]==S[1] && S[2]==S[3] && (S[0]!=S[2])) cout << "Yes";
  else if (S[0]==S[2] && S[1]==S[3] && (S[0]!=S[1])) cout << "Yes";
  else if (S[0]==S[3] && S[1]==S[2] && (S[0]!=S[1])) cout << "Yes";
  else cout << "No";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
#define No cout<<"No"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
    int n,k;
    cin>>n>>k;
    int x[n],ans=0;
    rep(i,n){
    cin>>x[i];
    ans+=min(2*(k-x[i]),2*x[i]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int n;
	std::cin >> n;
	std::vector<int> h(n);
	rep(i,n) std::cin >> h[i];
	int last=0;
	rep(i,n) {
		if(h[i]<last) {
			print("No");
			return 0;
		}
		if(h[i]>last) last=h[i]-1;
		else last=h[i];
	}
	print("Yes");
	return 0;
}


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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)((n)-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p){
    return o << "(" << p.first << ", " << p.second << ")";
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

vi g[200010];
vi d;
void dfs(int v, int p){
    for(int u : g[v]){
        if(u == p) continue;
        d[u] = d[v] + 1;
        dfs(u, v);
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int n; cin >> n;
    rep(i,n-1){
        int a,b; cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    d = vi(n, 0);
    dfs(0, -1);
    int s = 0;
    rep(i,n) if(d[s] < d[i]) s = i;
    d = vi(n, 0);
    dfs(s, -1);

    int turn = 0;
    rep(i,n) turn = max(turn, d[i]);
    if(turn % 3 == 1) cout << "Second" << endl;
    else cout << "First" << endl;
    return 0;
}

Measured memory_bytes: 24800
n,t = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]

ab.sort()

dp = [[0] * (t+1) for _ in range(n+1)]

for i in range(1,n+1):
    a,b = ab[i-1]
    for j in range(1,t):
        if(j < a):
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])
        else:
            dp[i][j] = max(dp[i-1][j], dp[i][j-1], dp[i-1][j-a] + b)
    dp[i][t] = max(dp[i-1][t], dp[i][t-1], dp[i-1][t-1]+b)

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

Measured memory_bytes: 118616
package main

import "fmt"

var H, W int
var S []string

func main() {
	fmt.Scanf("%d %d", &H, &W)

	S := make([]string, H)

	for i := 0; i < H; i++ {
		fmt.Scanf("%s", &S[i])
	}

	que := newQueue()
	que.enqueue(&Point{0, 0, 0})

	gone := make([][]bool, H)
	for i := 0; i < H; i++ {
		gone[i] = make([]bool, W)
	}
	gone[0][0] = true

	dx := []int{-1, 0, 1, 0}
	dy := []int{0, -1, 0, 1}

	s := 0
	for i := 0; i < H; i++ {
		for j := 0; j < W; j++ {
			if ([]rune(S[i]))[j] == '#' {
				s++
			}
		}
	}

	var p *Point
	for !que.isEmpty() {
		p = que.dequeue()

		if p.x == W-1 && p.y == H-1 {
			break
		}

		for i := 0; i < 4; i++ {
			y := p.y + dy[i]
			x := p.x + dx[i]
			if 0 <= x && x < W && 0 <= y && y < H {
				if !gone[y][x] && ([]rune(S[y]))[x] == '.' {
					gone[y][x] = true
					que.enqueue(&Point{x, y, p.m + 1})
				}
			}
		}
	}

	if p.x != W-1 || p.y != H-1 {
		fmt.Println(-1)
	} else {
		fmt.Println(W*H - s - p.m - 1)
	}
}

// Queue

type Point struct {
	x int
	y int
	m int
}

type queue struct {
	container []*Point
}

func newQueue() *queue {
	return &queue{make([]*Point, 0)}
}

func (q *queue) enqueue(s *Point) *Point {
	q.container = append(q.container, s)
	return s
}

func (q *queue) dequeue() *Point {
	s := q.container[0]
	q.container = q.container[1:]
	return s
}

func (q *queue) isEmpty() bool {
	return len(q.container) == 0
}


Measured memory_bytes: 2048
#include<iostream>
#include<vector>
#include<algorithm>
int main() {
	int t;
	std::cin >> t;
	std::vector<int> v(t);
	for (int i = 0;i < t;++i) {
		int n, k;
		std::cin >> n >> k;
			std::vector<int> x(n);
			int denki = 0;
			for (int j = 0;j < n;++j) {
				std::cin >> x[j];
			}
			if(n>k){
			std::vector<int>l(n - 1);
			for (int j = 0;j < n-1;++j) {
				l[j] = x[j + 1] - x[j];
			}
			std::sort(l.begin(), l.end());
			for (int j = n-2;j>n-1-k;--j) {
				denki += l[j];
			}
			v[i] = x[n - 1]-x[0] - denki;
		}
		else {
			v[i] = 0;
		}
	}
	for (int i = 0;i < t;++i) {
		std::cout << v[i]<< std::endl;
	}
	return 0;
}

Measured memory_bytes: 1804
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    T = [I() for _ in range(N)]

    gcd = T[0]
    ans = T[0]
    for i in T:
        gcd = math.gcd(i, ans)
        ans = ans * i // gcd

    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10064
#include<iostream>
#include<queue>
#include<stack>
using namespace std;
struct QS{
    stack< int > D[3];
    int cnt;
    int prev;
    //A->B 1
    //A<-B 2
    //B->C 3
    //B<-C 4
};
int m,n;
queue< QS > Q;
int BFS(){
    while(!Q.empty()){
        if(Q.front().cnt>m)return -1;

        if(Q.front().D[0].size()==n)return Q.front().cnt;
        if(Q.front().D[2].size()==n)return Q.front().cnt;

        //cout<<"prev = "<<Q.front().prev<<endl;

        int x = Q.front().D[0].empty() ? 0 : Q.front().D[0].top();
        int y = Q.front().D[1].empty() ? 0 : Q.front().D[1].top();
        int z = Q.front().D[2].empty() ? 0 : Q.front().D[2].top();

        QS sub = Q.front();
        if(x > y&&sub.prev!=2){
            sub.D[1].push(sub.D[0].top());
            sub.D[0].pop();
            sub.cnt++;
            sub.prev = 1;
            Q.push(sub);

        }
        sub = Q.front();
        if(x < y&&sub.prev!=1){
            sub.D[0].push(sub.D[1].top());
            sub.D[1].pop();
            sub.cnt++;
            sub.prev = 2;
            Q.push(sub);
        }

        sub = Q.front();
        if(y > z&&sub.prev!=4){
            sub.D[2].push(sub.D[1].top());
            sub.D[1].pop();
            sub.cnt++;
            sub.prev = 3;
            Q.push(sub);
        }
        sub = Q.front();
        if(y < z&&sub.prev!=3){
            sub.D[1].push(sub.D[2].top());
            sub.D[2].pop();
            sub.cnt++;
            sub.prev = 4;
            Q.push(sub);
        }
        Q.pop();
    }
    return -1;
}
int main(){


    while(cin>>n>>m,n||m){
        while(!Q.empty())Q.pop();
        QS data;
        for(int i = 0;i < 3;i++){
            int x;
            cin>>x;
            for(int j = 0;j < x;j++){
                int y;
                cin>>y;
                data.D[i].push(y);
            }
        }
        data.cnt = 0;
        data.prev = -1;
        Q.push(data);
        cout<<BFS()<<endl;

    }

    return 0;
}

Measured memory_bytes: 1244
#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cstring>

using namespace std;

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

class Rule{
	public:
	bool isempty(char c){
		return c==':' || c==' ' || c=='\n' || c==0;
	}
	Rule(char* str){
		int len = strlen(str);
		rep(i,len){
			if(isempty(str[i]))str[i]=0;
		}
		int count = 0;
		rep(i,len){
			if(!isempty(str[i])){
				if(i==0)name = string(str+i);
				else if(isempty(str[i-1]))to.push_back(string(str+i));
				count++;
			}
		}
	}
	string name;
	vector<string> to;
};

class S{
	public:
	bool a,t,g,c;
	S(string str){
		a=t=g=c=false;
		rep(i,str.size()){
			if(str[i]=='A')a=true;
			if(str[i]=='T')t=true;
			if(str[i]=='G')g=true;
			if(str[i]=='C')c=true;
		}
	}
};

int na,ng,nt,nc;
vector<Rule> rules;
map<string,int> rmap;

void input(){
	cin>>na>>nt>>ng>>nc;
	int r;
	cin>>r;
	bool b=false;
	rep(i,r){
		char str[3000];
		string s;
		getline(cin,s);
		if(!b){
			b=true;
			i--;
			continue;
		}
		str[s.size()]=0;
		rep(j,s.size())str[j]=s[j];
		rules.push_back(Rule(str));
		rmap[rules[i].name]=i;
	}
}

vector<S> state;

bool isend(string& str){
	return str[0]=='[';
}
void make_state_req(int num){
	rep(i,rules[num].to.size()){
		string next = rules[num].to[i];
		if(state.size()>na+nt+ng+nc)continue;
		if(isend(next)){
			state.push_back(S(next));
		}else{
			make_state_req(rmap[next]);
		}
	}
}

void printstate(){
	rep(i,state.size()){
		cout<<state[i].a<<" "<<state[i].t<<" "<<state[i].g<<" "<<state[i].c<<endl;
	}
}

void make_state(){
	make_state_req(0);
}


const int N = 51;
const int MOD = 1000000007;

int memo[N][N][N][N];

int solve_dp_req(int na,int nt,int ng, int nc){
	int sum = na+nt+ng+nc;
	if(na<0 || nt<0 || ng<0 || nc<0)return 0;
	if(sum==0)return 1;
	if(memo[na][nt][ng][nc]!=-1)return memo[na][nt][ng][nc];
	
	int ans = 0;
	if(state[sum-1].a && na!=0){
		//printf("****************** %d %d %d %d CALL %d %d %d %d\n",na,nt,ng,nc,na-1,nt,ng,nc);
		ans = (ans + solve_dp_req(na-1, nt, ng, nc))%MOD;
	}
	if(state[sum-1].t && nt!=0){
		//printf("****************** %d %d %d %d CALL %d %d %d %d\n",na,nt,ng,nc,na,nt-1,ng,nc);
		ans = (ans + solve_dp_req(na, nt-1, ng, nc))%MOD;
	}
	if(state[sum-1].g && ng!=0){
		//printf("****************** %d %d %d %d CALL %d %d %d %d\n",na,nt,ng,nc,na,nt,ng-1,nc);
		ans = (ans + solve_dp_req(na, nt, ng-1, nc))%MOD;
	}
	if(state[sum-1].c && nc!=0){
		//printf("****************** %d %d %d %d CALL %d %d %d %d\n",na,nt,ng,nc,na,nt,ng,nc-1);
		ans = (ans + solve_dp_req(na, nt, ng, nc-1))%MOD;
	}
	
	/*
	cout<<state[sum-1].a<<" "<<state[sum-1].t<<" "<<state[sum-1].g<<" "<<state[sum-1].c<<"| ";
	printf("%d %d %d %d : %d\n",na,nt,ng,nc,ans);
	*/
	return memo[na][nt][ng][nc]=ans;
}
int solve_dp(){
	rep(i,N)rep(j,N)rep(k,N)rep(p,N)memo[i][j][k][p]=-1;
	if(na+nt+ng+nc!=state.size())return 0;
	return solve_dp_req(na,nt,ng,nc);
}

int solve(){
	make_state();
	//printstate();
	return solve_dp();
}

int main(){
	input();
	printf("%d\n",solve());
}

/*
1 0 1 4
4
dna: a b c
a: c [AT]
b: c c [CG]
c: [ACT]

1 1 1 0
2
dna: a a
a: [ATCG]

*/

Measured memory_bytes: 27712
#include<bits/stdc++.h>
#include<vector>
#define Inf 100005
using namespace std;
const int maxn=100010;
typedef pair<int,int>PII;
typedef vector<PII>VII;
VII G[maxn];
int h,w;
void addedge(int from,int to,int weight)
{
    G[from].push_back(make_pair(to,weight));
}
void init(int n)
{
    for(int i=0;i<=n;i++)
    {
        G[i].clear();
    }
}
int vis[maxn],dis[maxn];
int n=10;
void dijkstra(int start)
{
    for(int i=0;i<=n;i++)
    {
        vis[i]=0;
        dis[i]=Inf;
    }
    dis[start]=0;
    priority_queue<PII,VII,greater<PII> > q;
    q.push(make_pair(dis[start],start));
    while(!q.empty())
    {
        PII p=q.top();
        int x=p.second;
        q.pop();
        if(vis[x]) continue;
        vis[x]=1;
        for(int i=0;i<G[x].size();i++)
        {
            int y=G[x][i].first;
            int d=G[x][i].second;
            if(!vis[y]&&dis[x]+d<dis[y])
            {
                dis[y]=dis[x]+d;
                q.push(make_pair(dis[y],y));
            }
        }
    }
}
int main()
{
    while(cin>>h>>w)
    {
        memset(dis,Inf,n);
        init(15);
        for(int i=0;i<10;i++)
        {
            for(int j=0;j<10;j++)
            {
                int cost;
                cin>>cost;
                addedge(j,i,cost);
            }
        }
        dijkstra(1);
        long long sum=0;
        for(int i=0;i<h;i++)
        {
            for(int j=0;j<w;j++)
            {
                int wall;
                cin>>wall;
                if(wall!=-1)
                    sum+=dis[wall];
            }
        }
        cout<<sum<<endl;
        //if(dis[g]!=Inf) cout<<dis[g]<<endl;
        //else cout<<"-1\n";
    }
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;



int main(){
    cin>>N>>M;
    if(N > M) swap(N, M);
    rep(i,M) cout<<N;
    cout<<endl;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

ae,be='',''
h,w=map(int,input().split())
a=[['#' for i in range(w)] for _ in range(h)]
b=[['#' for i in range(w)] for _ in range(h)]

a[-1]=['.' for i in range(w)]
b[0]=['.' for i in range(w)]

if w%2==1:
        ae='#'
        be='.'

for i in range(1,h-1):
    x,y='#','.'
    for j in range(w):
        a[i][j]=x
        b[i][j]=y
        x,y=y,x

for i in range(h):
    s=input()
    for j in range(w):
        if s[j]=='#':
            a[i][j]='#'
            b[i][j]='#'

for i in range(h):
    print(''.join(a[i]))
print('')
for i in range(h):
    print(''.join(b[i]))



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

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> d;
  vector<vector<int>> A;
  
  d.resize(K);
  A.resize(K, vector<int> ());
  
  for (int i = 0; i < K; i++){
    cin >> d.at(i);
    A.at(i).resize(d.at(i));
    for (int j = 0; j < d.at(i); j++){
      cin >> A.at(i).at(j);
    }
  }
  
  int ans = 0;
  
  for (int x = 1; x <= N; x++){
    bool trick = true;
    for (int i = 0; i < K; i++){
      for (int j = 0; j < d.at(i); j++){
        if( x == A.at(i).at(j)){
          trick = false;
        }
      }
    }
    if(trick){
      ans++;
    }
  }
  
  cout << ans << endl;
  
}
      
    
    

Measured memory_bytes: 3688
n = int(input())
a = list(map(int,input().split()))
c = [0,0,0]
count = 1
for i in range(n):
    match = (a[i]==c[0])+(a[i]==c[1])+(a[i]==c[2])
    if match==0:
        count = 0
        break
    elif match==1 or a[i]==0:
        c[c.index(a[i])] += 1
    else:
        c[c.index(a[i])] += 1
        count = (count*match)%(1e+9+7)
               
if count != 0:
    c = sorted(c,reverse=True)
    while 0 in c:
        c.pop()
    memory = set()
    kinds = 0
    for x in c:
        if not x in memory:
            kinds += 1
    for i in range(3,3-kinds,-1):
        count = (count*i)%(1e+9+7)

print(int(count))

Measured memory_bytes: 20784
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>

int main()
{
  int *A;
  int i, n, q, a, x;
  int head, tail;
  head=0; tail=0;
  fscanf(stdin, "%d", &n);
  A = (int*)malloc(sizeof(int)*n);
  bzero(A, sizeof(int)*n);
  for (i=0; i<n; i++) {
    fscanf(stdin, "%d %d", &q, &a);
    switch (q) {
    case 0:
      fscanf(stdin, "%d", &x);
      if (a==0) {
        head = (head-1+n)%n;
        A[head]=x;
      } else {
        A[tail]=x;
        tail = (tail+1)%n;
      }
      break;
    case 1:
      printf("%d\n", A[(head+a)%n]);
      break;
    case 2:
      if (a==0) {
        head++;
      }else {
        tail--;
      }
    }
  }
  return 0;
}



Measured memory_bytes: 3332
#include<iostream>
using namespace std;
int main(){
    int a, b, c;
    int sum;
    while(1){
        cin >> a >> b >> c;
        sum = a + b;
        if((a == -1) && (b == -1) && (c == -1)){
            break;
            
        }else if(sum >= 80){
            cout << "A" << endl;
        }else if((a == -1) || (b == -1) || (sum < 30)){
            cout << "F" << endl;
        }else if((sum >= 65) && (sum < 80)){
            cout << "B" << endl;
        }else if(((sum >= 50) && (sum < 65)) || ((sum >= 30) && (sum < 50) && (c >= 50))){
            cout << "C" << endl;
        }else if((sum >= 30) && (sum < 50) && (c < 50)){
            cout << "D" << endl;
        }
    }
    
    return 0;
}


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

struct Node {
  int parent;
  vector<int> children;
  int depth;
};

void dfs(vector<Node>& tree, int p, int v) {
  tree[v].parent = p;
  if ( p >= 0 ) tree[v].depth = tree[p].depth+1;
  for ( int c: tree[v].children ) {
    dfs(tree, v, c);    
  }
}

string node_type(Node v) {
  if ( v.parent == -1 ) return "root";
  else if ( v.children.size() == 0 ) return "leaf";
  else return "internal node";
}

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

  vector<Node> tree(n);
  bool used[n] = {0};  
  for ( int i = 0; i < n; i++ ) {
    int id, k;
    cin >> id >> k;
    for ( int j = 0; j < k; j++ ) {
      int c;
      cin >> c;
      used[c] = true;
      tree[id].children.push_back(c);      
    }
  }

  // calc depth
  for ( int i = 0; i < n; i++ ) {
    if ( !used[i] ) {
      dfs(tree, -1, i);
      break;
    }
  }

  for ( int i = 0; i < n; i++ ) {
    Node v = tree[i];
    printf("node %d: parent = %d, depth = %d, ", i, v.parent, v.depth);
    cout << node_type(v) << ", [";
    for ( int j = 0; j < (int)v.children.size(); j++ ) {
      if ( j ) cout << ", ";
      cout << v.children[j];      
    }
    cout << "]\n";    
  }
  
  return 0;
}



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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    string t = "CF";
    for (int i = 0, j = 0; i < n; ++i) {
        if(j < 2 && s[i] == t[j]) j++;
        if(j == 2) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 3588
# -*- coding: utf-8 -*-
"""
Created on Sun Jan 20 21:02:12 2019

@author: owner
"""

s=int(input())
dic={}
ans=0

dic[s]=1
for i in range(2,1000001):
    if s%2==0:
        s//=2
    else:
        s=3*s+1
    if dic.get(s,0)>0:
        ans=i
        break
    else:
        dic[s]=1
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        ll n, y;
        in >> n >> y;
        ll ichi_man = 0;
        ll go_sen = 0;
        ll ichi_sen = 0;
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= n; j++) {
                ll l = 0;
                ll r = n + 1;
                while (l < r) {
                    ichi_sen = (l + r) / 2;
                    if (i + j + ichi_sen == n && 10000 * i + 5000 * j + 1000 * ichi_sen == y) {
                        ichi_man = i;
                        go_sen = j;
                        n = 0;
                        break;
                    }
                    if (10000 * i + 5000 * j + 1000 * ichi_sen < y) {
                        l = ichi_sen + 1;
                    }
                    else {
                        r = ichi_sen;
                    }
                }
            }
        }
        if (n == 0) {
            out << ichi_man << ' ' << go_sen << ' ' << ichi_sen << '\n';
        }
        else {
            out << "-1 -1 -1" << '\n';
        }
    }
};
void solve(std::istream& in, std::ostream& out) {
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<atcoder/all>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) \
  for (ll i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, ) (__VA_ARGS__)  // NOLINT
#define chmax(x, a)  do { x = max(x, a); } while(0)
#define chmin(x, a)  do { x = min(x, a); } while(0)

using namespace std;
using namespace atcoder;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll,ll> PLL;

void solve() {
  ll N, Q;
  cin >> N >> Q;
  dsu u(N+1);
  rep(_, Q) {
    ll t, x, y;
    cin >> t >> x >> y;
    if (t == 0) {
      u.merge(x, y);
    } else {
      cout << u.same(x, y) << endl;
    }
  }
}

int main() {
  //ll T;
  //cin >> T;
  //rep(_,T)
    solve();
  return 0;
}


Measured memory_bytes: 4084
#define MOD_TYPE 1

#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
using multiInt = boost::multiprecision::cpp_int;
*/
/*
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
*/
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
constexpr int INF = (int)1e9;
constexpr ll LINF = (ll)4e18;
constexpr ld PI = acos(-1.0);
constexpr ld EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

inline void init_main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
}
template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}
#pragma endregion

int main()
{
  init_main();

  ll n, k;
  cin >> n >> k;
  if (k % 2 == 1)
  {
    ll cnt = n / k;
    cout << cnt * cnt * cnt << endl;
  }
  else
  {
    ll cnt0 = n / k;
    ll cnt1 = n / k + (n % k >= k / 2);
    ll ans = cnt0 * cnt0 * cnt0 + cnt1 * cnt1 * cnt1;
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  int d[100005];

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

  sort(d,d+n);

  cout<<d[n/2]-d[n/2-1]<<endl;

  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define int long long 
#define MOD 1000000007
using namespace std;

int32_t main()
{
	int a,b,k;
	cin>>a>>b>>k;

	int y=(min(k,a));
	a-=(min(k,a));
	k-=y;
	b-=(min(k,b));

	cout<<a<<" "<<b<<'\n';

}

Measured memory_bytes: 256
n,m = map(int,input().split())       
a = [list(map(int,input().split())) for i in range(n)]
c = [list(map(int,input().split())) for i in range(m)]
for i in a:
  index = 1;
  ans = abs(i[0]-c[0][0])+abs(i[1]-c[0][1])
  for o,j in enumerate(c[1:]):
    ans_ = abs(i[0]-j[0])+abs(i[1]-j[1])
    if ans > ans_:
      ans = ans_
      index = o+2
  print(index)

Measured memory_bytes: 3064
f = lambda: list(map(int,input().split()))
f_ = lambda: [int(x)-1 for x in input().split()]


class UnionFind(object):
    def __init__(self, size):
        self.parent = [i for i in range(size)]
        self.rank = [0 for _ in range(size)]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])

    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.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)


n,k,l = f()
ud = UnionFind(n)
for _ in range(k):
    p,q = f_()
    ud.unite(p,q)
ut = UnionFind(n)
for _ in range(l):
    p,q = f_()
    ut.unite(p,q)

p = [(ud.find(i),ut.find(i)) for i in range(n)]

from collections import Counter
c = Counter(p)
print(*[c[p[i]] for i in range(n)])

Measured memory_bytes: 59024
from collections import Counter
n = int(input())
V = list(map(int, input().split()))

c1 = Counter(V[::2])
c2 = Counter(V[1::2])
# print('c1, c2', c1, c2)

c1_items = sorted(c1.items(), key=lambda x: -x[1])
c2_items = sorted(c2.items(), key=lambda x: -x[1])
c1_max = c1_items[0][1]
c2_max = c2_items[0][1]
c1_second = 0
c2_second = 0

c1_max_group = set()
for key, value in c1_items:
    if value == c1_max:
        c1_max_group.add(key)
    else:
        c1_second = value
        break
c2_max_group = set()
for key, value in c2_items:
    if value == c2_max:
        c2_max_group.add(key)
    else:
        c2_second = value
        break

# print(c1_max_group, c1_max, c1_second)
# print(c2_max_group, c2_max, c2_second)
if len(c1_max_group) == 1 and len(c2_max_group) == 1 and list(
        c1_max_group)[0] in c2_max_group:
    v1 = n - c1_max - c2_second
    v2 = n - c1_second - c2_max
    ans = min(v1, v2)
else:
    ans = n - c1_max - c2_max
print(ans)


Measured memory_bytes: 25536
#include <bits/stdc++.h>
#define lli long long int
#define vec2 vector<vector<lli>> 
#define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FRE freopen("explicit.in","r",stdin);freopen("explicit.out","w",stdout)
#define mp make_pair
#define pll pair <lli,lli>
#define vll vector <lli>
#define pq2 priority_queue<pair<lli,lli>>
#define f first
#define s second
#define pb push_back
#define pf push_front
#define minii LLONG_MAX
#define all(x) x.begin(), x.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define ld long double 
const long double pi = 3.1415926535898;
#define dec greater<lli>()
const lli mod=1000000007;
//const lli mod=100000000;
using namespace std;
lli lcm (lli a, lli b) {return ((a*b)/__gcd(a,b));}
lli modpower (lli a,lli b)
{
    if(b==0) return 1;
    lli c=modpower(a,b/2)%mod;
    if (b%2) return (((a*c)%mod)*c)%mod;
    else return (c*c)%mod;
}
lli power (lli a,lli b)
{
    if(b==0) return 1;
    lli c=power(a,b/2);
    if (b%2) return (a*c*c);
    else return c*c;
}
bool prime (lli k)
{
    if (k==1||k==0) return 0;
    bool flag=1;
    lli a=sqrt(k);
    for (int i=2;i<=a;i++)
    {
        if (k%i==0)
        {flag=0;break;}
    }
    return flag;
}
lli sieve (int n)
{
    bool qrr[n+1];
    for (int i=0;i<=n;i++)
    qrr[i]=1;qrr[0]=0;qrr[1]=0;
    for (int i=2;i*i<=n;i++)
    {
        if (qrr[i]==1)
        {
            for (int j=2*i;j<=n;j+=i)
            {qrr[j]=0;}
        }
    }
    return 0;
}
int main()
{
    fio;
    lli n;
    cin>>n;
    ld a[n+1];
    for (int i=1;i<=n;i++)
    cin>>a[i];
    ld dp[3000]={0};
    dp[0]=1;
    for (int i=1;i<=n;i++)
    {
        for (int j=i;j>0;j--)
        {
            dp[j]=dp[j-1]*a[i]+dp[j]*(1-a[i]);
        }
        dp[0]*=(1-a[i]);
    }
    ld sum=0;
    for (int i=n/2+1;i<=n;i++)
    {
        sum+=dp[i];
    }
    cout<<fixed<<setprecision(12)<<sum;
    return 0;
}

Measured memory_bytes: 3896
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
#import numpy as np



def main():
	k,x=map(int,input().split())
	
	ans="No"
	
	if 500*k>=x:
		ans="Yes"
	
	print(ans)
	
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = 1e9;
long long n, k;
struct abdata {
    int A; long long B;
};
bool cmp(const abdata &aa, const abdata &bb) {
    return aa.A < bb.A;
}

int main() {
    cin >> n >> k;
    vector<abdata> abvec(n);
    for(int i = 0; i < n; ++i) {
        cin >> abvec.at(i).A >> abvec.at(i).B;
    }
    sort(abvec.begin(), abvec.end(), cmp);

    long long sum = 0;
    for(int i = 0; i < n; ++i) {
        sum += abvec.at(i).B;
        if(sum >= k) {
            cout << abvec.at(i).A;
            return 0;
        }
    }
}

Measured memory_bytes: 1792
import java.util.*;

public class Main{
	public static void main(String[] args){
		int i;
		int count =0;
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		for(i=a; i<=b; i++){
		//for(i =a; i<=b; i++){
			if(c%i == 0){
				count++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 17356
n = int(input())
L = list(map(int, input().split()))

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        if L[i] != L[j]:
            for k in range(j + 1, n):
                if not(L[i] == L[k] or L[j] == L[k]):
                    a, b, c = sorted([L[i], L[j], L[k]])
                    if c < a + b:
                        ans += 1
print(ans)

Measured memory_bytes: 9144
N, A, B = map(int, input().split())
S = input()
a = 0
b = 0
for i in range(N):
  if S[i] == 'a' and a+b < A+B:
    a += 1
    print('Yes')
  elif S[i] == 'b' and a+b < A+B and b < B:
    b += 1
    print('Yes')
  else:
    print('No')


Measured memory_bytes: 4016
#include <bits/stdc++.h>
using namespace std;
int n;
int main()
{
    cin>>n;
    int a=0;
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=n;++j)
        {
            for(int k=1;k<=n;++k)
                a+=__gcd(j,__gcd(i,k));
        }
    }
    cout<<a;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

void dfs( string s, int pos );

vector< string > v;
string sample = "AKIHABARA";

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

    string s;
    cin >> s;

    dfs( "", 0 );

    bool flg = false;
    for( int i = 0; i < v.size(); ++i ) {
        if( s == v[i] ) {
            flg = true;
            break;

        }
    }

    if( flg ) cout << "YES";
    else cout << "NO";
    cout << endl;

    return 0;
}

void dfs( string s, int pos )
{
    if( pos == sample.size() ) {
        v.pb( s );

        return;

    }

    if( sample[pos] == 'K' ||
        sample[pos] == 'I' ||
        sample[pos] == 'H' ||
        sample[pos] == 'B' ||
        sample[pos] == 'R' )  dfs( s + sample[pos], pos + 1 );
    else {
        dfs( s + sample[pos], pos + 1 );
        dfs( s, pos + 1 );

    }

    return;

}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define INF 1e9+7
using namespace std;
const int MOD = 1e9 +7;

int main(){
    int N;
    cin >>N;
    double x[11];
    string s[11];
    double ans=0.0;
    rep(i,N){
        cin >>x[i] >>s[i];
        if(s[i] =="JPY") ans +=x[i];
        else ans+= x[i] *380000.0;
    }
    printf("%.10f\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include "stdio.h"

typedef unsigned int uint;

//7A*days+Bdays>=C
uint days_base(uint A, uint B, uint C) {
	return C / (A*7+B);
}

uint calc_days(uint A, uint B, uint C) {
	uint days = days_base(A,B,C);
	while (days*A + (days / 7)*B < C)
		days++;

	return days;
}

int main()
{
	uint A, B, C, days;

	//获取输入
	scanf("%u %u %u", &A, &B, &C);

	days = calc_days(A, B, C);

	//打印输出
	printf("%u\n",days);
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
using namespace std;
char seq[8001];
int orderx[8001],ordery[8001];
int orderx_index=0,ordery_index=0,sumx=0,sumy=0;
bool mycmp(const int& a,const int& b)
{
	return a>b;
}
int main()
{
	char c;
	int countt,x,y,i,countf;
	countt=0;
	countf=0;
	while(c=getchar(),c=='T'||c=='F')
	{
		if(c=='F')
		{
			countf++;
		}
		else if(c=='T')
		{
			if(countt%2==0)
				orderx[orderx_index++]=countf;
			else
				ordery[ordery_index++]=countf;
			countt++;
			countf=0;
		}                          
	}	
	if(countt%2==0)
		orderx[orderx_index++]=countf;
	else
		ordery[ordery_index++]=countf;	
	scanf("%d%d",&x,&y);
	sort(orderx+1,orderx+orderx_index,mycmp);	
	sort(ordery,ordery+ordery_index,mycmp);
	sumx+=orderx[0];
	for(i=1;i<orderx_index;i++)
	{
		if(sumx<=x)
			sumx+=orderx[i];
		else
			sumx-=orderx[i];
	}
	for(i=0;i<ordery_index;i++)
	{
		if(sumy<=y)
			sumy+=ordery[i];
		else
			sumy-=ordery[i];
	}
	if(sumx==x&&sumy==y)
		printf("Yes");
	else
		printf("No");
	return 0;
}

Measured memory_bytes: 256
Scanf.scanf "%d %d" (fun n k ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in

    let count m =
        Array.fold_left (fun acc b -> acc + (b + m - 1) / m - 1) 0 a
    in

    let rec loop l r =
        if l = r then l else
            let m = (l + r) / 2 in
            if count m <= k then loop l m else loop (m + 1) r
    in
    loop 1 1000000001 |> Printf.printf "%d\n"
)

Measured memory_bytes: 7524
/**
 *   Author: Praveen Ojha
 *   Created: 14 April 2019
 *   Time: 07:13:48
**/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define inf 1e18+5
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int,int> > 
#define vvi vector<vector<int> >
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." <<endl;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int,int> pii;
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////

int32_t main(){__
	string s;
	cin>>s;
	int n=s.length();
	int ans=0;
	for(int i=1;i<n;i++){
		if(s[i]==s[i-1]){
			if(s[i]=='0'){
				if(i-2>=0){
					if(s[i-2]=='0')
						s[i-1]='1';
					else
						s[i]='1';
				}
				else
					s[i]='1';
			}
			else if(s[i]=='1'){
				if(i-2>=0){
					if(s[i-2]=='1')
						s[i-1]='0';
					else
						s[i]='0';
				}
				else
					s[i]='0';
			}
		ans++;
		}
	}
	cout<<ans<<"\n";
return 0;
}

Measured memory_bytes: 512
use std::io::prelude::*;
use std::str::FromStr;
pub struct Scanner<R: Read>(R);
impl<R: Read> Scanner<R> {
    pub fn new(reader: R) -> Self {
        Self(reader)
    }
    pub fn read<T: FromStr>(&mut self) -> T {
        let token = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| (b as char).is_whitespace())
            .take_while(|&b| !(b as char).is_whitespace())
            .collect::<Vec<u8>>();
        unsafe { std::str::from_utf8_unchecked(token.as_slice()) }
            .parse()
            .ok()
            .expect("Can't parse it.")
    }
    pub fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
fn main() {
    let (stdin, stdout) = (std::io::stdin(), std::io::stdout());
    let mut sc = Scanner::new(stdin.lock());
    let mut out = std::io::BufWriter::new(stdout.lock());
    solve(&mut sc, &mut out);
    out.flush().ok().unwrap();
}
fn solve(sc: &mut Scanner<std::io::StdinLock>, out: &mut std::io::BufWriter<std::io::StdoutLock>) {
    let (n, k, c): (usize, usize, usize) = (sc.read(), sc.read(), sc.read());
    let s = sc.chars();

    let mut l = vec![0; k + 1];
    let mut pos: usize = 1;
    for i in 1..=k {
        while s[pos - 1] == 'x' {
            pos += 1;
        }
        l[i] = pos;
        pos += c + 1;
    }

    let mut r = vec![0; k + 1];
    let mut pos: usize = n;
    for i in (1..=k).rev() {
        while s[pos - 1] == 'x' {
            pos -= 1;
        }
        r[i] = pos;
        if i > 1 {
            pos -= c + 1;
        }
    }

    for i in 1..=k {
        if l[i] == r[i] {
            let _ = write!(out, "{}\n", l[i]);
        }
    }
}


Measured memory_bytes: 5936
#include <bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9

typedef long long ll;

using namespace std;

const ll inf = 1e18;
const ll mod = 1e9+7;
const int N = 1e5+5;

int main()

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

    ll a, b;

    cin >> a >> b;

    ll ans = a*b/__gcd(a, b);

    cout << ans;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN=1e6+69;
const int mod = 1e9+7;
string s;
int n,m,k;
int a[MAXN],sum[MAXN];
int ans;
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
    int sc=m;
    int cnt=0;
    while(n>0){
        n/=m;
        cnt++;
    }
    cout<<cnt;
}


Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
const int BUF = 100005;


int nNode;
pair<int, int> edge[BUF];
vector<int> adj[BUF];

void read() {
    for (int i = 0; i < BUF; ++i) adj[i].clear();
    
    cin >> nNode;
    for (int i = 0; i < nNode - 1; ++i) {
        int s, t;
        cin >> s >> t;
        --s, --t;
        adj[s].push_back(t);
        adj[t].push_back(s);
        edge[i] = make_pair(s, t);
    }
}


void dfs(int cur, int pre, map<pair<int, int>, int> &edge2color, set<int> node2used[BUF]) {
    int color = 0;
    
    for (int i = 0; i < adj[cur].size(); ++i) {
        int nex = adj[cur][i];
        if (nex == pre) continue;

        while (node2used[cur].count(color)) ++color;

        node2used[cur].insert(color);
        node2used[nex].insert(color);

        edge2color[make_pair(cur, nex)] = color;
        edge2color[make_pair(nex, cur)] = color;
        
        dfs(nex, cur, edge2color, node2used);
    }
}


void work() {
    map<pair<int, int>, int> edge2color;
    set<int> node2used[BUF];

    dfs(0, -1, edge2color, node2used);
    
    int maxV = 0;
    for (int i = 0; i < nNode; ++i) maxV = max(maxV, (int)adj[i].size());
    
    cout << maxV << endl;
    for (int i = 0; i < nNode - 1; ++i) {
        cout << edge2color[make_pair(edge[i].first, edge[i].second)] + 1 << endl;
    }
}


int main() {
    read();
    work();
    return 0;
}


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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

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

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 512
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll A,B,K;
int main(){
    cin>>K>>A>>B;
    for(ll i=A;i<=B;i++){
        if(i%K==0){
            cout<<"OK"<<endl;
            return 0;
        }
    }
    cout<<"NG"<<endl;

    return 0;
}

Measured memory_bytes: 3600