akhauriyash/Code-Regression huggingface dataset:
import re

n = int(input())
w = x = y = z = 0
for i in range(n):
    s = input()
    t = re.sub(r'AB', "X", s)
    w += len(s) - len(t)
    if s[0] == "B":
        if s[-1] == "A":
            x += 1
        else:
            y += 1
    elif s[-1] == "A":
        z += 1
if x > 1:
    w += x - 1
    x = 1
if max(x, y, z) == y:
    w += x
    w += z
elif max(x, y, z) == z:
    w += x
    w += y
print(w)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=(ll)(1e9+21);
ll run();
int main() {
#ifdef home
    freopen("i", "r", stdin);
    freopen("d", "w", stderr);
#endif
    cout.precision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    run();
    return 0;
}


ll run() {
    int n;
    cin>>n;
    int h[n];
    int dp[n]={0};

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

    for(int i=1;i<n;i++) {
        dp[i]=1e9;
        for(int j=1;j<=2;j++){
            if(i-j>=0){
                dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]),dp[i]);
            }
        }
    }
    cout<<dp[n-1];
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#define int long long
using namespace std;
const int N = 1e5 + 5;
int n, s, a[N], p[N];
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
int calc(int l, int r, int x)
{
	if(s < a[l]) return a[r] - s;
	if(s > a[r]) return s - a[l];
	if(p[l] >= p[r]) return p[l] += p[r], calc(l, r - 1, l) + (x == r ? a[r] - a[l] : 0);
	else return p[r] += p[l], calc(l + 1, r, r) + (x == l ? a[r] - a[l] : 0);
}
signed main()
{
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	n = read(); s = read();
	for(int i = 1; i <= n; i ++) a[i] = read(), p[i] = read();
	printf("%lld\n", calc(1, n, p[1] < p[n] ? 1 : n));
	fclose(stdin);
	fclose(stdout);
	return 0;
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
 
typedef long long   ll;
typedef long double ld;
const int N  = 5e5+10;
const ll mod = 1e9+7;
const ll inf = 1e18;
 
#define fast            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define ub              upper_bound                 // first element >  val(itr)
#define lb              lower_bound                 // first element >= val(itr) 
#define all(x)          (x).begin(),(x).end()
#define reset(a,x)      memset(a,x,sizeof(a))       // x can be 0 or -1
#define leadzero(a)     __builtin_clz(a)            // count leading zeroes
#define trailzero(a)    __builtin_ctz(a)            // count trailing zeroes
#define bitcount(a)     __builtin_popcount(a)       // count set bits
#define iceil(n,x)      ((n)+(x)-1)/(x)
#define test            int t; cin>>t; while(t--)
#define forn(i,a,e)     for(ll i = a; i < e; i++)
#define pii             pair<int,int>
#define pll             pair<ll,ll>
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;    }
ll powm(ll base,ll exp){ll ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
ll modinv(ll n)    { ll ans=powm(n,mod-2); return ans; }
ll add(ll a,ll b)  { return (a%mod+b%mod)%mod;        }
ll sub(ll a, ll b) { return (a%mod+mod-b%mod)%mod;    }
ll mult(ll a,ll b) { return ((a%mod)*(b%mod))%mod;    }
ll choose2(ll n)   { ll ans=(n*(n-1))/2; return ans;  }
ll dist2(ll x1,ll y1,ll x2,ll y2){ ll ans=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1); return ans;}

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

	ll a[n];
	forn(i,0,n)
	cin>>a[i];

	double ans=0;
	forn(i,0,n)
	{
		ans+=(1.0/(a[i]));
	}
	ans=1.0/ans;
	cout<<fixed<<setprecision(7)<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

struct UnionFindTree {
    size_t n;
    vector<int> tree;
    UnionFindTree(size_t n): n(n) {
        tree = vector<int>(n, -1);
    }
    int find_root(size_t v) {
        if (tree[v] < 0) return v;
        return tree[v] = find_root(tree[v]);
    }
    bool unite(size_t x, size_t y) {
        x = find_root(x);
        y = find_root(y);
        if (x == y) return false;
        if (rank(x) < rank(y)) swap(x, y);
        tree[x] += tree[y];
        tree[y] = x;
        return true;
    }
    bool has_same_root(size_t x, size_t y) {
        return find_root(x) == find_root(y);
    }
    size_t rank(size_t v) {
        return -tree[find_root(v)];
    }
};

bool testcase_ends() {
    size_t N, M;
    if (scanf("%zu %zu", &N, &M) == EOF)
        return 1;

    UnionFindTree tree(N+M);
    for (size_t i=0; i<N; ++i) {
        size_t K;
        scanf("%zu", &K);
        for (size_t j=0; j<K; ++j) {
            size_t L;
            scanf("%zu", &L);
            --L;

            tree.unite(i, N+L);
        }
    }

    for (size_t i=1; i<N; ++i)
        if (!tree.has_same_root(0, i))
            return !printf("NO\n");

    printf("YES\n");
    return 0;
}

int main() {
    bool solved=false;
    while (!testcase_ends())
        solved |= 1;

    return !solved;
}


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

int main(){
    int a[3],b[3],num[5],ans1=0,ans2=0;
    for(int i=0;i<3;i++) cin >> a[i] >> b[i];
    for(int i=0;i<5;i++) num[i] = 0;
    for(int i=0;i<3;i++){
        num[a[i]]++;
        num[b[i]]++;
    }
    for(int i=1;i<5;i++){
        if(num[i]==1) ans1++;
        else if(num[i]==2) ans2++;
    }
    if(ans1==2 && ans2==2){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
loop do
  n = gets.to_i
  break if n == 0

  tw = Hash.new(0)
  n.times do
    m, a, b = gets.split(' ').map(&:to_i)
    tw[a] += m
    tw[b] += -1*m
  end

  sum = 0
  flag = true
  tw.sort_by{ |k,v| k*(10**10) + v }.each do |ti,we|
    sum += we
    if sum > 150
      flag = false
      break
    end
  end
  puts flag ? "OK" : "NG"
end

Measured memory_bytes: 6148
#include <bits/stdc++.h>
#define P pair<int,int>
#define All(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
typedef long long ll;
using namespace std;
const int INF = 1e9, MOD = 1e9 + 7;
const ll LINF = 1e18;
int main() {
	int x, y;
	cin >> x >> y;
	if (x % y == 0) {
		cout << -1 << endl;
	} else {
		cout << x << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
d = {}
for i in range(n):
    s = input()
    d[s] = d[s]+1 if (s in d) else 1
d_sorted = sorted(d.items(), key=lambda x:x[1], reverse=True)
m = d_sorted[0][1]
result = []
for i in d_sorted:
    if i[1]!=m:
        break
    result.append(i[0])
print(*sorted(result), sep='\n')

Measured memory_bytes: 48220
import java.util.*;
class Main{
    static Scanner sc=new Scanner(System.in);
    public static void main(String[] args){
        int N = sc.nextInt();
        int i=0;
        int count=1;
        String S[]=new String[N];
        int k=0;
        for(i=0;i<N;i++){
            S[i]=sc.next();
        }
        Arrays.sort(S);
        for(i=0;i<(N-1);i++){
            if(!(S[i].equals(S[i+1])))
                count++;
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 70028
n, m = map(int, input().split())
A = list(map(int, input().split()))
from itertools import accumulate
B = [0]+A
B = list(accumulate(B))
d = {}
ans = 0
for i in range(n+1):
    s = B[i]%m
    if s in d:
        ans += d[s]
        d[s] += 1
    else:
        d[s] = 1
print(ans)


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

int main() {
  // ここにプログラムを追記
int a;
int b;

cin>>a>>b;

int S = a*b;

if( S % 2 == 0){
  cout<<"Even"<<endl;
  }
else{
  cout<<"Odd"<<endl;
  }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
 
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m);i>=(int)(n);--i)
#define debug(x) cout << #x << "=" << (x) << endl;
 
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> void fail(T v){cout << v << endl;exit(0);}
//template end
const ll MOD=(int)1e9+7;
ll p(ll m,int n){
  if(n==0)return 1;
  if(n%2)return (p((m*m)%MOD,n>>1)*m)%MOD;
  else return p((m*m)%MOD,n>>1);
}
void solve(){
  int m,n;
  cin>>m>>n;
  cout<<p(m,n)<<endl;
}
 
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  solve();
  return 0;
}


Measured memory_bytes: 3208
#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<string.h>
#include<vector>
#include<cstdio>
#include<fstream>
using namespace std;
const int inf=1<<30;
vector<int> g[100001];
pair<int,int> dist[100001];
queue<int> q;
int y[100001];
bool used[100001];
int main(){
	//freopen("a.txt","r",stdin);
	int n;
	cin>>n;
	int a,b;
	for(int i=1;i<n;i++){
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dist[1].first=0;
	q.push(1);
	used[1]=true;
	while(!q.empty()){
		int x=q.front();
		q.pop();
		for(int i=0;i<g[x].size();i++){
			if(!used[g[x][i]]){
				used[g[x][i]]=true;
				dist[g[x][i]].first=dist[x].first+1;
				q.push(g[x][i]);
			}
		}
	}
	for(int i=1;i<=n;i++)
	used[i]=false;
	dist[n].second=0;
	q.push(n);
	used[n]=true;
	while(!q.empty()){
		int x=q.front();q.pop();
		for(int i=0;i<g[x].size();i++){
			if(!used[g[x][i]]){
				used[g[x][i]]=true;
				dist[g[x][i]].second=dist[x].second+1;
				q.push(g[x][i]);
			}
		}
	}
	//cerr<<endl;
	int n1=0;
	int n2=0;
	for(int i=1;i<=n;i++){
		//cout<<i<<" "<<dist[i].first<<" "<<dist[i].second<<endl;
		if(dist[i].first<=dist[i].second)n1++;
		else n2++;
	}
	if(n1>n2)cout<<"Fennec";
	else cout<<"Snuke";
	return 0;
}

Measured memory_bytes: 6784
#include<iostream> 
#include<iomanip> 
#include<vector> 
#include<map> 
#include<set> 
#include<algorithm> 
#include<numeric> 
#include<limits> 
#include<bitset> 
#include<functional> 
#include<type_traits> 
#include<queue> 
#include<stack> 
#include<array> 
#include<random> 
#include<utility> 
#include<cstdlib> 
#include<ctime>
#define _LIBCPP_DEBUG 0
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (n); i++)	
using namespace std;


int max(int a,int b) {
	int max;
	if (a > b) max = a;
	else max = b;
	return max;
}
int min(int a, int b) {
	int min;
	if (a < b) min = a;
	else min = b;
	return min;
}


int main() {
	int a, b;
	cin >> a >> b;
	if (a * b % 2 == 0) {
		cout << "Even" << endl;
	}
	else
		cout << "Odd" << endl;
}

Measured memory_bytes: 256
#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
using namespace std;
using namespace __gnu_pbds;

#define lsc(x)      scanf("%lld",&x)
#define sc(x)       scanf("%d",&x)
#define lpr(x)      printf("%lld ",x)
#define pr(x)       printf("%d ",x)
#define n_l         printf("\n")
#define VI          vector<int>
#define VII         vector<long long int>
#define MI          map<int, int>
#define PI          pair<int, int>
#define m_p         make_pair
#define pb          push_back
#define fi           first
#define se           second
#define mset(x,y)   memset(x,y,sizeof(x))
#define sz(v)       (int)v.size()
#define all(v)      v.begin(), v.end()
#define fr(i, a, n) for(int i=a;i<=n;i++)
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
const int N=(int)1e6+5;
const int mod = 1000000007;
typedef long long ll;
// order_of_key (val): returns the no. of values strictly less than val
// find_by_order (k): returns the kth largest element iterator.(0-based)
// vector<int>::iterator itr=lower_bound(v.begin(),v.end(),x);
// s.substr(pos[0-indexed], len(default=till end))
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::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...);
}
#else
#define trace(...)
#endif
int a[4][N];
int dp[4][N];
int main(){
    int n;sc(n);
    fr(i, 1, n) {
        sc(a[1][i]);sc(a[2][i]);sc(a[3][i]);
    }
    dp[1][1] = a[1][1];
    dp[2][1] = a[2][1];
    dp[3][1] = a[3][1];
    fr(i, 2, n){
        fr(j, 1, 3) fr(k, 1, 3){
            if (k==j) continue;
            dp[j][i] = max(dp[j][i], dp[k][i-1] + a[j][i]);
        }
    }
    pr(max(dp[1][n], max(dp[2][n], dp[3][n])));n_l;

    return 0;
}



Measured memory_bytes: 16640
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)

n = str(int(input()))

flag = False
if n[0] == n[1] and n[1] == n[2]:
    flag = True
if n[1] == n[2] and n[3] == n[2]:
    flag = True

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


Measured memory_bytes: 9136
program main
Implicit None
	integer A,B
	read*,A,B
	
	if(a.lt.6)	then
		write(6,"(i0)") 0
		stop
	else if(a.lt.13)	then
		write(6,"(i0)") B/2
		stop
	end if
	write(6,"(i0)") B
end program main

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
using tpl = tuple<ll, ll, ll>;
typedef pair<ll,ll> pii;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}

int N;
int X[1010];
vector<int> G[1010];

int dp1[1010];
int dp2[1010][5010];
int nexts[1010];
int par[1010];

const int INF = 1 << 29;

int rec1(int pos);
int rec2(int pos, int lef);

int rec1(int pos){
    // if(pos == -1) return 0;
    if(dp1[pos] >= 0) return dp1[pos];
    int res = 0;
    if(G[pos].size() == 0){
        res = 0;
    }
    else{
        res = rec2(G[pos][0], X[pos]);
    }
    return dp1[pos] = res;
}

int rec2(int pos, int lef){
    if(pos == -1) return 0;
    if(dp2[pos][lef] >= 0) return dp2[pos][lef];
    int res = INF;
    int next = nexts[pos];

    // 頂点と同じ色で、今回の子ノードを塗る場合
    if(lef - X[pos] >= 0)
        res = min(res, rec2(next, lef - X[pos]) + rec1(pos));
    // 頂点と異なる色で塗る場合
    if(lef - rec1(pos) >= 0)
        res = min(res, rec2(next, lef - rec1(pos)) + X[pos]);
    return dp2[pos][lef] = res;
}


int main(){

    cin >> N;
    par[0] = -1;
    for(int i = 0; i < N - 1; i++){
        int p; cin >> p;
        p--;
        G[p].push_back(i + 1);
        par[i + 1] = p;
    }

    for(int i = 0; i < N; i++){
        nexts[i] = -1;
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < (int)G[i].size()-1; j++){
            nexts[G[i][j]] = G[i][j+1];
        }
    }

    for(int i = 0; i < N; i++)
        cin >> X[i];
    for(int i = 0; i < N; i++){
        dp1[i] = -1;
        for(int j = 0; j < 5010; j++){
            dp2[i][j] = -1;
        }
    }

    if(rec1(0) == INF) {
        cout << "IMPOSSIBLE" << endl;
    }
    else{
        cout << "POSSIBLE" <<endl;
    }

    
    return 0;
}


Measured memory_bytes: 19968
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
	long long a, b, x;
	cin >> a >> b >> x;

	long long ans = b / x + 1;
	long long vv = (a / x);
	if (a % x == 0) vv -= 1;
	long long v2 = (b / x);

	cout << v2 - vv << endl;
	return 0;
}

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

int main()
{
// 前からGreedy
  int n;
  cin >> n;
  vector<long long> a(n + 1);
  for(int i = 0; i < n; i++)
  {
    cin >> a[i + 1];
  }
  long long ans = 0;
  for(int i = 1; i <= n; i++)
  {
    ans += (a[i - 1] + a[i]) / 2;
    if((a[i - 1] + a[i]) % 2 == 0 || a[i] == 0)
    {
      a[i] = 0;
    }
    else
    {
      a[i] = 1;
    }
  }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4036
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
typedef pair<int, int> P;

const int INF = 100000000;

int dl[201][201], ds[201][201], n, m, dp[1000][201];

int main(){
	int x, y, t, r, z, rz;
	char sl;
	
	while(1){
		scanf("%d%d",&n,&m);
		if(n == 0) return 0;
		
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++){
				dl[i][j] = INF;
				ds[i][j] = INF;
			}
		}
		for(int i = 1; i <= n; i++){ dl[i][i] = 0; ds[i][i] = 0;}
		
		for(int i = 0; i < m; i++){
			scanf("%d%d%d %c",&x,&y,&t,&sl);
			
			if(sl == 'L'){
				dl[x][y] = t;
				dl[y][x] = t;
			} else {
				ds[x][y] = t;
				ds[y][x] = t;
			}
		}
		
		for(int k = 1; k <= n; k++){
			for(int i = 1; i <= n; i++){
				for(int j = 1; j <= n; j++){
					dl[i][j] = min(dl[i][j], dl[i][k] + dl[k][j]);
					ds[i][j] = min(ds[i][j], ds[i][k] + ds[k][j]);
				}
			}
		}
		
		
		scanf("%d%d",&r,&rz);
		
		for(int i = 1; i <= 200; i++){
			for(int j = 0; j < r; j++){
				dp[j][i] = INF;
			}
		}
		dp[0][rz] = 0;
		
		
		for(int k = 1; k < r; k++){
			scanf("%d",&z);
			for(int i = 1; i <= n; i++){
				for(int j = 1; j <= n; j++){
					dp[k][i] = min(dp[k][i], dp[k-1][j] + dl[rz][j] + ds[j][i] + dl[i][z]);
					if(i == j) dp[k][i] = min(dp[k][i], dp[k-1][j] + dl[rz][z]);
				}
			}
			
			rz = z;
		}
		
		int ans = INF;
		for(int i = 1; i <= n; i++) ans = min(ans, dp[r-1][i]);
		
		printf("%d\n",ans);
	}
}


Measured memory_bytes: 3816
import sys

A=[]
B=[]
NM=input().split(" ")
N=int(NM[0])
M=int(NM[1])

for i in range(N):
    t=input()
    A.append(t)
for i in range(M):
    t=input()
    B.append(t)



for i in range(N-M+1):
    for j in range(N-M+1):
        k=i
        count=0
        while A[k+count][j:M+j:1]==B[count]:
            count+=1
            if count==M:
                print("Yes")
                sys.exit()

print("No")


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

int main(){
  int N;
  cin >> N;
  vector<long> H(N);
  for(int i = 0; i < N; i++) cin >> H.at(i);
  vector<long> R(2, 0);
  long now;
  long next = H.at(0);
  for(int i = 0; i < N-1; i++){
    now = next;
    next = H.at(i+1);
    if(now >= next){
      R.at(0)++;
//      cout << "R0 = " << R.at(0) << endl;
    }
    else{
      if(R.at(1) < R.at(0)){
        R.at(1) = R.at(0);
        R.at(0) = 0;
      }else R.at(0) = 0;
    }
  }
  if(R.at(1) < R.at(0)) R.at(1) = R.at(0);
  cout << fixed;
  cout << setprecision(12) << R.at(1) << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
 ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int t=1;
//   cin>>t;
  while(t--){
   	 int r,g,b,k;
   	 cin>>r>>g>>b>>k;
   	 int ans=0;
      while(g<=r){
          g=g*2;
          ans++;
      }
      while(b<=g){
          b=b*2;
          ans++;
      }
      if(ans>k){
          cout<<"No\n";
      }
      else
      cout<<"Yes\n";
       
  }
   return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
const int N =1e6+5;
const long long M = (long long)1e9+7;
#define     ll      long long
int Int() {
    int x;
    scanf("%d",&x);
    return x;
}
ll Long() {
    ll x;
    scanf("%I64d",&x);
    return x;
}
void Char(char* ch) {
    scanf("%s",ch);
}
template<typename t>t abs(t a) {
    if(a>=0)return a;
    return -a;
}
#define     Int         Int()
#define     Long        Long()
#define     pii         pair<int,int>
#define     vi          vector<int>
#define     vl          vector<ll>
#define     pb          push_back
#define     all(x)      x.begin(),x.end()
#define     LB          lower_bound
#define     UB          upper_bound
#define     Mx(a,b)     (a>b)?a:b
#define     Mn(a,b)     (a<b)?a:b

int main() {
    int n=Int;
    int m=n;
    int d=0;
    while(n)
    {
        d=(d*10)+(n%10);
        n/=10;
    }
    (d==m)?puts("Yes"):puts("No");
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int num(int n){ 
    int count=2;
    for(int i=2;i<=sqrt(n);i++){
        if(n%i==0){
            if(i==sqrt(n)&&n/i==i)count++;
            else count+=2;}}
    return count;}
int main(){
	int n;
	cin>>n;
	int cnt=0;
	for(int i=1;i<=n;i+=2){
    	if(num(abs(i))==8)cnt++;}
    cout<<cnt<<endl;
  return 0;
}
//105    135      165     189       195

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * b.cc: D: Fennec VS. Snuke
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef vector<int> vi;
typedef queue<int> qi;

enum { NA, BL, WH };

/* global variables */

vi nbrs[MAX_N];
int ds[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n - 1; i++) {
    int ai, bi;
    scanf("%d%d", &ai, &bi);
    ai--, bi--;
    nbrs[ai].push_back(bi);
    nbrs[bi].push_back(ai);
  }

  ds[0] = BL, ds[n - 1] = WH;
  qi q;
  q.push(0), q.push(n - 1);

  int bn = 0, wn = 0;
  while (! q.empty()) {
    int u = q.front(); q.pop();

    if (ds[u] == BL) bn++;
    else wn++;

    vi &nbru = nbrs[u];
    for (vi::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
      int &v = *vit;
      if (ds[v] == NA) {
	ds[v] = ds[u];
	q.push(v);
      }
    }
  }

  if (bn > wn) puts("Fennec");
  else puts("Snuke");

  return 0;
}


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

#pragma region Macros
using ll = long long;
#define int ll
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
#define IOS\
    ios::sync_with_stdio(false);\
    cin.tie(0);\
    cout.tie(0);
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SORT(name) sort(name.begin(), name.end())
#define RSORT(name)\
    SORT(name);\
    reverse(all(name));
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
template <class T> inline void print(T x){ cout << x << '\n';}
template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
#pragma endregion

#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const int MOD = 1000000007;
const int MAX_N = 100010;

signed main() {
    IOS;

    int N;
    V<> A;
    cin >> N;
    A.resize(N);
    REP(i, N) {
        cin >> A[i];
    }

    V<> cnt(32, 0); // i ビット目の 1 の数
    REP(i, N) {
        REP(j, 31) {
            if((A[i] >> j) & 1) {
                cnt[j]++;
            }
        }
    }

    V<> ans_v;
    REP(i, N) {
        int ans = 0;
        REP(j, 31) {
            if(cnt[j] % 2 == 0) {
                if((A[i] >> j) & 1) {
                    ans |= (1 << j);
                }
            }
            else {
                if(!((A[i] >> j) & 1)) {
                    ans |= (1 << j);
                }
            }
        }
        ans_v.pb(ans);
    }
    REP(i, ans_v.size()) {
        if(i == ans_v.size() - 1) {
            printf("%lld\n", ans_v[i]);
        }
        else {
            printf("%lld ", ans_v[i]);
        }
    }

    return 0;
}


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

#define mp make_pair
#define pb push_back
#define st first
#define nd second

typedef long long ll;
typedef pair < int , int > pp;
const int mod = 1e9 + 7;
const int N   = 2e5 + 5;

int a,b,c,x,y,t,mn;

int main(){
    cin >> a >> b >> c >> x >> y;
    if(c+c < a+b){
        mn = min(x,y);
        t += mn*c*2;
        x -= mn;
        y -= mn;
    }

    if(c+c < a){
        t += x*c*2;
        x = 0;
    }

    if(c+c < b){
        t += y*c*2;
        y = 0;
    }

    cout << t + x*a + y*b;
    return 0;
}

Measured memory_bytes: 256
module ABC081B
	sub Main(ByVal args() as String)
		dim i,n,x,r as integer
		r=1<<29
		n=Console.ReadLine()
		dim arr(n) as string
		arr=Split(Console.ReadLine())
		for i=1 to n
			dim r0 as integer
			r0=0
			x=arr(i-1)
			while (x mod 2)<1
				r0+=1
				x\=2
			end while
			if r>r0
				r=r0
			end if
		next
		Console.WriteLine(r)
	end sub
end module


Measured memory_bytes: 13532
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int A = in.nextInt();
        int B = in.nextInt();
        int C = in.nextInt();
        int X = in.nextInt();
        int count=0;
        for(int i=0; i<=A;i++){
            for(int j=0; j<=B;j++){
                for(int k=0; k<=C; k++){
                    if(500*i + 100*j + 50*k==X){
                        count++;
                    }
                }
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
 
 
const long long MOD = 998244353;
 
vector<int> parent;
 
int getRoot(int idx) {
    if(parent[idx] != idx) {
        parent[idx] = getRoot(parent[idx]);
    }
    return parent[idx];
}
 
 
void fusion(vector<tuple<int,int,int> > &coordinates, int left, int right) {
 
    if(right-left <= 0) {
        return  ;
    }
    int mid = (left + right+1) / 2;
 
 
    fusion(coordinates, left, mid-1);
    fusion(coordinates, mid, right);
 
    pair<int,int> miniY = make_pair(1e8,0), maxiY = make_pair(-1e8,0);
 
    for(int c=left;c<mid;c++) {
        miniY = min(miniY, make_pair(get<1>(coordinates[c]),get<2>(coordinates[c])));
    }
 
    for(int c=mid;c<=right;c++) {
        maxiY = max(maxiY, make_pair(get<1>(coordinates[c]),get<2>(coordinates[c])));
    }
 
 
    int rMaxi = getRoot(maxiY.second);
    for(int c=left;c<mid;c++) {
        if(get<1>(coordinates[c]) > maxiY.first) continue;
        int r = getRoot(get<2>(coordinates[c]));
        parent[r] = rMaxi;
    }
 
    int rMini = getRoot(miniY.second);
    for(int c=mid;c<=right;c++) {
        if(get<1>(coordinates[c]) < miniY.first) continue;
        int r = getRoot(get<2>(coordinates[c]));
        parent[r] = rMini;
    }
}
 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    int N;
    cin>>N;
    vector<tuple<int,int,int> > coordinates(N);
 
    for(int c=0;c<N;c++){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        coordinates[c] = make_tuple(a,b,c);
    }
 
    sort(coordinates.begin(),coordinates.end());
    parent.resize(N);
    for(int c=0;c<N;c++) parent[c]=c;
 
 
    fusion(coordinates, 0, N-1);
 
    vector<int> res(N);
 
    vector<int> taillePerRoot(N,0);
    for(int c=0;c<N;c++) taillePerRoot[getRoot(c)]++;
 
    for(int c=0;c<N;c++) {
        cout<<taillePerRoot[getRoot(c)]<<"\n";
    }
 
}

Measured memory_bytes: 7940
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long MOD = 1000000007;
    const int N = 13;
    string s;
    long dp[N] = {0};

    cin >> s;
    int LEN = s.length();

    dp[0] = 1;
    for (int i = 0; i<LEN; i++){
        long next_dp[13] = {0}; // これを作らないと変に上書きされちゃう
        // ?だったら全部当てはめてみる
        if(s[i] == '?'){
            for (int j = 0; j<10; j++){
                for (int k = 0; k<N; k++){
                    next_dp[(j + k*10 ) % N] += dp[k];
                    next_dp[(j + k*10 ) % N] %= MOD;
                }
            }
        // 普通の数字
        }else{
            int j = s[i] - '0'; // 文字->数字変換
            for (int k = 0; k<N; k++){
                next_dp[(j + k*10 ) % N] += dp[k];
                next_dp[(j + k*10 ) % N] %= MOD;
            }
        }
        // 配列コピー
        for (int l=0; l<N; l++){
            dp[l] = next_dp[l];
        }
    }

    cout << dp[5] << endl;
}


Measured memory_bytes: 512
#include <stdio.h>

int f[50];

int main()
{
  int n,i;
  scanf("%d",&n);
  f[0]=1;
  f[1]=1;
  for(i=2;i<=n;i++)
    {
      f[i]=f[i-1]+f[i-2];
    }

  printf("%d\n",f[n]);

  return 0;
}



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

int main(){
  int h, w, n;
  cin >> h >> w >> n;
  int ans=0;
  if(h<w){
    ans = n/w;
    if(n%w!=0)ans++;
  }
  else{
    ans = n/h;
    if(n%h!=0)ans++;
  }
  cout << ans ;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
typedef long long int LL;
#define fr(i,p,n) for(LL i=p;i<n;i++)
#define fr1(i,p,n) for(LL i=p;i>=n;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define PI 3.14159265358979323846
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define precise cout << std::setprecision(10) << std::fixed;
#define MAXN   1000000000001
using namespace std;
int main()
{
  LL N;
  cin>>N;
  LL ans=0;
  LL M=N;
  LL k;
  for(LL i=2;i*i<N;i++)
  {
    k=i;
    
    while(N%k==0)
    {
      ans++;
      N/=k;
      k*=i;      
    }
    
    while(N%i==0)
    {
      
      N/=i;      
    }
    
  }
  
  if(N>1) ans++;
  cout<<ans<<endl;
}

Measured memory_bytes: 3640
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
 
const int inf = 99999999;
const ll linf = 999999999999999999;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#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 ret return
 
ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

////////////////////////////////////////////////////////////

int main(){
  unsigned int N;
  cin >> N;
  unsigned int a[N];
  bool b[N];
  
  rep(i,0,N){
    cin >> a[i];
    b[i] = false;
  }
  unsigned int sum = 0;
  unsigned int num = 1; 
  while(1){
    if(a[num - 1] == 2){
      cout << sum + 1<< endl;
      return 0;
    }
      
    
    if(b[num - 1]){
      cout << "-1" << endl;
      return 0;
    }
    
    b[num - 1] = true;
    sum++;
    num = a[num - 1];
    //cout << "num:" << num << endl;
  }

    

  return 0;
}

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

int N;
string S;
#define MAXN 300000
int W[MAXN], E[MAXN];
int R = MAXN;

int main() {
  cin >> N >> S;
  for(int i = 0; i < (int)S.size() - 1; ++i) {
    W[i + 1] = W[i] + (S[i] == 'W');
  }
  for(int i = (int)S.size() - 1; i >= 1; --i) {
    E[i - 1] = E[i] + (S[i] == 'E');
  }
  for(int i = 0; i < (int)S.size(); ++i) {
    R = min(R, W[i] + E[i]);
  }
  cout << R << endl;
  return 0;
}


Measured memory_bytes: 3076
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
#define llMAX 9223372036854775807LL
#define llMIN -9223372036854775808LL
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll a,v,b,w,t;

int main(){
  ll ans=0;
  cin >> a>>v>>b>>w>>t;
  ll sa=abs(b-a);
  ll spd=v-w;

  if (b==a){
    cout<<"YES"<<endl;
    return 0;
  }

  if (v<=w){
    cout<<"NO"<<endl;
    return 0;
  }

  
  if (sa<=spd*t){
    cout<<"YES"<<endl;
  return 0;
  }else{
    cout<<"NO"<<endl;
  return 0;
  }
  

  return 0;
}

Measured memory_bytes: 3632
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    n, k = map(int, input().split())
    if 2 * k - n > 1:
        print(-1)
        exit()
    a = k + n // 2
    b = k + n
    c = k + 2 * n
    ab = []
    for i in range(n):
        ab.append([a, b])
        a, b = a + 1, b + 1
        if a == k + n: a = k
    ab.sort(key=lambda x: x[0] + x[1])
    for a, b in ab:
        print(a, b, c)
        c += 1

main()


Measured memory_bytes: 24308
local mab, mce, mfl, msq, mmi, mma = math.abs, math.ceil, math.floor, math.sqrt, math.min, math.max
local ior = io.input()
local n, m = ior:read("*n", "*n")
local left, right = ior:read("*n", "*n")
for i = 2, m do
  local x, y = ior:read("*n", "*n")
  left, right = mma(left, x), mmi(right, y)
end
if left <= right then
  print(right - left + 1)
else
  print(0)
end


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	double n, k, tmp1;
	double result = 0, tmp;
	cin >> n >> k;
	REP(i, 1, n+1){
		tmp = 1/n;
		tmp1 = i;
		while(tmp1 < k){
			tmp1 *= 2;
			tmp /= 2;
		}
		result += tmp;
	}
	cout << fixed << setprecision(9) << result;
	


}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>

typedef long long lint;

using namespace std;

// dpテンプレ
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

const lint INF = 10e9;

//入力
int n;
lint h[100000];
//dpテーブル
lint dp[100000];

int main(){
  int n,i;
  lint ans;
  cin >> n;
  for(i = 0; i < n; i++){
    cin >> h[i];
  }

  for(i = 0; i < n; i++){
    dp[i] = INF;
  }
  //初期条件
  dp[0] = 0;
  
  for(i = 1; i < n; i++){
    chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
    if(i > 1){
      chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }
  }
  ans = dp[n - 1];
  cout << ans;
}

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

const int MOD = (int)1e9+7;

int main(){
  int N,M,C;
  cin >> N >> M >> C;
  vector<int> B(M);
  vector<vector<int>> A(N,vector<int>(M));
  for(int i=0;i<M;i++)  cin >> B.at(i);
  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++){
      cin >> A.at(i).at(j);
    }
  }

  int ans=0;
  for(int i=0;i<N;i++){
    int x=0;
    for(int j=0;j<M;j++){
      x+=A.at(i).at(j)*B.at(j);
    }
    x+=C;
    if(x>0) ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as MP

step :: MP.Map String Int -> String -> MP.Map String Int
step mp x = MP.insertWith (+) x 1 mp

step' :: Int -> Int -> Int
step' acc v
    | v == 1 = acc
    | otherwise = acc + sum [1..v-1]

main = do
    n <- readLn :: IO Int
    xs <- V.replicateM n (B.unpack . B.sort <$> B.getLine)
    let mp = V.foldl' step MP.empty xs
    print $ MP.foldl step' 0 mp

Measured memory_bytes: 77180
def c_Sequence(N, A):
    total = 0  # 変化量の総量
    tmp1 = 0  # 条件を満たすために今見ている項をどれだけ変化させるか
    for i in range(N):
        total += A[i]
        # 奇数番目を正に、偶数番目を負にする(0-indexedで)
        if i % 2 == 0:
            if total >= 0:
                tmp1 += abs(-1 - total)
                total -= abs(-1 - total)
        else:
            if total <= 0:
                tmp1 += 1 - total
                total += 1 - total

    total = 0
    tmp2 = 0
    for i in range(N):
        total += A[i]
        # 奇数番目を負に、偶数番目を正にする
        if i % 2 == 0:
            if total <= 0:
                tmp2 += 1 - total
                total += 1 - total
        else:
            if total >= 0:
                tmp2 += abs(-1 - total)
                total -= abs(-1 - total)
    ans = min(tmp1, tmp2)
    return ans
N = int(input())
A = [int(i) for i in input().split()]
print(c_Sequence(N, A))

Measured memory_bytes: 14468
def isOdd(x : int) -> bool:
    if len(str(x)) % 2 == 1:
        return True
    else: return False

def main(): 
    n = int(input())
    cnt = 0
    for i in range(1, n+1):
        if isOdd(i):
            cnt += 1
    print(cnt)
if __name__ == "__main__":
    main()

Measured memory_bytes: 2940
#define _USE_MATH_DEFINES // for C++  
#include "bits/stdc++.h"
using LL = long long;
using ULL = unsigned long long;
#define NUM 1000000007

inline int ctoi(char c) {
    if (c >= '0' && c <= '9') {
        return c - '0';
    }
    std::cout << "例外：数字ではない文字をintに変換しようとしました";
    throw;
}

using namespace std;

int main()
{
    string s;
    cin >> s;
    int a, b, c, d;
    a = ctoi(s[0]);
    b = ctoi(s[1]);
    c = ctoi(s[2]);
    d = ctoi(s[3]);
    if (a + b + c + d == 7)
    {
        cout << a << '+' << b << '+' << c << '+' << d << '=' << 7 << endl;
        return 0;
    }
    if (a + b + c - d == 7)
    {
        cout << a << '+' << b << '+' << c << '-' << d << '=' << 7 << endl;
        return 0;
    }

    if (a + b - c + d == 7)
    {
        cout << a << '+' << b << '-' << c << '+' << d << '=' << 7 << endl;
        return 0;
    }
    if (a + b - c - d == 7)
    {
        cout << a << '+' << b << '-' << c << '-' << d << '=' << 7 << endl;
        return 0;
    }

    if (a - b + c + d == 7)
    {
        cout << a << '-' << b << '+' << c << '+' << d << '=' << 7 << endl;
        return 0;
    }
    if (a - b + c - d == 7)
    {
        cout << a << '-' << b << '+' << c << '-' << d << '=' << 7 << endl;
        return 0;
    }
    if (a - b - c + d == 7)
    {
        cout << a << '-' << b << '-' << c << '+' << d << '=' << 7 << endl;
        return 0;
    }
    if (a - b - c - d == 7)
    {
        cout << a << '-' << b << '-' << c << '-' << d << '=' << 7 << endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  ll L;
  cin >> L;

  vector<ll> v(25,1);
  REP(i,1,v.size()){
    v[i] = v[i-1] * 2;
  }

  ll N = 0;
  while(v[N] <= L) N++;

  vector<ll> w(N,0);
  ll l = L;
  for(int i=N-1; i>=0; i--){
    if(v[i] <= l){
      w[i] = 1;
      l -= v[i];
    }
  }

  vector<vector<ll>> ret;
  ll x = 1;
  rep(i,N-1){
    ret.push_back({i+1,i+2,0});
    ret.push_back({i+1,i+2,x});
    x *= 2;
  }
  x = L;
  for(int i=w.size()-1; i>=0; i--){
    if(w[i] == 1){
      x -= v[i];
      if(i == w.size()-1){
        ret[ret.size()-2][2] += x;
        ret[ret.size()-1][2] += x;
      }else{
        ret.push_back({i+1, N,x});
      }
    }
  }

  cout << N << " " << ret.size() << endl;
  rep(i,ret.size()){
    cout << ret[i][0] << " " << ret[i][1] << " " << ret[i][2] << endl;
  }
  return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define xx first
#define yy second
#define sci(n) scanf("%d",&n)
#define scii(n,m) scanf("%d%d",&n,&m)
#define sciii(n,m,w) scanf("%d%d%d",&n,&m,&w)
#define scl(n) scanf("%lld",&n)
#define scll(n,m) scanf("%lld%lld",&n,&m)
#define sclll(n,m,w) scanf("%lld%lld%lld",&n,&m,&w)
#define pf(a)   printf("%d\n",a)
#define CASE(a) printf("Case %d:\n",a)
#define dbg(i) printf("yo %lld\n", i)
#define endl '\n'
#define READ  freopen("input.txt","r",stdin)
#define WRITE freopen("output.txt","w",stdout);
#define pi acos(-1)
#define mem(a,b) memset(a,b,sizeof(a))
#define SQR(a) (a)*(a)
#define all(v) v.begin(),v.end()
#define pb push_back
#define pri priority_queue<int>
#define rev_pri priority_queue<int,vector<int>,greater<int> >
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define inf INT_MAX
#define eps 1e-9

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

using namespace __gnu_pbds;
using namespace std;


#define mxn 100005


//bool vis[1LL << 19];
const ll nax=100005;
vector<ll>v[nax];
ll ar[nax],LP;
bool vis[nax];
ll dfs(ll sr)
{
    vis[sr]=1;
    ll ln=0;
    for(ll i=0;i<v[sr].size();i++){
        if(vis[v[sr][i]]==0){
            ln=max(ln,dfs(v[sr][i])+1);
        }else ln=max(ln,ar[v[sr][i]]+1);
    }
    ar[sr]=ln;
    if(ln>LP){LP=ln;}
    return ln;
}
void solve()
{
    ll a,b,n,w,k=0,c,i,q=0,j,l,m,mx=-1;
    cin>>n>>m;
    FOR(i,1,m+1){
        scll(a,b);
        v[a].pb(b);
    }
    FOR(i,1,n+1)if(vis[i]==0)w=dfs(i);
    //FOR(i,1,n+1) cout<<ar[i]<<' ';
    //cout<<endl;
    cout<<LP<<'\n';
}
int main()
{
    //IOS;
    double start_time = clock();
    ll t=1,mex=1;
   //cin>>t;
    while(t--){
        solve();
    }
    double end_time = clock();
    //fprintf(stderr, "Time = %lf\n", (end_time - start_time) / CLOCKS_PER_SEC);
    return 0;
}


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

int main() {
    int K;
    int e, o;
    cin >> K;
    if (K % 2 == 0) {
	e = K/2;
    o = K/2;
    }
  	else {
      e = K/2;
      o = K/2 + 1;
    }
    cout << e*o << endl;
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> b(n - 1);
    rep(i, n - 1) cin >> b[i];
    long long sum = b[0];
    rep(i, n - 2) sum += min(b[i], b[i + 1]);
    sum += b[n - 2];
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;






int main(){
    map<ll,ll> A,B;
    ll n;
    cin>>n;
    vector<ll> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(i%2==0){A[a[i]]++;}
        else{B[a[i]]++;}
    }
    vector<pll> p,q;
    for(auto i=A.begin();i!=A.end();i++){
        p.push_back({(*i).S,(*i).F});
    }
    for(auto i=B.begin();i!=B.end();i++){
        q.push_back({(*i).S,(*i).F});
    }
    sort(p.begin(),p.end(),greater<pll>());
    sort(q.begin(),q.end(),greater<pll>());
    if(p[0].S!=q[0].S){cout<<n-p[0].F-q[0].F<<endl;}
    else{
        ll mi=n;
        if(p.size()>1){mi=min(mi,n-p[1].F-q[0].F);}
        mi=min(mi,n-p[0].F);
        if(q.size()>1){mi=min(mi,n-p[0].F-q[1].F);}
        mi=min(mi,n-q[0].F);
        cout<<mi<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 9592
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define fir first
#define sec second
#define Rep(x,y,z) for(int x=y;x<=z;++x)
#define Red(x,y,z) for(int x=y;x>=z;--x)
using namespace std;
const int MAXN=605;
char buf[1<<12],*p1=buf,*p2=buf,nc;int ny;
inline char gc() {return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<12,stdin),p1==p2)?EOF:*p1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;ny=1;while(nc=gc(),(nc<48||nc>57)&&nc!=EOF)if(nc==45)ny=-1;if(nc<0)return nc;
	x=nc-48;while(nc=gc(),47<nc&&nc<58&&nc!=EOF)x=(x<<3)+(x<<1)+(nc^48);return x*ny;
}
int n,d1,d2,p[2][MAXN][MAXN],tot,sz[2][2];
inline void Col(int d,int p[][MAXN]){
	int k=0;for(;d%(1<<(2*(k+1)))==0;k++);k=1<<k;
	int v=(d/(k*k))%4;if(v==0||v==3)return;
	Rep(i,0,n-1)Rep(j,0,n-1)p[i][j]=(v&1?(i/k+j/k)&1:(i/k)&1);
}
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read(),d1=read(),d2=read(),tot=n*n,n<<=1;
	Col(d1,p[0]),Col(d2,p[1]);
	Rep(i,0,n-1)Rep(j,0,n-1)sz[p[0][i][j]][p[1][i][j]]++;
	int Mx=0,ox,oy;
	Rep(i,0,1)Rep(j,0,1)if(sz[i][j]>Mx)Mx=sz[i][j],ox=i,oy=j;
	Rep(i,0,n-1)Rep(j,0,n-1)if(p[0][i][j]==ox&&p[1][i][j]==oy){
		cout<<i<<" "<<j<<"\n";if(--tot==0)return 0;
	}
	return 0;
}




Measured memory_bytes: 3840
import std.algorithm;
import std.bigint;
import std.bitmanip;
import std.concurrency : generator = Generator, yield;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;

alias Testimony = Tuple!(long, long);

void main() {
    long N = readln.chomp.to!long;

    Testimony[][] testimony;
    foreach (a; 0 .. N) {
        Testimony[] testimony_of_a;
        long A = readln.chomp.to!long;
        foreach (i; 0 .. A) {
            auto t = readln.chomp.split.map!(to!long);
            testimony_of_a ~= tuple(t[0], t[1]);
        }
        testimony ~= testimony_of_a;
    }

    long ans;
    for (long c = 0; c < (1 << N); c++) {
    long[] honests = iota(N).picks(scanbits(c, N)).array;
        if (isValid(honests, testimony))
            ans = ans.max(honests.length);
    }

    writeln(ans);
}

bool isValid(long[] honests, Testimony[][] testimony) {
    foreach (h; honests) {
        foreach (t; testimony[h]) {
            auto target = t[0] - 1;
            auto type = t[1];
            if (type == 0 && honests.canFind(target))
                return false;
            if (type == 1 && !honests.canFind(target))
                return false;
        }
    }
    return true;
}

auto scanbits(long x, long length) {
    return iota(length).map!(i => ((x >> i) & 1) == 1);
}

auto picks(R1, R2)(R1 range, R2 flags) {
    return zip(range, flags).filter!"a[1]".map!"a[0]";
}

Measured memory_bytes: 1276