akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll modpow(ll a, ll n){
  if(n==0)return 1;
  if(n%2==0){
    ll t=modpow(a,n/2);
    return t*t%MOD;
  }
  return a*modpow(a,n-1)%MOD;
}
ll modinv(ll a){
  return modpow(a,MOD-2);
}
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
 
    UnionFind(int n = 1) {
        init(n);
    }
 
    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;
    }
 
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
 
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
 
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};

    
  
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  COMinit();
  int a,b,c;
  cin >> a >> b >> c;
  if(a%2==0 || b%2==0)cout << "No" << endl;
  else cout << "Yes" << endl;
  
  
}


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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    string s;
    cin >> s;
    if (s == "ABC") print("ARC");
    if (s == "ARC") print("ABC");

    return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
using namespace std;

typedef ostringstream oss;
typedef istringstream iss;

struct Coin{
	Coin() {};
	Coin(int fh, int hd, int fy, int tn) : fh(fh), hd(hd), fy(fy), tn(tn){
	}
	int fh; //500
	int hd;	//100
	int fy;	//50
	int tn;	//10
	int calcNum(){
		return fh + hd + fy + tn;
	}
	int calcSum(){
		return fh * 500 + hd * 100 + fy * 50 + tn * 10;
	}
	Coin operator - (Coin c) {
		return Coin(fh - c.fh, hd - c.hd, fy - c.fy, tn - c.tn);
	}
	Coin operator + (Coin c) {
		return Coin(fh + c.fh, hd + c.hd, fy + c.fy, tn + c.tn);
	}
};

Coin GetChage(Coin pay, int price) {
	int chage = pay.calcSum() - price;
	Coin res(0, 0, 0, 0);
	
	while (chage / 500) {
		res.fh++;
		chage -= 500;
	}
	while (chage / 100) {
		res.hd++;
		chage -= 100;
	}
	while (chage / 50) {
		res.fy++;
		chage -= 50;
	}
	while (chage / 10) {
		res.tn++;
		chage -= 10;
	}

	return res;
}

int main(void) {
	int price;
	cin >> price;
	while (price) {
		Coin minAfterHold(20, 20, 20, 20);
		Coin hold;
		cin >> hold.tn >> hold.fy >> hold.hd >> hold.fh;

		// pay
		for (int fh = 0; fh <= hold.fh; fh++) {
			for (int hd = 0; hd <= hold.hd; hd++) {
				for (int fy = 0; fy <= hold.fy; fy++) {
					for (int tn = 0; tn <= hold.tn; tn++) {
						Coin Pay(fh, hd, fy, tn);
						if (price <= Pay.calcSum()) {
							Coin chage =  GetChage(Pay, price);
							Coin after = hold - Pay + chage;
							if (minAfterHold.calcNum() > after.calcNum()) {
								minAfterHold = after;
							}
						}
					}
				}
			}
		}

		// output
		Coin bestPay = hold - minAfterHold;
		if (bestPay.tn > 0) {
			printf("10 %d\n", bestPay.tn);
		}
		if (bestPay.fy > 0) {
			printf("50 %d\n", bestPay.fy);
		}
		if (bestPay.hd > 0) {
			printf("100 %d\n", bestPay.hd);
		}
		if (bestPay.fh > 0) {
			printf("500 %d\n", bestPay.fh);
		}

		cin >> price;
		if(price!=0){
			cout << endl;
		}
	}


	return 0;
}

Measured memory_bytes: 1180
from itertools import accumulate
from collections import defaultdict


def main():
    n = int(input())
    prime_counter = defaultdict(int)  # key ^ value
    acc = tuple(accumulate(range(1, 42)))  # because 10^12 < 2^39

    def facs():
        yield 2
        for x in range(10 ** 5 * 5):
            yield x * 2 + 3

    for fac in facs():
        count = 0
        while n % fac == 0:
            n //= fac
            count += 1
            # ここで if braek を入れると遅い？
        prime_counter[count] += 1
    if n != 1:
        prime_counter[1] += 1

    ans = 0
    for prime_count, count_count in prime_counter.items():
        for i, x in enumerate(acc):
            if prime_count < x:
                tmp = i
                break
        ans += tmp * count_count
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9456
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        a: u64,
        b: u64,
    }

    if (a+b) % 2 == 0 {
        println!("{}", (a+b)/2);
    } else {
        println!("IMPOSSIBLE");
    }
}

Measured memory_bytes: 4352
m, d = map(int, input().split())

ans = 0
for i in range(4, m+1) :
    for j in range(22, d+1) :
        d1 = j // 10
        d2 = j % 10
        if d2 < 2 :
            continue

        if d1 * d2 == i :
            ans += 1
            #print(d1, d2, i)

print(ans)


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

int main(){
	int a,b;
	cin >> a >> b;
	
	cout << max(a+b, max(a-b, a*b)) << endl;
    return 0;
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

int main() {

	string S;

	cin >> S;

	if (S == "ABC") {
		cout << "ARC";
	}
	else {
		cout << "ABC";
	}

	return 0;

}

Measured memory_bytes: 3596
/*#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include<bits/stdc++.h>
using namespace std;
# define ll long long
# define int long long  //comment it out when MLE
# define endl "\n"
#define gok ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//# define m 163577857
//# define MOD 163577857
# define pi acos(-1)
# define fi first
# define se second
#define REP(i,n) for (int i = 1; i <= n; i++)
const ll mod = 1000000007;
const int K = 2;
//typedef vector<vector<int> > matrix;
int add(int a, int b,int mod) {
    a%=mod;
    b%=mod;
	a += b;
	if (a >= mod) a -= mod;
	if(a<0)
    {
        a += mod;
        a %= mod;
    }
	return a;
}

int mul(ll a, int b,int mod) {
    a%=mod;
    b%=mod;
	a *= b;
	return a % mod;
}
int po(int a,int b,int mod)
{
    if(b==0)
        return 1;
    if(b%2==0)
        return po(mul(a,a,mod),b/2,mod);
    return mul(a,po(mul(a,a,mod),(b-1)/2,mod),mod);
}


ll fact[1000003];
ll inv[1000003];

void fact0()
{
	int i,j;
	fact[0]=1;
	for(i=1;i<=200000;i++)
	{
		fact[i]=i*fact[i-1]%mod;
	}
	inv[0]=1;
	inv[1]=1;
	ll p=mod;
	for (i=2; i<=200000; i++)
		inv[i] = (p - (p/i) * inv[p%i] % p) % p;

	for(i=2;i<=200000;i++)
	{
		inv[i]*=inv[i-1];
		inv[i]%=mod;
	}
}



signed main()
{
    gok
   //fact0();

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


vector<int> v;
bool ch[n+1] = {false};
int st=1;
while(!ch[st])
{
    v.push_back(st);
    ch[st]=true;
    st = a[st-1];
}
if(st==v[0])
{
   int id = k%v.size();
cout<<v[id];
return 0;
}
int cy=st,nst;
int an=-1;
//cout<<cy<<endl;
for(int i=0;i<v.size();i++)
    {
        if(cy!=v[i])
        {
            k--;
            if(k==0){
                 an = v[i+1];
                break;
            }
        }
        else
        {
            //k--;
            nst=i;
            break;
        }
    }
    if(k==0)
        cout<<an;
    else
    {
        vector<int> nv;
        for(int i=nst;i<v.size();i++){
            nv.push_back(v[i]);
         //cout<<v[i]<<" ";
        }
         int id = k%nv.size();
         cout<<nv[id];
    }



















 return 0;
}


Measured memory_bytes: 8752
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;

void main()
{
	int n = to!int(chomp(readln()));
	writeln(to!string((1+n)*n/2));
}

int[] stringText2IntArray(string text)
{
	return map!(to!int)(split(readln())).array;
}

Measured memory_bytes: 256
N = int(input())
name_list = [input() for i in range(N)]

M_list = []
A_list = []
R_list = []
C_list = []
H_list = []

for name in name_list:
    if name[0:1] == 'M':
        M_list.append(name)
    elif name[0:1] == 'A':
        A_list.append(name)
    elif name[0:1] == 'R':
        R_list.append(name)
    elif name[0:1] == 'C':
        C_list.append(name)
    elif name[0:1] == 'H':
        H_list.append(name)

M = len(M_list)
A = len(A_list)
R = len(R_list)
C = len(C_list)
H = len(H_list)

def cal(x,y,z):
    return x*y*z

print(cal(M,A,R)+cal(M,A,C)+
      cal(M,A,H)+cal(M,R,C)+
      cal(M,R,H)+cal(M,C,H)+
      cal(A,R,C)+cal(A,R,H)+
      cal(A,C,H)+cal(R,C,H))


Measured memory_bytes: 10776
using System.Linq;
using System.Collections.Generic;
using System;

public class P
{
    public List<int> from { get; set; }
    public List<int> to { get; set; }
}

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var e = int.Parse(line[1]);
        var d = new Dictionary<int, P>();
        for (int i = 0; i < n; i++) d[i] = new P { from = new List<int>(), to = new List<int>() };
        for (int i = 0; i < e; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var s = int.Parse(line[0]);
            var t = int.Parse(line[1]);
            d[s].to.Add(t);
            d[t].from.Add(s);
        }
        foreach (var x in tsort(d, n)) Console.WriteLine(x);
    }
    public static List<int> tsort(Dictionary<int, P> d, int n)
    {
        var ret = new List<int>();
        var q = new Queue<int>();
        for (int i = 0; i < n; i++) q.Enqueue(i);
        while (q.Count() > 0)
        {
            var w = q.Dequeue();
            if (d[w].from.Count == 0)
            {
                ret.Add(w);
                foreach (var x in d[w].to) d[x].from.Remove(w);
            }
            else q.Enqueue(w);
        }
        return ret;
    }
}




Measured memory_bytes: 15120
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define co(a) cout<<a<<endl
#define sz size()
#define bgn begin()
#define en end()
#define pb(a) push_back(a)
#define pop pop_back
#define V vector
#define P pair
#define V2(a,b,c) V<V<int>> a(b,V<int>(c))
#define V2a(a,b,c,d) V<V<int>> a(b,V<int>(c,d))
#define incin(a) int a; cin>>a
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
//#define min min<int>
//#define max max<int>
template<class T>
 void cou(vector<vector<T>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}
/*template<>
 void cou(vector<vector<char>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}*/
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 /*int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }*/
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
struct Union{
  vector<int> par;
  Union(int a){
	par= vector<int>(a,-1);
  }
  int find(int a){
    if(par[a]<0)
      return a;
    else
      return par[a]=find(par[a]);
  }
  bool same(int a,int b){
    return find(a)==find(b);
  }
  int Size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    a=find(a);
    b=find(b);
    if(a==b)
      return;
    if(Size(b)>Size(a))
      swap<int>(a,b);
    par[a]+=par[b];
    par[b]=a;
  }
};
int ketas(int a){
  string b=to_string(a);
  int c=0;
  fo(i,keta(a)){
    c+=b[i]-'0';
  }
  return c;
}
int gcm(int a,int b){
    if(b==0)
        return a;
    return gcm(b,a%b);
}
int lcm(int a,int b){
    return a/gcm(a,b)*b;
}
/*struct aa{
	vector<int> gt;
  aa(int n){
	gt= vector<int>(n, 1);
  }
	void c(V<int> d,int b){
	if(d[b]==0){
		gt[d[b]-1]++;
		gt[gt.sz-1]++;
	}
	else{
		gt[d[b]-1]++;
		c(d,d[d[b]]-1);
	}
}
void cok(int a){
	cout<<gt[a-1]<<endl;
	fo(i,a-1)
	cout<<gt[i]<<endl;
}
};
*/
signed main(){
	string a;
	cin>>a;
	cout<<700+((a[0]=='o')+(a[1]=='o')+(a[2]=='o'))*100<<endl;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
x=list(map(int,input().split()))

import bisect

b=bisect.bisect_left(x,0)

r=x[b:]
l=list(reversed(x[:b]))


R=len(r)
L=len(l)

ans=float('inf')

if k<=R:
    ans=min(ans,r[k-1])

if k<=L:
    ans=min(ans,abs(l[k-1]))

#右折り返し
for i in range(R):
    if i<k and k-i-2<=L-1 and k-i-2>=0:
        tmp=2*r[i] + abs(l[k-i-2])
        ans=min(ans,tmp)
#左折り返し
for j in range(L):
    if j<k and k-j-2<=R-1 and k-j-2>=0:
        tmp = 2*abs(l[j]) +r[k-j-2]
        ans=min(ans,tmp)


print(ans) 


Measured memory_bytes: 19896
#include <stdio.h>
 
int main(void){
  int i,e;
  static int n[26];
  char st,al[53] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
   
  do{
    e = scanf("%c", &st);
 
    for(i=0;i<52;i++)
      if(al[i] == st){
        n[ i%26 ]++;
      }
 
  }while(e != EOF);
 
  for(i=0;i<26;i++)
    printf("%c : %d\n", al[i] , n[i]);
 
  return 0;
}


Measured memory_bytes: 2760
#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)
using namespace std;
int_fast32_t nn, n, sqrtN;
int_fast64_t ans, d;
char c;
char wr[15];
char *w = wr;
main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> nn;
    const int_least32_t n = nn;
    if(n == 1){
        cout<<1;
        return 0;
    }
    const int_fast32_t sqrtN = sqrt(n);
    ans = -(int_fast64_t)(sqrtN) * (sqrtN + 1) * (2 * sqrtN + 1) / 6;
    for(int i = 1; i <= sqrtN; ++i) {
        const int_fast32_t a = n / i;
        ans += ((int_fast64_t)i * (i + a) * (a + 1 - i));
    }
    cout << ans;
}

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

const long long inf = 1e16;

int main(){
  long long L; cin >> L;
  vector<long long> A(L);
  for (int i=0; i<L; i++) cin >> A[i];
  vector<vector<long long>> dp(L+1, vector<long long>(5,inf));
  for (int i=0; i<5; i++) dp[0][i] = 0;
  for (int l=1; l<=L; l++){
    dp[l][0] = dp[l-1][0] + A[l-1];
    dp[l][1] = min(dp[l][0], dp[l-1][1] + ((A[l-1]==0)? 2:A[l-1]%2));
    dp[l][2] = min(dp[l][1], dp[l-1][2] + (A[l-1]+1)%2);
    dp[l][3] = min(dp[l][2], dp[l-1][3] + ((A[l-1]==0)? 2:A[l-1]%2));
    dp[l][4] = min(dp[l][3], dp[l-1][4] + A[l-1]);
  }
  cout << dp[L][4] << endl;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

string S;
void input(){
    fast_io();
    cin >> S;
}

bool kaibun(string t){
    for (int i = 0; i < t.length(); i++)
    {
        if(t[i]!=t[t.length()-1-i]) return false;
    }
    return true;
}

int solve(){
    int cntX = 0;
    string T = S;
    for (int i = 0; i < S.length(); i++)
    {
        if(S[i]=='x') {
            cntX++;
            S = S.substr(0,i)+S.substr(i+1);
            // if(i+1 < S.length()) S = S.substr(0,i)+S.substr(i+1);
            // else {S = S.substr(0,i); ans++;}
            i--;
        }
    }
    if(!kaibun(S)) {cout << -1 << endl; return 0;}
    int le=0,ri=T.length()-1;
    int ans = 0;
    while(le<ri){
        if(T[le]==T[ri]) {le++;ri--;}
        else{
            if(T[le]=='x'){
                le++;
                ans++;
            }
            if(T[ri]=='x'){
                ri--;
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}   

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

Measured memory_bytes: 824
#include <cstdio>
using namespace std;

int n;
int a, b, c, d;
int score[200], rank[200]={0};

int main(void)
{
    scanf("%d\n", &n);
    for(int i=0; i< n*(n-1)/2; i++) {
        scanf("%d %d %d %d", &a, &b, &c, &d);
        if(c > d)
            score[a] += 3;
        else if(c < d)
            score[b] += 3;
        else {
            score[a]++; score[b]++;
        }
    }
    for(int i=1; i<=n; i++) rank[i] = 1;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
            if(score[i] < score[j]) rank[i]++;

    for(int i=1; i<=n; i++)
        printf("%d\n", rank[i]);

    return 0;
}

Measured memory_bytes: 1032
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x) cout<<#x<<" = "<<(x)<<endl;
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int N,T; cin >> N >> T;
  int ans=INF;
  REP(i,N) {
    int c, t;
    cin >> c >> t;
    if (t > T) continue;
    ans = min(ans,c);
  }
  if (ans == INF) COUT("TLE");
  else COUT(ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<int64_t,int64_t> pll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second

void solve()
{
    ll m,ans=0,sum=0;;cin>>m;
    REP(i,m){
        ll d,c;cin>>d>>c;
        sum+=d*c;
        ans+=c;
    }
    ans--;
    ans+=(sum-1)/9;
    cout<<ans<<endl;
}
int main()
{
    cin.tie(0);
	ios::sync_with_stdio(false);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    int N,M,X,Y;
    cin >> N >> M >> X >> Y;

    vector<int> x(N),y(M);
    for ( int i = 0; i < N; i++ ) {
        cin >> x[i];
    }
    for ( int i = 0; i < M; i++ ) {
        cin >> y[i];
    }

    sort( x.begin(), x.end() );
    sort( y.begin(), y.end() );
    

    bool ans = false;
    for ( int z = X+1; z <= Y; z++ ) {
        if ( x[N-1] < z && y[0] >= z ) { ans = true; }
    }

    cout << ( ans ? "No War" : "War" ) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int h, w;
  cin >> h >> w;
  int mpt[10][10];
  for(int i=0; i<10; ++i) for(int j=0; j<10; ++j){
    cin >> mpt[i][j];
  }
  int t[10];
  for(int i=0; i<10; ++i) t[i] = mpt[i][1];
  mpt[1][1] = 0;
  for(int i=0; i<9; ++i){
    for(int j=0; j<10; ++j) for(int k=0; k<10; ++k){
      t[j] = min(t[j], mpt[j][k] + t[k]);
    }
  }
  
  int ans = 0;
  for(int i=0; i<h; ++i) for(int j=0; j<w; ++j){
    int x;
    cin >> x;
    if(x == -1) continue;
    ans += t[x];
  }
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int n,c;

int main()
{
    int m,d;
    cin>>m>>d;int ans=0;
    for(int i=1;i<=m;i++)
    {
        for(int j=20;j<=d;j++)
        {
             int temp=j;
             int t1,t2;
           t1=temp%10;
           temp/=10;
           t2=temp%10;

           if(t1*t2==i&&t1>=2&&t2>=2)
            { // cout<<i<<' '<<j<<endl;
                ans++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
typedef long long ll;
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>>;


int cnt_digit(ll N)
{
	int digit = 0;

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


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};



int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll a, b, c, k;
	cin >> a >> b >> c >>k;
	ll ans = 0;
	if (a >= k) {
		ans = k;
	}
	else if (a < k && a +b >= k) {
		ans = a;
	}

	else if (a+b < k && c>=k-(a+b)) {
		ans = a - (k - (a + b));
	}

	

	

	cout << ans << endl;
	
	
}

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

class Hello
{

    static void Main(string[] args)
    {
        int count = 0;
        var AB = (Console.ReadLine());
        var BB = Console.ReadLine();
        for (int i = 0; i < 3; i++)
        {
            if (AB[i] == BB[i])
            {
                count++;
            }
        }
        Console.WriteLine(count);
    }
}

Measured memory_bytes: 13140
#include<iostream>
    using namespace std;
    int a[101],b[101];
    int suma[101],sumb[101];
    int main()
    {
        int n;
        while(cin>>n){
            for(int i=0;i<n;i++){
                cin>>a[i];
            }
            for(int i=0;i<n;i++){
                cin>>b[i];
            }
            suma[0]=a[0];sumb[0]=b[0];
            for(int i=1;i<n;i++){
                suma[i]=suma[i-1]+a[i];
                sumb[i]=sumb[i-1]+b[i];
            }
            int maxn=suma[0]+sumb[n-1];
            for(int i=1;i<n;i++){
                int sum=suma[i]+sumb[n-1]-sumb[i-1];
                maxn=max(maxn,sum);
            }
            cout<<maxn<<endl;
        }
        return 0;
    }

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

int main() {
	int A[210];
	int N;
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}

	int counter = 0;
	while (true) {
		bool exist_odd = false;
		for (int i = 0; i < N; ++i) {
			if (A[i] % 2 != 0) {
				exist_odd = true;
			}
		}

		if (exist_odd) break;

		for (int i = 0; i < N; ++i) {
			A[i] /= 2;
		}
		++counter;
	}

	cout << counter << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(k,i,n) for(long long i=k;i<n;++i)
using namespace std;
typedef long long ll;
int main(void){
    // Your code here!
    ll X,A;
    cin>>X>>A;
    if(X<A){
        cout<<0<<endl;
    }else{
        cout<<10<<endl;
    }
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <fstream>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <time.h>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) (min(a,b) <= (x) && (x) <= max(a,b)) //hei
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007LL
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[4] = {
	{ -1 ,0 },{ 0 , 1 },{ 1 ,0 },{ 0 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)

struct Edge {
	int from, to;
	ll w;
	bool operator<(const Edge& rhs) const {
		return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to));
	}

};
typedef vector<vector<Edge>> Graph;

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

ll factorial(ll n) {//階乗
	ll ret = 1;
	rep(i, 1, n + 1)
		ret = (ret *i) % MODU;

	return ret;
}

ll mod_pow(ll x, ll n, ll mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x %mod;
		x = x * x%mod;
		n >>= 1;
	}
	return res;
}
ll divmod(ll a, ll b, ll m) { // a/b(mod m)
								  // a/b (mod m)
								  // a*b^-1
								  // b^-1 * b = 1
								  // b^(m-1) = 1 
								  // b^(m-2) * b = 1
								  // b^-1 = b^(m-2)

								  // a/b = a * b^(m-2)

	return (a * 1LL * mod_pow(b, m - 2, m)) % m;
}
ll ncr(ll n, ll r) {
	return divmod(factorial(n), (factorial(r) * (factorial(n - r))) % MODU, MODU);
}

int n;
string base;
bool quest(int from) { //True:base
	printf("?");
	REP(i, n) {
		printf(" %d", (from+ i) % (2*n) + 1);
	}
	cout << endl;
	string str;
	cin >> str;
	return str == base;
}

bool quest(int from, int ad) { //True:base
	printf("?");
	REP(i, n - 1) {
		printf(" %d", (from + i) % (2 * n) + 1);
	}
	printf(" %d", ad + 1);
	
	cout << endl;
	string str;
	cin >> str;
	return str == base;
}


array<int, 3> c[100001] = {};
int cc[100001] = {};
signed main() {
	int x;
	cin >> x;
	int dp[123456] = {};
	dp[0] = 1;

	REP(i, 100001) {
		if (dp[i] == 1) {
			dp[i + 100] = 1;
			dp[i + 101] = 1;
			dp[i + 102] = 1;
			dp[i + 103] = 1;
			dp[i + 104] = 1;
			dp[i + 105] = 1;
		}
	}
	cout << dp[x] << endl;
	return 0;
}


Measured memory_bytes: 768
#include <iostream>
using namespace std;
int main(){
int a,b,x;


	for(int j=1;j<=9;j++){
		a=j;
		for(int i=1;i<=9;i++){
		b=i;
		cout<<a<<"x"<<b<<"="<<a*b<<endl;
		
		}
	    }
}

Measured memory_bytes: 1116
N,X=map(int,input().split())
x=sorted(map(lambda x:int(x)-X if int(x)-X>0 else -(int(x)-X),input().split()))
for i in range(x[0]+1)[::-1]:
    if x[0]%i:continue
    if sum(map(lambda x:x%i,x))==0:
        print(i)
        break

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

#define ll long long
#define ld long double
#define FOR(x,y) for(ll i=x;i<=y;i++)
#define pb(x) push_back(x)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define matrix(x) vector<vector<x>>
#define vss vector<string>
#define PI (2*acos(0.0))
#define sqr(x) ((x)*(x))
#define sf(a)   scanf("%d",&a)
#define sfl(a)  scanf("%lld",&a)
#define sff(a,b)    scanf("%d %d",&a,&b)
#define sffl(a,b)   scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c)    scanf("%lld %lld %lld",&a,&b,&c)
#define ms(a,b) memset(a, b, sizeof(a))
#define ff  first
#define ss  second
#define lcm(a, b)   ((a)*((b)/__gcd(a,b)))
#define all(a)  a.begin(),a.end()
#define readfile freopen("input.txt","r",stdin);
#define writefile freopen("output.txt","w",stdout);
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define gap " "
#define mx 104
#define inf (ll)1e9
#define WHITE 1
#define GRAY 2
#define BLACK 3
#define EMPTY_VALUE -1
#define mod 1000000007
#define MOD(a,b) (a%b + b)%b

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


int main()
{
    //fastio
    ll n,d,x,y;
    sffl(n,d);
    ll cnt = 0;
    for(ll i=0;i<n;i++)
    {
        sffl(x,y);
        if((x*x+y*y)<=d*d) cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 3780
#include<bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long int ll;
typedef unsigned long long ull;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
typedef pair<ll,ll> P;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    map<int,int>mp;
    rep(i,n){
        cin>>a[i];
        mp[a[i]]++;
    }
    ll my=1000,kabu=0;
    rep(i,n){
        mp[a[i]]--;
        bool l=false,h=false;;
        for(int k=i+1;k<n;k++){
            if(a[i]>a[k]){
                l=true;
                if(h){
                    ll p =my/a[i];
                    kabu += p;
                    my-=a[i]*p;
                    break;
                }
                else{
                    my += a[i]*kabu;
                    kabu=0;
                    break;
                }
            }
            if(a[i]<a[k]){
                h=true;
                if(l){
                    my += a[i]*kabu;
                    kabu=0;
                    break;
                }
                else {
                    ll p =my/a[i];
                    kabu += p;
                    my-=a[i]*p;
                    break;
                }
            }
        }
        if(i==n-2 && a[i]<a[i+1]){
            int p =my/a[i];
            kabu += p;
            my-=a[i]*p;
        }
    }
    my+=kabu*a[n-1];
    cout<<my<<endl;
    return 0;
}


Measured memory_bytes: 3600
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int INF = 1001001001;
const ll LINF = 1e18;

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

int main() {
    int N; cin >> N;
    int a, idx = 0; vi as(N, 0);
    while(cin >> a){
        as[idx] = a;
      	idx++;
    }
    ll ret = 0;
    for(int i = 0; i < as.size(); i++)
        ret += as[i] - 1;
    
    cout << ret << endl;
    return 0;
}



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

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
int main(){
  int a,b;cin>>a>>b;
  Yes(((a%2) && (b%2)));
  return 0;
}


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

typedef long long int ll;

const ll maxn = 100010;

ll mp[maxn];
int main(){
	ll n;
	scanf("%lld",&n);
	ll sum = 0;
	for(ll i = 0; i < n; i++){
		ll temp;
		scanf("%lld",&temp);
		mp[temp]++;
		sum += temp;
	}
	
	ll q;
	
	scanf("%lld",&q);
	
	while(q--){
		ll b,c;
		
		scanf("%lld %lld",&b,&c);
		
		sum -= mp[b]*b;
		sum += mp[b]*c;
		mp[c] += mp[b];
		mp[b] = 0;
		printf("%lld\n",sum);
	}
}


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

int main(){
	int n,a,i,min,max;
	long long sum = 0;
	min = 1000001;
	max = -1000001;
	cin>>n;
	for (i = 0;i < n;i++){
		cin>>a;
		sum += a;
		if (min > a){
			min = a;}
		if (max < a){
			max = a;}
	}
	cout<<min<<" "<<max<<" "<<sum<<endl;
return 0;
}


Measured memory_bytes: 3116
def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools

    n = int(input())
    for i in range(int(math.sqrt(n)), 0, -1):
        if n % i == 0:
            print(i - 1 + n // i - 1)
            break



if __name__ == '__main__':
    main()

Measured memory_bytes: 3436
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>
#include <unordered_map>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;

int main(){
    int n;
    vector<int> p;
    cin >> n;
    for(int i = 0; i < n*n; i++){
        int j;
        cin >> j;
        p.push_back(j);
    }
    int mp[n+2][n+2];
    int done[n+2][n+2];
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            mp[i][j]=min(n-i,n-j);
            mp[i][j]=min(mp[i][j],i-1);
            mp[i][j]=min(mp[i][j],j-1);
            done[i][j] = 1;
        }
    }
    for(int i = 0; i <= n+1; i++){
        mp[i][0] = 0;
        mp[i][n+1] = 0;
        mp[0][i] = 0;
        mp[n+1][i] = 0;
    }
    
    ll ans = 0;
    int dir1[] = {1,0,-1,0};
    int dir2[] = {0,1,0,-1};
    for(int i = 0; i < n*n; i++){
        int h = p[i]/n +1;
        int w = p[i]%n;
        if(w == 0){
            w = n;
            h--;
        }
        ans+=mp[h][w];
        queue<pair<int,int> > bq;
        bq.push(make_pair(h,w));
        done[h][w] = 0;
        while(bq.size() > 0){
            auto pt = bq.front();
            bq.pop();
            int c = mp[pt.first][pt.second]+done[pt.first][pt.second];
            for(int j = 0; j < 4; j++){
                auto next = make_pair(pt.first+dir1[j],pt.second+dir2[j]);
                if(mp[next.first][next.second] > c){
                    mp[next.first][next.second] = c;
                    bq.push(next);
                }
            }
        }
    }

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

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  int a , b , c , x , y ;
  cin >> a >> b >> c >> x >> y ;
  intll ans = INF ;
  
 for(int i=0 ; i <300000;i+=2){
   intll now = 0;
   now += c*i ;
   now += max(0, x-(i/2)) * a ;
   now += max(0, y-(i/2)) * b ;
   
   ans = min(ans,now);
 }
  
  cout <<ans ; 

    
  
}


Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * a.cc: C: Candles
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int INF = 1 << 30;

/* typedef */

/* global variables */

int as[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", &as[i]);

  int mind = INF;
  for (int i = 0, j = k - 1; j < n; i++, j++) {
    int d;
    if (0 <= as[i]) d = as[j];
    else if (as[j] <= 0) d = -as[i];
    else d = (as[j] - as[i]) + min(-as[i], as[j]);
    if (mind > d) mind = d;
  }

  printf("%d\n", mind);
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){
int a,b,c,d,e,f,g,h,i,j;
cin>>a>>b>>c>>d;
cin>>e>>f>>g>>h;
i=a+b+c+d;
j=e+f+g+h;
if(i>j){
    cout<<i<<endl;
}else{
    cout<<j<<endl;
}

}


Measured memory_bytes: 3124
# 競プロ幼稚園に通う2人の子供がキャンディーの取り合いをしています。
# 3個のキャンディーパックがあり、それぞれのパックにはキャンディーがa,b,c個入っています。
# えび先生はこの3個のパックを、キャンディーの個数が等しくなるように2人に分けようとしています。そのような分け方が可能かどうかを判定してください。
# ただし、キャンディーをパックから取り出すことはできず、それぞれのパックをそのままどちらかの子供にあげる必要があります。

a,b,c =map(int,input().split())

if (a + b == c) or (a + c == b) or (b + c == a):
    print('Yes')

else:
    print('No')

Measured memory_bytes: 9100
#include <map>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long
#define N 100005
#define M 200005
map<ll, int>p;
map<ll, int>::iterator it;
int fat[N], siz[N], a[N], b[N], fir[N], nex[M], tar[M];
int n, cnt;
void Add(int a, int b)
{
	++cnt;
	tar[cnt] = b;
	nex[cnt] = fir[a];
	fir[a] = cnt;
}
ll wd[N], d[N];
void Dfs(int x, int dis)
{
    siz[x] = 1;
    d[1] += dis;
	for (int i = fir[x]; i; i = nex[i])
    {
		if (tar[i] != fat[x])
		{
			fat[tar[i]] = x;
			Dfs(tar[i], dis + 1);
			siz[x] += siz[tar[i]];
        }
    }
}
void Dfs(int x)
{
	for (int i = fir[x]; i; i = nex[i])
	{
		if (tar[i] != fat[x])
        {
            d[tar[i]] = d[x] + n - siz[tar[i]] * 2;
            Dfs(tar[i]);
        }
    }
}
int Getbel(int x)
{
	if (fat[x] == x)
		return x;
	return fat[x] = Getbel(fat[x]);
}
int main()
{
	scanf("%d",&n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%lld", &wd[i]);
		p[wd[i]] = i;
	}
	for (int i = 1; i <= n; i++)
	{
		fat[i] = i;
		siz[i] = 1;
	}
	it = p.end();
	for (it--; it != p.begin(); it--)
	{
		if (n - siz[it -> second] * 2 == 0 || !p.count(it -> first - (n - siz[it -> second] * 2)))
		{
			puts("-1");
			return 0;
		}
		cnt++;
		a[cnt] = it -> second;
		b[cnt] = p[it -> first - (n - siz[it -> second] * 2)];
		siz[fat[a[cnt]] = Getbel(b[cnt])] += siz[a[cnt]];
	}
	cnt = 0;
	for (int i = 1; i < n; i++)
	{
		Add(a[i], b[i]);
		Add(b[i], a[i]);
	}
	fat[1] = 0;
	Dfs(1, 0);
	Dfs(1);
	for (int i = 1; i <= n; i++)
	{
		if (wd[i] != d[i])
		{
			puts("-1");
		    return 0;
		}
	}
	for (int i = 1; i < n; i++)
		printf("%d %d\n", a[i], b[i]);
}

Measured memory_bytes: 17280
import java.util.*;

public class Main {
	Scanner sc;
	int r;
	
//=============
// constructor
//
	public Main() {
		sc = new Scanner(System.in);
	}
	
//==================
// instance methods
//
	void out(Object o) {
		System.out.println(o);
		System.out.flush();
	}
	
	public void exec() throws Exception {
		r = sc.nextInt();
		
		out(3*r*r);
	}
	
//======
// main
//
	public static void main(String[] args) throws Exception {
		Main m = new Main();
		m.exec();
	}

}

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

using namespace std;

#define X first
#define Y second
#define eps  1e-2
#define gcd __gcd
#define pb push_back
#define PI acos(-1.0)
#define lowbit(x) (x)&(-x)
#define bug printf("!!!!!\n");
#define mem(x,y) memset(x,y,sizeof(x))

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef unsigned long long uLL;

const int maxn = 1e5+7;
const LL  INF  = 1<<30;
const int mod  = 1e9+7;

int s[maxn];
int a[maxn*10];
int n;

void solve(){
    scanf("%d",&n);
    int sum = 0;
    for(int i=1;i<=n;i++){
        scanf("%d",&s[i]);
        sum += s[i];
    }
    int ans = sum - n;

    printf("%d\n",ans);
    return;
}

int main()
{
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
//    ios::sync_with_stdio(false);
    int cas = 1,t = 1;
    //scanf("%d",&t);
    while(t--){
    //    printf("Case %d: ",cas++);
        solve();
    }
    return 0;
}


Measured memory_bytes: 2304
#!/usr/bin/env ruby

def solve
  str = gets.chomp

  ans = str.to_i
  pos = Array.new(str.length - 1){|i| i+1}
  (str.length - 1).times do |i|
    pos.combination(i+1).each do |plus_positions|
      formula = str.dup
      plus_positions.reverse.each do |plus_pos|
        formula.insert(plus_pos, '+')
      end
      ans += eval(formula)
    end
  end

  puts ans
end

if $0 == __FILE__
  solve()
end


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

int main() {
    string s; cin >> s;
    deque<char> S(s.size());
    copy(s.begin(), s.end(), S.begin());    

    int Q; cin >> Q;
    bool is_rev = false;
    for (int i = 0; i < Q; i++)
    {
        int a; cin >> a;
        if(a==1) is_rev = !is_rev;
        else {
            int f; cin >> f;
            char c; cin >> c;
            if(f==1 && !is_rev || f==2 && is_rev) S.push_front(c);
            else S.push_back(c);
        }
    }
    s.resize(S.size());
    copy(S.begin(), S.end(), s.begin());
    if(is_rev) reverse(s.begin(), s.end());

    cout << s << endl;
}

Measured memory_bytes: 1280