akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <iterator>

using namespace std;

#if 1
#define PRINT(x) { cout << #x << ": " << (x) << endl; }
#define PRINT_CONTAINER(x)  { cout << #x << ": ";                       \
        for (size_t ix = 0; ix < (x).size(); ++ix) cout << (x)[ix] << ", "; \
        cout << endl; }
#else
#define PRINT(x)
#define PRINT_CONTAINER(x)
#endif

int main(int argc, char *argv[])
{
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    if (a + b == c + d)
        puts("Balanced");
    else if (a + b < c + d)
        puts("Right");
    else
        puts("Left");
}


Measured memory_bytes: 256
/**
 * Title:
 * Url:
 */
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<numeric>
#include<functional>
#include<sstream>
#include<iomanip>
#include<queue>

using namespace std;

#define ll long long

int main() {
    int n; cin >> n;
    vector<vector<pair<int, int>>> G(n+1, vector<pair<int, int>>());
    for(int i=0; i<n-1; i++) {
        int ui, vi, wi; cin >> ui >> vi >> wi;
        G[ui].push_back(make_pair(vi, wi));
        G[vi].push_back(make_pair(ui, wi));
    }

    vector<int> color(n+1, 0);

    queue<pair<int, int>> q;

    // to, from
    color[1] = 0;
    q.push(make_pair(1, 0));
    while(!q.empty()) {
        pair<int, int> vi = q.front();
        q.pop();
        for(auto v:G[vi.first]) {
            if(v.first==vi.second) continue;
            if(v.second%2==0) {
                color[v.first] = color[vi.first];
            } else {
                color[v.first] = (color[vi.first]+1)%2;
            }
            q.push(make_pair(v.first, vi.first));
        }
        
    }

    for(int i=1; i<=n; i++) cout << color[i] << endl;

    return 0;
}


Measured memory_bytes: 6784
import sys
sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline  # 文字列読み込む時はこっち
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(readline())


def ints(): return list(map(int, readline().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, readline().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, readline().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, readline().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce
from math import gcd


def lcm(a, b):
    # 最小公倍数
    g = gcd(a, b)
    return a // g * b


N = a_int()
A = ints()
B = [0] * N
for a in A:
    B[0] += a
    B[0] %= MOD
for i in range(1, N):
    B[i] = B[i - 1] - A[i - 1]
    B[i] %= MOD

ans = 0
for i in range(N - 1):
    ans += A[i] * B[i + 1] % MOD
print(ans % MOD)


Measured memory_bytes: 91740
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    a=STR()
    b=STR()
    c=STR()
    print(a[0]+b[1]+c[2])
if __name__ == '__main__':
    do()

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

#define endl '\n'
typedef long double ld;
ld eps = 1e-6;

struct point{
    ld x,y,c;
    point(ld x=0, ld y=0) : x(x), y(y){}
    point operator - () const{ return point(-x, -y);}
    point& operator += (const point& o){ x += o.x; y += o.y; return *this;}
    point operator + (const point& o) const{ return point(x, y) += o;}
    point& operator -= (const point& o){ x -= o.x; y -= o.y; return *this;}
    point operator - (const point& o) const{ return point(x, y) -= o;}
    point& operator /= (const ld k){ x /= k; y /= k; return *this;}
    point operator / (const ld k){ return point(x, y) /= k;}
    point r90cw(){ return point(y, -x);}
    point r90ccw(){ return point(-y, x);}
    ld dist(point o){ return sqrt((o.x - x)*(o.x - x) + (o.y - y)*(o.y - y));}
};

point operator * (const ld k, const point& p){ return point(p.x*k, p.y*k);}
point operator * (const point& p, const ld k){ return point(p.x*k, p.y*k);}

struct circle{
    point center; ld r;
    circle (point c = point(0, 0), ld rr = 0) : center(c), r(rr) {}
    bool intersect(circle o){
        return center.dist(o.center) <= r + o.r && center.dist(o.center) >= fabs(r - o.r);
    }
    vector<point> intersection(circle o){
        vector<point> ans;
        ld d = center.dist(o.center), R = o.r;
        if (d > r + R || d < fabs(r - R)) return ans;
        ld x = (d*d - R*R + r*r)/(2*d*r);
        ld y = r*sqrt(1 - x*x);
        point middle = center + (o.center - center)*( (r*x) / d);
        point vdif = (o.center - center).r90cw()*(y / d);
        ans.push_back(middle + vdif); ans.push_back(middle - vdif);
        return ans;
    }
};

int n,k;
int const N = 61;
point pts[N];

bool check(ld T){
    circle a[N];
    for (int i=0; i<n; i++){
        a[i] = circle(pts[i], T / pts[i].c);
    }

    vector<point> temp;
    for (int i=0; i<n; i++){
        for (int j=0; j<n; j++){
            if (j == i) temp.push_back(a[i].center);
            else{
                vector<point> inter = a[i].intersection(a[j]);
                for (int k=0; k<inter.size(); k++) temp.push_back(inter[k]);
            }
        }
    }
    for (int p=0; p<temp.size(); p++){
        int cont = 0;
        for (int i=0; i<n; i++){
            if (a[i].center.dist(temp[p]) <= a[i].r + 1e-7) cont++;
            if (cont >= k) return true;
        }
    }
    return false;
}

ld bb(){
    ld l = 0, r = 300000;
    while( (r - l)/r > eps && r - l > eps){
        ld m = (l + r) * 0.5;
        if (check(m)) r = m;
        else l = m;
    }
    return (l + r) * 0.5;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    for (int i=0; i<n; i++){
        cin >> pts[i].x >> pts[i].y >> pts[i].c;
    }
    if (k == 1) cout << "0.0\n";
    else cout << fixed << setprecision(9) << bb() << endl;
}

Measured memory_bytes: 692
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

string s,t;

int main () {
    cin >> s >> t;

    vector<string> ans;

    REP(i, s.size()) {
        bool match = true;
        string str = s;
        REP(j, t.size()) {
            if(i+j < s.size() && (s[i+j] == t[j] || s[i+j]=='?')) {
                str[i+j] = t[j];
            } else {
                match = false;
            }
        }
        
        replace(str.begin(), str.end(), '?', 'a');
        if(match) {
            ans.push_back(str);
        }
    }

    if(ans.size() == 0) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    sort(ans.begin(), ans.end());

    cout << ans[0] << endl;
}

 


Measured memory_bytes: 256
import java.io.*;
  
public class Main {
    public static void main(String[] args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        int x = Integer.parseInt(str);
        int h = x / 3600;
        int m = (x % 3600) / 60;
        int s = (x % 3600) % 60;
        System.out.println(h + ":" + m + ":" + s);
    }
}

Measured memory_bytes: 24220
#include<cstdio>
#include<iostream>
#include<cstring>
#include<utility>
#include <vector>
using namespace std;
typedef pair<int,int>P;
const int MAXN=2e6+9;
const int MAXNN=5e2+9;
int query[MAXNN][MAXNN];
int answer[MAXNN][MAXNN];
signed main()
{
    int N,M,Q;
    scanf("%d%d%d",&N,&M,&Q);
    for(int i=0; i<M; ++i)
    {
        int l,r;
        scanf("%d%d",&l,&r);
        query[l][r]++;
    }
    for(int i=0; i<Q; ++i)
    {
        int ans=0;
        int l,r;
        scanf("%d%d",&l,&r);
        if(answer[l][r])
        {
            printf("%d\n",answer[l][r]);
            continue;
        }
        else
        {
            for(int j=l; j<=r; ++j)
            {
                for(int k=j; k<=r; ++k)
                {
                    ans+=query[j][k];
                }
            }
            answer[l][r]=ans;
            printf("%d\n",ans);
        }
    }
    return 0;
}


Measured memory_bytes: 2816
// AOJ 1565 Squid Ink
// 2018.2.16 bal4u

#include <stdio.h>
#include <string.h>

#define QMAX 10000
typedef struct { char r, c; int t; } QUE;
QUE que[QMAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;
	QUE qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t < que[i].t) min = l; else min = i;
	if (r < qsize && que[r].t < que[min].t) min = r;
	if (min != i) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		min_heapify(min);
	}
}

void deq()
{
//	if (qsize == 0) return 0;
//	*n = que[0].node, *t = que[0].t, *c = que[0].c;
	que[0] = que[--qsize];
	min_heapify(0);
}

void enq(char r, char c, int t)
{
	int i, min;
	QUE qt;

	i = qsize++;
	que[i].r = r, que[i].c = c, que[i].t = t;
	while (i > 0 && que[min = PARENT(i)].t > que[i].t) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		i = min;
	}
}

#define INF  0x10101010
char map[33][33];
int dist[33][33];
int mv[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};

int main() 
{
	int R, C, i, j, r, c, nr, nc, d;
	int sr, sc, gr, gc;
	char buf[10];

	fgets(buf, 10, stdin), sscanf(buf, "%d%d", &R, &C);
	sr = gr = -1;
	for (r = 0; r < R; r++) {
		fgets(map[r], 33, stdin);
		if (sr >= 0 && gr >= 0) continue;
		for (c = 0; c < C; c++) {
			if      (map[r][c] == 'S') map[r][c] = '.', sr = r, sc = c;
			else if (map[r][c] == 'G') map[r][c] = '.', gr = r, gc = c;
		}
	}

	memset(dist, INF, sizeof(dist));
	qsize = 0;
	enq(sr, sc, 0), dist[sr][sc] = 0;
	while (qsize) {
		r = que[0].r, c = que[0].c, deq();
		d = dist[r][c];

		if (r == gr && c == gc) break;

		for (i = 0; i < 4; i++) {
			nr = r + mv[i][0], nc = c + mv[i][1];
			if (nr < 0 || nr >= R || nc < 0 || nc >= C) continue;
			if (map[nr][nc] == 'o') {
				if (dist[nr][nc] > d + 1) dist[nr][nc] = d + 1, enq(nr, nc, d+1);
			} else if (map[nr][nc] == '.') {
				if (dist[nr][nc] > d + 2) dist[nr][nc] = d + 2, enq(nr, nc, d+2);
			}
		}

		for (i = 0; i < 4; i++) {
			nr = r, nc = c;
			for (j = 0; j < 3; j++) {
				nr += mv[i][0], nc += mv[i][1];
				if (nr < 0 || nr >= R || nc < 0 || nc >= C) continue;
				if (map[nr][nc] == '#') break;
				if (dist[nr][nc] > d+3+j) {
					dist[nr][nc] = d+3+j, enq(nr, nc, d+3+j);
				}
			}
		}
	}
	printf("%d\n", d);
	return 0;
}



Measured memory_bytes: 2056
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>

using namespace std;

typedef long long ll;
#define rep(i, n) for(long long int (i) = 0; (i) < (int) (n); (i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()

const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const ll LINF = 1e18;

int main(int argc, char const *argv[])
{
    float a, b;

    
    cin >> a >> b;
    cout << a / b << endl;
    return 0;
}


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

int main() {
  int x, n;
  cin >> x >> n;
  if ( n == 0 ) { cout << x << endl; return 0; }
  int p[n];
  for ( int i = 0; i < n; i++ ) { cin >> p[i]; }
  sort(p, p+n);
  int pos = n-1;
  int dif = abs(101-x);
  int ans = 101;
  for ( int i = 100; i >= -1; i-- ) {
    if ( pos >= 0 && i == p[pos] ) {
      pos--;
      continue;
    }
    int now_dif = abs(i-x);
    if ( now_dif <= dif ) {
      dif = now_dif;
      ans = i;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3640
// ????????????????????? cl /EHsc bubbleSort.cpp

#include <iostream>
using namespace std;

int bubbleSort(int A[],int N) {
	int sw = 0; // ???????????° 0??§?????????
	bool flag = 1;
	for(int i=0; flag; i++) {
		flag = 0;
		for(int j=N-1;j>=i+1;j--) {
			if(A[j]<A[j-1]) {
				swap(A[j],A[j-1]);
				flag = 1;
				sw++;
			}
		}
	}
	return sw;
}

int main(void) {
	int A[100], N, sw;
	cin >> N;
	for(int i=0;i<N; i++) cin >> A[i];
	
	sw = bubbleSort(A,N);
	
	for(int i=0;i<N;i++) {
		if(i) cout << " ";
		cout << A[i];
	}
	cout << endl;
	cout << sw << endl;
	return 0;
}

Measured memory_bytes: 3008
/**
 *      purpose : ABC 113 C
 *      author  : kyomukyomupurin
 *      created : 2018-11-05 01:39:13
**/

#include <bits/stdc++.h>
using namespace std;
#define int64 long long
#define print(x) cout << (x) << '\n'

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N, M; cin >> N >> M;
    vector<pair<int, int>> town[100005];

    for (int i = 1; i <= M; ++i){
        int P, Y; cin >> P >> Y;
        town[P].emplace_back(Y, i); 
    }
    int ans1[100005] = {}; int ans2[100005] = {};

    for (int i = 1; i <= N; ++i){
        sort(town[i].begin(), town[i].end());
        for (int j = 0; j < (int) town[i].size(); ++j){
            ans1[town[i][j].second] = i;
            ans2[town[i][j].second] = j + 1;
        }
    }
    for (int i = 1; i <= M; ++i){
        cout << setfill('0') << right << setw(6) << ans1[i] << setfill('0') << right << setw(6) << ans2[i] << '\n';
    }

    return 0;
}

Measured memory_bytes: 7808
#include<iostream>
#include <vector>
#include <algorithm>

using namespace std;
int gojoho(int a, int b) { //a<=b
	int amari = 1;
	int kouho = 1;
	while (amari) {
		amari = b % a;
		b = a;
		a = amari;
	}
	return b;
}

int main(){
	int n,x;
	cin >> n >> x;
	vector<int> xs(n);
	for (int i=0; i < n; i++) {
		cin >> xs[i];
	}
	
	vector<int> modify(n);
	for (int i = 0; i < n; i++) {
		if (xs[i] > x) {
			modify[i] = xs[i] - x;
		}
		else {
			modify[i] = x - xs[i];
		}
	}

	sort(modify.begin(), modify.end());

	int hikaku=modify[0];
	for (int i = 0; i < n; i++) {
		hikaku = gojoho(hikaku,modify[i]);
	}
	cout << hikaku;
	return 0;
}

Measured memory_bytes: 1024
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void p(vector<int> A){rep(i,A.size()){cout << A[i] << " ";}cout << "\n";}

int main(){
    int cnt = 0;
    vector<int> a(3);
    rep(i,3) cin >> a[i];
    sort(a.begin(),a.end());
    //p(a);
    while(a[1] > a[0]){
        a[0] += 2;
        cnt++;
        sort(a.begin(),a.end());
        
    }
    //p(a);
    while(a[2] > a[1]){
        a[1]++;
        a[0]++;
        cnt++;
        sort(a.begin(),a.end());
    }
    //p(a);
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define ll long long
#define cpp boost::multiprecision::cpp_int
#define dequeue deque
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = 1; i <= n; i++)
#define drep(i, n) for(int i = n-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define vi vector<int>
#define P pair<ll, ll>
int mod = 1'000'000'000 + 7;
const double PI = 3.1415926535897932384626433832795;
struct edge {
	int to;
	ll cost;
};
void reverse(string* s) {
	reverse((*s).begin(), (*s).end());
}
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
void COME_LET_THE_GAMES_BEGIN() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << setprecision(20);
}

int X, Y, Z, K;
ll A[1000], B[1000], C[1000];
vector<ll> v, vv;
int main() {
	COME_LET_THE_GAMES_BEGIN();
	cin >> X >> Y >> Z >> K;
	rep(i, X)cin >> A[i];
	rep(i, Y)cin >> B[i];
	rep(i, Z)cin >> C[i];
	rep(i, X) {
		rep(j, Y) {
			v.push_back(A[i] + B[j]);
		}
	}
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	rep(i, min(K, (int)v.size())) {
		rep(j, Z) {
			vv.push_back(v[i] + C[j]);
		}
	}
	sort(vv.begin(), vv.end());
	reverse(vv.begin(), vv.end());
	rep(i, K) {
		cout << vv[i] << endl;
	}
}

Measured memory_bytes: 43364
N = int(input())
A_list = list(map(int, input().split()))

# 2A_i = (X_i+X_(i+1))
# これを解くと、X_i = (Σ(-1)^(i-k)*A_i)/2(0<=k<=N)
# 素直に解くとN^2掛かるので却下.
# (k<i∧k%2=0)∨(i=k)∨(i<k∧k%2=1)のときに加算。その逆のとき減算.その四パターンを先に計算すればNで済む
sum_A_first_plus = [A_list[0]]
sum_A_first_minus = [-1*A_list[0]]
sum_A_last_plus = [A_list[-1]]
sum_A_last_minus = [-1*A_list[-1]]
for i in range(1, N):
    sum_A_first_plus.append(sum_A_first_plus[i-1] + ((-1) ** i ) * A_list[i])
    sum_A_first_minus.append(sum_A_first_minus[i-1] + ((-1) ** (i+1) ) * A_list[i])
    sum_A_last_plus.append(sum_A_last_plus[i-1] + ((-1) ** i ) * A_list[-(i+1)])
    sum_A_last_minus.append(sum_A_last_minus[i-1] + ((-1) ** (i+1) ) * A_list[-(i+1)])
ans_list = []
for i in range(N):
    if(i == 0):
        ans_list.append(A_list[i] + sum_A_last_plus[N-1-i-1])
    elif(i == N-1):
        ans_list.append(sum_A_first_minus[i-1] + A_list[i])
    elif(i % 2 == 0):
        ans_list.append(sum_A_first_minus[i-1] + A_list[i] + sum_A_last_plus[N-1-i-1])
    else:
        ans_list.append(sum_A_first_plus[i-1] + A_list[i] + sum_A_last_minus[N-1-i-1])
print(" ".join(str(e) for e in ans_list))


Measured memory_bytes: 35872
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double ld;
const int MAXN = (int)2e5 + 10;
const int infint = (int)1e9;
const ll inf = (ll)1e18;
ll n, a[MAXN], b[MAXN];
bool equal()
{
	for (int i = 0; i < n; i++)
		if(a[i] != b[i])
			return 0;
	return 1;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> a[i] >> b[i];
	if(equal())	
		return cout << 0, 0;
	ll ans = 0;
	for (int i = 0; i < n; i++)
		ans += a[i];
	ll mn = inf;
	for (int i = 0; i < n; i++)
		if(b[i] < a[i])
			mn = min(mn, b[i]);
			
	cout << ans - mn;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
 
using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
typedef pair<ll ,pair<ll, ll > > iip;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1e15;
 
struct UnionFind{
    //ご本体
    vector<ll > tree;
    //高さ
    vector<ll > rank;
    //グループごとのサイズ
    vector<ll > size;
 
    //定義
    UnionFind(ll N) : tree(N), rank(N), size(N){
        for(int i = 0; i < N; i++){
            tree[i] = i;
            rank[i] = 0;
            size[i] = 1;
        }
    }
 
    //どの根っこに属しているのか？さかのぼり続ける
    int root(int x){
        if(tree[x] == x){
            return x;
        }
        //経路圧縮
        return tree[x] = root(tree[x]);
    }
 
    //木と木を(高さが低い方に)くっつける
    ll unite(int x, int y){
        int tx = root(x);
        int ty = root(y);
        //xとyの根が同じならくっつけない
        if(tx == ty){
            return 0;
        }
        
        ll s = size[tx] + size[ty];
        ll r = size[tx] * size[ty];
        size[tx] = s;
        size[ty] = s;
 
        //tree[tx] = ty;
        //高くない方にくっつけたい：効果がいまいちわからん
        //下：ランク付けのつもり 
        if(rank[tx] < rank[ty]){
            //小さい方を大きい方
            //txの根が大きい方の根に更新
            tree[tx] = ty; 
        }else{
            tree[ty] = tx;
            //つなげるときに同じ高さだったらつなげた後に高さを＋１する
            if(rank[tx] == rank[ty]){
                rank[tx]++;
            }
        }
 
        return r;
 
    }
 
    //同じ木に属しているか？根っこをさかのぼって調べてみる
    bool same(int x, int y){
        int tx = root(x);
        int ty = root(y);
        if(tx == ty){
            return true;
        }else{
            return false;
        }
    }
    //グループのサイズを返す
    int FindSize(int x){
        return size[root(x)];
    }
 
};
 
int main(){
 
    ll N, M; cin >> N >> M;
    //初期化
    vector<ll > p(N, 0);
    for(ll i = 0; i < N; i++){
        cin >> p[i];
        p[i]--;
    }
    //UnionFind準備
    UnionFind solv(N);

       
    for(ll i = 0; i < M; i++){
        ll a, b;
        cin >> a >> b;
        a--; b--;
        solv.unite(a, b);
    }

    ll ans = 0; 
    for(ll i = 0; i < N; i++){
        if(solv.same(i, p[i])){
            ans++;
        }
    }

    cout << ans << endl;

    

}

Measured memory_bytes: 3328
/*
ex 6_1
tomatokan
*/

#include <stdio.h>

typedef struct point{
    int x_elem;
    int y_elem;
}point;

point new_point(int x_elem,int y_elem){
    point new_p={x_elem,y_elem};
    return new_p;
}

point shift_point(point old,int shift_x,int shift_y){
    return new_point(old.x_elem+shift_x,old.y_elem+shift_y);
}

point add_as_complex(point point1,point point2){
    return shift_point(point1,point2.x_elem,point2.y_elem);
}

point mult_by_int_as_complex(point old,int times){
    return new_point(old.x_elem*times,old.y_elem*times);
}

point mult_as_complex(point point1,point point2){
    return new_point(point1.x_elem*point2.x_elem-point1.y_elem*point2.y_elem, point1.x_elem*point2.y_elem+point1.y_elem*point2.x_elem);
}

int main(void){
    int read1,read2;
    point vertex1,vertex2,vertex3,vertex4;
    point vector_1to2;
    point vector_2to3;
    scanf("%d",&read1);
    scanf("%d",&read2);
    vertex1=new_point(read1,read2);
    scanf("%d",&read1);
    scanf("%d",&read2);
    vertex2=new_point(read1,read2);
    vector_1to2=add_as_complex(vertex2,mult_by_int_as_complex(vertex1,-1));
    vector_2to3=mult_as_complex(vector_1to2,new_point(0,1));
    vertex3=add_as_complex(vertex2,vector_2to3);
    vertex4=add_as_complex(vertex1,vector_2to3);
    printf("%d %d %d %d\n",vertex3.x_elem,vertex3.y_elem,vertex4.x_elem,vertex4.y_elem);
    return 0;
}

Measured memory_bytes: 1700
#include <iostream>

using namespace std;

int main(void){
    int n;
    int ans;
    // 1        1-9 no (10-1)
    // 10       0
    // 100      1-9 + (100 - 999) = 9 + 900
    // 1000     0
    // 10000    1-9 + (100 - 999) + (10000 - 99999) = 9 + 900 + 900000
    // 100000   

    cin >> n;
    if(n == 100000){
        ans = 90909;
    }else if (n > 9999){
        ans = 9 + 900 + (n - 10000 + 1);
    }else if(n > 999){
        ans = 9 + 900;
    }else if(n > 99){
        ans = 9 + (n-100 +1);
    }else if(n > 9){
        ans = 9;
    }else{
        ans = (n);
    }

    cout << ans ;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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 int MAX_N = 100;
int N;
int T[MAX_N];

const int MAX_M = 100;
int M;
int P[MAX_M];
int X[MAX_M];
int effect[MAX_M];

void _main() {
  cin >> N;
  rep(i, 0, N) cin >> T[i];
  cin >> M;
  rep(i, 0, M) {
    cin >> P[i] >> X[i];
    effect[i] = T[P[i]-1] - X[i];
  }

  int base = accumulate(T, T + N, 0);
  rep(i, 0, M) {
    cout << (base - effect[i]) << "\n";
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(){
  int n,l,i,j;
  scanf("%d %d",&n,&l);
  if(l<=0&&l+n-1>=0){
    j=0;
  }
  else if(l>=0){
    j=l;
  }
  else{
    j=l+n-1;
  }
  int k=n*l+n*(n-1)/2;
  printf("%d",k-j);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define pb push_back
#define ld long double
#define mod 1000000007
#define mk make_pair
#define ull unsigned long long
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
void factor(ll n,vector<pair<ll,ll>>&p)
{
    ll i=1;
    for(i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            p.pb(mk(i,n/i));
        }
    }
}
int main()
{
    fastIO;
    ll n;
    cin>>n;
    vector<pair<ll,ll>>p;
    factor(n,p);
    ll flag=0,x,y;
    for(int i=0;i<n;i++)
    {
        x=p[i].first;
        y=p[i].second;
        if((x>=1 && x<=9) && (y>=1 && y<=9))
        {
            flag=1;
            break;
        }
    }
    if(flag)
    {
        cout<<"Yes\n";
    }
    else
    {
        cout<<"No\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
typedef long long ll;

ll MOD = 1e9+7;

int N;
string L;
ll pw3[100001];

ll f(int n) {
    if(n==0) return 1;
    if(n==N) {
        return (2*f(n-1))%MOD;
    } 
    if(L[N-n]=='0') {
        return f(n-1);
    } else {
        return (pw3[n-1]+(2*f(n-1))%MOD)%MOD;
    }
}

int main() {
    cin>>L;
    N = L.size();
    pw3[0]=1;
    for(int i=1;i<=N;i++) {
        pw3[i]=(pw3[i-1]*3)%MOD;
    }
    cout<<(pw3[N-1] + f(N))%MOD;
}

Measured memory_bytes: 4352
alphabet = str(input())
if alphabet == "a":
	print("b")
elif alphabet == "b":
	print("c")
elif alphabet == "c":
	print("d")
elif alphabet == "d":
	print("e")
elif alphabet == "e":
	print("f")
elif alphabet == "f":
	print("g")
elif alphabet == "g":
	print("h")
elif alphabet == "h":
	print("i")
elif alphabet == "i":
	print("j")
elif alphabet == "j":
	print("k")
elif alphabet == "k":
	print("l")
elif alphabet == "l":
	print("m")
elif alphabet == "m":
	print("n")
elif alphabet == "n":
	print("o")
elif alphabet == "o":
	print("p")
elif alphabet == "p":
	print("q")
elif alphabet == "q":
	print("r")
elif alphabet == "r":
	print("s")
elif alphabet == "s":
	print("t")
elif alphabet == "t":
	print("u")
elif alphabet == "u":
	print("v")
elif alphabet == "v":
	print("w")
elif alphabet == "w":
	print("x")
elif alphabet == "x":
	print("y")
elif alphabet == "y":
	print("z")



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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int,int> p;

int dy[4]={-1,1,0,0};
int dx[4]={0,0,1,-1};

#define MAX_N 100010

vector<int> child[MAX_N];

ll dfs(ll node){
    vector<int> v;
    for(auto ch: child[node]) {
        v.pb(dfs(ch));
    }
    sort(v.begin(),v.end(),greater<int>()); //N log N
    ll tmp=0;
    REP(i,v.size()){
        tmp=max(tmp,1+i+v[i]);
    }
    return tmp;
}
int main(){
    int N;
    cin>>N;
    REP(i,N-1){
        int a;
        cin>>a;
        child[--a].pb(i+1);
    }
    cout << dfs(0) << endl;
    
}

Measured memory_bytes: 13568
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
typedef long long LL;
LL beibao[10];
LL min(LL a,LL b)
{
	return a<b ?a:b;
}
int main()
{
	for(int i=0;i<10;i++)
		beibao[i]=9223372036854775807;
	LL Q[5];
	LL B[5]={0,1,2,4,8};
	double QQ[5];
	for(int i=1;i<=4;i++)
	{
		scanf("%lld",&Q[i]);
		QQ[i]=Q[i]*1.0/B[i];
	}
	LL N;
	scanf("%lld",&N);
	N*=4;
	double max_xjb=QQ[1];
	int maxloca=1;
	for(int i=1;i<=4;i++) 
	{
		if(QQ[i]<max_xjb)
		{
			max_xjb=QQ[i];
			maxloca=i;
		}
	}
//	printf("%d",maxloca);
	LL cost=0;
	cost=N/B[maxloca]*Q[maxloca];
	N%=B[maxloca];
	beibao[0]=0;
	for(int i=1;i<=4;i++)
		for(int k=0;k<=N;k++)
		{
			if(k>=B[i])
			{
				beibao[k]=min(beibao[k],beibao[k-B[i]]+Q[i]);
			}	
		} 
	cost+=beibao[N];
	printf("%lld\n",cost);
	return 0;
 } 

Measured memory_bytes: 128
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	ll x, y;
	cin>>x>>y;
	if(x>y) swap(x, y);
	y -= x;
	if(y<=1) cout<<"Brown"<<endl;
	else cout<<"Alice"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <sstream>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for(int i = a; i < b; ++i)
#define repll(i, a) REPLL(i, 0, a)
#define REPLL(i, a, b) for(ll i = a; i < b; ++i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<P, int> PP;
const double PI = 3.14159265358979323846;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+17 + 10;

int k, sum = 0;

int main(){
	while (std::cin >> k, k){
		sum = 0;
		rep(i, k * (k - 1) / 2){
			int c;
			std::cin >> c;
			sum += c;
		}
		std::cout << sum / (k - 1) << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define ff first
#define setp(x) setprecision(x)<<fixed
#define ss second
#define fori(v) for(lli i=0; i<v; i++)
#define forj(v) for(lli j=0; j<v; j++)
#define fork(v) for(lli k=0; k<v; k++)
#define forl(v) for(lli l=0; l<v; l++)
#define fort(v) for(lli t=0; t<v; t++)
#define forz(v) for(lli z=0; z<v; z++)
#define lli long long int
#define MAX 100004
#define double long double
#define ch 51
#define max_bit 20
#define pb push_back
#define magic 3
lli inf = pow(10,16);
lli modulo = pow(10,9)+7;
double eps = 1e-11;
ifstream in;
ofstream out;
//#define cin in
//#define cout out
void deal(){
	string a;
	int k;
	cin>>a>>k;
	int cn = 0;
	string cav = "";
	fori(a.length()){
		++cn;
		if(cn==1)
			cav+=a[i];
		if(cn==k)
			cn = 0;
	}
	cout<<cav;
}
int main() {
//	cin.open("i.txt");
//	cout.open("o.txt");
//	while(1)
	
	deal();
}

Measured memory_bytes: 256
import math

n = int(input())
x1 = math.floor(n / 1.08)
x2 = math.ceil(n / 1.08)
if int(x1 * 1.08) == n:
  print(x1)
elif int(x2 * 1.08) == n:
  print(x2)
else:
  print(':(')

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

int n;
int p[100005];
int a[100005];
int b[100005];
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
	{
		scanf("%d", &p[i]);
	}
	a[0] = 1;
	for(int i = 1; i <= n; i++)
	{
		a[i] = a[i - 1] + n + n;
	}
	b[n + 1] = 1;
	for(int i = n; i; i--)
	{
		b[i] = b[i + 1] + n + n;
	}
	for(int i = 1; i <= n; i++)
	{
		a[p[i]] += i;
	}
	for(int i = 1; i <= n; i++)
	{
		printf("%d%c", a[i], i == n ? '\n' : ' ');
	}
	for(int i = 1; i <= n; i++)
	{
		printf("%d%c", b[i], i == n ? '\n' : ' ');
	}
	
	
	return 0;
}

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

int main(){

  int w,h,x,y,r;
  cin>>w>>h>>x>>y>>r;
  
  string ans;

  if((r<=x&&x<=w-r)&&(r<=y&&y<=h-r))ans = "Yes";
  else ans = "No";

  cout<<ans<<endl;

  return 0;
}



Measured memory_bytes: 3200
N=int(input())

word=['a']*N
word[0]=input()




for i in range(1,N):
  word[i]=input()
  if word[i][0]!=word[i-1][-1]:
    print('No')
    exit()

wordunique=list(set(word))

if len(wordunique)!=N:
  print('No')
  exit()

print('Yes')




Measured memory_bytes: 3060
using System;
using System.Linq;

namespace solve
{
    class Program
    {
        static void Main(string[] args)
        {
            var NM = Console.ReadLine().Split(new char[] { ' ' }).Select(x => long.Parse(x)).ToArray();
            var Bs = Console.ReadLine().Split(new char[] { ' ' }).Select(x => long.Parse(x) / 2).ToArray();
            var X = LcmFromArray(Bs);

            var found = false;
            for (var i = 0; i < NM[0]; i++)
            {
                if ((X / Bs[i]) % 2 == 0)
                {
                    Console.WriteLine(0);
                    found = !found;
                    break;
                }
            }
            if (!found)
            {
                Console.WriteLine((NM[1] / X + 1) / 2);
            }
        }

        public static long ComputeGcd(long a, long b)
        {
            if (a < b)
            {
                var temp = a;
                a = b;
                b = temp;
            }
            while (a % b != 0)
            {
                var temp = a;
                a = b;
                b = temp % b;
            }

            return b;
        }

        public static long ComputeLcm(long a, long b)
        {
            return a * b / ComputeGcd(a, b);
        }

        public static long LcmFromArray(long[] As)
        {
            var ans = As[0];
            for (var i = 1; i < As.Length; i++)
            {
                ans = ans * As[i] / ComputeGcd(ans, As[i]);
            }
            return ans;
        }
    }
}


Measured memory_bytes: 33500
#include <iostream>

using namespace std;

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

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

  int ans = 0;
  rep(i, N/2) {
    if (S[i] != S[N-1-i])
      ++ans;
  }
  cout << ans << "\n";

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  string s,s1;
  cin>>s;
  int l=s.length();
  if(s[l-1]!='s')
  {
    s1=s+"s";
  }
  else
  {
    s1=s+"es";
  }
  cout<<s1;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
const int N=5005;
typedef long long ll;
int n,a[N],u,v,i,sz[N];
ll f[N][N],g[N][N];
vector<int>e[N];
void dfs(int u,int fa){
	f[u][0]=a[u];g[u][0]=a[u]>0?a[u]:1ll<<50;
if(u==9){
++u,--u;
}
	for(int v:e[u])if(v!=fa){
		dfs(v,u);
		static ll h[N];int i,j;
		for(i=0;i<=sz[u]+sz[v];++i)h[i]=1ll<<50;
		for(i=0;i<=sz[u];++i)for(j=0;j<=sz[v];++j)h[i+j]=min(h[i+j],f[u][i]+f[v][j]);
		memcpy(f[u],h,sz[u]+sz[v]+1<<3);
		for(i=0;i<=sz[u]+sz[v];++i)h[i]=1ll<<50;
		for(i=0;i<=sz[u];++i)for(j=0;j<=sz[v];++j)h[i+j]=min(h[i+j],g[u][i]+g[v][j]);
		memcpy(g[u],h,sz[u]+sz[v]+1<<3);sz[u]+=sz[v];
	}
	f[u][++sz[u]]=1ll<<50;
	for(i=sz[u]-1;i>=0;--i)if(f[u][i]<0 || g[u][i]<1ll<<50)f[u][i+1]=min(f[u][i+1],0ll),g[u][i+1]=min(g[u][i+1],0ll);
}
int main(){
	scanf("%d",&n);
	for(i=1;i<=n;++i)scanf("%d",a+i);
	for(i=1;i<n;++i)scanf("%d%d",&u,&v),e[u].push_back(v),e[v].push_back(u);
	dfs(1,0);
	for(i=0;f[1][i]>=0 && g[1][i]>=1ll<<50;++i);printf("%d\n",i);
	return 0;
}

Measured memory_bytes: 391424
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int(a.size()))
#define F first
#define S second
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};


int __sign;
int __ch;
int x;
inline int num(){
  x=0;
  while((__ch<'0' || __ch>'9') && __ch!='-' && __ch!=EOF) __ch=getchar();
  if (__ch=='-')
    __sign=-1 , __ch=getchar();
  else
    __sign=1;
  do
    x=(x<<3)+(x<<1)+__ch-'0';
  while((__ch=getchar())>='0' && __ch<='9');
  return x*__sign;
}

PI V[30][30];
int Vs[30];
bool vis[1<<8][30];
int ti[30];

main(){
  int n,m,p,a,b;
  while(cin>>n>>m>>p>>a>>b,n){
    if(!n)break;
    --a,--b;
    rep(i,n)cin>>ti[i];

    rep(i,m)Vs[i]=0;

    rep(i,p){
      int x,y,z;
      cin>>x>>y>>z;
      --x,--y;
      V[x][Vs[x]++]=mp(y,z);
      V[y][Vs[y]++]=mp(x,z);
    }

    priority_queue<pair<double,PI> > Q;
    Q.push(mp(0,mp(a,0)));
    memset(vis,0,sizeof(vis));
    double ans=-1;

    while(!Q.empty()){
      int v=Q.top().S.F,cst=Q.top().S.S;
      double cc=-Q.top().F;
      Q.pop();
      if(vis[cst][v])continue;
      vis[cst][v]=true;
      if(v==b){
        ans=cc;
        break;
      }

      rep(i,n){
        if(cst>>i&1)continue;
        rep(j,Vs[v]){
          int nv=V[v][j].first;
          int tc=V[v][j].second;
          int nst=cst|(1<<i);
          if(vis[nst][nv])continue;
          double nc=cc+1.0*tc/ti[i];
          Q.push(mp(-nc,mp(nv,nst)));
        }
      }
    }
    if(ans<0)puts("Impossible");
    else printf("%f\n",ans);
  }
}

Measured memory_bytes: 5556
q, h, s, d = list(map(int, input().split()))
n = int(input())
qpl = 4 * q
hpl = 2 * h
spl = s
dpl = d / 2
s_min = min(qpl, hpl, spl)
if dpl >= s_min:
    print(s_min * n)
elif n % 2 == 0:
    print(d * (n // 2))
else:
    print(d * (n // 2) + s_min)

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

int main(){
	int n;
  	cin>>n;
    string s;
  	cin>>s;
  	int mymax=0;
  	int ans=0;
  	
  	for (int i=0;i<n;i++){
  		if(s.at(i)=='I'){
        	ans++;	
        }
      	if(s.at(i)=='D'){
        	ans--;
        }
      	mymax=max(mymax,ans);
    }
  	cout<<mymax<<endl;
  	
}    



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

int main()
{
	int N, M;
	scanf("%d%d", &N, &M);
	std::priority_queue<int> pq;
	for (int i{}; i < N; i++)
	{
		int A;
		scanf("%d", &A);
		pq.push(A);
	}

	for (int i{}; i < M; i++)
	{
		int tmp{pq.top()};
		pq.pop();
		tmp /= 2;
		pq.push(tmp);
	}
	int64_t ans{};
	while (!pq.empty())
	{
		ans += pq.top();
		pq.pop();
	}
	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 892
#include<iostream>
#include<cstdio>
#include<cstdlib>
#define ll long long
#define il inline
#define RG register
using namespace std;
il ll gi(){ RG ll x=0,q=1; RG char ch=getchar(); while( ( ch<'0' || ch>'9' ) && ch!='-' ) ch=getchar();
  if( ch=='-' ) q=-1,ch=getchar(); while(ch>='0' && ch<='9') x=x*10+ch-48,ch=getchar(); return q*x; }

ll ans,n,cnt,V[5],w[10000],v[10000],dp[100000010];

il void init(){
  V[1]=gi(),V[2]=gi(),V[3]=gi(),V[4]=gi();  
  n=gi();

  if(V[2]>V[1]*2) V[2]=V[1]*2;
  if(V[3]>V[1]*4) V[3]=V[1]*4;
  if(V[4]>V[1]*8) V[4]=V[1]*8;
  if(V[3]>V[2]*2) V[3]=V[2]*2;
  if(V[4]>V[2]*4) V[4]=V[2]*4;
  if(V[4]>V[3]*2) V[4]=V[3]*2;
}

il void work(){
  if(n){ ans+=V[4]*(n/2); n-=n/2*2; }
  if(n){ ans+=V[3]*n; n-=n; }
  printf("%lld\n",ans);
}
int main(){ init(); work(); return 0; }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define CYES cout << "Yes" \
                  << "\n";
#define CNO cout << "No" \
                 << "\n";
#define CFS           \
    cin.tie(nullptr); \
    ios::sync_with_stdio(false);
#define CST(x) cout << fixed << setprecision(x);
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
const int IINF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = (int)1e9 + 7;
const string MM = " ";

struct UnionFind
{
    vector<int> _root;
    vector<int> _size;

    explicit UnionFind(int n) : _root(n)
    {
        for (int i = 0; i < n; i++)
            _root[i] = i;
        _size.assign(n, 1);
    }

    // 要素xの親を取得(経路圧縮もする)
    int root(int x)
    {
        if (_root[x] == x)
            return x;
        return _root[x] = root(_root[x]);
    }

    // 要素xとyが同じ木にいるかどうかを返す
    bool same(int x, int y)
    {
        return root(x) == root(y);
    }

    // 要素xとyが属する木を結合する
    // サイズの小さい木を大きい木につなぐ
    void unite(int x, int y)
    {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry)
            return;
        if (size(rx) < size(ry))
            swap(rx, ry);
        _root[ry] = rx;
        _size[rx] += _size[ry];
    }

    // 要素xが属する木の要素数を返す
    int size(int x)
    {
        return _size[root(x)];
    }
};

int main()
{
    string s;
    int q;
    cin >> s >> q;
    deque<char> d;
    for (size_t i = 0; i < s.size(); i++)
    {
        d.push_back(s[i]);
    }
    bool reversed = false;
    for (size_t i = 0; i < q; i++)
    {
        int t;
        cin >> t;
        if (t == 1)
        {
            reversed ^= true;
        }
        else
        {
            int f;
            char c;
            cin >> f >> c;
            if ((f == 1 && !reversed) || (f == 2 && reversed))
            {
                d.push_front(c);
            }
            else
            {
                d.push_back(c);
            }
        }
    }

    int n = d.size();
    if (reversed)
    {
        for (size_t i = 0; i < n; i++)
        {
            cout << d.back();
            d.pop_back();
        }
    }
    else
    {
        for (size_t i = 0; i < n; i++)
        {
            cout << d.front();
            d.pop_front();
        }
    }
    cout << "\n";
}

Measured memory_bytes: 896
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

using std::cout;
using std::cin;
using std::endl;
using std::pow;
using std::vector;
using std::string;

int main(){
    long long int N,D,count=0;
    long long int x,y;
    cin >> N >> D;
    for(int i=0;i<N;i++){
        cin >> x >> y;
        if(x*x+y*y <= D*D) count++;
    }
    cout << count;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define fors(i,a,b) for(int i=(a);i<=(b);++i)
int main(){
    ios::sync_with_stdio(0);
    register int a,wh[9],b,e;
    cin>>a>>b>>e;
    fors(c,-100,200){
        wh[1]=a+b+c;
        if(wh[1]<a+e) continue;
        fors(i,-100,200){
            wh[7]=a+e+i;
            if(wh[7]!=wh[1]) continue;
            fors(f,-100,200)
            {
                wh[6]=c+f+i;
                if(wh[6]!=wh[7]) continue;
                fors(d,-100,200){
                    wh[2]=d+e+f;
                    if(wh[2]!=wh[6]) continue;
                    fors(g,-100,200)
                    {
                        wh[4]=g+d+a;
                        wh[8]=c+e+g;
                        if((wh[8]!=wh[4])) continue;
                        fors(h,-100,200){
                            wh[3]=g+h+i;
                            wh[5]=b+e+h;
                            if((wh[3]!=wh[5]) || (wh[3]!=wh[4]) || (wh[3]!=wh[8])) continue;
                                cout<<a<<" "<<b<<" "<<c<<endl;
                                cout<<d<<" "<<e<<" "<<f<<endl;
                                cout<<g<<" "<<h<<" "<<i<<endl;
                                return 0;
                        }
                    }       
                }
            }
        }
    }
    return 0;
}

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


int main()
{
    int a,b,c,d,e,f;
    int i,j,x,y,z;
    int w,s,g,sg;
    scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f);
    int desired_sgw=a*100,desired_sg=0;
    double ans=0,p;
    for(i=0;i<30;i++) {
        for(j=0;j<30;j++) {
            w=100*(i*a+j*b);
            if(w==0 || w>=f) continue;
            g=min((w/100)*e,f-w);
            //printf("%d\n", g);
            sg=0;
            for(y=0;y<30;y++) {
                z=g-d*y;
                if(z<0) continue;
                x=z/c;
                sg=max(sg,c*x+d*y);
            }

            p=(double)sg/(double)(sg+w);
            if(p>ans) {
                ans=p;
                desired_sg=sg;
                desired_sgw=sg+w;
            }
        }
    }
    printf("%d %d\n", desired_sgw, desired_sg);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h> 
#include <string> 
#include <algorithm>
#include <numeric>
#include <cmath>
using namespace std;

int main() {

	long res;
	string S; cin >> S;
	long mylen = S.length();
	long zero = count(&S[0], &S[mylen], '0');

	res = 2 * min(zero, mylen - zero);

	cout << res << endl;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define PI acos(-1)
#define sz 100010
#define RUN_FAST ios::sync_with_stdio(false);
using namespace std;

int main()
{
    RUN_FAST; cin.tie(nullptr);
    int n, i;
    ll sum;
    scanf("%d", &n);
    int arr[n];
    for (i=0; i<n; i++) scanf("%d", &arr[i]);
    sum=0;
    for (i=1; i<n; i++) {
        if (arr[i]<arr[i-1])
            sum+=arr[i-1]-arr[i], arr[i]=arr[i-1];
    }
    printf("%lld\n", sum);
    return 0;
}


Measured memory_bytes: 4648
S=input()
import numpy as np
M=13
MOD=10**9+7
dp=np.zeros(M, dtype=np.int64)
dp[0]=1
idx = np.zeros(M, dtype=np.int8)
window = np.ones(10, dtype=np.int8)
for i in range(M):
  idx[i * 10 % M] = i
for s in S:
  if s=='?':
    tdp=dp[idx]
    ndp = np.concatenate([tdp[4:], tdp])
    dp = np.convolve(ndp, window, mode='valid') % MOD
  else:
    dp=np.roll(dp[idx],int(s))
print(dp[5]%MOD)



Measured memory_bytes: 14508
#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
using namespace std;

#define rep(i,n) for(long long i = 0; i < n; i++)

typedef long long ll;

const ll INF = ll(1e18) + 1;

void Main()
{
	ll h, n, sum = 0; cin >> h >> n;
	vector<ll> a(n);
	rep(i, n) {
		cin >> a[i];
		sum += a[i];
	}
	if (sum >= h) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

Measured memory_bytes: 1024
import sys,math,collections,itertools
input = sys.stdin.readline

N = int(input())
s = input().rstrip()
cntb =0
cntw = s.count('.')
ans =cntw
for i in range(len(s)):
    if s[i] == '#':
        cntb +=1
    else:
        cntw -=1
    ans = min(ans,cntb+cntw)
print(ans)

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

typedef long long ll;

int n;
string s;
bool ok(char x,char y,char z,char w){
	int cnt = 0;
	if(y == 'S')cnt ++;
	if(w == 'o')cnt ++;
	if(cnt&1)return x != z;
	else return x == z;
}
string solve(string t){
	t.resize(n);
	for(int i = 1 ; i+1 < n ; i ++){
		int cnt = 0;
		if(s[i] == 'o')cnt ++;
		if(t[i] == 'S')cnt ++;
		if(cnt&1){
			if(t[i-1] == 'S')t[i+1] = 'W';
			else t[i+1] = 'S';
		}
		else t[i+1] = t[i-1];
	}
	//cout << t << endl;
	if(!ok(t[n-2],t[n-1],t[0],s[n-1]))return "";
	if(!ok(t[n-1],t[0],t[1],s[0]))return "";
	return t;
}
	

int main(){
	cin >> n >> s;
	string ret;
	string init[4] = { "SS","SW","WS","WW" };
	for(int i = 0 ; i < 4 ; i ++){
		ret = solve(init[i]);
		if(ret != ""){
			cout << ret << endl;
			return 0;
		}
	}
	puts("-1");
}



Measured memory_bytes: 512
#include<stdio.h>

int partition(int *,int);

int main()
{
  int n,i,q;
  scanf("%d",&n);
  int A[n];
  for(i = 1;i <= n;i++)
    {
      scanf("%d",&A[i]);
    }
  q = partition(A,n);
  for(i = 1;i < q;i++)
    {
      printf("%d ",A[i]);
    }
  printf("[%d] ",A[q]);
  for(i = q+1;i <= n;i++)
    {
      printf("%d",A[i]);
      if(i != n)
	{
	  printf(" ");
	}
    }
  printf("\n");
}

int partition(int A[],int n)
{
  int x,i,j,temp;
  x = A[n];
  i = 0;
  for(j = 1;j < n;j++)
    {
      if(A[j] <= x)
	{
	  i = i+1;
	  temp = A[i];
	  A[i] = A[j];
	  A[j] = temp;
	}  
    }
    temp = A[i + 1];
    A[i + 1] = A[n];
    A[n] = temp;
    
  return i+1;
}



Measured memory_bytes: 2156
#include<stdio.h>
int main()
{
	int a,b,c,e,ans;
	scanf("%d %d %d %d",&a,&b,&c,&e);
	if((a*b) >= (c*e)) ans=(a*b);
	else ans=(c*e);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128