akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

struct UnionFind {
    UnionFind(int n) {
        parent.resize(n, -1);
        weight.resize(n, 0);
    }
    int find(int x) {
        if (parent[x] < 0)
            return x;
        else
            return parent[x] = find(parent[x]);
    }
    bool isSame(int x, int y) { return find(x) == find(y); }
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) {
            weight[x]++;
            return;
        }
        if (parent[x] < parent[y])
            swap(x, y);
        parent[x] += parent[y];
        parent[y] = x;
        weight[x] += weight[y] + 1;
    }
    int getSize(int x) { return -parent[find(x)]; }
    int getWeight(int x) { return weight[find(x)]; }

private:
    vector<int> parent;
    vector<int> weight;
};

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> p(N);
    map<int, int> mp;
    for (int i = 0; i < N; i++) {
        cin >> p[i];
        p[i]--;
        mp[p[i]] = i;
    }

    UnionFind UF(N);
    for (int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        UF.unite(x, y);
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (UF.isSame(i, mp[i])) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 6144
import numpy as np
import itertools
N,C = map(int,input().split())
D = np.array([[int(x) for x in input().split()] for _ in range(C)])
c = np.array([[int(x) for x in input().split()] for _ in range(N)])
c -= 1
cls = np.zeros_like(c)

for i,j in itertools.product([0,1,2],[0,1,2]):
  cls[i::3,j::3] = (i+j)%3

# 色の分布 cls, color -> count
color_dist = np.zeros((3,C),dtype=np.int64)
for i in range(3):
  for j in range(C):
    color_dist[i,j] = ((cls == i) & (c == j)).sum()

min_cost = np.inf

for a,b,c in itertools.product(range(C),repeat = 3):
  if a == b or a == c or b == c:
    continue
  cost = 0
  cost += (color_dist[0] * D[:,a]).sum()
  cost += (color_dist[1] * D[:,b]).sum()
  cost += (color_dist[2] * D[:,c]).sum()
  min_cost = min(cost,min_cost)
  
print(min_cost)
  


Measured memory_bytes: 17428
import java.util.*;
import java.io.*;

class Main {

	void solve () {

		int n = in.nextInt(), a = in.nextInt(), b = in.nextInt();
		out.println(Math.min(n*a, b));
		
	}

	public static PrintWriter out = new PrintWriter(System.out);
	public static Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main().solve();
		out.flush();
	}

}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
#define inv(x) power(x,Mod-2)
#define upd(a,b) a=add(a,b)
using namespace std;
typedef long long ll;
const int Mod=1e9+7;
int add(int a,const int b){a+=b;if(a>=Mod)a-=Mod;return a;}
int sub(int a,const int b){a-=b;if(a<0)a+=Mod;return a;}
int mul(const int a,const int b){return (ll)a*b%Mod;}
int power(int x,int cs)
{
	int ras=1;
	while(cs)
	{
		if(cs&1) ras=mul(ras,x);
		x=mul(x,x);cs>>=1;
	}
	return ras;
}
const int N=3050;
int n,m,ans=0;
int dp[N*2][N][2];
int main()
{
	int i,j,sx;
	scanf("%d%d",&n,&m);
	for(i=0;i<=n;i++) dp[0][i][i==0]=1;
	for(i=0;i<m*2;i++)
	{
		sx=n;
		if(i&1) sx--;
		for(j=0;j<=sx;j++)
		{
			upd(dp[i+1][j][0],dp[i][j][0]);
			upd(dp[i+1][j][1],dp[i][j][1]);
			if(i&1) 
			{
				upd(dp[i+1][j+1][0],dp[i][j][0]);
				upd(dp[i+1][j+1][1],dp[i][j][1]);
			}
			else
			{
				if(j>0)
				{
					upd(dp[i+1][j-1][1],dp[i][j][1]);
					upd(dp[i+1][j-1][(j-1)==0],dp[i][j][0]);
				}
			}
		}
	}
	for(i=0;i<=n;i++) upd(ans,dp[m*2][i][1]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 143232
import java.util.*;
import java.util.function.*;
import java.math.*;
public class Main {
    public static void main(String[] args){
		Scanner s = new Scanner(System.in);
		int N = s.nextInt();
		int M = s.nextInt();
		
		int a, b;
		boolean[][] pass = new boolean[N+1][N+1];
		for(int i = 0; i < M; i++) {
			a = s.nextInt();
			b = s.nextInt();
			pass[a][b] = true;
			pass[b][a] = true;
		}
		
		int goal = (1<<N) - 1;
		
		int[] start = {1, 1}; // 0=現在地、1=通過点 1=1, 10=2, 100=3,,,10000000 = 8;
		Stack<int[]> S = new Stack<int[]>();
		S.add(start);
		
		int[] tmp;
		int result = 0;
		while(!S.isEmpty()) {
			tmp = S.pop();
			// 現在地からN通りのグラフを調査
			for(int i = 1; i < N; i++) {
				// i番目が通過済みであれば処理をスキップ
				if(((tmp[1]>>i)&1) == 1) {
					continue;
				}
				if(pass[tmp[0]][i+1]) {
					if((tmp[1] + (1<<i)) == goal) {
						result++;
						continue;
					}
					S.add(new int[] {i+1, tmp[1] + (1<<i)});
				}
			}
		}
		System.out.println(result);
    }
}

Measured memory_bytes: 25044
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define fo(i,n)         for(int i=0;i<n;i++)
#define Fo(i,k,n)       for(int i=k;i<n;i++) 
#define endl            "\n"
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define vec(x)          vector<x>
#define matrix(x)       vector<vector<x>>
#define mem(a,b)        memset(a, b, sizeof a)
#define vii             vector<pair<int,int>>
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define MOD             998244353
#define deb(x)          cerr <<#x<<" = "<<x<<"\n"
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(v)          v.begin(),v.end()
#define rep(i,a,b)      for (int i = a; i<b; ++i)
#define len(s)          s.length()
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
 
int power(int a,int b,int m=mod)
{int ans=1;while(b>0){if(b&1)ans=(ans*a)%m;a=(a*a)%m;b>>=1;}
return ans;}

void angshuGod()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

const int N = 1e5+1;
const double pi = acos(-1);

vector<string>grid;

void solve(){    

	int n,m,k;
	cin>>n>>m>>k;
	grid.resize(n);
	fo(i,n) cin>>grid[i];

	int ans = 0;
	for(int i = 0;i<(1<<n);i++){
		for(int j = 0;j<(1<<m);j++){
			int cnt = 0;
			for(int p = 0;p<n;p++){
				for(int q = 0;q<m;q++){
					if(i&(1<<p) || j&(1<<q)) continue;
					else if(grid[p][q]=='#') cnt++;
				}
			}
			if(cnt==k) ans++;
		}
	}

	cout<<ans<<"\n";

}

 
int32_t main()
{
    angshuGod();

    int t;

    t = 1;
    //cin>>t;

    while(t--){
        solve();
    }
    
    return 0;
}

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

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
// #define int long long

using namespace std;

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

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define eprintf(...) 42
#define dump(x) 42
#define debug(x) 42
#endif

typedef long long ll;

const ll MOD = 1e9 + 7;

void solve(int N, int K, string& S) {
    int answer = 0;
    int left = 0, right = 0;
    int count = 0;
    while (right < S.size()-1 && (count < K || S[right+1] == '1')) {
        if (S[right+1] == '1' && S[right] == '0') {
            count++;
        }
        right++;
    }

    answer = max(answer, right - left + 1);

    while (right < S.size()-1) {
        count = 0;
        while (right < S.size()-1 && (count < 1 || S[right+1] == '1')) {
            if (S[right+1] == '1' && S[right] == '0') {
                count++;
            }
            right++;
        }
        count = 0;
        while (left < S.size()-1 && count < 1) {
            if (S[left+1] == '1' && S[left] == '0') {
                count++;
            }
            left++;
        }

        answer = max(answer, right - left + 1);
    }

	stringstream ss;
    ss << answer;
	cout << ss.str() << '\n';

    return;
}

signed main() {
    int N, K;
    string S;
    cin >> N >> K >> S;

    solve(N, K, S);
    
    return 0;
}



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

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF (1 << 29)
#define LLINF (1LL << 60)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;

string to_string(string s) { return s; }
template <class S>
string to_string(unordered_set<S> s);
template <class S>
string to_string(set<S> s);
template <class S, class T>
string to_string(map<S, T> m);
template <class T>
string to_string(vector<T> v);

template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}

template <class S>
string to_string(unordered_set<S> s) {
  string ret = "{";
  for (S x : s) ret += to_string(x) + ",";
  return ret + "}";
}

template <class S>
string to_string(set<S> s) {
  string ret = "{";
  for (S x : s) ret += to_string(x) + ",";
  return ret + "}";
}

template <class S, class T>
string to_string(map<S, T> m) {
  string ret = "{";
  for (pair<S, T> x : m) ret += to_string(x) + ",";
  return ret + "}";
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < (int)v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() { cerr << endl; }

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  string S;
  cin >> S;
  int lastcheck = N, ans = 0;
  vector<int> his;
  for (int i = N; i > 0;) {
    int j = max(0, i - M);
    while (S[j] == '1' && j < lastcheck) ++j;
    if (j == lastcheck) {
      cout << -1 << endl;
      return 0;
    }
    lastcheck = i - M;
    his.push_back(i - j);
    i = j;
    ans++;
  }
  for (int i = his.size() - 1; i >= 0; --i) cout << his[i] << " ";
  cout << endl;
  return 0;
}

Measured memory_bytes: 1144
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

trait Joinable {
    fn join(self, sep: &str) -> String;
}

impl<U: ToString, T: Iterator<Item = U>> Joinable for T {
    fn join(self, sep: &str) -> String {
        self.map(|x| x.to_string()).collect::<Vec<_>>().join(sep)
    }
}
fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let N: usize = sc.get();
    let M: usize = sc.get();
    let mut ans = 0;
    if N > 1 {
        ans += N * (N-1) / 2;
    }
    if M > 1 {
        ans += M * (M-1) / 2;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    int n;
    int x=0;
    int sum=0;
    int s[100];
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> s[i];
        sum += s[i];
    }
    sort(s,s+n);
    if(sum % 10 != 0){
        cout << sum << endl;
        return 0;
    }
    else if(sum % 10 == 0){
        for(int i=0;i<n;i++){
            if(s[i] % 10 != 0){
                sum -= s[i];
                //cout << x << endl;
                cout << sum << endl;
                return 0;
            }
            x++;
        }
        //cout << x << endl;
        if(x >= n){
            cout << 0 << endl;
        }
    }
    return 0;
    
    
    
}

Measured memory_bytes: 256
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))

def htemp(h):
    return abs(a - ((t * 1000) - (h * 6)) / 1000)

ans = list(map(htemp, h))
ans1 = ans.index(min(ans)) + 1

print(ans1)


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

using namespace std;
using ll = long long;


int main()
{
    int n, a, b;
    string s;
    cin >> n >> a >> b >> s;
    int t = a + b;
    for(auto i : s){

        if(i == 'c'){
            cout << "No" << endl;
        }

        if(i == 'b'){
            if(b <= 0 || t <= 0){
                cout << "No" << endl;
                continue;
            }
            t--;
            b--;
            cout << "Yes" << endl;

        }

        if(i == 'a'){

            if(t <= 0){
                cout << "No" << endl;
            }else{
                cout << "Yes" << endl;
                t--;
            }
        }
    }
}

Measured memory_bytes: 896
n,a,b=list(map(int,input().split()))

p=10**9+7
ans1=1
ans2=1

for i in range(n-a+1,n+1):
    ans1*=i
    ans1%=p

for i in range(1,a+1):
    ans1*=pow(i,p-2,p)
    ans1%=p
    
for i in range(n-b+1,n+1):
    ans2*=i
    ans2%=p

for i in range(1,b+1):
    ans2*=pow(i,p-2,p)
    ans2%=p

print((pow(2,n,p)-ans1-ans2-1)%p)

Measured memory_bytes: 39280
#include<bits/stdc++.h>
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define per(i,s,t) for(int i=s;i>=t;i--)
#define N 110 

using namespace std;

typedef long long LL;
int f[N][210],w[N],v[N];
int n,ans,W;

int check(int num){
	if((LL)num*w[1]>W) return 0;
	int tw,ww=min(W-num*w[1],2*n),tans=0;
	memset(f,0,sizeof f);
	rep(i,1,n){
		tw=w[i]-w[1];
		per(j,num,1)
			rep(k,tw,ww){
				f[j][k]=max(f[j][k],f[j-1][k-tw]+v[i]);
				//printf("%d %d %d\n",j,k,f[j][k]);
			}
	}
	rep(k,0,ww) tans=max(tans,f[num][k]);
	return tans;
}

int main(){
	scanf("%d%d",&n,&W);
	rep(i,1,n) scanf("%d%d",&w[i],&v[i]);
	rep(i,1,n) ans=max(ans,check(i));
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
import sys
N,H=map(int,input().split())
A=[0]*N
B=[0]*N
for i in range(N):
    A[i],B[i]=map(int,input().split())

B.sort()
B.reverse()
a=max(A)
c=0
p=0
for i in range(N):
    if B[i]<a:
        if (H-p) % a == 0:
            print((H-p)//a+c)
        else:
            print((H-p)//a+c+1)
        sys.exit()
    p+=B[i]
    c+=1
    if p>=H:
        print(c)
        sys.exit()
else:
    if (H-p) % a == 0:
        print((H-p)//a+c)
    else:
        print((H-p)//a+c+1)

Measured memory_bytes: 46040
#include<bits/stdc++.h>
#define ll long long
#define cri const register int
#define re register
using namespace std;
const int mod=998244353;
inline int qpow(int a,int b,int ans=1){
	for(;b;b>>=1,a=1ll*a*a%mod) if(b&1) ans=1ll*ans*a%mod;
	return ans;
}
inline void fwt(int *A,cri bin,cri opt){
	for(int i=1;i<bin;i<<=1)
		for(int j=0;j<bin;j+=i<<1)
			for(int k=0;k<i;k++){
				cri x=A[j+k],y=A[j+k+i];
				A[j+k]=(x+y)%mod;A[j+k+i]=(x-y+mod)%mod;
			}
	if(opt) return;
	cri pw=qpow(bin,mod-2);
	for(int i=0;i<bin;i++) A[i]=1ll*A[i]*pw%mod;
}
int F[1<<18],n,A[1<<18],sum=0;
int main(){
	cin>>n;
	for(int i=0;i<1<<n;i++) scanf("%d",&A[i]),sum=(sum+A[i])%mod;
	sum=qpow(sum,mod-2);
	for(int i=0;i<1<<n;i++) A[i]=1ll*A[i]*sum%mod;
	A[0]=(A[0]+mod-1)%mod;F[0]=(1<<n)-1;
	for(int i=1;i<1<<n;i++) F[i]=mod-1;
	fwt(A,1<<n,1);fwt(F,1<<n,1);
	sum=0;
	for(int i=1;i<1<<n;i++) F[i]=1ll*F[i]*qpow(A[i],mod-2)%mod,sum=(sum+F[i])%mod;
	F[0]=mod-sum;
	fwt(F,1<<n,0);
	for(int i=0;i<1<<n;i++) printf("%d\n",F[i]);
}

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

using namespace std;

using ll = long long;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))


/**
 * Library
 * --------------------------------------------------------
 */
int colors[100005];
bool is_bipartite_graph(const Graph &graph, int v, int c) {
    colors[v] = c;
    for (int u: graph[v]) {
        if (colors[u] == c) {
            return false;
        }
        if (colors[u] == 0 && !is_bipartite_graph(graph, u, -c)) {
            return false;
        }
    }
    return true;
}
/**
 * --------------------------------------------------------
 */


/**
 * C - 3 Steps
 * https://code-festival-2017-qualb.contest.atcoder.jp/tasks/code_festival_2017_qualb_c
 */
void Main() {
    int N, M;
    cin >> N >> M;
    Graph graph(N);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    if (is_bipartite_graph(graph, 0, 1)) {
        int b = 0;
        rep(i, ARRAY_SIZE(colors)) {
            if (colors[i] == 1)b += colors[i];
        }
        int w = N - b;
        cout << (ll) b * w - M << '\n';
    } else {
        cout << (ll) N * (N - 1) / 2 - M << '\n';
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}


Measured memory_bytes: 7040
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define ld long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
#define MOD 1000000007
#define INF 1000000000000000007LL


const int N = 100005;
 
// it's swapnil07 ;)
 
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif

int ch(int x){
    for(int i=1; i<=15; i++){
        int cur = (i*(i+1))/2;
        if(x < cur){
            return i-1;
        }
    }
    return 0;
}

void solve(){
    int n; cin>>n;
    map<int, int> m;
    for(int i=2; i*i<=n; i++){
        while(n%i==0){
            n/=i;
            m[i]++;
        }
    }
    if(n>1){
        m[n]++;
    }
    int ans = 0;
    for(pii p: m){
        int x = p.S;
        ans += ch(x);
    }
    cout<<ans;
}


signed main()
{
    fast
    #ifdef SWAPNIL07
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    int t=1; 
    // cin>>t;
    while(t--){
        solve();
        cout<<"\n";
    }
    return 0;
}



Measured memory_bytes: 3656
import Data.Maybe
import qualified Data.ByteString.Char8 as B

readInt = fst . fromJust . B.readInt

main = do
 n <- readLn
 as <- map readInt . B.words <$> B.getLine
 let (as1,as23) = splitAt n as
 let (as2,as3) = splitAt n as23
 print (n3 n as1 as2 as3)

n3 n as1 as2 as3 = maximum (zipWith diff rq1s rq2s)
 where
  diff (rh,_) (rl,_) = rh - negate rl
  rh0 = sum as1
  rl0 = negate (sum as3)
  q1 = foldr push Empty as1
  q2 = foldr push Empty (map negate as3)
  rq1s = scanl (flip pushpop) (rh0,q1) as2
  rq2s = scanr pushpop (rl0,q2) (map negate as2)

pushpop a (r,q) = (r + a - top q', pop q')
 where q' = push a q

data Heap a = Empty | Node a [Heap a] deriving (Show, Eq)

merge Empty h = h
merge h Empty = h
merge (Node x xs) (Node y ys)
  | x < y     = Node x (Node y ys : xs)
  | otherwise = Node y (Node x xs : ys)

mergeList []       = Empty
mergeList [x]      = x
mergeList (x:y:xs) = merge (merge x y) (mergeList xs)

push x h = merge (Node x []) h

pop (Node _ xs) = mergeList xs

top (Node x _) = x

Measured memory_bytes: 198012
#include <iostream>
#include <vector>

using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;

void solve()
{
	int N;
	while(cin >> N, N)
	{
		int xMin = 0;
		int xMax = 0;
		int yMin = 0;
		int yMax = 0;
		vector<PP> Vec;
		Vec.push_back(PP(0, P(0, 0)));
		--N;
		int count = 0;
		while(N--)
		{
			int n, d;
			cin >> n >> d;
			++count;
			for(int i = 0; i < Vec.size(); ++i)
			{
				if(Vec[i].first == n)
				{
					if(d == 0)
					{
						Vec.push_back(PP(count, P(Vec[i].second.first - 1, Vec[i].second.second)));
						if(Vec[i].second.first - 1 < xMin)
						{
							xMin = Vec[i].second.first - 1;
						}
					}
					else if(d == 1)
					{
						Vec.push_back(PP(count, P(Vec[i].second.first, Vec[i].second.second - 1)));
						if(Vec[i].second.second - 1 < yMin)
						{
							yMin = Vec[i].second.second - 1;
						}
					}
					else if(d == 2)
					{
						Vec.push_back(PP(count, P(Vec[i].second.first + 1, Vec[i].second.second)));
						if(Vec[i].second.first + 1 > xMax)
						{
							xMax = Vec[i].second.first + 1;
						}
					}
					else if(d == 3)
					{
						Vec.push_back(PP(count, P(Vec[i].second.first, Vec[i].second.second + 1)));
						if(Vec[i].second.second + 1 > yMax)
						{
							yMax = Vec[i].second.second + 1;
						}
					}
					break;
				}
			}
		}
		cout << xMax - xMin + 1 << " " << yMax - yMin + 1 << endl;
	}
}

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

Measured memory_bytes: 1204
n = int(input())
m = list(map(int,input().split()))
ans = []
cou = 0

for i in range(n):
  while m[i] % 2 == 0:
    m[i] = m[i] / 2
    cou += 1
  ans.append(cou)
  cou = 0
print(min(ans))


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

int main() {
    ll n, k;
    cin >> n >> k;
    vl a(n);
    vvi pos(200000 + 1);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        pos[a[i]].push_back(i);
    }
    int curr = 0;
    ll loop  = 0;
    while (loop < k - 1) {
        auto it = upper_bound(pos[a[curr]].begin(), pos[a[curr]].end(), curr);
        if (it == pos[a[curr]].end()) {
            loop++;
            curr = pos[a[curr]].front() + 1;
        } else {
            curr = *it + 1;
        }
        if (curr == n) {
            loop++;
            loop += (k - 1 - loop) / loop * loop;
            curr = 0;
        }
    }
    vector<ll> ret;
    vi cnt(200000 + 1, 0);
    for (int i = curr; i < n; ++i) {
        ret.push_back(a[i]);
        cnt[a[i]]++;
        if (cnt[a[i]] == 2) {
            while (cnt[a[i]] > 0) {
                cnt[ret.back()]--;
                ret.pop_back();
            }
        }
    }
    print(ret);
    return 0;
}

Measured memory_bytes: 16500
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
using namespace std;

int main() {
	string S;
	bool flag = true;
	cin >> S;
	for (int i = S.size() - 1; i >= 0;)
	{
		if (i <= 3)flag = false;
		if (S[i] == 'm')
		{
			if (!(S[i - 1] == 'a'&&S[i - 2] == 'e'&&S[i - 3] == 'r'&&S[i - 4] == 'd'))flag = false;
			else i -= 5;
		}
		else if (S[i] == 'e')
		{
			if (!(S[i - 1] == 's'&&S[i - 2] == 'a'&&S[i - 3] == 'r'&&S[i - 4] == 'e'))flag = false;
			else i -= 5;
		}
		else if (S[i] == 'r'&&S[i - 1] == 'e'&&S[i - 2] == 'm')
		{
			if (!(S[i - 3] == 'a'&&S[i - 4] == 'e'&&S[i - 5] == 'r'&&S[i - 6] == 'd'))flag = false;
			else i -= 7;
		}
		else if (S[i] == 'r'&&S[i - 1] == 'e'&&S[i - 2] == 's')
		{
			if (!(S[i - 3] == 'a'&&S[i - 4] == 'r'&&S[i - 5] == 'e'))flag = false;
			else i -= 6;
		}
		else flag = false;
		if (!flag)break;
	}
	if (flag)cout << "YES";
	else cout << "NO";
}


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

signed main(){

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

  vector<vector<int>> g(n);
  for(int i = 0; i < m; i++){
    int u, v; cin >> u >> v;
    u--, v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }

  int ans = 0;
  for(int i = 0; i < n; i++){
    bool judge = true;
    for(int v : g[i]){
      //cout << i+1 << " " << v+1 << endl;
      if(h[v] >= h[i]) judge = false;
    }
    ans += (judge == true);
    //if(judge) cout << i+1 << endl;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 9852
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    A = list(map(int, input().split()))

    ans = [[-N] * (N+1) for _ in range(N+1)]
    a0, a1 = A[:2]
    ans[a0][a1] = 0
    ans[a1][a0] = 0
    ma = [-N] * (N+1)
    ma[a0] = 0
    ma[a1] = 0
    mama = 0
    add = 0
    for i in range(N-1):
        a, b, c = A[i*3+2:i*3+5]
        if a == b == c:
            add += 1
            continue
        Q = []
        for _ in range(3):
            a, b, c = b, c, a
            # choose 2
            Q.append((a, b, max(mama, ans[c][c] + 1)))
            # choose 1
            for j in range(1, N+1):
                val = ma[j]
                if b == c:
                    val = max(val, ans[b][j] + 1)
                Q.append((a, j, val))
        for i, j, val in Q:
            ans[i][j] = max(ans[i][j], val)
            ans[j][i] = max(ans[j][i], val)
            ma[i] = max(ma[i], val)
            ma[j] = max(ma[j], val)
            mama = max(mama, val)
    ANS = 0
    for i in range(1, N+1):
        for j in range(1, N+1):
            if i == j == A[-1]:
                ANS = max(ANS, ans[i][j] + 1)
            else:
                ANS = max(ANS, ans[i][j])
    print(ANS + add)


if __name__ == '__main__':
    main()


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

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

  if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) {
    cout << "Possible" << endl;
  } else {
    cout << "Impossible" << endl;
  }

}

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

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	if (a % 2 == b % 2) cout << "Alice";
	else cout << "Borys";
	return 0;
}


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

namespace _051_DifferentialII
{
	class Program
	{
		static void Main ( string[] args )
		{
			int dataCount = int.Parse (Console.ReadLine ());

			for (int lp = 0; lp < dataCount; lp++)
			{
				string inputStr = Console.ReadLine ();

				string max = new string (inputStr.OrderByDescending (item => item).ToArray ());
				string min = new string (inputStr.OrderBy (item => item).ToArray ());

				int maxValue = int.Parse (max);
				int minValue = int.Parse (min);

				Console.WriteLine (maxValue - minValue);
			}
		}
	}
}

Measured memory_bytes: 10048
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) ((a)<<(b))
#define Rshift(a,b) ((a)>>(b))
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define sz(a) int(a.size())
#define mset(x) memset(x, 0, sizeof(x))
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;


int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, x;
    cin >> n >> x;
    vector<int> in(n);
    int i;
    rep(i, n) { cin >> in[i]; }
    int ans(1);
    for (auto v: in) {
        if (v > x) break;
        x -= v;
        ans++;
    }
    cout << ans << endl;
}


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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
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; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;

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

int main(){

  ll n,h,w;cin>>n>>h>>w;

  // out(ceil((lb)n/h)*ceil((lb)n/w));
  out((n-h+1)*(n-w+1));



  return 0;
}


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

typedef long long int LLI;

int n;
LLI a, b;
string A, B;

string Convert(LLI x) {
  string s;
  while (x > 0) {
    if (x%2) s += '1';
    else s += '0';
    x /= 2;
  }
  reverse(s.begin(), s.end());
  return s;
}

LLI calc(string A, string B, int idx) {
  if (idx == n-1) {
    if (A[idx] == B[idx]) return 1;
    return 2;
  }

  if (A[idx] == B[idx]) return calc(A, B, idx+1);
  
  LLI cnt = 0; // 0 ~ 0
  for (int i=idx+1; i<n; i++) {
    cnt = ((cnt*2) + ('1'-A[i]));
  }
  cnt = (cnt+1);

  LLI cnt2 = 0; // 0 ~ 0
  LLI used = 0;
  for (int i=idx+1; i<n; i++) {
    if (B[i] == '1') used = 1;
    cnt2 = (cnt2*2 + used);
  }
  cnt2 = (cnt2+1);

  LLI cnt3 = 0; // 0 ~ 0
  bool add = false;
  bool undecided = true;
  char u = '0';
  for (int i=idx+1; i<n; i++) {
    if (B[i] == '1') u = '1';
    if (undecided) {
      if (u > A[i]) add = true;
      else if (u < A[i]) add = false;
      
      if (u != A[i]) undecided = false;
    }
    cnt3 = (cnt3*2 + (u-A[i]));
  }
  cnt3 = (cnt3+1);

  if (undecided) add = true;
  if (!add) cnt3 = 0;
  //printf("cnt: %lld\n", cnt);
  //printf("cnt2: %lld\n", cnt2);
  //printf("cnt3: %lld\n", cnt3);
  return (cnt*2+cnt2-cnt3);
}

int main() {
  scanf("%lld", &a);
  A = Convert(a);
  scanf("%lld", &b);
  B = Convert(b);
  n = max(A.size(), B.size());
  A = string(n-A.size(), '0') + A;
  B = string(n-B.size(), '0') + B;
  printf("%lld\n", calc(A, B, 0));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(x) (x).begin(),(x).end()
using namespace std;

//素因数分解
vector<pair<ll,int>> factorize(ll n){
    vector<pair<ll,int>>res;
    for(ll i=2;i*i<=n;i++){
        if(n%i)continue;
        res.emplace_back(i,0);
        while (n%i == 0)
        {
        n /= i;
        res.back().second++;
        }
        
    }
    if(n != 1) res.emplace_back(n,1);
    return res;
}

int main(){
    int N;
    cin >> N;
    int ans =0;
    if(N<=2)ans = 0;
    else {
        if(N%2==0)ans = (N-1)/2;
        else ans = N/2;
    }
    cout << ans << endl;
}

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

int main() {
  int A, B, C, X, ax, bx, cx, p = 0;
  cin >> A >> B >> C >> X;
  for (int a = 0; a <= A; a++) {
    ax = a * 500;
    for (int b = 0; b <= B; b++) {
      bx = ax + b * 100;
      for (int c = 0; c <= C; c++) {
        cx = bx + c * 50;
        if (cx == X) p++;
      }
    }
  }
  cout << p << endl;
}


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

using namespace std;

#define INF 1000000000
#define INFLL 0x3f3f3f3f3f3f3f3fLL 
#define EPS 10e-9
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define st first
#define nd second
#define sz(v) int(v.size())
#define all(X) (X).begin(), (X).end()
#define FOR(I, A, B) for(int I = A; I < B; I++)
#define RFOR(I, A, B) for(int I = A; I >= B; I--)

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<iii> viii;
typedef vector<ll> vll;

ll poww(ll a, ll e){
	if(e == 0) return 1;
	ll ans = poww(a, e/2);
	ans *= ans;
	ans %= MOD;
	if(e%2){
		ans *= a;
		ans %= MOD;
	}
	return ans;
}

ll invmod(ll x){
	return poww(x, MOD-2);
}

ll comb(ll a, ll n){
	ll ans = 1;
	for(ll i = n; i >= n-a+1; i--){
		ans *= i;
		ans %= MOD;
	}
	for(ll i = 1; i <= a; i++){
		ans *= invmod(i);
		ans %= MOD;
	}
	return ans;
}

ll sub(ll a, ll b){
	ll ans = a-b;
	if(ans < 0) ans+=MOD;
	return ans%MOD;
}

int main(){
	ll n, a, b;
	scanf("%lld %lld %lld", &n, &a, &b);
	ll ans = poww(2, n);
	ll tosub = 1 + comb(a,n) + comb(b,n);
	tosub %= MOD;
	ans = sub(ans,tosub);
	printf("%lld\n", ans);
	return 0;
}



Measured memory_bytes: 256
# [1〜A - 1のXOR]と[1〜BのXOR]のXORが答え
# mod 4が3になる数でXORは0になるので、A(B)より小さい最大の4の倍数からA(B)までのXORだけ取ればよい

import sys
readline = sys.stdin.readline

A,B = map(int,readline().split())
a = 0
for i in range(((A - 1) // 4) * 4,A):
  a ^= i
  
b = 0
for i in range((B // 4) * 4,B + 1):
  b ^= i

print(a ^ b)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define pb push_back
#define MOD 1000000007
#define ull unsigned long long
#define all(x) (x).begin(), (x).end()
#define read(a, n) for(ll i = 0;i<n;i++) cin>>a[i];
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define print(x) for(auto it:x) cout<<it<<" "; cout<<<"\n";
#define FileIO freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
const int INF = 1e9 + 5;

void solve() {
	int n, x, t;
	cin>>n>>x>>t;
	
	int ans = (n/x);
	if(n%x != 0) ans++;
	
	cout<<ans*t<<"\n";
}

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


Measured memory_bytes: 3628
n = int(input())
enemies = list(map(int, input().split()))
heros = list(map(int, input().split()))
total = 0
remain = enemies[0]
for i in range(len(heros)):
    if heros[i] < remain:
        remain = enemies[i+1]
        total += heros[i]
    else:
        e = remain + enemies[i+1]
        total += min(heros[i], e)
        remain = e - heros[i] if e > heros[i] else 0
print(total)


Measured memory_bytes: 82020
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> 
#include <cstring>
#include <queue>
#include <ctime>
#include <set>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const ll INF = 10e16;
const int maxN = 100010;
const int maxD = 400;
const int maxH = 100; 
const int len = 100000;

int a[maxN];
int b[maxN];
ll ps[maxN];
ll ss[maxN];
int sum[maxN];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		b[a[i]]++;
	}
	for(int i=2;i<len;i++)
	{
		sum[i] = b[i-1] + b[i] + b[i+1];
	}
	sum[0] = b[0] + b[1];
	sum[len] = b[len] + b[len-1];
	sum[len+1] = b[len];
	sort(sum,sum+2+len);
	printf("%d\n",sum[len+1]);
	return 0;
}  

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

ll f(ll h) {
  if (h == 1) {
    return 1;
  }
  return 1 + f(h / 2);
}

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

  ll H;
  cin >> H;
  if (H == 1) {
    cout << 1 << endl;
    return 0;
  }

  ll depth = f(H);
  ll ans = 0;
  REPI(i, 1, depth + 1) { ans += pow(2, i - 1); }
  cout << ans << endl;

  return 0;
}


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

using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  
  vector<vector<int> > matrix(n, vector<int>(m));
  vector<int> vec(m);
  
  int a, b;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      cin >> a;
      matrix.at(i).at(j) = a;
      
    }
  }
  
  for(int i = 0; i < m; i++){
    cin >> b;
    vec.at(i) = b;
  }
  
  int prd;
  for(int i = 0; i < n; i++){
    int ans = 0;
    for(int j = 0; j < m; j++){
      prd = matrix.at(i).at(j) * vec.at(j);
      ans += prd;
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3176
mod = 10 ** 9 + 7
n, k = map(int, input().split())
a_i = list(map(int, input().split()))
list.sort(a_i)
ans = 1
isminus = False
if k % 2 == 0:
    left = 0
    right = n - 1
else:
    left = 0
    right = n - 2
    ans *= a_i[n - 1]
if ans < 0: isminus = True
for x in range(k // 2):
    ans_L = a_i[left] * a_i[left + 1]
    ans_R = a_i[right] * a_i[right - 1]
    if (isminus == False and ans_L < ans_R) or (isminus == True and ans_L > ans_R):
        ans *= ans_R
        right -= 2
    else:
        ans *= ans_L
        left += 2
    if ans < 0 or ans >= mod: ans %= mod
print(ans)


Measured memory_bytes: 31624
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
 long long int arr[2*N];
 for(int i=0;i<2*N;i=i+2)
 {
     cin>>arr[i]>>arr[i+1];
 }
 double sum=0;
 for(int i=0;i<(2*N)-2;i=i+2)
 {
     for(int j=i+2;j<2*N;j=j+2)
     {double dis=sqrt(pow(arr[i]-arr[j],2)+pow(arr[i+1]-arr[j+1],2));
     sum=sum+dis;
         
     }
 }
 double  ans=(2*sum)/N;
 cout<<fixed<<setprecision(9)<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main (void) {
int h,a;
scanf("%d %d",&h,&a);
float c = (float)h/(float)a;
int d = h/a;
if (c==(float)d) printf("%d",d);
else if (c>(float)d) {d++;
printf("%d",d);}
return EXIT_SUCCESS;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		String S = scan.next();

		if (S.equals("AAA") || S.equals("BBB")) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}

	}

}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

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

    lint ans=0;

    REP(i, SZ(s)) { 
        if((i+1)%2==1){
            if(s[i]=='L'){
                ans += 1;
            }
        }else{
            if (s[i] == 'R')
            {
                ans += 1;
            }
        }
     }
    if(ans!=0){
        cout << "No" << "\n";
    }else{

        cout << "Yes"
             << "\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
const int maxn = 1e5+5;
int a[maxn],b[maxn];
ll sum[maxn][55];

int main()
{
    int n, m, k;
    cin >> n >> m >> k;
    swap(n ,m);
    swap(n, k);
    cout << n << " " << m << " " << k;
    return 0;
}


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

/* int main(){//A
int N;
cin>>N;
cout<<N*N*N<<endl;

    return 0;
}*/

/* int main(){//B
    int N;cin>>N;
    int s=0;
    int j=0;
    vector<int> A(N),B(N),C(N-1);
    rep(i,0,N) cin>>A[i];
    rep(i,0,N) cin>>B[i];
    rep(i,0,N-1) cin>>C[i];
    rep(i,0,N){
        if(j!=0&&A[i]==j+1) s+=C[j-1];
        s+=B[A[i]-1];
        j=A[i];
    }
    cout<<s<<endl;
    return 0;
}*/

int main(){//C
    int N;cin>>N;
    vector<int> B(N-1);
    rep(i,0,N-1) cin>>B[i];
    vector<int> A(N);
    int c=0;
    A[0]=B[0];
    //A[1]=A[0];
    rep2(i,1,N) {
        if(B[i-1]>B[i]) A[i]=B[i];
        else A[i]=B[i-1];
    }  
    A[N-1]=B[N-2];
    rep(i,0,N) c+=A[i];
    cout<<c<<endl; 
    return 0;
}


Measured memory_bytes: 256
N,Y=map(int,input().split())
answer=-1,-1,-1
for x in range(N+1):
    for y in range(N-x+1):
        z=N-x-y
        if 0<=z<=2000 and 10000*x+5000*y+1000*z==Y:
            answer=x,y,z
            break
    else:
        continue
    break
print(*answer)



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

int main()
{
	string S;cin>>S;
	long long n;cin>>n;
	long long ans=0;
	if(S.size()==1)
	{
		cout<<n/2<<endl;
		return 0;
	}
	for(long long i=1;i<S.size();++i)
	{
		long long l=1;
		while(S[i]==S[i-1])
		{
			l++;
			i++;
		}
		ans+=l/2;
		if(l==S.size()){
			cout<<(S.size()*n)/2<<endl;
			return 0;
		}
		if(l!=1){
		i--;
		//cout<<l<<endl;
		}
	}
	ans*=n;
	if(S[0]==S[S.size()-1]){
		long long r=1;
		for(long long i=0;S[i]==S[i+1];++i)r++;
		//cout<<"r="<<r<<endl;
		long long l=1;
		for(long long i=(long long)S.size()-1;S[i]==S[i-1];--i)l++;
		//cout<<"l="<<l<<endl;
		ans=ans-(r/2+l/2-(l+r)/2)*(n-1);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)a;i<=(sign)b;++i)
#define Fordown(i,a,b) for(register sign i=(sign)a;i>=(sign)b;--i)
const int N=1e5+5;
void cmax(sign &a,sign b){if(a<b)a=b;}
void cmin(sign &a,sign b){if(a>b)a=b;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
void file()
{
	#ifndef ONLINE_JUDGE
		freopen("a.in","r",stdin);
		freopen("a.out","w",stdout);
	#endif
}
cc_hash_table<int,int>mp;
int a[N],n,ans;
void work()
{
	n=read<int>();
	For(i,1,n)a[i]=read<int>(),mp[a[i]]++;
	For(i,1,n)
	{
		if(mp[a[i]]<a[i])ans+=mp[a[i]],mp[a[i]]=0;
		else ans+=mp[a[i]]-a[i],mp[a[i]]=a[i];
	}
	printf("%d\n",ans);
}
int main()
{
	//file();
	work();
	return 0;
}


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

#define all(v) v.begin(), v.end()
#define rep(i, n) REP1(i, 0, n)
#define REP1(i, x, n) for (int i = x; i < n; i++)
#define REP2(i, x, n) for (int i = x; i <= n; i++)
#define OP(x) cout << x << endl;
template<typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> void chmax(T& a, T b) { if(a > b) a = b; }
template<class T> void chmin(T& a, T b) { if(a < b) b = a; }
typedef long long ll;

int main() {
    int n; cin >> n;
    vector<int> L(n);
    rep(i, n) cin >> L[i];
    sort(all(L));
    int sum = 0;
    rep(i, n - 1) sum += L[i];
    if(L[n - 1] < sum) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back

using namespace std;

int main()
{
	int a,b,c,x;
	cin>>a>>b>>c>>x;
	int ans=0;
	for(int i=0;i<=a;i++)
	{
		for(int j=0;j<=b;j++)
		{
			for(int k=0;k<=c;k++)
			{
				if(500*i+100*j+50*k==x)
				{
					ans++;
				}
			}
		}
	}
	cout<<ans<<endl;
}


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

int main() {
  int n;
  double t, a;
  cout << fixed << setprecision(5);
  cin >> n >> t >> a;
  double min_a = 10000;
  int number = 0;
  for(int i = 0; i < n; i++){
    int x;
    cin >> x;
    double y = abs(a - (t - x * 0.006));
    if(y < min_a){
      number = i + 1;
      min_a = y;
    }
  }
  cout << number << endl;
}


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


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

    vector<int> l(m);
    vector<int> r(m);

    int i;
    for (i = 0; i < m; ++i)
    {
        cin >> l[i] >> r[i];
    }

    int ans = *(min_element(r.begin(), r.end())) - *(max_element(l.begin(), l.end())) + 1;
    if (ans < 0) ans = 0;

    cout << ans;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
long long a,b,c;
long long ab,ac,bc,Min;

int main()
{
std::ios::sync_with_stdio(false);
cin>>a>>b>>c;
ab=a*b;
ac=a*c;
bc=b*c;
Min=ab;
if(ab%2==0||ac%2==0||bc%2==0)
	 cout<<"0"<<endl;
else 
{if(Min>ac)
	Min=ac;
if(Min>bc)
	Min=bc;
	cout<<Min<<endl;
	

}
	return 0;

}

Measured memory_bytes: 256