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

const double pi = acos(-1);
#define INF 999999999
int main ()
{
    long long all=0,cnt=0,n,max=-INF,min=INF;
    vector<int>h(10000);
    vector<int>w(10000);

    for(int i=0;i<10000;i++){
        cin >> h.at(i) >> w.at(i);
        
        if(h.at(i)==0 && w.at(i)==0) break;
        cnt++;
    }

    for(int i=0;i<cnt;i++){
        for(int j=0;j<h.at(i);j++){
            for(int k=0;k<w.at(i);k++){
                cout << '#' ;
            }
            cout << endl;
        }

        cout << endl;
    }

    

    
}



Measured memory_bytes: 3172
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <iomanip>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
ll intpow(ll N, ll P){
    if(P==0) return 1;
    if(P%2==0){
        ll t = intpow(N, P/2);
        return t*t;
    }
    return N * intpow(N, P-1);
}
ll gcd(ll n,ll m){
    n = max(n,m);
    m = min(n,m);
    if(n%m == 0)return m;
    return gcd(m,n%m);
}
ll lcm(ll n,ll m){
    return n*m/gcd(n,m);
}
ll c_point(char c,ll r,ll s,ll p){//cに対して勝利
    if(c == 'r')return p;
    if(c == 's')return r;
    if(c == 'p')return s;
}
int main(){
    int n,k;cin>>n>>k;
    ll r,s,p;cin>>r>>s>>p;
    vector<vector<char>> t;
    t.resize(k);
    string T;
    cin>>T;
    ll sum = 0;
    rep(j,k){
        int cnt = 0;
        if(j+k>=n)sum += c_point(T[j],r,s,p);
        for(int i=0;j+i*k+k<n;i++){
            if(cnt%2 == 0 && T[j+i*k] != T[j+i*k+k]){
                sum += c_point(T[j+i*k],r,s,p);
                cnt = 0;
                if(j+i*k>=n-2*k)sum += c_point(T[j+i*k+k],r,s,p);
                }
            else if(cnt%2 == 0 && T[j+i*k] == T[j+i*k+k]){
                cnt++;
                sum += c_point(T[j+i*k],r,s,p);
                }
            else if(cnt%2 == 1 && T[j+i*k] == T[j+i*k+k]){
                cnt++;
                if(j+i*k>=n-2*k)sum += c_point(T[j+i*k+k],r,s,p);
            }
            else if(cnt%2 == 1 && T[j+i*k] != T[j+i*k+k]){
                cnt=0;
                if(j+i*k>=n-2*k)sum += c_point(T[j+i*k+k],r,s,p);
            }
            }
        }
    cout <<sum<<endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
// #include <iostream>
// #include <vector>
#define rep(i, j, k) for (int i = (int)j; i < (int)k; i++)
#define itrep(i, x) for (auto i = (x).begin(); i != (x).end(); i++)
#define Sort(x) sort((x).begin(), (x).end())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
//typedef std::pair<int,int> P;
int D     = 1;
int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};

using namespace std;

int main() {
    int M, T, PP, R;
    while (cin >> M >> T >> PP >> R && M) {
        vector<int> tim(T, 0);                                   //各チームの所用時間
        vector<vector<bool>> solve(T, vector<bool>(PP, false));  //チームごとに各問題が解けたかどうかをboolで
        vector<vector<int>> WA(T, vector<int>(PP, 0));           //チームごとに各問題を何回間違えたか

        rep(i, 0, R) {
            int m, t, p, r;
            cin >> m >> t >> p >> r;
            t--;
            p--;
            if (r == 0) {  //正解したら、その時のmを足してとsolveをtrueに
                solve[t][p] = true;
                tim[t] += m;
            } else
                WA[t][p]++;  //間違えたらWAを増やす
        }

        vector<int> solve_count(T, 0);  //チームごとに結局何問正解できたか
        //２重forで数えます
        rep(i, 0, T) {
            rep(j, 0, PP) {
                if (solve[i][j]) {
                    solve_count[i]++;
                    tim[i] += WA[i][j] * 20;
                }
            }
        }
        vector<pair<int, pair<int, int>>> rank;  //いよいよソートします。この配列は３つの値を持ち、<問題数、時間、チーム番号>で格納。
        /*ソート自体は昇順で行いますが、問題数は降順、時間は昇順、チーム番号は降順でソートしたいので、
        降順にしたいものにはマイナスをつけることで対処します。これにより、元の値が大きいほど値が小さくなるのでうまくいきます。
        */
        rep(i, 0, T) {
            rank.pb(MP(-solve_count[i], MP(tim[i], -(i + 1))));
        }
        Sort(rank);

        /*rep(i,0,T){
            cout<<rank[i].fi<<" "<<rank[i].se.fi<<" "<<-rank[i].se.se<<endl;
        }*/

        //最後に出力です。出力するものはrank[].se.seだけですが、マイナスをつけて格納しているのでマイナスをつけて出力します。
        rep(i, 0, T) {
            if (i) cout << ",";
            cout << -rank[i].se.se;
            while (i + 1 < T && rank[i].fi == rank[i + 1].fi && rank[i].se.fi == rank[i + 1].se.fi) {
                i++;
                cout << "=";
                cout << -rank[i].se.se;
            }
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3132
import numpy as np

MAX_DIGIT = 60
MOD = 10**9 + 7

N = int(input())
A = np.array([int(a) for a in input().split()])

answer = 0
for d in range(MAX_DIGIT + 1):
    A, r = (A>>1), A % 2
    s = int(r.sum())
    base = (1<<d) % MOD #this may be key
    answer += (base * s * (N - s)) % MOD

answer %= MOD
print(answer)


Measured memory_bytes: 48832
sub f{
	my $d=0;
	$_-$_[1]&&($d^=1+f($_,$_[0]))for@{$G[$_[0]]};
	$d;
}
<>;
/ /&&(push(@{$G[$`]},$'),push(@{$G[$']},$`))for<>;
print f(1,0)?Alice:Bob,$/

Measured memory_bytes: 113024
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define endl "\n"
typedef long long ll;
#define traceV(v) for(auto x:v)cout<<x<<" ";cout<<endl
#define traceM(mp) for(auto x:mp)cout<<x.first<<" "<<x.second<<endl
#define MOD 1000000007

//nの階乗を計算
int factorial(int n){
  int answer = 1;
  while(n > 1){
    answer *= n;
    n--;
  }
  return answer;
}
//組み合わせの数nCrを計算
int calcNumOfCombination(int n, int r){
  return factorial(n) / (factorial(r) * factorial(n-r));
}

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

  int N,M; cin>>N>>M;

  int res1;
  if(N<=1)res1=0;
  else res1 = N*(N-1)/2;
  int res2;
  if(M<=1)res2=0;
  else res2 = M*(M-1)/2;
  int res = res1+res2;
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype (i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype (i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype (i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,
mod=1000000007;
const double pi=3.1415926535897932,
eps=1e-6;
int n,kk,a[2005],cnt[2005],res[2005],ans;ll k;
int main()
{
    scanf("%d%d",&n,&kk);k=kk;
    rep(i,1,n) scanf("%d",a+i);
    rep(i,1,n) rep(j,1,n) if(a[j]>a[i]) cnt[i]++;
    rep(i,1,n) rap(j,1,i) if(a[j]>a[i]) res[i]++;
    rep(i,1,n) {
        ans+=(k*(k-1)/2%mod)*cnt[i]%mod;if(ans>mod)ans-=mod;
        ans+=k*res[i]%mod;if(ans>mod)ans-=mod;
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#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)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

const string YES = "Yes";
const string NO = "No";

int main()
{
    string S;
    cin >> S;
    REP(i, S.length() - 1) if (S[i] == 'A' and S[i + 1] == 'C')
    {
        cout << YES << endl;
        return 0;
    }
    cout << NO << endl;
    return 0;
}


Measured memory_bytes: 256
n = input()

s_list = []

for i in range(len(n)):
    if n[i] == '9':
        s_list.append('1')
    elif n[i] == '1':
        s_list.append('9')
    else:
        s_list.append(n[i])

print(s_list[0] + s_list[1] + s_list[2])


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

using namespace std;

int main() {
    string O, E;
    cin >> O >> E;
    
    int sz = O.size() + E.size();
    for (int i = 0; i < sz; i++) {
        if (i % 2) cout << E[i / 2];
        else cout << O[i / 2];
    }
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 256
use std::str::FromStr;

fn get_one<T : FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().parse().ok().unwrap();
}

fn get_vec<T : FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
}

fn main() {
    let v : Vec<i32> = get_vec();
    println!("{}", (v[0] + v[1]) % 24 )
}


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

using namespace std;

int pow(int x,int y){
	if(y==0) return 1;
	return pow(x,y-1)*x;
}

int make_max(int x,int y){

	int keta=pow(10,y-1);
	int ans=0;

	for(int i=9;i>=0;i--){
		for(int j=0;j<=y;j++){
			if((x/pow(10,j))%10==i){
				ans+=i*keta;
				keta/=10;
			}
		}
	}

	return ans;
}

int make_small(int x,int y){

	int keta=pow(10,y);
	int ans=0;

	for(int i=0;i<=9;i++){
		for(int j=0;j<=y;j++){
			if((x/pow(10,j))%10==i){
				ans+=i*keta;
				keta/=10;
			}
		}
	}

	return ans;
}

int main(){

	int x,l;
	vector<int> data;
	int i;

	while(1){
		cin>>x>>l;
		if(x==0&&l==0) break;
		if(!data.empty()) data.clear();

		data.push_back(x);
		i=1;
		while(1){
			x=make_max(x,l)-make_small(x,l);
			if(find(data.begin(),data.end(),x)!=data.end()){
				break;
			}
			data.push_back(x);
			i++;
		}
		cout<<distance(data.begin(),find(data.begin(),data.end(),x))<<" "<<x<<" "<<i-distance(data.begin(),find(data.begin(),data.end(),x))<<endl;
	}
 
}
 

Measured memory_bytes: 1224
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
A = LI()

tmp = 1000
stocks = 0
for i in range(N - 1):
    if A[i] < A[i + 1]: # 明日の方が高い　買う
        new_stocks = tmp // A[i]
        stocks += new_stocks
        tmp -= new_stocks * A[i]
    else:# 明日の方が安い　うる
        tmp += stocks * A[i]
        stocks = 0
tmp += stocks * A[-1]
print(tmp)



Measured memory_bytes: 10928
import java.util.*

fun gcd(a: Int, b: Int): Int {
    return if (a == 0) b else gcd(b % a, a)
}

fun findGCD(arr: IntArray, n: Int): Int {
    var result = arr[0]
    for (i in 1 until n)
        result = gcd(arr[i], result)
    return result
}
fun main(args: Array<String>)
{
    val scan = Scanner(System.`in`)
    var kotlin=scan.nextLine().toInt()
    var ans: Long=0
    for(i in 1..kotlin)
    {
        for(j in 1..kotlin)
        {
            for(k in 1..kotlin)
            {
                val x = arrayOf(i,j,k)
                    ans+=findGCD(x.toIntArray(),3)
            }
        }
    }
    println(ans)
}

Measured memory_bytes: 56964
/*"Everything in the universe is balanced. Every disappointment
   you face in life will be balanced by something good for you!
                Keep going, never give up."            */

#include "bits/stdc++.h"
using namespace std;

#define ll long long
const ll N=1e6+9;
const ll mod=1e9+7;

ll a[N];
ll dp[3003][3003];

ll go(int l, int r, int flag){
	if(l>r){
		return 0;
	}

	ll &ans = dp[l][r]; 
	if(ans!=-1)return ans;

	ans = 0 ;
	if(!flag){
		ans = max( go(l+1,r,1)+a[l], go(l,r-1,1)+a[r] );
	}
	else{
		ans = min( go(l+1,r,0), go(l,r-1,0) );
	}
	//cout<<l<<r<<flag<<" "<<ans<<"\n";
	return ans;
}

void solve()
{    
    ll n, m ,total=0;
    cin>>n;
    memset(dp,-1,sizeof dp);
    for(int i=1; i<=n; i++){
    	cin>>a[i];
    	total+=a[i];
    }

    ll x = go(1,n,0);
    cout<<x-(total-x);
}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll t=1;
    //pre();
    //cin>>t;
    while(t--)
    {
      solve();
    }  
}


// Xorawar

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

int main() 
{
    int N;
    cin>>N;
    vector<int>X(N);
    for (int i = 0; i < N; i++)
    {
        cin>>X[i];
    }
    
    priority_queue<int,vector<int>,greater<int>>Sum;

    for (int P = 1; P < 101; ++P)
    {
        int cash=0;
        for(int i=0;i<N;++i)
        {
            int x=X[i];
            cash += (x-P)*(x-P);
        }
        Sum.push(cash);
    }

    cout<<Sum.top()<<endl;


    return 0;
}

Measured memory_bytes: 3608
# -*- coding: utf-8 -*-
"""
Created on Sun May 10 20:54:30 2020

@author: Kanaru Sato
"""

n,m,x = list(map(int,input().split()))
costs = []
a = []
for i in range(n):
    _ = list(map(int,input().split()))
    costs.append(_[0])
    a.append(_[1:])

mincost = 10**9

for state in range(2**n):
    rikaido = [0 for i in range(m)]
    rikaishita = 1
    cost = 0
    for k in range(n):
        if (state&(1<<k))>>k:
            cost += costs[k]
            for i in range(m):
                rikaido[i] += a[k][i]
    for i in range(m):
        if rikaido[i] < x:
            rikaishita = 0
    if rikaishita == 1:
        mincost = min(mincost,cost)

if mincost == 10**9:
    print(-1)
else:
    print(mincost)

Measured memory_bytes: 9244
m=input().split()
N=int(m[0])
K=int(m[1])
S=list(input())

if S[K-1]=="A":
  S[K-1]="a"

if S[K-1]=="B":
  S[K-1]="b"

if S[K-1]=="C":
  S[K-1]="c"

SS=""
for i in range(N): 
  SS+=S[i]

print(SS)


Measured memory_bytes: 3060
#include <cmath>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <bitset>
#include <set>
const int inf=2147483647;
const int mo=1e9+7;	
const int N=105;
using namespace std;
int n,a[N],s[N],mx;
bool q=true;
int main()
{
	//freopen("agc005c.in","r",stdin);
	//freopen("agc005c.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),s[a[i]]++,mx=max(mx,a[i]);
	if(mx&1)
	{
		for(int i=mx;i>=mx/2+2;i--)
			if(s[i]<2) q=false;
		if(s[mx/2+1]!=2) q=false;
		for(int i=mx/2;i>=1;i--)
			if(s[i]) q=false;
	}
	else
	{
		for(int i=mx;i>=mx/2+1;i--)
			if(s[i]<2) q=false;
		if(s[mx/2]!=1) q=false;
		for(int i=mx/2-1;i>=1;i--)
			if(s[i]) q=false;
	}
	if(q) printf("Possible\n");
	else printf("Impossible\n");
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>
#include <deque>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;
Graph G;
const int AMAX = 100000;
/*int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}



int n;
vll a;

ll solve(bool isp)
{
	ll sum = 0ll;
	ll ret = 0ll;

	for (int i = 0; i < n; i++)
	{
		sum += a[i];
		if (isp and sum <= 0)
		{
			ret += -sum + 1;
			sum = 1ll;
		}
		if (not isp and sum >= 0)
		{
			ret += sum + 1;
			sum = -1ll;
		}
		isp ^= 1;
	}
	return ret;
}

*/


/*
 * 最大公約数計算
 */
int gcd(int a, int b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll N;
	cin >> N;
	
	ll sum = 0;
	for (int i = 1; i <= N; i ++)
	{
		for (int j = 1; j <= N; j++)
		{
			for (int k = 1; k <= N; k++)
			{
				sum += gcd(gcd(i, j), k);

			}
			

		}
	}
	
		cout << sum << endl;

	return 0;

	


}


Measured memory_bytes: 3616
from collections import defaultdict

import sys
sys.setrecursionlimit(10**6)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    n,k=mis()
    a=lmis()
    memo=defaultdict(int)
    for val in a: memo[val]+=1
    a_cnt=sorted(memo,key=memo.get)
    ans=0
    if k<len(memo):
        for i in range(len(memo)-k):
            ans+=memo[a_cnt[i]]
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 32556
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    VI a(n);
    REP(i,n) a[i] = in();
    int x = a[0];
    REP(i,n) x = __gcd(x, a[i]);
    cout << x << endl;

    return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;
import java.util.Stack;

public class Main {

	public static void main(String argsw[])
	{
		Scanner scan=new Scanner(System.in);
		Stack<Integer> stk=new Stack<Integer>();
		String eg=scan.next();
		long count=0;
		stk.add(eg.charAt(0)-'0');
		for(int i=1;i<eg.length();i++)
		{
			if( !stk.isEmpty() && (eg.charAt(i)-'0')!=stk.peek())
			{
				stk.pop();
				count+=2;
			}else {
				stk.add(eg.charAt(i)-'0');
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 28584
n, k = map(int, input().split())
Ps = list(map(int, input().split()))

import numpy as np

Ps = np.array(Ps)

Exp_each_p = (Ps + 1) /2

sum_Exp = [sum(Exp_each_p[0:k])]
if n == 1:
    print(sum_Exp[0])
else:    
    for id in range(1, n - k + 1):
        sum_Exp.append(sum_Exp[id - 1] - Exp_each_p[id - 1] + Exp_each_p[id + k - 1])

    print(max(sum_Exp))

Measured memory_bytes: 25060
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

template <class T>
struct Edge {
  using w_type = T;
  Edge(int u, int v, w_type w): u(u), v(v), w(w) { }
  int u, v;
  w_type w;
  bool operator<(const Edge<T> & rhs) const {
    if (w != rhs.w) { return w < rhs.w; }
    if (u != rhs.u) { return u < rhs.u; }
    return v < rhs.v;
  }
};

template <class Edge>
decltype(auto) AllPairsShortestPaths(const vector<Edge> & edges,
                 typename vector<Edge>::size_type node_num) {
  using size_type = typename vector<Edge>::size_type;
  using w_type = typename Edge::w_type;
  const w_type kInf = numeric_limits<int>::max();

  vector<vector<w_type>> adjacency_matrix(node_num, vector<w_type>(node_num, kInf));
  for (const auto & e: edges) {
    adjacency_matrix[e.u][e.v] = e.w;
  }
  for (unsigned i = 0; i < node_num; ++i) {
    adjacency_matrix[i][i] = 0;
  }

  unsigned m = 1;
  auto dist_m = adjacency_matrix;
  while (m < 2 * (node_num - 1)) {
    vector<vector<w_type>> dist_2m(node_num, vector<w_type>(node_num, kInf));
    for (unsigned i = 0; i < node_num; ++i) {
      for (unsigned j = 0; j < node_num; ++j) {
        for (unsigned k = 0; k < node_num; ++k) {
          if (dist_m[i][k] == kInf || dist_m[k][j] == kInf) { continue; }
          dist_2m[i][j] = min(dist_2m[i][j], dist_m[i][k] + dist_m[k][j]);
        }
      }
    }
    if (m >= node_num - 1 && dist_m != dist_2m) {
      return make_pair(false, dist_m);
    }
    dist_m = dist_2m;
    m *= 2;
  }

  return make_pair(true, dist_m);
}

int main(int argc, char const *argv[]) {
  using w_type = int;
  const w_type kInf = numeric_limits<w_type>::max();
  vector<Edge<w_type>> edges;
  unsigned V, E;
  cin >> V >> E;
  for (unsigned i = 0; i < E; ++i) {
    unsigned u, v;
    w_type w;
    cin >> u >> v >> w;
    edges.emplace_back(u, v, w);
  }

  auto ans = AllPairsShortestPaths(edges, V);
  auto have_neg_cycle = ans.first;
  auto dist = ans.second;
  if (!have_neg_cycle) {
    cout << "NEGATIVE CYCLE\n";
  } else {
    for (unsigned i = 0; i < V; ++i) {
      for (unsigned j = 0; j < V; ++j) {
        if (dist[i][j] == kInf) {
          cout << "INF";
        } else {
          cout << dist[i][j];
        }
        if (j == V - 1) {
          cout << "\n";
        } else {
          cout << " ";
        }
      }
    }
  }

  return 0;
}

Measured memory_bytes: 3280
#include "bits/stdc++.h"
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;++i)
#define END(x) (*(x.end()-1))

using namespace std;
typedef long long ll;
typedef vector<vector<int>> Graph;

template<typename T>
T gcd(T a, T b){
   if (a%b == 0){
       return(b);
   }
   else{
       return(gcd(b, a%b));
   }
}

template<typename T>
T lcm(T a,T b){
    return a*b/gcd(a,b);
}


template<typename T>
bool same(T x_b,T x_e,T y_b,T y_e){
    for(auto i = x_b, j = y_b; i != x_e && j != y_e;++i,++j){
        if(*i!=*j){
            return false;
        }
    }
    return true;
}

using Graph=vector<vector<int>>;//グラフ型
void dfs(const Graph &G,int v/*根*/,vector<bool> &seen){
    seen[v]=true;  //vを訪問済にする
    for(auto next_v:G[v]){ //訪問済にしたvとつながっている場所を順番に探す
        if(seen[next_v]) continue; //もし探索済みならスルー
        dfs(G,next_v,seen); //再帰的に探索
    }
}
 
void bfs(const Graph &G,queue<int> &que/*発見したが訪問はしていない*/,vector<int> &dist/*開始地点からの距離*/){
    while(!que.empty()){
        int v=que.front();//queのうち先頭のものからスタート
        que.pop();//先頭を削除
 
        for(int nv :G[v]){//vとつながっている点を列挙
            if(dist[nv]!=-1) continue;//発見済(=距離が格納されている)であればスルー
            dist[nv]=dist[v]+1;//vとつながっている点に距離の情報を追加
            que.push(nv);//vとつながっている点を発見済にする
        }
    }
}


int main(void){
    map<ll,ll>a;
    int n;
    cin>>n;
    int num;
    rep(i,n-1){
        cin>>num;
        a[num-1]++;
    }
    rep(i,n){
        cout<<a[i]<<endl;
    }
}
/*

*/


Measured memory_bytes: 16108
n = int(input())

cnt = 0
ans = ""
while n != 0:
    if n % 2 == 0:
        ans = "0" + ans
    else:
        ans = "1" + ans
        if cnt % 2 == 0:
            n -= 1
        else:
            n -= -1
    cnt += 1
    n //= 2
if len(ans) == 0:
    ans = "0"
print(ans)

Measured memory_bytes: 3060
from sys import stdin
n = int(stdin.readline().rstrip())
a = list(map(int, stdin.readline().rstrip().split()))

c = [0] * 9
for i in a:
    if i >= 3200:
        c[8] += 1
    else:
        for j in range(9):
            if 400 * j <= i <= 400 * j + 399:
                c[j] += 1

res = len([i for i in c[:-1] if i > 0])
print(1 if res == 0 else res, res + c[-1])

Measured memory_bytes: 3064
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define SREP(s,i,m) for(unsigned int i = s; i < m; ++i)
#define REP(i,m) SREP(0,i,m)

using namespace std;
#ifdef _MSC_VER
using LONG = __int64;
using ULONG = unsigned __int64;
#else
using LONG = long long int;
using ULONG = unsigned long long int;
#endif

using namespace std;

int main() {
    string s; int n;
    cin >> n >> s;
    int red = 0, blue = 0;
    for(int i = 0; i < s.size(); ++i) {
        if(s[i] == 'R') red++;
        else blue++;
    }
    cout << ((red > blue) ? "Yes" : "No") << endl;
    return 0;
}

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

const int MOD = 1e9 + 7;

int main() {
    string S;
    cin >> S;
    //cout << S << endl;

    int n = S.size();
    ll dp[n+1][13] = {};
    dp[0][0] = 1;

    int mul = 1;
    rep(i, n) {
        if (S[n-1-i] == '?') {
            rep(k, 10) {
                //int c = pow(10, i) * k;
                //c %= 13;
                int c = mul * k % 13;
                rep(j, 13) {
                    dp[i+1][j] += dp[i][(j+13-c)%13];
                    dp[i+1][j] %= MOD;
                }
            }
        } else {
            rep(j, 13) {
                //int c = S[n-1-i] - '0';
                //c *= pow(10, i);
                //c %= 13;
                int c = S[n-1-i] - '0';
                c *= mul;
                c %= 13;
                dp[i+1][j] += dp[i][(j+13-c)%13];
                dp[i+1][j] %= MOD;
            }
        }
        mul *= 10;
        mul %= 13;
    }
    cout << dp[n][5] << endl;
    /*
    rep(i, 13) cout << dp[0][i] << " ";
    cout << endl;
    rep(i, 13) cout << dp[1][i] << " ";
    cout << endl;
    rep(i, 13) cout << dp[2][i] << " ";
    cout << endl;
    rep(i, 13) cout << dp[3][i] << " ";
    cout << endl;
    */
}

Measured memory_bytes: 10624
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define nn 65536*4
#define lf double
vector<int> va[nn],vb[nn];
vector<pair<int,int> >ea;
int dep[nn];int n;int sa,sb;
int pa[nn];
void dfs(int x,int p)
{
	pa[x]=p;
	for(int i=0;i<vb[x].size();i++)
	{
		if(vb[x][i]==p) continue;
		dep[vb[x][i]]=dep[x]+1;		
		dfs(vb[x][i],x);
	}
}
int vis[nn];
void bfs(int st)
{
	queue<int> q,cq;
	vis[st]=1;q.push(st);
	int now=1;
	while(q.size() or cq.size())
	{
		if(q.size()==0)
		{
			swap(cq,q);
			now++;
		}
		int x=q.front();q.pop();
		for(int i=0;i<va[x].size();i++)
		{
			int y=va[x][i];if(vis[y]) continue;
			if(pa[y]==pa[x] or pa[y]==x or pa[x]==y or pa[pa[x]]==y or pa[pa[y]]==x)
			{
				if(dep[y]>now)
					vis[y]=1,cq.push(y);
			}
			else 
			{
				puts("-1");
				exit(0);
			}
		}
	}
}
int main()
{
	scanf("%d%d%d",&n,&sa,&sb);
	for(int i=1;i<n;i++)
	{
		int x,y;scanf("%d%d",&x,&y);
		va[x].push_back(y);va[y].push_back(x);
	}
	for(int i=1;i<n;i++)
	{
		int x,y;scanf("%d%d",&x,&y);
		vb[x].push_back(y);vb[y].push_back(x);
	}
	dfs(sb,0);//cout<<"k";
	bfs(sa);int ma=0;
	for(int i=1;i<=n;i++) if(vis[i]) ma=max(ma,dep[i]);
	cout<<ma*2;
	return 0;
} 

Measured memory_bytes: 39036
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>
#include <set>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#define REP(i, n) for(int i=0; i<n; i++)
#define REPR(i, n) for(int i=n; i>0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)
#define FORR(i, m, n) for(int i=m; i>=n; i--)
#define INF 1999999999
#define ll long long
#define VSORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
using namespace std;

#ifdef INPUT
stringstream input(R"(
314159265 358979323 84
)");
#define cin input
#endif

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

	REP(i, k)
	{
		if(i%2==0)
		{
			if(a%2==1)
			{
				a--;
				b += a/2;
				a = a/2;
			}
			else
			{
				b += a/2;
				a = a/2;
			}
		}
		else
		{
			if(b%2==1)
			{
				b--;
				a += b/2;
				b = b/2;
			}
			else
			{
				a += b/2;
				b = b/2;
			}
		}
	}
	cout << a << ' ' << b << endl;
	return 0;
}

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

int main()
{
    long long n, m, a[1010][3];
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> a[i][j];
        }
    }

    long long ans = -(1LL << 60);
    for (int i = 0; i < 8; i++) {
        vector<long long> v;
        for (int j = 0; j < n; j++) {
            long long t = 0;
            for (int k = 0; k < 3; k++) {
                if ((i >> k) & 1) t += a[j][k];
                else t -= a[j][k];
            }
            v.push_back(t);
        }
        sort(v.begin(), v.end());
        reverse(v.begin(), v.end());
        long long t = 0;
        for (int j = 0; j < m; j++) t += v[j];
        ans = max(ans, t);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    String aa = scan.next();
    String bb = scan.next();
    String cc = scan.next();
    int a = Integer.parseInt(aa);
    int b = Integer.parseInt(bb);
    int c = Integer.parseInt(cc);
    if (a < b && b < c || a == b && a < c || a == b && b == c) {
      System.out.println(a + " " + b + " " + c);
    } else if (a < c && c < b) {
      System.out.println(a + " " + c + " " + b);
    } else if (c < b && b < a) {
      System.out.println(c + " " + b + " " + a);
    } else if (c < a && a < b || a == c && b > a) {
      System.out.println(c + " " + a + " " + b);
    } else if (b < a && a < c) {
      System.out.println(b + " " + a + " " + c);
    } else if (b < c && c < a || b == c && b < a) {
      System.out.println(b + " " + c + " " + a);
    } else {
    }
  }
}

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

using namespace std;
const int N=1e5+5;

int n, k, R, S, P, dp[5][N], mx[N];
string x;

int main()
{

      cin >> n >> k >> R >>S >> P >> x;

      for (int i=0; i<x.size(); i++){
      int temp =  mx[i];

    if (i+1 >k)
    temp-=mx[i-k+1], dp[0][i]=max(dp[1][i-k],dp[2][i-k]), dp[1][i]=max(dp[0][i-k],dp[2][i-k]), dp[2][i]=max(dp[1][i-k],dp[0][i-k]);

      dp[1][i]+= temp, dp[2][i]+=temp, dp[0][i]+=temp;
        if (x[i]=='r') dp[2][i]+=P;
        if (x[i]=='s') dp[0][i]+=R;
        if (x[i]=='p') dp[1][i]+=S;
        mx[i+1]= max(dp[0][i], dp[1][i]), mx[i+1]=max(mx[i+1],dp[2][i]);
      }

      cout << mx[n];
    return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
#define all(v) v.begin(), v.end()

int main(){
  ll A,V,B,W,T;
  cin >> A >> V >> B >> W >> T;
  if(W>=V){
    cout << "NO" << endl;
    return 0;
  }
  if((V-W)*T>=abs(A-B)){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 3596
#include <stdio.h>

int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, -1, 0, 1, 1, -1, 1, -1};
int c[50][50];
int h, w;

void dfs(int x, int y);

int main (void) {

	int i, j;
	int linenum;

	while(1) {
		scanf("%d%d", &w, &h);
		
		if ((w == 0)&&(h == 0)) return 0;

		// syokika
		linenum = 0;

		for(i = 0; i < h; i++) {
			for(j = 0; j < w; j++) {
				scanf("%d", &c[i][j]);
			}
		}

		// dfs
		for(i = 0; i < h; i++) {
			for(j = 0; j < w; j++) {
				if (c[i][j] == 1) {
					dfs(j, i);
					linenum++;
				}
			}
		}
		
		printf("%d\n", linenum);

	}

	return 0;
}

void dfs(int x, int y) {
	int i;
	int j;

	c[y][x] = 0;

	for(i = 0; i < 8; i++) {
		int nx = x + dx[i];
		int ny = y + dy[i];

		if ((nx >= 0)&&(ny >= 0)&&(nx < w)&&(ny < h)) {
			if (c[ny][nx] == 1) {
				dfs(nx, ny);
			}
		}
	}

}

Measured memory_bytes: 680
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

using namespace std;
typedef long long ll;

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

int main() {
    int n;
    cin >> n;
    map<int, int> a;
    REP(i, n) {
        int b;
        cin >> b;
        a[b]++;
    }

    int res = 0;
    FOR(i,a) {
        int p[5];
        REP(j,5) {
            auto itr = a.find(i->first -2 +j);
            if (itr != a.end()) p[j] = itr->second;
            else p[j] = 0;
        }

        int x = p[0] + p[1] + p[2];
        int y = p[1] + p[2] + p[3];
        int z = p[2] + p[3] + p[4];
        res = max({res, x, y, z});
    }

    cout << res << endl;
}


Measured memory_bytes: 3200
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true) {
			int n = stdIn.nextInt();
			int m = stdIn.nextInt();
			
			if(n == 0 && m == 0) {
				break;
			}
		
			int[][] cost = new int[m+1][m+1];
			int[][] time = new int[m+1][m+1];
		
			for(int i = 0; i < m+1; i++) {
				for(int j = 0; j < m+1; j++) {
					cost[i][j] = 1000000000;
					time[i][j] = 1000000000;
					if(i == j) {
						cost[i][j] = 0;
						time[i][j] = 0;
					}
				}
			}
		
			for(int i = 0; i < n; i++) {
				int a = stdIn.nextInt();
				int b = stdIn.nextInt();
				int costA = stdIn.nextInt();
				int timeA = stdIn.nextInt();
			
				cost[a][b] = costA;
				cost[b][a] = costA;
			
				time[a][b] = timeA;
				time[b][a] = timeA;
			}
		
			for(int k = 0; k < m+1; k++) {
				for(int i = 0; i < m+1; i++) {
					for(int j = 0; j < m+1; j++) {
						cost[i][j] = Math.min(cost[i][j], cost[i][k]+cost[k][j]);
						time[i][j] = Math.min(time[i][j], time[i][k] + time[k][j]);
					}
				}
			}
		
			int k = stdIn.nextInt();
		
			for(int i = 0; i < k; i++) {
				int p = stdIn.nextInt();
				int q = stdIn.nextInt();
				int r = stdIn.nextInt();
			
				if(r == 0) {
					System.out.println(cost[p][q]);
				}
				else {
					System.out.println(time[p][q]);
				}
			
			}
		
		}
		
	}
}

Measured memory_bytes: 66036
import numpy as np
N, M = map(int, input().split())

S = []
for i in range(M):
    tmp = list(map(lambda s: int(s)-1, input().split()))
    S.append(tmp[1:])

P = list(map(int, input().split()))
P = np.array(P)



def f(fixed_l, res):
    if res == 0:
        ll = np.array(fixed_l)
        ss = 0
        for i in range(len(P)):
            p = P[i]
            if ll[S[i]].sum() % 2 == p:
                ss += 1
        return 1 if ss == M else 0
        

    a = f(fixed_l + [0], res-1)
    b = f(fixed_l + [1], res-1)
    return a + b

print(f([], N))


Measured memory_bytes: 12500
#include<stdio.h>
int main(void)
{
  int max, a,b,i,count=0,judge;
  scanf("%d%d%d",&max,&a,&b);
  for(i=1; i<=max; i++)
  {
    judge=i%10;
    judge=judge+(i/10)%10;
    judge=judge+(i/100)%10;
    judge=judge+(i/1000)%10;
    judge=judge+(i/10000)%10;
    if(judge>=a && judge<=b) count=count+i;
  }
  printf("%d",count);
  return 0;
}

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

int main(){
  long long a,b,c,d;
  cin >> a >> b >> c >> d; 
  if(a>=d){
    cout << d << endl;
    return 0;
  } else if(a+b>=d){
    cout << a << endl;
    return 0;
  } else {
    cout << a - d + a + b << endl; 
  }
}


Measured memory_bytes: 3544
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int a, b;
    int d;
    int r;
    double f;
    
    scanf("%d %d", &a, &b);
    d = a/b;
    r = a%b;
    f = (double)a/(double)b;
    printf("%d %d %f\n", d, r, f);
    
    return 0;
}

Measured memory_bytes: 636
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = [0] * (N + 1)
    if A[0] >= 2:
        print(-1)
        exit()
    if A[0] == 1:
        if len(A) == 1:
            print(1)
            exit()



        else:
            print(-1)
            exit()
    B[0] = 1
    ans = 1
    for i in range(1,N+1):
        tmp = 2 * (B[i-1] - A[i-1])
        if tmp < A[i]:
            print(-1)
            exit()
        elif tmp == A[i]:
            if i != N:
                print(-1)
                exit()

        B[i] = tmp
    ans += A[N]
    C = [0] * (N+1)

    C[N] += A[N]
    for i in range(N-1,0,-1):
        
        if C[i+1] + A[i] <= B[i]:
            ans += A[i] + C[i+1]
            C[i] = A[i] + C[i+1]
        else:
            ans += B[i]
            C[i] = B[i]
            
    print(ans)
        







if __name__ == "__main__":
    main()

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

using namespace std;

#define fore(i, s, e) for(int i = s; i < e; i++)
#define pb push_back

typedef long long ll;

typedef ll tc;
const tc is_query=-(1LL<<62); // special value for query
struct Line {
	tc m,b;
	mutable multiset<Line>::iterator it,end;
	const Line* succ(multiset<Line>::iterator it) const {
		return (++it==end? NULL : &*it);}
	bool operator<(const Line& rhs) const {
		if(rhs.b!=is_query)return m<rhs.m;
		const Line *s=succ(it);
		if(!s)return 0;
		return b-s->b<(s->m-m)*rhs.m;
	}
};
struct HullDynamic : public multiset<Line> { // for maximum
	bool bad(iterator y){
		iterator z=next(y);
		if(y==begin()){
			if(z==end())return false;
			return y->m==z->m&&y->b<=z->b;
		}
		iterator x=prev(y);
		if(z==end())return y->m==x->m&&y->b<=x->b;
		return (x->b-y->b)*(z->m-y->m)>=(y->b-z->b)*(y->m-x->m);
	}
	iterator next(iterator y){return ++y;}
	iterator prev(iterator y){return --y;}
	void add(tc m, tc b){
		iterator y=insert((Line){-m,-b});
		y->it=y;y->end=end();
		if(bad(y)){erase(y);return;}
		while(next(y)!=end()&&bad(next(y)))erase(next(y));
		while(y!=begin()&&bad(prev(y)))erase(prev(y));
	}
	tc eval(tc x){
		Line l=*lower_bound((Line){x,is_query});
		return l.m*x+l.b;
	}
};

const int N = 2e5 + 10;
int n;
ll c;
ll h[N];
ll dp[N];

int main() {
    cin >> n >> c;
    fore(i, 0, n) cin >> h[i];
    struct HullDynamic cht;
    dp[n - 1] = 0;
    for(int i = n - 2; i >= 0; i--) {
        cht.add(-2 * h[i + 1], dp[i + 1] + h[i + 1] * h[i + 1]);
        dp[i] = -cht.eval(h[i]) + h[i] * h[i] + c;
    } 
    // fore(i, 0, n) cout << dp[i] << " "; cout << endl;
    cout << dp[0] << endl;
    return 0;
}

Measured memory_bytes: 19840
import collections as col

N, K = map(int,input().split())
A = list(map(int,input().split()))
L = col.Counter(A).most_common()
ans = 0

if len(L) <= K:
    print('0')
    exit()

for i in range(K,len(L)):
    ans += L[i][1]

print(ans)


Measured memory_bytes: 39336
#include<cstdio>
const int N=55;
long long dp[N][N][N*N];
int n,a,x[N];
int main()
{
    scanf("%d %d",&n,&a);
    dp[0][0][0]=1;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&x[i]);
        dp[i][0][0]=1;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            for(int k=0;k<=N*j;k++)
            {
                if(k<x[i])
                    dp[i][j][k]=dp[i-1][j][k];
                else
                    dp[i][j][k]=dp[i-1][j][k]+dp[i-1][j-1][k-x[i]];
            }
        }
    }
    long long sum=0;
    for(int i=1;i<=n;i++)
        sum+=dp[n][i][a*i];
    printf("%lld",sum);
    return 0;
}

Measured memory_bytes: 66048
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n, a[210];
int main () {
	scanf ("%d", &n);
	for (int i = 1; i <= 2 * n; i++) scanf ("%d", &a[i]);
	sort (a + 1, a + 2 * n + 1);
	long long ans = 0;
	for (int i = 2 * n - 1; i >= 1; i -= 2) ans += a[i];
	printf ("%lld\n", ans);
	return 0;
}

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

int main() {
	int N;
	int L[15];
	int max = 0;
	int total = 0;

	cin >> N;

	for (int i = 1; i <= N; i++) {
		cin >> L[i];
		total += L[i];
		if (L[i] > max)
		{
			max = L[i];
		}
	}

	if (total - max > max) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val a = Array(n) { sc.nextInt() }
    val b = Array(n) { sc.nextInt() }
    val ab = (0 until n).map { a[it] to b[it] }.sortedBy { it.second }
    for (i in 0 until n) {
        a[i] = ab[i].first
        b[i] = ab[i].second
    }
    val ap = (0 until n).map { a[it] to it }.sortedBy { it.first }
    for (i in 0 until n) {
        if (ap[i].first > b[i]) {
            println("No")
            return
        }
    }
    val p = ap.map { it.second }
    var x = 0
    var len = 0
    do {
        x = p[x]
        len++
    } while (x != 0)
    if (len != n) {
        println("Yes")
        return
    }
    a.sort()
    for (i in 0 until n - 1) {
        if (a[i + 1] <= b[i]) {
            println("Yes")
            return
        }
    }
    println("No")
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


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

#define fi first
#define se second
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define repr(i, a, b) for (int i = (int)(a - 1); i >= b; i--)
#define rep(i, n) repl(i, 0, n)
#define each(itr, v) for (auto itr : v)
#define pb(s) push_back(s)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x " = " << x << endl
#define dbgv(i, a, v) \
  rep(i, a) { cout << v[i] << ((i < a - 1) ? ' ' : '\n'); }
#define maxch(x, y) x = max(x, y)
#define minch(x, y) x = min(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define INF INT_MAX / 3

string toArray(string a, string b) {
  if (a.size() == 0 || b.size() == 0) return "";
  int pr, qr, pi, pj, qi, qj;
  {
    int l = 1, i = 1;
    string s = a;
    while (l > 0 && i < s.size()) {
      if (s[i] == '(')
        l++;
      else if (s[i] == ')')
        l--;
      i++;
    }
    int j = i + 1, r = 0;
    while ('0' <= s[j] && s[j] <= '9') {
      r = r * 10 + (s[j] - '0');
      j++;
    }
    pr = r, pi = i, pj = j;
  }
  {
    int l = 1, i = 1;
    string s = b;
    while (l > 0 && i < s.size()) {
      if (s[i] == '(')
        l++;
      else if (s[i] == ')')
        l--;
      i++;
    }
    int j = i + 1, r = 0;
    while ('0' <= s[j] && s[j] <= '9') {
      r = r * 10 + (s[j] - '0');
      j++;
    }
    qr = r, qi = i, qj = j;
  }
  string ret = "(";
  ret += toArray(a.substr(1, pi - 2), b.substr(1, qi - 2));
  ret += ")[" + to_string(pr + qr) + "](";
  ret += toArray(a.substr(pj + 2, a.size() - pj - 3),b.substr(qj + 2, b.size() - qj - 3));
  return ret + ")";
}

int main() {
  cin.sync_with_stdio(false);
  string a, b;
  cin >> a >> b;
  cout << toArray(a, b) << endl;
  return 0;
}



Measured memory_bytes: 3428
#include<bits/stdc++.h>
using namespace std; 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
  	string s,t;
  	cin>>s>>t;
  	if(s == t.substr(0,s.length()))
       cout<<"Yes";
    else
       cout<<"No";
}

Measured memory_bytes: 3660
#include<stdio.h>

int main(){
  int ans=0;
  int a1,a2,a3,b1,b2,b3;
  int c[3][3];
  for (int i = 0; i < 3; i++){
    for (int j = 0; j < 3; j++){
      scanf("%d",&c[i][j]);
    }
  }

  for (int i = 0; i <= c[0][0]; i++)
  {
    a1=i;
    b1=c[0][0]-i;
    a2=c[1][0]-b1;
    b2=c[0][1]-i;
    a3=c[2][0]-b1;
    b3=c[0][2]-i;
    if (c[1][1]==a2+b2&&c[1][2]==a2+b3&&c[2][1]==a3+b2&&c[2][2]==a3+b3)
    {
      ans = 1;
    }
  }

  ans > 0 ? puts("Yes"):puts("No");

  return 0;
}

Measured memory_bytes: 1664
from collections import defaultdict
d = defaultdict(int)
w = input()

for i in w:
    d[i] += 1

t = True
for key, v in d.items():
    if (v % 2 == 0):
        continue
    else:
        t = False
        break

if t:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,X;
  cin >> N >> X;
  
  int m=0, minm=0;
  int sum=0;
  for (int i=0;i<N;i++) {
    cin >> m;
    sum += m;
    if (minm==0) minm = m;
    else minm = min(m,minm);
  }
  
  int cnt=N;
  cnt += (X-sum)/minm;
  cout << cnt << endl;
  
}

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

using namespace std;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    for (int i = a; i <= b; i++) {
        if (i%n == 0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M 1000000007
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
typedef pair<ll,ll> P;
typedef pair<P,P> PP;
int main(void){
	ll i,j,n,m;
	ll s,g,v,pp;
	ll ri[21][21];
	ll leng[21],flg[21];
	ll min,ki,sam;
	PP p[100];
	scanf("%lld %lld",&n,&m);
	for(i=0;i<m;i++) scanf("%lld,%lld,%lld,%lld",&p[i].ff,&p[i].fs,&p[i].sf,&p[i].ss);
	scanf("%lld,%lld,%lld,%lld",&s,&g,&v,&pp);
	//sort(p,p+m);
	for(i=0;i<=n;i++) for(j=0;j<=n;j++) ri[i][j]=M;
	for(i=0;i<m;i++) ri[p[i].ff][p[i].fs]=p[i].sf,ri[p[i].fs][p[i].ff]=p[i].ss;
	for(i=0;i<=n;i++) flg[i]=0,leng[i]=M;
	leng[s]=0;
	for(i=0;i<=n;i++){
		min=M;
		for(j=0;j<=n;j++){
			if(flg[j]==0&&leng[j]<min){
				min=leng[j];
				ki=j;
			}
		}
		flg[ki]=1;
		for(j=0;j<=n;j++){
			if(min+ri[ki][j]<leng[j]){
				leng[j]=min+ri[ki][j];
			}
		}
	}
	sam=leng[g];
	//printf("%d\n",leng[g]);
	for(i=0;i<=n;i++) flg[i]=0,leng[i]=M;
	leng[g]=0;
	for(i=0;i<=n;i++){
		min=M;
		for(j=0;j<=n;j++){
			if(flg[j]==0&&leng[j]<min){
				min=leng[j];
				ki=j;
			}
		}
		flg[ki]=1;
		for(j=0;j<=n;j++){
			if(min+ri[ki][j]<leng[j]){
				leng[j]=min+ri[ki][j];
			}
		}
	}
	//printf("%d\n",leng[s]);
	sam=v-pp-leng[s]-sam;
	printf("%d\n",sam);
	return 0;
}


Measured memory_bytes: 3188
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;

int N;
ll a[400000];
int main(){
  cin >> N;
  for(int i = 0; i < 3*N; i++)  cin >> a[i];
  sort(a, a+3*N); reverse(a, a+3*N);

  ll sum = 0;
  for(int i = 0; i < N; i++){
    sum += a[2*i+1];
  }
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 2560