akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main() {
    int h, w;
    while(cin >> h  >> w){
        if(h==0 && w==0) break;
        for(int i=0; i<h; i++){
            for(int j=0; j<w; j++){
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1152
import collections

h = int(input().strip())

m = collections.defaultdict(int)
m[h] = 1

count = 0
while 0 < len(m.keys()):
    nm = collections.defaultdict(int)
    for hp, num in m.items():
        if 1 < hp:
            nhp = hp // 2
            nm[nhp] += 2 * num
            count += num
        else:
            count += num
    m = nm

print(count)


Measured memory_bytes: 3316
n, k, q = map(int, input().split())
scores = {i: 0 for i in range(n)}
for _ in range(q):
    i = int(input()) - 1
    scores[i] += 1
for i in range(n):
    print('Yes' if k - (q - scores[i]) > 0 else 'No')

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

const int _ = 2e5 + 7 , MOD = 1e9 + 7;
char str[_]; int N , M;

int main(){
	scanf("%d %d %s" , &N , &M , str + 1);
	if(str[1] == 'B') for(int i = 1 ; i <= M ; ++i) str[i] = 'B' + 'R' - str[i];
	int limit = 1e9 , pre = 1;
	for(int i = 2 ; i <= M ; ++i)
		if(str[i] == 'B'){
			if(!pre) continue;
			if(pre == 1) limit = min(limit , (i - pre) / 2 * 2 + 1);
			if((i - pre) & 1) limit = min(limit , i - pre);
			pre = 0;
		}
		else if(!pre) pre = i;
	int ans = 0;
	if(limit == 1e9){
		static long long dp[_][2][2]; dp[2][0][0] = dp[2][1][0] = dp[2][0][1] = 1;
		for(int i = 3 ; i <= N ; ++i)
			for(int j = 0 ; j < 2 ; ++j){dp[i][j][0] = (dp[i - 1][j][0] + dp[i - 1][j][1]) % MOD; dp[i][j][1] = dp[i - 1][j][0];}
		ans = (dp[N][0][0] + dp[N][0][1] + dp[N][1][0]) % MOD;
	}
	else if(!(N & 1)){
		static int dp[_]; dp[1] = 1;
		if(limit >= N - 1) ans = N;
		for(int i = 3 ; i <= N ; i += 2){
			int val = (MOD + dp[i - 2] - dp[max(0 , i - limit - 3)]) % MOD;
			if(N - i <= limit) ans = (ans + 1ll * val * (N - i + 1)) % MOD;
			dp[i] = (dp[i - 2] + val) % MOD;
		}
	}
	cout << ans << endl; return 0;
}

Measured memory_bytes: 6656
def main():
    h, w, n, *a = map(int, open(0).read().split())
    s = sum([[i + 1] * a[i] for i in range(n)], [])

    for i in range(h):
        print(' '.join(map(str, s[i * w:(i + 1) * w])) if i % 2 == 0 else ' '.join(map(str, s[i * w:(i + 1) * w][::-1])))


if __name__ == '__main__':
    main()


Measured memory_bytes: 4716
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <cassert>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr ll INF = 3000000000000000000;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];
    
    sort(ALL(A));
    reverse(ALL(A));
    ll ans = A[0];
    ll k = N - 2;
    for (int i = 1; i < N; ++i) {
        if (k == 0) {
            continue;
        } else if (k == 1) {
            k -= 1;
            ans += A[i];
        } else {
            k -= 2;
            ans += A[i] * 2;
        }
    }
    
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 4836
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int n,m,l;
int d[101][101];
int P[101];
int K[101];
const int INF=1000000000;
const int MAX_V = 301;
int sp,gp;

struct edge{
	int to,cap,rev;
};

vector<edge> G[MAX_V];
bool used[MAX_V];

void add_edge(int from,int to,int cap){
	edge e;
	e.to = to;
	e.cap = cap;
	e.rev = G[to].size();
	G[from].push_back(e);
	e.to = from;
	e.cap = 0;
	e.rev = G[from].size()-1;
	G[to].push_back(e);
}

// ÁpXðTõ
int dfs(int v,int t,int f){
	if(v == t)
		return f;
	used[v] = true;
	for(int i = 0; i < G[v].size(); i++){
		edge &e = G[v][i];
		if(!used[e.to] && e.cap > 0){
			int d = dfs(e.to,t,min(f,e.cap));
			if(d > 0){
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s,int t){
	int flow = 0;
	while(1){
		fill(used,used+MAX_V,false);
		int f = dfs(s,t,INF);
		if(f == 0)return flow;
		else flow += f;
	}
	return 0;
}
void warshallFloyd(){
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			for(int k=0;k<n;k++)
				d[j][k]=min(d[j][k],d[j][i]+d[i][k]);
}

int main(){

	while(cin>>n>>m>>l){
		for(int i=0;i<MAX_V;i++)G[i].clear();
		for(int i=0;i<101;i++)for(int j=0;j<101;j++)
			if(i==j)d[i][j]=0;
			else d[i][j]=INF;
		for(int i=0;i<m;i++){
			int a,b,D;
			cin>>a>>b>>D;
			a--;b--;
			d[a][b]=d[b][a]=D;
		}
		warshallFloyd();
		for(int i=0;i<n;i++)cin>>P[i];
		for(int i=0;i<n;i++)cin>>K[i];
		sp=2*n;
		gp=2*n+1;
		// ÅZ£ªLæè¬³¢ÌàÌðGbWÅÂÈ®
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				if(d[i][j]<l)add_edge(i,j+n,INF);
		// start©ç
		for(int i=0;i<n;i++)add_edge(sp,i,P[i]);
		// goalÖ
		for(int i=0;i<n;i++)add_edge(i+n,gp,K[i]);
		int res=max_flow(sp,gp);
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 1272
import sys
input = sys.stdin.readline

N,M,X,Y = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))

if max(x) >= min(y):
	print("War")
	exit()

z = [i+1 for i in range(max(x),min(y))]

for Z in z:
	if X < Z <= Y:
		print("No War")
		exit()

print("War")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define FORD(x,y,z) for(int x=y;x>=z;x--)
#define MSET(x,y) memset(x,y,sizeof(x))
#define FOR(x,y) for(__typeof(y.begin()) x=y.begin();x!=y.end();x++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 
void RI(){}
template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}
using namespace std;
typedef long long LL;
int main()
{
	int ans=0;
	LL n;
	scanf("%lld", &n);
	while(n) n/=2, ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1172
#include <iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
int ans =0;
string S;
cin>>S;
if(S.at(0)=='1'){
    ans++;
}
if(S[1]=='1'){
    ans++;
}
if(S[2]=='1'){
    ans++;
}
cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
	int N;
	cin>>N;
	int i;
	long long preT;
	long long preA;
	cin>>preT>>preA;
	long long currT;
	long long currA;
	for (i=1;i<N;i++){
		cin>>currT>>currA;
		long long n,n1=1,n2=1;
		if (preT>currT){
			n1=preT/currT;
			if (preT%currT>0){
				n1++;
			}
		}
		if (preA>currA){
			n2=preA/currA;
			if (preA%currA>0){
				n2++;
			}
		}
		n=max(n1,n2);
		currT = currT*n;
		currA = currA*n;
		preT = currT;
		preA = currA;
	}
	cout<<preT+preA<<endl;
	return 0;
}

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

int main()
{
	long long int n;
	cin >> n;
	bitset<32> bit(n);
	
	cout << bit << endl;
	cout << (~bit) << endl;
	cout << (bit << 1) << endl;
	cout << (bit >> 1) << endl;
	return 0;
}


Measured memory_bytes: 3160
def q1():
    """ A - Duplex Printing
    高橋君は、全Nページから成る書類を両面印刷します。
    両面印刷では、1枚の紙に2ページ分のデータを印刷することが出来ます。
    最小で何枚の紙が必要か求めてください。
    """
    N = int(input())
    d,m = divmod(N,2)
    print(d+m)


if __name__ == '__main__':
    q1()

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

int main(){

int n; cin >> n;

vector<int> x(n);
rep(i, n) cin >> x.at(i);

rep(i, n){
    cout << x.at(n-(1+i));
    if (i != n-1) cout << ' ';
    }
cout << endl;

}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int x, y, z;
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    cin >> x >> y;
    z += y - x + 1;
  }
  cout << z << endl;
  
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define repr(i,a,n) for(ll i = n-1;i >= a;i--)
#define LINF (ll)1e17
#define INF 1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second
#define setprecision(d) cout << fixed << setprecision(d);

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
	
}

ll lcm(ll a,ll b){
	return a * b / gcd(a,b);
}


signed main(){

	string s;
	cin >> s;
	ll n = s.size()+1,ans = 0;
	ll a[n] = {};

	rep(i,0,n)a[i] = LINF;

	if(s[0] == '<') a[0] = 0;
	if(s[s.size()-1] == '>') a[n-1] = 0;

	rep(i,0,s.size()-1){
		if(s[i] == '>' && s[i+1] == '<') a[i+1] = 0;
		else if(s[i] == '>' && s[i+1] == '>' && a[i] != LINF) a[i+1] = a[i]-1;
		else if(s[i] == '<' && s[i+1] == '<' && a[i] != LINF) a[i+1] = a[i]+1;
	}

	repr(i,0,s.size()-1){
		if(s[i] == '>' && s[i+1] == '>' && a[i+2] != LINF) a[i+1] = a[i+2]+1;
		else if(s[i] == '<' && s[i+1] == '<' && a[i+2] != LINF) a[i+1] = a[i+2]-1;
	}

	rep(i,0,s.size()-1){
		if(s[i] == '<' && s[i+1] == '>') a[i+1] = max(a[i]+1,a[i+2]+1);
	}

	if(s[0] == '>') a[0] = a[1]+1;
	if(s[s.size()-1] == '<') a[n-1] = a[n-2]+1;

	rep(i,0,n)ans += a[i];

	cout << ans << endl;


	//rep(i,0,n)cout << a[i] << endl;

    return 0;
}

Measured memory_bytes: 4740
N=int(input())
A=list(map(int,input().split()))
lis=[]
flag=1

for i in A:
  if i%2==0:
    lis.append(i)
    
for j in lis:
  if j%3!=0 and j%5!=0:
    flag=0
print("DENIED"if flag==0 else "APPROVED")

Measured memory_bytes: 3060
D, G = map(int, input().split())
pc = [list(map(int, input().split())) for i in range(D)]
ans = 100 ** 11
for i in range(2**D):
    score = 0
    count = 0
    bit = format(i, 'b').zfill(D)
    for j, b in enumerate(bit):
        if int(b):
            score += pc[j][0] * (100 * (j+1)) + pc[j][1]
            count += pc[j][0]
    if score < G:
      	for j in range(D-1, -1, -1):
            if not int(bit[j]):
                for k in range(pc[j][0]-1):
                    if score >= G:
                        break
                    score += 100 * (j+1)
                    count += 1
    
    if score >= G:
	    ans = min(ans, count)
    
print(ans)



Measured memory_bytes: 3064
#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

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

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

ll a[100010];
ll d[100010];

void solv() {
	
	int p, q, r;
	cin >> p >> q >> r;
	cout << min(p + q, min(q + r, p + r)) << endl;
	

}

int main() {
	//COMinit();
	solv();

	return 0;
}
 

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(void) {

	float x1,x2,x3,y1,y2,y3,xp,yp,ax,ay,bx,by,cx,cy,a,b;

	while(scanf("%f %f %f %f %f %f %f %f",&x1,&y1,&x2,&y2,&x3,&y3,&xp,&yp)!=EOF){

		ax=x2-x1; ay=y2-y1;
		bx=x3-x1; by=y3-y1;
		cx=xp-x1; cy=yp-y1;

		if(by!=0){
			a=(cx*by-cy*bx)/(ax*by-ay*bx);
			b=(cy-a*ay)/by;
		}
		else{
			a=cy/ay;
			b=(cx-a*ax)/bx;
		}

		if(a>=0 && b>=0 && a+b<=1)printf("YES\n");
		else printf("NO\n");
	}

	return 0;
}

Measured memory_bytes: 608
#include <stdio.h>
#define MAX 100000
int main()
{
	int n,num=0;
	int a[MAX];
	int i;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	  scanf("%d",&a[i]);
	  i=1;
	  while(1)
	  {
  		num++;
  		if(a[i]==2)
  		{
		  	printf("%d",num);
		  	break;
		  }
		  i=a[i];
		  if(num>n)
		  {
  			printf("-1\n");
  			break;
  		}
  	}
	
	

}

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

int main() {
  int a, b;
  double c;
  cin >> a >> b;
  
  c = (a + b) / 2.0;
  
  if (c == (a + b) / 2) {
    cout << (a + b) / 2 << endl;
  }
  else {
    cout << (a + b) / 2 + 1 << endl;
  }
}

Measured memory_bytes: 256
# instead of AVLTree
class BITbisect():
    def __init__(self, max):
        self.max = max
        self.data = [0]*(self.max+1)
    
    # 0からiまでの区間和
    # 立っているビットを下から処理
    def query_sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s

    # i番目の要素にxを足す
    # 覆ってる区間すべてに足す
    def add(self, i, x):
        while i <= self.max:
            self.data[i] += x
            i += i & -i

    def insert(self, x):
        self.add(x, 1)

    def delete(self, x):
        self.add(x, -1)

    def count(self, x):
        return self.query_sum(x) - self.query_sum(x-1)
    
    def length(self):
        return self.query_sum(self.max)
    
    # 下からc番目(0-indexed)の数
    # O(log(N))
    def search(self, c):
        c += 1
        s = 0
        ind = 0
        l = self.max.bit_length()
        for i in reversed(range(l)):
            if ind + (1<<i) <= self.max:
                if s + self.data[ind+(1<<i)] < c:
                    s += self.data[ind+(1<<i)]
                    ind += (1<<i)
        if ind == self.max:
            return False
        return ind + 1
    
    def bisect_right(self, x):
        return self.query_sum(x)

    def bisect_left(self, x):
        if x == 1:
            return 0
        return self.query_sum(x-1)

    # listみたいに表示
    def display(self):
        print('inside BIT:', end=' ')
        for x in range(1, self.max+1):
            if self.count(x):
                c = self.count(x)
                for _ in range(c):
                    print(x, end=' ')
        print()


import sys
input = sys.stdin.readline

N, K = map(int, input().split())
A = [int(input()) for _ in range(N)]
ans = 0
B = []
b = 0
for a in A:
    b += a-K
    B.append(b)
    if b >= 0:
        ans += 1

ind_to_co = [0] + sorted(B)
co_to_ind = {}
for i in range(N):
    co_to_ind[ind_to_co[i+1]] = i+1

bit = BITbisect(N)
for b in B:
    bit.insert(co_to_ind[b])

for b in B:
    ib = co_to_ind[b]
    bit.delete(ib)
    ans += bit.length() - bit.bisect_left(ib)

print(ans)

Measured memory_bytes: 82208
#include <bits/stdc++.h>
typedef long long int ll;
#define rep(i,n) for (int i = 0; i< (n); i++)
#define Rep(i,n,m) for (int i = (n); i< (m); i++)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
using namespace std;



int main() {
    ll n, sumr=0, sumg=0,sumb=0, all = 0;
    string s;
    
    cin>>n;
    cin>>s;
    
    vector<ll> r;
    vector<ll> g;
    vector<ll> b;
    
    vector<ll> banB;
    vector<ll> banR;
    vector<ll> banG;
    
    rep(i, n){
        if(s[i] == 'R'){
            sumr+=1;
            r.push_back(i+1);
        }
        else if(s[i] == 'G'){
            sumg+=1;
            g.push_back(i+1);
        }
        else{
            sumb+=1;
            b.push_back(i+1);
        }
    }
    
    all = sumr * sumg * sumb;
    
    //b最大
    for (int i = 0; i<r.size(); i++) {
        for (int j = 0; j<g.size(); j++){
            if(r[i]<g[j]){
                if(n>=2*g[j]-r[i]) banB.push_back(2*g[j]-r[i]);
            }
            else{
                if(n>=2*r[i]-g[j]) banB.push_back(2*r[i]-g[j]);
            }
        }
    }
    
    //r最大
    for (int i = 0; i<g.size(); i++) {
        for (int j = 0; j<b.size(); j++){
            if(g[i]<b[j]){
                if(n>=2*b[j]-g[i]) banR.push_back(2*b[j]-g[i]);
            }
            else{
                if(n>=2*g[i]-b[j]) banR.push_back(2*g[i]-b[j]);
            }
        }
    }
    
    //g最大
    for (int i = 0; i<b.size(); i++) {
        for (int j = 0; j<r.size(); j++){
            if(b[i]<r[j]){
                if(n>=2*r[j]-b[i]) banG.push_back(2*r[j]-b[i]);
            }
            else{
                if(n>=2*b[i]-r[j]) banG.push_back(2*b[i]-r[j]);
            }
        }
    }
    
    
    for(int i = 0; i<banR.size();i++){
        for(int j = 0; j<r.size(); j++){
            if(banR[i] == r[j]){
                all = all-1;
                break;
            }
            if(banR[i]<r[j]) break;
        }
    }
    
    for(int i = 0; i<banG.size();i++){
        for(int j = 0; j<g.size(); j++){
            if(banG[i] == g[j]){
                all = all-1;
                break;
            }
            if(banG[i]<g[j]) break;
        }
    }
    
    for(int i = 0; i<banB.size();i++){
        for(int j = 0; j<b.size(); j++){
            if(banB[i] == b[j]){
                all = all-1;
                break;
            }
            if(banB[i]<b[j]) break;
        }
    }
    
    cout<<all<<endl;
    
    return 0;
}


Measured memory_bytes: 29372
#include<iostream>
#include<map>
#include<algorithm>
#include<cassert>
#include<vector>
#include<cstring>
using namespace std;

int dp[1000], catsum[20010];
vector<pair< int, int > > cats;
vector<int> foods;
int N,M,lmost;

bool isable(int mid) {
    memset(dp, -1, sizeof(dp));

    for(int i=M-1; i>=0; --i) {
        if(i == M-1) {
            dp[i] = 0;
            continue;
        }
        int ret = 1<<29;
        for(int j=i+1; j<M; ++j) {
            int right = catsum[foods[j]] - catsum[(foods[i]+foods[j])/2];;
            int left = catsum[(foods[i]+foods[j])/2] - catsum[foods[i]];

            if(right + dp[j] <= mid) ret = min(left, ret);
        }
        dp[i] = ret;
    }
    if(dp[0] + catsum[foods[0]] <= mid) return true;
    return false;
}

int main() {
    int x,y,c,totalcats = 0;
    while(cin>>N>>M, N|M) {

        memset(catsum, 0, sizeof(catsum));
        foods.clear();
        cats.clear();
        totalcats = 0;

        for(int i=0; i<N; ++i) {
            cin>>x>>y>>c;
            x += 10000;
            totalcats += c;
            cats.push_back(make_pair(x,c));
        }

        for(int i=0; i<M; ++i) {
            cin>>c;
            foods.push_back(c+10000);
        }

        if(M == 1) {
            cout<<totalcats<<endl;
            continue;
        }

        sort(cats.begin(), cats.end());
        sort(foods.begin(), foods.end());

        lmost = 0;
        for(int i=0; i<N; ++i) {

            if(cats[i].first <= foods[0]) {
                cats[i].first = foods[0];
                lmost += cats[i].second;
            }
            if(cats[i].first >= foods[M-1]) cats[i].first = foods[M-1];
            catsum[cats[i].first] += cats[i].second;
        }

        int ss = 0;
        for(int i=0; i<20010; ++i) {
            ss += catsum[i];
            catsum[i] = ss;
        }

        int low = -1,hi = totalcats;
        while(low+1<hi) {
            int mid = (low+hi)/2;
            if(isable(mid)) hi = mid;
            else low = mid;
        }
        cout<<hi<<endl;
    }
}

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

int main() {
   int N, K;
   cin >> N >> K;
   if( N % K == 0 ) cout << 0 << endl;
   else cout << 1 << endl;
}

Measured memory_bytes: 3588
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
#define pb push_back
int main()
{
    int h, w;
    cin >> h >> w;
    int n;
    cin >> n;
    vi a(n);
    rep(i, n)
    {
        cin >> a[i];
    }
    int d = 1;
    vvi c(h, vi(w));
    int i = 0;
    int j = 0;
    int col = 1;
    int hw = h * w;
    while (hw--)
    {
        while (a[col - 1] == 0)
        {
            col++;
        }
        c[j][i] = col;
        a[col - 1]--;
        if ((i == 0 && d < 0) || (i == w - 1 && d > 0))
        {
            j++;
            d = -d;
            i = i - d;
        }
        i = i + d;
    }
    rep(y, h)
    {
        rep(x, w - 1)
        {
            cout << c[y][x] << " ";
        }
        cout << c[y][w-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 384
N = int(input())
cnt = 0
res =[]
for i in range(N):
    D1, D2 = map(int, input().split())
    if D1 == D2:
        cnt += 1
        res.append(cnt)
    else:
        cnt = 0
        res.append(cnt)
if max(res) >= 3:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9180
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdio>
#include <sstream>
#include <cassert>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <random>
#include <chrono>
#include <ctime>

using namespace std;

#define en '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) int((x).size())

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9 + 7;
const ll INFLL = 1e18;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int MAX_SIZE = 5e5;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

bool IS_ONE_TEST = 1;
ld START_TIME, TIME;

void fast_in_out() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

void solve() {
    int x;
    cin >> x;
    int cur = 7;
    for (int i = 0; i < 10 * x; ++i) {
        if (cur % x == 0) {
            cout << i + 1 << en;
            return;
        }
        cur = cur * 10 + 7;
        cur %= x;
    }
    cout << -1 << en;
}

int main() {
    START_TIME = clock();
    fast_in_out();
    int TESTS = 1;
    if (!IS_ONE_TEST) cin >> TESTS;
    while (TESTS--) { solve(); }
#ifdef __APPLE__
    TIME = (clock() - START_TIME) / CLOCKS_PER_SEC;
    cerr << en << TIME * 1000 << " ms." << en;
#endif
    return 0;
}

/*
     ▄▀▀▀▄
▄███▀░◐░░░▌
    ▌░░░░░▐
    ▐░░░░░▐
    ▌░░░░░▐▄▄
    ▌░░░░▄▀▒▒▀▀▀▀▄
   ▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
   ▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
    ▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
      ▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
           ▌▌░▌▌
           ▌▌░▌▌
         ▄▄▌▌▄▌▌        */


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


int main() {

    int N;
    cin >> N;
    vector<int> A(N+1), B(N);
    forn(i, N + 1) cin >> A[i];
    forn(i, N) cin >> B[i];
    ll cnt = 0;
    forn(i, N) {
        if (B[i] <= A[i]) {
            cnt += B[i];
        } else if (B[i] <= A[i] + A[i+1]) {
            cnt += B[i];
            A[i+1] = A[i] + A[i+1] - B[i];
        } else {
            cnt += A[i] + A[i+1];
            A[i+1] = 0;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1024
import sys

ABCD = input()
for n in range(2 ** (len(ABCD) - 1)):
    value = ""
    for i in range(len(ABCD) - 1):
        value += ABCD[i]
        if n & (2 ** i) != 0:
            value += "+"
        else:
            value += "-"
    value += ABCD[-1]
    if eval(value) == 7:
        print(value + "=7")
        sys.exit()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vpii = vector<pair<int,int>>;
using vpll = vector<pair<ll,ll>>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int) n;i++)
#define rep1(i,m,n) for(int i=(int) m;i<(int) n;i++)
#define fix(n) cout << fixed << setprecision((int)n)

void absll(ll &x) {
    if(x>=0) return ;
    else x=-x; return;
}

template<class T> inline bool chmax(T &a, T b) {
    if(a<b) {
        a=b; return 1;
    } 
    return 0;
}

template<class T> inline bool chmin(T &a, T b) {
    if(a>b) {
        a=b; return 1;
    } 
    return 0;
}

const ll INF = 1LL << 60;

int N;

//DPテーブル
vector<ll> dp(100010);

int main() {
    int a,b,c,d,k;
    cin>>a>>b>>c>>d>>k;
    int ans;
    ans=60*c+d-60*a-b-k;
    cout<<ans<<endl;
    
}

Measured memory_bytes: 3904
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include<functional>
#include<queue>
#include<regex>
#include<time.h>

using namespace std;


#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl

#define Tof(x) (x) ? Yes : No
#define TOF(x) (x) ? YES : NO
#define tof(x) (x) ? yes : no

using ll = long long;

//constexpr ll MOD = 1000000007;
constexpr ll INF = 1050000000;


/*vectorの要素を全部確認するやつだよ。普通に拡張for文したほうがいいよ。

for (vector<int>::iterator itr = ans.begin(); itr != ans.end(); ++itr) {
	cout << *itr << " ";
}

*/


/*for文でx,yを上下左右確認するやつだよ。正直使いづらいよ。

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


for (int i = 0; i < 4; i++) {
	int ny = y + dy[i];
	int nx = x + dx[i];
}

*/


/*繰り返し二乗法だよ。modもとってくれるよ。n^kをmodで割った余りでやってくれるよ。

ll POW_MOD(ll n, ll k, ll mod) {
	ll r = 1;

	for (; k > 0; k >>= 1) {
		if (k & 1) {
			r = (r * n) % mod;
		}
		n = (n * n) % mod;
	}
	return r;
}

*/


/*実行開始からの経過時間を表すよ。

while (clock() < 1900000) {  }

*/


/*まだ使えないテクニックのメモだよ。

for (int bit = 0; bit < (1<<n); ++bit)//bit全探索用のfor文だよ

*/


/*2重for文書くのめんどくなった時用だよ。

for (int i = 0; i < h; ++i) {
	for (int j = 0; j < w; ++j) {

	}
}

*/

void saiki(string s,int *ans, int a,int n) {

	if (s.size() > a) { return; }

	if (s.find('7') != -1 && s.find('5') != -1 && s.find('3') != -1 && stoi(s) <= n) { (*ans)++; }

	saiki(s + '3', ans, a, n);
	saiki(s + '5', ans, a, n);
	saiki(s + '7', ans, a, n);
}


int main() {
	int n; cin >> n;
	string s = "";
	int ans = 0;
	int keta = 0;
	int f = n;

	while (f) {
		keta++;
		f /= 10;
	}

	saiki(s, &ans, keta, n);

	cout << ans << endl;

}



Measured memory_bytes: 256
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> a >> b;
  Cout(a * b);
  return 0;
}

Measured memory_bytes: 3656
A = int(input())
B = int(input())
C = int(input())
X = int(input())

count = 0

for i in range(A + 1):
    for j in range(B + 1):
        for k in range(C + 1):
            if ((500 * i) + (100 * j) + (50 * k)) == X:
                count += 1
print(count)

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

int main(){
    double pai=3.141592653589;
    int n;
    scanf("%d",&n);
    for(int i=3;i<=n;i++){
        int x=i;
        if(i%3==0){
            printf(" %d",i);
        }else{
            do{
                if(x%10==3){
                    printf(" %d",i);
                    break;
                }
                x/=10;
            }
            while(x);
        }
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 3232
#include<iostream>
#include<string>
using namespace std;
typedef pair<long long, long long> Complex;

#define MAX 10000

Complex expression();
Complex term();
Complex factor();
bool overflow;
string expp;
int p;

void check(Complex v){
  if( v.first > MAX || v.first < MAX*(-1) )  overflow = true;
  if( v.second > MAX || v.second < MAX*(-1) )  overflow = true;
}

Complex expression(){
    Complex value = term();
    while( expp[p] == '+' || expp[p] == '-' ){
	if ( expp[p] == '+' ) { 
	  p++; 
	  Complex t = term();
	  value.first += t.first;
	  value.second += t.second;
	  check(value);
	} else { 
	  p++; 
	  Complex t = term();
	  value.first -= t.first;
	  value.second -= t.second;
	  check(value);
	}
    }
    return value;
}

Complex term(){
    Complex value = factor();
    while( expp[p] == '*' ){
      p++; 
      Complex f = factor();
      Complex v = value;
      value.first = v.first*f.first - v.second*f.second;
      value.second = v.first*f.second + v.second*f.first;
      check(value);
    }
    return value;
}

Complex factor(){
  Complex value;
  value.first = value.second = 0;
    if ( expp[p] == '(' ){
	p++; value = expression(); p++;
    } else {
      if ( expp[p] == 'i' ){
	p++;
	value.first = 0;
	value.second = 1;
      } else {
	while( isdigit(expp[p]) ) { 
	  value.first = value.first*10 + expp[p] - '0'; p++;
	  check(value);
	}
      }
    }
    return value;
}

void output(Complex c){
  if ( c.first == 0 && c.second == 0 ) {
    cout << 0; return;
  } 
  if ( c.first != 0 ) cout << c.first;
  if ( c.second == 0 ) return;
  if ( c.first != 0 && c.second > 0 ) cout << "+";
  cout << c.second << "i";
}

int main(){
  while( cin >> expp ){
    p = 0;
    overflow = false;
    Complex ans = expression();
    if ( overflow ) cout << "overflow" << endl;
    else {
      output(ans);
      cout << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define pb push_back
#define int long long 
#define pii pair<int,int>
#define ub upper_bound
#define lb lower_bound
#define all(x) x.begin(),x.end()
#define ld long double
#define fast  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
signed main(){
    fast;
    int a,b;
    cin>>a>>b;
    cout<<(a*b);
}

Measured memory_bytes: 3600
fn get_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().to_string()
}

fn reads<T>() -> Vec<T>
    where
        T: std::str::FromStr,
        <T as std::str::FromStr>::Err: std::fmt::Debug {
    get_line().split(' ').map(|x| x.parse().unwrap()).collect()
}

use std::cmp;

fn main() {
    let rcn = reads();

    let mut xs: Vec<(usize, usize, bool)> = vec![];

    let convf = |&x, &y| {
        if x == 0 {
            Some(2 * (rcn[0] + rcn[1]) - y)
        }
        else if x == rcn[0] {
            Some(x + y)
        }
        else if y == 0 {
            Some(x)
        }
        else if y == rcn[1] {
            Some(rcn[0] * 2 + y - x)
        }
        else {
            None
        }
    };

    for i in 0..rcn[2] {
        let xys = reads();

        let vm1 = convf(&xys[0], &xys[1]);
        let vm2 = convf(&xys[2], &xys[3]);

        if let (Some(v1), Some(v2)) = (vm1, vm2) {
            xs.push((cmp::min(v1, v2), i, true));
            xs.push((cmp::max(v1, v2), i, false));
        }
    }

    xs.sort();

    let mut s = vec![];

    let mut res = true;

    for (_, i, b) in xs {
        if b {
            s.push(i);
        }
        else {
            let j = s.pop().unwrap();

            if j != i {
                res = false;
                break;
            }
        }
    }

    println!("{}",
        if res {
            "YES"
        }
        else {
            "NO"
        }
    );
}


Measured memory_bytes: 13432
#include<cctype>
#include<string>
#include<algorithm>
#include<iostream>
#include<set>
#include<regex>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<ctime>
#include<vector>
#include<bitset>
#include<cstdio>
#include<numeric>
#include<utility>
#include<sstream>
#include<cstdlib>
#include<iomanip>
#include<cstring>
#include<map>
#include<functional>
#include<unordered_map>
#define _USE_MATH_DEFINES
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(),N.end()),N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K,L,N,S) vector<L> K(N,S)
#define dv(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define tv(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define maxx 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define endl "\n"
typedef long long int lli;
typedef unsigned long long int uli;
const uli mod = 1e9 + 7;
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
  
    int k, s, cou = 0;
    cin >> k >> s;
    for(int i = 0; i <= k; ++i) {
        for(int j = 0; j <= k; ++j) {
            int z = s - i - j;
            if(0 <= z && z <= k)
                ++cou;
        }
    }
    cout << cou << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
  
// #define int long long
#define pb push_back
#define print(Target) cout << Target << '\n'

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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}

signed main()
{
  ios::sync_with_stdio(false);
  int n;
  
  while (cin >> n, n){
    string s;
    char ss[256];
    sprintf(ss, "%o", n);
    s = ss;
    REP(i, s.size()){
      if (s[i] >= '4') s[i]++;
      if (s[i] >= '6') s[i]++;
    }
    print(s);
  }

  return (0);
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr ll MOD = 1000000007;
constexpr ll INF = 2147483647;
constexpr long long INFF = 3223372036854775807;


signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    ll ruiseki[200100] = {};
    ll kasane[200100] = {};
    ll N;cin >> N;
    REP(i,N){
        ruiseki[i+1] += i;
        if(i != 0) ruiseki[i] += ruiseki[i-1];
    }
    ll A[N];
    REP(i,N){
        cin >> A[i];
        kasane[A[i]]++;
    }
    ll sum = 0;
    REPP(i,1,N+1){
        sum += ruiseki[kasane[i]];
    }
    REP(i,N){
        ll ans;
        ans = sum - ruiseki[kasane[A[i]]] + ruiseki[kasane[A[i]] - 1];
        cout << ans << endl;
    }
}

Measured memory_bytes: 7296
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) a[i] = sc.nextInt();
		boolean[][] dp = new boolean[101][10200];
		dp[0][0] = true;
		for(int i = 0 ; i < n ; i++) {
			for(int j = 0 ; j <= 10000 ; j++) {
				if(dp[i][j] == true) {
					dp[i + 1][j] = true;
					dp[i + 1][j + a[i]] = true;
				}
			}
		}
		for(int i = 10000 ; i >= 0 ; i--) {
			if(i % 10 != 0 && dp[n][i] == true) {
				System.out.println(i);
				return;
			}
		}
		System.out.println(0);
	}
}


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

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

  double ret = 0;
  for(int i = 0;i < n;i++){
    double x;
    string u;
    cin >> x >> u;

    if(u == "BTC")x *= 380000;

    ret += x;
  }

  cout << ret << endl;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d",$n);
fscanf(STDIN, "%s",$temp);
$s=str_split($temp);
$count=array_count_values($s);
$magic=pow(10,9)+7;
$result=1;
reset($count);
for ($i=0; $i < sizeof($count); $i++)
{
	$result*=(current($count)+1);
	$result%=$magic;
	next($count);
}
$result--;
if($result<0)
	printf("%d\n",$result+$magic);
else
	printf("%d\n",$result);

Measured memory_bytes: 10872
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
count=0
ans=0
for i in range(n):
    ans+=b[a[i]-1]
    if count!=n-1:
        if a[count]+1==a[count+1]:
            ans+=c[a[count]-1]
    count+=1
print(ans)


Measured memory_bytes: 3064
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)
	before := 0
	count := 0
	for i := 0; i < n; i++ {
		var v int
		fmt.Scanf("%d", &v)
		if v - before != 1 {
			count++
		}
		before++
	}
	if count == 2 || count == 0 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 1832
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

typedef pair<int,int> P;

int in[3][3],mod;
vector<int> V;
vector<P> empty;
bool used[11];
int ans;

void init(){
  V.clear();
  empty.clear();
  fill(used,used+11,false);
  ans = 0;
}

int check_row(){
  int sum[3];
  
  for(int i = 0; i < 3; i++){
    int tmp = 0;
    for(int j = 0; j < 3; j++)
      tmp += in[i][j];
    sum[i] = tmp;
  }
  
  for(int i = 0; i < 3; i++)
    sum[i] %= mod;
  
  
  if((sum[0] == sum[1])&&(sum[0] == sum[2])) return sum[0];
  return -1;
}

int check_column(){
  int sum[3];
  
  for(int i = 0; i < 3; i++){
    int tmp = 0;
    for(int j = 0; j < 3; j++)
      tmp += in[j][i];
    sum[i] = tmp;
  }
  
  for(int i = 0; i < 3; i++)
    sum[i] %= mod;
  
  if((sum[0] == sum[1])&&(sum[0] == sum[2])) return sum[0];
  return -1;
}

int check_dia(){
  int sum[2] = {0,0};
  
  for(int i = 0; i < 3; i++){
    sum[0]+=in[i][i];
    sum[1]+=in[i][2-i];
  }
  
  sum[0] %= mod;
  sum[1] %= mod;
  
  if(sum[0] == sum[1]) return sum[0];
  return -1;
}

bool check(){
  
  int ansmod[3];
  
  if((ansmod[0] = check_row()) == -1) return false;
  
  if((ansmod[1] = check_column()) == -1) return false;
  if((ansmod[2] = check_dia()) == -1) return false;
  
  
  return (ansmod[0] == ansmod[1] && ansmod[0] == ansmod[2]);
}

void print(){
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++)
      cout << in[i][j] << " ";
    cout << endl;
  }
  cout << "mod " << mod << endl << endl;
  
}

void solve(){
  
  bool modchange = false;
  
  if(mod == 0) modchange = true;
  
  
  do{
    
    
    if(modchange){
      for(int i = 0; i < V.size()-1; i++)
	in[empty[i].first][empty[i].second] = V[i];
      
      mod = V[V.size()-1];
      
      
      
    }else{
      for(int i = 0; i < V.size(); i++)
	in[empty[i].first][empty[i].second] = V[i];
    }
    
    //print();
    
    if(check()) ans++;
    
  }while(next_permutation(V.begin(),V.end()));
  
  cout << ans << endl;
}

bool input(){
  init();
  
  bool flg = false;
  
  for(int i = 0; i < 3; i++)
    for(int j = 0; j < 3; j++){
      cin  >> in[i][j];
      if(in[i][j] == 0) empty.push_back(P(i,j));
      if(in[i][j] != -1) flg = used[in[i][j]] = true;
    }
  
  cin >> mod;
  
  if(mod >= 0) used[mod] = true;
  
  for(int i = 1; i < 11; i++)
    if(!used[i]) V.push_back(i);
  
  return flg;
}

int main(){
  
  while(input()) solve();
  
  return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
int s(int x){
  int a = 0;
  while(x) a += x % 10, x /= 10;
  return a;
}
int main(){
  int n; cin >> n;
  if(n%s(n)) cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}

int main(void) {
  string s;
  cin >> s;
  
  ll a=(s[0]-'0')*10+(s[1]-'0');
  ll b=(s[2]-'0')*10+(s[3]-'0');
  
  if(1<=a && a<=12) {
    if(1<=b && b<=12) {
      pt("AMBIGUOUS");
    }else {
      pt("MMYY");
    }
  }else {
    if(1<=b && b<=12) {
      pt("YYMM");
    }else {
      pt("NA");
    }
  }
  
  
}











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

//#define DEBUG

using namespace std;

template <class T>
void print_vect(std::vector<T> v){
    for(int i = 0 ; i < v .size(); i++) cout << v[i] << " ";
    cout << endl;
}


void solve(){
    uint32_t X, A ;
    cin >> X >> A;
    if(X < A){
        cout << "0" << endl;
    }else{
        cout << "10" << endl;
    }
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/

    #ifdef DEBUG
    int TEST_CASES = 3;
    while(TEST_CASES--){
    #endif // DEBBUG

    solve();

    #ifdef DEBUG
    }
    #endif // DEBUG
    
    return 0;
}


Measured memory_bytes: 3652
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

constexpr char kcWall = '#';
constexpr char kcPath = '.';

int main() {
  int H, W; std::cin >> H >> W;

  bool available[21][21];
  int s[21][21];
  for (int h = 0; h < H; ++h) {
    for (int w = 0; w < W; ++w) {
      char c; std::cin >> c;
      if (c == kcWall) available[h][w] = false;
      else             available[h][w] = true;
    }
  }

  std::deque<std::pair<int, int>> que;
  int max_cost = 0;
  for (int h = 0; h < H; ++h) {
    for (int w = 0; w < W; ++w) {
      if (!available[h][w]) continue;
      que.push_back({h, w});

      for (int h = 0; h < H; ++h) {
        for (int w = 0; w < W; ++w) {
          s[h][w] = -1;
        }
      }

      int max_c = 0;
      while (!que.empty()) {
        auto pair = que.front();
        que.pop_front();

        int h = pair.first;
        int w = pair.second;
        if (s[h][w] >= 0) continue;

        int cost = INT_MAX;
        int nh, nw;
        // up
        nh = h-1; nw = w;
        if (nh >= 0 && available[nh][nw]) {
          if (s[nh][nw] >= 0) cost = std::min(cost, s[nh][nw] + 1);
          else que.push_back({nh, nw});
        }

        // down
        nh = h+1; nw = w;
        if (nh < H && available[nh][nw]) {
          if (s[nh][nw] >= 0) cost = std::min(cost, s[nh][nw] + 1);
          else que.push_back({nh, nw});
        }

        // left
        nh = h; nw = w-1;
        if (nw >= 0 && available[nh][nw]) {
          if (s[nh][nw] >= 0) cost = std::min(cost, s[nh][nw] + 1);
          else que.push_back({nh, nw});
        }

        // right
        nh = h; nw = w+1;
        if (nw < W && available[nh][nw]) {
          if (s[nh][nw] >= 0) cost = std::min(cost, s[nh][nw] + 1);
          else que.push_back({nh, nw});
        }

        s[h][w] = (cost < INT_MAX) ? cost : 0;
        max_c = std::max(max_c, s[h][w]);
      }
      max_cost = std::max(max_cost, max_c);
    }
  }

  std::cout << max_cost << std::endl;
}


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

int const MAX = 100005;

struct position {
	int number; int pos;
};

bool order(position x, position y) {
	return x.number < y.number;
}
position p[MAX];

class unionfind {
private:
	int par[MAX]; int rank[MAX];
public:
	unionfind(int n) {
		for (int i = 0; i < n; i++) {
			par[i] = i;
			rank[i] = 0;
		}
	}
	int find(int x) {
		if (par[x] == x) {
			return x;
		}
		else {
			return par[x] = find(par[x]);
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	void unite(int x, int y) {
		if (!same(x, y)) {
			x = par[x]; y = par[y];
			if (rank[x] < rank[y]) {
				par[x] = y;
			}
			else {
				par[y] = x;
				if (rank[x] == rank[y]) {
					rank[x]++;
				}
			}
		}
	}
};

int main() {
	int n, m;
	cin >> n >> m;
	unionfind u(n + 1);
	for (int i = 1; i <= n; i++) {
		int t;
		cin >> t;
		p[i] = { t,i };
	}
	sort(p + 1, p + n + 1, order);

	for (int i = 0; i<m; i++) {
		int x, y;
		cin >> x >> y;
		u.unite(x, y);
	}
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		if (u.same(i, p[i].pos)) {
			cnt++;
		}
	}
	cout << cnt << endl;


}

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

int main(){
	int n;
    ll k,a[200005],b[200005];
 	int ans=0;
  	cin>>n>>k;
  	for(int i=0;i<n;i++){
      	cin>>a[i]>>b[i];
      	if(a[i]*a[i]+b[i]*b[i]<=k*k){
        	ans++;
        }
    }
  
  cout<<ans<<endl;
  
  return 0;
  
}



Measured memory_bytes: 6728
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = 1000000007;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;

	Set<Long> setA = new HashSet<>();
	Set<Long> setB = new HashSet<>();
	void doIt() {
		long a = sc.nextLong();
		long b = sc.nextLong();
		long len = a;
		setA.add(1l); setB.add(1l);
		for(long i = 2; i * i< len; i++) {
			while(a % i == 0) {
				a /= i;
				setA.add(i);
				//System.out.println(a + " " + i);
			}
		}
		setA.add(a);
		len = b;
		for(long i = 2; i * i < len; i++) {
			while(b % i == 0) {
				b /= i;
				setB.add(i);
			}
		}
		setB.add(b);
		long cnt = 0;
		for(long i : setA) {
			if(setB.contains(i)) {
				cnt++;
			}
		}
		//System.out.println(Arrays.toString(setA.toArray()));
		System.out.println(cnt);

	}



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


Measured memory_bytes: 23508
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{

int k,i,j;
int count;
count =0;
scanf("%d",&k);
for(i=2;i<=k;i=i+2)
{
for(j=1;j<=k;j=j+2)
{
count++;
}
}
printf("%d",count);
return 0;
}


Measured memory_bytes: 256