akhauriyash/Code-Regression huggingface dataset:
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let H: usize = read();
    let W: usize = read();
    let map: Vec<Vec<char>> = (0..H).map(|_| read::<String>().chars().collect()).collect();
    let mut check_map = vec![vec![false; W]; H];
    use std::collections::VecDeque;
    let mut parts: Vec<Vec<char>> = vec![];
    for i in 0..H {
        for j in 0..W {
            if check_map[i][j] {
                continue;
            }
            let mut queue = VecDeque::new();
            queue.push_front((i, j));
            check_map[i][j] = true;
            let mut part = vec![];
            part.push(map[i][j]);
            while let Some((y, x)) = queue.pop_back() {
                for (add_y, add_x) in &[(1, 0), (-1, 0), (0, 1), (0, -1)] {
                    let y = y as i32;
                    let x = x as i32;
                    if y + add_y < 0
                        || y + add_y >= H as i32
                        || x + add_x < 0
                        || x + add_x >= W as i32
                        || check_map[(y + add_y) as usize][(x + add_x) as usize]
                        || map[y as usize][x as usize]
                            == map[(y + add_y) as usize][(x + add_x) as usize]
                    {
                        continue;
                    }
                    let y = (y + add_y) as usize;
                    let x = (x + add_x) as usize;
                    queue.push_front((y, x));
                    check_map[y][x] = true;
                    part.push(map[y][x]);
                }
            }
            parts.push(part);
        }
    }
    let sum = parts.into_iter().fold(0, |acc, part| {
        let black_count = part.iter().filter(|&&x| x == '#').count();
        let white_count = part.iter().filter(|&&x| x == '.').count();
        acc + black_count * white_count
    });
    println!("{}", sum)
}


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

typedef long long LL;

using std::min;
using std::max;

const int N=1e5+10,Inf=1e9+10;

struct Edge{ int to,next,cost; }way[N<<1];

int mc,son[N],n,num[N],tot,mson,wson;
LL ans;
bool flag;

void Build(int a,int b,int c) { way[++tot]=(Edge){b,num[a],c}; num[a]=tot; }

void Init() {
	scanf("%d",&n);
	int a,b,c;
	for (int i=2;i<=n;++i) {
		scanf("%d%d%d",&a,&b,&c);
		Build(a,b,c); Build(b,a,c);
	}
}

int Calc(int x,int y) { if (x==y) return x+y-1;else return min(x,y)<<1; }

void Dfs(int x,int fa) {
	son[x]=1;
	for (int i=num[x];i;i=way[i].next) {
		int v=way[i].to;
		if (v==fa) continue;
		Dfs(v,x);
		int w=Calc(son[v],n-son[v]); if (w&1) flag=1;
		ans+=1ll*way[i].cost*w;
		son[x]+=son[v];
	}
	int ms=max(son[x],n-son[x]);
	if (ms<mson || (ms==mson && son[x]>n-son[x])) mson=ms,wson=x;
}

void Solve() {
	ans=0ll; flag=0; mson=Inf; wson==0;
	Dfs(1,0);
	if (flag) printf("%lld\n",ans);
	else { 
		ans=0;
		Dfs(wson,0);
		mc=Inf;
		for (int i=num[wson];i;i=way[i].next) {
			int v=way[i].to;
			mc=min(mc,way[i].cost);
		}
		printf("%lld\n",ans-mc);
	}
}

int main() {
	Init();
	Solve();
	return 0;
}

Measured memory_bytes: 7424
#include <bits/stdc++.h>
using namespace std;
#define LL long int
#define ULL unsigned long int
#define LD long double

LL MOD = 1000000007;

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

    b *= 1000;

    LL ans = a * b / 1000;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3784
#include<stdio.h>

#define N 100

int main(){
  int M[N][N], n, x, y, i, j, num;
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      M[i][j] = 0;
    }
    scanf("%d",&num);
    scanf("%d",&x);
    if(x != 0){
      for(j = 0; j < x; j++){
	scanf("%d",&y);
	M[num-1][y-1] = 1;
      }
    }
  }
  for(i = 0; i < n; i++){
    for(j = 0; j < n-1; j++){
      printf("%d ",M[i][j]);
    }
    printf("%d\n",M[i][j]);
  }
  return 0;
}

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

// Union-Find木を利用
struct UnionFind {
    vector<int> par;

    UnionFind(int N) {
        par = vector<int>(N, -1);
    }

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

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        if (par[rx] > par[ry]) swap(rx, ry);
        par[rx] += par[ry];
        par[ry] = rx;
    }

    int size(int x) {
        return -par[root(x)];
    }
};

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

    UnionFind tree(N);
    for (int i = 0; i < M; i++) {
        int A, B;
        cin >> A >> B;
        tree.unite(A, B);
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        ans = max(ans, tree.size(i)); 
    }

    cout << ans << endl;
}

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

#define all(c) (c).begin(),(c).end()
#define allDESC(c) (c).begin(),(c).end(),greater<int>()
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define pb push_back
#define MAX 1000000000
#define mod 1000000007

int main(){
  int N,A,B;cin>>N>>A>>B;
  vector<int>a(N); rep(i,N)cin>>a[i];
  int mon[3];
  rep(i,3)mon[i]=0;
  rep(i,N){
    if(A >= a[i])mon[0]++;
    else if(B >= a[i])mon[1]++;
    else mon[2]++;
    
  }
  int mx = N;
  rep(i,3){
    mx = min(mx,mon[i]);
  }
  cout << mx << endl;
  return 0;
}

Measured memory_bytes: 256
I = input()

for i in range(len(I)):
    if 'a' <= I[i] <= 'z':
        print(I[i].upper(), end = '')
        continue
    if 'A' <= I[i] <= 'Z':
        print(I[i].lower(), end = '')
        continue
    print(I[i], end = '')
print()

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

#define fi first
#define se second
#define sc scanf
#define pr printf
#define pb push_back
#define ll long long
#define fin(s) freopen( s, "r", stdin );
#define fout(s) freopen( s, "w", stdout );

const long long N = 200100;
const long long MX = sqrt(N);
const long long H = 17;
const long long MAGIC = 1000;
const long long mod = 1e9 + 7;

using namespace std;

ll co(ll a, ll b, ll c)
{
        return max(max(a, b), c) - min(min(a, b), c);
}

ll f(ll h, ll w)
{
        ll ans = 1e15;
        for(ll i = 1; i < h; i++){
                ll g1 = (h - i) / 2, g2 = (h - i) - g1;
                if(g1 && g2){
                        ans = min(ans, co(i * w, g1 * w, g2 * w));
                }
                g1 = w / 2, g2 = w - g1;
                ans = min(ans, co(i * w, (h - i) * g1, (h - i) * g2));
        }
        return ans;
}

ll w;
ll h;

void solve()
{
        cin >> h >> w;
        ll ans1 = f(h, w), ans2 = f(w, h);
        cout << min(ans1, ans2) << endl;
}

bool mtest = false; int main()
{
        //fin("input.txt");
        //fout("output.txt");
        //fin("landscape.in");
        //fout("landscape.out");
        ios_base::sync_with_stdio(0);
        int TE = 1;
        if(mtest)
                cin >> TE;
        while(TE--)
                solve();
        return 0;
}


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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	long long N; cin >> N;
	long long A, B, C, D, E; cin >> A >> B >> C >> D >> E;
	long long minnum = min({A, B, C, D, E});

	long long ans = ((N + minnum - 1) / minnum) + 4;

	cout << ans << endl;



	return 0;

}


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

int main()
{
      ll n,m;
      cin>>n>>m;
  
      vector<ll>h(n);
      vector<int>to[1000005];
  
     for(int i=0;i<n;i++)
     {
        cin>>h.at(i);
     }

     for(int i=0;i<m;i++)
     {
         int a,b;
         cin>>a>>b;
         a--;b--;
         to[a].push_back(b);
         to[b].push_back(a);
     
     }
  
     bool goo;
    int cnt =0;
  
     for(int i=0;i<n;i++) 
     {    
          goo = true;
          int hig = h.at(i);
                          
          for(auto x:to[i])
          {
            if(hig<=h.at(x))
            {
                goo = false;
            }    
          }
       
       if(goo)
         cnt++;
       
     }
  
   
  
  cout<<cnt<<endl;
  
  return 0;
}


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

int main(void){
    int n;
    cin >> n;
    map<string,int> mp;
    for(int i=0;i<n;i++){
        string s;
        cin >> s;
        mp[s] = 1;
    }
    int count = 0;
    for(auto p: mp) count++;
    cout << count << endl;
}

Measured memory_bytes: 19200
s = gets.chomp
y = s[0..3].to_i
m = s[5..6].to_i
d = s[8..9].to_i

res = "Heisei"
if y > 2019
  res = "TBD"
end
if m > 4
  res = "TBD"
end
if d > 30
  res = "TBD"
end

puts res

Measured memory_bytes: 1916
N = int(input())
A = list(map(int, input().split()))

ans = 0
while max(A) >= N:
    i = A.index(max(A))
    k = A[i] // N
    A[i] %= N
    ans += k
    for j in range(N):
        if j != i:
            A[j] += k
print(ans)


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

int S;

void solve() {
  int s1 = S / 100, s2 = S % 100;
  if (1 <= s1 && s1 <= 12 && 1 <= s2 && s2 <= 12) {
    cout << "AMBIGUOUS\n";
    return;
  } else if ((!(1 <= s1 && s1 <= 12) && 1 <= s2 && s2 <= 12)) {
    cout << "YYMM\n";
    return;
  } else if (1 <= s1 && s1 <= 12 && !(1 <= s2 && s2 <= 12)) {
    cout << "MMYY\n";
    return;
  } else {
    cout << "NA\n";
    return;
  }
}

int main() {
  cin >> S;

  solve();
  return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
int32_t main()
{
	#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
	#endif

	int n;
	cin>>n;
	map<int,int> f;
	int x;
	for(int i=0;i<n;i++)
	{
		cin>>x;
		f[x]++;
	}

	int ans=0;

	for(auto i:f)
	{
		x=i.first;

		if(f[x]>=x)ans+=f[x]-x;
		else ans+=f[x];
	}

	cout<<ans;
	




	
}

Measured memory_bytes: 9448
#include <bits/stdc++.h>
#define pb push_back
#define tam 120000
#define se second
#define fi first
#define pitem item*
#define forr(i,p,n) for(int i=p;i<n;i++)
using namespace std;
typedef long long ll;
const ll MOD=1000000007 ;
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
typedef pair<int,int> ii;
typedef vector<vector<int> > vvi;
typedef  double lld;
int n,A,B;
ll dp[tam],v[tam];
ll f(int pos)
{
    if (pos==n-1)
        return 0;
    if (dp[pos]!=-1)
        return dp[pos];
    ll tot;
    tot=f(pos+1)+(v[pos+1]-v[pos])*A;
    tot=min(f(pos+1)+B,tot);
    return dp[pos]=tot;
}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>n>>A>>B;
    forr(i,0,n)
    {
        cin>>v[i];
    }
    memset(dp,-1,sizeof dp);
    cout<<f(0);


}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds; 
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define T pair<int, int>
#define ordered_set tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define MOD 1000000007
#define pb push_back 
#define ins insert
#define fast(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int m(int a) {
    return ((a%MOD)+MOD)%MOD;
}
int p(int a, int b) {
    if (b==0) return (int)1;
    int x = p(a, b>>1);
    if (b & 1) return m(x*m(a*x));
    return m(x*x);
}
signed main(){
    fast();
    int n;
    cin >> n;
    int ans = 0;
    ans += (n/500)*1000;
    n -= (n/500)*500;
    ans += (n/5)*5;
    cout << ans << endl;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int h, w, d, px[90005], py[90005], q, l, r, sum[90005];

int main() {
    cin >> h >> w >> d;
    rep(i, h)rep(j, w) {
        int a;
        cin >> a;
        px[a] = i+1;
        py[a] = j+1;
    }
    for (int i=d+1; i<=h*w; i++) {
        sum[i] = sum[i-d] + abs(px[i] - px[i-d]) + abs(py[i] - py[i-d]);
    }
    cin >> q;
    rep(i, q) {
        cin >> l >> r;
        cout << (sum[r] - sum[l]) << endl;
    }
    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define fr(i, j, k) for(register int i = j; i <= k; ++i)
#define gc ch = getchar()
int read(){
	int ret = 0, f = 1; char gc;
	while(!isdigit(ch) && (ch ^ '-'))gc;
	if(!(ch ^ '-'))f = -1, gc;
	while(isdigit(ch)){ret = (ret << 3) + (ret << 1) + (ch ^ '0'), gc;}
	return ret * f;
}
#undef gc
const int maxn = 1e5 + 10;
const int inf = 2147483647;
int n;
int a[maxn << 1];
int minn = inf, maxx = -inf;
bool small(int i, int j, int x){
	return a[i] <= x && a[j] <= x;
}
bool big(int i, int j, int x){
	return a[i] > x && a[j] > x;
} 
bool check(int x){
	for(int i = 0; i < n - 1; ++i){
		if(big(n + i, n + i + 1, x) || big(n - i, n - i - 1, x))return 0;
		if(small(n + i, n + i + 1, x) || small(n - i, n - i - 1, x))return 1;
	}
	return small(1, 1, x);
}
int main(){
	n = read();
	fr(i, 1, 2 * n - 1){
		a[i] = read();
		minn = min(a[i], minn);
		maxx = max(a[i], maxx);
	}
	int l = minn, r = maxx, ans = 0;
	while(l <= r){
		int mid = (l + r) >> 1;
		if(check(mid)){
			ans = mid;
			r = mid - 1;
		}
		else l = mid + 1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=1e6+5;
int main() {
    ll n,x,m;cin>>n>>x>>m;
    if(n==1) return cout<<x<<'\n',0;
    map<int,ll> pos,ps;
    pos[x]=1;ps[1]=x;
    ll now=x,sum=x;
    for(int i=2;i<=m+2;i++) {
    	now=now*now%m;sum+=now;
    	if(i==n) return cout<<sum<<endl,0;
    	if(pos[now]) {
    		ll need=n-pos[now]+1;
    		ll circle=i-pos[now];
    		return cout<<ps[pos[now]-1]+need/circle*(sum-ps[pos[now]])+ps[pos[now]+need%circle-1]-ps[pos[now]-1],0;
    	}else {
    		pos[now]=i;
    		ps[i]=sum;
    	}
    }
    return 0;
}

Measured memory_bytes: 9828
#include <iostream>
using namespace std;
	typedef long long int lli;
	const int MaxN=100005;
	typedef long long int lli;
int main(){
	lli N,M,i,j,p,q,res=0;
	cin>>N;
	for(i=-1000;i<=1000;i++){
		p=i*i*i*i*i;
		for(j=-1000;j<=1000;j++){
			q=j*j*j*j*j;
			if(p-q==N){
				cout<<i<<" "<<j<<"\n";
				return 0;
			}	
		}	
	}
}

Measured memory_bytes: 3124
#include<stdio.h>
int l[210],b;
int main(void) {
    int i,n,t,m[2],x;
    while(1){
        scanf("%d",&n);
        if(n==0){
            break;
        }
        for(i=1;i<=n*2;i++){
            l[i]=1;
        }
        for(i=1;i<=n;i++){
            scanf("%d",&t);
            l[t]=0;
        }
        m[0]=m[1]=n;
        x=0;
        b=0;
        while(m[0]>0&&m[1]>0){
            for(i=b+1;i<=n*2;i++){
                if(x==l[i]){
                    b=i;
                    l[i]=2;
                    m[x]--;
                    break;
                }
            }
            if(i>n*2){
                b=0;
            }
            x=!x;
        }
        printf("%d\n%d\n",m[1],m[0]);
    }
    return 0;
}

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

int main(){
	int n;
 	string s;
  	cin >> s;
  	cin >> n;
  	int memo = n;
  	
  	rep(i,0,s.size()){
		if(memo == n){
          memo = 0;
          cout << s[i];
        }
      	
      	memo++;
    }
  	cout <<endl;
	return 0; 
}

Measured memory_bytes: 256
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}


int main(){
	FIO
	
	int x;
	for(int _ = 1;; _++){
		cin >> x;
		if(x == 0)break;
		cout << "Case " << _ << ": " << x << "\n";
	}
	return 0;
}



Measured memory_bytes: 3120
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func getInput() (int, int) {
	sc.Split(bufio.ScanWords)

	sc.Scan()
	N, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	Y, _ := strconv.Atoi(sc.Text())

	return N, Y
}

func main() {

	main2()
	return

	N, Y := getInput()

	for x := 0; x <= N; x++ {
		for y := 0; y <= N-x; y++ {
			if 10000*x+5000*y+1000*(N-x-y) == Y {
				fmt.Printf("%d %d %d\n", x, y, N-x-y)
				return
			}
		}

	}

	fmt.Println("-1 -1 -1")
}

func main2() {
	N, Y := getInput()

	for x := Y / 10000; 0 <= x; x-- {
		for y := (Y - x*10000) / 5000; 0 <= y; y-- {
			if 10000*x+5000*y+1000*(N-x-y) == Y {
				fmt.Printf("%d %d %d\n", x, y, N-x-y)
				return
			}
		}
	}

	fmt.Println("-1 -1 -1")
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define last last2

using namespace std;

char s1[1000005],s2[1000005];

int solve1(int n) {
  int last=0,s=0;
  for(int i=1;i<=n+1;i++)
    if (i==n+1||s1[i]=='A') {
    	if (i-last>2||s1[i-1]=='B') s--;
    	else if (i-last>1&&last&&i<=n&&s1[i-1]=='C') s++;
    	last=i;
	}
  if (s>0) {
    int cnt=0;
    last=0;
    for(int i=1;i<=n;i++) {
    	if (s1[i]=='A') {
    	  if (s&&last&&i-last==2&&s1[i-1]=='C') {
    		  cnt-=2;
    		  if (s2[cnt]!='C') s2[++cnt]='C';
    		  s--; 
		  }
		  last=i;
	    }
    	s2[++cnt]=s1[i];
	}
	n=cnt;
	for(int i=1;i<=n;i++) s1[i]=s2[i];
    s1[n+1]='\0';
    //for(;;);
  }
  int cnt=0;s=0;
  for(int i=1;i<=n;i++)
    if (s1[i]=='B') s--;
    else if (s1[i]=='C') s++;
  last=0;
  for(int i=1;i<=n+1;i++)
    if (i==n+1||s1[i]=='A') {
    	if (i-last>1&&s&&(s1[last+1]!='B'||s1[i-1]!='B')&&(i-last>2||!last||i>n)) {
    		if (i-last==2) s--;
    		else if (s>1&&s1[last+1]=='C'&&s1[i-1]=='C') {
    			for(int j=last+2;j<i-1;j++) s2[++cnt]=s1[j];
    			s-=2;
			}
			else if (s1[last+1]=='C') {
				for(int j=last+2;j<i;j++) s2[++cnt]=s1[j];
				s--;
			}
			else {
				for(int j=last+1;j<i-1;j++) s2[++cnt]=s1[j];
				s--; 
			}
		}
		else {
			for(int j=last+1;j<i;j++) s2[++cnt]=s1[j];
		}
		if (i<=n) s2[++cnt]='A';
		last=i;
	}
  n=cnt;
  for(int i=1;i<=n;i++) s1[i]=s2[i];
  s1[n+1]='\0';
  return n;
}

int solve2(int n) {
  int cnt=0,s=0;
  for(int i=1;i<=n;i++)
    if (s1[i]=='A') s--;
	else if (s1[i]=='B') s++;
  int last=0;
  for(int i=1;i<=n+1;i++)
    if (i==n+1||s1[i]=='A') {
    	for(int j=last+1;j<i;j++)
    	  if (s1[j]=='B') {
    	  	if (s&&s2[cnt]=='C'&&(s2[cnt-1]!='A'||i>n||j!=i-1)) {
    	  		cnt--;
    	  		s--;
			  }
			else s2[++cnt]='B';
		  }
		  else {
    	  	if (s&&s2[cnt]=='B'&&(s2[cnt-1]!='A'||i>n||j!=i-1)) {
    	  		cnt--;
    	  		s--;
			  }
			else s2[++cnt]='C';
		  }
		if (i<=n) s2[++cnt]='A';
		last=i;
	} 
  n=cnt;
  for(int i=1;i<=n;i++) s1[i]=s2[i];
  s1[n+1]='\0';
  return n;
}

int main() {
  scanf("%s",s2+1);
  int n=strlen(s2+1),cnt=0;
  for(int i=1;i<=n;i++)
    if (s2[i]!=s1[cnt]) s1[++cnt]=s2[i];
  n=cnt;
  int size[3]={0,0,0};
  for(int i=1;i<=n;i++) size[s1[i]-'A']++;
  int id[3]={0,1,2};
  if (size[id[0]]>size[id[1]]) swap(id[0],id[1]);
  if (size[id[0]]>size[id[2]]) swap(id[0],id[2]);
  if (size[id[1]]>size[id[2]]) swap(id[1],id[2]);
  for(int i=1;i<=n;i++) {
  	int v=s1[i]-'A';
  	for(int j=0;j<3;j++)
  	  if (id[j]==v) s1[i]='A'+j;
  }
  n=solve1(n);
  n=solve2(n);
  for(int i=1;i<=n;i++) s1[i]='A'+id[s1[i]-'A'];
  puts(s1+1);
  return 0;
}

Measured memory_bytes: 3200
def digits(n):
    if n < 10: return 1
    c = 0
    while n > 0:
        c += 1
        n = n // 10

    return c

while 1:
    try:
        inp = input()
    except EOFError:
        break
    else:
        n, m = inp.split(' ')
        n = int(n)
        m = int(m)
        print(digits(n + m))

Measured memory_bytes: 6724
import Data.List (sort,tails)
import System.IO (isEOF)

main = do
    quit <- isEOF
    if quit then return () else do
        s1 <- getLine
        s2 <- getLine
        print $ solve s1 s2
        main

solve :: String -> String -> Int
solve s1 s2 = solve' (sort $ tails s1) (sort $ tails s2) 0
    where
    solve' [] _ n = n
    solve' _ [] n = n
    solve' (u:us) (v:vs) n
        | u < v = solve' us (v:vs) (max n (matchN u v))
        | u > v = solve' (u:us) vs (max n (matchN u v))
        | u == v = solve' us vs (max n (matchN u v))

    matchN "" _ = 0 
    matchN _ "" = 0 
    matchN (c:cs) (d:ds)
        | c == d = 1 + matchN cs ds
        | c /= d = 0

Measured memory_bytes: 6664
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSharp_AtCoder
{

    
    class Program
    {
        
        static int Solve(int n, int[] h)
        {
            int[] dp = new int[n];
            dp[0] = 0;
            dp[1] = Math.Abs(h[1] - h[0]);

            for(int i = 2; i < n; i++)
            {
                dp[i] = dp[i - 1] + Math.Abs(h[i] - h[i - 1]);
                dp[i] = Math.Min(dp[i], dp[i - 2] + Math.Abs(h[i] - h[i - 2]));
            }

            return dp[n - 1];
        }

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] h = new int[n];

            h = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            Console.WriteLine(Solve(n, h));

        }
    }
}


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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var types = new int[3];
            var ans = 0;
            for (var i = 0; i < N; i++) {
                var s = Console.ReadLine();
                
                if (s[0] == 'B') {
                   if (s[s.Length-1] == 'A') {
                      types[2]++;
                   } else {
                      types[1]++;
                   }
                } else if (s[s.Length-1] == 'A') {
                   types[0]++;
                }
                
                var len = s.Length;
                s = s.Replace("AB", "");
                ans += (len-s.Length) / 2;
                
            }
            //Console.WriteLine(ans);
            //for(var i=0;i<3;i++) Console.WriteLine(types[i]);
            while (types[0] > 0 || types[1] > 0 || types[2] > 0) {
                if (types[0] > 0) {
                    types[0]--;
                    ans += Judge(types);
                } else if (types[2] > 0) {
                    types[2]--;
                    ans += Judge(types);
                } else {
                   types[1]--;
                }
            }
            
            Console.WriteLine(ans);
        }

        static int Judge(int[] t) {
            if (t[2] > 0) {
                t[2]--;
                t[0]++;
                return 1;
            } else if (t[1] > 0) {
                t[1]--;
                return 1;
            }
            
            return 0;
        }
    }
}


Measured memory_bytes: 11092
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		String s = sc.next();
		int K = sc.nextInt();
		
		// 計算
		long result = 0;
		int len = s.length();
		int[][][] dp = new int[len+1][4][2];
		dp[0][0][0] = 1;
		for(int i = 0; i < len; i++){
		    int n = s.charAt(i) - '0';
		    for(int j = 0; j < 4; j++){
		        for(int d = 0; d < 10; d++){
		            int ni = i+1;
		            int nj = j;
		            if(d > 0) nj++;
		            if(nj > K) continue;
		            dp[ni][nj][1] += dp[i][j][1]; 
		            if(n == d){
		                dp[ni][nj][0] += dp[i][j][0];
		            }else if(n > d){
		                dp[ni][nj][1] += dp[i][j][0];
		            }
		        }
		    }
		}
		result = dp[len][K][0] + dp[len][K][1];
		
		// 出力
		System.out.println(result);
	}
}


Measured memory_bytes: 21716
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<set>
#include<vector>
#include<iomanip>
#include<queue>
#include<string>
#include<map>

typedef long long ll;
const int inf = 0x3f3f3f3f,maxn = 120000 + 5;

using namespace std;

int main(){

	int t,x;

	while(cin >> t >> x)
	{
		double ans = (double)t / x;

		printf("%.10f\n",ans);	
		
	}

	return 0;
}

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

using namespace std;

#define scan(x) scanf("%d", &x)
#define scan2(x, y) scanf("%d %d", &x, &y)
#define PRI(x) printf("%d\n", x)
#define FOR(A, B, C) for (int A=B;A<C;A++)
#define RFOR(A, B, C) for (int A=B;A>=C;A--)
#define MEM(A, B) memset(A,B, sizeof A)
#define mod 1000000007
typedef long long int LL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;


int main() {
	LL x, y;
	cin >> x >> y;
	LL cnt = 0, it = x;
	while (it <= y) {
		it *= 2;
		cnt++;
	}
	printf("%lld\n", cnt);
	return 0;
}

Measured memory_bytes: 256
#[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")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;

fn main() {
    input! {
        n: usize,
    }

    let mut ans = 0;

    let mut v = 11;
    let mut cnt = 0;
    while v < 55555 {
        let mut ok = true;
        let mut j = 2;
        while j * j <= v {
            if v % j == 0 {
                ok = false;
                break;
            }
            j += 1;
        }
        if ok {
            if cnt != 0 {
                print!(" ");
            }
            print!("{}", v);
            cnt += 1;
            if cnt == n {
                break;
            }
        }
        v += 10;
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdlib>
#include <vector>
#include <math.h>
 
using namespace std;
// https://qiita.com/Clpsplug/items/81fe12400d4093a8fb5a
 
int main() {
    long N;
    cin >> N;

    long minimun = 10000;
    long f = 100;
    for (long i = 1; i * i < N+1; i++) {
        long A = i;
        long B = (long)N/A;
        if (N%A != 0) {
            continue;
        }

        long digit_A = 0;
        while (A > 0) {
            A = A/10;
            digit_A++;
        }

        long digit_B = 0;
        while (B > 0) {
            B = B/10;
            digit_B++;
        }
        f = digit_A;

        if (f < digit_B) {
            f = digit_B;
        }

        if (minimun > f) {
            minimun = f;
        } 
    }
    cout << minimun << endl;
}

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

long long int  arr1[100];
long long  int  arr2[100];
long long  int  arr3[105][100000];
 long long int n,w;

 long long int knap(long long int i,long long int w)
 {
     long long int k=0;
     //cout<<k++<<" ";
     if(w<0) return INT_MIN;
     //cout<<k++<<" ";
     if(i<0 || w==0) return 0;
     //cout<<k++<<endl;;
     if(arr3[i][w]!=-1)
     {
         return arr3[i][w];
     }
     long long int res1=arr2[i]+knap(i-1,w-arr1[i]);
     long long int res2=knap(i-1,w);
     arr3[i][w]=max(res1,res2);
     return arr3[i][w];

 }


int main()
{
   // cout<<long long int_MIN;
    scanf("%lld",&n);
    scanf("%lld",&w);
    for(long long int i=0;i<n;i++)
    {
        scanf("%lld",&arr1[i]);
        scanf("%lld",&arr2[i]);
    }
    memset(arr3,-1,sizeof(arr3));
    long long int res= knap(n-1,w);
    /*for(int i=0;i<n;i++)
    {
        for(int j=0;j<w;j++)
        {
            cout<<arr3[i][j]<<" ";
        }
        cout<<endl;
    }*/
    printf("%lld",res);
}


Measured memory_bytes: 82304
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
#include <deque>
#include <queue>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, a, b;
    cin >> n >> a >> b;
    int x = 0, ans = 0;
    for (int i = 1 ; i <= n ; i++) {
    	string c = to_string(i);
    	for (int j = 0 ; j < c.length() ; j++) x += c[j] - '0';
    	if (x >= a && x <= b) ans += i;
    	x = 0;
	}
	cout << ans;
}

Measured memory_bytes: 3684
from operator import mul
from functools import reduce

def cmb(n,r):
    if n < r:
        return 0

    else:
        r = min(n-r,r)
        if r == 0: return 1
        over = reduce(mul, range(n, n - r, -1))
        under = reduce(mul, range(1,r + 1))
        return over // under


sList = {}

N = int(input())


for i in range(N):
    s = list(input())
    s.sort()

    s_data = ''.join(s)

    if s_data in sList.keys():
        sList[s_data] = sList[s_data] + 1

    else:    
        sList[s_data] = 1

result = 0
for i in sList:
    result += cmb(sList[i],2)

print(str(result))

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

int main(void)
{
  long long number = 0;
  std::cin >> number;
  
  long long baseNumber = 1;
  long long preCount = 0;
  long long count = 26;
  while(count < number)
  {
    baseNumber *= 26;
    preCount = count;
    count += baseNumber * 26;
  }
  
  number -= preCount + 1;
  
  std::string name;
  std::string const characterList = "abcdefghijklmnopqrstuvwxyz";
  while(0 < baseNumber)
  {
    name = characterList[number % 26] + name;
    number /= 26;
    baseNumber /= 26;
  }
  std::cout << name << std::endl;
  
  return 0;
}

Measured memory_bytes: 3104
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <cctype>
#include <utility>
#include <queue>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <numeric>
#include <bitset>
#include <ctime>
#include <list>
#include <deque>
#include <functional>
using namespace std;
const int MAXN = 100000;
const int INF = int(1E9);
int arr[MAXN + 5], sum[MAXN + 5], temp[MAXN + 5];
long long tot1 = 0, tot2 = 0;
int N;
void MergeSort(int le, int ri) {
    if( le == ri ) return ;
    int mid = (le + ri) >> 1;
    MergeSort(le, mid);
    MergeSort(mid+1, ri);
    int p = le, q = mid+1, r = le;
    while( p <= mid && q <= ri ) {
        if( sum[p] < sum[q] ) {
            temp[r++] = sum[p++];
        }
        else {
            tot1 += (p-le);
            temp[r++] = sum[q++];
        }
    }
    while( p <= mid ) {
        temp[r++] = sum[p++];
    }
    while( q <= ri ) {
        tot1 += (p-le);
        temp[r++] = sum[q++];
    }
    for(int i=le;i<=ri;i++)
        sum[i] = temp[i];
}
bool Check(int x) {
    tot1 = 0;
    for(int i=1;i<=N;i++)
        sum[i] = (arr[i] <= x ? 1 : -1);
    for(int i=1;i<=N;i++)
        sum[i] += sum[i-1];
    MergeSort(0, N);
    return tot1 >= (tot2/2 + 1);
}
int main() {
    int le = INF, ri = -INF;
    scanf("%d", &N);
    for(int i=1;i<=N;i++) {
        scanf("%d", &arr[i]);
        le = min(le, arr[i]);
        ri = max(ri, arr[i]);
        tot2 += i;
    }
    while( le < ri ) {
        int mid = (le + ri) >> 1;
        if( Check(mid) ) ri = mid;
        else le = mid + 1;
    }
    printf("%d\n", ri);
}


Measured memory_bytes: 1408
n = gets.to_i
a = gets.split.map(&:to_i)

# 交換回数
$count = 0

def selection_sort(a, n)
  for i in 0..n-1
    minj = i

    for j in i..n-1
      if a[j] < a[minj]
        minj = j
      end
    end
    tmp = a[i]
    a[i] = a[minj]
    a[minj] = tmp

    if i != minj
      $count += 1
    end
  end
  a
end

puts selection_sort(a, n).join(' ')
puts $count


Measured memory_bytes: 6872
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define case(i) printf("Case #%d: ",i);
using namespace std;
typedef long long int ll;
typedef complex<double> com;
typedef pair<int, int> P;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 4e18;



int main(){
	int n; cin >> n;
	vector<int> a(n);
	rep(i, 0, n) cin >> a[i];
	deque<int> ans;
	rep(i, 0, n) {
		if (i % 2) ans.push_back(a[i]);
		else ans.push_front(a[i]);
	}
	if (n % 2) {
		rep(i, 0, n) {
			printf("%d ", ans.front());
			ans.pop_front();
		}
	}
	else {
		rep(i, 0, n) {
			printf("%d ", ans.back());
			ans.pop_back();
		}
	}
	return 0;
}

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

long a, b;
char s;

int main()
{
    while (cin >> a >> s >> b)
    {
        if (s == '?')
            return 0;
        if (s == '+')
            cout << a + b << endl;
        else if (s == '-')
            cout << a - b << endl;
        else if (s == '*')
            cout << a * b << endl;
        else
            cout << a / b << endl;
    }
}


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

using namespace std;

int N;
long long int A[100005];
vector<long long int> a, b,c;

int main(void) {

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


	for (int i = 1; i <= N; i += 2) {
		a.push_back(A[i]);
		c.push_back(A[i]);
	}


	for (int j = 2; j <= N; j += 2) {
		b.push_back(A[j]);
		c.push_back(A[j]);
	}

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

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

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

	int ans = 0;
	int q = 0;

	for (int i = 0; i < (int) a.size(); i++) {
		while (c[q] != a[i]) { q++; }
		if (q % 2 != 0) { ans++; }
	}
	

	cout << ans << endl;

	//system("pause");
	return 0;
}

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

int main(){
  int x, a, b;
  cin >> x >> a >> b;
  if(a>=b){
    cout << "delicious";
  }
  else if(a+x>=b){
    cout << "safe";
  }
  else{
    cout << "dangerous";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
def isCLKWISE(ph):
    return not ((ph[-1][0] - ph[-3][0])*(- ph[-3][1] + ph[-2][1]) - (ph[-2][0] - ph[-3][0])*(- ph[-3][1] + ph[-1][1] ) < 0)
      
def ConvexHullScan(P):
    P.sort()
    phU = [P[0],P[1]]
    for p in P[2:]:
        phU.append(p)
        while(True):
            if isCLKWISE(phU) : break
            else :
                del phU[-2]
                if len(phU) == 2 : break
    phL = [P[-1],P[-2]]
    for p in P[-3::-1]:
        phL.append(p)
        while(True):
            if isCLKWISE(phL) : break
            else :
                del phL[-2]
                if len(phL) == 2 : break
    ph = phU + phL[1:-1]
    return ph
  
n = range(int(input()))
P = []
for i in n:
    P.append([int(x) for x in input().split()])
      
Q = ConvexHullScan(P)
Q.reverse()
print(len(Q))
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(Q)])[2]
R = Q[idx:] + Q[:idx]
for r in R : print(r[0],r[1])

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


int  main(){
  string s,t; cin>>s>>t;
  if(s.size()==t.size()){
    rep(i,s.size())cout<<s.at(i)<<t.at(i);
  }
  else{
    rep(i,t.size())cout<<s.at(i)<<t.at(i);
    cout<<s.at(s.size()-1);
  }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def main():
    from collections import Counter
    n = int(input())
    a = Counter(list(map(int, input().split())))
    ans = 0

    for key, value in a.items():
        if key > value:
            ans += value
        elif key < value:
            ans += value - key

    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

void ABC113D()
{
	constexpr int MOD = 1000000007;
	int H, W, K;
	cin >> H >> W >> K;
	--K;
	if (W == 1)
	{
		cout << 1 << endl;
		return;
	}

	vi tmp(W + 1);
	tmp[0] = 0;
	tmp[1] = 1;
	for (int i = 2; i <= W; ++i)
	{
		for (int j = 0; j < i - 1; ++j)
			tmp[i] += tmp[j];
		++tmp[i];
	}
	vl lines(W + 1);
	lines[0] = 1;
	for (int i = 1; i <= W; ++i)
		lines[i] = lines[i - 1] + tmp[i];

	vvl dp(H + 1, vl(W));
	dp[0][0] = 1;

	for (int i = 1; i <= H; ++i)
	{
		dp[i][0] = dp[i - 1][0] * lines[W - 2] + dp[i-1][1] * lines[max(0,W - 3)];
		dp[i][0] %= MOD;
		dp[i][W - 1] = dp[i - 1][W - 1] * lines[W - 2] + dp[i - 1][W - 2] * lines[max(0,W - 3)];
		dp[i][W - 1] %= MOD;
		for (int j = 1; j < W - 1; ++j)
		{
			dp[i][j] = dp[i - 1][j - 1] * lines[max(j - 2, 0)] * lines[max(W - j - 2, 0)];
			dp[i][j] += dp[i - 1][j] * lines[max(j - 1, 0)] * lines[max(W - j - 2, 0)];
			dp[i][j] += dp[i - 1][j + 1] * lines[max(j - 1, 0)] * lines[max(W - j - 3, 0)];
			dp[i][j] %= MOD;
		}
	}
	cout << dp[H][K] << endl;
}
int main()
{
	ABC113D();
	return 0;
}


Measured memory_bytes: 256
n,m = map(int, input().split())
t = [0]*m
for i in range(n):
    l = list(map(int, input().split()))
    for j in range(1,l[0]+1):
        t[l[j]-1] += 1
p = 0
for i in range(m):
    if(t[i] == n):
        p += 1
print(p)

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

int main(){
  string s;
  cin>>s;
  if(s=="SUN")cout<<7<<endl;
  else if(s=="MON")cout<<6<<endl;
  else if(s=="TUE")cout<<5<<endl;
  else if(s=="WED")cout<<4<<endl;
  else if(s=="THU")cout<<3<<endl;
  else if(s=="FRI")cout<<2<<endl;
  else if(s=="SAT")cout<<1<<endl;
}

Measured memory_bytes: 256
MOD = int(1e9) + 7

def main():
    buf = input()
    buflist = buf.split()
    N = int(buflist[0])
    M = int(buflist[1])
    a = []
    for i in range(M):
        buf = input()
        a.append(int(buf))
    a.append(N+1) # sentinel
    pattern = [1]
    for i in range(1, N+3):
        pattern.append(0)
    pointer = 0
    for i in range(0, N+1):
        if a[pointer] == i:
            pattern[i] = 0
            pointer += 1
        pattern[i+1] = (pattern[i+1] + pattern[i]) % MOD
        pattern[i+2] = (pattern[i+2] + pattern[i]) % MOD
    print(pattern[N])

if __name__ == '__main__':
    main()


Measured memory_bytes: 7848
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <tuple>
#include <random>
#include <map>
using namespace std;

const double pi = acos(-1);
#define nyan cout << "(=^•ω•^=)" << endl;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop while(true)
#define YN(f) f?cout<<"YES"<<endl:cout<<"NO"<<endl;
#define yn(f) f?cout<<"Yes"<<endl:cout<<"No"<<endl;

int a[20];
int ans;

signed main(){
	int n;cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<n;i++){
		ans+=(i==n-1?a[i]/2:a[i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

int n;
vector<vector<int>> g;
vector<int> color;
vector<int> mod_res;

void input() {
	cin >> n;
	g.resize(n);
	color.resize(n, 0);
	mod_res.resize(n, -1);
	for (int i = 0; i < n - 1; ++i) {
		int a, b; cin >> a >> b;
		--a, --b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
}

void dfs(int s = 0, int p = -1, int prv_color = 1) {
	color[s] = (!prv_color);
	for (int nxt : g[s])
		if (nxt != p)
			dfs(nxt, s, color[s]);
}

int main() {
	input();
	dfs();
	// sum := 色1のやつの個数
	int sum = 0;
	for (auto ci : color) sum += ci;
	int c1 = (n + 2) / 3;
	int c2 = (n + 1) / 3;
	int c12 = n / 3;
	if (sum >= (n - sum)) { // sumの方が少ないことにする
		for (int i = 0; i < n; ++i)
			color[i] = !color[i];
		sum = n - sum;
	}
	if (sum <= c12) { // sumが超小さい
		// 1 : c12
		// 0 : のこり
		for (int i = 0; i < n; ++i) {
			if (color[i]) {
				mod_res[i] = 0;
				--c12;
			}
		}
		for (int i = 0; i < n; ++i) {
			if (!color[i]) {
				if (c12) {
					mod_res[i] = 0; --c12;
				}
				else if (c1) {
					mod_res[i] = 1; --c1;
				}
				else {
					mod_res[i] = 2; --c2;
				}
			}
		}
	}
	else { // 色1にc2を使う
		for (int i = 0; i < n; ++i) {
			if (color[i]) {
				if (c2) {
					mod_res[i] = 2;
					--c2;
				}
				else {
					mod_res[i] = 0;
					--c12;
				}
			}
		}
		for (int i = 0; i < n; ++i) {
			if (!color[i]) {
				if (c12) {
					mod_res[i] = 0;
					--c12;
				}
				else {
					mod_res[i] = 1;
					--c1;
				}
			}
		}
	}
	/*
	for (auto i : mod_res) cout << i << " ";
	cout << endl;
	*/
	int c1ptr = 1, c2ptr = 2, c12ptr = 3;
	for (int i = 0; i < n; ++i) {
		if (mod_res[i] == 0) {
			mod_res[i] = c12ptr;
			c12ptr += 3;
		}
		else if (mod_res[i] == 1) {
			mod_res[i] = c1ptr;
			c1ptr += 3;
		}
		else {
			mod_res[i] = c2ptr;
			c2ptr += 3;
		}
	}
	for (auto i : mod_res) cout << i << " ";
	cout << endl;
	return 0;
}

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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;

ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    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;
    }
}
ll 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;
}

ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int K,X;
    cin>>K>>X;
    for(int i=X-K+1;i<X+K-1;i++){
        cout<<i<<" ";
    }
    cout<<X+K-1<<endl;
    return 0;
}


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

using namespace std;

int main() {
  int n, t; cin >> n >> t;
  int a[n];

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

  long long ans = 0;
  for(int i = 0; i < n-1; i++) {
    if(a[i+1] - a[i] < t) {
      ans += a[i+1] - a[i];
    }
    else {
      ans += t;
    }
  }
  ans += t;
  
  cout << ans << endl;
}

Measured memory_bytes: 1024
# coding: utf-8
# hello worldと表示する
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
m,a,r,c,h=0,0,0,0,0
for i in range(n):
    s=SI()
    if s[0]=="M":
        m+=1
    elif s[0]=="A":
        a+=1
    elif s[0]=="R":
        r+=1
    elif s[0]=="C":
        c+=1
    elif s[0]=="H":
        h+=1
lis=[]
lis.append(m)
lis.append(a)
lis.append(r)
lis.append(c)
lis.append(h)
u=[0,1,2,3,4]
ans=0
for i in combinations(u,3):
    pro=1
    for j in range(3):
        pro*=lis[i[j]]
    ans+=pro
print(ans)

Measured memory_bytes: 41452
n, m = (int(x) for x in input().split())
LRD = [tuple(int(x) for x in input().split()) for _ in range(m)]

G = [[] for _ in range(n)]
dist = dict()
for l, r, d in LRD:
    l -= 1
    r -= 1
    G[l].append(r)
    G[r].append(l)
    dist[(l, r)] = d
    dist[(r, l)] = -d

INF = 10**18
X = [INF] * n
for i in range(n):
    stack = [i]
    while stack:
        u = stack.pop()
        if X[u] == INF:
            X[u] = 0
        for v in G[u]:  # u -> v
            if X[v] == INF:
                X[v] = X[u] + dist[(u, v)]
                stack.append(v)
            else:
                if X[v] != X[u] + dist[(u, v)]:
                    print("No")
                    exit()

print("Yes")

Measured memory_bytes: 214408