akhauriyash/Code-Regression huggingface dataset:
def INT():
    return int(input())

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

def MI():
    return map(int, input().split())

class UnionFind:
    def __init__(self, N):
        self.root = [_ for _ in range(N)]
        self.rank = [0] * N
        self.size = [1] * N
        
    def find(self, x):
        if self.root[x] == x:
            return x
        else:
            #パス圧縮
            self.root[x] = self.find(self.root[x])
            return self.root[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        else:
            if self.rank[x] > self.rank[y]:
                self.size[x] += self.size[y]
                self.root[y] = x
            else:
                self.size[y] += self.size[x]
                self.root[x] = y
                if self.rank[x] == self.rank[y]:
                    self.rank[y] += 1
            
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def getSizeOfSet(self, x):
        return self.size[self.find(x)]

import sys
sys.setrecursionlimit(10**9)

N, M = MI()
friend = UnionFind(N)

for _ in range(M):
    A, B = MI()
    friend.union(A - 1, B - 1)
    
ans = 0
for i in range(N):
    ans = max(ans, friend.getSizeOfSet(i))
    
print(ans)

Measured memory_bytes: 90160
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e15+9
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n;
int field[110][110];
bool f[110][110];

int main(){
	while (cin >> n&&n){
		REP(i, 110)REP(j, 110)f[i][j] = 0;
		REP(i, n)REP(j, n)cin >> field[i][j];
		
		REP(i, n){
			int MIN = field[i][0];
			REP(j, n)MIN = min(MIN, field[i][j]);
			REP(j, n){
				if (MIN == field[i][j])f[i][j] = 1;
			}
		}
		int ans = 0;
		REP(j, n){
			int MAX = field[0][j];
			REP(i, n)MAX = max(MAX, field[i][j]);
			REP(i, n){
				if (MAX == field[i][j] && f[i][j]){
					ans = field[i][j];
					break;
				}
			}
			if (ans != 0)break;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1180
#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 <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>
#include <regex>
#include <numeric>

#define M_PI       3.14159265358979323846

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//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)
#define MOD 1000000007
#define SQ(x) ((x)*(x))

int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	LL lx=0, ly=0;
	LL tx;
	scanf("%lld", &tx);
	FOR(i, 1, n) {
		LL x;
		scanf("%lld", &x);
		LL len = ((LL)i*(LL)(n - i))%MOD;
		len = (len * (x - tx)) % MOD;
		lx = (lx + len) % MOD;
		tx = x;
	}
	scanf("%lld", &tx);
	FOR(i, 1, m) {
		LL x;
		scanf("%lld", &x);
		LL len = ((LL)i*(LL)(m - i)) % MOD;
		len = (len * (x - tx)) % MOD;
		ly = (ly+ len) % MOD;
		tx = x;
	}
	cout << (lx*ly) % MOD << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i,N){
        int a;
        cin >> a;
        a--;
        A[a] = i;
    }

    set<int> B;
    set<int> C;
    ll ans = 0;
    REP(a,N){
        int idx = A[a];
        ll right, left;
        auto riter = B.upper_bound(idx);
        if(riter == B.end())
            right = N - idx - 1;
        else
            right = *riter - idx - 1;

        auto liter = C.upper_bound(-idx);
        if(liter == C.end())
            left = idx;
        else
            left = idx + *liter - 1;

        ans += (ll)(a+1) * (left+1) * (right+1);
        B.insert(idx);
        C.insert(-idx);
    }

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


Measured memory_bytes: 19840
#include <algorithm>  //min, max, sort, unique, fill
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>  //pair, swap,
#include <vector>

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

vector<long long> vi;

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

  for (int i = 1; i < n ; i++) {
    temp = 0;
    string s1 = s.substr(0, i);
    string s2 = s.substr(i, n - i);
    for (char c = 'a'; c <= 'z'; c++) {
      if (s1.find(c) != string::npos && s2.find(c) != string::npos) temp++;
    }
    vi.push_back(temp);
  }
  cout << *max_element(vi.begin(), vi.end()) << endl;

  return 0;
}


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

int S[10000],A[500];
int 	linearSearch(int,int);

int main() {
	int n,i,q,k=0,aa,p=0;
	int T[500];
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++) {
		scanf("%d",&S[i]);
		}
		scanf("%d",&q);
		
		for(i=0;i<q;i++) {
			scanf("%d",&T[i]);
			}
			
			for(i=0;i<q;i++) {
			aa=linearSearch(T[i],n);
			if(aa==1) p++;
			n++;
		}	
		printf("%d\n",p);
		return 0;
}
		
		
	int 	linearSearch(int key, int n) {
int i = 0;
   S[n] = key;
  while (S[i]!=key) { 	
     i++; 
   }
    if (i==n) {
     return 0;
    }
        return 1;
        }


Measured memory_bytes: 2144
N = int(input())
a = list(map(int, input().split()))

ans = 0

for i in range(N):
  j = 0
  while 1:
    if a[i] % (2 ** (j + 1)) == 0:
      j += 1
    else:
      ans += j
      j = 0
      break
else:
  print(ans)

Measured memory_bytes: 10064
import java.util.ArrayList;
import java.util.Scanner;


public class Main {
public static void main (String[] args){


	Scanner sc =new Scanner(System.in);
	ArrayList<Integer> list=new ArrayList<Integer>();

	while(sc.hasNext()) {
		list.add(Integer.parseInt(sc.next()));
	}

	int num= list.get(0);
	int sum=list.get(1);
	int i=0;
	
	if(sum==1) {
		System.out.print(0);
	}else if(num>=sum) {
		System.out.print(1);
	}else {
		sum=sum-num;
		i++;
		num--;
		while(true){
			sum=sum-num;
			i++;

			if(sum<1) {
				System.out.print(i);
				break;
			}
		}
	}
}
}



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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define LL long long

LL n,a,b;

int main(){
  cin>>n>>a>>b;
  if(a < b){
    LL tmp = a;
    a = b;
    b = tmp;
  }
  if((a - b) % 2 == 0){
    cout<<(a-b)/2<<endl;
    return 0;
  }
  LL ret = (a + b - 2 + 1)/2;
  ret = min(ret,(n-a+n-b+1)/2);
  cout<<ret<<endl;
  return 0;
}


Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize
    };

    let mut sum = 0.0;
    for _ in 0..n {
        input! {
            x: f64,
            u: String,
        }

        if u == "JPY" {
            sum += x;
        } else {
            sum += x * 380000.0;
        }
    }

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


Measured memory_bytes: 2236
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <climits>
#include <set>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ve vector
#define umap unordered_map
#define iter iterator

void solve() {
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout << max(0, min(b,d) - max(a,c)) << endl;
}

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

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
  int M, N;
  cin >> M >> N;
  // M - cat N - room
  double pos[16][16];
  REP(i, M) REP(j, N) cin >> pos[i][j];

  static double dp[1 << 16][17];
  REP(S, 1 << M) REP(u, N + 1) dp[S][N] = (S > 0 && u == N) ? 1.0 : 0.0;

  for(int u = N - 1; u >= 0; u--){
    for(int S = 0; S < 1 << M; S++){
      for(int i = 0; i < M; i++) if(S >> i & 1){
        double p = 1.0;
        double npos = 0.0;
        for(int v = u; v < N; v++){
          npos += dp[S & ~(1 << i)][v] * p * (1.0 - pos[i][v]);
          p *= pos[i][v];
        }
        npos += dp[S][N] * p;
        dp[S][u] = max(dp[S][u], npos);
      }
    }
  }

  printf("%.12f\n", dp[(1 << M) - 1][0]);
  return 0;
}

Measured memory_bytes: 9956
//THE DOC

#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
typedef long long int ll;
typedef unsigned long long int ull;
#define fi first
#define se second
#define pb push_back
ll mod1=pow(10,9)+7;
int mod2=998244353;
ll inf=1e9;
ll maxxy=1e6+9;
typedef long double ld;
const double PI =  3.141592653589793238;

ll power(ll x, ll y, ll pp)
{
    ll res = 1;
    x = x % pp;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % pp;
        y = y>>1;
        x = (x*x) % pp;
    }
    return res;
}

ll modInverse(ll n, ll pp)
{
    return power(n, pp-2, pp);
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x,t;
    cin>>n>>x>>t;
    if(n%x==0){
        cout<<(n/x)*t<<"\n";
    }
    else{
        cout<<(n/x+1)*t<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3636
//https://atcoder.jp/contests/abc120/tasks/abc120_d
//D - Decayed Bridges
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
const ll LINF = 0x1fffffffffffffff;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}

struct uf_tree {
    std::vector<int> parent;
    int __size;
    uf_tree(int size_) : parent(size_, -1), __size(size_) {}
    void unite(int x, int y) {
        if ((x = find(x)) != (y = find(y))) {
            if (parent[y] < parent[x]) std::swap(x, y);
            parent[x] += parent[y];
            parent[y] = x;
            __size--;
        }
    }
    bool is_same(int x, int y) { return find(x) == find(y); }
    int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
    int size(int x) { return -parent[find(x)]; }
    int size() { return __size; }
};

int main() {
#if LOCAL&01
  std::ifstream in("./test/sample-1.in");
  //std::ifstream in("./input.txt");
  std::cin.rdbuf(in.rdbuf());
#else
  cin.tie(0);
  ios::sync_with_stdio(false);
#endif
  ll N,M; cin>>N>>M;
  vector<pair<ll,ll>> abm(M);
  for(auto&& ab:abm){
    cin>>ab.first>>ab.second;
  }
  ll sum=0;
  vector<ll> sums;
  uf_tree ut(N+1);
  for(ll i=M-1;i>=0;--i){
    sums.push_back(sum);
    const auto& ab=abm.at(i);
    if(ut.is_same(ab.first,ab.second)){
      ll n0 = ut.size(ab.first);
      sum -= n0*(n0-1)/2;
    } else{
      ll n0 = ut.size(ab.first);
      sum -= n0*(n0-1)/2;
      ll n1 = ut.size(ab.second);
      sum -= n1*(n1-1)/2;
    }

    ut.unite(ab.first,ab.second);

    ll n3 = ut.size(ab.first);
    sum += n3*(n3-1)/2;
  }
  dump(sums);
  ll ttl=N*(N-1)/2;
  for(auto it=sums.rbegin();it!=sums.rend();++it){
    ll ans=(ttl-*it);
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 4212
#include<bits/stdc++.h>
#define pii pair<ll,ll>
using namespace std;
typedef long long ll;
const ll modd=1000000007;
ll n,cnt_o,ans=1;
map<pii,ll> cnt_vec,vis;
vector<pii> v;
ll qpow(ll a,ll b) {
	ll ans=1,base=a;
	while(b) {
		if(b&1) ans=ans*base%modd;
		b>>=1,base=base*base%modd;
	}
	return ans;
}
pii get(ll tx,ll ty) {
	swap(tx,ty),ty=-ty;
	if(tx<0) tx*=-1,ty*=-1;
	if(tx==0&&ty<0) ty*=-1;
	return make_pair(tx,ty);
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i=1; i<=n; i++) {
		ll x,y;
		cin>>x>>y;
		ll gcd=__gcd(x,y);
		if(!gcd) cnt_o++;
		else {
			x/=gcd,y/=gcd;
			if(x<0) x*=-1,y*=-1;
			cnt_vec[make_pair(x,y)]++;
			if(!vis[make_pair(x,y)]) {
				v.push_back(make_pair(x,y));
				vis[make_pair(x,y)]=1;
			}
		}
	}
	vis.clear();
	for(int i=0; i<v.size(); i++) {
		ll tx=v[i].first,ty=v[i].second;
		pii v_verti=get(tx,ty);
		if(!vis[v[i]]) {
			ll cur=(qpow(2,cnt_vec[v[i]])+qpow(2,cnt_vec[v_verti])-1)%modd;
			vis[v_verti]=vis[v[i]]=1;
			ans=ans*cur%modd;
		}
	}
	ans=((ans+cnt_o-1)%modd+modd)%modd;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 56364
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <string>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <map>
using namespace std;
#define ms(a, x) memset(a, x, sizeof(a))
#define fore(i, a, n) for (long long i = a; i < n; i++)
#define ford(i, a, n) for (long long i = n - 1; i >= a; i--)
#define si(a) scanf("%d", &a)
#define sl(a) scanf("%lld", &a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define siii(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sll(a, b) scanf("%lld%lld", &a, &b)
#define slll(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define debug(a) cout << a << endl
#define pr(a) printf("%d ", a)
#define endl '\n'
#define pi acos(-1.0)
#define tr t[root]
#define lson t[root << 1]
#define rson t[root << 1 | 1]
#define IO ios::sync_with_stdio(false), cin.tie(0)
#define ull unsigned long long
#define py puts("Yes")
#define pn puts("No")
#define pY puts("YES")
#define pN puts("NO")
#define re(i, a, b) for (int i = a; i <= b; ++i)
#define de(i, a, b) for (int i = a; i >= b; --i)
const double eps = 1e-8;
inline int sgn(const double &x) { return x < -eps ? -1 : x > eps; }
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int MAXN = 1e5 + 5;
template <class T>
inline void cmin(T &a, T b) { ((a > b) && (a = b)); }
template <class T>
inline void cmax(T &a, T b) { ((a < b) && (a = b)); }
string s;
ll a[MAXN];
int main()
{
  int n, k, d;
  sii(n, k);
  while (si(d) == 1)
  {
    int t;
    re(i, 1, d)
    {
      si(t);
      a[t] = i;
    }
  }
  int cnt = 0;
  re(i, 1, n) if (a[i]==0) cnt++;
  cout << cnt << endl;
}


Measured memory_bytes: 3724
n,m=list(map(int,input().split()))
par=[i for i in range(n)]
ro=dict()

for i in range(n):
    ro[i]=1
def root(i):
    if par[i]==i:
        return i
    else:
        a=root(par[i])
        par[i]=a
        return a

def unite(x,y):
    rx=root(x)
    ry=root(y)
    if rx!=ry:
        par[rx]=ry
        ro[ry]+=ro[rx]
        ro[rx]=0

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

print(max(ro.values()))

Measured memory_bytes: 37772
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int X = sc.nextInt();
		int Y = sc.nextInt();
		sc.close();

		int sum1 = A*X + B*Y;
		int sum2 = X > Y ? (2*C*Y) + (A*(X - Y)):(2*C*X) + (B*(Y - X)) ;
		int sum3 = X > Y ? 2*C*X : 2*C*Y;
		System.out.println(Math.min(sum3, Math.min(sum1,sum2)));
	}
}

Measured memory_bytes: 23380
#!/usr/bin/env python3
import sys


def solve(N: int, K: int):
    if K % 2 == 0:
        k2 = K // 2
        print(((N // k2 + 1) // 2) ** 3 + (N // K) ** 3)
    else:
        print((N // K) ** 3)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
N = int(input())
ls = list(map(int, input().split()))
alice = 0
bob = 0

for i in range(N):
    if((i % 2) == 0):
        alice += max(ls)
    else:
        bob += max(ls)
    ls[ls.index(max(ls))] = 0

out = alice - bob
print(out)


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

using namespace std;

#define int long long
#define ar array
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)

template<class T>
bool umin(T &a, const T &b) {
    return b < a ? a = b, 1 : 0;
}

template<class T>
bool umax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

template<class A>
void read(vt<A> &v);

template<class A, size_t S>
void read(ar<A, S> &a);

template<class T>
void read(T &x) {
    cin >> x;
}

void read(double &d) {
    string t;
    read(t);
    d = stod(t);
}

void read(long double &d) {
    string t;
    read(t);
    d = stold(t);
}

template<class H, class... T>
void read(H &h, T &... t) {
    read(h);
    read(t...);
}

template<class A>
void read(vt<A> &x) {
    EACH(a, x)read(a);
}

template<class A, size_t S>
void read(array<A, S> &x) {
    EACH(a, x)read(a);
}

string to_string(char c) {
    return string(1, c);
}

string to_string(bool b) {
    return b ? "true" : "false";
}

string to_string(const char *s) {
    return string(s);
}

string to_string(string s) {
    return s;
}

string to_string(vt<bool> v) {
    string res;
    FOR(sz(v))res += char('0' + v[i]);
    return res;
}

template<size_t S>
string to_string(bitset<S> b) {
    string res;
    FOR(S)res += char('0' + b[i]);
    return res;
}

template<class T>
string to_string(T v) {
    bool f = 1;
    string res;
    EACH(x, v) {
        if (!f)
            res += ' ';
        f = 0;
        res += to_string(x);
    }
    return res;
}

template<class A>
void write(A x) {
    cout << to_string(x);
}

template<class H, class... T>
void write(const H &h, const T &... t) {
    write(h);
    write(t...);
}

void print() {
    write("\n");
}

template<class H, class... T>
void print(const H &h, const T &... t) {
    write(h);
    if (sizeof...(t))
        write(' ');
    print(t...);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n) {
    v = vt<T>(n, x);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n, size_t m...) {
    v = vt<T>(n);
    EACH(a, v)vti(a, x, m);
}

void solve() {
    int n;
    read(n);
    
    vt<int> a(26, 1e9);
    
    FOR(n) {
        string s;
        read(s);
        FOR(j, 26) {
            int cnt = 0;
            FOR(k, s.size()) {
                cnt += s[k] - 'a' == j;
            }
            a[j] = min(a[j], cnt);
        }
        
    }
    
    FOR(26) {
        write(string(a[i], i + 'a'));
    }
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int tt = 1;
    //read(tt);
    FOR(tt) {
        
        solve();
        
    }
    
}



Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int dp[n],a[n];
  cin>>a[0]>>a[1];
  dp[0]=0;
  dp[1]=abs(a[1]-a[0]);
  for(int i=2;i<n;i++){
    cin>>a[i];
    dp[i]=min(abs(a[i]-a[i-1])+dp[i-1],abs(a[i]-a[i-2])+dp[i-2]);
  }
  cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int main() {
	int n; cin >> n;
	ll a[200000];
	rep(i, n) {
		cin >> a[i]; a[i] = a[i] - (ll)(i + 1);
	}
	sort(a, a + n);
	ll sum[200001]; sum[0] = 0;
	rep(i, n) {
		sum[i + 1] = sum[i] + a[i];
	}
	ll mi = INF;
	rep(i, n) {
		ll r = sum[n] - sum[i] - ((ll)(n - i))*a[i] -( sum[i] - sum[0] - (ll)i*a[i]);
		mi = min(mi, r);
	}
	cout << mi << endl;
	return 0;
}

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

void Main()
{
    int n;
    cin >> n;
    vector<string> s;
    s.push_back("a");
    for (int i = 0; i < n-1; i++)
    {
        vector<string> d;
        for (auto j: s) {
            char lc = 'a';
            for (auto k: j) {
                lc = max(lc, k);
            }
            for (char k = 'a'; k <= lc+1; k++)
            {
                d.push_back(j+k);
            }
        }
        s = d;
   }
    
    for (auto i: s) {
        cout << i << endl;
    }
}

int main(int argc, char **argv)
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    Main();
    return 0;
}


Measured memory_bytes: 11156
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int N,M;
vector<int>G[50];
int a[20],b[20];
int depth[50];
long subtree[50];
long dfs(int u,int p,int d)
{
	depth[u]=d;
	subtree[u]=1LL<<u;
	for(int v:G[u])
	{
		if(v!=p)
		{
			subtree[u]|=dfs(v,u,d+1);
		}
	}
	return subtree[u];
}
int u[50],v[50];
int check[50];
main()
{
	cin>>N;
	for(int i=0;i<N-1;i++)
	{
		cin>>u[i]>>v[i];u[i]--,v[i]--;
		G[u[i]].push_back(v[i]);
		G[v[i]].push_back(u[i]);
	}
	dfs(0,-1,0);
	cin>>M;
	for(int i=0;i<M;i++)
	{
		cin>>a[i]>>b[i];
		a[i]--,b[i]--;
		long test=1LL<<a[i]|1LL<<b[i];
		for(int j=0;j<N-1;j++)
		{
			int U=depth[u[j]]<depth[v[j]]?v[j]:u[j];
			if((test&subtree[U])!=test&&(test&subtree[U])!=0)
			{
				check[j]|=1<<i;
			}
		}
	}
	long ans=0;
	for(int i=0;i<1<<M;i++)
	{
		int cnt=N-1;
		for(int j=0;j<N-1;j++)
		{
			if(check[j]&i)cnt--;
		}
		long now=1LL<<cnt;
		ans+=__builtin_parity(i)?-now:now;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
MOD = 10**9 + 7
import sys
input = sys.stdin.readline
N = int(input())
S = input().strip()

LR = []
d = 0
for s in S:
    if s == 'B':
        if d % 2:
            LR.append('R')
            d -= 1
        else:
            LR.append('L')
            d += 1
    else:
        if d % 2:
            LR.append('L')
            d += 1
        else:
            LR.append('R')
            d -= 1
    if d < 0:
        print(0)
        exit()
if not d == 0:
    print(0)
    exit()

ans = 1
d = 0
for m in LR:
    if m == 'L':
        d += 1
    else:
        ans *= d
        ans %= MOD
        d -= 1

for i in range(N):
    ans *= (i+1)
    ans %= MOD
print(ans)





Measured memory_bytes: 86680
import java.lang.Exception;
import java.lang.System;
import java.util.LinkedList;
import java.util.Scanner;

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

        LinkedList<Integer> queue = new LinkedList<Integer>();
        while (sc.hasNextInt()) {
            int n = sc.nextInt();

            if (n > 0) {
                queue.push(n);
            } else {
                System.out.println(queue.pop());
            }
        }
    }
}

Measured memory_bytes: 17212
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4.2")
#include <bits/stdc++.h>

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = 1e9+7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n; ll k;
	cin >>n >>k;
	VL a(n);
	rep(i, n) cin >>a[i];
	VI sm(52, 0);
	repr(i, 51, 0) rep(j,n){
		if(a[j]>>i &1) sm[i]++;
	}
	ll  cnd=0, ans=0;
	repr(i, 51, 0){
		if(sm[i] < n-sm[i] && cnd + (1LL<<i) <=k  ) cnd += (1LL<<i);
	}
	auto f =[&a](ll cnd)->ll{
		ll rtn =0;
		for(auto x: a){
			rtn += x ^ cnd;
		}
		return rtn;
	};
	ans = f(cnd);
	repr(j, 41, 0){
		if(cnd >> j &1){
			ll wc = 0;
			repr(i, 41, 0){
				if(sm[i] < n-sm[i] && j !=i && wc + (1LL<<i) <=k  ) wc += 1LL<<i;
			}
			ans = max(ans, f(wc));
			//dbg(j, wc, f(wc));
		}
	}
	
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
using namespace std;
const int INF = 2e9;
const ll INFLL = 4e18;
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 1e6+100;
const int mod = 1e9+7;
int a[upperlimit];
int main() {
	int n,r=0,w=0;
	string s;
	cin >> n >> s;
	for(int i = n-1; i >= 0; i--){
		if(s[i]=='R'){
			r++;
			a[r]=i;
		}
	}
  	a[r+1]=-1;
	for(int i = 0; i < n; i++){
		if(s[i]=='W'){
			w++;
			if(a[w]<i){
				pd(w-1);
				return 0;
			}
		}
	}
	pd(w);
	return 0;
}

Measured memory_bytes: 4508
function Main(input) {
	input = input.trim().split("\n").map(function(x) { return x.split(" ")});
	let N = parseInt(input[0][0], 10);
	a = input[1] .map(e => parseInt(e, 10));
	DP = Array.from({length: N}, () => []);
	ruisekiwa = [0];
	for (let i = 0; i < N; i++) ruisekiwa.push(ruisekiwa[i] + a[i]);
	console.log(kukanDP(0, N - 1))
}

function kukanDP(l, r){
	if (DP[l][r] != null) return DP[l][r];
	if (l === r) {
		DP[l][r] = 0;
		return 0;
	}
	if (r === l + 1){
		DP[l][r] = a[l] + a[r];
		return DP[l][r];
	}
	let tmp = Infinity;
	for (let i = l; i < r; i++){
		tmp = Math.min(tmp, kukanDP(l, i) + kukanDP(i + 1, r) - ruisekiwa[l] + ruisekiwa[r + 1]);
	}
	DP[l][r] = tmp;
	return tmp;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 42368
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner scanner = new Scanner(System.in);
        
        long N = scanner.nextLong();
        long K = scanner.nextLong();
        long Sum = 0;
        List<Long> list = new ArrayList<Long>();
        
        for(long i=0; i<N; i++){
            
            long HP = scanner.nextLong();
            list.add(HP);
            
        }
        
        Collections.sort(list, Collections.reverseOrder());
        
        for(long i=K; i<N; i++){
            Sum += list.get((int)i);
        }
        
        System.out.println(Sum);
    }
}


Measured memory_bytes: 96292
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
typedef long long LL;

int main() {
  int N; std::cin >> N;
  std::string S; std::cin >> S;
  if (N%2 == 1) {
    std::cout << "No" << std::endl;
    return 0;
  }

  for (int i = 0; i < N/2; ++i) {
    if (S[i] != S[i + N/2]) {
      std::cout << "No" << std::endl;
      return 0;
    }
  }
  std::cout << "Yes" << std::endl;
  return 0;
}


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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int west = 0;
  int east = 0;
  for(int i=0;i<n;i++) {
    if(s[i] == 'W') west++;
    else east++;
  }

  vector<int> ans(n);

  for(int i=0;i<n;i++) {
    if(i==0) {
      if(s[i] == 'W') ans[i] = east;
      else ans[i] = east - 1; 
    } else {
      if(s[i-1] == 'W') {
        if(s[i] == 'E') ans[i] = ans[i-1];
        else ans[i] = ans[i-1] + 1;
      } else {
        if(s[i] == 'E') ans[i] = ans[i-1] - 1;
        else ans[i] = ans[i-1];
      }
    }
  }

  int min = *min_element(ans.begin(), ans.end());

  cout << min << endl;
}

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

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

  int b = 0, w = 0;
  for (int i = 0; i < n; i ++) {
    if (s[i] == '#') b ++;
    else w ++;
  }
  int ans = min(b, w);
  vector<int> a;
  if (s[0] == '.') a.push_back(0);
  int cnt = 1;
  for (int i = 1; i < n; i ++) {
    if (s[i] != s[i-1]) {
      a.push_back(cnt);
      cnt = 0;
    }
    cnt ++;
  }
  a.push_back(cnt);
  if (s[n-1] == '#') a.push_back(0);

  int bv = 0, wv = w;
  for (int i = 0; i < a.size(); i += 2) {
    bv += a[i];
    wv -= a[i+1];
    ans = min(ans, bv + wv);
  }

  cout << ans << endl;
}


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

int main(){
  string str;
  string ans = "No";
  cin >> str;
  if(str.size() %2 == 0){
    ans = "Yes";
    sort(str.begin(),str.end());
    for(int i = 0; i < str.size(); i+=2){
      if(str.at(i) != str.at(i+1)){
        ans = "No";
        break;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use itertools_num::ItertoolsNum;
#[allow(unused_imports)]
use proconio::{fastout, input, marker::Bytes, marker::Chars, marker::Isize1, marker::Usize1};
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::iter;
#[allow(unused_imports)]
use superslice::*;

fn run() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let x: usize = sc.read();

    let ans = if x == 0 { 1 } else { 0 };
    println!("{}", ans);
}

fn main() {
    std::thread::Builder::new()
        .name("run".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(run)
        .unwrap()
        .join()
        .unwrap();
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn read_pairs<T: std::str::FromStr>(&mut self, n: usize) -> Vec<(T, T)> {
        (0..n).map(|_| (self.read(), self.read())).collect()
    }
    pub fn read_pairs_1_indexed(&mut self, n: usize) -> Vec<(usize, usize)> {
        (0..n)
            .map(|_| (self.read::<usize>() - 1, self.read::<usize>() - 1))
            .collect()
    }
    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    pub fn read_char_grid(&mut self, n: usize) -> Vec<Vec<char>> {
        (0..n).map(|_| self.read_chars()).collect()
    }
    pub fn read_matrix<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n)
            .map(|_| (0..m).map(|_| self.read()).collect())
            .collect()
    }
}


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

int main(){
	int m, f, b;
	cin >> m >> f >> b;

	if(m >= b) cout << 0 << endl;
	else if(m + f >= b) cout << abs(m - b) << endl;
	else cout << "NA" << endl;

	return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
using namespace std;
 
int main(){
    
    int N , a[10010]={};
    long ans ;
    cin >> N;

    for(int i=1;i<=N;i++){
        cin >> a[i];
    }

    for(int i=1;i<=N;i++){
        while((a[i]%2)==0){
            a[i] = a[i] / 2;
            ans +=1;
        }
    }

    cout << ans << endl;

    return 0;
}

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

class UnionFind
{
    vector<int> par;
public:
    UnionFind(int n){par.assign(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 0;
        if(par[x]>par[y])swap(x,y);
        par[x]+=par[y];
        par[y]=x;
        return 1;
    }
    int size(int x){return -par[root(x)];}
};
const long long ma=110000;
long long n;
vector<long long> x,y;

long long solve()
{
    cin>>n;
    UnionFind uf(ma*2);
    x.resize(n);y.resize(n);
    for(int i=0;i<n;i++)cin>>x[i]>>y[i],uf.merge(x[i],y[i]+ma);

    map<int,long long> mx,my;
    for(int i=0;i<ma;i++)mx[uf.root(i)]++;
    for(int i=ma;i<2*ma;i++)my[uf.root(i)]++;
    long long res=0;
    for(int r=0;r<ma*2;r++)res+=mx[r]*my[r];
    return res-n;
}
main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cout<<solve()<<endl;
    return 0;
}

Measured memory_bytes: 32256
#include<iostream>
#include<string.h>
#include<vector>
#include<algorithm>
using namespace std;
#define ll long long 
#define ull unsigned long long
#define pb push_back
const int maxn = 50005;
const ll mod = 1000000007;
int main()
{
    string s1 = "dreamer", s2 = "dream", s3 = "eraser", s4 = "erase"; 
    string s;
    cin >> s;
    int f = 1;
    while (f)
    {
        f = 0;
        int len = s.length();
        if (len < 5)break;

        if ((s.compare(len - 5, len, s2) == 0) || (s.compare(len - 5, len, s4) == 0))
        {
            s.erase(len - 5, len);
            f = 1;
            continue;
        }
        if ((s.compare(len - 6, len, s3) == 0))
        {
            s.erase(len - 6, len);
            f = 1;
            continue;
        }
        if ((s.compare(len - 7, len, s1) == 0))
        {
            s.erase(len - 7, len);
            f = 1;
            continue;
        }
    }
    if (s.length() == 0)puts("YES");
    else puts("NO");
 }

Measured memory_bytes: 3784
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#define pb push_back
using namespace std;
typedef pair<int,int> pii;

int main(){
  string s,t;
  cin>>s>>t;
  bool f=false;
  for(int i=0;i<s.size();i++){
    if(s==t) f=true;
    t=t[t.size()-1]+t;
    t.pop_back();
    //cout<<":"<<t<<endl;
  }
  if(f) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}



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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<long long, long long> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<pair<ll,ll> > vii;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pair<long long,long long> > vpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;

#define PI 3.141592653589793
#define mod 1000000007
#define N 100005
# define M 5001
//int N;
//# define N 2003
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
# define INF (ll)1e18
# define A 1000000


int main()
{
  ll a,b,c,x,y;
  cin >> a >> b >> c >> x >> y;
  ll ans=0;
  ll cost1=min(a+b,2*c);
  ll qt=min(x,y);
  ans+=qt*cost1;
  x-=qt;
  y-=qt;
  if(x>0)
  {
    ll ncost=min(a,2*c);
    ans+=(x*ncost);
    cout << ans;
    return 0;
  }
  else if(y>0)
  {
    ll ncost=min(b,2*c);
    ans+=(y*ncost);
    cout << ans;
    return 0;
  }
  cout << ans;

}

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

#include <bits/stdc++.h>

using namespace std;
#define ll long long

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int (i) = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int (i) = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int (i) = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "yes"
#define FALSE__ "no"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#define INF 1e9

int dp[201][101];
int temp[200];
vector<pair<pair<int, int>, int> > v;

int D, N;

void init()
{
	rep(i, 201) rep(j, 101) dp[i][j] = -INF;
	dp[0][0] = 0;
}
	

int main()
{
	init();
	cin >> D >> N;
	rep(i, D) cin >> temp[i];
	rep(i, N) {
		CIN(int, t);
		CIN(int, tt);
		CIN(int, ttt);
		v.PB(MP(MP(t, tt), ttt));
	}
	sort(all(v));
	rep(i, D) {
		int t = temp[i];
		vector<int> vv; 
		rep(j, v.size()) {
			auto pt = v[j];
			auto ptt = pt.first;
			if (ptt.first <= t && ptt.second >= t) {
				vv.PB(pt.second);
			}
		}
		rep(j, 101) {
			if (dp[i][j] == -INF) continue;
			rep(k, vv.size()) {
				if (i == 0) {
					dp[i+1][vv[k]] = 0;
				} else {
					dp[i+1][vv[k]] = max(dp[i+1][vv[k]], dp[i][j] + abs(j-vv[k]));
				}
			}
		}	
	}
	int res = -1;
	rep(i, 101) res = max(res, dp[D][i]);
	cout << res << endl;
}


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

void swap(long long int x,long long int y){
  long long int a=x;
  x=y;
  y=a;
}
  

long long int gcd (long long int a,long long int b){
  if (a>b) swap(a,b);
  while(b%a!=0){
    long long int c=b;
    b=a;
    a=c%a;
  }
  return a;
}

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

int main(){
  long long int A,B,C,D,E;
  cin>>A>>B>>C>>D;
  E=lcd(C,D);
  
 long long int F,G,H,I,J,K;
  
  F=(A-1)/C;
  H=(A-1)/D;
  J=(A-1)/E;
  G=B/C;
  I=B/D;
  K=B/E;
  
 long long int ans;
  ans=(B-A+1)-(G-F+I-H+J-K);
  cout<<ans<<endl;
}
  
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

typedef long long LL;

const int maxn=1e5+5;
const LL mo=1e9+7;

int n,apb[30];
char S[maxn];

int main()
{
	scanf("%d",&n);
	scanf("%s",S+1);
	fo(i,1,n) apb[S[i]-'a']++;
	
	LL ans=1;
	fo(i,0,25) (ans*=apb[i]+1)%=mo;
	
	printf("%lld\n",(ans-1+mo)%mo);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll  long long int
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define br cout <<"\n";
#define all(x)  (x).begin(),(x).end()
#define rall(x)  (x).rbegin(),(x).rend()
#define tr(c,i) for(auto i :c)
#define pii pair< int,int >
#define Fast_IO() ios_base::sync_with_stdio(false);cin.tie(0)
#define pq priority_queue< pair<ll,pii> ,vector<pair<ll,pii>>,greater <pair<ll,pii>> >p;//container adapter makes ascending q
#define er(x) cout << x << " "
#define err(x,y) cout << x << " "<<y
const int MOD = 1000 * 1000 * 1000 + 7; // odd modulus
const int N = 100;
using namespace std;
clock_t time_p=clock();
void dem()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
int main()
{
    Fast_IO();
    int n ;
    cin >> n ;
    vector<ll> v ( n + 1 , 0  ) ;
    ll sum = 0 , tot = 0  ;

    for ( int  i = 1 ; i <= n ; ++i )
    {   ll x ;
        cin >> x ;
        tot += x ;
        v[i] = 2 * x ;
        if ( i % 2 == 0 )sum += v[i] ;
    }
    int st =  tot - sum ;
    cout << st <<" ";
    for ( int i = 2 ; i <= n ; ++ i )
    {
      cout << v[i-1] - st   <<" " ;
        st = v[i-1] - st ;
    }





    return 0 ;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
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()
{
    int K, S;
    cin >> K >> S;
    int64_t count = 0;
    for (int x=0; x<=K; x++) {
        for (int y=0; y<=K; y++) {
            int sum_ = x + y;
            if (sum_ <= S && (S - sum_) <= K) {
                count += 1;
            }

            if (sum_ > S) {
                break;
            }
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define ll long long
#define MAX 100000
#define INF 1000000
#define M 1000000007
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std; 
int main(){
    fast_io 
    ll n;
    cin>>n;
    ll a[n+1];
    for(ll i = 1;i<=n;i++) cin>>a[i];
    ll ans = 0;
    for(ll i = 1;i<=n;i++){
        if(i%2 != 0 && a[i]%2 != 0){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3580
typedef long long ll;
#include <bits/stdc++.h>

using namespace std;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll n,K;

const ll INF = 4e18;

pair<ll,ll> ps[60];

int main() {
    std::cin >> n>>K;
    for (int i = 0; i < n; i++) {
        std::cin >> ps[i].first>>ps[i].second;
    }
    
    ll result = INF;
    
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            for (int k = 0; k < n; k++) {
                for (int l = k+1; l < n; l++) {
                    // K個以上あるかの判定
                    ll min_x = min(ps[i].first,ps[j].first);
                    ll max_x = max(ps[i].first,ps[j].first);
                    ll min_y = min(ps[k].second,ps[l].second);
                    ll max_y = max(ps[k].second,ps[l].second);
                    
                    ll num = 0;
                    for (int aaaa = 0; aaaa < n; aaaa++) {
                        if(min_x <= ps[aaaa].first && ps[aaaa].first <=max_x && min_y<= ps[aaaa].second && ps[aaaa].second <= max_y){
                             num++;
                        }
                    }
                    
                    if(num>=K){
                        result = min(result,(ll)abs(ps[j].first - ps[i].first)*(ll)abs(ps[l].second - ps[k].second ));
                    }
                }
            }
        }
    }
    std::cout << result << std::endl;
}



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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repr(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<(int)(n);i++)
#define INF 99999999999999

    /*Solve*/

int main(){
    ll n;
    cin >> n;
    ll l[100010];
    rep(i,n){
        cin >> l[i];
    }
    sort(l,l+n,greater<>());
    ll sum=0;
    rep(i,n){
        if(i!=0){
            sum+=l[i];
        }
    }
    if(sum-l[0]>0){
        cout << "Yes" << endl;
    }else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    int a = 1000000;
    long long count=0;
    for(int B=min(a,N);B!=0;B--){
        for(int A=min(a/B*10,min(N,B));A!=0;A--){
            if(A*B<=N-1){
                if(A==B) count--;
                count += 2*A;
                break;
            }
        }
    }
    cout << count << endl;
    return 0;
} 

Measured memory_bytes: 3636
#include <stdio.h>
int main(){
  int a,i,count=0;
  int b[200];
  
  for(i=0;i<150;i++){
    b[i]=1;
  }
  for(i=0;i<3;i++){
    scanf("%d",&a);
    b[a]=0;
  }
  
  for(i=0;i<150;i++){
    if(b[i]==0) count++;
  }
  
  printf("%d",count);
  
}

Measured memory_bytes: 128