akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1 << 29;
const int MOD = 1000000007;

// Union-Find
class UnionFind {
   public:
    vector<int> parent;  // 根の番号
    vector<int> height;  // 木の高さ
    vector<int> count;   // 根に含まれるノードの数(根を参照したときに限る)

    // 要素数nで初期化
    UnionFind(int n) : parent(n), height(n, 1), count(n, 1) {
        for (int i = 0; i < n; i++) {
            parent[i] = i;
        }
    }

    // 木の根を求める
    int root(int x) {
        // 根の場合
        if (parent.at(x) == x) return x;
        // 根ではない場合:経路圧縮しながら根を求める
        return parent.at(x) = root(parent.at(x));
    }

    // xとyが同じ集合に属するか否か
    bool same(int x, int y) {
        return root(x) == root(y);
    }

    // xとyの属する集合を併合
    void unite(int x, int y) {
        int rx = root(x), ry = root(y);
        // 既に同じ集合にある場合
        if (rx == ry) return;

        // 木の高さが低い方を高い方につなげる
        if (height[rx] < height[ry]) {
            parent.at(rx) = ry;
            // 小さい方の大きさを大きい方に足す
            count.at(ry) += count.at(rx);
        } else {
            parent.at(ry) = rx;
            count.at(rx) += count.at(ry);
            // 同じときはyの親をxにしてxの高さを1増やす
            if (height.at(rx) == height.at(ry)) height.at(rx)++;
        }
    }

    // xの属する集合の要素数
    int element_count(int x) {
        return count.at(root(x));
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    vector<int> b(m);
    rep(i, m) {
        cin >> a.at(i) >> b.at(i);
    }

    // UnionFInd treeで友達関係を管理
    UnionFind tree(n);

    rep(i, m) {
        // 友達関係の構築（値は-1する）
        tree.unite(a.at(i) - 1, b.at(i) - 1);
    }

    int num_max = 0;

    // 友達関係の集合の内、要素が最大のものの要素数でグループを分ければよい
    rep(i, n) {
        int element = tree.element_count(i);
        if (element > num_max) {
            num_max = element;
        }
    }

    cout << num_max << endl;
}


Measured memory_bytes: 7148
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O0")
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1e9+7;
const ll INF = 1e18;
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  ll ans = 0;
  rep(i,n-1) {
    if (a[i] > a[i+1]) {
      ans += a[i]-a[i+1];
      a[i+1] += a[i]-a[i+1];
    }
  }
  cout << ans << '\n';

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}

Measured memory_bytes: 4832
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#define ll long long
#define re register
using namespace std;
struct ios{
	inline char fchar(){
		static char buf[100000],*p1=buf,*p2=buf;
		return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
	}
//	#define getchar fchar
	template <typename ty> inline ios& operator >> (ty &x)
	{
		register int f=1;x=0;register char c=getchar();
		for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
		for(;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
		x*=f;return *this;
	}
	template <typename ty>  inline ios& operator << (ty x)
	{
		if(x<0) x=-x,putchar('-');
		if(x>9) *this << x/10;
		putchar(x%10+48);
		return *this;
	}
	inline ios& operator << (char x){putchar(x);return *this;}
}io;
const int N = 6e4+5;

int n;
int a[1005];
priority_queue<double,vector<double>,greater<double> > q;
int main()
{
	io >> n;
	for(int i=1;i<=n;i++) io >> a[i],q.push(a[i]);
	for(int i=1;i<n;i++)
	{
		double t1 = q.top();q.pop();
		double t2 = q.top();q.pop();
		q.push(1.0*(t1+t2)/2);
	}
	printf("%.2lf",q.top());
	
	return 0;
} 

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

class union_find{
	private:
	vector<int> parent,rank,gs;
    int size;
	public:
    int count_group;
    union_find()=default;
    union_find(int n){ init(n); }
    void init(int n){
		size=n;
		count_group=n;
		parent.resize(size);
		rank.assign(size,0);
        gs.assign(size,1);
		for(int i=0; i<size; ++i) parent[i]=i;
	}
	int find(int x){
		if(parent[x]==x) return x;
		else return parent[x]=find(parent[x]);
	}
	void unite(int x,int y){
		x=find(x);
		y=find(y);
		if(x==y) return;
		if(rank[x]<rank[y]){
			parent[x]=y;
            gs[y]+=gs[x];
		} else {
			parent[y]=x;
            gs[x]+=gs[y];
			if(rank[x]==rank[y]) ++rank[x];
		}
		--count_group;
	}
	bool is_same_group(int x,int y){
		return find(x)==find(y);
	}
    int group_size(int x){
        return gs[find(x)];
    };
};

struct edge{
    int from,to,cost;
    bool operator<(const edge& other)const{
        return cost<other.cost;
    }
};

void solve(){
    int n,m;
    cin >> n >> m;
    vector<edge> edges;
    rep(i,0,m){
        int a,b,c;
        cin >> a >> b >> c;
        --a;
        --b;
        edges.push_back(edge({a,b,c}));
    }
    sort(edges.begin(),edges.end());

    union_find uf(n);
    vector<bool> use(m);
    int64_t sum_cost=0;
    rep(i,0,m){
        edge &e=edges[i];
        if(uf.is_same_group(e.to,e.from)) continue;
        uf.unite(e.to,e.from);
        sum_cost+=e.cost;
        use[i]=true;
    }

    vector<vector<pair<int,int>>> graph(n);
    rep(i,0,m){
        if(!use[i]) continue;
        print(edges[i].from+1);
        print(edges[i].to+1);
        graph[edges[i].from].push_back(make_pair(edges[i].to,edges[i].cost));
        graph[edges[i].to].push_back(make_pair(edges[i].from,edges[i].cost));
    }

    vector<vector<int>> max_cost(n,vector<int>(n));
    vector<bool> done(n);
    function<void(int,int,int)> dfs=[&](int s,int u,int ma){
        done[u]=true;
        max_cost[s][u]=ma;
        for(auto &p:graph[u]){
            if(done[p.first]) continue;
            dfs(s,p.first,max(ma,p.second));
        }
        done[u]=false;
    };
    rep(i,0,n) dfs(i,i,0);
    rep(i,0,n){
        print(i+1);
        rep(j,0,n){
            print(j+1);
            print(max_cost[i][j]);
        }
    }
    int q;
    cin >> q;
    rep(i,0,q){
        int s,t;
        cin >> s >> t;
        --s;
        --t;
        cout << sum_cost-max_cost[s][t] << endl;
    }
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 69100
let n = stdin.ReadLine() |> int
let s = stdin.ReadLine().ToCharArray()

let charCount char = s |> Array.filter (fun x -> x = char)|> Array.length
let wNum, eNum = charCount 'W', charCount 'E'

let countAns =
    let ansArray = Array.zeroCreate n
    let rec countAns i =
        if 0 < i && i < n - 1 then
            let acc =
                if s.[i-1] = 'W' then 1 else 0
                - if s.[i] = 'E' then 1 else 0 
            ansArray.[i] <- ansArray.[i-1] + acc
            countAns (i+1)
        elif i = 0 then
            ansArray.[0] <- eNum - (if s.[i] = 'E' then 1 else 0)
            countAns (i+1)
        else 
            let acc =
                if s.[i-1] = 'W' then 1 else 0
                - if s.[i] = 'E' then 1 else 0 
            ansArray.[i] <- ansArray.[i-1] + acc

    countAns 0
    ansArray

countAns |> Array.min |> stdout.WriteLine 

Measured memory_bytes: 16736
#define CPP_IO

#pragma region

#ifdef LOCAL
#define debug cout
#else
#define debug \
    if (0) cout
#endif

#include <bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;
using ll = long long;

template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    os << "[ ";
    for (auto e : v) os << e << " ";
    return os << "]";
}

template <typename T, typename V>
ostream& operator<<(ostream& os, set<T, V> v) {
    os << "{ ";
    for (auto e : v) os << e << " ";
    return os << "}";
}

template <typename T, typename V, typename S>
ostream& operator<<(ostream& os, map<T, V, S> v) {
    os << "{ ";
    for (auto e : v) os << e << " ";
    return os << "}";
}

template <typename T, typename V>
ostream& operator<<(ostream& os, pair<T, int> x) {
    return os << "( " << x.first << ", " << x.second << " )";
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    for (auto& e : v) is >> e;
    return is;
}

template <typename T, typename V>
istream& operator>>(istream& is, pair<T, V>& x) {
    return is >> x.first >> x.second;
}

template <typename T>
T divfloor(T a, T b) {
    assert(b != 0);
    if (a >= 0 && b > 0 || a <= 0 && b < 0) return a / b;
    return (a % b == 0) ? a / b : a / b - 1;
}

template <typename T>
T divceil(T a, T b) {
    assert(b != 0);
    if (a >= 0 && b > 0 || a <= 0 && b < 0) return (a % b == 0) ? a / b : a / b + 1;
    return a / b;
}

void solve();

int main() {
#ifdef LOCAL
    freopen("data.txt", "r", stdin);
#else
#ifdef CPP_IO
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
#endif
    solve();
}

#pragma endregion

int sum(const vector<int>& s, int i, int j) {
    if (j) return s[i] - s[j - 1];
    return s[i];
}

void solve() {
    const int mod = 1e9 + 7;
    int n;
    string s;
    cin >> n >> s;
    auto dp = vector<vector<int>>(2);
    dp[0] = {1};
    for (int i = 1; i < n; ++i) {
        auto& cur = dp[i & 1];
        auto& pre = dp[(i - 1) & 1];
        cur.resize(i + 1);
        if (s[i - 1] == '>') {
            cur[i] = 0;
            for (int j = i - 1; j >= 0; --j) cur[j] = (cur[j + 1] + pre[j]) % mod;
        } else {
            cur[0] = 0;
            for (int j = 1; j <= i; ++j) cur[j] = (cur[j - 1] + pre[j - 1]) % mod;
        }
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) ans = (ans + dp[(n - 1) & 1][i]) % mod;
    cout << ans << "\n";
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstddef>
#include<queue>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    int n;
    cin >> n;
    long long ans = 1;
    vector<long long> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a.at(i);
        if(a.at(i) == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    for(int i = 0; i < n; ++i){
        if(a.at(i) > 1000000000000000000 / ans){
            ans = -1;
            break;
        }
        ans *= a.at(i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3984
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A, B, V):
    V.sort(reverse=True)
    mean = sum(V[:A])/A

    print(mean)

    if A == N:
        return 1

    c = V[:A].count(V[A-1])
    d = V[A:].count(V[A-1])

    if d == 0:
        return 1

    @lru_cache(maxsize=None)
    def comb2(n, r):
        if n < 0 or r < 0 or n < r:
            return 0
        elif n == 0 or r == 0:
            return 1
        return comb2(n-1, r-1)+comb2(n-1, r)

    if V[0] == V[A-1]:
        return sum([comb2(c+d, i) for i in range(A, B+1)])

    return comb2(c+d, c)


def main():
    N, A, B = read_int_n()
    V = read_int_n()

    print(slv(N, A, B, V))


if __name__ == '__main__':
    main()


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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout.precision(12);
    cout.setf(ios_base::fixed, ios_base::floatfield);
    
    int n, m;
    cin >> n >> m;
    int a[200000];
    for(int i=0;i<n;i++) cin >> a[i];
    sort(a, a+n);
    vector<pair<int, int>> cb;
    for(int i=0;i<m;i++){
        int b, c;
        cin >> b >> c;
        cb.emplace_back(c, b);
    }
    sort(cb.rbegin(), cb.rend());
    int adr = 0;
    for(auto p : cb){
        if(adr >= n) break;
        for(int i=0;i<p.second;i++){
            if(a[adr]<p.first){
                a[adr] = p.first;
                adr++;
                if(adr >= n) goto next;
            }else break;
        }
    }next: ;

    int64_t ans = 0;
    for(int i=0;i<n;i++) ans += a[i];
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1784
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

	vector<ll> cnt_R(n,0);
	vector<ll> cnt_G(n,0);
	vector<ll> cnt_B(n,0);
	for(int i = 0;i < n;i++){
		if(s[i] == 'R'){
			cnt_R[i] = 1;
		}
		if(s[i] == 'G'){
			cnt_G[i] = 1;
		}
		if(s[i] == 'B'){
			cnt_B[i] = 1;
		}
	}

	for(int i = 0;i < n-1;i++){
		cnt_R[i+1] = cnt_R[i+1] + cnt_R[i];
		cnt_G[i+1] = cnt_G[i+1] + cnt_G[i];
		cnt_B[i+1] = cnt_B[i+1] + cnt_B[i];
	}

	ll ans = 0;
	for(int j = 1;j < n-1;j++){
		for(int k = j+1;k < n;k++){
			if((s[j] == 'R' && s[k] == 'G') || (s[j] == 'G' && s[k] == 'R')){
				ans += cnt_B[j-1];
				int i = 2 * j - k;
				if(i >= 0 && i < n && i != j && i != k && s[i] == 'B')ans--;
			}
			else if((s[j] == 'G' && s[k] == 'B') || (s[j] == 'B' && s[k] == 'G')){
				ans += cnt_R[j-1];
				int i = 2 * j - k;
				if(i >= 0 && i < n && i != j && i != k && s[i] == 'R')ans--;
			}
			else if((s[j] == 'R' && s[k] == 'B') || (s[j] == 'B' && s[k] == 'R')){
				ans += cnt_G[j-1];
				int i = 2 * j - k;
				if(i >= 0 && i < n && i != j && i != k && s[i] == 'G')ans--;
			}
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

int main() {
    int N; cin >> N;
    map<string,int> mp;
    rep(i,N) {
        string s; cin >> s;
        mp[s] ++;
    }
    int M; cin >> M;
    rep(i,M) {
        string s; cin >> s;
        mp[s] --;
    }
    int ans = 0;
    for (auto &p:mp) {
        ans = max(ans,p.second);
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3612
import collections
N=int(input())
L=[]
NL=[]
cL={}
for _ in range(N):
  L.append(str(input()))

cL=collections.Counter(L)
v,c=zip(*cL.most_common())

for i in range(len(v)):
           if c[0]==c[i]:
           	NL.append(v[i])
NL.sort()
for j in range(len(NL)):
           print(NL[j])

Measured memory_bytes: 59500
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
#include<math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,m,n) for(ll i=m;i<(ll)(n);i++)
typedef pair<int,long long> pint;
typedef long long ll;
const ll mod= 1e9+7;
const ll  longinf = 1LL<<60;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

vector<pint> v[3010];
ll dist[3010];
int used[3010];
int f[6000],t[6000],d[6000];
int n,m,p;
void bfs(){
    dist[0]=0;
    rep(_,3*m){
    vector<ll> nd(3000,longinf);
    rep(i,n)nd[i]=dist[i];
    rep(i,m){
        nd[t[i]]=min(nd[t[i]],dist[f[i]]+d[i]);
    }
    if(dist[n-1]>nd[n-1])used[n-1]=_;
    rep(i,n)dist[i]=nd[i];
    }
}

int main(){
  cin>>n>>m>>p;
  rep(i,m){
    ll a,b,c;
    cin>>a>>b>>c;
    f[i]=a-1;
    t[i]=b-1;
    d[i]=p-c;
    }
  rep(i,n)dist[i]=longinf;
  bfs();
  if(used[n-1]>m)cout<<-1<<endl;
  else cout<<max(-dist[n-1],0ll)<<endl;
  return 0;
  }


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

typedef long long ll;

int a, b, c, d, x, y;

int main() {
	cin>>a>>b>>c>>d;
	x = (c + b - 1)/b;
	y = (a + d - 1)/d;
	if(x <= y) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int my_gcd(int a,int b){
	while(b!=1){
		if(a%b == 0) return b;
		int temp = a;
		a = b;
		b = temp%b;
	}
	return 1;
}

int main(){
	int n,x,a;
	
	cin >> n >> x;
	int k = n;
	if(n==1) {cin >> a; cout << abs(x-a); return 0;}
	vector<int> v;
	v.push_back(x);
	while(n--){
		cin >> a;
		v.push_back(a);
	}
	sort(v.begin(),v.end());
	int g = my_gcd(abs(v[1]-v[0]),abs(v[2]-v[1]));
	for(int i = 2; i<k;i++){
		g = my_gcd(v[i+1]-v[i],g);
	}
	cout << g;
	
}
		
		
    
	



Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
//ofstream cout("output.out");

#define fast() {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
#define o(a) { cout << #a << ":" << (a) <<" ";}
#define ov(a) { cout << "["; \
	for(int i = 0; i < (a).size(); ++i){ \
		cout << i <<":" << a[i] <<" "; \
		if(i % 10 == 9) cout <<"\n"; \
		} \
	cout << "]"; \
}
#define ovv(a) { cout << "["; \
	for(int i = 0; i < a.size(); ++i){ \
		for(int j = 0; j < a[i].size(); ++j){ \
			cout << "(" << i <<"," <<j <<")" <<":" << a[i][j] <<" "; \
		} \
		cout << "\n"; \
	} \
	cout << "]"; \
}
#define op(a) { cout <<"[" << #a << ".fi:"<<a.first; \
					cout << " "<< #a << ".se:" << a.second <<"]"; }

#define ll long long
int n, m, k, q;

int main(){
	fast();
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int t1 = a / d + (a % d == 0 ? 0 : 1);
	int t2 = c / b + (c % b == 0 ? 0 : 1);
	if (t1 >= t2){
		cout << "Yes";
	}
	else cout << "No";
}

Measured memory_bytes: 3652
#include <algorithm>
#include <iostream>
using namespace std;
int N;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;

  if (N == 2) { cout << -1 << endl; return 0; }
  if (N % 2 == 1) {
    for (int j = 0; j < N; ++j) {
      for (int k = 0; k < N-1; ++k) {
        if (k > 0) { cout << ' '; }
        cout << (j+k+1) % N + 1;
      } cout << endl;
    }
    return 0;
  }

  for (int j = 0; j < N/2; ++j) {
    for (int k = 0; k < N-1; ++k) {
      if (k > 0) { cout << ' '; }
      cout << (j+k+1)%N+1;
    }
    cout << endl;
  }
  for (int j = N/2; j < N; ++j) {
    for (int k = 0; k < N-1; ++k) {
      if (k > 0) { cout << ' '; }
      if (k == N/2-1) { cout << (j+N/2+1)%N + 1; }
      else if (k == N/2) { cout << (j+N/2)%N + 1; }
      else { cout << (j+k+1)%N+1; }
    }
    cout << endl;
  }

  return 0;
}

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

int main() {
    int n;
    cin >> n;
    int odds = (n+1)/2;
    double ans = double(odds)/double(n);
    cout << ans << endl;
}

Measured memory_bytes: 256
from sys import stdin

q,h,s,d = [int(x) for x in stdin.readline().split()]
n = int(stdin.readline().strip())

min_for_one = min([q*4, h*2, s])
min_for_two = min([min_for_one*2, d])

print(n//2*min_for_two + n%2*min_for_one)

Measured memory_bytes: 9104
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def brute_force():
    N, M = map(int, input().split())
    lamps = [list(map(lambda x:int(x)-1, input().split()))[1:]
             for _ in range(M)]
    p = list(map(int, input().split()))
    ans = 0

    for i in range(1 << N):
        for r in range(M):
            on_sum = 0
            for j in range(N):
                if i >> j & 1 and j in lamps[r]:
                    on_sum += 1
            if on_sum % 2 != p[r]:
                break
        else:
            ans += 1
    print(ans)


brute_force()


Measured memory_bytes: 3064
// 提出時に消す


import java.util.Scanner;

// 提出時にMainに変更する
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        if (Character.isUpperCase(sc.next().charAt(0))) {
            System.out.println("A");
        } else {
            System.out.println("a");
        }

        sc.close();
    }
}

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

typedef struct Poker{
	char sign, value;  // sign表示花色 , value表示值 
}Poker;

void BubbleSort(Poker C[], int n){
	for(int i = 0; i < n; i++){
		for( int j = n-1; j >= i+1; j--){
			if(C[j].value < C[j-1].value){
				Poker t = C[j];
				C[j] = C[j-1];
				C[j-1] = t;
			}
		}
	}
}

void SelectionSort(Poker C[], int n){
	for(int i = 0; i < n; i++){
		int min = i;
		for(int j = i; j < n; j++){
			if(C[j].value < C[min].value)
				min = j;
		}
		Poker t = C[i];
		C[i] = C[min];
		C[min] = t;
	}
}

bool isStable(Poker C1[], Poker C2[], int n){  // use bubble_sort to check selectionSort' stable 
	for(int i = 0; i < n; i++){
		if(C1[i].sign != C2[i].sign)
			return false;  // Not stable
	}
	return true;  // Stable
}

void printInfo(Poker C[], int n){
	for(int i = 0; i < n; i++){
		if(i) cout << " ";
		cout << C[i].sign << C[i].value; 
	}
	cout << endl;
}

int main(){
	int n;
	cin >> n;
	if( n < 1 || n > 36 )
		return 0;  // end.
	Poker C1[100], C2[100];
	for(int i = 0; i < n; i++)
		cin >> C1[i].sign >> C1[i].value;
	
	// 复制C1到C2 
	for(int i = 0; i < n; i++)
		C2[i] = C1[i];
	
	BubbleSort(C1, n);
	SelectionSort(C2, n);
	
	printInfo(C1, n);
	cout << "Stable" << endl;
	printInfo(C2, n);
	if(isStable(C1, C2, n))
		cout << "Stable" << endl;
	else
		cout << "Not stable" << endl;
	
	return 0;
} 


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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int k, n; cin >> k >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());

    int ans = a[n-1] - a[0];
    for(int i = 0; i < n-1; i++){
        ans = min(ans, k - (a[i+1] - a[i]));
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
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 n, h, a[100010], b[100010];
int amax = 0;
vector<int> thr;

int iceil(int x, int y) {
    return (x + y - 1) / y;
}

int main() {
    cin >> n >> h;
    rep(i, n) {
        cin >> a[i] >> b[i];
        amax = max(amax, a[i]);
    }
    rep(i, n) {
        if (b[i] > amax) thr.push_back(b[i]);
    }
    sort(thr.begin(), thr.end(), greater<int>());

    int ans = 0;
    for (int &x: thr) {
        h -= x;
        ans++;
        if (h <= 0) {
            cout << ans << endl;
            return 0;
        }
    }
    ans += iceil(h, amax);
    cout << ans << endl;
}


Measured memory_bytes: 1660
#include <iostream>
#include <vector>
#include <map>
#include <queue>

using namespace std;

class BIT
{
 public:
  vector<int> bit;
  int M;

  BIT(int M):
      bit(vector<int>(M+1, 0)), M(M) {}

  int sum(int i) {
    if (!i) return 0;
    return bit[i] + sum(i-(i&-i));
  }

  void add(int i, int x) {
    if (i > M) return;
    bit[i] += x;
    add(i+(i&-i), x);
  }
};

int main() {
  int N, Q;
  cin >> N >> Q;
  vector<int> C;
  for (int i = 0; i < N; i++) {
    int c;
    cin >> c;
    C.push_back(c-1);
  }

  vector<tuple<int, int, int>> queries;
  for (int q = 0; q < Q; q++) {
    int l, r;
    cin >> l >> r;
    queries.push_back(make_tuple(l-1, r-1, q));
  }
  sort(queries.begin(), queries.end(),
       [](const tuple<int, int, int> &a,
          const tuple<int, int, int> &b) {
         if (get<1>(a) < get<1>(b)) return 1;
         return 0;
       });
  vector<int> ans(Q);
  vector<int> rightmost(N, -1);
  BIT bit(N);
  int start = 0;
  for (tuple<int, int, int> query : queries) {
    for (int i = start; i <= get<1>(query); i++) {
      if (rightmost[C[i]] >= 0) {
        bit.add(rightmost[C[i]]+1, -1);
      }
      rightmost[C[i]] = i;
      bit.add(i+1, 1);
    }
    ans[get<2>(query)] = bit.sum(get<1>(query)+1)-bit.sum(get<0>(query)-1+1);

    start = get<1>(query) + 1;
  }
  for (int a : ans) {
    cout << a << endl;
  }
}




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

int main()
{
    ll l, r;
    cin >> l >> r;
    int ans = 2019;
    // r = min(r, l + 2019 * 2);
    for (ll i = l; i < r; i++)
    {
        for (ll j = i + 1; j <= r; j++)
        {
            int w = i * j % 2019;
            if (ans > w)
                ans = w;
            if (ans == 0)
            {
                cout << ans << endl;
                return 0;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    ll N;
    cin >> N;
    ll ai, bi, ci;
    vector<set<ll>> g(N, set<ll>());
    for(int i=0;i<N-1;i++){
        cin >> ai >> bi;
        ai--; bi--;
        g[ai].insert(bi);
        g[bi].insert(ai);
    }
    vector<ll> C;
    for(int i=0;i<N;i++){
        cin >> ci;
        C.push_back(ci);
    }
    sort(C.begin(), C.end());

    set<ll> used;
    queue<ll> q;
    ll ic = N-1;
    vector<ll> res(N, -1);
    q.push(0);
    used.insert(0);
    while(!q.empty()){
        auto v = q.front(); q.pop();
        res[v] = C[ic--];
        for(auto x : g[v]){
            if(used.count(x)) continue;
            q.push(x);
            used.insert(x);
        }
    }
    auto M = accumulate(C.begin(), C.end(), (ll)0);
    M -= C.back();
    cout<<M<<endl;
    for(auto d : res){
        cout<<d<<" ";
    }
    cout<<endl;

    return 0;
}


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

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

        if(n == 0)  break;

        int A[n];
        for(int i = 0; i < n; i++)  cin >> A[i];

        int x;
        cin >> x;
        int ans = 0;
        int r = n-1, l = 0;

        while(l <= r){
            ans++;
            int mid = (r+l)/2;
            if(A[mid] == x || l > r) break;
            else if(A[mid] < x) l = mid+1;
            else if(A[mid] > x) r = mid-1;
        }

        cout << ans << endl;
    }
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    set<int> s;
    for(int i=0; i<n; i++){
        int d;
        cin >> d;
        s.insert(d);
    }
    cout << s.size() << endl;
    return 0;
}


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

int main() {
    int N,c=0;
    cin >> N;

    rep(i,55556) {
        int t = i+2;

        bool isP=0;
        for(int j=2; j*j<=t; j++)
            if(t%j == 0)    
                isP = 1;
        
        if(!isP && t%5==1) {
            cout << t << " ";
            c++;
        }

        if(c == N)
            break;
    }
}

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

int k;
string cur,unlocking;
int minCnt;

void dfs(int idx,int cnt){
    if(idx==k){
        minCnt=min(minCnt,cnt);
        return;
    }
    if(minCnt<=cnt)
        return;
    string tmp=cur;
    // ツづつアツづ慊づ連ツ督ョツつウツつケツづゥツつゥツづ湘ェツ債づュツつッ
    for(int j = idx; j < k; j++){
        bool isDec=false;
        // diffツ閉ェツつセツつッツ嘉アツ転
        int diff=cur[idx]-unlocking[idx];
        if(abs(diff)!=0){
            // ツ嘉アツ転ツつウツつケツづゥ
            for(int i = idx; i <= j; i++)
                cur[i]=(cur[i]-'0'-diff+10)%10+'0';
            // rec
            dfs(idx+1,cnt+1);
            cur=tmp;
        }
        else
            dfs(idx+1,cnt);
    }
}

int main(){
    while(cin>>k&&k!=0){
        minCnt=10000;
        cin>>cur>>unlocking;
        dfs(0,0);
        cout<<minCnt<<endl;
    }

    return 0;
}

Measured memory_bytes: 928
#include <stdio.h>
#include <string.h>

int main() {

    char s[200001];
    char t[200001];

    scanf("%s %s", s, t);

    int cnt = 0;
    for (int i = 0; i < strlen(s); i++) {
        if (s[i] != t[i]) {
            cnt++;
        }
    }

    printf("%d", cnt);


    return 0;
}


Measured memory_bytes: 2100
s = input()

a = int(s[:2])
b = int(s[2:])

if 0 <  a <= 12 and 0 < b <= 12:
  print("AMBIGUOUS")
elif (a > 12 or a == 0) and 0 < b <= 12:
  print("YYMM")
elif 0 < a <= 12 and (b > 12 or b == 0):
  print("MMYY")
else:
  print("NA")

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

int main() {
	int x, y;
	cin >> x >> y;

	bool flag = false;
	for (int i = 0; i <= x; i++) {
		if (i*4 + (x-i)*2 == y) {
			flag = true;
			cout << "Yes" << endl;
			break;
		}
	}

	if (!flag) cout << "No" << endl;
}

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

#define ll long long
#define mtv(kit) cout<<#kit<<" - "<<kit<<"\n";
#define ff first
#define ss second
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define pii pair<ll , ll>
#define ump unordered_map<ll , ll>

void doit(){
	ll n,m,i,x;
	cin >> n>> m ;
	bool ok=0;
	rep(i,0,n+1){
		x=(i*2) + ((n-i)*4);
		if(x==m){ok=1 ; break;}
	}
	if(ok)cout<<"Yes"<<"\n";
	else cout << "No"<<"\n";
}	

int main() {
#ifndef ONLINE_JUDGE
	freopen("input1.txt","r",stdin);
	freopen("output1.txt","w",stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t = 1;
	//cin>>t;
	for(ll i = 1; i <= t; i++){
		doit();
	}
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const long double EPS = 1e-10;

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

  FOR(i, 1, 10) {
    if (n % i == 0 && 1 <= n / i && n / i <= 9) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;



  
  return 0;
}

Measured memory_bytes: 256
#include <stdlib.h>
#define INFINITY 1000000001

void merge(int *, int, int, int);
void mergeSort(int *, int, int);

int nn=0;

main(){
  int n, *arryA, i;

  scanf("%d", &n);
  arryA = (int *)malloc(sizeof(int) * n);
  for(i=0; i<n; i++) scanf("%d", arryA+i);

  mergeSort(arryA, 0, n);
  for(i=0; i<n-1; i++) printf("%d ", arryA[i]);
  printf("%d\n%d\n", arryA[i], nn);
 
  free(arryA);
  return 0;
}

void merge(int *arryA, int left, int mid, int right){
  int n1, n2, i, j, k, *arryL, *arryR;

  n1 = mid - left;
  n2 = right - mid;

  arryL = (int *)malloc(sizeof(int)*(n1 + 1));
  arryR = (int *)malloc(sizeof(int)*(n2 + 1));
  for(i=0; i<n1; i++) arryL[i] = arryA[left+i];
  for(i=0; i<n2; i++) arryR[i] = arryA[mid+i];
  arryL[n1] = INFINITY;
  arryR[n2] = INFINITY;

  /* printf("**merge(%d, %d, %d) n(L)=%d\n", left, mid, right, n1);
  for(i=0; i<(n1+1); i++) printf("%d ", arryL[i]);
  printf("\n");
  printf("**merge(%d, %d, %d) n(R)=%d\n", left, mid, right, n2);
  for(i=0; i<(n2+1); i++) printf("%d ", arryR[i]);
  printf("\n\n");*/

  i=0;//L
  j=0;//R

  for(k=left; k<right; k++){
    nn++;
    if(arryL[i] <= arryR[j]){
      arryA[k] = arryL[i++];
    }
    else
      arryA[k] = arryR[j++];
  }

  free(arryL);
  free(arryR);
}

void mergeSort(int *arryA, int left, int right){
  int mid;

  if(left+1 < right){
    mid = (right + left) / 2;
    mergeSort(arryA, left, mid);
    mergeSort(arryA, mid, right);
    merge(arryA, left, mid, right);
  }
}

Measured memory_bytes: 4484
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
const Int MOD = 1000000007;
int main()
{
    int N; cin >> N;
    vector<int> C(N); for (auto& c : C) cin >> c, c--;
    vector<Int> prev(N), dp(N), number(200000, -1);
    for (int i = 0; i < N; i++) {
        prev[i] = number[C[i]];
        number[C[i]] = i;
    }
    dp[0] = dp[1] = 1;
    for (int i = 2; i < N; i++) {
        if (prev[i] != -1 && prev[i] != i-1) {
            dp[i] = (dp[i-1] + dp[prev[i]]) % MOD;
        } else {
            dp[i] = dp[i-1];
        }
    }
    cout << dp[N-1] << endl;
    return 0;
}

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

int main()
{
    string s;
    int i,j,k,l,mx,mx1,a[200005],b[200005];
    while(cin>>s)
    {

        k=0;
        l=0;
        for(i=0;i<s.size();i++)
        {
            if(s[i]=='A')
            {
                a[k++]=i;
            }
            if(s[i]=='Z')
            {
                b[l++]=i;
            }

        }
      sort(a,a+k);
      sort(b,b+l);
          cout<<b[l-1]-a[0]+1<<endl;
    }
    return 0;

}



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


int main()
{
	int64_t n, m;
	cin >> n >> m;
	vector<pair<int64_t, int64_t>> a(n);
	for (int64_t i = 0; i < n; i++) {
		int64_t a_in;
		cin >> a_in;
		a.at(i) = make_pair(a_in, 1);
	}
	for (int64_t i = 0; i < m; i++) {
		int64_t b_in, c_in;
		cin >> b_in >> c_in;
		a.push_back(make_pair(c_in, b_in));
	}

	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());

	int64_t ans = 0;
	int64_t cnt = 0;
	for (int64_t i = 0; i < n + m; i++) {
		int64_t b = a.at(i).second;
		int64_t c = a.at(i).first;
		if (cnt + b <= n) {
			ans += c * b;
			cnt += b;
		} else {
			ans += c * (n - cnt);
			break;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 6624
'use strict';
(function(stdin) {
  var lines  = stdin.toString().split('\n');
  var result = (function(source,word) {
    return {
      true:'Yes',false:'No'
    }[source.concat(source).indexOf(word) !== -1];

  }(lines[0],lines[1]
  ));
  console.log(result);
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 7384
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int turn = int.Parse(Console.ReadLine());

            int taropoint = 0;
            int hanakopointo = 0;

            for(int i = 1; i <= turn; i++)
            {
                string[]card = Console.ReadLine().Split(' ');

                int comparison = card[0].CompareTo(card[1]);

                //CompareTo????????????????????£????????¶??????
                switch (comparison)
                {
                    case 0:
                        taropoint += 1;
                        hanakopointo += 1;
                        break;

                    case 1:
                        taropoint += 3;
                        break;


                    default:
                        hanakopointo += 3;
                        break;
                }
            }

            Console.WriteLine("{0} {1}", taropoint, hanakopointo);


        }
    
    }

}

Measured memory_bytes: 10044
import itertools

n, k = map(int, input().split())
d = list(map(int, input().split()))
use = [i for i in range(10) if not i in d]

p = list(itertools.product(use, repeat=len(str(n))))

ans = float('inf')
for i in p:
    numlist = []
    if i[0] != 0:
        for g in range(len(str(n))):
            numlist.append(str(i[g]))
        num = int(''.join(numlist))
        if num>=n:
            ans=min(ans,num)

if ans==float('inf'):
    if min(use)==0:
        print(int(str(use[1])+"0"*len(str(n))))
    else:
        print(int(str(min(use))*(len(str(n))+1)))
else:
    print(ans)

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

bool mycomp(int x, int y)
{
    return x>y;
}

int main()
{
  long long x, y, a, b, c;
  cin>>x>>y>>a>>b>>c;
  vector<long long>red, green, col;
  long long k;
  for(int i=0; i<a; i++)
  {
      cin>>k;
      red.push_back(k);
  }
  for(int i=0; i<b; i++)
  {
      cin>>k;
      green.push_back(k);
  }
  for(int i=0; i<c; i++)
  {
      cin>>k;
      col.push_back(k);
  }
  sort(red.begin(), red.end(), mycomp);
  sort(green.begin(), green.end(), mycomp);
  for(int i=0; i<x; i++)
  {
      col.push_back(red[i]);
  }
  for(int i=0; i<y; i++)
  {
      col.push_back(green[i]);
  }
  sort(col.begin(), col.end(), mycomp);
  long long sum=0;
  for(int i=0; i<(x+y); i++)
  {
      sum+=col[i];
  }
  printf("%lld", sum);
}

Measured memory_bytes: 7920
#include <iostream>
#include <memory>
#include <string>
#include <map>
#include <algorithm>
#include <vector>

using namespace std;

class Problem {
public:
	virtual void main() = 0;
};

class Problem_A : public Problem {
	string s;
	bool same(string s) {
		for (auto e : s) if (e != s.front()) return false;
		return true;
	}
	int solve(char c) {
		int ans = 0;
		while (!same(s)) {
			for (int i = 0; i < s.size() - 1; i++) {
				if (s[i + 1] == c) s[i] = c;
			}
			s.pop_back();
			ans++;
		}
		return ans;
	}
	void main() override {
		string tmp;
		while (cin >> tmp) {
			int answer = 1e4;
			for (auto e : tmp) {
				s = tmp;
				answer = min(solve(e), answer);
			}
			cout << answer << endl;
		}
	}
};

class Problem_B : public Problem {
	void main() {
		int n;
		while (cin >> n) {
			vector<int> v(n);
			for (auto& e : v)  cin >> e;
			string answer = "yes";
			int k = v.front();
			for (int i = 1; i < n; i++) {
				if (v[i] == k - 1 || v[i] == k) {
					k = v[i];
					continue;
				}
				answer = "no";
				break;
			}
			cout << answer << endl;
		}
	}
};

int main() {
	unique_ptr<Problem> pr(new Problem_A());
	pr->main();
	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;

int main(){
  int A,B;
  cin >> A >> B;
  if(A==1)A=14;
  if(B==1)B=14;

  if(A==B){
    cout << "Draw" << endl;
  }else if(A>B){
    cout << "Alice" << endl;
  }else{
    cout << "Bob" << endl;
  }

}



Measured memory_bytes: 256
#include <stdio.h>
#include <queue>
using namespace std;
typedef long long ll;

int main(void) {
  ll i, j, k, l, t, n, now, m;
  scanf("%lld", &t);
  for(l = 0; l < t; ++l) {
    scanf("%lld", &n);
    ll a[n + 1];
    i = 0;
    while(i < n) scanf("%lld", &a[++i]);
    char s[n + 10];
    scanf("%s", s + 1);
    priority_queue<ll> q;
    vector<ll> vec, vec2;
    for(i = n; i; --i) {
      if(s[i] == '0') {
        if(vec.size()) {
          for(j = 0; j < vec.size(); ++j) q.push(vec[j]);
          vec.clear();
          vec2.clear();
        }
        q.push(a[i]);
      } else {
        while(q.size()) {
          now = q.top(), q.pop();
          if(!now) continue;
          for(k = 60; !((now >> k) & 1); --k);
          m = 1ll << k;
          while(q.size() && (q.top() & m)) q.push(q.top() ^ now), q.pop();
          for(k = 0; k < vec.size(); ++k) if(m & vec[k]) vec[k] ^= now;
          vec.push_back(now);
          vec2.push_back(m);
        }
        for(j = 0; j < vec.size(); ++j) if(vec2[j] & a[i]) a[i] ^= vec[j];
        if(a[i]) break;
      }
    }
    if(i) printf("1\n");
    else printf("0\n");
  }
  return 0;
}

Measured memory_bytes: 3132
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect
import sys
import random
import time
inf = 10**9


def main():
  n, a, b = list(map(int, input().split()))
  r = n %(a + b)
  l = math.floor(n / (a + b))
  print(a * l + min(r, a))

if __name__ == '__main__':
  main()

Measured memory_bytes: 5924
#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#include<deque>
using namespace std;
typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;





int main(){
	int n, p;
	cin >> n >> p;
	string s;
	cin >> s;
	

	map<int, int> m;
	ll mod = 0;
	ll c = 1;
	ll ans = 0;
	for (ll i = n-1; i >=0; i--) {
		if (p == 2 || p == 5) {
			if ((s[i]-'0') % p == 0) {
				ans += (i + 1LL);
			}
		}
		else {
			mod = (mod  +c * (s[i] - '0')) % p;
			c = (c * 10) % p;
			ans += m[mod];
			m[mod]++;
			if (mod == 0) {
				ans++;
			}
		}
	}
	
	cout << ans << endl;

}  



Measured memory_bytes: 900
n = int(input())
a = list(map(int, input().split()))

di = {}
for i in a:
    if i in di:
        di[i] += 1
    else:
        di[i] = 1

ans = 0
for i, j in di.items():
    if i<j:
        ans += j-i
    elif i>j:
        ans += j
print(ans)

Measured memory_bytes: 17780
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;

string s1, s2;

int lcs() {
  int i, j;
  int dp[s1.length()+1][s2.length()+1] = {};
  
  for(i = 1; i <= s1.length(); i++) {
    for(j = 1; j <= s2.length(); j++) {
      if(s1[i-1] == s2[j-1])
	dp[i][j] = dp[i-1][j-1]+1;
      else
	dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
    }
  
  }
  return dp[s1.length()][s2.length()];
}

int main(){
  int n;
  cin >> n;
  while(n--) {
    cin >> s1 >> s2;
    cout << lcs() << endl;
  }
  
  return 0;
}

Measured memory_bytes: 7088
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint A, B; cin >> A >> B;
    cout << max(0LL, A - 2 * B) << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() 
{
	string s;
	int c,f;
	cin>>s;
	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='C')
		{
			c=i;
			break;
		}
	}
	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='F')
		{
			f=i;
		}
	}
	if(c<f)
	{
		cout<<"Yes";
		return 0;
	}
	cout<<"No";
	return 0;
}

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


int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  ll vmin = LLONG_MAX;
  ll cnt = 0;
  for (ll i = 0; i < N; i++) {
    ll p; cin >> p;
    if (p <= vmin) {
      cnt++;
      vmin = p;
    }
  }
  cout << cnt << endl;

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repX(i, n ,x) for (int i = x; i < (int)(n); ++i)
#define repBack(i, n) for (int i = n; i >= 0; --i)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    int N;
    cin >> N;
    vector<int> V(N),C(N);
    rep(i,N)cin >> V[i];
    rep(i,N)cin >> C[i];
    vector<int> a(N);
    rep(i,N)a[i] = V[i] - C[i];
    sort(a.begin(),a.end(),greater<int>());
    int ans = 0;
    rep(i,N){
        if(a[i]>0)ans += a[i];
    }
    cout << ans << endl;
    
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef pair<ul, ul> P;

const int INF = 1e9;
const int MOD =1e9+7;
const ll LINF = 1e18;

int main(){
    int L, R;
    cin >> L >> R;

    int diff = R - L;
    int minVal = INF;

    if (diff > 2019) diff = 2019;
    for (int i = 0;  i < diff; i++) {
        for (int j = i + 1; j <= diff; j++) {
            int val = ((ll)(L + i) * (ll)(L + j)) % 2019;
            if (val < minVal) minVal = val;
        }
    }

    cout << minVal << endl;
} 

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

#define fast ios::sync_with_stdio(0); cin.tie(NULL); 
#define fi first
#define se second
#define mp make_pair
#define pi 3.14159265359
#define MOD 1000000007
typedef long long ll;
#define mp make_pair
#define ALL(v) v.begin(), v.end() 
#define F(i,s,n) for(i=s;i<n;++i)
#define pb push_back
#define tin freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define pll pair<ll,ll>
ll max(ll a,ll b)
{
    return a*(a>=b)+b*(b>a);
}
/*----------------------------------------------------------*/
ll n;vector<vector<ll>>a;
map<pll,ll>dp;
ll fun(ll n,ll pre)
{
    if(n==-1)return 0;
    if(dp.count(mp(n,pre)))return dp[mp(n,pre)];
    ll p=-1;
    for(ll i=0;i<3;++i)
    {
        if(i==pre)continue;
        p=max(p,a[n][i]+fun(n-1,i));
    }
    return dp[mp(n,pre)]=p;
}
void solve()
{
    cin>>n;a.resize(n,vector<ll>(3));
    for(ll i=0;i<n;++i)
    {
        for(ll j=0;j<3;++j)cin>>a[i][j];
    }
    cout<<fun(n-1,-1);
}

int main()
{
    //tin
    fast
    ll tc=1;//cin>>tc;
   for(ll i=1;i<=tc;++i)
   {
    //cout<<"Case #"<<i<<": ";
    solve();
    if(i!=tc)cout<<"\n";
   }
return 0;
}
//End-Cases
//Precomputation
//Segmentation Fault
//Complexity
//Break it up
//Sub Problems


Measured memory_bytes: 39852