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

int main() {
int a,b,c,d,l,r;
cin>>a>>b>>c>>d;
l=a+b;
r=c+d;
if(l>r){
cout<<"Left"<<endl;
}else if(l==r){
cout<<"Balanced"<<endl;
}else if(l<r){
cout<<"Right"<<endl;
}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int h = scan.nextInt();
        int w = scan.nextInt();
        int n = scan.nextInt();
        int a[] = new int[n];
        for(int i = 0;i < n;i++){
            a[i] = scan.nextInt();
        }
        int map[][] = new int[h][w];
        int num = 1;
        boolean dir = true;
        for(int i = 0;i < h;i++){
            for(int j = 0;j < w;j++){
                if(dir) {
                    map[i][j] = num;
                }else{
                    map[i][w-j-1] = num;
                }
                a[num-1]--;
                if(a[num-1] == 0)num++;
            }
            dir = !dir;
        }

        for(int i = 0;i < h;i++){
            for(int j = 0;j < w;j++){
                System.out.print(map[i][j]+" ");
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 34812
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define ll long long
#define cpp boost::multiprecision::cpp_int
#define dequeue deque
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = 1; i <= n; i++)
int mod = 1'000'000'000 + 7;
const double PI = 3.1415926535897932384626433832795;
void COME_LET_THE_GAMES_BEGIN() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << setprecision(20);
}
int N, M;
priority_queue<int> q;
vector<int> v[100010];
int main() {
	COME_LET_THE_GAMES_BEGIN();
	cin >> N >> M;
	rep(i, N) {
		int A, B;
		cin >> A >> B;
		if (M - A >= 0) {
			v[M - A].push_back(B);
		}
	}
	int ans = 0;
	for (int i = M; i >= 0; i--) {
		for (auto x: v[i]) {
			q.push(x);
		}
		if (!q.empty()) {
			ans += q.top();
			q.pop();
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 5632
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>

using namespace std;
using i64=long long int;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &e: a) cin >> e;

    int cur = 1;
    int ans = 0;
    for (int i = 1; i < n; ++i) {
        if (a[i] != a[i-1]) {
            ans += cur / 2;
            cur = 1;
        } else {
            ++cur;
        }
    }
    ans += cur / 2;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int N,M,s;
	int K[10000];
	int k1[30];
	int count=0;
	scanf("%d %d",&N,&M);
		for(int i=1;i<=N;i++){
			scanf("%d",&K[i]);
				for(int j=1;j<=K[i];j++){
					scanf("%d",&s);
					k1[s]++;
				}
		}

		for(int i=1;i<=M;i++){
			if(k1[i]==N){
				count+=1;
			}
		}
	printf("%d",count);
	return 0;
}

Measured memory_bytes: 128
def a():
    A, B, C = list(map(int, input().split()))
    cnt = 0
    rcd = []
    while True:
        if A%2==1 or B%2==1 or C%2==1:
            break
        if [A,B,C] in rcd:
            cnt = -1
            break
        rcd.append([A,B,C])
        A, B, C = B/2+C/2, A/2+C/2, A/2+B/2 # exchange
        cnt += 1
    print(cnt)
    return

a()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 10;
int n;
int a[maxn], b[maxn], c[maxn];
ll ans;
void solve(int x)
{
	int r = (1 << x) - 1, l = 1 << (x - 1);
	for(int i = 1; i <= n; ++i) c[i] = b[i] & r;
	sort(c + 1, c + n + 1);
	ll tot = 0;
	for(int i = 1; i <= n; ++i)
	{
		int L = l - (a[i] & r); while(L < 0) L += 1 << x;
		int R = r - (a[i] & r); while(R < 0) R += 1 << x;
		if(L <= R)
			tot += upper_bound(c + 1, c + n + 1, R) - lower_bound(c + 1, c + n + 1, L);
		else
			tot += upper_bound(c + 1, c + n + 1, R) + n - lower_bound(c + 1, c + n + 1, L);
	}
	if(tot & 1) ans |= l;
}
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	for(int i = 1; i <= n; ++i) scanf("%d", &b[i]);
	for(int i = 1; i <= 29; ++i)
		solve(i);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
// @Author :- Gaurav Bharti
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define empb emplace_back
#define mp make_pair
#define F first
#define S second
#define vii vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vpii vector<pii>
#define mapii map<int,int> 
#define mapll map<ll,ll>
#define all(a) a.begin(),a.end()
#define test ll t; cin>>t; while(t--)
#define prec(n) fixed<<setprecision(n)
#define ItsFUN ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007



int main(){
	
	ll a, b, c, d ;cin >> a >> b >> c >> d;
	cout << max({a*c, a*d, b*c, b*d}) << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
#include<assert.h>

using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
//SOLVE


void solve(void)
{
  int N,M;
  cin>>N>>M;
  vector<int> vec (N,0);
  priority_queue<int> pq;
  for (int i = 0; i < N; i++)
  {
    int X;cin>>X;
    pq.push(X);
  }
  for (int i = 0; i < M; i++)
  {
    int X = pq.top();
    pq.pop();
    pq.push(X/2);
  }
  int SUM = 0;
  while(!pq.empty())
  {
    SUM += pq.top();
    pq.pop();
  }
  cout<<SUM<<endl;
  
  

  
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Measured memory_bytes: 2168
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
using namespace std;
int a,b,c;
int main(){
	scanf("%d%d%d",&a,&b,&c);
	if((a&1^1)|(b&1^1)|(c&1^1))return puts("0"),0;
	printf("%lld\n",min(1ll*a*b,min(1ll*a*c,1ll*b*c)));
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
  int A,B,C,D; cin>>A>>B>>C>>D;
  while(1) {
    C -= B;
    if (C<=0) {
      cout<<"Yes"<<endl;
      break;
    }
    A -= D;
    if (A<=0) {
      cout<<"No"<<endl;
      break;
    }
  }
}

Measured memory_bytes: 3592
#include <algorithm>
#include <cmath>
#include <climits>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <numeric>
#include <vector>
#include <map>

using namespace std;
using ll = long long;
template<typename T> void print(T t) {cout << t << endl;}

vector<pair<ll, int>> prime_factorize(ll n) {
    vector < pair < ll, int >> res;
    int num = 0;
    while (n % 2 == 0) {
        num++;
        n /= 2;
    }
    if (num != 0) res.emplace_back(make_pair( 2, num ));

    for (ll p = 3; p * p <= n; p += 2) {
        num = 0;
        while (n % p == 0) {
            num++;
            n /= p;
        }
        if (num != 0) res.emplace_back(make_pair(p, num));
    }
    if (n != 1)res.emplace_back(make_pair(n, 1));
    return res;
}

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

    ll m = min(N, B - 1);
    print(A*m/B);
}



Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int i,i0,n,m,ans,a[200005],cnt0,cnt1,cnt2,siz[200005],msiz[200005],vis[200005],c1,c0;
vector<int>mp[200005];
void dfs(int now,int root,int dep)
{
	for(int x:mp[now])if(x!=root)dfs(x,now,dep+1);
	if(dep%2)
	{
		c1++;
		if(cnt1)a[now]=(cnt1-1)*3+1,cnt1--;
		else a[now]=cnt0*3,cnt0--;
	}
	else
	{
		c0++;
		if(cnt2)a[now]=(cnt2-1)*3+2,cnt2--;
		else a[now]=cnt0*3,cnt0--;
	}
}
void dfs0(int now,int root,int dep)
{
	for(int x:mp[now])if(x!=root)dfs0(x,now,dep+1);
	if(c1>c0)
	{
		if(dep%2)
		{
			if(cnt1)a[now]=(cnt1-1)*3+1,cnt1--;
			else if(cnt2) a[now]=(cnt2-1)*3+2,cnt2--;
			else a[now]=cnt0*3,cnt0--;
		}
		else
		{
			a[now]=cnt0*3,cnt0--;
		}
	}
	else
	{
		if(dep%2==0)
		{
			if(cnt1)a[now]=(cnt1-1)*3+1,cnt1--;
			else if(cnt2) a[now]=(cnt2-1)*3+2,cnt2--;
			else a[now]=cnt0*3,cnt0--;
		}
		else
		{
			a[now]=cnt0*3,cnt0--;
		}
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int x,y;
		scanf("%d %d",&x,&y);
		mp[x].push_back(y);
		mp[y].push_back(x);
	}
	cnt0=n/3;
	cnt1=n/3+(n%3!=0);
	cnt2=n/3+(n%3==2);
	dfs(1,-1,0);
	if(cnt0==0)for(int i=1;i<=n;i++)printf("%d%c",a[i],i==n?'\n':' ');
	else
	{
		cnt0=n/3;
		cnt1=n/3+(n%3!=0);
		cnt2=n/3+(n%3==2);
		dfs0(1,-1,0);
		for(int i=1;i<=n;i++)printf("%d%c",a[i],i==n?'\n':' ');
	}
	return 0;
}

Measured memory_bytes: 24704
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = INF+7;
const ll LINF = 1e18;
#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,j,N) for(int (i)=(j);(i)<(N);++(i))
#define put(n) cout<<(n)<<endl;
#define all(v) v.begin(),v.end()
#define MP make_pair
#define pb(n) push_back(n)

int main(){
    int N; cin >> N;
    int Odd = 0;
    rep(i,N){
        int n; cin >> n;
        if(n%2) ++Odd;
    }

    if(Odd%2) cout << "NO" << endl;
    else cout << "YES" << endl;
}

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

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

int n, k;
string s;

int main() {
    cin >> n;
    Vi p(n), q(n);
    REP(i, n) cin >> p[i];
    REP(i, n) cin >> q[i];

    int pp, pq;
    int cnt = 0;
    Vi v(n);
    REP(i, n) v[i] = i+1;
    do {
        bool fp = true, fq = true;
        REP(i, n) {
            fp = fp && (p[i] == v[i]);
            fq = fq && (q[i] == v[i]);
        }
        if (fp) pp = cnt;
        if (fq) pq = cnt;
        cnt++;
    } while(next_permutation(ALL(v)));
    std::cout << abs(pp - pq) << '\n';

    return 0;
}


Measured memory_bytes: 256
n, *a = map(int, open(0).read().split())
a.sort(reverse=True)
max_a = a[0]
min_diff = float('inf')
for v in a[1:]:
    if abs(max_a/2 - v) <= min_diff:
        ans = v
        min_diff = abs(max_a/2 - v)
print(max_a, ans)

Measured memory_bytes: 20076
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define init(n) int n;cin>>n;int a[n];rep(i,n)cin>>a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p=1000000007;
int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    int T=1;
    // cin>>T;
    while(T--){
        string ans="APPROVED";
        int n;cin>>n;
        rep(i,n){
            int x;cin>>x;
            if(x%2==0){
                if(x%3!=0&&x%5!=0){
                    ans="DENIED";
                }
            }
        }
        cout<<ans;
    }   
    return 0;   
}

Measured memory_bytes: 256
use std::cmp::max;


macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}


fn main() {
    input! {
        N: usize,
        L: [i32; N],
    }

    let mut ans = 0;
    for i in 0..N {
        for j in i..N {
            for k in j..N {
                if L[i] == L[j] || L[i] == L[k] || L[j] == L[k] {
                    continue;
                }
                let sum = L[i] + L[j] + L[k];
                let ma = max(max(L[i], L[j]), L[k]);
                if ma < sum - ma {
                    ans += 1;
                }
            }
        }
    }

    println!("{}", ans);
}


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

int main() {
  ll n;
  cin >> n;
  vector<pair<ll, int>> fs;
  for (ll i = 2; i*i < n; ++i) {
    int x = 0;
    while (n%i == 0) {
      n /= i;
      x++;
    }
    fs.emplace_back(i, x);
  }
  if (n != 1) fs.emplace_back(n, 1);
  int ans = 0;
  for (auto p : fs) {
    int x = p.second;
    int b = 1;
    while (b <= x) {
      x -= b;
      b++;
      ans++;
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 19772
#include <stdio.h>
#include <stdlib.h>

struct node {
	int key;
	struct node *car;
	struct node *cdr;
	struct node *parent;
};

struct node *root;

void
record(struct node *r, struct node *p)
{
	if (p->key < r->key) {
		if (r->car == NULL)
			r->car = p, p->parent = r;
		else
			record(r->car, p);
	} else {
		if (r->cdr == NULL)
			r->cdr = p, p->parent = r;
		else
			record(r->cdr, p);
	}
}

void
delete(struct node *p)
{
	struct node *c = NULL;

	if (p->car != NULL && p->cdr != NULL) {
		for (c = p->cdr; c->car != NULL; c = c->car);
		p->key = c->key;
		return delete(c);
	}

	if (p->car != NULL)
		c = p->car;
	else if (p->cdr != NULL)
		c = p->cdr;

	if (c != NULL)
		c->parent = p->parent;

	if (p->parent == NULL) {
		root = c;
	} else if (p->parent->car == p) {
		p->parent->car = c;
	} else {
		p->parent->cdr = c;
	}
	free(p);
}

struct node *
find(struct node *r, int key)
{
	if (r == NULL)
		return r;
	else if (key == r->key)
		return r;
	else if (key < r->key) {
		if (r->car == NULL)
			return NULL;
		else
			return find(r->car, key);
	} else {
		if (r->cdr == NULL)
			return NULL;
		else
			return find(r->cdr, key);
	}
}

void
preorder(struct node *a)
{
	if (a == NULL)
		return;

	printf(" %d", a->key);
	preorder(a->car);
	preorder(a->cdr);
}

void
inorder(struct node *a)
{
	if (a == NULL)
		return;

	inorder(a->car);
	printf(" %d", a->key);
	inorder(a->cdr);
}

int
main(void)
{
	int i, n, p;
	struct node *a;
	scanf("%d", &n);

	for (i = p = 0; i < n; i++) {
		char cmd[16];
		int key;

		scanf("%s", cmd);
		switch (cmd[0]) {
		case 'i':
			scanf("%d", &key);
			a = (struct node *)malloc(sizeof(struct node));
			if (a == NULL)
				return 1;
			a->key = key;
			a->car = NULL;
			a->cdr = NULL;
			if (root == NULL)
				root = a;
			else
				record(root, a);
			break;
		case 'f':
			scanf("%d", &key);
			printf("%s\n",
			       find(root, key) != NULL ? "yes" : "no");
			break;
		case 'd':
			scanf("%d", &key);
			a = find(root, key);
			if (a != NULL)
				delete(a);
			break;
		case 'p':
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
			break;
		}
	}

	return 0;
}



Measured memory_bytes: 20468
#include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FSP(x) fixed << setprecision(x)
using namespace std;
using ll = long long;
constexpr ll INF = LLONG_MAX;
constexpr long double PI = acosl(-1);
void Yes() {cout << "Yes\n";}
void No() {cout << "No\n";}
void YES() {cout << "YES\n";}
void NO() {cout << "NO\n";}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//constexpr ll P = 1e9 + 7;
	//constexpr ll P = 998244353;

	string s;
	cin >> s;
	ll ans = 0;
	for (auto i : s) {
		ans += i - '0';
		ans %= 9;
	}
	if (ans == 0) Yes();
	else No();
}

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

int main() {
  long long N, M;
  cin >> N >> M;
  long long x   = N;
  long long y   = M;
  long long ans = 0;
  // Sを使った場合
  if (N < M / 2) {
    ans += N;
    M -= 2 * N;
    N = 0;
  } else {
    ans += M / 2;
    N -= M / 2;
    M = 0;
  }
  // Cのみの組み合わせ
  ans += M / 4;
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys




def solve():
    res = 1
    over = False
    for i in range(len(a)):
        if not over:
            res *= a[i]
            if res > mxn:
                over = True
        else:
            if a[i] == 0:
                print(0)
                return
    if not over:
        print(res)
    else:
        print(-1)
    return


mxn = 10**18
n = int(input())
a = [int(i) for i in input().split()]
solve()


Measured memory_bytes: 84728
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N,A,B=map(int,readline().split())
    if (B-A)%2==0:
        print((B-A)//2)
    else:
        print(min(N-B,A-1)+1+(B-A-1)//2)

if __name__=="__main__":
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int A, B; cin >> A >> B;
    Out(max(0LL, A - 2 * B));

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    int D;
    long long G;
    cin >> D >> G;
    G /= 100;
    vector<int> P(D);
    vector<int> C(D);
    for ( int i = 0; i < D; i++ ) {
        cin >> P[i] >> C[i];
        C[i] /= 100;
    }

    int ans = INT_MAX;
    for ( int i = 0; i < (2<<D); i++ ) {
        long long s = 0;
        int n = 0;
        for ( int j = 0; j < D; j++ ) {
            if ( 1<<(j) & i ) {
                s += (j+1)*P[j] + C[j];
                n += P[j];
            }
        }
        if ( G <= s ) { ans = min( ans, n ); continue; }

        for ( int j = D-1; j >= 0; j-- ) {
            if ( 1<<(j) & i ) { continue; }

            if ( s + (j+1)*(P[j]-1) >= G ) {
                n += (G-s)%(j+1) ? (G-s)/(j+1)+1 : (G-s)/(j+1);
                ans = min( ans, n );
                break;
            }            
            else {
                s += (j+1)*(P[j]-1);
                n += P[j]-1;
            }
        }
    }

    cout << ans << endl;


    return 0;
}

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

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

	return 0;
	
}

Measured memory_bytes: 3720
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;++i)
using namespace std;
int main(){
int a,b;
cin>>a>>b;
cout<<"100 100\n";
REP(i,100){REP(j,100)i<50?cout<<(i%2&&j%2&&--a>0?".":"#"):cout<<(i%2&&j%2&&--b>0?"#":".");cout<<"\n";}
}


Measured memory_bytes: 256
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()

score = 0
char_list = list(t)
v_list = []
janken = {0:r, 1:s, 2:p}
dp = [[0 for i in range(3)] for j in range(n)]

for i in range(n):
  if char_list[i] == 'r':
    v_list.append(2)
  elif char_list[i] == 's':
    v_list.append(0)
  else:
    v_list.append(1)

for i in range(k):
  dp[i][v_list[i]] = janken[v_list[i]]
  for j in range(i+k, n, k):
    for l in range(3):
      if v_list[j] == l:
        dp[j][l] = max(dp[j-k][(l+1)%3], dp[j-k][(l+2)%3]) + janken[l]
      else:
        dp[j][l] = max(dp[j-k][(l+1)%3], dp[j-k][(l+2)%3])

for i in range(1, k+1):
  score += max(dp[n-i][0], max(dp[n-i][1], dp[n-i][2]))

print(score)

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

ll power(ll a, ll b) {
	ll res = 1;
	while (b) {
		if (b & 1)res = res * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return res;
}

ll c(ll a, ll b) {
	ll res = 1;
	for (ll i = 1; i <= b; i++)res = res * (a + 1 - i) % mod * power(i, mod - 2) % mod;
	return res;
}

void solve() {
	ll n; cin >> n;
	ll ans = 0;
	ll cnt = n / 3;
	for (ll i = 1; i <= cnt; i++) {
		ans = (ans + c(n - 3 * i + i - 1, i - 1)) % mod;
	}
	cout << ans;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	// int t; cin >> t;
	// while (t--)
	solve();

}



Measured memory_bytes: 3616
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
public class Main {
	public static void main(final String[] args){
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int count = 0;
    for(int i = 1; i < 10 ; i++){
        if(n % i == 0){
            if(n / i <= 9){
                count++;
            }
        }
    }
    if(count == 0){
        System.out.println("No");
    }else{
        System.out.println("Yes");
    }
    
    
	}
}

Measured memory_bytes: 21844
import java.io.*;
import java.util.*;
public class Main {
	public static class FS {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens()) {
				try { st = new StringTokenizer(br.readLine()); }
				catch (Exception e) {}
			} return st.nextToken();
		}
		int nextInt() { return Integer.parseInt(next()); }
		long nextLong() { return Long.parseLong(next()); }
	}

	public static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); }
	public static long lcm(long a, long b) { return a * b / gcd(a, b); }
	public static int abs(int x) { if (x < 0) return -x; return x; }

	public static void main(String[] args) {
		FS in = new FS();

		long a = in.nextLong();
		long b = in.nextLong();
	
		System.out.println(lcm(a, b));
	}
}


Measured memory_bytes: 21204
L, R = map(int, input().split())
l_mod = L % 2019
r_mod = R % 2019
if R >2019+L:
    print(0)
else:
    mod = (l_mod*(l_mod+1)) % 2019
    for i in range(l_mod,r_mod):
        for j in range(i+1,r_mod+1):
            if mod>(i*j)%2019:
                mod=(i*j)%2019
    print(mod)

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

string s, t;

int main() {
    t = "AKIHABARA";
    cin >> s;
    int n = s.size();
    int ind = 0;
    for (char c : t) {
        if (ind == n || s[ind] != c) {
            if (c != 'A') {
                cout << "NO" << endl;
                return 0;
            }
        } else {
            ++ind;
        }
    }
    if (ind != n) {
        cout << "NO" << endl;
        return 0;
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn
import scala.collection.mutable.Map

object Main{
  def main(args: Array[String]): Unit = {
    val houses:Map[Int, Array[Array[Int]]] = Map.empty[Int, Array[Array[Int]]]
    (1 to 4).foreach{ b =>
      houses += (b -> Array.fill(3)(Array.fill(10)(0)))
    }

    val n = StdIn.readInt()
    (1 to n).foreach{ _ =>
      val Array(b, f, r, v, _*) = StdIn.readLine().split(" ").map(_.toInt)
      houses.get(b).foreach(building => {building(f-1)(r-1) += v})
    }

    (1 to 4).foreach{ b =>
      def buildingPrint(bl: Array[Array[Int]]){
        bl.foreach(f => println(" " + f.mkString(" ")))
      }

      if(b != 4){
        buildingPrint(houses(b))
        println("####################")
      }else{
        buildingPrint(houses(b))
      }
    }
  }
}

Measured memory_bytes: 44212
#include<stdio.h>
int main(){
long int a,b,c,d,A[101][101]={0},e=0;
scanf("%d %d",&a,&b);
for(c=0;c<a;c++){
for(d=0;d<b;d++){
scanf("%d",&A[c][d]);
}
}

for(c=0;c<a;c++){
for(d=0;d<b;d++){
A[a][d]+=A[c][d];
e+=A[a][d];
A[c][b]+=A[c][d];
}
}

for(c=0;c<=a;c++){
for(d=0;d<=b;d++){
if(c==a&&d!=b)
A[a][b]+=A[a][d];
printf("%ld",A[c][d]);



if(d!=b)
printf(" ");
else
printf("\n");
}
}
return 0;
}

Measured memory_bytes: 692
#include <stdio.h>
#define t 1
#define f 0
int solve(int ,int );

int A[2000],n;
int main(){
  int i,q,m[2000],zero=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&m[i]);
  }
  for(i=0;i<q;i++){
    if(solve(zero,m[i])==1){
      printf("yes\n");
    }
    else {
      printf("no\n");
    }
  }
  return 0;
}




int solve(int i,int m){
  int r;
  if(m==0){
    return t;
  }
  if(i>=n){
    return f;
  }
  r=solve(i+1,m) || solve(i+1,m-A[i]);
  
  return r;
}



Measured memory_bytes: 2108
#include <cstdio>
#include <map>
#include <vector>
#include <algorithm>

long long cum[200001];

int main()
{
  int n;
  long long k;
  scanf("%d%lld", &n, &k);
  std::map<long long, std::vector<int>> mp;
  mp[0].emplace_back(0);
  for (int i = 0; i < n; ++i)
  {
    long long a;
    scanf("%lld", &a);
    cum[i + 1] = (cum[i] + a - 1) % k;
    mp[cum[i + 1]].emplace_back(i + 1);
  }
  long long ans = 0;
  for (int i = 0; i < n; ++i)
  {
    auto& v = mp[cum[i]];
    auto r = std::lower_bound(v.begin(), v.end(), i + int(k));
    auto l = std::upper_bound(v.begin(), v.end(), i);
    ans += r - l;
  }
  printf("%lld\n", ans);
  return 0;
}

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

using namespace std;

string operation(string S)
{
	string T;

	int left = 0;

	if (S.size() == 1)
	{
		return "1" + S;
	}

	for (int i = 1; i < S.size(); i++)
	{
		if (S[i - 1] != S[i])
		{
			T += (to_string(i - left) + S[i - 1]);

			left = i;
		}

		if (i + 1 == S.size())
		{
			T += (to_string(S.size() - left) + S[i]);
		}
	}

	return T;
}

int main()
{
	int n; string S;

	while (true)
	{
		cin >> n;

		if (n == 0) { break; }

		cin >> S;

		for (int i = 0; i < n; i++)
		{
			S = operation(S);
		}

		cout << S << endl;
	}

	return 0;
}

Measured memory_bytes: 3344
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>

#define max(a, b) ((a) < (b) ? (b) : (a))
#define min(a, b) ((a) < (b) ? (a) : (b))

using namespace std;
int main()
{
  int n, z, w;
  cin >> n >> z >> w;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];

  if (n == 1)
  {
    cout << abs(a[0] - w) << endl;
  }
  else
  {
    cout << max(abs(a[n - 1] - w), abs(a[n - 2] - a[n - 1])) << endl;
  }

  return 0;
}

Measured memory_bytes: 888
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>
using namespace std;

#define ll long long

void solve()
{
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    while (1)
    {
        C -= B;
        if (C <= 0)
        {
            cout << "Yes" << endl;
            return;
        }

        A -= D;
        if (A <= 0)
        {
            cout << "No" << endl;
            return;
        }
    }

    return;
}

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


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

using namespace std;

int main(){
  int n;
  cin >> n;
  cin.ignore();
  long long ans = 1;
  long double ans_d = 1;
  long long tmp;
  // ゼロサーチもする
  bool min1 = false;
  for(int i = 0; i < n; i++){
    cin >> tmp;
    ans *= tmp;
    ans_d *= tmp;
    if(ans_d > 1000000000000000000){
      if(ans != 1000000000000000000){
        min1 = true;
      }
    }
    if(tmp == 0){
      cout << 0 << endl;
      return 0;
    }
  }
  if(min1 == true){
    cout << "-1" << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
    int A, B; cin >> A >> B;
    cout << (A%3==0 || B%3==0 || (A+B)%3==0 ? "Possible" : "Impossible") << endl;
}

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

int main() {
  int a,b,c;
  int num;
  long long kekka = 0;
  
  vector<int> vec(3);
  
  cin >> a >> b >> c >> num;
  vec.at(0) = a;
  vec.at(1) = b;
  vec.at(2) = c;
  
  sort(vec.begin(), vec.end());
  
  kekka = vec.at(2);
  for(int i = 0; i < num; i++){
    kekka *=  2;
  }
  cout << vec.at(0) + vec.at(1) + kekka;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(num,init,name) vector<int> name((num),(init));


int main(){
    string s;
    int k;
    cin>>s>>k;
    vector<string> v;
    rep(i,k){
        rep(j,s.length()-i){
            v.push_back(s.substr(j,i+1));
        }
    }
    sort(all(v));
    
    unique(all(v));
    
    cout<<v[k-1]<<endl;
    return 0;

}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

int main(){
  int K,A,B;
  cin >> K >> A >> B;
  if(K <= A || B<=A+2){
    cout << K+1 << endl;
    return 0;
  }
  K -= A-1;
  ll ans = A;
  ans += (K/2LL)*(B-A);
  if(K%2){
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N  = int(input())
a = [int(i) for i in input().split()] 

n = 1
ans = []
for i in range(len(a)):
    if a[i] == n:
        ans.append(a[i])
        n += 1

x = len(a) - len(ans)
if x == len(a):
    print(-1)
else:
    print(x)

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

class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll n){
    	rep(i,n){
    		par.push_back(i); // 初期では親は自分自身
    		siz.push_back(1);
    	}
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        ll rx = root(x);
        ll ry = root(y);
        if (rx == ry) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[rx] < siz[ry]) swap(rx, ry);
        siz[rx] += siz[ry];
        par[ry] = rx;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
	
};


int main(){
    
    int n,m;
    cin >> n >> m;
	vector<P> bridge(m);
	UnionFind uf(n);
	rep(i,m){
		int a,b;
		cin >> a >> b;
		bridge[i] = make_pair(--a,--b);
	}
	reverse(bridge.begin(), bridge.end());
	
	vector<ll> csum(n);
	rep(i,n-1) csum[i+1] = csum[i] + i+1;
	
	vector<ll> res(m);
	res[0] = csum[n-1];
	
	rep(i,m-1){
		int n1 = bridge[i].first;
		int n2 = bridge[i].second;
		if(uf.issame(n1,n2)){
			res[i+1] = res[i];
		}
		else{
			int rs1 = uf.size(n1);
			int rs2 = uf.size(n2);
			res[i+1] = res[i] - rs1*rs2;
		}
		uf.merge(n1,n2);
	}
	reverse(res.begin(), res.end());
	rep(i,m) cout << res[i] << endl;
    return 0;
    
}


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


int main()
{
    string s;
    cin>>s;
    for (char i='a';i<='z';i++){
        if (s.find(i)==-1){
            cout<<i;
            return 0;
        }
    }
    cout<<"None";
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<stack>
#include<queue>

using namespace std;

int main(){
	int a,b,c;
	int N;
	int at[1000],bt[1000],ct[1000],res[1000];
	while(1){
		scanf("%d %d %d",&a,&b,&c);
		if(a==0&&b==0&&c==0)
		break;
		vector<int> p(a+b+c+1,2);
		scanf("%d",&N);
		for(int i=0;i<N;i++){
			scanf("%d %d %d %d",&at[i],&bt[i],&ct[i],&res[i]);
			if(res[i]==1){
				p[at[i]]=1;
				p[bt[i]]=1;
				p[ct[i]]=1;
			}
		}
		for(int i=0;i<N;i++){
			if(res[i]==1) continue;
			if(p[at[i]]==1&&p[bt[i]]==1) p[ct[i]]=0;
			if(p[bt[i]]==1&&p[ct[i]]==1) p[at[i]]=0;
			if(p[at[i]]==1&&p[ct[i]]==1) p[bt[i]]=0;
		}
		for(int i=1;i<=a+b+c;i++){
			printf("%d\n",p[i]);
		}
	}
}


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

int main() {
  long int N,h,n,w,q;
  cin >> N;
  for(h=1;h<=3500;h++) {
    for(n=h;n<=3500;n++) {
      q = 4*h*n-N*n-N*h;
      if(q>0&&N*h*n%q==0) {
        cout << h << " " << n << " " << N*h*n/q << endl;
        return 0;
      }
      else continue;
    }
  }
  return 0;
} 

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(100000000)
n = int(input())
graph = [[] for _ in range(n)]
for _ in range(n-1):
  u, v, w = map(int, input().split())
  u -= 1
  v -= 1
  graph[u] += [[v, w]] 
  graph[v] += [[u, w]] 

color = [-1]*n 
def dfs(u, c):
  color[u] = c 
  for v, w in graph[u]:
    if color[v] != -1:
      continue
    if color[v] != c and w % 2 == 0:
      dfs(v, c)
    elif color[v] != c and w % 2 != 0:
      dfs(v, abs(1-c))

  return

dfs(0, 0)
for c in color:
  print(c)


Measured memory_bytes: 85212
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

ll dfs (string r, ll n)
{
    ll k;
    if (r=="")
        k=0;
    else
        k=stoll(r);
    if (k>n)
        return 0;
    int i,f[3]={0};
    for (i=0;i<r.size();i++)
    {
        if (r[i]=='7')
            f[0]++;
        else if (r[i]=='5')
            f[1]++;
        else
            f[2]++;
    }
    if (f[0] && f[1] && f[2])
        return 1+dfs(r+'7',n)+dfs(r+'5',n)+dfs(r+'3',n);
    else
        return dfs(r+'7',n)+dfs(r+'5',n)+dfs(r+'3',n);
}

main()
{
    fast;
    ll n;
    cin>>n;
    ll ans=dfs("",n);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int main(){
  string s;
  cin >> s;
  priority_queue<int> pq;
  int cnt = 0;
  for(int i = 0; i < s.size(); i++){

    if(s.at(i) == 'A'||s.at(i) =='T'||s.at(i) =='G'||s.at(i) =='C'){
      cnt++;
    }else{
      cnt = 0;
    }
        pq.push(cnt);
  }
  cout << pq.top() <<endl;
}

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvl = vector<vector<ll>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };
constexpr int MAX = 10010;

// ──────────────────────────────────────────────────────────────────────────────

int main() {
	int n;
	cin >> n;
	vector<int> a(n), b(n), c(n);
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> b[i];
	rep(i, n) cin >> c[i];

	sort(ASC(a));
	sort(ASC(b));
	sort(ASC(c));

	ll ans = 0;
	for (int i = 0; i < n; ++i) {
		ll up = lower_bound(ASC(a), b[i]) - a.begin();
		ll down = c.end() - upper_bound(ASC(c), b[i]);
		ans += up * down;
	}
	cout << ans << endl;
}


Measured memory_bytes: 1408
#pragma target("avx")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define rep(i,b,e) for(ll i=b; i<e; i++)
#define be(vec) vec.begin(),vec.end()
#define print(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define scan(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	ll n, m;
	scanf("%ld %ld", &n, &m);

	std::vector<P> links[n];
	while(m--){
		ll l, r, d;
		scanf("%ld %ld %ld", &l, &r, &d);
		links[l-1].emplace_back(r-1, d);
		links[r-1].emplace_back(l-1, -d);
	}

	bool ok = true;
	V coo(n, -1), used(n, 0);

	rep(i, 0, n){
		if(used[i]) continue;
		std::queue<P> que;
		que.emplace(i, 0);
		while(!que.empty()){
			P p = que.front();
			que.pop();
			if(used[p.fi]) continue;
			used[p.fi] = true;
			coo[p.fi] = p.se;
			for(P to: links[p.fi]){
				if(!used[to.fi]) que.emplace(to.fi, p.se+to.se);
				else if(coo[to.fi]!=p.se+to.se) ok = false;
			}
		}
	}

	if(ok) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 16000
s = input()
l = int(input())
char = []
if len(s) == 1:
    print(s)
else:
    for i in range(len(s)):
        char.append(s[i])
    charset = set(char)
    ans = []
    for i in charset:
        for j in range(len(s)):
            if i == s[j]:
                for k in range(1, 6):
                    ans.append(s[j:j+k])
    ansset = sorted(list(set(ans)))
    print(ansset[l-1])

Measured memory_bytes: 5084
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,i,j,k,l,a,b,c,d;
    cin>>n;
    ll arr[n+10];
    for(i=0;i<n;i++)
    {
        cin>>k;
        k-=(i+1);
        arr[i]=k;
    }
    sort(arr+0,arr+n);
    c=0;
    l=arr[n/2];

    for(i=0;i<n;i++)
    {
        c+=abs(arr[i]-l);
    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 1792
from operator import itemgetter


def main():
    N = int(input())
    ab = [[int(j) for j in input().split()] for i in range(N)]
    cd = [[int(j) for j in input().split()] for i in range(N)]
    # y 降順
    ab.sort(key=itemgetter(1), reverse=True)
    # x 昇順
    cd.sort(key=itemgetter(0))
    # ペアになった赤
    done = [False] * N
    for bx, by in cd:
        for k, ([rx, ry], d) in enumerate(zip(ab, done)):
            if not d and rx < bx and ry < by:
                done[k] = True
                break
    print(sum(done))
    return


main()


Measured memory_bytes: 3316
def main():
    N, K = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    d = [-1]*(N+1)
    v = 1
    i = 0
    while d[v] == -1:
        d[v] = i
        v = A[v-1]
        i += 1
    c_length = i - d[v]  # 閉路長
    pre_c_length = d[v]
    if K < i:
        return print(d.index(K))
    else:
        K -= pre_c_length
        K %= c_length
        return print(d.index(pre_c_length+K))


if __name__ == '__main__':
    main()


Measured memory_bytes: 92536
n,m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]

ans = 'No'
for di,dj in [(pi,pj) for pi in range(n-m+1) for pj in range(n-m+1)]:
    for i,j in [(pi,pj) for pi in range(m) for pj in range(m)]:
        if a[di+i][dj+j] != b[i][j]:
            break
    else:
        ans = 'Yes'
        break
print(ans)


Measured memory_bytes: 9180
#pragma GCC optimize("O3")

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <assert.h>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <random>
#include <cmath>
#include <chrono>
#include <bitset>

#define ld long double
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;

const int INF = 2e18;
const int MOD = 1e9 + 7;
const int MB = 20;

void solve() {
	string s;
	cin >> s;
	bool good = true;
	for (int i = 0; i < s.size(); i++) {
		if (i % 2) {
			if (s[i] == 'R') good = false;
		}
		else {
			if (s[i] == 'L') good = false;
		}	
	}
	cout << (good ? "Yes" : "No");
}
signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout.precision(12);
	solve();
}

Measured memory_bytes: 256
a, b = map(int, input().split())
s0 = input()
s = [x for x in s0]

if len(s) != a + b + 1:
  print('No')
  exit()
if s[a] != '-':
  print('No')
  exit()
for i in range(a):
  if s[i] == '-':
    print('No')
    exit()
for i in range(a+1, a+b):
  if s[i] == '-':
    print('No')
    exit()
print('Yes')

Measured memory_bytes: 3064
s=input()
if s[0]=="S" or s[0]=="T":
  if s[2]=="E":
    print('5')
  elif s[2]=='U':
    print('3')
  elif s[2]=='T':
    print('1')
  else:
    print('7')
else:
  if s[1]=='R':
    print('2')
  elif s[1]=='O':
    print('6')
  else:
    print('4')



Measured memory_bytes: 3060