akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>

#define CK(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)
#define F first
#define S second
#define ll long long;

const int INF = 1e9;
const long long  LLINF = 1e15;

using namespace std;

long long N, A, B, H[100010];

bool check(long long k){
     long long sum = 0;
     REP(i,0,N) sum += max(0LL, (H[i]-k*B+(A-B-1))/(A-B));
     return (sum <= k);
}

int main() {
  cin>>N>>A>>B;
  REP(i,0,N) cin>>H[i];
  long long l = 0, r = 1e9;
  while(r-l > 1){
    long long mid = (l+r)/2;
    if(check(mid)) r = mid;
    else l = mid;
  }
  cout<<r<<endl;
  return 0;
}


Measured memory_bytes: 1024
# AOJ 1200: Goldbach's Conjecture
# Python3 2018.7.19 bal4u

MAX = 32770    # > 2^15
SQRT = 182     # sqrt(MAX)+1

prime = [True]*(MAX+1)
def sieve():
    for i in range(4, MAX, 2): prime[i] = False
    for i in range(3, SQRT, 2):
        if prime[i]:
            for j in range(i*i, MAX, i): prime[j] = False

sieve()
while True:
    n = int(input())
    if n == 0: break
    if n == 4: ans = 1
    else:
        ans = 0
        for i in range(3, 1+(n>>1), 2):
            if prime[i] and prime[n-i]: ans += 1
    print(ans)



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

int main() {
	int n;
	cin >> n;
	int ans=0;
	for(int i=0; i<n; i++){
		int l,r;
		cin >> l >> r;
		
		ans+=r-l+1;
	}
	cout << ans << endl;
	return 0;
}

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

int main(){

    int n;
    int cnt=0;
    string s;
    cin>>n>>s;

    for(int i=0;i<n-2;i++){
        if(s.at(i)=='A'&&s.at(i+1)=='B'&&s.at(i+2)=='C') cnt++;
    }

    cout<<cnt<<endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
list_A = list(map(int, input().split()))
list_B = list(map(int, input().split()))
list_C = list(map(int, input().split()))
p = 0
for i in list_B:
    p += i
for i in range(N-1):
    if list_A[i+1] - list_A[i] == 1:
        p += list_C[list_A[i] - 1]
print(p)

Measured memory_bytes: 3060
const int isDebugMode = 1;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
struct edge{long long to,cost;};
const int inf = 1 << 27;
const long long INF = 1LL << 60;
const int COMBMAX = 1001001;
const long long MOD = 1000000007;
const long long dy[] = {-1, 0, 0, 1};
const long long dx[] = {0, -1, 1, 0};
string abc = "abcdefghijklmnopqrstuvwxyz";
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define eachdo(v, e) for (const auto &e : (v))
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (long long)distance((v).begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (long long)distance((v).begin(), upper_bound((v).begin(), (v).end(), e))
long long mpow(long long a, long long n, long long mod = MOD){long long res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
void pt(){cout << endl; return;}
template<class Head> void pt(Head&& head){cout << head; pt(); return;}
template<class Head, class... Tail> void pt(Head&& head, Tail&&... tail){cout << head << " "; pt(forward<Tail>(tail)...);}
void dpt(){if(!isDebugMode) return; cout << endl; return;}
template<class Head> void dpt(Head&& head){if(!isDebugMode) return; cout << head; pt(); return;}
template<class Head, class... Tail> void dpt(Head&& head, Tail&&... tail){if(!isDebugMode) return; cout << head << " "; pt(forward<Tail>(tail)...);}
template<class T> void debug(T v){if(!isDebugMode) return; rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void debug2(T v){if(!isDebugMode) return; rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2> inline bool chmax(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
template<class T1, class T2> long long recgcd(T1 a, T2 b){return a % b ? recgcd(b , a % b) : b;}
bool valid(long long H, long long W, long long h, long long w) { return 0 <= h && h < H && 0 <= w && w < W; }

int main(){
    ll N; cin >> N;
    vector<ll> a(N);
    rep(i, N) cin >> a[i];
    ll cur = 0;
    ll ans = 0;
    cur = a[0];
    rep(i, N - 1){
        chmax(cur, a[i]);
        if(cur > a[i + 1]){
            ans += cur - a[i + 1];
        }
        // pt(ans, cur);
    }
    pt(ans);
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  int cnt = 1;
  for (int i = 1; i < 3; i++) {
    cnt += (s[i] == s.front());
  }
  cout << (cnt == 3 ? "No" : "Yes") << '\n';
  return 0;
}


Measured memory_bytes: 256
a = int(input())
b = int(input())

if a == 1 and b == 2 or a == 2 and b == 1:
    print(3)
elif a == 1 and b == 3 or a == 3 and b == 1:
    print(2)
elif a == 2 and b == 3 or a == 3 and b == 2:
    print(1)

Measured memory_bytes: 3060
N, M = map(int, input().split())
L_min = 0
R_min = N
for i in range(M):
    L_i, R_i = map(int, input().split())
    if L_min < L_i:
        L_min = L_i
    if R_min > R_i:
        R_min = R_i
if R_min >= L_min:
    print(R_min - L_min + 1)
else:
    print(0)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
int main(){
    string s;
    cin >> s;
    int ans = 0;
    for(int i = 0; i < 4; i++){
        if(s.at(i) == '+')
        ans++;
        else 
        ans--;
    }
    cout << ans << endl;
    return 0; 
}

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

using namespace std;

int n, m;
const int mod = 1e9 + 7;

long long Pow(long long a, long long b) {
  long long s = 1;
  long long t = 1;
  while (b) {
    if (b & t) {
      s = (s * a) % mod;
    }
    a = (a * a) % mod;
    b = b >> 1;
  }
  return s;
}

long long inv(long long a) { return Pow(a, mod - 2); }

int main() {
  cin >> n >> m;
  long long a = 2 * m - n, b = 2 * n - m;
  if (a < 0 || a % 3 || b < 0 || b % 3) {
    cout << "0\n";
  } else {
    a /= 3;
    b /= 3;
    if (a > b) swap(a, b);
    long long s = a + b;
    long long res = 1;
    for (long long i = 1; i <= a; i++) {
      res = (res * (s - i + 1) % mod * inv(i)) % mod;
    }
    cout << res << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>

using namespace std;
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-13)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1e9 + 7;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H& b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H& b) const { return x == b.x && y == b.y; }
	bool operator!=(const H& b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T& a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T& a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
ll bitcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
/*ll fact_[200000];
ll comb(ll x, ll y, ll mod = Mod) {
	if (!fact_[0]) {
		fact_[0] = 1;
		for (int i = 1; i < 200000; i++) {
			fact_[i] = fact_[i - 1] * i % mod;
		}
	}
	if (x < y) return 0;
	return mod_pow(fact_[x], mod, mod) *
		mod_pow(fact_[x - y], mod - 2, mod) % mod *
		mod_pow(fact_[y], mod - 2, mod) % mod;
}//xCy*/
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int a;
string s;
signed main() {
	cin >> a >> s;
	cout << (a >= 3200 ? s : "red") << endl;
}

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

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

    int count = 0;
    while (true) {
        for (int i = 0; i < N; i++) {
            if (A[i] % 2 == 1) {
                goto OUT;
            }
            A[i] /= 2;
        }
        count++;
    }
    
    OUT:
    cout << count << endl;
}

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

using ll = long long;

const int MAXN = 100010;
int N, M;
ll K;
int X[MAXN];
int dist[MAXN];
ll ans[MAXN];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> X[i];
	}
	for (int i = 0; i < N - 1; i++) {
		dist[i] = X[i + 1] - X[i];
	}
	vector<int> perm(N - 1);
	iota(perm.begin(), perm.end(), 0);
	cin >> M >> K;
	for (int i = 0; i < M; i++) {
		int x; cin >> x; x--;
		swap(perm[x - 1], perm[x]);
	}

	auto go = [&](vector<int> a, vector<int> b) -> vector<int> {
		vector<int> c(N - 1);
		for (int i = 0; i < N - 1; i++) {
			c[i] = a[b[i]];
		}
		return c;
	};

	vector<int> res(N - 1);
	iota(res.begin(), res.end(), 0);
	while (K) {
		if (K & 1) {
			res = go(res, perm);
		}
		perm = go(perm, perm);
		K /= 2;
	}

	ans[0] = X[0];
	for (int i = 0; i < N - 1; i++) {
		ans[i + 1] = ans[i] + dist[res[i]];
	}
	for (int i = 0; i < N; i++) {
		cout << ans[i] << '\n';
	}

	return 0;
}

Measured memory_bytes: 4184
#include<stdio.h>

int main()
{
    int x, a, b,c,i,j,k,sum,ans=0;

    scanf("%d%d%d%d", &a, &b, &c,&x);
    for(i=0;i<=a;i++)
        for(j=0;j<=b;j++)
            for (k = 0; k <= c; k++)
            {
                sum = i * 500 + j * 100 + k * 50;
                if (sum == x)
                    ans++;
            }
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 888
x = int(input())

if x <= 599:
    print(8)
elif x <= 799:
    print(7)
elif x <= 999:
    print(6)
elif x <= 1199:
    print(5)
elif x <= 1399:
    print(4)
elif x <= 1599:
    print(3)
elif x <= 1799:
    print(2)
elif x <= 1999:
    print(1)

Measured memory_bytes: 9180
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n , cs[N] , k;
string s;
int freq[N];
int main(){
    cin >> n >> k ;
    cin >> s;
    memset(freq , -1 , sizeof freq);
    cs[0] = (s[0] == '0');
    freq[0] += (s[0] == '1');
    int ans = 1;
    for(int i = 1 ; i < s.size() ; i++){
        if(s[i] == s[i - 1] || s[i] == '1')
            cs[i] = cs[i - 1];
        else
            cs[i] = cs[i - 1] + 1;
        if(cs[i] <= k){
            ans = i + 1;
        }else{
        if(freq[cs[i] - k] != -1)
        ans = max(ans , i - freq[cs[i] - k] + 1);}
        if(s[i] == '1' && freq[cs[i]] == -1) freq[cs[i]] = i;  
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
const int maxi = 1e5 + 10;
long long M[105][2], dp[105][maxi];
long long f(int n, int s){
	if(n < 0 || s <= 0) return 0;
	if(dp[n][s] != -1) return dp[n][s];
	if(s - M[n][0] < 0) return dp[n][s] = f(n - 1, s);
	return dp[n][s] = max(M[n][1] + f(n - 1, s - M[n][0]), f(n - 1, s));
}
int main() {
	int n, w;
	cin >> n >> w;
	for(int i=0;i<n;i++) cin >> M[i][0] >> M[i][1];
	memset(dp, -1, sizeof(dp));
	cout << f(n - 1, w);
	return 0;
}

Measured memory_bytes: 82304
from itertools import groupby


def main():

    S = input()
    K = int(input())
    a = [len(tuple(s)) for _, s in groupby(S)]
    ans = 0

    if S[0] == S[-1] and K > 1:
        if len(a) == 1:
            ans = a[0] * K // 2
        else:
            ans = a[0] // 2 + a[-1] // 2 + (a[0] + a[-1]) // 2 * (K - 1)
            ans += sum(n // 2 for n in a[1:-1]) * K
    else:
        ans = sum(n // 2 for n in a) * K
    print(ans)


if __name__ == "__main__":
    main()


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

#%%
ab = sorted(ab, key=lambda x: x[1])
flag = True

cost = 0
for a, b in ab:
    cost += a
    if cost > b:
        flag = False
        break

if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 89748
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
int N;
int dest[3];
int arr[8];
int chk[8];
int ans=987654321;
int sol(int s){
	vector<int> list;
	list.clear();
	for(int i=0;i<N;i++) if(chk[i]==s) list.push_back(arr[i]);
	int full=(1<<list.size())-1;
	int ret=987654321;
	for(int subset=full;subset;subset=((subset-1)&(full))){
		int sum=0,cnt=0;
		for(int i=0;i<list.size();i++){
			if(subset&(1<<i)){
				sum+=list[i];
				cnt++;
			}
		}
		ret=min(ret,abs(dest[s]-sum)+(cnt-1)*10);
	}
	return ret;
}
void bt(int x){
	if(x==N){
		ans=min(ans,sol(0)+sol(1)+sol(2));
		return;
	}
	for(int i=0;i<3;i++){
		chk[x]=i;
		bt(x+1);
		chk[x]=0;
	}
}
int main(){
	scanf("%d",&N);
	for(int i=0;i<3;i++) scanf("%d",dest+i);
	for(int i=0;i<N;i++) scanf("%d",arr+i);
	sort(arr,arr+N);
	sort(dest,dest+3);
	bt(0);
	printf("%d",ans);
}

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

int n, m;
vector<int> G[100100];
bool seen[100100];
int dp[100100];
int dfs(int x) {
  if(seen[x]) return dp[x];
  seen[x] = true;
  int num = 0;
  for(auto nxt : G[x]) {
    num = max(num,dfs(nxt)); 
  }
  dp[x] = num + 1;
  return dp[x];
}

int main() {
  cin >> n >> m;
  rep(i,m) {
    int x, y;
    cin >> x >> y;
    G[x].push_back(y);
  }
  for(int i = 1; i <= n; i++) dfs(i);
  int ans = -1;
  for(int i = 1; i <= n; i++) ans = max(ans,dp[i]);
  cout << ans-1 << endl;
  return 0;
}

Measured memory_bytes: 11504
t = int(input()) 
lie = list(map(int,input().split()))
c=0
l= []
for i in range(len(lie)-1):
  if lie[i]>=lie[i+1]:
    c=c+1
  else:
    l.append(c)
    c=0
l.append(c)
print(max(l))

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

int main()
{
	int A, B;
	cin >> A >> B;

	int count = 0;
	for (int i = A; i <= B; i++) {
		string s = to_string(i);
		string rev_s = s;
		reverse(rev_s.begin(), rev_s.end());

		if (s == rev_s) {
			count++;
		}

	}
	
	cout << count << endl;
		
	
}




Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main() {
	int N, K;
	cin >> N >> K;
	vector<int>A(N);
	vector<int>B(N, 0);
	for (int i = 0; i < N; i++) {
		cin >> A.at(i);
		B.at(A.at(i) - 1)++;
	}
	int kind = 0;
	for (int i = 0; i < N; i++) {
		if (B.at(i) == 0) {
			B.at(i) = N + 1;
		}
		else kind++;
	}
	sort(B.begin(), B.end());
	int ans = 0;
	for (int i = 0; i < kind - K; i++) {
		ans += B.at(i);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
N, K = gets.split.map(&:to_i)

hash = {}
N.times do |i|
    t, d = gets.split.map(&:to_i)
    hash[t] ||= []
    hash[t].push(d)
end

maxes = []
others = []
hash.values.each do |arr|
    arr.sort!
    maxes.push(arr.pop)
    others.concat(arr)
end

maxes = maxes.sort.reverse
others = others.sort.reverse

maxes_s = [0]
maxes.each do |a|
    maxes_s.push(maxes_s[-1] + a)
end
others_s = [0]
others.each do |a|
    others_s.push(others_s[-1] + a)
end

ans = 0
(1..[maxes.size, K].min).each do |kinds|
    result = kinds*kinds + maxes_s[kinds] + (others_s[K-kinds] || 0)
    ans = result if ans < result
end

puts ans

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

string s;
int ans;

int main(){
	cin>>s;

	if(s =="SUN"){
		ans = 7;
	}
	else if(s =="MON"){
		ans = 6;
	}
	else if(s =="TUE"){
		ans = 5;
	}
	else if(s =="WED"){
		ans = 4;
	}
	else if(s =="THU"){
		ans = 3;
	}
	else if(s =="FRI"){
		ans = 2;
	}
	else if(s =="SAT"){
		ans = 1;
	}
	cout<<ans;
}

Measured memory_bytes: 256
while True:
    d=raw_input()
    if d=="0":break
    m,n=map(int,d.split())
    cnt=0
    for i in range(m,n+1):
        t=i
        while t!=1:
            if t%2==0:
                t/=2
            elif t%3==0:
                t/=3
            elif t%5==0:
                t/=5
            else:
                break
        else:
            cnt+=1
    print cnt

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

int main()
{
    int n, x;
    int i, j, k;
    int num;

    while (1) {
        cin >> n >> x;

        if (n == 0 && x == 0) break;

        if ((n >= 3 && n <= 100) && (x >= 0 && x <= 300)) {
            num = 0;

            for (i = 1; i <= n-2; i++) {
                if (i >= x) break;
                for (j = i+1; j <= n-1; j++) {
                    if ((i+j) >= x) break;
                    for (k = j+1; k <= n; k++) {
                        if ((i+j+k) > x) break;
                        if ((i+j+k) == x) num++;
                    }
                }
            }
            cout << num << endl;
        }
    }

     return 0;
}


Measured memory_bytes: 3108
#include<stdio.h>

int main(){
  int A, B, C;
  char op[2];
  
  scanf("%d %s %d", &A, op, &B);
  
  if(op[0] == '+'){
    C = A + B;
  } else if(op[0] == '-'){
  	C = A - B;
  }
  
  printf("%d", C);
  
  return 0;
}

Measured memory_bytes: 128
<?php
    fscanf(STDIN, "%d", $n);
    fscanf(STDIN, "%s", $s);
    if($n % 2 === 0){
        $cutnum = $n/2;
        $front = substr($s, 0, $cutnum);
        $back = substr($s, $cutnum, $cutnum);
        if($back === $front){
            echo 'Yes';
        }else{
            echo 'No';
        }
    }else{
        echo 'No';
    }
?>

Measured memory_bytes: 4728
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long int ll;
ll a[309];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    ll x=0;
    for(int i=3;i<=n;i++) x=x^a[i];
    ll y=a[1]+a[2];
    if(y%2!=x%2) cout<<-1;
    else if(y<x) cout<<-1;
    else{
        ll z=(y-x)/2;
       // cout<<x<<" "<<y<<" "<<z<<"\n";
        vector<int>f;
        vector<int>Z;
        vector<int>X;
        while(Z.size()<45)
        {
            Z.push_back(z%2);
            z=z/2;
        }
        while(X.size()<45)
        {
            X.push_back(x%2);
            x=x/2;
        }
      //  for(int x : X) cout<<x;cout<<"\n";
       //  for(int x : Z) cout<<x;cout<<"\n";
        ll poss=0;
        vector<int>add;
        for(int i=0;i<45;i++)
        {
            if(X[i]==1 and Z[i]==1) { cout<<-1 ; return 0 ;}
            else if(X[i]==1 and Z[i]==0){ add.push_back(i) ; }
            else if(X[i]==0 and Z[i]==1) {
                poss+=(1LL<<i);
            }
        }
        ll s=0;
        //for(int x : add) cout<<x;cout<<"\n";
        //cout<<poss<<"\n";
        if(poss<a[2])
        {
            ll diff=a[2]-poss;
            vector<int>v;
            int idx=0;
            while(diff>0){if(diff%2==1) v.push_back(idx) ; diff=diff/2; idx++ ;}
            reverse(v.begin(),v.end());
           // for(int x : v) cout<<x<<" "; cout<<"\n";
            for(int x : v)
            {  // cout<<x;
                if(!binary_search(add.begin(),add.end(),x)) { if(upper_bound(add.begin(),add.end(),x)!=add.end()) s+=(1LL<<add[upper_bound(add.begin(),add.end(),x)-add.begin()]) ; else {cout<<-1 ; return 0 ;}  break ; }
                else s+=(1LL<<x);
               // cout<<s;
            }
           // cout<<s<<"\n";
        }
        else{ s=poss-a[2]; cout<<s; return 0 ;}
       if(poss+s>=a[2] and a[1]+a[2]-poss-s>0) cout<<poss+s-a[2];
        else cout<<-1;
    }
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#define in(n, m) for (ll i=n; i<m;i++)
#define inj(n, m)for (ll j=n; j<m;j++)
#define ink(n, m)for (ll k=n; k<m;k++)
using namespace std;
using ll=long long;
using P =pair<ll, ll>;
const ll INF = 1LL << 60;
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; }


int main() {
	ll X;
	cin >> X;
	ll A, B;
	in(-118, 120) {
		inj(i, 120) {
			if (pow(j, 5) - pow(i, 5) == X) {
				A = j;
				B = i;
			}
		}
	}

	cout << A << " " << B << endl;
	return 0;
}


Measured memory_bytes: 3600
import java.util.*;
import java.io.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		if(c>=a && c<=b){
			System.out.println("Yes");
			return;
		}
		System.out.println("No");		
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,n;
    while(1)
    {
        cin>>a>>b;
        if((a>=2&&a<=100)&&(b>=2&&b<=100))
            break;
    }
    n=(a-1)*(b-1);
   
    cout<<n<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
long double const pi = std::acos(-1.0L);
typedef pair<int,int> P;
const int INF = 1001001001;

bool G[10][10];

int dfs(int v,int n, bool visited[10]){
  bool ok = true;

  rep(i,n){
    if(visited[i]==false) ok = false;
  }
  if(ok) return 1;

  int ret = 0;
  rep(i,n){
    if(G[v][i]==false) continue;
    if(visited[i]) continue;

    visited[i]=true;
    ret+=dfs(i,n,visited);
    visited[i]=false;
  }
  return ret;
}
int main() {
  int n,m; cin >> n >> m;
  rep(i,m){
    int a, b; cin >> a >> b; --a,--b;
    G[a][b]=G[b][a]=true;
  }
  bool visited[10];
  rep(i,n){
    visited[i]=false;
  }
  visited[0]=true;
  cout << dfs(0,n,visited) << endl;
  return 0;
}

Measured memory_bytes: 256
/*input

*/


//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define pb          push_back
#define pii         pair<ll int,ll int>
#define vpii        vector< pii >
#define vi          vector<ll int>
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define repr(i,a,b) for(ll int i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll N = 5e5+5;
vvi adj(N,vi ());
vi top;
vi vis(N,0),vis2(N,0),dp(N,0);
vi vis3(N,0);


ll is_cycle=0;
void dfs(ll u)
{
	// whatis(u);
	vis[u]=1;
	vis2[u]=1;
	rep(i,0,sz(adj[u]))
	{
		ll ch  = adj[u][i];
		if(vis2[ch]==1)
		{
			is_cycle=1;
			break;
		} 
		if(vis[ch]==0) dfs(ch);
	}
	top.pb(u);
	vis2[u]=0;
	return ;
}

void dfs2(ll u)
{
	// whatis(u);
	vis3[u]=1;
	rep(i,0,sz(adj[u]))
	{
		ll ch = adj[u][i];
		dp[u]=max(dp[u],dp[ch]+1);
		if(vis3[ch]==0) dfs2(ch);
	}

	// cout<<u<<" "<<dp[u]<<"\n";
	return ;
}



int solve()
{
	ll n;cin>>n;
	map<pii,ll> m;
	ll cnt=0;
	rep(x,0,n) rep(y,x+1,n) m[mp(x,y)]=cnt,m[mp(y,x)]=cnt,cnt++; 
	rep(i,0,n)
	{
		ll prev = -1;
		rep(j,0,n-1)
		{
			ll x;cin>>x;
			x--;
			if(prev!=-1) adj[prev].pb(m[mp(i,x)]);
			prev=m[mp(i,x)];
		}
	}

	rep(i,0,cnt)
	{
		if(vis[i]==0) dfs(i);
		if(is_cycle==1) break;
	} 
	if(is_cycle==1)
	{
		cout<<"-1\n";
		return 0;
	}
	// rep(i,0,sz(top)) cout<<top[i]<<" ";
	// reverse(top.begin(), top.end());
	rep(i,0,sz(top)) if(vis3[top[i]]==0) dfs2(top[i]);

	ll ans=0;
	rep(i,0,cnt) ans=max(ans,dp[i]);
	cout<<ans+1<<"\n";



	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	// cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}

Measured memory_bytes: 111860
#include<bits/stdc++.h>
using namespace std;
int main()
{
int c=0;
string s1;
string s2;
cin>>s1;
cin>>s2;
int a=s1.size();
int b=s2.size();
for(int i=0;i<a;i++)
{
if(s1[i]==s2[i])
c++;
}
if(c==a)
{
cout<<"Yes"<<endl;
}
else
{
cout<<"No"<<endl;
}
	return 0;
}


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

using namespace std;

int n,i,j,ans[1000005],cnt[505];
pair <int, int> a[505];
queue <int> ok;

int main(){
	scanf("%d", &n);
	for(i = 1; i <= n; i++){
		scanf("%d", &a[i].first);
		a[i].second = i;
		ans[a[i].first] = i;
		cnt[i]++;
	}
	sort(a + 1, a + 1 + n);
	
	int p = 1;
	
	for(i = 1; i <= n * n; i++){
		
		while(p <= n && cnt[a[p].second] == a[p].second)
		p++;
		
		
		if(p <= n && i == a[p].first) return 0 * printf("No\n");
		
		if(p <= n && ans[i] == 0){
			int id = a[p].second;
			ans[i] = id;
			cnt[id]++;
		}
	}
	
	p = 1;
	
	for(i = 1; i <= n * n; i++){
		int id = a[p].second;
		if(a[p].first == i){
			ok.push(id);
			p++;
		}
		
		if(ans[i] != 0) continue;
		
		while(ok.size() && cnt[ok.front()] == n)
		ok.pop();
		
		if(ok.empty())
		return 0 * printf("No\n");
		
		ans[i] = ok.front();
		cnt[ok.front()]++;
	}
	
	printf("Yes\n");
	for(i = 1; i <= n * n; i++){
		if(i == 1)
		printf("%d", ans[i]);
		else
		printf(" %d", ans[i]);
	}
	printf("\n");
}


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

int main(){
  long long n;
  long long MX=1e18;
  cin>>n;
  vector<long long> a(n);
  long long ans=1;
  bool ng=false;
  for(int i=0;i<n;i++){
    long long a;
    cin>>a;
    if(a==0){
      cout<<0<<endl;
      return 0;
    }
    if(ng || MX/ans<a){
      ng=true;
    }
    ans*=a;
  }
  if(ng) cout<<-1<<endl;
  else cout<<ans<<endl;
}

Measured memory_bytes: 4040
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string coffee;
  cin >> coffee;
  if (coffee.at(2)==coffee.at(3) && coffee.at(4)==coffee.at(5)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
n=int(input())
k=2

a=list(map(int, input().split()))

if n<3:
    print(abs(a[0]-a[-1]))
    exit()

c=[0]*n
c[-1]=0
mini=1000000

for i in reversed(range(n-k, n-1)):
    # print(i)
    c[i]=abs(a[i]-a[n-1])
    mini=min(mini, c[i])


for i in reversed(range(n-k)):
    c[i]=min([c[t]+abs(a[i]-a[t]) for t in range(i+1, i+k+1)])

# print("?", c)

print(c[0])

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


/// File input & output /////
#define fRead(x)        freopen("x.txt","r",stdin)
#define fWrite(x)       freopen ("x.txt","w",stdout)

#define mt              make_tuple
#define ld              long double
#define ll              long long
#define ull             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())


#define FASTIO        ios_base::sync_with_stdio(0);cin.tie(nullptr);




///..................Sort by second element in a pair in decending order............. ///
bool SortbySecDesc(const pair<long long,long long > &a, const pair<long long,long long > &b)
{
    return a.second>b.second;
}

///.........................first element of pair in descending order..........................//////
bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}



///.............................................................TEMPLATE................................................./////




int main()
{
    FASTIO;

    ll n;

    cin >> n;

    ll a[n+1];


    int f = 1;


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

    sort(a,a+n);

    for(int i=0; i<n-1; i++)
    {
        if(a[i]==a[i+1])
        {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;





    return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define OK cout<<"OK";
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    ll k,u;
    cin>>k;
    if(k<13)
     {
         cout<<k;
         return 0;
     }
    set<ll> s;
    ll i=1;
    while(i<10)
    {
        s.insert(i);
        i++;
    }
    while(k--)
    {
         u=*s.begin();
         s.erase(u);
         s.insert(u*10+u%10);
         if(u%10<=8)
            s.insert(u*10+(u%10)+1);
         if(u%10>=1)
            s.insert(u*10+(u%10)-1);
    }
    cout<<u;
}


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

using namespace std;

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

#define int long long
#define tie() ios_base :: sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define f(i,from,to) for(int i = from ; i <to ; i++)
#define mem(a , v) memset(a , v , sizeof a)
#define all(v) v.begin() , v.end()
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define what_is(x) cerr << #x << " is : " << x <<endl

const int INF = 1e9 + 7;
const int sz = 1e5 + 20;
const int N =1e5 + 20;
/***************************************************************/

bool prime(int n)
{
    int x = sqrt(n);
    f(i , 2 , x+1)
        if(n % i == 0)
            return false;
    return true;
}


void solve()
{
    int n;
    cin >> n;
    int i = n;
    while(true)
    {
        if(prime(i))
        {
            cout << i << endl;
            break;
        }
        i++;
    }


    return;
}


int32_t main()
{
    int t = 1;
    //cin>>t;
    while(t--)
        solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

typedef struct Edge {
    int to, cost;
} edge;

vector<edge> G[100000];
int color[100000];

void dfs(int n, int before, bool odd) {
    int before_c = color[before];
    color[n] = odd ? 1 : 0;

    for (auto e : G[n]) {
        if (e.to == before) continue;
        if ((e.cost % 2 == 0 && odd) || (e.cost % 2 == 1 && !odd)) {
            dfs(e.to, n, true);
        } else {
            dfs(e.to, n, false);
        }
    }
}

int main() {
    int N;
    cin >> N;
    REP(i, N - 1) {
        int u, v, w;
        cin >> u >> v >> w;
        u--; v--;
        G[u].push_back({v, w});
        G[v].push_back({u, w});
    }
    dfs(0, -1, false);
    REP(i, N) cout << color[i] << endl;
    return 0;
}

Measured memory_bytes: 8320
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	int H; int W;
	while(~scanf("%d%d", &H, &W)) {
		vector<string> A(H);
		int num = 0;
		rep(i, H) {
			char buf[101];
			scanf("%s", buf);
			A[i] = buf;
			num += count(buf, buf + W, '#');
		}
		bool ans = num == H + W - 1;
		puts(ans ? "Possible" : "Impossible");
	}
	return 0;
}


Measured memory_bytes: 892
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  string s;
  cin >> s;
  for (auto& c : s) {
    if (c == 'A') {
      c = 'T';
    } else if (c == 'T') {
      c = 'A';
    } else if (c == 'G') {
      c = 'C';
    } else {
      c = 'G';
    }
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<long long, long long>;
const int INF = numeric_limits<int>::max();
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

bool is_prime(ll n) {
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return n != 1;
}

int main()
{
    ll n; cin >> n;
    vector<pair<ll, ll>> a;
    rep(i,n) {
        ll b, c;
        cin >> b >> c;
        a.push_back(make_pair(c, b));
    }
    sort(a.begin(), a.end());
    ll ans = 0;
    ans += a[0].second;
    rep1(i,n) {
        ans += min(a[i-1].second - a[i].second, a[i-1].first - a[i].first);
    }
    ans += a[n-1].first;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5356
using System;
using System.IO;
using System.Linq;

class Program{
    static void Main(string[] args){
        var arr = Console.ReadLine().Split();
        var N = int.Parse(arr[0]);
        var C = int.Parse(arr[2]);
        var B = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var answer = 0;
        for (int i = 1; i <= N; i++){
            var A = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var sum = 0;
            foreach (var (a,b) in A.Zip(B)){
                sum += a * b;}
            if (sum + C > 0) answer++;}
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();}}

Measured memory_bytes: 28284
import sys
import copy
import math
import itertools
import numpy as np
S=input()
N = len(S)+1
a = [0]*N
b = [0]*N
for i in range(N-1):
    if S[i]=="<":
        a[i+1]=a[i]+1

for i in reversed(range(N-1)):
    if S[i]==">":
        b[i]=b[i+1]+1

for i in range(N):
    if a[i] < b[i]:
        a[i]=b[i]

print(sum(a))

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

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

  unordered_map<int, vector<int>> routes;
  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    routes[A].push_back(B);
    routes[B].push_back(A); 
  }

  queue<int> q;
  q.push(1);
  map<int, int> ans;
  while (!q.empty()) {
    int room = q.front();
    q.pop();
    for (auto val: routes[room]){
     if(ans[val]==0) {
        ans[val]=room;
        q.push(val);
      }
    }
  }

  cout << "Yes" << endl;
  for (int i = 2; i <= N; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 17656
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
#include <stack>
#include <cctype>
#include <cmath>
#include <bitset>

using namespace std;

/* typedef */
typedef long long ll;

/* constant */
const int INF = 1 << 30;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;

/* global variables */

/* function */

/* main */
int main(){

    ll a, b;
    cin >> a >> b;
    bitset<32> bs_a(a);
    bitset<32> bs_b(b);

    // AND
    bitset<32> and_bits = bs_a & bs_b;
    // OR
    bitset<32> or_bits = bs_a | bs_b;
    // XOR
    bitset<32> xor_bits = bs_a ^ bs_b;
    
    cout << and_bits << '\n';
    cout << or_bits << '\n';
    cout << xor_bits << '\n';
}



Measured memory_bytes: 3168
using System;
using System.Collections.Generic;

class AGC_033_A
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int H = int.Parse(input[0]);
        int W = int.Parse(input[1]);

        char[][] A = new char[H][];
        List<Point> executeBlackList = new List<Point>();

        for (int i = 0; i < H; i++)
        {
            string s = Console.ReadLine();

            A[i] = new char[W];
            for (int j = 0; j < W; j++)
            {
                A[i][j] = s[j];
                if(A[i][j]=='#') executeBlackList.Add(new Point(j, i));
            }
        }

        int count = 0;

        while (executeBlackList.Count > 0)
        {
            List<Point> nextBlackList = new List<Point>();

            for (int i = 0; i < executeBlackList.Count; i++)
            {
                Point p = executeBlackList[i];

                Point left = new Point(p.X - 1, p.Y);
                Point right = new Point(p.X + 1, p.Y);
                Point top = new Point(p.X, p.Y - 1);
                Point bottom = new Point(p.X, p.Y + 1);

                if (left.X >= 0 && A[left.Y][left.X] == '.')
                {
                    A[left.Y][left.X] = '#';
                    nextBlackList.Add(left);
                }
                if (right.X < W && A[right.Y][right.X] == '.')
                {
                    A[right.Y][right.X] = '#';
                    nextBlackList.Add(right);
                }
                if (top.Y >= 0 && A[top.Y][top.X] == '.')
                {
                    A[top.Y][top.X] = '#';
                    nextBlackList.Add(top);
                }
                if (bottom.Y < H && A[bottom.Y][bottom.X] == '.')
                {
                    A[bottom.Y][bottom.X] = '#';
                    nextBlackList.Add(bottom);
                }
            }

            if (nextBlackList.Count>0) count++;

            executeBlackList.Clear();
            executeBlackList.AddRange(nextBlackList);
        }

        Console.WriteLine(count);
    }
}

struct Point
{
    public int X, Y;

    public Point(int x, int y)
    {
        X = x;
        Y = y;
    }
}


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

int main() {
    ll N, M, K; cin >> N >> M >> K;
    vector<int> A(N), B(M);
    for (int i = 0; i < N; ++i) cin >> A[i];
    for (int i = 0; i < M; ++i) cin >> B[i];
    ll s = accumulate(B.begin(), B.end(), 0LL);
    int j = M;
    int ans = 0;
    for (int i = 0; i <= N; ++i) {
        while (j > 0 && K < s) {
            --j;
            s -= B[j];
        }
        if (K >= s) ans = max(ans, i + j);
        if (i < N) s += A[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4740
import scala.io.StdIn

object Main extends App {
  val n = StdIn.readLine.toInt
  val ans = Iterator.continually(StdIn.readLine.toInt)
    .take(n)
    .toVector
    .sorted
    .foldLeft(0,0)((acc,e) => {
      if(acc._2 < e) (acc._1+1, e)
      else (acc._1, e)
    })._1
  println(ans)
}

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

int A, B, C, D;

int main(){
    scanf("%d%d%d%d", &A, &B, &C, &D);
    printf("%d", min(B, D) - max(A, C) >= 0 ? min(B, D) - max(A, C): 0);
}


Measured memory_bytes: 256
n = int(input())

dp = [float('inf')]*100001
dp[0] = 0
for i in range(1,100001):
    p = 1
    while p <= i:
        dp[i] = min(dp[i], dp[i-p] + 1)
        p *= 6
    
    p = 1
    while p <= i:
        dp[i] = min(dp[i], dp[i-p] + 1)
        p *= 9

print(dp[n])

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

const int maxe = 2e5+5;

ll t=1, n, x, k;
ll arr[maxe][4];
ll dp[maxe][4];
void solve(){
	cin >> n;
	for(int i = 1; i<=n; i++){
		for(int j = 1; j<=3; j++){
			cin >> arr[i][j];
		}
	}
	for(int i = 1; i<=3; i++){
		dp[1][i] = arr[1][i];
	}
	for(int i = 2; i<=n; i++){
		dp[i][1] = max(arr[i][1] + dp[i-1][2], arr[i][1] + dp[i-1][3]);
		dp[i][2] = max(arr[i][2] + dp[i-1][1], arr[i][2] + dp[i-1][3]);
		dp[i][3] = max(arr[i][3] + dp[i-1][1], arr[i][3] + dp[i-1][2]);
	}
	ll ans = max(dp[n][1], dp[n][2]);
	ans = max(dp[n][3], ans);
	cout << ans;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	while(t--){
		solve();
	}
    return 0;
}


Measured memory_bytes: 9896
<?php
$k = trim(fgets(STDIN));

if ($k % 2 == 0) {
    echo "-1".PHP_EOL;
    exit;
}

$a = 7;
for($i = 1; $i < 1000000; ++$i) {
    if ($a % $k == 0) {
        echo $i.PHP_EOL;
        exit;
    }
    $a = $a % $k; // $kで割り切れるときは割っておく（桁あふれ防止？）
    $a = $a * 10 + 7;
}

echo "-1".PHP_EOL;

Measured memory_bytes: 16216
inf = float("INF")
x,y,z,k=map(int,input().split())
dp=[0]*3000
l =[]
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
for i in a:
  for j in b:
    l.append(i+j)
l.sort()
l = l[::-1]
t =[]
for i in l[:k]:
  for j in c:
    t.append(i+j)
t.sort()
t = t[::-1]
for i ,n in enumerate(t):
  print(n)
  if i == k-1:break

Measured memory_bytes: 163684
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#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 << '\n'; }
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__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
int fix(int x){
    return (x % 26 + 26) % 26 ; 
}
signed main(){
    fastio
    int n ;
    cin >> n ;
    string ans = "" ;
    while(n != 0){
        ans.push_back(fix(n % 26 - 1) + 'a') ; 
        if ( n % 26 == 0 ) {
            n /= 26 ; 
            n--;
        }
        else n /= 26 ; 
    }
    reverse(ans.begin(), ans.end()) ;
    cout << ans << endl;
    return 0; 
}

Measured memory_bytes: 3652
N = int(input())
h = list(map(int, input().split()))

dp = [0 for i in range(N)]
dp[1] = abs(h[1] - h[0])

for i in range(1, N-1):
    dp[i+1] = min(dp[i] + abs(h[i+1] - h[i]), dp[i-1] + abs(h[i+1] - h[i-1]))

print(dp[N-1])

Measured memory_bytes: 13928
H, W = [int(i) for i in input().split()]

candidate = [
    H // 2 + W // 3 + 1,
    H // 3 + W // 2 + 1,
    H,
    W,
]
if H % 3 == 0 or W % 3 == 0:
    candidate.append(0)
if H % 2 == 0:
    candidate.append(H // 2)
if W % 2 == 0:
    candidate.append(W // 2)

print(min(candidate))

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

using namespace std;

#define ll long long
const ll infI = 1e17;

int main(){
  int n,k;
  cin>>n>>k;
  vector<ll> h(n),dp(n,infI);
  for(int i=0;i<n;i++){
    cin>>h[i];
  }
  dp[0]=0;
  for(int i = 0;i<n;i++){
    for(int j = 1;j<=k and i+j<n;j++){
      dp[i+j] = min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
    }
  }
  cout<<dp[n-1];
}


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

int main(){
    ll N, K;
    cin >> N >> K;
    int a[2000];
    for(int i=0; i<N; i++) cin >> a[i];
    ll cnt1 = 0;
    for(int i=0; i<N; i++){
        for(int j=0; j<i; j++) if(a[j] > a[i]) cnt1++;
    }
    ll cnt2 = 0;
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++) if(a[j]>a[i]) cnt2++;
    }
    cout << (cnt1%mod * K%mod + cnt2%mod * (K*(K-1)/2%mod)%mod)%mod;
}

Measured memory_bytes: 256