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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<string> v(n);
	REP(i, n)cin >> v[i];
	vvi a(n + 1, vi(m)), b(n + 1, vi(m)), c(n, vi(m + 1)), d(n, vi(m + 1));
	REP(i, n) {
		REP(j, m) {
			if (v[i][j] == '#') {
				a[i + 1][j] = 0;
				c[i][j + 1] = 0;
			}
			else {
				a[i + 1][j] = a[i][j] + 1;
				c[i][j + 1] = c[i][j] + 1;
			}
		}
	}
	RREP(i, n)RREP(j, m) {
		if (v[i][j] == '#') {
			b[i][j] = 0;
			d[i][j] = 0;
		}
		else {
			b[i][j] = b[i + 1][j] + 1;
			d[i][j]= d[i][j + 1] + 1;
		}
	}
	int ans = -INF;
	REP(i, n)REP(j, m) {
		if (v[i][j] == '.') {
			chmax(ans, a[i + 1][j] + b[i][j] + c[i][j+1] + d[i][j] - 3);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 67328
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
typedef long double ld;
using namespace std;

const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int> flower(n, 0);
    vector<int> h(n);
    for(int i = 0; i < n; i++)
    {
        cin >> h[i];
    }
    int i = 0;
    int cnt = 0;
    while(1)
    {
        bool flag = 1;
        bool flag2 = 0;
        while(flower[i] == h[i] && i < n)
        {
            i++;
        }
        while(flower[i] < h[i] && i < n)
        {
            flag2 = 1;
            flower[i]++;
            i++;
        }
        if(flag2)
        {
            cnt++;
        }
        for(int j = 0; j < n; j++)
        {
            if(flower[j] != h[j])
            {
                flag = 0;
                break;
            }
        }
        if(flag)
        {
            cout << cnt;
            return 0;
        }
        else
        {
            if(i == n)
            {
                i = 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 256
// AOJ 2001 "Amida, the City of Miracle" (ICPC模擬国内予選 2006 Problem B)
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        while (true) {
            int n = sc.nextInt();
            int m = sc.nextInt();
            int a = sc.nextInt();
            if (n == 0) {
                break;
            }
            
            boolean[][] hline = new boolean[1000+1][n+1];
            for (int i = 0; i < m; i++) {
                int h = sc.nextInt();
                int p = sc.nextInt();
                int q = sc.nextInt();
                hline[h][p] = true;
            }
            
            int xpos = a;
            for (int h = 1000; h >= 1; h--) {
                if (hline[h][xpos-1]) {
                    // 左側に横棒がある場合
                    xpos--;
                } else if (hline[h][xpos]) {
                    // 右側に横棒がある場合
                    xpos++;
                }
            }
            System.out.println(xpos);
        }
    }
}

Measured memory_bytes: 62624
# -*- coding: utf-8 -*-
import sys
from itertools import combinations,product
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,K=map(int,input().split())
    x,y=[0]*N,[0]*N
    for i in range(N):
        x[i],y[i]=map(int,input().split())
    unique_x,unique_y=list(sorted(list(set(x)))),list(sorted(list(set(y))))
    d_x={z:i for i,z in enumerate(unique_x)}
    d_y={z:i for i,z in enumerate(unique_y)}
    xx=[d_x[z] for z in x]
    yy=[d_y[z] for z in y]
    c=[[0]*N for _ in range(N)]
    for i,j in zip(yy,xx):
        c[i][j]+=1
    s=[[0]*(N+1) for _ in range(N+1)]
    for i in range(N):
        for j in range(N):
            s[i+1][j+1]+=s[i][j+1]+s[i+1][j]-s[i][j]+c[i][j]
    xx.sort()
    yy.sort()
    ans=INF*10
    for (x0,x1),(y0,y1) in product(combinations(xx,2),combinations(yy,2)):
        if s[y1+1][x1+1]-s[y1+1][x0]-s[y0][x1+1]+s[y0][x0]>=K:
            ans=min(ans,(unique_y[y1]-unique_y[y0])*(unique_x[x1]-unique_x[x0]))
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 41452
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public final class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final String[] line = in.nextLine().split(" ");
        final int n = Integer.parseInt(line[0]);
        final int k = Integer.parseInt(line[1]);
        for (int i = 0; i < n; i++) {
            in.nextInt();
        }
        in.nextLine();
        System.out.println((int) Math.ceil((double) (n - 1) / (k - 1)));
    }
}


Measured memory_bytes: 58340
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>
#include <cmath>
#include <numeric>
#include <iomanip>

using namespace std;

#define int long long

#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define rrep(i, n) for (int i=(int)n-1;i>=0;--i)
#define rrep1(i, n) for (int i=n;i>=1;--i)
#define range(i, l, r) for (int i=l;i<(int)r;++i)
#define rrange(i, l, r) for (int i=(int)r-1;i>=(int)l;--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}
constexpr int TEN(int n){return n==0?1:10*TEN(n-1);}

int f(int i)
{
	return i*i*i*i*i;
}

signed main()
{
	int X; cin >> X;
	for (int A = -5000; A <= 5000; ++A) {
		for (int B = -5000; B < A; ++B) {
			if (f(A) - f(B) == X) {
				printf("%lld %lld\n", A, B);
				return 0;
			}
		}
	}
}



Measured memory_bytes: 3748
# solve 64 by Kruskal algorithm

class UnionFind(object):
    def __init__(self, n):
        self.par = [-1] * n
    
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if x == y:
            return False
        else:
            if self.par[x] > self.par[y]:
                x, y = y, x
            self.par[x] += self.par[y]
            self.par[y] = x
            return True

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

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


# グラフの読み込み
from heapq import heappush, heappop
edges = []
N, M = map(int, input().split())
for _ in range(M):
    si, ti, wi = map(int, input().split())
    heappush(edges, (wi, si, ti))

# クラスカル法
uf = UnionFind(N)
cost = 0
mst = []
while len(edges) > 0:
    (w, u, v) = heappop(edges)
    if not uf.same(u, v):
        uf.unite(u, v)
        mst.append((u, v))
        cost += w

print(cost)
# print(mst)


Measured memory_bytes: 23444
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n,X,Y;
	cin>>n>>X>>Y;
	vp in(n);
	rep(i,n){
		int a,b;char d;
		pii c;
		cin>>a>>b>>d;
		if(d=='N')c={a,Y-b};
		if(d=='E')c={X+Y-b,X-a};
		if(d=='S')c={X+Y+X-a,b};
		if(d=='W')c={X+Y+X+b,a};
		int l=c.first-c.second,r=c.first+c.second;
		if(l<0)l+=X+X+Y+Y,r+=X+X+Y+Y;
		in[i]={r,l};
	}
	int out=inf;
//	rep(i,n)cout<<in[i].second<<" "<<in[i].first<<endl;
	rep(i,2*n){
		sort(all(in));
		int co=0;
		int mi=-1;
	//	rep(j,n)cout<<in[j].second<<" "<<in[j].first<<endl;
		rep(j,n){
			if(mi<in[j].second){
				mi=in[j].first;
				co++;
			}
//			cout<<mi<<" "<<co<<endl;
		}
//		if(co==6){
//			cout<<i<<endl;
//			rep(j,n)cout<<in[j].second<<" "<<in[j].first<<endl;
//			return 0;
//		}
		out=min(out,co);
		in.pb({in[0].first+X+X+Y+Y,in[0].second+X+X+Y+Y});
		in.erase(in.begin());
	}
	cout<<out<<endl;
}

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

int main(){
    int n, i, a[5], res = 0;

    for(i = 0; i < 5; i++){
        cin >> a[i];
        if(a[i] == 0){
            res = i;
        }
    }

    cout << res + 1 << "\n";
    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int v[10];
int main()
{
	for(int i= 1; i <= 3; i ++)
	{
		int x, y;
		cin >> x >> y;
		v[x] ++;
		v[y] ++;
	}
	for(int i = 1; i<= 4; i ++)
	{
		if(v[i] >= 3)
			return cout << "NO", 0;
	}
	cout << "YES";





	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  double weight;

  while(scanf("%lf", &weight) != EOF){
    if(weight > 91.0)
      printf("heavy\n");
    else if(weight > 81.0)
      printf("light heavy\n");
    else if(weight > 75.0)
      printf("middle\n");
    else if(weight > 69.0)
      printf("light middle\n");
    else if(weight > 64.0)
      printf("welter\n");
    else if(weight > 60.0)
      printf("light welter\n");
    else if(weight > 57.0)
      printf("light\n");
    else if(weight > 54.0)
      printf("feather\n");
    else if(weight > 51.0)
      printf("bantam\n");
    else if(weight > 48.0)
      printf("fly\n");
    else
      printf("light fly\n");
  }

  return 0;
}

Measured memory_bytes: 0
import sys
from io import StringIO
import unittest
import os

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


# 実装を行う関数
def resolve(test_def_name=""):
    # 数値取得サンプル
    #   1行1項目 n = int(input())
    #   1行2項目 x, y = map(int, input().split())
    #   1行N項目 x = list(map(int, input().split()))
    #   N行1項目 x = [int(input()) for i in range(n)]
    #   N行N項目 x = [list(map(int, input().split())) for i in range(n)]

    # 文字取得サンプル
    #   1行1項目 x = input()
    #   1行1項目(1文字ずつリストに入れる場合) x = list(input())
    n, m = map(int, input().split())
    py_s = [list(map(int, input().split())) for i in range(m)]


    num = 0
    city = 0
    city_str = ""
    numdict = {}

    for i in sorted(py_s, key=lambda x: [x[0], int(x[1])]):
        if city != i[0]:
            city = i[0]
            city_str = format(city, '06')
            num = 0
        num += 1
        numdict[i[1]] = "".join([city_str, format(num, '06')])

    for i in py_s:
        print(numdict[i[1]])


# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """2 3
1 32
2 63
1 12"""
        output = """000001000002
000002000001
000001000001"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """2 3
2 55
2 77
2 99"""
        output = """000002000001
000002000002
000002000003"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def test_original1(self):
        test_input = """100000 4
100000 1000000000
2 1
2 10
2 2
"""
        output = """100000000001
000002000001
000002000003
000002000002"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def t_est_original2(self):
        test_input = """4 1
1 20
"""
        output = """000001000001"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()


Measured memory_bytes: 116552
#include <iostream>
#define MAX 100000

using namespace std;

int h;

void print(int i, int h, int *A){
    cout << "node " << i << ": ";
    cout << "key = " << A[i] << ", ";
    if(i > 1) cout << "parent key = " << A[i/2] << ", ";
    if(2 * i  <= h) cout << "left key = " << A[2*i] << ", ";
    if(2 * i + 1 <= h) cout << "right key = " << A[2*i+1] << ", ";
}

int main(){
    int i, A[MAX+1];
    cin >> h;
    for(i = 1; i <= h; i++) cin >> A[i];
    for(i = 1; i <= h; i++){
        print(i, h, A);
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3132
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;
#include <cstring>

int main() {
  int n = 0;
  string s;
  cin >> s;
  for (int i = 0; i < s.length(); i++) {
    n += s[i] - '0';
    n %= 9;
  }
  cout << (n == 0 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3688
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> 
#include <cstring>
#include <queue>
#include <ctime>
#include <set>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const ll INF = 1ll<<50;
const int IINF = 1000000009;
const int maxP = 1000010;
const int maxN = 10005;
const int maxM = 200010;

int a[maxN];
int n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	int ans = 0;
	for(int i=1;i<=n;i++)
	{
		ans += a[i];
	}
	ans -= n;
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 256
N = int(input())
xyh = [list(map(int, input().split())) for _ in range(N)]
xyh.sort(key=lambda val: val[2])

for cx in range(101):
    for cy in range(101):
        check = True
        H = xyh[-1][2] + abs(xyh[-1][0] - cx) + abs(xyh[-1][1] - cy)
        for x in xyh[:-1]:
            if x[2] != max(H - abs(x[0] - cx) - abs(x[1] - cy), 0):
                check = False
                break
        if check:
            print(cx, cy, H)
            exit()


Measured memory_bytes: 3064
#include <iostream>
#include <deque>
#include <algorithm>
typedef long long ll;
using namespace std;
int a[100005];
int b[100005];
int main() {
  int n;
  cin >> n;

  for(int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(a,a+n);
  sort(b,b+n,greater<int> ());
  int f = 0;
  int l = n - 1;

  deque<ll> de;
  deque<ll> de2;
  if(n & 1) {
  
    de.push_back(a[f]);
    f++;
    bool t = true;
  
  while(f < l) {
    // cout << "ji"<<endl;
    if(t) {
      de.push_front(a[l]);
      l--;
      de.push_back(a[l]);
      l--;
      t = !t;
    }
    else {
      de.push_front(a[f]);
      f++;
      de.push_back(a[f]);
      f++;
      t = !t;
    }
  }
  }
  else {
    de.push_front(a[f]);
    f++;
    de.push_back(a[l]);
    l--;
    bool t = true;
   
    while(f < l) {
      if(t) {
      de.push_front(a[l]);
      l--;
      de.push_back(a[f]);
      f++;
      t = !t;
      }
      else {
	de.push_front(a[f]);
	f++;
	de.push_back(a[l]);
	l--;
	t = !t;
      }
    }	
  }

  f = 0;
  l = n - 1;
  if(n & 1) {
  
    de2.push_back(b[f]);
    f++;
    bool t = true;
  
  while(f < l) {
    // cout << "ji"<<endl;
    if(t) {
      de2.push_front(b[l]);
      l--;
      de2.push_back(b[l]);
      l--;
      t = !t;
    }
    else {
      de2.push_front(b[f]);
      f++;
      de2.push_back(b[f]);
      f++;
      t = !t;
    }
  }
  }
  else {
    de2.push_front(b[f]);
    f++;
    de2.push_back(b[l]);
    l--;
    bool t = true;
  
    while(f < l) {
      if(t) {
      de2.push_front(b[l]);
      l--;
      de2.push_back(b[f]);
      f++;
      t = !t;
      }
      else {
	de2.push_front(b[f]);
	f++;
	de2.push_back(b[l]);
	l--;
	t = !t;
      }
    }	
  }

  
  ll ans = 0;
  ll ans2 = 0;
  for(int i = 1; i < n; i++) {
    //  cout << de[i] << endl;
    ans += abs(de[i] - de[i-1]);
    ans2 += abs(de2[i] - de2[i-1]);
  }
  cout << max(ans,ans2) << endl;
}
    
    
    


Measured memory_bytes: 2688
# https://atcoder.jp/contests/abc142/tasks/abc142_c
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def main():
    n = int(input())
    al = list(map(int, input().split()))
    al = [(i, a) for i, a in enumerate(al)]
    al.sort(key=lambda a: a[1])
    al = [i + 1 for i, a in al]
    print(' '.join(map(str, al)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 72044
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		
		String s=sc.next();
		int count=0;
		int ans=0;
		
		for(int i=0;i<s.length();i++) {
			if(s.charAt(i)=='0') {
				count++;
			}else {
				ans++;
			}
		}
		int r=Math.min(count,ans)*2;
		System.out.println(r);
		sc.close();
	}

}

Measured memory_bytes: 30292
S  = list(input())
n = len(S)
ans = 0

for i in range(2 ** (n-1)):

    list = S[0]
    for j in range(1, n):

        if (i >> (j - 1)) & 1:

            list = list + "+" + S[j]
            # print(i >> (j-1))

        else:
            list += S[j]

    ans += eval(list)

print(ans)


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define IN(x, a, b) x >= a and x < b

using namespace std;
using ll = long long;

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;
}
template <typename T> constexpr T INF = numeric_limits<T>::max() / 2;
#pragma endregion

struct UnionFind {
  vector<int> data;

  UnionFind(int sz) { data.assign(sz, -1); }

  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if (x == y)
      return (false);
    if (data[x] > data[y])
      swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  int find(int k) {
    if (data[k] < 0)
      return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k) { return (-data[find(k)]); }
};

template <typename T> struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return cost; }
};

template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;

// Functor to compare by the Mth element
template <int M, template <typename> class F = std::less> struct TupleCompare {
  template <typename T> bool operator()(T const &t1, T const &t2) {
    return F<typename tuple_element<M, T>::type>()(std::get<M>(t1),
                                                   std::get<M>(t2));
  }
};

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

  int N;
  cin >> N;
  vector<tuple<int, int, int>> t;
  REP(i, N) {
    int x, y;
    cin >> x >> y;
    t.emplace_back(x, y, i);
  }

  vector<tuple<int, pair<int, int>>> ds;
  sort(ALL(t), TupleCompare<0>());
  REP(i, N - 1) {
    ds.emplace_back(get<0>(t[i + 1]) - get<0>(t[i]),
                    make_pair(get<2>(t[i + 1]), get<2>(t[i])));
  }
  sort(ALL(t), TupleCompare<1>());
  REP(i, N - 1) {
    ds.emplace_back(get<1>(t[i + 1]) - get<1>(t[i]),
                    make_pair(get<2>(t[i + 1]), get<2>(t[i])));
  }
  sort(ALL(ds));

  UnionFind uf(N);

  int ans = 0;
  for (auto d : ds) {
    if (uf.find(get<1>(d).first) != uf.find(get<1>(d).second)) {
      uf.unite(get<1>(d).first, get<1>(d).second);
      ans += get<0>(d);
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 6132
#include <stdio.h>

int main(void) {
	int query_num;
	int i;
	int now,sum;
	while(1) {
		scanf("%d",&query_num);
		if(query_num==0)break;
		query_num/=4;
		for(i=0,sum=0;i<query_num;i++) {
			scanf("%d",&now);
			sum+=now;
		}
		printf("%d\n",sum);
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<sstream>
#include<fstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<string>
using namespace std;

long long fac(int n){
	long long ret = 1;
	for(int x=2;x<=n;++x)ret *= x;
	return ret;
}

int main(){
	int n;
	while(scanf("%d",&n)==1){
		cout<<fac(n)<<endl;
	}
	return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <algorithm>
using namespace std;
#define MAX 100000

int n, A[MAX+1], L[MAX+1];
int LIS()
{
    L[0] = A[0];
    int length = 1;

    for(int i=1; i<n; i++)
    {
        if(L[length-1] < A[i])
            L[length++] = A[i];
        else
            *lower_bound(L,L+length,A[i]) = A[i];
    }
    return length;
}
int main()
{
    cin >> n;
    for(int i=0; i<n; i++)
        cin >> A[i];
    cout << LIS() << endl;
    return 0;
}

Measured memory_bytes: 3876
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, StdoutLock, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , bytes ) => { read_value ! ( $ next , String ) . into_bytes ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }
#[allow(dead_code)]
pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
    let out = stdout();
    let writer = BufWriter::new(out.lock());
    f(writer)
}
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) } ; }
#[allow(dead_code)]
fn main() {
    input!{
        n: u64,
        h: u64,
        w: u64,
    }
    println!("{}", (n-h+1) * (n-w+1));
}

Measured memory_bytes: 4352
#include<string>
#include<sstream>
#include<iostream>

using namespace std;

int main()
{
	for(int n;cin>>n,n;){
		string s;	cin>>s;
		for(int i=0;i<n;i++){
			stringstream ss;

			int cnt=1;
			char bef=s[0];
			for(int i=1;i<s.length();i++){
				if(s[i]==bef)	cnt++;
				else{
					ss<<cnt<<bef;
					cnt=1;
					bef=s[i];
				}
			}
			ss<<cnt<<bef;

			s=ss.str();
		}
		cout<<s<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a,b,c;
    cin >> n;
    while(n--){
        cin >> a >> b >> c;
        if(a<b) swap(a,b);
        if(a<c) swap(a,c);
        if((a*a)==(b*b+c*c))    cout << "YES\n";
        else cout << "NO\n";
    }
}  

Measured memory_bytes: 3100
#include <iostream>
#include <string.h>
#include <map>
#include <iomanip>
#include <vector>
#include <set>
#include <queue>
#include <cmath>
#include <algorithm>
#define pb push_back
#define mk make_pair
#define ll long long
#define fast ios_base::sync_with_stdio(false);
using namespace std;
int main()
{
	ll int h,sum=0,b,n;
	cin>>h>>n;
	vector<ll int >v;
	for(int i=0;i<n;i++)
	{
		cin>>b;
		v.pb(b);
		sum+=b;
	}
	if(h<=sum)
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(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 ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;
ll dpp[200000];
ll dp[200000];
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
int a[200000];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    //int a[m];
    rep(i, m) cin >> a[i];
    //unsigned ll dp[n + 1];
    //ll dpp[n + 1];
    memset(dpp, -1, sizeof(dpp));
    memset(dp, 0, sizeof(dp));
    rep(i, m){
        dpp[a[i]] = -2;
    }
    dp[0] = 1;
    if(dpp[1] != -2) dp[1] = 1;
    //if(dp[1] != -2) dp[2] = 2;
    //else dp[2] = 1;
    rep(i, n - 1){
        if(dpp[i + 2] == -1 && dpp[i] != -2 && dpp[i + 1] != -2){
            dp[i + 2] = dp[i + 1] + dp[i];
            dpp[i + 2] = 0;
        }
        else if(dpp[i + 2] == -1 && dpp[i] == -2 && dpp[i + 1] !=  -2){
            dp[i + 2] = dp[i + 1];
            dpp[i + 2] = 0;
        }
        else if(dpp[i + 2] == -1 && dpp[i] != -2 && dpp[i + 1] == -2){
            dp[i + 2] = dp[i];
            dpp[i + 2] = 0;
        }
        else if(dpp[i + 2] == -1 && dpp[i + 1] == -2 && dpp[i] == -2) {
            dp[i + 2] = 0;
            dpp[i + 2] = -2;
        }
      dp[i + 2] %= 1000000007;


    }

    if(dp[n] <= 0) cout << 0 << endl;
    else cout << dp[n] % 1000000007 << endl;

}


Measured memory_bytes: 3840
def resolve():
    '''
    code here
    '''
    import collections
    import copy

    N, P = [int(item) for item in input().split()]
    P_org = copy.deepcopy(P)

    fact_list = [1]

    cnt = 2
    while P > 1 and cnt**2 <= P:
        if P % cnt == 0:
            fact_list.append(cnt)
            P //= cnt
        else:
            cnt += 1
    fact_list.append(P)

    if N == 1:
        res = P_org
    else:
        cnt_num = collections.Counter(fact_list[1:])
        res_list = []
        for i, v in cnt_num.items():
            if v//N > 0:
                res_list.append(i**(v//N))
        
        res = 1
        for item in res_list:
            res *= item
    print(res)

if __name__ == "__main__":
    resolve()



Measured memory_bytes: 9556
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
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 MOD = 1000000007;
const int INF = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
	string x;
	cin >> x;
	deque<char> q;
	rep(i, x.size()){
		if(x[i]=='S'){
			q.push_back('S');
		}else{
			if(q.size()&&q.back()=='S') q.pop_back();
			else q.push_back('T');
		}
	}
	int ans = q.size();
	cout << ans << endl;
}

Measured memory_bytes: 644
(let ((a (read))
      (b (read))
      (c (read))
      (k (read))
      (ans 0))
  (loop :for x :from 0 :upto a :do
    (loop :for y :from 0 :upto b :do
      (loop :for z :from 0 :upto c :do(if (= k (+ (* x 500) (* y 100) (* z 50)))
                                          (incf ans)))))
  (princ ans))

Measured memory_bytes: 12260
require "prime"
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
p=Prime.prime_division(N)
ans=0
p.each do|k,v|
    head=-1
    tail=v+1
    while tail-head>1
        mid=head+(tail-head)/2
        if mid*(mid+1)/2<=v
            head=mid
        else
            tail=mid
        end
    end
    ans+=head
end
puts ans

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

using namespace std;

typedef long long int ll;

void solve()
{
ll arr[5];
for(int i = 0; i < 5; i++)
{
	cin >> arr[i];
	if(arr[i] == 0)
	{
		cout << i  +1;
		return;
	}
}
}

int main()
{
	int t = 1;
//	cin >> t;
	while(t--)
	{
		solve();
	}
	return 0;
}



Measured memory_bytes: 3572
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
 
#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for(int i = x; i < n; i++)

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template <typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template <typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




int main()
{

    ld L;
    cin >> L;
    outset(10);
    cout << L*L*L/27 << endl;
    
    
    
    

    return 0;
}


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

int main()
{
    int a, b;
    cin >> a >> b;

    int ans = 0;
    ans = a-b*2;
    ans = max(ans, 0);

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

Measured memory_bytes: 3596
from collections import Counter 
import sys
def No():
    print("No")
    sys.exit()

def Yes():
    print("Yes")
    sys.exit()

N=int(input())
A = [int(i) for i in input().split()]
C=Counter(A)
if N%3==0:
    if len(C)==1:
        if C.get(0,0):
            Yes()
        else:No()
    if len(C)==2:
        if C.get(0,0) == N//3:
            Yes()
        else:No()
    if len(C)>3:No()
    if not all([v==N//3 for v in C.values()]):
        No()    
    bits = [format(a,"040b") for a in C.keys()]
    if all([z.count("0")%2 for z in zip(*bits)]):
        print("Yes")
    else:No()
else:
    if len(C)==1 and C.get(0,0):
        Yes()
    else:No()

Measured memory_bytes: 14460
#include <vector>

struct union_find {
    using size_type = std::size_t;
private :
    size_type _size;
    std::vector<int> node;
public :
    union_find (int n) : node(n, -1), _size(n) { }

    bool unite (int x, int y) {
        if ((x = root(x)) == (y = root(y))) return false;
        if (node[x] > node[y]) std::swap(x, y);
        node[x] += node[y];
        node[y] = x;
        _size--;
        return true;
    }

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

    int root (int x) {
        if (node[x] < 0) return x;
        return node[x] = root(node[x]);
    }

    size_type size (size_type x) {
        return (size_type(-node[root(x)]));
    }

    constexpr const size_type &size () const noexcept {
        return _size;
    }

};


#include <bits/stdc++.h>

int main() {
	int n, m;
	std::cin >> n >> m;
	union_find uf(n);
	for (int i = 0; i < m; i++) {
		int a, b;
		std::cin >> a >> b;
		uf.unite(--a, --b);
	}
	
	std::size_t ans = 0;
	for (int i = 0; i < n; i++) {
		ans = std::max(ans, uf.size(i));
	}
	
	std::cout << ans << '\n';
	
	return 0;
}

Measured memory_bytes: 4044
#include "bits/stdc++.h"

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1 << 30;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};

string s;
int n;

int main(void){
	cin>>s;
	n = s.size();

	ll ans = 0;
	for(int i=0;i < (1 << n - 1);i++) {
		ll sum = 0;
		ll a = s[0] - '0';

		for(int j=0;j<n - 1;j++) {
			if(i & (1 << j)) {
				sum += a;
				a = 0;
			}
			a = a * 10 + (s[j + 1] - '0');
		}
		sum += a;
		ans += sum;
	}

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

Measured memory_bytes: 256
#include <stdio.h>

int c10, c50, c100, c500;
int a10, a50, a100, a500;
int b_mon;
int a_mon;
int price;

int main(void) 
{
	scanf("%d",&price);

	while (price) {
		scanf("%d %d %d %d", &c10, &c50, &c100, &c500);
		b_mon = c10 * 10 + c50 * 50 + c100 * 100 + c500 * 500;
		a_mon = b_mon - price;

		a500 = a_mon / 500;
		a_mon %= 500;
		a100 = a_mon / 100;
		a_mon %= 100;
		a50 = a_mon / 50;
		a_mon %= 50;
		a10 = a_mon / 10;
		a_mon %= 10;

		if (a10 < c10) {
			printf("10 %d\n",c10 - a10);
		}
		if (a50 < c50) {
			printf("50 %d\n",c50 - a50);
		}
		if (a100 < c100) {
			printf("100 %d\n",c100 - a100);
		}
		if (a500 < c500) {
			printf("500 %d\n",c500 - a500);
		}
		scanf("%d",&price);
if (price) { puts(""); }
	}
	return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int D;
  cin >> D;
  
  if(D == 25){
    cout << "Christmas" << endl;
  }
  
  if(D == 24){
    cout << "Christmas Eve" << endl;
  }
  
   if(D == 23){
    cout << "Christmas Eve Eve" << endl;
  }
  
   if(D == 22){
    cout << "Christmas Eve Eve Eve" << endl;
  }
}


Measured memory_bytes: 256
# 2019/04/23
# AtCoder Beginner Contest 095 - C

# Input
n, x = map(int, input().split())
min = 10 ** 4
ans = 0
for i in range(n):
    m = int(input())
    if m < min:
        min = m
    ans += 1
    x -= m

ans += int(x / min)

print(ans)
    


Measured memory_bytes: 2940
n = int(input())
s = input()
en = s.count("E")
es = n - en
cnt = ans = en - (s[0] == "E") * 1
for i in range(1, n):
    if s[i] == "E": cnt -= 1
    if s[i - 1] == "W": cnt += 1
    if cnt < ans:
        ans = cnt
print(ans)


Measured memory_bytes: 3700
#include <stdio.h>

int main(void)
{
	int x, y, m, n, c;
	scanf("%d %d",&x,&y);
	m = x; n = y;
	while(y != 0)
	{
		c = x%y;
		x = y;
		y = c;
	}
	printf("%d\n",x);
	return 0;
}


Measured memory_bytes: 2080
while True:
    H,W = map(int,input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        for j in range(W):
            if i == 0 or j == 0 or i == H-1 or j == W-1:
                print('#', end='')
            else:
                print('.', end='')
        print()
    print()


Measured memory_bytes: 7004
a, b, c, x, y = map(int, input().split())
if c * 2 > a + b:
    print(a * x + b * y)
else:
    ans = c * 2 * min(x, y)

    z = x - min(x, y)
    if z > 0:  # Aを買い足す必要あり
        ans += min(a * z, 2 * c * z)

    z = y - min(x, y)
    if z > 0:  # Bを買い足す必要あり
        ans += min(b * z, 2 * c * z)
    print(ans)


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

#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")

const int INF = 1000000000;

#define vi vector<int>
#define ll long long int
#define vvi vector<vi>
#define pi pair<int,int>
#define vp vector<pi>
#define vvp vector<vp>
#define vl vector<ll>
#define vvl vector<vl>
#define pl pair<ll,ll>
#define vpl vector<pl>

#define sz(x) (int)x.size()
#define mp make_pair
#define pb push_back
#define fe first
#define se second
#define all(x) x.begin(),x.end()


int main()
{
    int n,k;
    cin >> n >> k;
    vector<ll> c(n,0);
    vector<ll> p(n,0);
    int fans = INT_MIN;
    bool all_neg = true;
    for(ll i=0;i<n;++i) { cin >> p[i]; }
    for(ll i=0;i<n;++i) { cin >> c[i]; fans = max(fans,int(c[i])); if(c[i]>0) all_neg = false; }
    for(ll i=0;i<n;++i) { p[i] -= 1; }
    if(all_neg){
        cout << fans << endl;
        return 0;
    }
    ll ans = 0; 
    for(ll i=0;i<n;++i){
        ll now = p[p[i]];
        ll cnt = 1;
        ll val = c[p[i]];
        ans = max(ans,val);
        // cout << now << endl;
        // cout << i << endl << endl;
        if(val==0) continue;
        while( now != p[i] && cnt < k ){
   
                val += c[now];
                ans = max(ans,val);
                cnt++;
                now = p[now];

        }
        if(now==p[i] && cnt!=k){
            ll rem = k%cnt;
            ll t= k/cnt;
            if(t>1){
            	ll _val_=val*(t-1);
            	ll cnt=1;
            	if(rem>0)
	                _val_ += c[p[i]];
	            ans = max(ans,_val_);
	            now = p[p[i]];
	            while( now != p[i] ){

	                    _val_ += c[now];
	                    ans = max(ans,_val_);
	                    cnt++;
	                    now = p[now];
	                }

	            }
            
            val *= (k/cnt);
            cnt = 1;
            if(rem>0)
                val += c[p[i]];
            ans = max(ans,val);
            now = p[p[i]];
            while( now != p[i] && cnt < rem ){
                    val += c[now];
                    ans = max(ans,val);
                    cnt++;
                    now = p[now];

            }
 }
    }
    cout << ans << endl;


    return 0;
}

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

int main() {
	int n;
	long long sum = 1, ans = 0;
	cin >> n;
	rep(i, n) {
		long long ai;
		cin >> ai;
		if (ai == 0) {
			cout << 0 << endl;
			return 0;
		}
		if (sum > 1000000000000000000 / ai) ans = -1;
		sum *= ai;
	}
	if (ans == -1) cout << -1 << endl;
	else cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#include <tuple>
#include <cassert>
#include <array>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using ti = tuple<int, int, int>;

#define REP(i,m,n) for(int i=(m); i<(n); i++)
#define RREP(i,n,m) for(int i=(n);i>=(m); i--)
#define pb push_back
#define mp make_pair
#define debug(x) cerr << #x << ": " << x << endl
// #define int long long 

const double eps=1e-14;
const int mod = 1e9 + 7;
const int inf = ((1<<30)-1);
const ll linf = (1LL<<60);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct mint 
{
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, y, z;
    cin >> x >> y >> z;
    swap(x,y);
    swap(x,z);
    cout << x << " " << y << " " << z << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k; cin >> n >> k;
    n = (n % 2 == 0 ? n / 2 : n / 2 + 1);
    if(n >= k) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;

const int MAXN = 1e6 + 10;
const int INF = 1e9 + 7;
int N;
char S[MAXN], T[MAXN];
int q[MAXN], ql, qr;
int ans;

int main() {
	register int i, j;
	scanf("%d%s%s", &N, S + 1, T + 1);
	j = N; ql = 1, qr = 0;
	bool ok = 1;
	for(i = 1; i <= N; ++i)
		ok &= S[i] == T[i];
	if(ok)
		return puts("0"), 0;
	for(i = N; i; --i) {
		if(T[i] == T[i - 1]) continue;
		j = min(j, i);
		while(j && T[i] != S[j]) --j;
		if(j == 0) return puts("-1"), 0;
		while(ql <= qr) {
			if(q[ql] - (qr - ql + 1) + 1 > i) ++ql;
			else break;
		}
		q[++qr] = j;
		if(i != j) ans = max(ans, (qr - ql + 1));
	}
	printf("%d\n", ans + 1);
	return 0;
}


Measured memory_bytes: 6016
#include <iostream>
#include <string.h>

using namespace std;

int main(void)
{
    char S[5];

    cin >> S;

    if(strcmp(S,"SUN")==0){
        cout << "7" << endl;
    }

    if(strcmp(S,"MON")==0){
        cout << "6" << endl;
    }

    if(strcmp(S,"TUE")==0){
        cout << "5" << endl;
    }

    if(strcmp(S,"WED")==0){
        cout << "4" << endl;
    }
    if(strcmp(S,"THU")==0){
        cout << "3" << endl;
    }

    if(strcmp(S,"FRI")==0){
        cout << "2" << endl;
    }

    if(strcmp(S,"SAT")==0){
        cout << "1" << endl;
    }

    return 0;
}

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

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

		
		String[] tmpList = String.valueOf(X).split("");
		
		int [] ch = new int[tmpList.length];
		
		for (int i = 0; i < tmpList.length; i++) {
			ch[i] = Integer.parseInt(tmpList[i]);
		}
		
		double result2 = java.util.Arrays.stream(ch).sum();
				
		double result = result2 % 9;
		
		if (result == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		
		
		
	}

}


Measured memory_bytes: 58420