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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n; cin>>n;
	ll ans=0;
	for(int i=(int)(sqrt(n)); i>=1; i--){
		if (n%i==0){
			ans += i-1;
			ans += n/i-1;
			break;
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int n;
  cin >> n;
  VEC<LL> a(n);
  REP(i, 0, n) { cin >> a[i]; }
  LL sum =0;
  REP(i,0,n){
    int m = a[i];
    while(m>0&& m%2==0){
      ++sum;
      m/=2;
    }
  }
  cout<<sum<<endl;

  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;

int N,M;
vector<vector<int>> G;
int dist[100010][3];

void bfs(int S){
    dist[S][0] = 0;
    queue<pair<int,int>> q;
    q.push(make_pair(S,0));
    
    while(!q.empty()){
        int u = q.front().first;
        int v = q.front().second;
        q.pop();
        for(auto t : G[u]){
            int tov = (v+1) % 3;
            if(dist[t][tov] != INF) continue;
            dist[t][tov] = dist[u][v] + 1;
            q.push(make_pair(t,tov));
        }
    }
}


int main(){
    cin >> N >> M;
    G.resize(N);
    rep(i,M){
        int u,v;
        cin >> u >> v;
        u--; v--;
        G[u].push_back(v);
    }
    int S,T;
    cin >> S >> T;
    S--; T--;
    rep(i,N)rep(j,3) dist[i][j] = INF;
    bfs(S);
    if(dist[T][0] == INF) cout << -1 << endl;
    else cout << dist[T][0] / 3 << endl;

    
}

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

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


Measured memory_bytes: 256
#include <algorithm>
#include <stdio.h>
#include <iostream>
#include <math.h>

int main(void){
    using namespace std;
    long long a;
    long long b;

    cin >> a >> b;

    if (a * b % 2 == 1){
        cout << "Odd" << endl; 
    }else{
        cout << "Even" << endl; 
    }
    long long min_n;

    //cout << min_n << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int n = 0;
	char s[4];
	for (int i = 0; i < 4; i++) cin >> s[i];

	for (int i = 0; i < 4; i++) {
		if (s[i] == '+') n++;
		else n--;
	}

	cout << n << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const double PI=acos(-1);
const ll INF = 1LL<<62;
const ll MINF = -(1LL<<62);

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)

ll dp[200001][64];

int main() {
	IO;
	ll n,k;
	cin>>n>>k;
	vector<ll> p(n);
	
	for(int i=0;i<n;++i) {
		cin>>p[i];
		p[i]--;
	}
	
	
	for(int i=0;i<n;++i) {
		dp[i][0]=p[i];
	}
	
	
	for(int i=1;i<64;++i) {
		for(int j=0;j<n;++j) {
			dp[j][i]=dp[dp[j][i-1]][i-1];
		}
	}
	
	//~ LOG(dp[0][2]);
	
	
	ll akt=0;
	for(ll x=0;x<64;++x) {
		if((1LL<<x)&k) {
			akt=dp[akt][x];
		}
	}
	
	cout<<(akt+1)<<"\n";
	
	
	
	return 0;
}


Measured memory_bytes: 104840
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
  int a,b;
  cin >> a >>b;
  cout << (a+b)%24 << endl;
  ret 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
 public class Main{

	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
       while(true){
           int H = sc.nextInt();
           int W= sc.nextInt();
        for( int i = 0; i<H; i++ ){
            for( int n = 0; n<W; n++ ){
            System.out.print("#");
          }
        System.out.println();
       }
        if(H==0&&W==0)break;   
         System.out.println();

       }
	}
 }


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

#define int long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
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;}

struct UF{
    vector<int>par,sz;
    void init(int n){
        par.resize(n);
        sz.resize(n);
        for(int i=0;i<n;i++){
            par[i]=i;
            sz[i]=1;
        }
    }
    int find(int x){
        return x==par[x]?x:par[x]=find(par[x]);
    }
    void unite(int x,int y){
        x=find(x);y=find(y);
        if(x==y)return;
        sz[x]+=sz[y];
        par[y]=x;
    }
    bool same(int x,int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};

int N,M;

signed main(){
    UF uf;
    cin>>N>>M;
    uf.init(M);
    bool ex[111111]={};
    rep(i,N){
        int K;cin>>K;
        vint L(K);rep(j,K)cin>>L[j],L[j]--,ex[L[j]]=true;
        for(int j=1;j<K;j++)uf.unite(L[j-1],L[j]);
    }
    int cnt=0;
    rep(i,M)cnt+=ex[i];
    rep(i,M)if(ex[i]){
        if(uf.size(i)==cnt)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
        return 0;
    }
    return 0;
}


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

int n, m, c;
int a[20][20];
int b[20];
int main()
{
    cin >> n >> m >> c;
    for (int i = 0; i < m; i++)
    {
        cin >> b[i];
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> a[i][j];
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        int tmp = c;
        for (int j = 0; j < m; j++)
        {
            tmp += a[i][j] * b[j];
        }
        if (tmp > 0)
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import Counter
one=list(input())
#print(one)
two=list(input())
z={}
result=[]
for num,i in enumerate(one):
    if i not in z:
        z[i]=[num]
    else:
        z[i].append(num)
p={}
for num,i in enumerate(two):
    if i not in p:
        p[i]=[num]
    else:
        p[i].append(num)

#print(p)
#print(z)

w=[]
for k,v in z.items():
    if len(v)>1:
        w.append(v)
o=[]
for k,v in p.items():
    if len(v)>1:
        o.append(v)
#print(w)
#print(o)
for i in w:
    if i not in o:
        print("No")
        sys.exit()
for i in o:
    if i not in w:
        print("No")
        sys.exit()
print("Yes")

Measured memory_bytes: 23600
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define int long long
using namespace std;

const int N = 100;
const int inf = 1e10;
int l,r;

signed main()
{
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    cin >> l >> r;
    int mn = 2019;
    if (r - l >= 2019){
        cout << 0 << endl;
        return 0;
    }
    else {
        for (int i=l+1;i<=r;i++){
            for (int j=l;j<i;j++){
                int t = i*j;
                t%=2019;
                while (t < 0){
                    t+=2019;
                }
                mn = min(mn,t);
            }
        }
    }

    cout << mn << endl;

    return 0;
}


Measured memory_bytes: 256
program arc091_d
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,k,b,ans=0

    read*, n,k

    do b = k+1,n
        ans=ans+(n/(b)*(b-k))+max((n-((n/b)*b+k)+1),0)
    end do
    if (k==0) ans=ans-n
    print'(i0)', ans
end program arc091_d

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

const double INF = 1e9;
const double EPS = 1e-11;

// ????¬????
struct P3{
  double x,y,z;
  double vx,vy,vz;
  double r,vr;
  P3(double x=0, double y=0, double z=0):x(x),y(y),z(z){}
  P3 operator + (const P3 &a) const{ return P3(x+a.x, y+a.y, z+a.z); }
  P3 operator - (const P3 &a) const{ return P3(x-a.x, y-a.y, z-a.z); }
  P3 operator * (const double &c) const{ return P3(x*c, y*c, z*c); }
  void input(){cin>>x>>y>>z>>vx>>vy>>vz>>r>>vr;}
  P3 v ()const{return P3(vx,vy,vz);}
};
P3 operator * (double c, const P3 &a){ return P3(c * a.x, c * a.y, c * a.z); }


double norm(P3 a){ return a.x*a.x + a.y*a.y + a.z*a.z; }
double abs(P3 a){ return sqrt(norm(a)); }

typedef pair<int,int> P;
typedef pair<double,P> PP;

double calc(P3 A,P3 B,double t){
  if((A.r-t*A.vr)<0|| (B.r-t*B.vr)<0) return -1;
  return abs((A+t*A.v())-(B+t*B.v())) - ((A.r-t*A.vr) + (B.r-t*B.vr));
}

double calc(P3 A,P3 B){
  double L=0,R=INF,cnt = 64;
  while(L<R){
    double M = (L+R)/2;
    double y1 = calc(A,B,M);
    double y2 = calc(A,B,M+EPS);
    if(y1<0||y1-y2<0) R = M-EPS;
    else L = M+EPS;
  }
  return L;
}

int main(){
  int n;
  while(cin>>n,n){
    vector<P3>A(n);
    for(int i=0;i<n;i++) A[i].input();

    priority_queue<PP,vector<PP>,greater<PP> >Q;
    for(int i=0;i<n;i++)
      for(int j=i+1;j<n;j++){
	double t = calc(A[i],A[j]);
	if(abs(calc(A[i],A[j],t))<2e-8)Q.push(PP(t,P(i,j)));
      }

    vector<double> ans(n,-1);
    while(!Q.empty()){
      PP t = Q.top();Q.pop();
      double c = t.first;
      int a = t.second.first;
      int b = t.second.second;
      if(ans[a]>=0||ans[b]>=0)continue;
      ans[a] = ans[b] = c;
    }

    for(int i=0;i<n;i++){
      if(ans[i]<0) ans[i] = A[i].r / A[i].vr;
      ans[i] = min(ans[i],A[i].r / A[i].vr);
      printf("%.10Lf\n",ans[i]);
    }    
    
  }
  return 0;    
}

Measured memory_bytes: 3224
#python3

def main():
    n = int(input())
    a = []
    for _ in range(n):
        x, y, z = map(int, input().split())
        a.append((x, y, z))

    dp = [[0 for _ in range(3)] for _ in range(10*n)]

    for i in range(n):
        for j in range(3):
            for k in range(3):
                if j == k:
                    continue
                dp[i+1][j] = max(dp[i+1][j], dp[i][k] + a[i][j])

    ans = max(dp[n])
    print(ans)
main()

Measured memory_bytes: 148168
#include <iostream>
using namespace std;
// フィボナッチ数
int fib(int n)
{
if(n==0 || n==1) return 1;
return fib(n-1)+fib(n-2);
}
int main()
{
int x, y;
cin >> x >> y;
int x_min = 0;
int x_max = 1;
int y_min = 0;
int y_max = 1;
int c = 0;
while(true){ if(x_min<=x && x<x_max && y_min<=y && y<y_max){ cout << c%3+1 << endl;
return 0; }
 c++; x_min = x_max; x_max = x_min+fib(c); y_min = y_min; y_max = y_min+fib(c);
 if(x_min<=x && x<x_max && y_min<=y && y<y_max){ cout << c%3+1 << endl;
return 0; }
 c++; x_max = x_max; x_min = x_max-fib(c); y_min = y_max; y_max = y_min+fib(c);
 if(x_min<=x && x<x_max && y_min<=y && y<y_max){ cout << c%3+1 << endl;
return 0; }
 c++; x_max = x_min; x_min = x_max-fib(c); y_max = y_max; y_min = y_max-fib(c);
 if(x_min<=x && x<x_max && y_min<=y && y<y_max){ cout << c%3+1 << endl;
return 0; }
 c++; x_min = x_min; x_max = x_min+fib(c); y_max = y_min; y_min = y_max-fib(c);
}
return 0;
}


Measured memory_bytes: 3092
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n, qq = list(map(int, input().rstrip('\n').split()))

    ls = collections.defaultdict(list)
    ls[1]
    for i in range(n-1):
        a, b = list(map(int, input().rstrip('\n').split()))
        ls[a] += [b]
        ls[b] += [a]

    ans = [0 for _ in range(n)]
    for i in range(qq):
        p, x = list(map(int, input().rstrip('\n').split()))
        ans[p-1] += x

    q = collections.deque()
    q.append(1)
    fq = collections.defaultdict(list)
    while True:
        if len(q) != 0:
            p = q.popleft()
            fq[p]
            for i in ls[p]:
                if i not in fq:
                    q.append(i)
                    ans[i-1] += ans[p-1]
        else:
            break
    print(*ans)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 124584
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    string s;
    cin >> s;
    cout << s[0] << s.length() - 2 << s[s.length() - 1] << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
C - たくさんの数式 / Many Formulas
"""
import types
#import copy

# Input
abcd = input()
n = len(abcd) - 1 # 閾の数
sum_ = 0

# Print
for i in range( 2**n ):
    op = n * ["+"]

    # Create operation list
    # example: ['', '+', '']
    for j in range(n):
        if ( i >> j ) & 1:
            op[n-1 -j] = ""
            
    formula = ""
    for p_n, p_o in zip(abcd, op+[""]):
        formula += (p_n + p_o)
    #print(formula)

    sum_ += eval(formula)

print(sum_)


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

bool solve() {
	ll a, b, c;
	cin >> a >> b >> c;
	ll left = a*a + b*b + c*c;
	ll right = (a-b)*(a-b) + (b-c)*(b-c) + (c-a)*(c-a);
	return left < right && c-a-b > 0;
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	cout << (solve() ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
using System;

namespace aoj
{
    class Program
    {
        static void Main(string[] args)
        {
            var num = Console.ReadLine();
            string[] nums = num.Split(' ');   

            int one =  int.Parse(nums[0]);
            int two =  int.Parse(nums[1]);

            if (one > two) {
                Console.WriteLine("a > b");
            } else if (one < two) {
                Console.WriteLine("a < b");
            } else {
                Console.WriteLine("a == b");
            } 
        }
    }
}



Measured memory_bytes: 15948
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    // AtCoder
    // template
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll ans = 0;
    for(size_t i = 1; i < n; i++) {
        ll cnt = 0;
        for(char c = 'a'; c <= 'z'; c++) {
            bool left = false, right = false;

            for(ll j = 0; j < i; j++) {
                if(s[j] == c)
                    left = true;
            }

            for(ll j = i; j < n; j++) {
                if(s[j] == c)
                    right = true;
            }

            if(left && right)
                cnt++;
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
int x,y;
int c[4]={0,300000,200000,100000};
int res;
int main(){
	cin>>x>>y;
	if(x<=3)res+=c[x];
	if(y<=3)res+=c[y];
	if(x==1&&y==1)res+=4e5;
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()

n, m = map(int, input().split())

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

uf = UnionFind(n)

for i in range(m):
    a, b = map(int, input().split())
    uf.union(a-1, b-1)

ans = 0
for i in range(n):
    cnt = uf.size(i)
    ans = max(ans, cnt)
print(ans)

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

typedef long long ll;

int a, b, c, k;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> a >> b >> c >> k;
    int res = 0;
    if (k >= a) {
        res += a;
        k -= a;
    } else {
        res += k;
        k = 0;
    }
    if (k >= b) {
        k -= b;
    } else {
        k = 0;
    }
    if (k) {
        res -= k;
    }
    cout << res << endl;

    return 0;
}



Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  int n, m; cin >> n >> m;
  vector<int> a(m), b(m);
  for(int i = 0; i < m; i++){
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
  }

  map<pair<int ,int> ,int> mp;
  for(int i = 0; i < m; i++){
    if(a[i] > b[i]) swap(a[i], b[i]);
    if(a[i] == 0){
      mp[{a[i], b[i]}]++;
    }else {
      mp[{0, a[i]}]++;
      mp[{0, b[i]}]++;
    }
  }

  bool judge = true;
  for(auto p : mp){
    if(p.second % 2 != 0) judge = false;
  }
  cout << (judge ? "YES" : "NO") << endl;

  return 0;
}


Measured memory_bytes: 7168
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(int n);            // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;

// code
// ------------------------------------------------
int main() {
  
  ll n;cin >> n;
  vector<ll> b(n-1),a(n,LLONG_MAX);

  rep(i,n-1) cin >> b[i];

  rep(i,n-1)
  {
    a[i] = min(a[i],b[i]);
    a[i+1] = min(a[i+1],b[i]);
  }

  ll ans = 0;
  rep(i,n)
  {
    ans += a[i];
  }

  cout << ans << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(int n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 1)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

#define MAX 101
#define inf 100000000
#define WHITE 0
#define BLACK 1

int n,A[MAX][MAX],d[MAX],C[MAX],pi[MAX];

void MST()
{
  int i,j,min,u;

  d[1] = 0;

  while(1)
    {
      min = inf;

      for(i = 1 ; i <= n ; i++)
	{
	  if(C[i] != BLACK && d[i] < min)
	    {
	      min = d[i];
	      u = i;
	    }
	}

      if(min == inf) return;

      C[u] = BLACK;

      for(i = 1 ; i <= n ; i++)
	{
	  if(C[i] != BLACK && A[u][i] < d[i] && A[u][i] != inf)
	    {
	      d[i] = A[u][i];
	      pi[i] = u;
	    }
	}
      
    }

}

int main()
{
  int i,j,a=0;

  scanf("%d",&n);

  for(i = 1 ; i <= n ; i++) //初期化
    {
      C[i] = WHITE;
      d[i] = inf;
      pi[i] = -1;
    }

  for(i = 1 ; i <= n ; i++)
    {
      for(j = 1 ; j <= n ; j++)
	{
	  scanf("%d",&A[i][j]);
	  
	  if(A[i][j] < 0) A[i][j] = inf;
	}
    }

  MST();

  for(i = 1 ; i <= n ; i++)
    {
      a += d[i];
    }
  
  printf("%d\n",a);
  
  return 0;
}



Measured memory_bytes: 2104
#include <stdio.h>

int main() {
  int x,y ,a;
  scanf("%d %d",&x,&y);

  while(x != 0 || y !=0) {
    if(x > y) {
      a = x;
      x =y;
      y = a;
    } 
    printf("%d %d\n",x , y);
    scanf("%d %d" ,&x,&y);
 
  }
  return 0;
}

Measured memory_bytes: 600
#include <iostream>

void draw_sharp(int);

int main(){
	int Height, Width; //入力される、長方形のたてよこ
	while (true)
	{
		std::cin >> Height >> Width;
		if (Height == 0 && Width == 0)
			break;
		for (int i = 0; i < Height; i++)
		{
			draw_sharp(Width);
		}
		std::cout << "\n";
	}
}

void draw_sharp(int num_sharp){
	for (int i = 0; i < num_sharp; i++)
	{
		std::cout << "#";
	}
	std::cout << "\n";
}


Measured memory_bytes: 3100
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string w, a, b;
    int ans = 0;
    cin >> w;
    while(cin >> a){
        for(int i = 0; i < a.length(); i++){
            if(a[i] >= 'A' && a[i] <= 'Z' ) {
                a[i] -= 'A' - 'a';
            }
        }
        if(a == w){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3140
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define all(a) (a).begin(),(a).end()
#define X first
#define Y second
using namespace std;
int ans;
void solve()
{
    int n,wt; cin>>n>>wt;
    int w[n],val[n];
    for(int i=0;i<n;i++)cin>>w[i]>>val[i];
    int dp[wt+1];
    memset(dp,-1,sizeof(dp));
    dp[0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=wt;j>=0;j--)
        {
            if(j-w[i]<0||dp[j-w[i]]==-1)continue;
            dp[j]=max(dp[j],dp[j-w[i]]+val[i]);
            ans=max(ans,dp[j]);
        }
    }
    cout<<ans;
    return;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t; t=1;
    while(t--)solve();
    return 0;
}


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




int gcd(int a, int b){
  int bigger=max(a,b);
  int smaller=min(a,b);
  
  if (bigger%smaller==0){
    return smaller;
  }
  else {
    return gcd(smaller,bigger%smaller);
  }
  
}






int main(){


  int n;
  cin>>n;
  
  vector<int> data(n);
  
  for (int i=0;i<n;i++){
    int tmp;
    cin>>tmp;
    data.at(i)=tmp;
  }
  
  int answer=gcd(data.at(0),data.at(1));
  
  for (int i=2;i<n;i++){
    answer=gcd(answer,data.at(i));
  }
  
  cout<<answer<<endl;
  
  
  
  

  

        
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define inf 1000000000
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define yoi cout<<"yo"<<endl;
#define debug(x) cerr << #x << " is " << x << endl;
#define all(x) x.begin(),x.end()
const int mod=1e9+7;
lli dp[100001][13];
lli power(lli x,lli y){
    lli res=1;
    if(y<=0)
        return res;
    while(y){
        if(y%2)
            res=(res*x)%13;
        y=y/2;
        x=(x*x)%13;
    }
    return res;
}
int main(){
IOS;
string s;
cin>>s;
int n=s.length(),i,j,k;
dp[n][0]=1;
for(i=n-1;i>=0;i--){
        lli x=power(10,n-i-1);
        //cout<<x<<endl;
    for(j=0;j<13;j++){
        if(s[i]!='?'){
            int digit=s[i]-48;
            digit*=x;
            dp[i][(j+digit)%13]=(dp[i][(j+digit)%13]+dp[i+1][j])%mod;
            continue;
        }
        for(k=0;k<=9;k++){
            dp[i][(j+x*k)%13]=(dp[i][(j+x*k)%13]+dp[i+1][j])%mod;
        }
    }
}
cout<<dp[0][5]<<endl;
}



Measured memory_bytes: 10604
n = int(input())

multiplier = [0 for _ in range(n)]
for m in range(2, n+1):
    a = m
    i = 2
    while i ** 2 <= m:
        while a % i == 0:
            a = int(a / i)
            multiplier[i-1] += 1
        i += 1
    if a != 1:
        multiplier[a-1] += 1
ans = 1
for x in multiplier:
    ans *= x + 1
print(ans % (10**9 + 7))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a>b)
    {
        for(int i=1; i<=a; i++)
            cout<<b;
    }
    else
    {
        for(int i=1; i<=b; i++)
            cout<<a;
    }
    return 0;
}

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

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i=0; i<n; i++)
    cin >> a.at(i);
  
  sort(a.begin(), a.end());
  cout << a.at(a.size()-1) - a.at(0) << endl;
}

Measured memory_bytes: 256
import Control.Monad
main = do
    str <- getLine
    if str == "0 0" then return ()
                    else do
                        let [len,sumNum] = map read.words $ str
                        print $ length.filter(\x -> sum x == sumNum && length x == len).filterM (\x -> [True,False]) $ [0..9] 
                        main

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

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i=0; i<N; i++) cin >> A[i];
  int ans =  1;
  N -= K;
  if (N == 0) cout << 1 << endl;
  else cout << 1+ceil((double)N/(K-1)) << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <stack>
#include <string>

using namespace std;
int main()
{
    int n;
    cin>>n;
    stack <string> s;string tmp;
    stack <int> t;int tem;
    for (int i=1;i<=n;i++)
    {
        cin>>tmp>>tem;
        s.push(tmp);
        t.push(tem);
    }
    string x;
    cin>>x;
    int k=0;
    while (!s.empty())
    {
        if (s.top()==x)
        {
            cout<<k;
            return 0;
        }
        else 
        {
            k+=t.top();
            t.pop();s.pop();
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cassert>
using namespace std;

#define REP(i,n) for (int i = 0; i < n; i++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long ll;

ll Paty[100];
ll Cnt[100];

ll dfs (ll L, ll Left) 
{
    if (L == 0) {
        return 1;
    }

    if (Left == 1) return 0;
    if (Left <= 1 + Cnt[L - 1]) {
        return 0 + dfs(L - 1, Left - 1);
    }
    if (Left == 2 + Cnt[L - 1]) {
        return 1 + Paty[L - 1];
    }
    if (Left <= 2 + Cnt[L - 1] * 2) {
        return 1 + Paty[L - 1] + dfs(L - 1, Left - 2 - Cnt[L - 1]);
    }
    return 1 + Paty[L - 1] * 2;
}

int main ()
{
    ll N,X;
    cin >> N >> X;

    ll cnt = 1;
    ll pcnt = 1;
    for (ll i = 0; i < 100; i++) {
        Cnt[i] = cnt;
        Paty[i] = pcnt;
        cnt = cnt * 2 + 3;
        pcnt = pcnt * 2 + 1;
    }

    cout << dfs(N, X) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#define MAX 100
using namespace std ;

int main()
{
	int n;
	int t=0,h=0;
	char tarou[MAX], hanako[MAX];
	
	cin >> n ;
	
	for(;n>0;n--){
		
		cin >> tarou >> hanako ;
		
		if(strcmp(tarou, hanako)>0){
			t += 3;
		}
		
		if(strcmp(tarou, hanako)==0){
			t++;
			h++;
		}
		
		if(strcmp(tarou, hanako)<0){
			h+=3;
		}
	}    
	
	cout << t << ' ' << h << endl ;
	
	return 0;
}

Measured memory_bytes: 1164
//#include <bits/stdc++.h>
#include <iostream>
#include<iomanip>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <unordered_map>
#include <cmath>
#include <chrono>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <cmath>
#include <set>
#include <list>
#include <stack>
#include <queue>
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_update
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define endl "\n"
#define ll long long
int inf = 1e9 + 7;
int ninf = -inf;
int mod = 998244353;
// typedef tree<
//     int,
//     null_type,
//     less<int>,
//     rb_tree_tag,
//     tree_order_statistics_node_update
//   >
// ordered_set;
int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
#ifdef _DEBUG
  FILE *fp;
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int n;
  cin>>n;
  vector<double> p(n);
  for(int i=0;i<n;++i){
    cin>>p[i];
  }
  int heads=n/2+1;
  vector<vector<double> > dp(n+1,vector<double>(n+1,0));
  dp[0][0]=1;
  for(int i=1;i<=n;++i){
    double heads_p=p[i-1];
    double tails_p=1-heads_p;
    for(int j=0;j<=n;++j){
      if(j==0){
        dp[i][j]=tails_p*dp[i-1][j];
      }
      else{
        dp[i][j]=(heads_p*dp[i-1][j-1])+(tails_p*dp[i-1][j]);
      }
    }
  }
  // for(int i=0;i<=n;++i){
  //   for(int j=0;j<=n;++j){
  //     cout<<dp[i][j]<<" ";
  //   }
  //   cout<<endl;
  // }
  double ans=0;
  for(int j=heads;j<=n;++j){
    ans+=dp[n][j];
  }
  cout << setprecision(15) << ans <<endl;
}

Measured memory_bytes: 73324
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
#define int long long



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

    int h,w; cin >> h >> w;

    int ans = 0;

    if( h == 1 || w == 1){
        cout << 1 << endl;
        return 0;
    }
    if(h % 2 == 0){
        ans += w * h / 2;
    }else{
        ans += w * (h-1) / 2;
        ans += w / 2;
        if(w % 2 == 1) ans ++;
    }

    cout << ans << endl;
}







Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	vector<int> arr(n);
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	if(k>=n)
	cout<<0<<endl;
	else
	{
		long long int res=0;
		sort(arr.begin(),arr.end());
		for(int i=0;i<n-k;i++)
		{
			res+=arr[i];
		}
		cout<<res<<endl;
	}
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
template <class T>void UNIQUE(vector<T> &x){
	sort(all(x));
	x.erase(unique(all(x)), x.end());
}

// }}} End Header
int main() {
	string s;
	cin >> s;
	vector<int> a(4);
	rep(i,4) a[i] = s[i]-'0';

	for(int bit = 0; bit<(1<<3); bit++){
		string t = to_string(a[0]);
		int sum = a[0];
		for(int i = 0; i<3; i++){
			if(bit&(1<<i)){
				sum+=a[i+1];
				t+=("+" + to_string(a[i+1]));
			}else{
				sum-=a[i+1];
				t+=("-" + to_string(a[i+1]));
			}
		}

		if(sum == 7){
			cout << t << "=7" <<endl;
			return 0;
		}
	}


	return 0;
}


Measured memory_bytes: 3692
from collections import deque

H, W = map(int, input().split())
grid = [list(input()) for _ in range(H)]
cnt = 0
INF = 10**4
dp = [[INF] * (W) for _ in range(H)]
dp[0][0] = 0
for i in range(H):
  for j in range(W):
    if grid[i][j] == '.':
      cnt += 1
dy = [1,0,-1,0]
dx = [0,1,0,-1]
que = deque([])
que.append((0, 0))
while len(que) > 0:
  cy, cx = que.popleft()
  if cy == H-1 and cx == W-1:
    break
  for i in range(4):
    ny, nx = cy+dy[i], cx+dx[i]
    if ny >= 0 and ny <= H-1 and nx >= 0 and nx <= W-1:
      if dp[ny][nx] == INF and grid[ny][nx] == '.':
        dp[ny][nx] = dp[cy][cx] + 1
        que.append((ny, nx))
if dp[H-1][W-1] == INF:
  print(-1)
else:
  print(cnt-dp[H-1][W-1]-1)


Measured memory_bytes: 3316
#include<iostream>

int main(){
  int a, b;
  std::cin >> a >> b;
  if(a == 1)
    a += 13;
  if(b == 1)
    b += 13;
  if(a == b)
    std::cout << "Draw";
  else if( a > b)
    std::cout << "Alice";
  else if(a < b)
    std::cout << "Bob";
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

int main()
{
  string s;
  cin >> s;
  int len = s.length();
  int depth = 0;
  int count = 0;
  for (int i=0;i<len;i++) {
    if (s[i] == '0') {
      if (depth > 0) count+=2;
      depth--;
    } else {
      if (depth < 0) count+=2;
      depth++;
    }
  }
  cout << count << endl;
  return 0;
}


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

int main(){

	string a, b, c;
	cin >> a >> b >> c;

	cout << char(toupper(a[0])) << char(toupper(b[0])) << char(toupper(c[0]))<<endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b;
	cin>>a>>b;
	int ans=0;
	FOR(i,a,b+1){
		string s=to_string(i);
		string t(s);
		reverse(begin(t),end(t));
		if(t==s) ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int Max = 1000000;
int main(){
  	string S;
  	cin >> S;
  	int N = S.size();

  	for(int i=0;i<N;i++){
  		cout << 'x';
  	}
  	cout <<endl;

    
  	return 0;
}






Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define forr(i,n) for(int i=n;i>=0;i--)
#define all(x) x.begin(), x.end()
const int MAXN = 1e5 +5;

void fio(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int main(){
  fio();
  int n; cin>>n;
  vector <pair<LL,LL> > v;
  vector <pair<LL,LL> > vx, vz;
  forn(i,n){
  	LL x = 0, z = 0;
  	string s; cin>>s;
  	LL t = 0;
  	while(s[t]==')' && t<s.size()){
  		x++;
  		z-=1;
  		t++;
  	}
  	while(t<s.size()){
  		if(s[t]==')') z--;
  		else z++;
  		t++;
  	}
  	if(z==s.size()) vx.pb({x,z});
  	else if(z==-1*s.size()) vz.pb({x,z});
  	else v.pb({x,z});
  }

  LL aa = 0, bb = 0;
  for(auto i:vx){
  	aa = bb - i.fi;
  	if(aa<0){
  		cout<<"No"<<endl;
  		return 0;
  	}
  	bb+=i.se;
  }

  sort(all(v), [&](pair<LL,LL> a, pair<LL,LL> b){
  	return a.se > b.se;
  });
 // forn(i,n) cout<<v[i].fi<<" "<<v[i].se<<endl;
  for(auto i:v){
  	aa = bb - i.fi;
  	if(aa<0){
  		cout<<"No"<<endl;
  		return 0;
  	}
  	bb+=i.se;
  }

  for(auto i:vz){
  	aa = bb - i.fi;
  	if(aa<0){
  		cout<<"No"<<endl;
  		return 0;
  	}
  	bb+=i.se;
  }

  cout<<(bb==0?"Yes":"No")<<endl;
  return 0;
}

Measured memory_bytes: 19084
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

signed main(void){
  int n,k,x,y;
  cin >> n >> k>> x>>y;
  int ans = x*k + y * (n-k);
  if(n-k<0){
    ans = x*n;
  }
  
  cout << ans << endl;
  return 0;
}


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


using namespace std;

int main()
{
    string Letter;
    string Vowel[] = {"a","e","i","o","u"};
    cin >> Letter;
    if(Letter == Vowel[0] || Letter == Vowel[1] || Letter == Vowel[2] || Letter == Vowel[3] || Letter == Vowel[4]){
        cout << "vowel" << endl;
    }else{
        cout << "consonant" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
using System.Linq;
using System;
using System.IO;

class Program
{
  static void Main(string[] args) => new Program().solve();

  private void solve()
  {
    var seq = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    var a = seq[0];
    var b = seq[1];

    var cnt = 0;
    for (int i = a; i <= b; i++)
    {
      if(i == reverse(acc:0, n:i)) cnt++;
    }

    Console.WriteLine(cnt);
  }

  private int reverse(int acc, int n)
  {
    if(n == 0) return acc;
    else return reverse(acc * 10 + (n % 10), n / 10);
  }
}

Measured memory_bytes: 13396
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int D = scanner.nextInt();
    int N = scanner.nextInt();
    long res = 1;
    for (int i = 0; i < D; i++) res *= 100;
    if (N == 100) N++;
    System.out.println(res * N);
  }
}


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

int main(){
    int a,b;
    while(1){
        cin>>a>>b;
        if (a==0&&b==0)break;
        
        if (a<b){
            cout<<a<<" "<<b<<endl;
        }else{
            cout<<b<<" "<<a<<endl;
        }
    }
        
    
    return 0;
}


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

#define int long long
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define yn(x) ((x) ? "YES" : "NO")

typedef pair <int, int> ii;
typedef pair <int, ii> iii;

const int siz = 1e5 + 10;
const int SIZ = 1e6 + 10;
const int mod = 1e9 + 7;
const int maxx = 2e9;
const int MAXX = 1e18;
const int offset = 1e9 - 1;
const string file = "1";

int psum1[siz], psum2[siz];

int get(char c) {
    if (c == 'A') {
        return 1;
    }
    return -1;
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

//    freopen ((file + ".inp").c_str(), "r", stdin);
//    freopen ((file + ".out").c_str(), "w", stdout);

    string s, t;
    cin >> s >> t;

    for (int i = 1; i <= sz(s); i++) {
        psum1[i] = psum1[i - 1] + get(s[i - 1]);
    }

    for (int i = 1; i <= sz(t); i++) {
        psum2[i] = psum2[i - 1] + get(t[i - 1]);
    }

    int q;
    cin >> q;

    while (q--) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;

        int sum1 = psum1[b] - psum1[a - 1];
        int sum2 = psum2[d] - psum2[c - 1];

        cout << yn((sum1 - sum2 + offset) % 3 == 0) << "\n";
    }

//    cerr << "Time: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

    return 0;
}


Measured memory_bytes: 5340