akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
const lli mod=1e9+7;
const lli pINF=LLONG_MAX;
const lli nINF=-LLONG_MAX;
void fast() {std::ios::sync_with_stdio(false);cin.tie(NULL);}
lli power(lli a,lli b){lli ans=1;while(b!=0){ if(b%2==1){ans*=a;}b/=2;a*=a;} return ans;}
lli invmod(lli a) {return pow(a,mod-2);}
#define vi vector<int>
#define vlli vector<lli>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define si(n) scanf("%d",&n)
#define sli(n) scanf("%lld",&n)
#define printi(n) printf("%d\n",n)
#define printli(n) printf("%lld\n",n)
#define all(vi) (vi.begin(),vi.end())
#define forn(i,n) for(int i=0;i<n;i++)
void print(int a[],int n){for(int i=0;i<n;i++) cout<<a[i]<<" ";}
int sum1[100005],sum2[100005];

int main() {
	string s,t;
	cin>>s>>t;
	s=" "+s;
	t=" "+t;
	
	for(int i=1;i<=s.size();i++){
	    sum1[i]=sum1[i-1]+((s[i]=='A')?1:2);
	}
	
	for(int i=1;i<=t.size();i++){
	    sum2[i]=sum2[i-1]+((t[i]=='A')?1:2);
	}
	
	int q,a,b,c,d;
	si(q);
	
	while(q--){
	    si(a);si(b);si(c);si(d);
	    int ss=(sum1[b]-sum1[a-1])%3;
	    int ts=(sum2[d]-sum2[c-1])%3;
	    
	    if(ss==ts) cout<<"YES\n";
	    else cout<<"NO\n";
	}
	return 0;
}

Measured memory_bytes: 1636
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <functional>
#include <numeric>
//#include "bits/stdc++.h"
using namespace std;
//using namespace std::vector;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)

#define huge 1000000007
typedef unsigned long long int ll;
ll gcd(ll a, ll b);

int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll D = 0;
	ll M = 0;
	//ll M = 0;
	ll a[100] = {};
	//ll b[200] = {};
	//ll v[3] = {};
	ll *c, *s, *n;
	string S,T,U[52];
	ll count = 0;
	ll count2 = 0;
	ll sum = 0;
	ll min = 100000;
	ll max = 0;
	ll smax = 0;
	ll max2 = 0;
	ll smax2 = 0;
	int tmax = 0;
	int tmax2 = 0;
	int flag = 0;
	char temp,head;
	//int is = 0;
	
	
	//char p;


	

	

	//cin >> S;
	
	//b = (ll *)malloc(M * sizeof(ll));
	//vector<pair<int,int>> ch(50);

	
	cin >>N >> B;

	
	
	
	
		cout << (N+B)%24 << endl;
	
	//x = (ll *)malloc((N+1) * sizeof(ll));
	//c = (ll *)malloc((N) * sizeof(ll));
	//cin >> D >> G;
	//vector<pair<int,int>> tr(M);
	//vector<pair<int,int>> qes(Q);
	//sort(c.begin(), c.end());
	
	//cout << c[2] - c[1] << endl;

	

	/*A = N / 1000;
	N %= 1000;
	B = N / 100;
	N %= 100;
	C = N / 10;
	N %= 10;
	D = N;*/
	


	return 0;

}

ll gcd(ll a, ll b) {
	
	/* 自然数 a > b を確認・入替 */
	if (a<b) {
		ll tmp = a;
		a = b;
		b = tmp;
	}
	ll x = b;
	ll y = a;
	/* ユークリッドの互除法 */
	ll r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}


	return y/b*x;
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll n;

int main(){
  ll res=INF;
  cin>>n;
  repl(a,1,n){
    ll nb=n-a;
    ll na=a;
    ll sum=0;
    while(na>0){
      sum+=na%10;
      na/=10;
    }
    while(nb>0){
      sum+=nb%10;
      nb/=10;
    }
    minch(res,sum);
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 768
//Utkarsh-raj

#include<bits/stdc++.h>

#define ll long long int
#define vc vector
#define mod 100000000007
#define mp make_pair
#define pb push_back
#define nl cout<<endl;
#define ff first
#define ss second

using namespace std;

const ll MAX = 1e9+5;

void dfs(int root, vector<int> v[ ], int *vis, int *dp){
    vis[root] = 1;
    dp[root] = 1;

    int ansFromChild = 0;
    for(int i=0; i<v[root].size(); i++){
        if(!vis[v[root][i]]){
            dfs(v[root][i], v, vis, dp);
        }
        ansFromChild = max(ansFromChild, dp[v[root][i]]);
    }

    dp[root] += ansFromChild;
}

int main()
{
    ifstream myFile("task.in");
    if(!myFile.fail())
    {
        assert(freopen("task.in", "r", stdin));
    }

    int n, m;
    cin>>n>>m;

    vector<int> v[n+1];
    for(int i=0; i<m; i++){
        int x, y;
        cin>>x>>y;
        v[x].pb(y);
    }

    int vis[n+1];
    int dp[n+1];

    for(int i=0; i<=n; i++){
        vis[i] = 0;
        dp[i] = 0;
    }

    for(int i=1; i<=n; i++){
        if(!vis[i]){
            dfs(i, v, vis, dp);
        }
    }

    int ans = 0;

    for(int i=1; i<=n; i++){
        ans = max(ans, dp[i]);
    }   

    if(ans != 0) ans--;
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 10624
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
H = list(map(int,readline().split()))
A = list(map(int,readline().split()))

"""
・最後の高さ -> 価値の総和
・BITでmaxを管理
"""

class BIT():
    def __init__(self, max_n):
        self.size = max_n + 1
        self.tree = [0] * self.size
        
    def __repr__(self):
        return self.tree.__repr__()
        
    def get_max(self,i):
        s = 0
        while i:
            t = self.tree[i]
            if s<t:
                s=t
            i -= i & -i
        return s
 
    def update(self, i, x):
        while i < self.size:
            if self.tree[i] < x:
                self.tree[i] = x
            i += i & -i

bit = BIT(N)

for i,(a,h) in enumerate(zip(A,H),1):
    x = bit.get_max(h)
    bit.update(h,x+a)

answer = bit.get_max(N)
print(answer)

Measured memory_bytes: 31424
#include<bits/stdc++.h>
using namespace std;
#define fine cout<<"fine"<<endl;
#define ll long long int
#define pb push_back
#define FASTIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
const ll inf=(ll)2e18;
const int mod=1e9+7;
bool overflow(ll a,ll b){
    if (a <= (inf+b-1)/b) return false;
    return true;
}
int main(){
FASTIO;
ll a,b,n;
cin>>a>>b>>n;
ll x=min(b-1,n);
ll y=(a*x)/b;
cout<<y<<endl;
}


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

int main() {
  int N, A, B;
  int a;
  cin >> N >> A >> B;
  
  a = N * A;
  
 // cout << x << endl << y <<endl;
 
	  if (B >= a){
	    cout << a << endl;
	  }
 	 else {
     	 cout << B << endl;
     }
}

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

using namespace std;

void solve_case();

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

	solve_case();

	return 0;
}

void solve_case() {
	int arr[4] = { 0, };
	int tmp;

	for (int i = 0; i < 6; i++) {
		cin >> tmp;
		arr[tmp - 1]++;
	}

	sort(arr, arr + 4);

	if (arr[1] == 1 && arr[3] == 2)
		cout << "YES\n";
	else
		cout << "NO\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
//#define f(i,a,n) for(ll i=a;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll isPrime(int n) 
{ 
	// Corner cases 
	if (n <= 1) 
		return 1; 
	if (n <= 3) 
		return 2; 

	// This is checked so that we can skip 
	// middle five numbers in below loop 
	if (n % 2 == 0 || n % 3 == 0) 
		return 1; 

	for (int i = 5; i * i <= n; i = i + 6) 
		if (n % i == 0 || n % (i + 2) == 0) 
			return 1; 

	return 2; 
} 

ll fact(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = res * i,res%=1000000007; 
    return res; } 
 
int main() 
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll A[3];
        cin>>A[0]>>A[1]>>A[2];
        sort(A,A+3);
        cout<<A[0]+A[1];
    }    
    return 0;
}


Measured memory_bytes: 3664
N = int(input())
S = list(input())

EAST = []
WEST = []
e = 0
w = 0
for s in S:
  if s == "E":
    e += 1
  else:
    w += 1
  EAST.append(e)
  WEST.append(w)
  
ans = N - 1
for i in range(N):
  c = 0
  if i > 0:
    c += WEST[i-1]
  if i < N - 1:
    c += EAST[N-1] - EAST[i]
  
  ans = min(c,ans)

print(ans)
    

  


Measured memory_bytes: 25536
x, k, d = gets.split.map(&:to_i)

first_min_count, first_min = x.abs.divmod(d)
second_min = first_min > 0 ? first_min - d : first_min + d

if first_min_count <= k
  if k.odd? && first_min_count.odd? || k.even? && first_min_count.even?
    puts first_min.abs
  else
    puts second_min.abs
  end
else
  puts [(x - k * d).abs, (x + k * d).abs].min
end


Measured memory_bytes: 14336
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
ans = []

for i in range(N):
  for _ in range(A[i]):
    ans.append(i+1)
  
for i in range(H):
  if i%2 == 0:
    print(*ans[i*W:(i+1)*W])
  else:
    print(*reversed(ans[i*W:(i+1)*W]))

Measured memory_bytes: 9568
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;

int main() {
	int n;
	cin >> n;
	if (n == 1) cout << "Hello World" << endl;
	else {
		int a, b;
		cin >> a >> b;
		cout << a + b << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <tuple>

using lint = long long;

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;
    Edge(int src = -1, int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = int>
using Edges = std::vector<Edge<Cost>>;

template <class T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

struct UnionFind {
    std::vector<int> par, sz;
    int gnum;

    explicit UnionFind(int n)
        : par(n), sz(n, 1), gnum(n) {
        std::iota(par.begin(), par.end(), 0);
    }

    int find(int v) {
        return (par[v] == v) ? v : (par[v] = find(par[v]));
    }

    void unite(int u, int v) {
        u = find(u), v = find(v);
        if (u == v) return;

        if (sz[u] < sz[v]) std::swap(u, v);
        sz[u] += sz[v];
        par[v] = u;
        --gnum;
    }

    bool same(int u, int v) { return find(u) == find(v); }
    bool ispar(int v) { return v == find(v); }
    int size(int v) { return sz[find(v)]; }
};

void solve() {
    int n;
    lint d;
    std::cin >> n >> d;

    std::vector<lint> xs(n);
    for (auto& x : xs) std::cin >> x;

    MinHeap<Edge<lint>> heap;
    std::queue<std::pair<int, int>> que;
    que.emplace(0, n);

    while (!que.empty()) {
        int l, r;
        std::tie(l, r) = que.front();
        que.pop();
        if (r - l <= 1) continue;
        int m = (l + r) / 2;

        int li = l;
        for (int i = l + 1; i < m; ++i) {
            if (xs[i] - i * d < xs[li] - li * d) li = i;
        }
        int ri = m;
        for (int i = m + 1; i < r; ++i) {
            if (xs[i] + i * d < xs[ri] + ri * d) ri = i;
        }

        for (int i = l; i < m; ++i) {
            heap.emplace(i, ri, xs[i] + xs[ri] + (ri - i) * d);
        }
        for (int i = m; i < r; ++i) {
            heap.emplace(li, i, xs[li] + xs[i] + (i - li) * d);
        }

        que.emplace(l, m);
        que.emplace(m, r);
    }

    lint ans = 0;
    UnionFind uf(n);
    while (!heap.empty()) {
        auto e = heap.top();
        heap.pop();

        if (uf.same(e.src, e.dst)) continue;
        ans += e.cost;
        uf.unite(e.src, e.dst);
    }
    std::cout << ans << std::endl;
}

int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}


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

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

    int keta = 0;//桁数を求める
    if (n < 10)
        keta = 1;
    else if (n < 100)
        keta = 2;
    else if (n < 1000)
        keta = 3;
    else if (n < 10000)
        keta = 4;
    else if (n < 100000)
        keta = 5;
    else
        keta = 6;
    
    int ans;
    switch (keta){
        case 1:
            ans = n;
            break;
        case 2:
            ans = 9;
            break;
        case 3:
            ans = 9;
            ans += (n - 100 + 1);
            break;
        case 4:
            ans = 909;
            break;
        case 5:
            ans = 909;
            ans += (n - 10000 + 1);
            break;
        case 6:
            ans = 90909;
            break;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
while True:
    try:
        n=float(input())
    except:
        break
    num=2
    tmp=round(n,9)
    total=round(n,9)
    while num<=10:
        if num%2==0:
            tmp=round(tmp*2,9)
        else:
            tmp=round(tmp/3,9)
        total+=tmp
        num+=1
    print(round(total,8))



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

bool isPalindrome(std::string str){
    int len = str.size();
    --len;
    for(int i = 0; i < len; ++i){
        if(str[i] != str[len - i]) return false;
    }
    return true;
}

int main(){
    bool is_palindrome[10001];
    for(int i = 1; i <= 10000; ++i){
        is_palindrome[i] = isPalindrome(std::to_string(i));
        //if(is_palindrome[i]) std::cout << i << std::endl;
    }

    int n;

    std::cin >> n;

    for(int i = 0; ; ++i){
        if(n - i >= 0 && is_palindrome[n - i]){
            std::cout << n - i << std::endl;
            break;
        }
        
        if(n + i <= 10000 && is_palindrome[n + i]){
            std::cout << n + i << std::endl;
            break;
        }
    }

}

Measured memory_bytes: 3276
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
/*

*/
int main(){
  ll N; cin>>N;
  ll ans=N/1000;
  ans*=1000;
  if(ans==N)
    cout<<0<<endl;
  else{
    ans=1000-N%1000;
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 3636
import math
INFTY=100000000

n=int(input())

def kock(p1,p2,n):
    s=[(p1[0]*2+p2[0])/3, (p1[1]*2+p2[1])/3]
    t=[(p1[0]+p2[0]*2)/3, (p1[1]+p2[1]*2)/3]
    u=[(t[0]-s[0])/2-(t[1]-s[1])/2*math.sqrt(3)+s[0], (t[0]-s[0])/2*math.sqrt(3)+(t[1]-s[1])/2+s[1]]
    if n==0:
        print("%.8f %.8f"%(p1[0],p1[1]))
    else:
        kock(p1,s,n-1)
        kock(s,u,n-1)
        kock(u,t,n-1)
        kock(t,p2,n-1)

start=[0.0,0.0]
end=[100.0, 0.0]
if n==0:
    print("%.8f %.8f"%(start[0],start[1]))
    print("%.8f %.8f"%(end[0],end[1]))
else:
    kock(start,end,n)
    print("%.8f %.8f"%(end[0],end[1]))   




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

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF (1 << 29)
#define LLINF (1LL << 60)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;

string to_string(string s) { return s; }
template <class S>
string to_string(unordered_set<S> s);
template <class S>
string to_string(set<S> s);
template <class S, class T>
string to_string(map<S, T> m);
template <class T>
string to_string(vector<T> v);

template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}

template <class S>
string to_string(unordered_set<S> s) {
  string ret = "{";
  for (S x : s) ret += to_string(x) + ",";
  return ret + "}";
}

template <class S>
string to_string(set<S> s) {
  string ret = "{";
  for (S x : s) ret += to_string(x) + ",";
  return ret + "}";
}

template <class S, class T>
string to_string(map<S, T> m) {
  string ret = "{";
  for (pair<S, T> x : m) ret += to_string(x) + ",";
  return ret + "}";
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < (int)v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() { cerr << endl; }

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int N;
  cin >> N;
  string S;
  cin >> S;
  int ans = 0;
  for (int k = 1; k < N - 1; ++k) {
    int tmp = 0;
    for (int i = 0; i + k < N; ++i) {
      if (S[i] == S[i + k])
        tmp++;
      else
        tmp = 0;
      ans = max(ans, min(tmp, k));
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef struct pair<int,int> P;
typedef struct pair<int,P> P2;

int n;

int dp[31][1000001]={};
int d[31][1000001]={};

const ll INF=100000000001;
int main() {
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b)cout<<c<<endl;
	if(c==b)cout<<a<<endl;
	if(a==c)cout<<b<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define dfor(i,a,b) for(ll i=(a);i>=(b);i--)
#define mem(u, vis) memset(u, vis, sizeof(u))
#define ll long long
#define ull unsigned long long
#define MOD  1000000007
#define MAX  1e9
#define pb   push_back
#define F    first
#define S    second

signed main(){
	int t = 1;
	// cin>>t;
	while(t--){
		int n;
		cin>>n;
		string ans = n >= 30 ? "Yes" : "No";
		cout<<ans;
	}
}

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

int a, b;

int main() {
  cin >> a >> b;
  if(a == b){
    cout << "a == b" << endl;
  }else if(a > b){
    cout << "a > b" << endl;
  }else{
    cout << "a < b" << endl;
  }
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,a[N],sa[N],r[N];
bool cmp(int x,int y){return a[x]<a[y];}
int main()
{
scanf("%d",&n);
for (int i=1;i<=n;i++) scanf("%d",a+i),sa[i]=i;
sort(sa+1,sa+n+1,cmp);
for (int i=1;i<=n;i++) r[sa[i]]=i;
int ans=0;
for (int i=1;i<=n;i++)
if ((i&1)!=(r[i]&1)) ans++;
printf("%d\n",ans/2);
return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> A;
    int sub;
    for(int i = 0; i < N; i++){
        cin >> sub;
        A.push_back(sub);
    }
    
    sort(A.begin(), A.end());

    int x, y;
    x = A[0];
    for(int i = 1; i < A.size(); i++){
        y = A[i];
        if(y % x == 0)      continue;
        
        while(x > 0 && y > 0){
           if(x == y){
                break;
            }
            else if(x > y){
                x -= y;
            }
            else{
                y -= x;
            }
        }
        
        x = max(x, y);
    }
    
    cout << x << endl;
}

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

typedef long long ll;
const ll MOD = 1e9+7;
const ll INF = 1e18;
const int N = 2e5+5;
const ll M = 1e6+5;

template<int SZ>
struct LiChao_min{
    struct Line{
        ll k,m;
        Line(){k=0,m=0;}
        Line(ll _k,ll _m){k=_k,m=_m;}
        ll Get(ll x){return k*x+m;}
    };

    struct node{
        node *l, *r;
        Line p;

        node(){p=Line(),l=nullptr,r=nullptr;}
        node(ll k,ll m){p=Line(k,m),l=nullptr,r=nullptr;}
        node(Line _p){p=_p,l=nullptr,r=nullptr;}
    };
    typedef node* pnode;

    pnode root = nullptr;

    void Reset(){root=nullptr;}
    void Set(ll k,ll m){
        Line p = Line(k,m);
        Set(root,-SZ,SZ,p);
    }
    void Set(Line p){
        Set(root,-SZ,SZ,p);
    }
    ll Get(ll x){return Get(root,-SZ,SZ,x);}

    void Set(pnode &v,ll ss,ll se,Line t){
        if(!v){
            v = new node(t);
            return;
        }

        ll vss=v->p.Get(ss),vse=v->p.Get(se);
        ll tss=t.Get(ss),tse=t.Get(se);

        if(vss>tss&&vse>tse){v->p=t;return;}
        if(vss<=tss&&vse<=tse)return;

        //if(t.Get(ss)<v->p.Get(ss)&&t.Get(se)<v->p.Get(se)){v->p=t;return;}
        //if(t.Get(ss)>=v->p.Get(ss)&&t.Get(se)>=v->p.Get(se))return;

        ll mid=(ss+se)>>1LL;
        /*
        int64_t trl = nd->f.eval(l), trr = nd->f.eval(r);
		int64_t vl = v.eval(l), vr = v.eval(r);

		if(trl <= vl && trr <= vr) return;
		if(trl > vl && trr > vr) { nd->f = v; return; }

		int mid = (l + r) >> 1;
		if(trl > vl) swap(nd->f, v);
		if(nd->f.eval(mid) < v.eval(mid)) insert(v, mid + 1, r, nd->r);
        else swap(nd->f, v), insert(v, l, mid, nd->l);
        */
        if(vss>tss)swap(v->p,t);
        if(v->p.Get(mid)<t.Get(mid))Set(v->r,mid+1,se,t);
        else {
            swap(v->p,t);
            Set(v->l,ss,mid,t);
        }

        /*
        if(t.Get(ss)>v->p.Get(ss)&&t.Get(mid)<v->p.Get(mid)){
            swap(t,v->p);
            Set(v->l,ss,mid,t);
        }else if(t.Get(ss)>v->p.Get(ss)&&t.Get(mid)>v->p.Get(mid)){
            Set(v->r,mid+1,se,t);
        }else if(t.Get(ss)<v->p.Get(ss)&&t.Get(mid)>v->p.Get(mid)){
            Set(v->l,ss,mid,t);
        }else{
            swap(t,v->p);
            Set(v->r,mid+1,se,t);
        }
        */
    }

    ll Get(pnode &v,ll ss,ll se,ll x){
        if(v==nullptr)return INF;
        if(ss==se)return v->p.Get(x);

        ll mid=(ss+se)>>1LL;
        if(x<=mid)return min(v->p.Get(x),Get(v->l,ss,mid,x));
        return min(v->p.Get(x),Get(v->r,mid+1,se,x));
    }
};


LiChao_min<M> tree;
int n;
ll c,h[N],dp[N];

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n>>c;

    for(int i=1;i<=n;i++)cin>>h[i];

    dp[1]=0LL;
    //tree.init(M);
    //tree.add_line(-2LL*h[1],1LL*h[1]*h[1]);
    tree.Set(-2LL*h[1],1LL*h[1]*h[1]);

    for(int i=2;i<=n;i++){
        dp[i]=tree.Get(h[i])+h[i]*h[i]+c;
        //dp[i]=tree.query(h[i])+h[i]*h[i]+c;
        tree.Set(-2LL*h[i],dp[i]+1LL*h[i]*h[i]);
        //tree.add_line(-2LL*h[i],dp[i]+1LL*h[i]*h[i]);
    }
    cout<<dp[n];
    return 0;
}


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

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

long long total = 0;
for(int pairIndex=0; pairIndex<N-1; pairIndex++){
int first = pairIndex;
int second = pairIndex+1;
if(a[first] > x){
int diff = a[first] - x;
a[first] -= diff;
total += diff;
}
if(a[first] + a[second] > x){
int diff = a[first] + a[second] - x;
a[second] -= diff;
total += diff;
}
}

cout << total << '\n';
}

Measured memory_bytes: 3548
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
int main(){
	int a[105],b[105],len1,len2,vis,dis;
	char c[105],d[105];
	scanf("%s%s",c+1,d+1);
	len1=strlen(c+1);
	len2=strlen(d+1);
	for(int i=1;i<=len1;i++){
		a[i]=c[i]-'0';
		b[i]=d[i]-'0';
	}
	dis=0;
	if(len1>len2) printf("GREATER\n");
	else if(len1<len2) printf("LESS\n");
	else{
		for(int i=1;i<=len1;i++){
			if(a[i]<b[i]){
				vis=1;
				break;
			}
			else if(a[i]>b[i]){
				vis=2;
				break;
			}
			else{
				vis=3;
				dis++;
			}
		}
		if(vis==1) printf("LESS\n");
		else if(vis==2) printf("GREATER\n");
		else if(dis==len1) printf("EQUAL\n");
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update> pref_trie;
typedef unsigned long long BITMASK; typedef long long ll; typedef long double ld;
#define smallest_on_bit(bit_mask) (__builtin_ctzint((bit_mask) & (-(bit_mask))))
#define CLOCK_START clock_t chrono_clk_beg = clock()
#define CLOCK_END clock_t chrono_clk_end = clock(); cerr << (double(chrono_clk_end - chrono_clk_beg) / CLOCKS_PER_SEC) << " sec"
#define bug(args ...) cerr << __LINE__ << ">> ", err(new istringstream(string(#args)), args), cerr << '\n'
#define decToBin(name, num) string name = bitset<8>(num).to_string();
#define binToDec(name, binary) unsigned long name = bitset<8>(binary).to_ulong();
#define radToDeg(name, radians) double name = radians * 180 / M_PI;
#define all(x) x.begin(), x.end()
#define mapfind(mp, x) (mp.find(x) != mp.end())
#define arrfind(arr, x) (find(all(arr), x) != arr.end())
#define removeDuplicates(vec) sort(vec.begin(), vec.end()); vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define printMat(mat) for (auto &x : mat) { for (auto &y : x) cout << y << " "; cout << '\n'; }
#define printArr(arr) for (auto &x : arr) cout << x << " "; cout << '\n';
#define ceil(a, b) ((a+b-1)/b)
#define int ll
#define double ld
#define INF (1LL<<62)
#define M_PI 3.14159265358979323846
void err(istringstream *iss) {} template<typename T, typename ... Args> void err(istringstream *iss, const T &_val, const Args & ... args) { string _name; *iss >> _name; if (_name.back()==',') _name.pop_back(); cerr << _name << " = " << _val << "; ", err(iss, args ...); }
void str_replaceAll(string& str, const string& from, const string& to) { if(from.empty()) return; size_t start_pos = 0; while((start_pos = str.find(from, start_pos)) != std::string::npos) { str.replace(start_pos, from.length(), to); start_pos += to.length(); } }
#define MOD 1000000007

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n;
    cin >> n;
    cout << ceil(n, 2) << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define moder 100000
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue
using namespace std;
signed main(){
	double a,b,c;
	cin>>a>>b>>c;
	double d=(a+b+c)/2;
	cout<<(int)sqrt(d*(d-a)*(d-b)*(d-c))<<endl;
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  int result = 0;
  if (s[0] == '1') result++;
  if (s[1] == '1') result++;
  if (s[2] == '1') result++;
  cout << result << endl;
}

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long N, long long K, std::vector<long long> t, std::vector<long long> d){
    multiset<pair<int, int>> all, notIncluded, included;
    unordered_map<int, int> cnt;
    rep(i,0,N) all.insert({-d[i], t[i]});
    notIncluded = all;
    ll answer = 0;
    for (const auto& p : all) {
        if (included.size() == K) break;
        if (cnt.find(p.second) == cnt.end()) {
            cnt[p.second]++;
            answer += abs(p.first);
            notIncluded.erase(notIncluded.find(p));
            included.insert({abs(p.first), p.second});
        }
    }
    vector<pair<int, int>> toBeRemoved;
    for (const auto& p : notIncluded) {
        if (included.size() == K) break;
        cnt[p.second]++;
        answer += abs(p.first);
        toBeRemoved.push_back(p);
        included.insert({abs(p.first), p.second});
    }
    for (const auto& p : toBeRemoved) notIncluded.erase(notIncluded.find(p));
    for (const auto& p : included) {
        auto add = notIncluded.begin();
        auto remove = included.find(p);
        if (add == notIncluded.end() || remove == included.end() || abs(add->first) <= abs(remove->first)) break;
        if (add->second == remove->second || pow(cnt.size()-1,2) + abs(add->first) > pow(cnt.size(), 2) + abs(remove->first)) {
            notIncluded.erase(add);
            answer += abs(add->first) - abs(remove->first);
            cnt[remove->second]--;
            cnt[add->second]++;
            if (cnt[remove->second] == 0) cnt.erase(remove->second);
        }
    }
    answer += pow(cnt.size(),2);
    cout << answer << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> t(N);
    std::vector<long long> d(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&t[i]);
        scanf("%lld",&d[i]);
    }
    solve(N, K, std::move(t), std::move(d));
    return 0;
}


Measured memory_bytes: 15908
import bisect
a,b,q=map(int,input().split())
s=[int(input())for i in range(a)]
t=[int(input())for i in range(b)]
for i in range(q):
    x=int(input())
    c=bisect.bisect_left(s,x)
    d=bisect.bisect_left(t,x)
    p=[]
    if c!=a and d!=b:
        p.append(max(abs(s[c]-x),abs(t[d]-x)))
    if c!=0 and d!=0:
        p.append(max(abs(s[c-1]-x),abs(t[d-1]-x)))
    if c!=a and d!=0:
        p.append(min(abs(s[c]-x)*2+abs(t[d-1]-x),abs(s[c]-x)+2*abs(t[d-1]-x)))
    if c!=0 and d!=b:
        p.append(min(abs(s[c-1]-x)*2+abs(t[d]-x),abs(s[c-1]-x)+2*abs(t[d]-x)))
    print(min(p))

Measured memory_bytes: 12092
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int MOD=1e9+7;
int n, m, k;
string fr[250], to[250];
unordered_map<string, int> word;
string w[501];
unordered_map<int, int> dp[2][501][501];
vector<int> g[500];
struct node{
	node* nxt[26];
	node* fail;
	int cnt;
	int num;
	node():fail(nullptr), cnt(0), num(0){
		fill(nxt, nxt+26, nullptr);
	}
};
node v[602];
int nw, ns;
void add(string s){
	node* v0=&v[0];
	for(int i=0; i<s.size(); i++){
		if(!v0->nxt[s[i]-'a']){
			v0->nxt[s[i]-'a']=&v[ns];
			v[ns].num=ns;
			ns++;
		}
		v0=v0->nxt[s[i]-'a'];
	}
	v0->cnt++;
}
void addfail(){
	queue<node*> que;
	que.push(&v[0]);
	while(!que.empty()){
		node* v0=que.front(); que.pop();
		for(int i=0; i<26; i++){
			if(!v0->nxt[i]) continue;
			node* v1=v0;
			while(1){
				if(v1==&v[0]){
					v0->nxt[i]->fail=&v[0];
					break;
				}
				if(v1->fail->nxt[i]){
					v0->nxt[i]->fail=v1->fail->nxt[i];
					v0->nxt[i]->cnt+=v0->nxt[i]->fail->cnt;
					break;
				}
				v1=v1->fail;
			}
			que.push(v0->nxt[i]);
		}
	}
}

void init(){
	word.clear();
	for(int t=0; t<2; t++){
		for(int i=0; i<=m; i++){
			for(int j=0; j<nw; j++){
				dp[t][i][j].clear();
			}
		}
	}
	for(int i=0; i<nw; i++) g[i].clear();
	for(int i=0; i<ns; i++){
		v[i].fail=nullptr;
		fill(v[i].nxt, v[i].nxt+26, nullptr);
		v[i].cnt=v[i].num=0;
	}
}
int solve(){
	dp[0][0][0][0]=1;
	for(int i=0; i<m; i++){
		for(int j=0; j<nw; j++){
			for(int t=0; t<2; t++){
				for(auto p:dp[t][i][j]){
					int x=p.first;
					for(auto y:g[j]){
						if(i+(int)w[y].size()>m) continue;
						node* v0=&v[x]; int t1=t;
						for(int l=0; l<w[y].size(); l++){
							while(1){
								if(v0->nxt[w[y][l]-'a']){
									v0=v0->nxt[w[y][l]-'a'];
									break;
								}
								if(v0==&v[0]){
									break;
								}
								v0=v0->fail;
							}
							t1+=v0->cnt;
							if(t1>1) break;
						}
						if(t1>1) continue;
						dp[t1][i+(int)w[y].size()][y][v0->num]+=p.second;
						dp[t1][i+(int)w[y].size()][y][v0->num]%=MOD;
					}
				}
			}
		}
	}
	int ans=0;
	for(int i=1; i<nw; i++){
		for(auto p:dp[1][m][i]){
			ans+=p.second;
			ans%=MOD;
		}
	}
	return ans;
}
int main()
{
	while(1){
		init();
		cin>>n>>m>>k;
		if(n==0) return 0;
		for(int i=0; i<n; i++){
			cin>>fr[i]>>to[i];
			word[fr[i]]=0, word[to[i]]=0;
		}
		nw=1;
		for(auto& p:word){
			p.second=nw; w[nw]=p.first; nw++;
		}
		for(int i=0; i<n; i++){
			g[word[fr[i]]].push_back(word[to[i]]);
		}
		for(int i=1; i<nw; i++) g[0].push_back(i);
		ns=1;
		v[0].fail=&v[0];
		for(int i=0; i<k; i++){
			string s; cin>>s;
			add(s);
		}
		addfail();
		cout<<solve()<<endl;
	}
	return 0;
}


Measured memory_bytes: 165732
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int MAXN = 41;
const int mod = 1e9 + 7;
#define sz(v) ((int)v.size())

int n, m, px, py;
char str[MAXN][MAXN];
int sum[MAXN][MAXN];
int dp[MAXN][MAXN][MAXN][MAXN];

bool has(int sx, int ex, int sy, int ey){
	return sx <= px && px < ex && sy <= py && py < ey;
}

int gs(int sx, int ex, int sy, int ey){
	return sum[ex][ey] - sum[sx][ey] - sum[ex][sy] + sum[sx][sy];
}

int f(int sx, int ex, int sy, int ey){
	if(ex - sx == 1 && ey - sy == 1) return 0;
	if(~dp[sx][ex][sy][ey]) return dp[sx][ex][sy][ey];
	int ret = min({
		gs(sx, px + 1, sy, py + 1),
		gs(px, ex, py, ey),
		gs(sx, px + 1, py, ey),
		gs(px, ex, sy, py + 1)});
	for(int i=sx+1; i<ex; i++){
		int x1 = has(sx, i, sy, ey) ? f(sx, i, sy, ey) : gs(sx, i, sy, ey);
		int x2 = has(i, ex, sy, ey) ? f(i, ex, sy, ey) : gs(i, ex, sy, ey);
		ret = min(ret, x1 + x2);
	}
	for(int i=sy+1; i<ey; i++){
		int x1 = has(sx, ex, sy, i) ? f(sx, ex, sy, i) : gs(sx, ex, sy, i);
		int x2 = has(sx, ex, i, ey) ? f(sx, ex, i, ey) : gs(sx, ex, i, ey);
		ret = min(ret, x1 + x2);
	}
	for(int i=sx+1; i<ex; i++){
		for(int j=sy+1; j<ey; j++){
			if(has(sx, i, sy, j)){
				ret = min(ret, f(sx, i, sy, j) + gs(i, ex, sy, j) + gs(sx, i, j, ey));
			}
			if(has(i, ex, sy, j)){
				ret = min(ret, f(i, ex, sy, j) + gs(i, ex, j, ey) + gs(sx, i, sy, j));
			}
			if(has(sx, i, j, ey)){
				ret = min(ret, f(sx, i, j, ey) + gs(sx, i, sy, j) + gs(i, ex, j, ey));
			}
			if(has(i, ex, j, ey)){
				ret = min(ret, f(i, ex, j, ey) + gs(sx, i, j, ey) + gs(i, ex, sy, j));
			}
		}
	}
	return dp[sx][ex][sy][ey] = ret;
}

int main(){
	cin >> n >> m;
	for(int i=0; i<n; i++){
		cin >> str[i];
		for(int j=0; j<m; j++){
			if(str[i][j] == 'P'){
				px = i;
				py = j;
			}
			if(str[i][j] == '#') sum[i+1][j+1]++;
		}
	}
	for(int i=1; i<=n; i++){
		for(int j=1; j<=m; j++){
			sum[i][j] += sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1];
		}
	}
	memset(dp, -1, sizeof(dp));
	cout << f(0, n, 0, m) << endl;
}


Measured memory_bytes: 11264
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD 1000000007

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

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

    vector<int> A(N), B(M);
    rep(i, N) cin >> A[i];
    rep(i, M) cin >> B[i];

    sort(all(A));
    sort(all(B));

    unordered_set<int> sA(all(A)), sB(all(B));

    if (sA.size() != N || sB.size() != M) {
        cout << 0 << endl;
        return 0;
    }

    int ret = 1;
    for (int i = N * M; i >= 1; i--) {
        bool tA = sA.find(i) != sA.end();
        bool tB = sB.find(i) != sB.end();
        if (tA && tB) {

        } else if (tA) {
            auto it = lower_bound(all(B), i);
            int idx = distance(B.begin(), it);
            int num = M - idx;
            ret *= num;
        } else if (tB) {
            auto it = lower_bound(all(A), i);
            int idx = distance(A.begin(), it);
            int num = N - idx;
            ret *= num;
        } else {
            auto itA = lower_bound(all(A), i);
            auto itB = lower_bound(all(B), i);
            int idxA = distance(A.begin(), itA);
            int idxB = distance(B.begin(), itB);
            int numA = N - idxA;
            int numB = M - idxB;
            ret *= (numA * numB - (N * M - i));
        }

        ret %= MOD;
    }

    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
const int maxn=15;
const int INF=0x3f3f3f3f;
int n,m,x,cost[maxn],add[maxn][maxn];
int val[maxn];
bool type[maxn];
int check()
{
    memset(val,0,sizeof(val));
    for(int i=1;i<=n;i++)
        if(type[i])
            for(int j=1;j<=m;j++)
                val[j]+=add[i][j];
    for(int i=1;i<=m;i++)
        if(val[i]<x)
            return INF;
    int res=0;
    for(int i=1;i<=n;i++)
        if(type[i])
            res+=cost[i];
    return res;
}
int ans;
void dfs(int cur)
{
    if(cur==n+1)
    {
        ans=min(ans,check());
        return;
    }
    type[cur]=false; dfs(cur+1);
    type[cur]=true; dfs(cur+1);
    return;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin>>n>>m>>x;
    for(int i=1;i<=n;i++)
    {
        cin>>cost[i];
        for(int j=1;j<=m;j++)
            cin>>add[i][j];
    }
    ans=INF;
    dfs(1);
    cout<<(ans==INF?-1:ans)<<'\n';
    return 0;
}


Measured memory_bytes: 3620
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>
#include <stack>
#include <bitset>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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

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

  int n;
  cin >> n;
  string s;
  cin >> s;
  int r = 0, b = 0;
  REP(i, n){
    if(s[i] == 'R') r++;
    else b++;
  }
  cout << (r>b ? "Yes" : "No") << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define nmax_def 110000
#define Cmax_def 2200
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

int main() {
	int N;
	cin >> N;
	int ans = (N - 1) / 2;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict,deque
import numpy as np
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N = inp()
lines = defaultdict(set)
for _ in range(N-1):
    x,y = inpl()
    x,y = x-1,y-1
    lines[x].add(y)
    lines[y].add(x)

lines2 = defaultdict(set)
visited = [False]*N
def dfs(s):
    visited[s] = True
    for t in lines[s]:
        if not visited[t]:
            lines2[s].add(t)
            dfs(t)
dfs(0)

dp = [[-1,-1] for _ in range(N)]
def solve(s,c):
    global dp

    if dp[s][c] != -1:
        return dp[s][c]

    ans = 1
    if c == 0:
        for t in lines2[s]:
            ans *= solve(t,0)+solve(t,1)
            ans %= mod
    else: # c == 1
        for t in lines2[s]:
            ans *= solve(t,0)
            ans %= mod

    dp[s][c] = ans
    return ans

print((solve(0,0)+solve(0,1))%mod)


Measured memory_bytes: 166784
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;
 
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 long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;

 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>=(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
  
 

ll sum(ll n) {
ll m=0;
  while(n){
    m+=n%10;
    n/=10;
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
 
#define comuse Comuse()
 
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
 
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}




 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll q;
    cin>>q;
  vbl A(100100,true);
  FOR(i,2,100010){
    ll up=sqrt(i)+1;
    FOR(j,2,up){
      if(i%j==0){
         A[i]=false;
        break;
      }
    }
  }

  vll B(100100);
  for(int i=3;i<=100010;i+=2){
    if(A[i]&&A[(i+1)/2]){
      B[i]=B[i-2];
      B[i]++;
    }
    else{
      B[i]=B[i-2];
    }
  }
  FOR(i,0,q){
    ll l,r;
      cin>>l>>r;
    if(l==1){
      l+=2;
    }
    cout<<B[r]-B[l-2]<<endl;
  }
}

Measured memory_bytes: 1408
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main(void)
{
    int N;cin >>N;
    map<string,int> tizu;
    int Ma = 0;
    for(int i = 0;i <N;i++)
    {
        string s;cin >> s;
        tizu[s]++;    
    }
    for(const auto& e : tizu)
    {
        Ma = max(Ma,e.second);
    }
    for(const auto& e : tizu)
    {
        if(e.second == Ma)
        {
            cout << e.first << endl;    
        }    
    }
}


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

#define loop(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define dump(a) cerr << #a << " = " << (a) << "(L:" << __LINE__ << ")" << endl

const string YES = "Yes";
const string NO = "No";

void solve(long long A, long long B, long long C, long long D) {
    rep (i, 500) {
        if (i % 2 == 0) {
            C -= B;
        } else {
            A -= D;
        }

        if (C <= 0) {
            cout << YES << endl;
            return;
        } else if (A <= 0) {
            cout << NO << endl;
            return;
        }
    }
}

int main() {
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    long long C;
    scanf("%lld", &C);
    long long D;
    scanf("%lld", &D);
    solve(A, B, C, D);
    return 0;
}


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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N,M;
vector<ll> A,accX,accY;

int main()
{
	scanf("%d%d",&N,&M);
	A.assign(N,0);
	accX.assign(M * 2,0);
	accY.assign(M * 2,0);
	FOR(i,0,N){
		scanf("%lld",&A [i]);
	}

	ll ans = 0;
	FOR(i,0,N - 1){
		int l = A [i],r = A [i + 1];
		if(r < l) r += M;
		ans += r - l;
		accX [l] -= l;
		accX [r] += l;
		accY [l] += 1;
		accY [r] -= 1;
	}

	vector<ll> res(M);
	FOR(i,0,M * 2){
		if(i){
			accX [i] += accX [i - 1];
			accY [i] += accY [i - 1];
		}
		res [i % M] += accX [i];
		res [i % M] += accY [i] * i;
	}

	ans -= *max_element(res.begin(),res.end());
	printf("%lld\n",ans);
	
	return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
map<int,int>o;
map<int,int>e;
int main()
{
    int n;
    cin>>n;
    int m=0,M=0;
    int m1=0,M1=0;
    int a,A;
    for(int i=1;i<=n;i++){
        int t;
        cin>>t;
        if(i%2){
            o[t]++;
            //cout<<t<<' '<<o[t]<<endl;
            if(o[t]>m){
                m=o[t];
                a=t;
            }
            else if(o[t]>m1){
                    //cout<<t<<endl;
                m1=o[t];
            }
            //cout<<m1<<endl;
        }
        else {
            e[t]++;
            if(e[t]>M){
                M=e[t];
                A=t;
            }
            else if(e[t]>M1){
                M1=e[t];
            }
        }
    }
    //cout<<m<<' '<<M<<endl;
    //cout<<m1<<' '<<M1<<endl;
    if(A!=a)cout<<n-m-M;
    else {
        cout<<min(n-m-M1,n-M-m1);
    }
}


Measured memory_bytes: 4992
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
#include <numeric>
#include <bitset>
#include <map>
#include <limits.h>

using namespace std;

/// 各桁の和
int sumdigit(int x){
   int sum = 0;
    while(x != 0){
        sum += x % 10;
        x /= 10;    
    }
    return sum;
}
/// 最大公約数 
int gcd(int x, int y){
      if(x<y){
          int temp = x;
          x = y;
          y = temp;
      }
      int r = x % y;
       while(r!=0){
           x = y;
           y = r;
           r = x % y;
       }
      return y;
   }



int main(){
string S;
cin >> S;
int ans = 0;
int cnt0 = 0;
int cnt1 = 0;
for(int i = 0; i < S.size(); i++){
    if(S[i] == '0'){
        cnt0++;
    }
    else if(S[i] == '1'){
        cnt1++;
    } 
 }
 cout << 2 * min(cnt0,cnt1) << endl;
}

Measured memory_bytes: 512
N,M=map(int,input().split())

ab=[list(map(int,input().split())) for i in range(M)]

ans=0
stack=[]

for i in ab:
    if i[0]==1:
        stack.append([i[1],1+2**(i[1]-1)])

while len(stack)>0:
    p=stack.pop()

    if p[1]==2**N-1:
        ans+=1
    else:
        for i in ab:
            if i[0]==p[0] and not(2**(i[1]-1)&p[1]):
                stack.append([i[1],p[1]+2**(i[1]-1)])
            if i[1]==p[0] and not(2**(i[0]-1)&p[1]):
                stack.append([i[0],p[1]+2**(i[0]-1)])

print(ans)


Measured memory_bytes: 3064