akhauriyash/Code-Regression huggingface dataset:
def calc_beauty_list(N, A):
    cumsum = [0 for _ in range(N)]
    cumsum[0] = A[0]
    for n in range(1, N):
        cumsum[n] = cumsum[n - 1] + A[n]
    beauty_list = [0 for _ in range(N * (N + 1) // 2)]
    index = 0
    for left in range(N):
        for right in range(left, N):
            beauty = cumsum[right]
            if left > 0:
                beauty -= cumsum[left - 1]
            beauty_list[index] = beauty
            index += 1
    return beauty_list


def main():
    MAX_BIT = 40
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    beauty_list = calc_beauty_list(N, A)
    # K個の論理積の最大値の計算
    #     2進表記して上位ビットから見ていく（高々数十ビット程度）。
    #     K個以上ビットが立っている桁に当たったら、ビットが立っていない数を消す。
    #         最終桁に行く前にK個になったら、それらの論理積を出して終了。
    #         最終桁まで行き、
    #             それまでK個以上のビットが立ってたことがないなら 0 が答え。
    #             そうでなければ、残っている中から適当にK個選んで論理積を出す。
    usable_flag = [1 for _ in range(N * (N + 1) // 2)]
    found_k_bit = False
    for shift in range(MAX_BIT - 1, -1, -1):
        cnt = len([b for b, u in zip(beauty_list, usable_flag) if u == 1 and (b >> shift & 1 == 1)])
        if cnt >= K:
            found_k_bit = True
            for n, b in enumerate(beauty_list):
                if b >> shift & 1 == 0:
                    usable_flag[n] = 0
        if cnt == K:
            found_k_bit = True
            break
    if not found_k_bit:
        print(0)
    else:
        ans = (1 << MAX_BIT) - 1
        cnt = 0
        for n, b in enumerate(beauty_list):
            if usable_flag[n] == 1 and cnt <= K:
                ans &= b
                cnt += 1
        print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 153360
(n, m) = [int(i) for i in input().split()]
A = []
b = []
for i in range(n):
    A.append([int(j) for j in input().split()])
 
for i in range(m):
    b.append(int(input()))
 
for i in range(n):
    s = 0
    for j in range(m):
        s += A[i][j] * b[j]
    print(s)

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

// 貪欲法
// この方法は完全ではないが一旦実装
int D;
int C[26];
int last[26];

int main() {
    cin >> D;
    for (int i = 0; i < 26; i++) {
        cin >> C[i];
        last[i] = 0;
    }

    // vector<vector<int>> S[][];
    int S[D][26];
    for (int i = 0; i < D; i++) {
        for (int j = 0; j < 26; j++) {
            cin >> S[i][j];
        }
    }

    long long sSum = 0;
    // それぞれの日の増加量を計算
    for (int i = 0; i < D; i++) {
        int maxAddS = 0;  // それぞれの日の満足度
        int nowSPoint = 0;  // 最大の値の場所を保存
        // 全種類の最大増加量を選択する
        for (int j = 0; j < 26; j++) {
            int nowSAdd = S[i][j];
            // 自分以外のマイナス量を確認
            for (int k = 0; k < 26; k++) {
                if (j == k) continue;
                if (last[k] == 0) continue;
                nowSAdd -= C[k] * (i - last[k]);
            }
            // maxAddS = max(nowSAdd, maxAddS);
            if (j == 0) {
                maxAddS = nowSAdd;
                nowSPoint == 0;
            } else {
                if (nowSAdd > maxAddS) {
                    maxAddS = nowSAdd;
                    nowSPoint = j;
                }
            }
        }
        cout << nowSPoint + 1 << endl;
        sSum += (long long)maxAddS;
    }
    // sSumを出力?
}


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

using namespace std;

int main(){
  string s, t;

  cin >> s >> t;
  
  if(s == t){
    cout << "Yes" << endl;
    return 0;
  }
  
  for(int i = 0; i < s.size() - 1; i++){
    string tmp (s);
    for(int j = 1; j < s.size(); j++){
      s[j] = tmp[j-1]; 
    }
    s[0] = tmp[tmp.size()-1];

    if(s == t){
      cout << "Yes" << endl;
      return 0;
    }
  }  

  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a,b,k,i,j;
	while(scanf("%d%d%d",&a,&b,&k)==3)
	{
		if(b-a<=k)
		{
			for(i=a;i<=b;i++)
			printf("%d\n",i);
		}
		else if((a+k)<=(b-k))
		{
			for(i=a;i<a+k;i++)
				printf("%d\n",i);
			for(j=b-k+1;j<=b;j++)
				printf("%d\n",j);
		}
		else
		{
			for(i=a;i<a+k;i++)
				printf("%d\n",i);
			for(j=a+k;j<=b;j++)
				printf("%d\n",j);
		}
	}
	return 0;
}

Measured memory_bytes: 128
# 単一視点最短経路, Dijkstra(ダイクストラ)のアルゴリズム
from collections import deque

n = int(input())
# グラフの作成
INF = float('inf')
M = [[INF]*n for _ in range(n)]
d = [INF]*n
for _ in range(n):
    u, k, *v = map(int, input().split())
    if k == 0:
        continue
    cnt = 0
    for _ in range(k):
        M[u][v[cnt]] = v[cnt+1]
        cnt += 2

# アルゴリズム部分
def djikstra(n, M, d):
    d[0] = 0
    color = ['W']*n
    color[0] = 'G'
    while True:
        mincost = INF
        u = -1
        for i in range(n):
            if mincost > d[i] and color[i] != 'B':
                u = i
                mincost = d[i]
        if u == -1:
            break

        color[u] = 'B'
        for v in range(n):
            if color[v] != 'B' and M[u][v] != INF:
                if d[v] > d[u]+M[u][v]:
                    d[v] = d[u]+M[u][v]
                    color[v] = 'G'
    return d

D = djikstra(n, M, d)
for i, c in enumerate(D):
    print(i, c)


Measured memory_bytes: 6116
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int main(){

    int n;
    cin >> n;
    if(n % 2 == 0){
        cout << (n/2)*(n/2) << endl;
    }else{
        cout << (n/2)*(n/2+1) << endl;
    }



    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <queue>
using namespace std;
struct data{
    int e,nx;
}a[200010];
int st[100010],cnt;
void make_al(int s,int e){a[++cnt]={e,st[s]},st[s]=cnt;}
long long s[100010];
int e[100010],chk[100010],flag=1;
void dfs(int p,int root){
    int i,mx;
    long long t=0,k;
    priority_queue<long long> q;
    chk[p]=1;
    if(e[p]==1)return;
    for(i=st[p];i;i=a[i].nx)if(!chk[a[i].e]){
        dfs(a[i].e,root);
        if(!flag)return;
        t+=s[a[i].e];
        q.push(s[a[i].e]);
    }
    k=t-s[p];
    if(p==root&&k!=s[p]){flag=0;return;}
    if(k<0||t<k*2){flag=0;return;}
    s[p]=t-k*2;
    if(q.top()>=k&&t-q.top()<k){flag=0;return;}
}
int main(){
    int i,n,x,y;
    scanf("%d",&n);
    for(i=1;i<=n;++i)scanf("%lld",s+i);
    if(n<3){puts(s[1]==s[2]?"YES":"NO");return 0;}
    for(i=1;i<n;++i){
        scanf("%d%d",&x,&y);
        make_al(x,y);
        make_al(y,x);
        ++e[x],++e[y];
    }
    if(e[1]>1)dfs(1,1);
    else dfs(a[st[1]].e,a[st[1]].e);
    puts(flag?"YES":"NO");
    return 0;
}


Measured memory_bytes: 10368
# ARC079C - Cat Snuke and a Voyage (ABC068C)
import sys
input = sys.stdin.readline

def main():
    n, m = map(int, input().rstrip().split())
    s, d = set(), set()
    for _ in range(m):
        a, b = map(int, input().rstrip().split())
        if a == 1:
            s.add(b)
        elif b == n:
            d.add(a)
    print("POSSIBLE" if s & d else "IMPOSSIBLE")


if __name__ == "__main__":
    main()

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

int main() {
  char a; 
  cin >> a;
  // ここにプログラムを追記
  if (a == 'a' || a == 'i' || a == 'u' || a == 'e' || a == 'o') {
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}


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

int main()
{
  int k, s, x, y;
  cin >> k >> s;
  int cnt = 0;
  
  for (x=0; x<=k; x++) {
    for (y=0; y<=k; y++) {
      if (s-x-y >= 0 && s-x-y <= k) cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
N,M,X,Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
flag = False
for i in range(X+1,Y+1):
    if max(x) < i and min(y) >= i:
        flag = True
        break
if flag:
    print("No War")
else:
    print("War")

Measured memory_bytes: 38384
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	char a[22];
while(scanf("%c",&a[0])!=-1)
{
for(int i=1;i<=19;i++)
scanf("%c",&a[i]);
for(int n=0;n<=4;n++)
printf("%c",a[n]);
printf("  ");

for(int m=6;m<=12;m++)
printf("%c",a[m]);
printf("  ");
for(int b=14;b<=18;b++)
printf("%c",a[b]);
printf(" \n");

}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
int main()
{
    int n;
    cin >> n;
    lli a[10005], b[10005];
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    lli sa = 0, sb = 0;
    rep(i, n) sa += a[i], sb += b[i];
    lli piyo = sb - sa;
    if (piyo < 0) {
        cout << "No" << endl;
    } else {
        lli ta = 0, tb = 0;
        rep(i, n)
        {
            if (a[i] < b[i]) {
                if ((b[i] - a[i]) & 1) {
                    tb += 1;
                    ta += (b[i] + 1 - a[i]) / 2;
                    b[i]++;
                    a[i] = b[i];
                } else {
                    ta += (b[i] - a[i]) / 2;
                    a[i] = b[i];
                }
            } else if (a[i] > b[i]) {
                tb += a[i] - b[i];
                b[i] = a[i];
            }
        }
        //cout << ta << " " << tb << " " << piyo << endl;
        if (ta <= piyo and tb <= piyo and 2 * (piyo - ta) == (piyo - tb)) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (int i = l; i < r; i++)
using namespace std;
typedef pair<int, int> P;
struct edge {
	int to, cost;
};
class dijkstra {
  private:
	int V;
	int d[100002];
	priority_queue<P, vector<P>, greater<>> que;

  public:
    dijkstra(int v, int s, vector<edge> G[]) {
        V = v;
        update(s, G);
    }

    void update(int s, vector<edge> G[]) {
        fill(d, d + V + 1, 100000000000ll);
        d[s] = 0;
        que.push(make_pair(0, s));
        while (!que.empty()) {
            P p = que.top();
            que.pop();
            int v = p.second;
            if (d[v] < p.first)
                continue;
            rep(i, G[v].size()) {
                edge e = G[v][i];
                if (d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    que.push(make_pair(d[e.to], e.to));
                }
            }
        }
    }

	int find(int e) {
		return d[e];
	}
};

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

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

bool prime(int a) {
	if (a == 1)
		return false;
	for (int i = 2; i * i <= a; i++) {
		if (a % i == 0)
			return false;
	}
	return true;
}

class Union_Find {
  private:
	vector<int> t, s;

  public:
	Union_Find(int max_length) {
		rep(i, max_length + 1) {
			t.push_back(i);
			s.push_back(1);
		}
	}

	void Union(int x, int y) {
		if (same(x, y))
			return;
		int tx = Find(x), ty = Find(y);
		if (s[tx] < s[ty]) {
			s[ty] += s[tx];
			t[tx] = ty;
		}
		else if (s[tx] > s[ty]) {
			s[tx] += s[ty];
			t[ty] = tx;
		}
		else if (tx > ty) {
			t[tx] = ty;
			s[ty] += s[tx];
		}
		else {
			t[ty] = tx;
			s[tx] += s[ty];
		}
	}

	int Find(int n) {
		if (t[n] == n)
			return n;
		else
			return t[n] = Find(t[n]);
	}

	bool same(int x, int y) {
		return Find(x) == Find(y);
	}

	int get_Size(int a) {
		return s[a];
	}
};

vector<int> primeFactorization(int n) {
	vector<int> re;
	int cnt = 2;
	while (n != 1) {
		if (n % cnt != 0) {
			cnt++;
			continue;
		}
		n /= cnt;
		re.push_back(cnt);
	}
	return re;
}

signed main(){
    char c,mc;
    cin>>mc;
    rep(i,3){
        cin>>c;
        if(c==mc){
            cout<<"Bad"<<endl;
            return 0;
        }
        mc=c;
    }
    cout<<"Good"<<endl;
}


Measured memory_bytes: 256
/*
#include <boost/functional/hash.hpp>
#include <boost/multiprecision/cpp_int.hpp>
typedef boost::multiprecision::cpp_int mlint;
*/
#include <bits/stdc++.h>
using namespace std;

#define debug 0
#define print(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define fcout(d) cout << fixed << setprecision(d)
#define each(i,v) for(auto i = begin(v); i != end(v); ++i)
#define reach(i,v) for(auto i = rbegin(v); i != rend(v); ++i)
#define urep(i,s,t) for(int i = (int)(s); i <= (int)(t); ++i)
#define drep(i,s,t) for(int i = (int)(s); i >= (int)(t); --i)
#define rep(i,n) urep(i,0,(n) - 1)
#define rep1(i,n) urep(i,1,(n))
#define rrep(i,n) drep(i,(n) - 1,0)
#define all(v) begin(v),end(v)
#define rall(v) rbegin(v),rend(v)
#define vct vector
#define prique priority_queue
#define l_bnd lower_bound
#define u_bnd upper_bound
#define rsz resize
#define ers erase
#define emp emplace
#define emf emplace_front
#define emb emplace_back
#define pof pop_front
#define pob pop_back
#define mkp make_pair
#define mkt make_tuple
#define fir first
#define sec second

typedef long long ll;
typedef double db;
typedef vct<vct<ll>> mat;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tiii;
typedef map<int,int> mpii;
typedef unordered_map<int,int> umpii;

template <class T, class U> ostream& operator << (ostream& s, pair<T,U> p) { return s << p.fir << " " << p.sec; }
template <class T> ostream& operator << (ostream& s, vct<T> v) { each(i,v) { if(i != begin(v)) s << " "; s << *i; } return s; }

auto esc = [](auto ret) { cout << ret << endl; exit(0); };
auto odd = [](auto x) { return x & 1; };
auto even = [](auto x) { return !odd(x); };
auto qceil = [](auto x, auto y) { return x > 0 ? (x - 1) / y + 1 :  x / y; };
auto parity = [](auto x, auto y) { return odd(x) ^ even(y); };
auto chmax = [](auto& m, auto x) { if(m < x) { m = x; return 1; } return 0; };
auto chmin = [](auto& m, auto x) { if(m > x) { m = x; return 1; } return 0; };
auto cmprs  = [](auto& v) {
    auto tmp = v;
    sort(all(tmp));
    tmp.erase(unique(all(tmp)),end(tmp));
    for(auto it = begin(v); it != end(v); ++it) *it = l_bnd(all(tmp),*it) - begin(tmp) + 1;
    return tmp.size() != v.size();
};

const int dir[8][2] = { {1,0},{0,1},{-1,0},{0,-1},{1,1},{-1,1},{-1,-1},{1,-1} };
const ll inf32 = (1 << 30) - 1;
const ll inf64 = (1LL << 62) - 1;
const ll mod = 1e9 + 7;
const db eps = 1e-15;



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

    int n,k;
    cin >> n >> k;
    int a[100001];
    rep(i,n) cin >> a[i];
    int s[100001];
    s[0] = 0;
    rep(i,n) {
        s[i + 1] = s[i] + a[i];
    }
    if(s[n] < k) esc(0);
    int ans = n;
    rep(i,n){
        if(s[n] - s[i] < k) break;
        chmin(ans,l_bnd(s + i,s + 1 + n,s[i] + k) - s - i);
    }
    esc(ans);
}



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

int main() {
    int h, w;

    cin >> h >> w;

    while (h != 0 || w != 0) {
        for (int i = 0; i < h; i++) {
            for (int s = 0; s < w; s++) {
                if (i % 2 == 0) {
                    if (s % 2 == 0) {
                        cout << "#";
                    } else {
                        cout << ".";
                    }
                } else {
                    if (s % 2 == 0) {
                        cout << ".";
                    } else {
                        cout << "#";
                    }
                }
            }
            cout << endl;
        }
        cout << endl;
        cin >> h >> w;
    }

    return 0;
}

Measured memory_bytes: 3012
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

int main(void){
	int N;
	cin >> N;
	vector<int> v(2*N);
	for(int i=0;i<2*N;i++)cin >> v[i];
	sort(ALL(v));
	ll ans = 0;
	for(int i=0;i<N;i++){
		ans += min(v[2*i],v[(2*i)+1]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
class Node:
    def __init__(self, data):
        self.data = data #ノードが持つ数値
        self.depth = None
        self.children = None
#解答 dfs…深さ優先探索
class Node:
  def __init__(self):
    self.parent = -1
    self.sibling = -1

def dfs(v, d = 0):
  G[v].depth, G[v].height = d, 0
  if G[v].left != -1:
    G[v].height = max(G[v].height, dfs(G[v].left, d + 1) + 1)
  if G[v].right != -1:
    G[v].height = max(G[v].height, dfs(G[v].right, d + 1) + 1)
  return G[v].height

N = int(input())
G = [Node() for _ in range(N)]
for _ in range(N):
  idx, *children = [int(x) for x in input().split()]
  G[idx].left, G[idx].right = children
  if G[idx].left != -1 and G[idx].right != -1:
    G[G[idx].left].sibling, G[G[idx].right].sibling = G[idx].right, G[idx].left #兄弟を設定
  if G[idx].left != -1 or G[idx].right != -1:
    G[idx].type = 'internal node'
  else:
    G[idx].type = 'leaf'
  for child in children:
    if child != -1:
      G[child].parent = idx

root = [i for i, x in enumerate(G) if x.parent == -1][0]
G[root].type = 'root'
dfs(root)

for i, node in enumerate(G):
    print('node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}'.format(i, node.parent, node.sibling, (node.left != -1) + (node.right != -1), node.depth, node.height, node.type))


Measured memory_bytes: 5620
#include<bits/stdc++.h>
using namespace std;
int n,cnt,c1,c2,a[100005],tot[100005];
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	tot[1]=1; cnt=1;
	for (int i=2;i<=n;i++){
		if (a[i]!=a[i-1])
			a[++cnt]=a[i];
		tot[cnt]++;
	}
	for (int i=cnt;i;i--){
		if (tot[i]>=4)
			if (!c1) c1=c2=a[i];
			else if (!c2) c2=a[i];
		if (tot[i]>=2)
			if (!c1) c1=a[i];
			else if (!c2) c2=a[i];
	}
	printf("%lld",1ll*c1*c2);
}

Measured memory_bytes: 1024
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll n,ans=1,s=1e18; cin>>n;
    vector<ll> a(n,0);
    rep(i,n) cin>>a[i];
    sort(al(a));
    rep(i,n){
        if(ans==-1) continue;
        if(ans==0) continue;
        if(a[i]>s/ans){
            ans=-1;
        }
        else{
            ans*=a[i];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4052
#include <iostream>
#include <string>
int main()
{
    std::string str;
    int i = 0;
    int j = 0;
    std::cin >> j >> i;
    std::cin.ignore();
    std::cin >> str;
    char c = str[i - 1];
    if (c == 'A') {
        str[i - 1] = 'a';
    }
    else if (c == 'B') { str[i - 1] = 'b'; }
    else str[i - 1] = 'c';
    std::cout << str;
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
L1 = [0]
for i in range(N):
    L1.append(L1[-1] + A[i])
L1.sort()
ans = 0
tmp = L1[0]
cnt = 1
for i in range(1,len(L1)):
    if tmp == L1[i]:
        cnt += 1
    else:
        ans += cnt*(cnt-1) // 2
        tmp = L1[i]
        cnt = 1
ans += cnt * (cnt - 1) // 2
print(ans)

Measured memory_bytes: 26720
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <map>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

int main(void)
{
    int N;
    cin >> N;

    vector<int> sw(100050);

    for (int i = 0; i < N; i++)
    {
        cin >> sw[i];
        sw[i]--;
    }

    int i = 0;
    int cnt = 0;
    bool ok = false;
    while (i != -1)
    {
        if (i == 1)
        {
            ok = true;
            break;
        }

        int tmp = i;
        i = sw[i];
        sw[tmp] = -1;
        cnt++;
    }

    if (ok)
    {
        cout << cnt << endl;
    }
    else
    {
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 640
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)
function root(uf::Array{Int,1},x)
	s=x
	while uf[s]!=s
		s=uf[s]
	end
	s
end
function same(uf::Array{Int,1},x,y)
	root(uf,x)==root(uf,y)?true:false
end
function unite(uf::Array{Int,1},x,y)
	l = root(uf,x)
	r = root(uf,y)
	if l < r
		uf[r] = l
	elseif l > r
		uf[l] = r
	end
end

function main()
	n,k,l = readline() |> split |> parseMap
	d = [i for i in 1:n]
	e = [i for i in 1:n]
	for i in 1:k
		p,q = readline() |> split |> parseMap
		unite(d,p,q)
	end
	for i in 1:l
		r,s = readline() |> split |> parseMap
		unite(e,r,s)
	end
	f = Dict{Tuple{Int,Int},Int}()
	for i in 1:n
		tp = (root(d,i),root(e,i))
		if haskey(f,tp)
			f[tp] += 1
		else
			f[tp] = 1
		end
	end
	for i in 1:n-1
		print(f[(root(d,i),root(e,i))], " ")
	end
	println(f[(root(d,n),root(e,n))])
end
main()


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

#define MAX 2000001
#define INF 2000000000

int h;

int parent(int i){
  return i / 2;
}

int left(int i){
  return 2 * i;
}

int right(int i){
  return 2 * i + 1;
}

int maxHeapify(int *A, int i){
  int l,r,largest,buf;
  l = left(i);
  r = right(i);

  if((l <= h) && (A[l] > A[i]))
    largest = l;
  else
    largest = i;
  
  if((r <= h) && (A[r] > A[largest]))
    largest = r;

  if(largest != i){
    buf = A[largest];
    A[largest] = A[i];
    A[i] = buf;
    maxHeapify(A,largest);
  }
    
}

void heapIncreaseKey(int *A,int i, int key){
  int buf;
  
  A[i] = key;
  while((i > 1) && (A[parent(i)] < A[i])){
    buf = A[parent(i)];
    A[parent(i)] = A[i];
    A[i] = buf;
    i = parent(i);
  }
}

void maxHeapInsert(int *A, int key){
  A[++h] = -INF;
  heapIncreaseKey(A,h,key);
}

int extractMax(int *A){
  int max;

  max = A[1];
  A[1] = A[h];
  h--;
  maxHeapify(A,1);
  return max;
}


int main(){
  int i,k,c[MAX];
  char com[20];

  h = 1;
  
  while(1){
    scanf("%s", com);
    if(com[0] == 'i'){
      scanf("%d",&k);
      maxHeapInsert(c,k);
    }
    else if(com[1] == 'x'){
      printf("%d\n",extractMax(c));
    }
    else if(com[1] == 'n'){
      break;
    }   
  }

  return 0;
}



Measured memory_bytes: 5772
#include <stdio.h>
int main (void){
  int a,b,c;
  int tmp;
  scanf("%d %d %d",&a,&b,&c);
  tmp=a;
  a=b;
  b=tmp;
  tmp=a;
  a=c;
  c=tmp;
  
  printf("%d %d %d",a,b,c);
  
  return 0;

}

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

const int N = 25;

int n;
int c[N], v[N];

int main() {

	FAST;

	cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> v[i];
	}
	for (int i = 1; i <= n; i ++) {
		cin >> c[i];
	}
	int ans = 0;
	for (int i = 1; i <= n; i ++) {
		if (v[i] - c[i] > 0) ans += (v[i] - c[i]);
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
import math

a, b, h, m = map(int, input().split())


tansin = 360 * h / 12 + 360 * m / 60 / 12
chosin = 360 * m / 60


sa = abs(chosin - tansin)
sa = min(360 - sa, sa)

sa = math.radians(sa)
nijo = a * a + b * b - 2 * a * b * math.cos(sa)
print(nijo ** 0.5)


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

s_len = len(s)
t_len = len(t)

dp = [[] * (t_len + 1)] * (s_len + 1)

for i in range(s_len + 1):
  dp[i] = [0] * (t_len + 1)


# 最長共通部分列問題（LCS）として計算
for i in range(s_len):
  for j in range(t_len):
    if s[i] == t[j]:
      # 文字が同じ場合はカウントアップ
      dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1)
    else:
      # 異なる場合は、1文字前のs or 1文字前のt から変化がないので、持ってくる
      dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1])
      dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j])
    

# 文字列生成
ans = ''
i = s_len
j = t_len

while(i > 0 and j > 0):
    
  if dp[i][j] == dp[i-1][j]:
    i -= 1
  elif dp[i][j] == dp[i][j-1]:
    j -= 1
  else:
    ans = s[i-1] + ans
    i -= 1
    j -= 1
    

print(ans)
# for i in range(s_len+1):
#   print(dp[i])


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

long long int gcd(long long int l, long long int r) {
	assert(l > 0 && r > 0);
	if (l > r)return gcd(r, l);
	else {
		const long long int num = r%l;
		if (num) {
			return gcd(l, num);
		}
		else {
			return l;
		}
	}
}
long long int lca(long long int l, long long int r) {
	return l / gcd(l, r)*r;
}
int main() {
	long long int N; cin >> N;
	long long int num = 100;
	while (N--) {
		num =num* 1.0499999999+1;
	}
	cout << num * 1000 << endl;
	return 0;
}

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

int main(){
	int n,m,x,y,war;
	int i,f,mem;
	
	scanf("%d %d %d %d",&n,&m,&x,&y);
	
	int wantx[n];
	int wanty[m];
	
	for(i=0;i<n;i++){
		scanf("%d",&wantx[i]);
	}
	for(i=0;i<m;i++){
		scanf("%d",&wanty[i]);
	}
	
	for(i=0;i<n;i++){
		for(f=i+1;f<n;f++){
			if(wantx[i]>wantx[f]){
				mem=wantx[i];
				wantx[i]=wantx[f];
				wantx[f]=mem;
			}
		}
	}
	
	for(i=0;i<m;i++){
		for(f=i+1;f<m;f++){
			if(wanty[i]>wanty[f]){
				mem=wanty[i];
				wanty[i]=wanty[f];
				wanty[f]=mem;
			}
		}
	}
	
	if(wantx[n-1]<wanty[0] && wantx[n-1]<y && wanty[0]>x && x<y)	printf("No War");
	else		printf("War");
	
	return 0;
}

Measured memory_bytes: 128
/*************************************************************************
    > File Name: test.cpp
    > Author: Akira 
    > Mail: qaq.febr2.qaq@gmail.com 
 ************************************************************************/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <ctime>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define Sqr(a) ((a)*(a))
using namespace std;

#define MaxN 100000
#define MaxM MaxN*10
#define INF 0x3f3f3f3f
#define bug cout<<88888888<<endl;
#define MIN(x,y) (x<y?x:y)
#define MAX(x,y) (x>y?x:y)

LL A[MaxN];
LL B[MaxN];
int N;

int main()
{
    while(~scanf("%d", &N))
    {
        for(int i=1;i<=N;i++)
        {
            scanf("%lld%lld", &A[i], &B[i] );
        }
        LL tmp = 0;
        for(int i=N;i>0;i--)
        {
            if(A[i]==0) continue;
            A[i] += tmp;
            if(A[i]<B[i])
            {
                tmp+=B[i]-A[i];
            }
            else if(A[i]%B[i] == 0) continue;
            else
            {
                LL cnt = A[i]%B[i];
                tmp += (B[i]-cnt);
            }
            //cout << tmp << endl;
        }
        printf("%lld\n", tmp);
    }
    //system("pause");
}

Measured memory_bytes: 1792
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#define pan(i,n) for(int i=0;i<n;i++)
#define ll long long int
using namespace std;

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if( (c>a && c<b) || (c<a && c>b) ){
    	cout<<"Yes";
    }
    else{cout<<"No";}
}


Measured memory_bytes: 256
A,B = list(map(int, input().split()))
#B = list(map(int, input().split()))

data = [A*B*1, A*B*2, A*B*3]
odd = False

for i in range(3):
    if data[i]%2==1:
        odd = True


if odd:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
function main(input) 
{
    input = input.split(" ");
    var comb = input[0] + input[1];
    var a = parseInt(comb, 10);
    var x = Math.sqrt(a);
    if (Number.isInteger(x))
    {
        console.log("Yes");
    }
    else
    {
        console.log("No");
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main() {
  int N, A;
  cin >> N >> A;

  int Fractions;
  Fractions = N % 500;
  
  if (Fractions <= A) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <utility>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF=1<<29;

vector<P> table[100001]; //隣接リスト to,cost
ll d[100001]; //S→Gのcost
bool used[100001];
priority_queue<P> que;

void dijkstra(ll s){
	fill(d,d+100001,LLONG_MAX);
	fill(used,used+100001,false);
	d[s]=0;
	que.push(P(s,0));

	while(!que.empty()){

		ll Rto=que.top().first, Rcost=que.top().second; //中継点(Relay),S→Rのcost
		que.pop();
		if(used[Rto]) continue;
		if(Rcost > d[Rto]) continue;
		used[Rto]=true;

		for(int i=0;i<table[Rto].size();i++){
			ll to=table[Rto][i].first, cost=table[Rto][i].second; //目的地(G),R→Gのcost
			if(d[to] > cost + Rcost){
				d[to] = cost + Rcost;
				que.push( P(to,d[to]) );
			}
		}

	}
	return;
}

int main(){
	int N;
	cin>>N;
	for(int i=0;i<N-1;i++){
		ll x,y,z;
		cin>>x>>y>>z;
		table[x].push_back(P(y,z));
		table[y].push_back(P(x,z));
	}
	dijkstra(1);
	for(int i=1;i<=N;i++){
		//cout<<d[i];
		if(d[i]%2==0) cout<<0<<endl;
		else cout<<1<<endl;
	}
	return 0;
}

Measured memory_bytes: 7296
n,m,x = map(int,input().split())
C = list()
A = list()
for i in range(n):
    temp = list(map(int,input().split()))
    C.append(temp[0])
    A.append(temp[1:])

maxnum = 10000000000
def dfs(a,cost,i):
    if min(a) >= x:
        return cost
    elif i == n:
        return maxnum
    
    getA = [x+y for (x,y) in zip(a,A[i])]
    
    return min(dfs(a,cost,i+1), dfs(getA,cost+C[i],i+1))

ans = dfs([0]*m,0,0)

if ans == maxnum:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9244
import java.util.*;

class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        if(N%K == 0){
            System.out.println("0");
        }else{
            System.out.println("1");
        }
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <algorithm>
#include <unordered_map>

using namespace std;

int main()
{
	const int MAX_N = 100000;

	int n;
	cin >> n;
	unordered_map<string, int> map;
	for (int i = 0; i < n; i++)
	{
		string temp;
		cin >> temp;
		sort(temp.begin(), temp.end());
		map[temp]+=1;
	}
	
	long long answer = 0;

	for (auto e : map)
	{
		int val = e.second;
		answer += (long long)val * (val -1) / 2;
	}

	std::cout << answer;

	return 0;
}



Measured memory_bytes: 10660
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        try {
            int price = Integer.parseInt(reader.readLine());
            reader.close();
            int num1000 = price / 1000; // 必要な1000円の枚数-1
            if (price % 1000 == 0) {
                // 価格が1000円で割り切れるときはお釣り０
                System.out.println("0");
            } else {
                System.out.println(1000 * (num1000 + 1) - price);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

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

int main(){
  int i,j,cnt=0;
  int n;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++)cin>>a[i];
  int p1=0,p2=0,p4=0;
  for(i=0;i<n;i++){
    if(a[i]%2==1)p1++;
    else if(a[i]%4==2)p2++;
    else p4++;
  }
  if(p4+1<p1){
    cout<<"No"<<endl;
  }else if(p4+1==p1 && p2!=0){
    cout<<"No"<<endl;
  }else cout<<"Yes"<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define bye ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD (ll)(1e9+7)

ll n,k,a[100100],fac[100100];

ll faspo(ll a,ll po){
    if(!po)
        return 1;
    ll mul = faspo(a,po/2);
    mul = (mul*mul)%MOD;
    if(po&1)
        mul = (mul*a)%MOD;
    return mul;
}

ll c(ll x,ll y){
    if(y>x)
        return 0;
    ll div = faspo((fac[y]*fac[x-y])%MOD,MOD-2)%MOD;
    ll ret = fac[x];
    return (ret*div)%MOD;
}

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

    for(int i=0;i<n;i++)
        cin >> a[i];
    sort(a,a+n);

    fac[0]=1;
    for(int i=1;i<=100000;i++){
        fac[i] = fac[i-1]*i;
        fac[i]%=MOD;
    }

    ll mx = 0;
    ll mn = 0;
    for(int i=0;i<n;i++){
        ll add = c(i,k-1);
        add %= MOD;
        mx += add*a[i];
        mx%=MOD;
        add = c(n-i-1,k-1);
        add %= MOD;
        mn += add*a[i];
        mn%=MOD;
    }

    cout << (mx - mn + MOD)%MOD<< endl;
    return 0;
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrepa(i,a,n) for(int i=(n)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

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

    //if(n%2==0)cout<<0.5<<endl;
    //else cout<<(((double)n+1)/2)/n<<endl;
    
    double ans = (double(n+n%2)/2)/n;
    printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    double c[101][101],p[101][51],notp[101][51];
    double t[101],v[101],ans[101];
    int main()
    {
        int n,m,i,j,k,ii;
        double l,sum;
        scanf("%d%d%lf",&n,&m,&l);
        c[0][0]=1;
        for(i=1;i<=100;++i)
        {
            c[i][0]=1;
            for(j=1;j<=i;++j)
                c[i][j]=c[i-1][j-1]+c[i-1][j];
        }
        //cout <<c[100][50]<<endl;
        for(i=0;i<n;++i)
        {
            scanf("%lf%lf%lf",&p[i][1],&t[i],&v[i]);
            p[i][1]/=100;
            notp[i][0]=p[i][0]=1;
            notp[i][1]=1-p[i][1];
            for(j=2;j<=m;++j)
                p[i][j]=p[i][j-1]*p[i][1],notp[i][j]=notp[i][j-1]*notp[i][1];
        }
        double sp,ap,at,tim;
        for(ii=0;ii<n;++ii)
        {
            ans[ii]=0;
            for(i=0;i<=m;++i)
            {
                sp=c[m][i]*p[ii][i]*notp[ii][m-i];
                tim=i*t[ii]+l/v[ii];
                //cout <<ii<<" "<<i<<" "<<sp<<" "<<tim<<endl;
                for(j=0;j<n;++j)
                {
                    if(j==ii)continue;
                    sum=0;
                    for(k=0;k<=m;++k)
                    {
                        ap=c[m][k]*p[j][k]*notp[j][m-k];
                        at=k*t[j]+l/v[j];
                        if(at>tim)
                        {
                            sum+=ap;
                        }
                    }
                    sp*=sum;
                }
                ans[ii]+=sp;
            }
        }
        //cout<<c[50][20]<<" "<<p[2][20]<<" "<<p[2][30]<<" "<<c[50][20]*p[2][20]*p[2][30]<<endl;
        for(i=0;i<n;++i)
        printf("%.5f\n",ans[i]);
        return 0;
    }

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

int main()
{
    string N;
    int K;
    cin >> N >> K;
    vector<int> n(N.size());
    for (int i = 0; i < N.size(); i++)
    {
        n[i] = N[i] - '0';
    }
    long long ans = 0;
    if (K == 1)
    {
        ans += n.front();
        ans += 9 * (n.size() - 1);
    }
    if (K == 2)
    {
        ans += (n.front() - 1) * 9 * (n.size() - 1);
        for (long long i = 1; i < n.size(); i++)
        {
            if (n[i] > 0)
            {
                ans += n[i];
                ans += 9 * (n.size() - (i + 1));
                break;
            }
        }
        ans += 9 * 9 * ((n.size() - 1) * (n.size() - 2) / 2);
    }
    if (K == 3)
    {
        ans += (n.front() - 1) * 9 * 9 * ((n.size() - 1) * (n.size() - 2) / 2);
        for (long long i = 1; i < n.size(); i++)
        {
            if (n[i] > 0)
            {
                ans += (n[i] - 1) * 9 * (n.size() - (i + 1));
                ans += 9 * 9 * ((n.size() - (i + 1)) * (n.size() - (i + 2)) / 2);
                for (long long j = i + 1; j < n.size(); j++)
                {
                    if (n[j] > 0)
                    {
                        ans += n[j];
                        ans += 9 * (n.size() - (j + 1));
                        break;
                    }
                }
                break;
            }
        }
        ans += 9 * 9 * 9 * ((n.size() - 1) * (n.size() - 2) * (n.size() - 3) / 6);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod107 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)
#define Graph vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(), v.end()
#define PI acos(-1)
#define inf 1000000321
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main(){
    int N;
    cin >> N;
    vector<ll> L(N);
    for(int i = 0;i < N;i++){
        cin >> L[i];
    }
    sort(all(L));
    ll ans = 0;
    for(int a = 0;a < N;a++){
        for(int b = a+1;b < N;b++){
            int k = lower_bound(all(L),L[a] + L[b]) - L.begin();
            ans += max(k - b-1,0);            
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3608
N, K = map(int,input().split())
ans = 0
for b in range(K+1, N+1):
    k = (N+1) // b
    temp = (b - K) * k + max(0, N - (K + b * k) + 1)
    if K == 0:
        temp -= 1
    ans += temp
print(ans)

Measured memory_bytes: 3060
N ,K = input().split()
N = int(N)
K = int(K)

d = {}
for i  in range(N):
    if i+1 not in d:
        d.setdefault(str(i+1) , 0)

while(K):
    tmp = input()
    data = input().split()

    for i in range(int(tmp)):
        if data[i] in d:
            d[data[i]]+=1
    
    K-=1

count = 0 
for k,v in d.items():
    if v == 0 :
        count+=1
print(count)



Measured memory_bytes: 9212
#include <stdio.h>
int main (void){
    int a;
    int b;
   if(0<a<=12){
  int a1=  scanf("%d",&a);
   }if(0<b<32){
  int b1= scanf("%d",&b);
   }
 //  if(scanf("%d %d",&a,&b)!=2||a<1||a>12||b<1||b>31){
     //  printf("0\n");

//       exit(1);
 //  }
  
    int count=0;
    if(a<=b){
   count=a;
    
    }else{
      count=a-1;
     

    }    
    printf("%d",count);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(c) c.begin(),c.end()
#define init(c) memset(c,0,sizeof c)
typedef long long ll;
const int N=20000005;
int n,k,x,t,a,b,y,c;
string s;
vector<pair<int,int>>v;
int main(){

	cin >> x >> y >> a >> b >> c;
	for(int i =0,z;i<a;i++){
		cin >> z;
		v.push_back({z,0});
	}
	for(int i =0,z;i<b;i++){
		cin >> z;
		v.push_back({z,1});
	}
	for(int i =0,z;i<c;i++){
		cin >> z;
		v.push_back({z,2});
	}
	sort(all(v));
	reverse(all(v));
	vector<int>clr;
	ll sum=0;
	for(int i =0;i<v.size();i++){

		if(v[i].second == 2){
			clr.push_back(v[i].first);
		}else{
			if(x+y <= clr.size())break;
			if(v[i].second == 0&&x){
				x--;
				sum+=v[i].first;
			}else if(y&&v[i].second==1){
				y--;
				sum+=v[i].first;
			}
		}
	}

	int tmp = x+y;
	for(int i =0;i<clr.size()&&tmp;i++){

		sum+=clr[i];
		tmp--;
	}	
	cout << sum<<endl;


	return 0;
}

Measured memory_bytes: 6384
// ------------------------------------
// Date:2018/ 3/31
// Problem:Ice Tea Store 019.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

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

  long double a[3], d;
  cin >> a[0] >> a[1] >> a[2] >> d;

  a[0] *= 4.0;
  a[1] *= 2.0;
  d /= 2.0;
  CIN(N);

  
  long double t = INF;
  EACH(ai, a)
    t = min(t, ai);

  debug(t);
  ll ans = 0ll;
  if (N & 1) {
    // OK(true);
    // odd number
    if (t <= d) ans = N * t;
    else ans = (int)(N / 2) * d * 2 + t;
  } else {
    // OK(false);
    // even number
    if (t <= d) ans = N * t;
    else ans = N * d;
  }

  cout << ans << endl;

  return 0;
}



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

int main() {
	int n, x;
	cin >> n >> x;
	vector<int> m(n);
	for (int i = 0; i < n; i++)
		cin >> m[i];
	int sum = 0, min = 1000;
	for (int i = 0; i < n; i++) {
		sum += m[i];
		if (min > m[i])
			min = m[i];
	}
	x -= sum;
	cout << n + x / min << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
//#include <string>
#include <algorithm>
//#include <functional>
//#include <array>
#include <math.h>
using namespace std;
typedef long long ll;

int main() {
	int a,b;
	cin >> a >> b;
	int res = 0;
	int cnt = 0;
	for (int i = a; i <= b; ++i) {
		if ((i/10000) == (i%10)){
			if ((i / 1000 - i / 10000 * 10) == (i / 10 - i / 100 * 10)) {
				res++;
			}
		}
	}
	
	cout << res << endl;
	return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//#pragma GCC target("popcnt")  //https://godbolt.org/z/yQv94Y 

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

#define INF 1e9
#define pi 3.141592653589
#define e 2.718281828459
#define phi 1.618033988749
#define MOD 1000000007
#define printarr(arr,n){for(int i=0;i<(n);i++){cout<<arr[i]<<" ";}cout<<endl;}
#define foreach(it , l) for(auto it = l.begin(); it != l.end(); ++it)
#define xlr8 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll> >
#define rev_sort(a) sort(a.rbegin(),a.rend());

struct Timer
{
    chrono::time_point<chrono::high_resolution_clock> start , end;
    chrono:: duration<float> dur;
    Timer()
    {
        start = chrono::high_resolution_clock::now();
    }
    ~Timer()
    {
        end = chrono::high_resolution_clock::now();
        dur = end - start;
        cout<<"\nTime Elapsed : " <<dur.count() << " s\n";
    }
};

ll sum() {return 0;}
template<typename T, typename... Args>
T sum(T a , Args... args)   {return a + sum(args...); }

//76149
template<int D, typename T> 
struct Vec : public vector<Vec<D - 1, T>> {
  static_assert(D >= 1, "Vector dimension must be greater than zero!");
  template<typename... Args>
  Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {
  }
};
template<typename T>
struct Vec<1, T> : public vector<T> {
  Vec(int n = 0, T val = T()) : vector<T>(n, val) {
  }
};



int main()
{
    xlr8;
    int testCases  = 1;
    //cin>>testCases;
    while (testCases--)
    {
        int n;
        cin>>n;
        map<int ,string> m;
        m[2] = m[4] = m[5] = m[7] = m[9] = "hon";
        m[0] = m[1] = m[6] = m[8] = "pon";
        m[3] = "bon";
        cout<<m[n%10]<<"\n";  
    }
    
    

    

}


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

using namespace std;
using ll = long long;

class UnionFind{
  private:
	vector<int> data;

  public:
	UnionFind(int n) : data(n,-1) {}
	int root(int i) { return data[i] < 0 ? i : data[i] = root(data[i]); }
	int size(int i) { return -data[root(i)]; }
	bool same(int x, int y) {return root(x) == root(y); }
	bool connected() {return size(0) == (int)data.size(); }

	bool unit(int i,int j){
		i = root(i);
		j = root(j);
		if(i != j){
			data[i] += data[j];
			data[j] = i;
		}
		return i != j;
	}
};

int main()
{
	int n, q; cin >> n >> q;
	UnionFind tree(n);
	for(int i = 0; i < q; i++) {
		int a, b, c; cin >> a >> b >> c;
		if(a) {
			cout << tree.same(b, c) << endl;
		} else {
			tree.unit(b, c);
		}
	}
}

Measured memory_bytes: 3836
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    long long N,i;
    cin>>N;
    long long d[N];
    for(i=0;i<N;i++){
        cin>>d[i];
    }
    sort(d,d+N);
    N/=2;
    cout<<d[N]-d[N-1]<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
char a[10],b[10];
int main ()
{
	int i,p=2,s=0;
	cin>>a>>b;
	for(i=0;i<3;i++)
	{
		if(a[p]==b[i])
		    s++;
		p--;
	}
	if(s==3)
	    cout<<"YES";
	else
	    cout<<"NO";
}

Measured memory_bytes: 256
import sys
from itertools import combinations
sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

# 入力を整数に変換して受け取る
def input_int():
    return int(input())

def map_int_input():
    return map(int, input())

MII = map_int_input

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

def MII_to_index():
    return map(to_index, input())

def MII_split_to_index():
    return map(to_index, input().split())

# 入力全てを整数に変換したものの配列を受け取る
def list_int_inputs():
    return list(map(int, input()))

LII = list_int_inputs

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

# 2次元リスト化
def LII_2D(rows_number):
    return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number):
    return [LII_split() for _ in range(rows_number)]

N, K = MII_split()

count = 0
p_min_sum = 0
p_max_sum = 0
for num_nums in range(K, N + 2):
    # 実は，すべての和を実際に計算する必要はない．
    # M個の数字を選んだ場合，和の最小値は小さい方からM個，最大値は大きい方からM個だが，
    # 最小値と最大値の間の数は ---全て作ることができる---
    # 和は和の公式か尺取法か累積和を使って求める
    # --- 尺取法？ ---
    if num_nums == K:
        p_min_sum = sum(range(num_nums))
        p_max_sum = sum(range(N - num_nums + 1, N + 1))
    else:
        p_min_sum += num_nums - 1
        p_max_sum += N - num_nums + 1

    # （等差数列の）和の公式
    # p_min_sum = num_nums * (num_nums - 1) // 2
    # p_max_sum = num_nums * (2 * N - num_nums + 1) // 2
    #
    count += p_max_sum - p_min_sum + 1

    # すべての和の計算（TLE）
    # tmp_nums = []
    # for n in combinations(range(0, N + 1), num_nums):
    #     s = sum(n)
    #     tmp_nums.append(s)
    # count += len(set(tmp_nums))

print(int(count % (1e9 + 7)))

Measured memory_bytes: 9268
N = int(input())
if N % 2:
    print(0)
    exit()
ans = 0
tmp = 10
while N >= tmp:
    ans += N//tmp
    tmp *= 10
tmp = 50
tmp_2 = 100
while N >= tmp:
    ans += N//tmp - N//tmp_2
    tmp *= 5
    tmp_2 *= 10
print(ans)
ans = 0

Measured memory_bytes: 9184
// AOJ 0329: Bilateral Trade
// 2017.8.26 bal4u@uu
// 2017.11.14

#include <stdio.h>

#define MAX 200000

#define HASHSIZ 370003LL
#define BASE 200000000000001LL        // -200,000 x 10^9
typedef struct { int i; long long s; } HASH;
HASH hash[HASHSIZ+2], *hashend = hash+HASHSIZ;

int insert(int i, long long s)
{
    HASH *p;
    s += BASE;
    p = hash + s % HASHSIZ;
    while (p->s) {
        if (p->s == s) return p->i;
        if (++p == hashend) p = hash;
    }
    p->s = s, p->i = i;
    return -1;
}

char buf[20], *p;
int getint()
{
	int n = 0;
	if (*p == '-') {
		p++; while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
		return -n;
	}
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int main()
{
//  int N, d;
	int N;
    int i, k, max;
    long long s0, s;

//	memset(hash, 0, sizeof(hash));
//  scanf("%d", &N);
	fgets(p=buf, 20, stdin), N = getint();
    insert(0, 0);
    for (max = 0, s0 = 0, i = 1; i <= N; i++, s0 = s) {
//      scanf("%d", &d), s = s0 + d;
		fgets(p=buf, 20, stdin), s = s0 + getint();
        if ((k = insert(i, s)) >= 0) {
            if (i - k > max) max = i - k;
        }
    }
    printf("%d\n", max);
    return 0;
}

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

#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ll long long
#define nl '\n'
#define deb(x) cerr<<#x" = "<<x<<nl
#define in() ( { int a ; scanf("%d",&a); a; } )

const int N = 3e5 + 9;
const int mod = 1e9 + 7;


int32_t main()
{
    int n=in();
    vector<int> a(n), b(n), v;
    for(auto &x: a) cin>>x;
    for(auto &x: b) cin>>x;
    for(int i=1; i<=n; i++) v.eb(i);
    int ca, cb, cnt=0;
    do{
        cnt++;
        if(v==a) ca=cnt;
        if(v==b) cb=cnt;
    }while(next_permutation(v.begin(), v.end()));
    cout<<abs(ca-cb)<<nl;
    return 0;
}


Measured memory_bytes: 256