akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod2=1000000007;
ll mod=998244353;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
int main(){
    ll n;cin>>n;
    ll a[n];
    ll sum=0;
    rep(i,0,n){
        cin>>a[i];
        sum+=a[i];
    }
    //cout<<sum-n*(n-1)<<" "<<sum<<endl;return 0;
    for(ll i=max((ll)0,sum-n*(n-1));i<sum+1;i++){
        ll cnt=0;
        rep(j,0,n){
            ll r=a[j]+i-n+1;
            if(r<=0)continue;
            cnt+=r/(n+1);
            if(r%(n+1)!=0)cnt++;
        }
        //cout<<i<<endl;
        if(cnt==i){
            cout<<i<<endl;
            return 0;
        }
    }
    
}


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

vector<vector<int>> data2(50, vector<int>(4));
long max_wk=0;

void dfs(vector<int> &vec,int N, int M, int A_n, int Q)
{
    //終了条件
    //数列のサイズがNになったら
    if(vec.size()==N){
    //条件チェック
    //Q個の条件を調べる。
        long point=0;
        for(int i=0;i<Q;i++){
            if(vec.at(data2.at(i).at(1)-1)-vec.at(data2.at(i).at(0)-1)==data2.at(i).at(2))
                point+=data2.at(i).at(3);
        }
        max_wk=max(max_wk,point);
        return;
    }

    //再帰条件
    //Ai以上の値をAi+1に追加する。
    for(int i=A_n;i<=M;i++){
        vector<int> wk=vec;
        wk.push_back(i);
        dfs(wk,N,M,i,Q);
    }
    
    return;
}

int main()
{
    int n,m,q;
    cin>>n>>m>>q;

    for(int i=0;i<q;i++){
        cin>>data2.at(i).at(0);
        cin>>data2.at(i).at(1);
        cin>>data2.at(i).at(2);
        cin>>data2.at(i).at(3);
    }

    vector<int> wk;

    dfs(wk,n,m,1,q);

    cout<<max_wk<<endl;

    return 0;
}

Measured memory_bytes: 3604
def main():
    import sys
    input = sys.stdin.readline

    N, mod = map(int, input().split())
    adj = [[] for _ in range(N+1)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        adj[a].append(b)
        adj[b].append(a)

    """ここから変更"""
    # op: 普通に根を固定した木DPで子の情報を親に集めるときの演算
    def op(a, b):
        return (a * (b + 1))%mod

    # cum_merge: 累積opどうしをマージするときの演算
    def cum_merge(a, b):
        return (a * b)%mod
    """ここまで変更"""

    # root=1でまず普通に木DPをする
    # 並行して各頂点につき、子の値の累積opを左右から求めておく
    # その後根から順番に、親からの寄与を求めていく(from_par)
    def Rerooting(adj):
        N = len(adj) - 1
        st = [1]
        seen = [0] * (N + 1)
        seen[1] = 1
        par = [0] * (N + 1)
        child = [[] for _ in range(N + 1)]
        seq = []
        while st:
            v = st.pop()
            seq.append(v)
            for u in adj[v]:
                if not seen[u]:
                    seen[u] = 1
                    par[u] = v
                    child[v].append(u)
                    st.append(u)
        seq.reverse()
        dp = [1] * (N + 1)
        left = [1] * (N + 1)
        right = [1] * (N + 1)
        for v in seq:
            tmp = 1
            for u in child[v]:
                left[u] = tmp
                tmp = op(tmp, dp[u])
            tmp = 1
            for u in reversed(child[v]):
                right[u] = tmp
                tmp = op(tmp, dp[u])
            dp[v] = tmp

        seq.reverse()
        from_par = [0] * (N + 1)
        for v in seq:
            if v == 1:
                continue
            from_par[v] = op(cum_merge(left[v], right[v]), from_par[par[v]])
            dp[v] = op(dp[v], from_par[v])

        return dp

    dp = Rerooting(adj)
    for i in range(1, N+1):
        print(dp[i])


if __name__ == '__main__':
    main()


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

int a[2];
int b[2];

int n;
string str;

bool canGetTo(int x, int y){

        if(x == y){
            return true;
        }else if(x < y){
            while(x < y){
                if(x < n - 1 && str[x + 1] == '.'){
                    ++x;
                }else if(x < n - 2 && str[x + 2] == '.'){
                    x += 2;
                    if(x > y){
                        return false;
                    }
                }else{
                    return false;
                }
            }
        }else{
            return false;
        }
    return true;
}

int main()
{
    cin >> n >> a[0] >> a[1] >> b[0] >> b[1];
    cin >> str;

    a[0]--;
    a[1]--;
    b[0]--;
    b[1]--;

    if(b[0] >= b[1]){
        int x = -1;
        for(int i = a[1]; i <= b[1]; ++i){
            if(str[i] == '.' && str[i - 1] == '.' && str[i + 1] == '.'){
                x = i;
                break;
            }
        }
        if(x == -1){
            cout << "No\n";
            return 0;
        }

        for(int i = a[0]; i < x; ++i){
            if(str[i] == '#' && str[i + 1] == '#'){
                cout << "No\n";
                return 0;
            }
        }

        if(canGetTo(a[0], x + 1) && canGetTo(a[1], x)){
            a[0] = x + 1;
            a[1] = x;
        }else{
            cout << "No\n";
            return 0;
        }
    }

    if(canGetTo(a[1], b[1])){
        str[b[1]] = '#';
        if(canGetTo(a[0], b[0])){
            cout << "Yes\n";
            return 0;
        }
        str[b[1]] = '.';
    }
    
    if(canGetTo(a[0], b[0])){
        str[b[0]] = '#';
        if(canGetTo(a[1], b[1])){
            cout << "Yes\n";
            return 0;
        }
    }
    
    cout << "No\n";
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
int main(){
    int N,A,B;
    scanf("%d",&N);
    scanf("%d",&A);
    scanf("%d",&B);
    int taxi=B;
    int train=A*N;
    if(taxi<train){
        printf("%d\n",taxi);
    }else{
        printf("%d\n",train);
    }
        return 0;
}


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

int tb(int x)
{
	int res = 2;
	while(res<x)res *= 2;
	res = res - x;
	if(res==0)res = x;
	return res;
}
int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0;i<n;i++)cin >> a[i];
	map<int,int> mp;
	for(int i = 0;i<n;i++)mp[a[i]]++;
	sort(a.rbegin(),a.rend());
	int ans = 0;
	for(int i = 0;i<n;++i)
	{
		if(mp[a[i]]==0)continue;
		int now = tb(a[i]);
		if(a[i]==now)
		{
			if(mp[a[i]]>1)
			{
				ans++;
				mp[now]-=2;
			}
			continue;
		}
		if(mp[now]>0)
		{
			mp[now]--;
			ans++;
			mp[a[i]]--;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 22668
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int n;
bool G[25][25], visited[1<<24];
char dp[1<<24];
vector<int> col[5];

bool check(int i, int S){
    rep(j, i)if(!(S>>j & 1) && G[j][i]) return false;
    return true;
}

char dfs(int S){
    if(n - __builtin_popcount(S) <= 1) return 0;
    if(visited[S]) return dp[S];
    visited[S] = true;
    dp[S] = 0;
    rep(c, 4)if(col[c].size() >= 2){
        rep(i, col[c].size()-1)if(!(S>>col[c][i] & 1) && check(col[c][i], S)){
            For(j, i+1, col[c].size())if(!(S>>col[c][j] & 1) && check(col[c][j], S)){
                chmax(dp[S], (char)(2 + dfs(S | (1<<col[c][i]) | (1<<col[c][j]))));
            }
        }
    }
    return dp[S];
}

void solve(){
    int x[n], y[n], r[n], c[n];
    rep(i, 4) col[i].clear();
    rep(i, n){
        scanf("%d%d%d%d", &x[i], &y[i], &r[i], &c[i]);
        --c[i];
        col[c[i]].push_back(i);
    }
    rep(i, n)rep(j, n) G[i][j] = false;
    rep(i, n)For(j, i+1, n){
        if((x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]) < (r[i]+r[j])*(r[i]+r[j])){
            G[i][j] = true;
        }
    }
    
    rep(i, 1<<n) visited[i] = false;
    printf("%d\n", dfs(0));
}

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


Measured memory_bytes: 36028
s = input()
t = input()


if len(set(list(s))) != len(set(list(t))):
    print("No")
    exit()

# ある1文字に対応する文字が1種であることを確認
d = dict()
for si, ti in zip(s, t):
    if si not in d:
        d[si] = ti
    else:
        if d[si] != ti:
            print("No")
            exit()
print("Yes")

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

using namespace std;

typedef long long ll;

int time(int a, int b, int c, int d){
	if(b < c) return 0;
	if(c <= b && b <= d) return b - max(c, a);
	if(a < d) return d - max(a, c);
	return 0;
}

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

	int a, b, c, d;
	cin >> a >> b >> c >> d;

	cout << time(a, b, c, d) << endl;
}


Measured memory_bytes: 256
I=lambda : list(map(int,input().split()))

n,m = I();md=10**9+7;p=0;a=1
dp=[0,1];l=[0]*(10**5+2)
for _ in range(m):
    x=int(input())
    l[x]=1
for i in range(1,n+1):
    if l[i]:
        dp.append(0)
    else:
        dp.append((dp[-1]+dp[-2])%md)
print(dp[-1])

Measured memory_bytes: 50392
n,edge = map(int,input().split())
l = [0]*n 
stack = [1]
dic  = {}
for i in range (edge) :
    x = [int(x) for x in input().split()]
    if x[0] not in dic :
        dic[x[0]] = []
    if x[1] not in dic :
        dic[x[1]] = []
    dic[x[0]].append(x[1])
    dic[x[1]].append(x[0])
x = 1 
while len(stack) != 0 :
    check = stack[0]
    stack.pop(0)
    for i in range (len(dic[check])) :
        if l[dic[check][i]-1] == 0 :
            x += 1 
            stack.append(dic[check][i])
            l[dic[check][i]-1] = check 
if l.count(0) != 0 :
    print("No")
else :
    print("Yes")
    for i in range (1,n) :
        print(l[i])
    
    
    
    
    

Measured memory_bytes: 38364
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
using namespace std;

int main() {
    int N;
    unsigned long long S = 1;
    long long P[1001] = {0};
    scanf("%d", &N);
    int d;
    for (int i = 2; i <= N; i++) {//iの約数を求める
        d = i;
        for (int j = 2; d > 1; j++) {//素因数分解
            while (d % j == 0) {
                P[j] += 1;
                d /= j;
            }
        }
    }
    for (int i = 2; i <= N; i++) {
        S = (S * (P[i] + 1)) % 1000000007;
        //printf("%llu\n",S);
    }
    printf("%llu", S);
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {
    int r, D, x;
    cin >> r >> D >> x;
    for (int i = 0; i < 10; i++) {
        x = r * x - D;
        cout << x << endl;
    }
    return 0;
}

Measured memory_bytes: 256
// 131_C_Anti-Division.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <numeric>

using namespace std;


long long gcd(long long a, long long b)
{
	if (a < b)
	{
		long long tmp = a;
		a = b;
		b = tmp;
	}

	long long r = 0;
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}


	return b;
}

long long lcm(long long a, long long b)
{
	return a * b / gcd(a, b);
}

long long countIntegerDivisibleBy(long long divisor,
	                              long long rangeStart, 
	                              long long rangeEnd)
{
	//割り切れる数（開始）の算出
	long long rStart = rangeStart % divisor;
	if (rStart > 0)
	{
		rangeStart = rangeStart - rStart + divisor;
	}

	//割り切れる数（終了）の算出
	long long rEnd = rangeEnd % divisor;
	if (rEnd > 0)
	{
		rangeEnd = rangeEnd - rEnd;
	}

	return (rangeEnd - rangeStart) / divisor + 1;
}

int main()
{
	//回答方針
	//ド・モルガンの法則を使用する。
	//CでもDでも割り切れない整数の個数 = 全体の個数 - Cで割り切れる整数の個数 - Dで割り切れる整数の個数 + CでもDでも割り切れる整数の個数

	long long a, b, c, d = 0;
	cin >> a >> b >> c >> d;

	//全体の個数
	long long countTotal = b - a + 1;

	long long countDivisibleByC = countIntegerDivisibleBy(c, a, b);

	long long countDivisibleByD = countIntegerDivisibleBy(d, a, b);

	long long countDivisibleByCAndD = countIntegerDivisibleBy(lcm(c, d), a, b);

	cout << countTotal - countDivisibleByC - countDivisibleByD + countDivisibleByCAndD;

	return 0;
}


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

using namespace std;

#define MOD 1000000007

typedef long long ll;

vector<ll> factn, factk, ifactn, ifactk;

ll mod(ll b, ll p){
    ll res = 1;
    while(p){
        if(p&1)
            res = (res*b)%MOD;
        b = (b*b)%MOD;
        p = p>>1;
    }

    return res;
}

void cal(ll a, ll b){
    factk.resize(a+1);
    ifactk.resize(a+1);
    factn.resize(b+1);
    ifactn.resize(b+1);
    factk[0] = factk[1] = 1;
    factn[0] = factn[1] = 1;
    for(int i = 2; i <= a; i++)
        factk[i] = (factk[i-1]*i)%MOD;
    for(int i = 2; i <= b; i++)
        factn[i] = (factn[i-1]*i)%MOD;
    for(int i = 0; i <= a; i++)
        ifactk[i] = mod(factk[i], MOD-2);
    for(int i = 0; i <= b; i++)
        ifactn[i] = mod(factn[i], MOD-2);
}

ll kcr(ll k, ll r){
    if( k < r )
        return 0;
    return (factk[k]*((ifactk[r]*ifactk[k-r])%MOD))%MOD;
}

ll ncr(ll n, ll r){
    if( n < r )
        return 0;
    return (factn[n]*((ifactn[r]*ifactn[n-r])%MOD))%MOD;
}

int main(){

    int n, k;
    cin >> n >> k;

    cal(k-1, n-k+1);

    int nn = n-k+1;
    for(int i = 0; i < k; i++){
        cout << (ncr(nn, i+1)*kcr(k-1, i))%MOD << endl;
    }

    return 0;
}

Measured memory_bytes: 256
A,B,C,X,Y=map(int,input().split())

C*=2

tmp = max([X,Y])
result = 1e10
for i in range(tmp+1):
    current = C*i+max([0,A*(X-i)])+max([0, B*(Y-i)])
    if result>current:
        result = current
print(result)


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

#define ll long long
#define ull unsigned long long

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n, 0);
	int in;
	for (int i=0; i<n-1; i++)
	{
		cin >> in;
		a[--in]++;
	}
	for (int x : a) cout << x << '\n';
}

Measured memory_bytes: 3984
#include <iostream>

using namespace std;

int main() {
    int a,b,c,x,cnt=0;

    cin >> a >> b >> c >> x;

    for(int i=0; i<=a; i++){
        for(int j=0; j<=b; j++){
            for(int k=0; k<=c; k++){
                if(i*500 +j*100 +k*50 == x){
                    cnt++;
                }
            }
        }
    }
    cout << cnt << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
#define DEBUG 0 
#define LIMIT (LONG_MAX / 10)
#define POSITIVE_LAST_D (LONG_MAX % 10)
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;

int main(){
    string s;
    cin>>s;
    int sizes=s.size()/2;
    int cnt=0;
    rep(i,sizes){
        if(s[i]!=s[s.size()-i-1])cnt++;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
import string
N = int(input()) - 1
a = list(string.ascii_lowercase)
ans = ''
tmp = 0
m = 0
while True:
    m, v = divmod(N, 26)
    if m == 0:
        N = m
    else:
        N = m - 1
    ans += a[v]
    if N <= 25:
        break
if m != 0:
    ans += a[N]
print(ans[::-1])

Measured memory_bytes: 68504
h, w = map(int, input().split())
def calculate_t(x, y):
    min_d = 1e12
    for i in range(x):
        s1 = (y//2)*i
        s2 = y*(x-i)
        s3 = (y-y//2)*i
        min_d = min(min_d, max(s1,s2,s3) - min(s1,s2,s3))
    return min_d
def calculate_3(x, y):
    min_d = 1e12
    for i in range(x):
        w1 = i
        w2 = (x-i)//2
        w3 = x - w1 -w2
        min_d = min(min_d, (max(w1,w2,w3)-min(w1,w2,w3))*y)
    return min_d
if (h*w)%3 == 0:
    print(0)
else:
    d1 = calculate_t(h,w)
    d2 = calculate_t(w,h)
    d3 = calculate_3(h,w)
    d4 = calculate_3(w,h)
    print(min(d1,d2,d3,d4))

Measured memory_bytes: 3064
import math
S = [int(input()) for _ in range(5)]
ans=0
mini=10
for i in S:
    ans+=math.ceil(i/10)*10
    b = i % 10
    if b== 0:
      b=10
    mini=min(b,mini)

if mini == 10:
  print(ans)
else:
  print(ans-(10-mini))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define INFTY (1<<30)

int H;
vector<int> A(2000001);

void maxHeapify(int i){
    int l=i*2;
    int r=i*2+1;
    int largest;
    if(l<=H&&A[l]>A[i]){
        largest=l;
    }
    else{
        largest=i;
    }
    if(r<=H&&A[r]>A[largest]){
        largest=r;
    }
    if(largest!=i){
        swap(A[i],A[largest]);
        maxHeapify(largest);
    }
}

void heapIncreaseKey(int i,int k){
    if(k<A[i]) return;
    A[i]=k;
    while(i>1&&A[i/2]<A[i]){
        swap(A[i],A[i/2]);
        i/=2;
    }
}

void insert(int k){
    H++;
    A[H]=-INFTY;
    heapIncreaseKey(H,k);
}

int heapExtractMax(){
    if(H<1) return -INFTY;
    int max=A[1];
    A[1]=A[H];
    H--;
    maxHeapify(1);
    return max;
}

int main(){
    H=0;
    while(1){
        char com[10];
        int x;
        scanf("%s%d",com,&x);
        if(com[0]=='i'){
            insert(x);
        }
        else if(com[1]=='x'){
            int y=heapExtractMax();
            cout<<y<<endl;
        }
        else break;
    }
}


Measured memory_bytes: 10524
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<string>
#include<unordered_map>
#include<math.h>
using namespace std;
using ll = long long;
int main(){
    int N, A, B;
    cin >> N >> A >>B;
    if(A * N > B)cout << B;
    else cout << A * N;
}


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

using namespace std;

#define ll long long int

#define DEBUG (0)
int main()
{
    ll A,B,C,K;
    cin >> A >> B >> C >> K;
    ll sum = 0;

    if(K >= A){
        sum += A*1;
        K -= A;
    }else{
        sum = K*1;
        cout << sum << "\n";
        return 0;
    }

    if(K >= B){
        sum += B*0;
        K -= B;
    }else{
        cout << sum << "\n";
        return 0;
    }

    if(K >= C){
        sum += C*(-1);
        K -= C;
    }else{
        sum += K*(-1);
        cout << sum << "\n";
        return 0;
    }

    cout << sum << "\n";
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++)
#define vrepr(v,it) for(auto it = v.rbegin(); it != v.rend(); it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; using vl = vector<ll>;
using vi = vector<int>; using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,...) do { cerr << #v << " = "; array_out(v , __VA_ARGS__ );} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif
 
using P = pair<ll,ll>; using vp = vector<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
/////////////////

void solve(){
  ini(N);
  vvi f(N , vi(10)); in(f);
  vvi p(N , vi(11)); in(p);
  int ans = -inf;
  rep1(b , 1023){
    int cur = 0;
    rep(i , N){
      int cnt = 0;
      rep(j , 10){
        if( (b & (1 << j)) && f[i][j] == 1) cnt++;
      }
      cur += p[i][cnt];    
      //trc(b , i , cnt , cur);
    }
    amax(ans , cur);
  }
  out(ans);

}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

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

	ll x1, y1, x2, y2;
	int N;
	vector<pair<ll, ll> > foun;

	cin >> x1 >> y1 >> x2 >> y2;
	cin >> N;
	bool f = 0, f2 = 0;
	if(x2 < x1){
		swap(x2, x1);
		f2 = 1;
	}
	if(y2 < y1){
		swap(y2, y1);
		f = 1;
	}
	REP(i, N){
		ll x, y;
		cin >> x >> y;
		if(x1 <= x && x <= x2 && y1 <= y && y <= y2){
			foun.push_back({x, y*(f ? -1 : 1)});
		}
	}
	ll dp[214514] = {};
	fill(dp, dp+214514, INF_LL);
	if(f2)
		sort(all(foun), greater<pair<ll, ll> >());
	else
		sort(all(foun));
	vector<ll> fy;
	REP(i, foun.size()){
		fy.push_back(foun[i].second);
	}
	ll max_in = -1;
	REP(i, fy.size()){
		ll in = lower_bound(dp, dp+214514, fy[i])-dp;
		dp[in] = fy[i];
		max_in = max(max_in, in);
	}
	long double res = (x2-x1+y2-y1)*(ll)100;
	max_in++;
	res -= max_in*20;
	if(x1 == x2 || y1 == y2)
		res += M_PI*max_in*10;
	else{
		if((max_in == (y2-y1+1) || max_in == (x2-x1+1))){
			res += M_PI*10;
			res += M_PI*(max_in-1)*5;
		}else{
			res += M_PI*max_in*5;
		}
	}
	cout << fixed << setprecision(20) << res << endl;
}


Measured memory_bytes: 9580
import java.util.*;

public class Main {
    public static void main(String[] args ) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] all = new int[N];
        for(int i = 0;i < N;i++) {
            all[i] = sc.nextInt();
        }
        Arrays.sort(all);
        int buy = 0;
        for(int i = 0;i < K;i++){
            buy += all[i];
        }
        System.out.println(buy);
    }
}


Measured memory_bytes: 30104
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
int cmp(const void *a, const void *b);
//your code here!

int main(void){
    ll N;
    scanf("%lld", &N);
    printf("%lld\n", N*800 - 200*(N/15));
    return 0;
}

int cmp(const void *a, const void *b){
    ll A=*(ll *)a, B=*(ll *)b;
    if(A==B)return 0;
    else return A>B ? 1:-1;//昇順ソート
}


Measured memory_bytes: 128
using System;

namespace ABC052D
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] buf;
            int n;
            uint a;
            uint b;
            uint pos;
            ulong res = 0;
            double bb;

            buf = Console.ReadLine().Split(' ');
            n = Int32.Parse(buf[0]);
            a = UInt32.Parse(buf[1]);
            b = UInt32.Parse(buf[2]);
            bb = (double)b / a;

            buf = Console.ReadLine().Split(' ');

            pos = UInt32.Parse(buf[0]);

            for (int i = 1; i < n; i++)
            {
                uint next = UInt32.Parse(buf[i]);
                uint diff = next - pos;
                res += (diff >= bb) ? b : diff * a;
                pos = next;
            }

            Console.WriteLine(res);
            return;
        }
    }
}


Measured memory_bytes: 20064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
ll modfac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
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;
}
int main(){
    ll n,w;cin >> n >>w;
    vvl dp(n+1,vl(w+1,0));
    vpl v(n);
    rep(i,n)cin >> v[i].fi >>v[i].se;
    rep(i,w+1)dp[0][i]=0;
    rep(i,n){
        rep(j,w+1){
            if(j<v[i].se)dp[i+1][j]=dp[i][j];
            else dp[i+1][j]=max(dp[i][j-v[i].se]+v[i].fi,dp[i+1][j]=dp[i][j]);
        }
    }
    cout << dp[n][w] <<endl;
}



Measured memory_bytes: 10800
#include <iostream>
#include <cstdlib>

using namespace std;

#define INF (1 << 31)

struct Node
{
  int val;
  Node *next;
};

Node *allocNode(int val)
{
  Node *p = (Node*)malloc(sizeof(Node));
  p->val = val;
  p->next = NULL;
  return p;
}

void push(Node **top, int val)
{
  Node *p = allocNode(val);
  p->next = *top;
  *top = p;
}

int top(Node *top)
{
  if (top == NULL) return INF;
  return top->val;
}

void pop(Node **top)
{
  if (*top == NULL) return;
  Node *p = *top;
  *top = p->next;
  free(p);
}

int main()
{
  Node **ary;
  int n, q, i, com, index, val;

  cin >> n >> q;

  ary = (Node**)malloc(sizeof(Node*) * n);

  for (i = 0; i < n; i++) ary[i] = NULL;

  for (i = 0; i < q; i++)
  {
    cin >> com >> index;
    switch (com)
    {
    case 0:
      cin >> val;
      push(&ary[index], val);
      break;
    case 1:
      val = top(ary[index]);
      if (val != INF) cout << val << endl;
      break;
    case 2:
      pop(&ary[index]);
      break;
    }
  }

  free(ary);

  return 0;
}


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

#define sc1(a)  scanf("%d",&a)

int main(){
    int mod=1000000007;
    int n,ans;
    sc1(n);
    for (int i=1;i<10;i++)  for (int j=i;j<10;j++) {
        if (i*j==n) {
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
#define all(v) v.begin(), v.end()
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    //a.erase(unique(a.begin(), a.end()), a.end());
    ll N,K;
    cin>>N>>K;
    vector<ll> H(N);
    rep(i,N) cin>>H.at(i);
    sort(H.begin(),H.end(),greater<ll>());
    if(H.size()<=K) cout<<0<<endl;
    else if(K==0) {
        ll counter=0;
        rep(i,N) counter+=H.at(i);
        cout<<counter<<endl;
    }
    else {
        ll counter=0;
        for(ll i=K; i<N; i++) counter+=H.at(i);
        cout<<counter<<endl;
    }
}

Measured memory_bytes: 1792
import java.io.*;

public class Main
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        char c = br.readLine().charAt(0);
        switch (c)
        {
            case 'A':
                bw.write("T");
                break;
            case 'C':
                bw.write("G");
                break;
            case 'G':
                bw.write("C");
                break;
            case 'T':
                bw.write("A");
                break;
        }
        bw.close();
    }
}


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

#define rep(i, a) for (int i = 0; i < (a); i++ )

 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

long long gcd(long long a, long long b) {
   if (a%b == 0) {
       return(b);
   }
   else {
       return(gcd(b, a%b));
   }
}

long long lcm(long long a, long long b) {
   long long tmp = max(a,b)/gcd(a,b);
   return min(a,b)*tmp;}

int main(){
    int N;
    cin >> N;
    ll A[N];
    ll g;
    rep(i,N) {
        ll a;
        cin >> a;
        A[i] = a;
        if (i==0) {
            g = a;
        }
        else {
            g = gcd(g,a);
        }
    }
    cout << g << endl;
}


Measured memory_bytes: 4308
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int A, B, N;
	cin >> A >> B >> N;
	vector<int> R(A), M(B);
	for(int i = 0; i < A; i++) cin >> R[i];
	for(int i = 0; i < B; i++) cin >> M[i];
	int min_R = R[0], min_M = M[0];
	for(int i = 0; i < A; i++) min_R = min(min_R, R[i]);
	for(int i = 0; i < B; i++) min_M = min(min_M, M[i]);
	int ans = min_R+min_M;
	for(int i = 0; i < N; i++) {
		int x, y, c;
		cin >> x >> y >> c;
		ans = min(ans, R[x-1]+M[y-1]-c);
	}
	ans = max(ans, 0);
	cout << ans << "\n";
	return 0;
}

// look at my code
// my code is amazing


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0;i<n;i++)
using ll = long long;
const int MOD = 1e9+7;

int n;
int dp[1000010][2][2]; // [N][0を含むかどうか][9を含むかどうか]

ll modpow(ll x, ll y) {
  ll v = 1;
  REP(i,y) { v *= x; v %= MOD; }
  return v;
}

// 包除原理解法
void solve1() {
  ll p1 = modpow(10, n);
  ll p2 = (modpow(9, n) * 2) % MOD;
  ll p3 = modpow(8, n);
  ll ans = p1 - (p2 - p3);
  ans %= MOD;
  ans = (ans + MOD) % MOD;
  cout << ans << endl;
}

// DP解法
void solve2() {
  dp[0][0][0] = 1;
  REP(i,n) {
    REP(j,2) {
      REP(k,2) {
        REP(x,10) {
          int nj = j || x == 0;
          int nk = k || x == 9;
          dp[i+1][nj][nk] += dp[i][j][k];
          dp[i+1][nj][nk] %= MOD;
        }
      }
    }
  }
  cout << dp[n][1][1] << endl;
}

int main() {
  cin >> n;
  // solve1();
  solve2();
  return 0;
}

Measured memory_bytes: 19032
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n,q;
    cin>>n>>q;
    string a;
    cin>>a;
    a="@"+a;
    char x,y;
    vector<pair<int,int>> qq;
    for(int i=0;i<q;i++)
    {
        cin>>x>>y;
        if(y=='L')
            qq.push_back({x,-1});
        else
            qq.push_back({x,1});
    }

    int mx=0;
    int l=1,r=n;
    while (l<=r)
    {
        int mid=l+(r-l)/2;
        int x=mid;
        bool flag=false;
        for(auto i:qq)
        {
            if(a[x]==i.first)
            {
                x+=i.second;                
            }
            if(x==0)
            {
                flag=true;
                break;
            }
            else if(x==n+1)
            {
                break;
            }
        }
        if(flag)
        {
            l=mid+1;
            mx=max(mx,mid);
        }
        else
        {
            r=mid-1;
        }        
    }
    int mn=n+1;
    l=1,r=n;
    while (l<=r)
    {
        int mid=l+(r-l)/2;
        int x=mid;
        bool flag=false;
        for(auto i:qq)
        {
            if(a[x]==i.first)
            {
                x+=i.second;                
            }
            if(x==n+1)
            {
                flag=true;
                break;
            }
            else if(x==0)
            {
                break;
            }
        }
        if(flag)
        {
            r=mid-1;
            mn=min(mn,mid);
        }
        else
        {
            l=mid+1;
        }        
    }
    int z=mn-mx-1;
    cout<<max(0LL,z);
} 



Measured memory_bytes: 6984
var
 a,b,i,ss1:longint;
 st:string;
begin
 readln(a,b);
 readln(st);
 for i:=1 to a+b+1 do
  if (i<>a+1) and not (st[i] in ['0'..'9']) then ss1:=1;
 if (ss1=1) or (st[a+1]<>'-') then writeln('No')
                            else writeln('Yes');
end.

Measured memory_bytes: 128
import math

def check(x):
    k = 0
    global h, a, b
    for i in h:
        if x * b < i:
            k += math.ceil((i - x * b) / (a - b))
    return k <= x


n, a, b = map(int, input().split())
h = []
for i in range(n):
    h.append(int(input()))
l = -1
r = max(h) // b + 1
while r - l > 1:
    m = (l + r) // 2
    if check(m):
        r = m
    else:
        l = m
print(r)

Measured memory_bytes: 7068
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())

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

  ll N; cin >> N;

  ll ans =0;
  rep(i,N){
    ll l,r;
    cin >> l >> r;
    ans += (r-l+1);
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using ll = int64_t;
using ld = long double;
using ull = uint64_t;
using namespace std;
using namespace __gnu_pbds;

const int MAXN = 200228;

int l[MAXN];
int r[MAXN];

int main() {
#ifdef BZ
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(20);
    int n;
    cin >> n;

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

    ++n;
    sort(l, l + n);
    sort(r, r + n);
    reverse(l, l + n);

    int p = 0;
    ll ans = 0;
    while (l[p] > r[p]) {
        ans -= r[p] - l[p];
        ++p;
    }

    cout << ans * 2 << "\n";
}

Measured memory_bytes: 1024
program main;
var
  a, b, k, i : qword;

begin
  readln(a, b, k);
  if (a > k) then a := a-k
  else begin
    k := k-a;
    a := 0;
    if (b > k) then b:= b-k
    else b := 0;
  end;
  writeln(a, ' ', b);
end.


Measured memory_bytes: 1392
s = input()
n = len(s)
l = [0]*n
pre = "R"
cnt = 0
cnt_r = 0
cnt_l = 0
save_i = -1

def check(c,r,i):
    ans = c//2
    if(cnt%2==0):
        l[i],l[i+1] = ans,ans
    else:
        if(r%2==0):
            l[i],l[i+1] = ans,ans+1
        else:
            l[i],l[i+1] = ans+1,ans 

for i in range(n):
    if(pre=="R"):
        if(s[i]=="R"):
            cnt_r += 1
        else:
            save_i = i-1
            pre = "L"
        cnt += 1
        continue
    if(pre=="L"):
        if(s[i]=="R"):
            check(cnt,cnt_r,save_i)
            cnt = 1
            cnt_r = 1
            save_i = -1
            pre = "R"
        else:
            cnt += 1
check(cnt,cnt_r,save_i)

print(*l)

Measured memory_bytes: 6512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    string s;
    cin >> s;
    rep(i, 3){
        if(s[i] == '1') cout << '9';
        else cout << '1';
    }
}

Measured memory_bytes: 256
n,c,k = [int(x) for x in input().split()]
t = [int(input()) for _ in range(n)]
t.sort()
bus = c
f_bus = 0
ans = 0
for i in range(n):
    if t[i] > f_bus or bus == 0:
        ans += 1
        f_bus = t[i]+k
        bus = c-1
    else:
        bus -= 1

print(ans)


Measured memory_bytes: 7384
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {
    new Main().run();
  }

  void run() {
    int a = ni();
    int b = ni();
    int h = ni();

    System.out.println(((a + b) * h) / 2);
  }

  int ni() {
    return Integer.parseInt(sc.next());
  }

  void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  }
}

Measured memory_bytes: 9680
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N, M;
    cin >> N;
    vl A(N);
    rep(i, N) cin >> A[i];
    cin >> M;
    vl B(M);
    rep(i, M) cin >> B[i];

    A.eb(INF);
    sort(all(A));

    ll ans = 0;
    rep(i, M){
        if (*lower_bound(all(A), B[i]) == B[i]) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4656
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    auto f = [](int x) {
                 int res = 0;
                 while (x > 0) {
                     res += x % 10;
                     x /= 10;
                 }
                 return res;
             };
    int ans = 1001001001;
    for (int a = 1; a < n; ++a) {
        int b = n - a;
        chmin(ans, f(a) + f(b));
    }
    cout << ans << endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
    char s[4];
    scanf("%s", s);
    int cnt=700;
    for (int i = 0; i < 3; i++) {
        if (s[i]=='o'){
            cnt+=100;
        }
    }
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;

public class Main {

    private static final Scanner SCANNER = new Scanner(System.in);

    static int readOneInt() {
        String line = SCANNER.nextLine();
        return Integer.parseInt(line);
    }

    private static int[] readInts() {
        String s = SCANNER.nextLine();
        String[] str = s.split(" ");
        int[] ints = new int[str.length];
        for (int j = 0; j < str.length; ++j) {
            ints[j] = Integer.parseInt(str[j]);
        }
        return ints;
    }

    public static void main(String[] args) {
        int tc = 1;
        for (int i = 0; i < tc; ++i) {
            int[] ints = readInts();
            int n = ints[0];
            int m = ints[1];

            int adjSize = Math.min(n, m) / 4;

//            Map<Integer, Set<Integer>> g = new HashMap<>(m);
            Set[] g = new Set[n + 1];
            for (int j = 1; j <= n; ++j) {
                g[j] = new HashSet<Integer>();
            }
            Set<Integer> nodes = new HashSet<>();

            for (int j = 0; j < m; ++j) {
                int[] p = readInts();
                nodes.add(p[0]);
                nodes.add(p[1]);

                g[p[0]].add(p[1]);
                g[p[1]].add(p[0]);
            }

            if (nodes.size() < n) {
                System.out.println("No");
            } else {
                test(n, m, g);
            }
        }
    }

    private static void test(int n, int m, Set[] g) {
        System.out.println("Yes");
        int[] d = new int[n+1];
        int[] s = new int[n+1];
        boolean[] visited = new boolean[n+1];
        Arrays.fill(d, Integer.MAX_VALUE);
        d[1] = 0;
        LinkedList<Integer> q = new LinkedList<>();
        q.add(1);
        while (!q.isEmpty()) {
            int roomId = q.remove();
            if (visited[roomId]) continue;
            visited[roomId] = true;

            Set<Integer> adj = g[roomId];

            for (int a : adj) {
                int dist = d[roomId] + 1;
                if (d[a] > dist) {
                    d[a] = dist;
                    s[a] = roomId;
                }

                if (!visited[a]) {
                    q.addLast(a);
                }
            }
        }

        StringBuilder b = new StringBuilder();
        for (int i = 2; i < s.length; ++i) {
            b.append(s[i]);
            b.append("\n");
        }

        System.out.println(b.toString());

    }


}



Measured memory_bytes: 113192
n=int(raw_input())
s=raw_input()
cnt1=0
cnt2=0
for i in xrange(n):
    if s[i]=="(":
        cnt1+=1
    else:
        if cnt1>0:
            cnt1-=1
        else:
            cnt2+=1

for i in xrange(cnt1):
    s+=")"
for i in xrange(cnt2):
    s="("+s
print s

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

using namespace std;

static const int INF = 1e9 + 7;

void hawawa()
{
  int n, c, k;
  cin >> n >> c >> k;
  vector<int> a(n);
  for (auto&& i : a) {
    cin >> i;
  }
  sort(begin(a), end(a));
  int ans = 0;
  int time = 0;
  for (int i = 0; i < n; i++) {
    time = a[i] + k;
    ans++;
    int j;
    for (j = 1; j < c && i + j < n; j++) {
      if (time < a[i + j]) {
        break;
      }
    }
    i += j;
    i--;
  }
  cout << ans << "\n";
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  hawawa();
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
        using namespace std;
        #define tani_nachi_ke  ios_base::sync_with_stdio(false); cin.tie(NULL);
        #define M_PI 3.14159265358979323846
        #define data data_
        #define ff first
        #define ss second
        #define pb push_back
        #define ld long double
        #define int long long
        #define print(t) cout << "Case #" << t << ": ";
        int32_t main()
        {
            tani_nachi_ke  
            
            double r;
            cin >> r;
            cout << setprecision(3) << fixed;
            cout << 2*M_PI*r << endl;





           return 0;
        }
          

Measured memory_bytes: 3804