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

int n, H[2000000];

void maxHeapify(int i) {
    int l, r, largest;
    l = 2 * i;
    r = 2 * i + 1;
    
    if(r <= n && H[r] > H[i]) largest = r;
    else largest = i;
    if(l <= n && H[l] > H[largest]) largest = l;
    
    if(largest != i){
        swap(H[i], H[largest]);
        maxHeapify(largest);
    }else return;
}

void heapIncreaseKey(int i){
    while(i / 2 > 0 && H[i] > H[i / 2]){
        swap(H[i], H[i / 2]);
        i = i / 2;
    }
}

void insert(int key){
    n++;
    H[n] = key;
    heapIncreaseKey(n);
}

int extract(){
    int max = H[1];
    H[1] = H[n];
    n--;
    maxHeapify(1);
    return max;
}

int main()
{
    n = 0;
    int k;
    string s;
    while(1){
        cin >> s;
        if(s == "end") break;
        if(s == "insert") {
            cin >> k;
            insert(k);
        }else{
            cout << extract() << endl;
        }
        
    }

    
    
    return 0;
}


Measured memory_bytes: 7044
#import<bits/stdc++.h>
using namespace std;set<int>A;long K,S,T,U,i,j,c[51]={1},P[51],a,w;main(){for(cin>>K>>K>>S>>T;cin>>j;)for(~j&S|j&~T||(A.insert(j),0),++i,j=K;j;j--)P[i]+=c[j]+=c[j-1];for(;U<1<<18;w=!++U){map<int,int>M;for(int v:A)M[v&U]++;for(auto[p,q]:M)w+=P[q];a+=~U&S|U&~T?0:__builtin_parity(U&~S)?-w:w;}cout<<a;}

Measured memory_bytes: 3516
#include <iostream>
#include <algorithm>
#include <cctype>
#include <cstring>
#include <cstdlib>
using namespace std;

#define INF (1<<25)

int sx,sy,gx,gy,W,H;
int px[1000][5], py[1000][5], pn[5];
int dp[1000][1000][5];

void init()
{
	for(int i=0; i<H; i++)
	for(int j=0; j<W; j++)
	for(int k=0; k<5; k++)
		dp[j][i][k]=INF;
}

int dist(int x1, int y1, int x2, int y2)
{
	return abs(x1-x2)+abs(y1-y2);
}

void calc(int n)
{
	int b=(n+1)%5;
	for(int i=0; i<pn[b]; i++)
	{
		int x=px[i][b], y=py[i][b];
	 	dp[x][y][b]=min(dp[x][y][b],dist(x,y,sx,sy));
	}
	
	for(int i=2; i<5; i++)
	{
		int l=(i+n)%5, p=(i+n-1)%5;
		for(int j=0; j<pn[p]; j++)
		{
			int s=px[j][p], t=py[j][p];
			if(dp[s][t][p]==INF) continue;
			
			for(int m=0; m<pn[l]; m++)
			{
				int x=px[m][l], y=py[m][l];
				dp[x][y][l]=min(dp[x][y][l], dp[s][t][p]+dist(x,y,s,t));
				
				dp[gx][gy][l]=min(dp[gx][gy][l], dp[x][y][l]+dist(x,y,gx,gy));
			}
		}
	}
}


int main()
{
	while(cin >> W >> H, (W||H))
	{
		memset(pn, 0, sizeof(pn));
		
		for(int i=0; i<H; i++)
		for(int j=0; j<W; j++)
		{
			char t;
			cin >> t;
			
			if(t=='.') continue;
			if(isdigit(t))
			{
				int n=t-'1';
				px[pn[n]][n]=j;
				py[pn[n]][n]=i;
				
				pn[n]++;
			}
			
			if(t=='S')
			{
				sx=j;
				sy=i;
			}
			
			if(t=='G')
			{
				gx=j;
				gy=i;
			}
		}
		
		int v,m=INF;
		
		for(int i=0; i<5; i++)
		{
			init();
			calc(i);
			
			if(m > dp[gx][gy][(i+4)%5]) 
			{
				v=i+1;
				m=dp[gx][gy][(i+4)%5];
			}
		}
		
		if(m==INF) cout << "NA" << endl;
		else cout << v << " " << m << endl;
	}
}

Measured memory_bytes: 19000
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
const int maxn = 1e5;
struct NOOD {
	int a, d;
}num[maxn + 5];
int sum, n;
int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)scanf("%d", &num[i].a);
	num[0].a = 0;
	num[n + 1].a = 0;
	for(int i = 1; i <= n + 1; i++) {
		num[i].d = abs(num[i].a - num[i - 1].a);
		sum += num[i].d;
	}
	for(int i = 1; i <= n; i++) {
		printf("%d\n", sum - num[i].d - num[i + 1].d + abs(num[i + 1].a - num[i - 1].a));
	}
	return 0;
}

Measured memory_bytes: 1920
s=input()
ans=""

slist=list(s)
if(len(slist)==26):
    if(s=='zyxwvutsrqponmlkjihgfedcba'):
        print(-1)
    else:
        tlist=list(s)
        while(''.join(tlist)!='zyxwvutsrqponmlkjihgfedcba'):
            ttail=tlist.pop(-1)
            while(ttail=='z'):
                ttail=tlist.pop(-1)
            tlist.append(chr(ord(ttail)+1))

            if(len(tlist) == len(list(set(tlist)))):
                break

        print(''.join(tlist))
else:
    tlist=list(s)
    tlist.append('a')
    c=97
    while(ord('z') >= c):
        tlist[-1]=chr(c)
        if(len(list(set(slist))) != len(list(set(tlist)))):
            break
        else:
            c+=1
    print(''.join(tlist))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REPR(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define FOR(i, n, m) for (ll i = (n); i < (m); ++i)
#define FORR(i, n, m) for (ll i = (m) - 1; i >= (n); --i) 
#define FORE(x, xs) for (auto &x: (xs))
#define ALL(v) v.begin(), v.end()
#define ZERO(a) memset(a,0,sizeof(a))

const int INF = 1000000009;
const int MOD = 1000000007;
const double EPS = 1e-14;
const double PI = acos(-1);

const int MAX = 1e5;
int parents[MAX+1];

int N;
string s;

void wrong(int n) {
  cout << -1 << endl;
}

int main() {

  cin >> s;
  N = s.length();
  if (s[0] == '0') { /// 最初は絶対1
    wrong(1);
    return 0;
  }
  if (s[N-1] == '1') { /// 最後は絶対0
    wrong(2);
    return 0;
  }
  REP (i, (N-1)/2) { 
    if (s[i] != s[N-2-i]) { /// 対称的になる
      wrong(3);
      return 0;
    }
  }

  REP (i, MAX+1) parents[i] = 0;

  int p = 1;
  parents[1] = 1;
  parents[2] = 1;
  FOR (i, 2, N) {
    if (s[i-1] == '0') { // iを作りたくない
      parents[i+2] = p;
      if (parents[i+1] == 0) 
        parents[i+1] = p;
    }
    else {
      if (parents[i+1] == 0) {
        parents[i+1] = i;
        p = i;
      }
      else {
        parents[i+2] = i+1;
        p = i+1;
      }
    }
  }

  if (s[1] == '0') { // 2を作りたくない
    parents[N] = parents[N-1];
  } else {
    parents[N] = N-1;
  }


  FOR (i, 2, N+1) {
    cout << parents[i] << " " << i << endl;
  }
  return 0;

}


Measured memory_bytes: 2048
import sys
input = sys.stdin.readline


def main():
    R, G, B, N = map(int, input().split())
    ans = 0
    for r in range(N+1):
        if r*R > N:
            continue
        for g in range(N+1):
            if r*R + g*G > N:
                continue
            if (N - r*R - g*G) % B == 0:
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 39408
class AtCoder {
  // 入力系
  input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);
  input_i=-1;
  n(){
    this.input_i++;
    return Number(this.input[this.input_i]);
  }
  nn(n):number[]{
    const a=[];
    for(let i=0;i<n;i++){
      a.push(this.n());
    }
    return a;
  }
  s(){
    this.input_i++;
    return String(this.input[this.input_i]);
  }
  ss(n):string[]{
    const a=[];
    for(let i=0;i<n;i++){
      a.push(this.s());
    }
    return a;
  }

  // コンソール
  o(...a:any){
    console.log(...a);
  }

  // Math
  abs(a:number){
    return Math.abs(a);
  }
  min(...a:number[]){
    return Math.min(...a);
  }
  max(...a:number[]){
    return Math.max(...a);
  }
  floor(a:number){
    return Math.floor(a);
  }
  ceil(a:number){
    return Math.ceil(a);
  }
  round(a:number){
    return Math.round(a);
  }

  // ソート
  asc(ar:number[]){
    const t=[...ar];
    ar.sort((a,b)=>{return a-b});
  }
  desc(ar:number[]){
    const t=[...ar];
    ar.sort((a,b)=>{return b-a});
  }

  // 自作
  gcd(...arr):number{
    for(let i=0;i<arr.length-1;i++){
      let [x,y]=[arr[i],arr[i+1]];
      while(y){
        [x,y]=[y,x%y];
      }
      arr[i+1]=x;
    }
    return arr[arr.length-1];
  };
  lcm(...arr):number{
    for(let i=0;i<arr.length-1;i++){
      let [x,y]=[arr[i],arr[i+1]];
      while(y){
        [x,y]=[y,x%y];
      }
      arr[i+1]=arr[i]*arr[i+1]/x;
    }
    return arr[arr.length-1];
  };
  isPrime(n:number):boolean{
    if(n < 2) return false;
    const suq=Math.sqrt(n);
    for(let i=2;i<=suq;i++){
      if(n%i==0){
        return false;
      }
    }return true;
  };
  deduplicate(a:any[]):any[]{
    return Array.from(new Set(a));
  };
}

const o = new AtCoder()
let [a,b]=[...o.ss(2)]
let [n,m]=[...o.nn(2)]
let c=o.s()

if(a==c){
  o.o(n-1+" "+m)
}else{
  o.o(n, m-1)
}


Measured memory_bytes: 11468
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7,N=2e5+5;
int n,tot,si[N],head[N],nex[N<<1],to[N<<1];
void add(int u,int v){to[++tot]=v;nex[tot]=head[u];head[u]=tot;}
ll qpow(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=ans*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return ans;
}
void dfs1(int u,int p)
{
    si[u]=1;
    for(int i=head[u];i;i=nex[i])
    {
        int v=to[i];if(v==p) continue;
        dfs1(v,u);
        si[u]+=si[v];
    }
}
ll ans=0;
void dfs2(int u,int p)
{
    ll res=qpow(2,n-1)-1;
    for(int i=head[u];i;i=nex[i])
    {
        int v=to[i];
        res=(res-qpow(2,si[v])+1)%mod;
    }
    ans=(ans+res)%mod;
    for(int i=head[u];i;i=nex[i])
    {
        int v=to[i];if(v==p) continue;
        si[u]-=si[v];
        si[v]+=si[u];
        dfs2(v,u);
        si[v]-=si[u];
        si[u]+=si[v];
    }
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<n;i++)
    {
        int u,v;scanf("%d%d",&u,&v);
        add(u,v);add(v,u);
    }
    dfs1(1,0);
    dfs2(1,0);
    ans=(ans+mod)%mod;
    ans=ans*qpow(qpow(2,n),mod-2)%mod;
    printf("%lld\n",ans);
}


Measured memory_bytes: 11648
#include <stdio.h>
#include <string.h>
 
int main() {
   int k;
   char s[100];
   scanf("%d %s", &k,s);
 
   if(strlen(s) <= k) {
      printf("%s\n",s);
   } else {
      s[k]='\0';
      printf("%s",s);
      printf("...\n");
   }
   return 0;
}

Measured memory_bytes: 1724
n = int(input())
al = list(map(int, input().split())) 
q = int(input())

from collections import Counter
count = Counter(al)

als = sorted(al)
dp = [0]*(10**5+1)
res = sum(als)

for i in range(10**5+1):
    dp[i] =count[i]

for j in range(q):
    a,b = map(int, input().split())
    res += dp[a] * (b-a)
    dp[b] += dp[a]
    dp[a] = 0
    print(res)

Measured memory_bytes: 21024
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import qualified Data.ByteString.Char8 as BC
import           Data.Maybe            (fromJust)

main :: IO ()
main = do
  [a, b] <- map readInt . BC.words <$> BC.getLine
  print $ solve a b

solve :: Int -> Int -> Int
solve a b
  | a <= b    = a
  | otherwise = a - 1

readInt :: BC.ByteString -> Int
readInt = fst . fromJust . BC.readInt


Measured memory_bytes: 380
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//cout << fixed << setprecision(17) << res << endl;
 
int main() {
    ll n;
    cin >> n;
    ll res = 0;
    for (ll i = 1; i <= n; i+=2) {
        ll count = 0;
        for (ll j = 1; j <= i; j+=2) {
            if ((i%j) == 0) {
                ++count;
            }
        }
        if (count == 8) {
            ++res;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
s = gets.chomp

def rle s
  s.each_char.inject([]) do |memo, c| 
     memo.last && c == memo.last.last ? memo.last[0] += 1 : memo << [1, c]
     memo
  end
end

ans = []
(rle s).each_slice(2) do |r, l|
  length = r[0] + l[0]
  r_num = r[0].odd? ? (length / 2.0).ceil : (length / 2.0).floor
  l_num = length - r_num
  res = Array.new(length, 0)
  res[r[0] - 1] = r_num
  res[-l[0]] = l_num
  ans << res
end

puts ans.flatten.join(' ')


Measured memory_bytes: 30500
#include<iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a;
  int ans=0;
  for(int i=1;i<=n;i++){
    cin>>a;
    if(a%2==0 & (a%3!=0 & a%5!=0)){
      ans-=1;
    }
  }
  if(ans>=0){
    cout<<"APPROVED"<<endl;
  }
  else{
    cout<<"DENIED"<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;
int main(){
    ll a,b;cin>>a>>b;
    if(a*b%2==0){
        cout<<"Even"<<endl;
    }else{
        cout<<"Odd"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3516
import sys
input = sys.stdin.readline
MOD = 10**9 + 7
INF = float('INF')

def main():
    n = int(input())
    a = list(map(int, input().split()))

    ans = [0] * n
    for i in range(n):
        ans[a[i]-1] = i + 1

    print(*ans)

if __name__ == '__main__':
    main()

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

using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  string s;
  cin >> s;
  for(int x = 0;x<s.size();x++){
    if(s[x]=='-'&&x!=a){
      cout << "No";
      return 0;
    }
    if(x==a&&s[x]!='-'){
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}


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

int N, A, B, C;
int mod = 1e9 + 7;

int main() {
    cin >> N >> A >> B >> C;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    
    int ans = 1e9;
    for (int i = 0; i < (1 << 2 * N); i++) {
        vector<int> sum(3), cnt(3);
        for (int j = 0; j < N; j++) {
            int flag = (i >> 2 * j);
            if (flag & 1) {
                if (flag >> 1 & 1) {
                    sum[2] += a[j];
                    ++cnt[2];
                } else {
                    sum[0] += a[j];
                    ++cnt[0];
                }
            } else if (flag >> 1 & 1) {
                sum[1] += a[j];
                ++cnt[1];
            }
        }
   //     cout << sum[0] << sum[1] << sum[2] << endl;
        if (sum[0] == 0 || sum[1] == 0 || sum[2] == 0) continue;
        int tmp = abs(A - sum[0]) + abs(B - sum[1]) + abs(C - sum[2]) + (cnt[0] + cnt[1] + cnt[2] - 3) * 10;
      ans = min(tmp, ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7,INF=mod*mod*3;//M_PI
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define f first
#define s second
#define pb push_back
#define mp make_pair

ll N;
ll dp[200005];
ll cnt[10][15][15];
ll get_p(ll n){
	while(1){
		if(n/10==0) return n%10;
		n/=10;
	}
}
ll get_s(ll n){
	return n%10;
}
ll keta(ll n){
  ll ret=0;
  ll nn=n;
  while(1){
    nn/=10; 
    ret++;
    if(nn==0) break;
  }
  return ret;
}


int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>N;
rep1(i,N+1){
	ll i_keta=keta(i);
	ll ip=get_p(i);
	ll is=get_s(i);
	ll add=0;
	if(ip==is){
		rep1(k,i_keta+1) add+=2*cnt[k][ip][is];
		add++;
	}else{
		rep1(k,i_keta+1){
			if(is==0) continue;
			if(k==i_keta&&is>ip) continue;
			add+=2*cnt[k][is][ip];
		}
	}
	dp[i]=dp[i-1]+add;
	cnt[i_keta][ip][is]++;
}
cout<<dp[N]<<endl;

}
	

Measured memory_bytes: 5168
import java.util.Scanner;
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
        try (Scanner scn = new Scanner(System.in)) {
            int n = scn.nextInt();
            int k = scn.nextInt();
            scn.nextLine();
            long total = 0;
            if(n>k) {
                List<Long> listH = new ArrayList<>();
                for (int i = 0; i < n; i++) {
                    listH.add(scn.nextLong());
                }
                listH.sort(Collections.reverseOrder());
                if (k > 0) {
                    listH.subList(0, k).clear();
                }
                for(long l:listH){
                    total = total + l;
                }
            }
            System.out.println(total);
        }
	}
	
}


Measured memory_bytes: 98400
#include <cmath>
#include <cstdio>
#include <limits>
#include <tuple>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>
#include <iomanip>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  ll n;
  ll ii;
  cin >> n;
  cin >> ii;
  cout << n - ii + 1 << endl;

  return 0;
}

Measured memory_bytes: 256
max2 = lambda x,y: x if x > y else y
min2 = lambda x,y: x if x < y else y

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline



def solve(N,edges):
    adj = [[] for _ in range(N)]
    for a,b in edges:
        adj[a].append(b)
        adj[b].append(a)

    visited = [False]*N

    right = []
    v = 0
    visited[v] = True
    while True:
        for u in adj[v]:
            if not visited[u]:
                right.append(u)
                v = u
                visited[v] = True
                break
        else:
            break

    left = []
    v = 0
    while True:
        for u in adj[v]:
            if not visited[u]:
                left.append(u)
                v = u
                visited[v] = True
                break
        else:
            break

    left.reverse()
    return left+[0]+right



if __name__ == '__main__':
    N,M = map(int,readline().split())
    m = map(lambda x: int(x)-1, read().split())

    path = solve(N,zip(m,m))
    print(len(path))
    print(*(v+1 for v in path))

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

using namespace std;
using ll = long long;

int const NMAX = 2e5 + 11;

int n, m;
ll  k, pa[NMAX], pb[NMAX];

int main(void)
{
    int ai, bi;
    cin >> n >> m >> k;

    for (int i = 1; i <= n; ++i)
        cin >> ai, pa[i] = ai + pa[i - 1];
    for (int i = 1; i <= m; ++i)
        cin >> bi, pb[i] = bi + pb[i - 1];

    int ans = 0, j;
    for (int i = 0; i <= n; ++i)
    {
        if (k - pa[i] < 0)
            break;
        auto match = prev(upper_bound(pb + 1, pb + m + 1, k - pa[i]));

        j   = distance(pb, match);
        ans = max(ans, i + j);
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;
#define ll unsigned long long
#define pb push_back
#define mp make_pair

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main()
{
	ll k, a, b;
	cin >> k >> a >> b;
	ll ans = k+1;
	ll bis = 1;
	if(b > a)
	{
		if(a+1 <= k)
		{
			bis = b;
			k -= a+1;
			if(k%2) bis++;
			ll z = k/2;
			bis += z*(b-a);
			ans = max(ans, bis);
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

#define ll long long
#define pb push_back

ll MAX(ll a, ll b) {

	if (a > b)return a;
	else return b;

}
ll MIN(ll a, ll b) {

	if (a < b)return a;
	else return b;

}
ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}//pは素数,aのb乗をpで割った余り
ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}//pは素数,(nCr)%p
ll gcd(ll a, ll b) {

	if (a < b) {

		ll tmp = a;
		a = b;
		b = tmp;

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

}//最大公約数
ll lcm(ll a, ll b) {

	return a / gcd(a, b)*b;

}//最小公倍数

int main() {
	
	while(1){
		int N;
		ll sum=0;
		cin>>N;
		if(N==0)break;
		vector<int> S;
		for(int i=0;i<N;i++){
			int s;
			cin>>s;
			S.pb(s);
			sum+=s;
		}
		sort(S.begin(),S.end());
		cout<<(sum-S[0]-S[N-1])/(N-2)<<endl;
	}

	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	string s;cin>>s;
	int n;cin>>n;
	vector<string>a;
	int k=s.size();
	rep(i,k){
		string t="";
		for(int j=i;j<min(i+5,k);++j){
			t+=s[j];
			a.PB(t);
		}
	}
	sort(all(a));
    a.erase(unique(all(a)),a.end());
	cout<<a[n-1]<<endl;
}


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

int main() {
  string S;
  cin >> S;
  vector<int> X(26, 0);
  for (int i = 0; i < S.size(); i++) {
    X.at(S.at(i) - 97)++;
  }
  for (int i = 0; i < 26; i++) {
    if (X.at(i) == 0) {
      cout << (char)(97 + i) << endl;
      return 0;
    }
  }
  cout << "None" << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <algorithm>
#include <set>
using namespace std;
int main() { 
	long long int S; cin >> S; 
	long long int R = (S + 999999999) / 1000000000; 
	cout << 0 << " " << 0 << " " << 1000000000 << " " << 1 << " " << R * 1000000000 - S << " " << R << endl;  
} 

Measured memory_bytes: 256
n, h, w = input().split()
n = int(n)
h = int(h)
w = int(w)
ans = 0

for _ in range(n):
    a, b = input().split()
    a = int(a)
    b = int(b)
    if a - h >= 0 and b - w >= 0:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define F first
#define S second
#define pii pair<int, int>
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 110, INF = 1e9;
int a[N], cnt[N];

int main(){
	int n, d = -INF, r = INF; cin >> n;
	for(int i=0; i<n; i++){
		cin >> a[i];
		d = max(d, a[i]);
		r = min(r, a[i]);
		cnt[a[i]]++;
	}

	if(d % 2 == 0){
		if(r != d/2)return cout << "Impossible\n", 0;
		if(cnt[r] > 1)return cout << "Impossible\n", 0;
	}else{
		if(r <= d/2)return cout << "Impossible\n", 0;
		if(r != (d + 1)/2)return cout << "Impossible\n", 0;
		if(cnt[r] != 2)return cout << "Impossible\n", 0;
	}
	for(int i=d; i>d/2; i--){
		if(cnt[i] < 2)return cout << "Impossible\n", 0;
	}
	cout << "Possible\n";

}

Measured memory_bytes: 256
/*
	专 业 爆 搜
			--InterestingLSY
*/
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define pb push_back
#define mp make_pair
#define INF 9999999
#define LINF 9999999999999999
#define SINF "%"
#define uint unsigned int
#define msn(a,v) memset(a,v,sizeof(a))
#define ms(a) msn(a,0)
#define NONE -1
#define ll long long
#define ull unsigned ll
#define uchar unsigned char
#define sint short int
#define usint unsigned sint
#define xsize(a) sizeof(a)/1024/1024
#define fr(aaaaa,bbbbb) for(aaaaa = 1;aaaaa <= bbbbb;aaaaa++)
#define frr(aaaaa,bbbbb,ccccc) for(aaaaa = ccccc;aaaaa <= bbbbb;aaaaa++)
using namespace std;
#define MAXN 200010
 
int n,k,l;
map<int,int> m[MAXN];

class DSU{
public:
	int dsu[MAXN];
	void init(){
		for(int i = 0;i <= n;i++) dsu[i] = i;
	}
	int getfa(int pos){
		if( dsu[pos] == pos ) return pos;
		dsu[pos] = getfa(dsu[pos]);
		return dsu[pos];
	}
	void pa(int a,int b){
		a = getfa(a); b = getfa(b);
		dsu[a] = b;
	}
	bool same(int a,int b){
		return getfa(a) == getfa(b);
	}
};
DSU road,train;

int main(){
	//freopen("D.txt","r",stdin);
	
	scanf("%d %d %d",&n,&k,&l);
	
	road.init();
	train.init();
	
	for(int i = 1;i <= k;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		road.pa(a,b);
	}
	for(int i = 1;i <= l;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		train.pa(a,b);
	}
	
	for(int i = 1;i <= n;i++)
		m[road.getfa(i)][train.getfa(i)]++;
	for(int i = 1;i <= n;i++)
		printf("%d ",m[road.getfa(i)][train.getfa(i)]);
	printf("\n");
	
	return 0;
}

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

#if defined(DEBUG)

#include <unistd.h>
#include <sys/fcntl.h>
#define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else  // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)

template<typename F>
class FixPoint : private F {
public:
  explicit constexpr FixPoint(F&& f) noexcept : F(forward<F>(f)) {}

  template<typename... Args>
  constexpr decltype(auto) operator()(Args&&... args) const {
    return F::operator()(*this, forward<Args>(args)...);
  }
};

template<typename F>
static inline constexpr decltype(auto) fix(F&& f) noexcept {
  return FixPoint<F>{forward<F>(f)};
}


int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2) dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  int N, K; cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++)  cin >> A.at(i);
  sort(A.begin(), A.end());

  auto chk = [&](int i) -> bool {
    if (A.at(i) >= K) return true;
    vector<bool> tbl(K);
    tbl.at(0) = true;
    for (int j = 0; j < N; j++) {
      if (i == j) continue;
      int a = A.at(j);
      for (int x = K-1; x-a >= 0; x--) {
	if (tbl.at(x-a)) {
	  if (K <= x + A.at(i)) return true;
	  tbl.at(x) = true;
	}
      }
    }
    return false;
  };
  
  auto bsch = fix([&](auto f, int lo, int hi) -> int {
      if (lo + 1 == hi)  return hi;
      int mid = (lo + hi) / 2;
      if (chk(mid)) return f(lo, mid);
      else          return f(mid, hi);
    });

  int i0 = bsch(-1, N);
  cout << i0 << endl;

  return 0;
}



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

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

  bool loop1 = true;
  int i;
  i = 0;
  while(i < (n-1)/2)
  {
    if(s[i] != s[n-1-i])
      loop1 = false;
    i++;
  }

  i = 0;
  while(i < (int)((n-1)/4))
  {
    if(s[i] != s[(n-1)/2-1-i])
      loop1 = false;
    i++;
  }

  i = (n-1)/2+1;
  while(i < (n-1)/2+1 + (int)((n-1)/4))
  {
    if(s[i] != s[(n-1)-i])
      loop1 = false;
    i++;
  }
  if(!loop1)
  {
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
  return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int N;
P p[50];

int H[55][333][2];

int calc(int i,int f,int t,int c,int *F){
  int tot = t + p[i].first;
  if( c == 0 ) return tot;
  for(int j=i+1;j<N;j++){
    if( c - F[j] - 1 < 0 ) continue;
    if( H[j][c-F[j]-1][f] > tot )
      tot = H[j][c-F[j]-1][f];    
  }
  for(int j=i+1;j<N;j++){
    if( c-F[j]-1<0 ) continue;
    if( H[j][c-F[j]-1][f] == tot ) F[j]++;
  }
  return tot;
}

int main(){
  while( cin >> N && N ){
    for(int i=0;i<N;i++){
      cin >> p[i].first >> p[i].second;
    }
    memset(H,0,sizeof(H));
    int res = 0;
    sort(p,p+N);
    for(int i=N-1;i>-1;i--){
      int t = 0, F[55] = {};
      for(int c=0; c < p[i].second; c++ ){
	t = calc(i,0,t,c,F);
	H[i][c][0] = t;
	t = calc(i,1,t,c,F);
	H[i][c][1] = t;
	res = max( res, t );
      }
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 1316
#include<bits/stdc++.h>
using namespace std;
int main(){
  int y,z,x,w,ans;
  cin>>y>>z;
  x=y/100;
  w=z/100;
  ans=w-x+1;
  if(100*x+10*(y/1000%10)+y/10000<y) ans--;
  if(100*w+10*(z/1000%10)+z/10000>z) ans--;
  cout<<ans<<endl;
}

Measured memory_bytes: 3632
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
graph = [[] for _ in range(N+1)]
AB = [lr() for _ in range(N-1)]
for a, b in AB:
    graph[a].append(b)
    graph[b].append(a)

root = 1
parent = [0] * (N+1)
order = []
stack = [(root, 0)]
color = [0] * (N+1)
# 頂点と、親方向の辺を対応させる
while stack:
    cur, ng = stack.pop()
    c = 1
    for next in graph[cur]:
        if next == parent[cur]:
            continue
        if c == ng:
            c += 1
        parent[next] = cur
        color[next] = c
        stack.append((next, c))
        c += 1

answer = []
append = answer.append
for a, b in AB:
    if parent[a] == b:
        append(color[a])
    else:
        append(color[b])

print(max(answer))
print(*answer, sep='\n')
# 02

Measured memory_bytes: 39792
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <deque>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <iomanip>
using namespace std;

int main()
{
    int num;
    cin >> num;
    int town[100001];
    int brave[100001];
    for(int i=0;i<=num;i++){
        cin >> town[i];
    }
    for(int i=0;i<num;i++){
        cin >> brave[i];
    }

    long ans = 0;
    //town0
    if(town[0]>=brave[0]){
        ans += brave[0];
        brave[0]=0;
    }else{
        ans += town[0];
        brave[0]-=town[0];
    }

    for(int i=1;i<num;i++){
        if(town[i]>=brave[i-1]){
            ans += brave[i-1];
            town[i]-=brave[i-1];
        }else{
            ans += town[i];
            town[i]=0;
        }
        if(town[i]>=brave[i]){
            ans += brave[i];
            brave[i]=0;
        }else{
            ans += town[i];
            brave[i]-=town[i];
        }
    }

    //townN
    if(town[num]>brave[num-1]){
        ans += brave[num-1];
    }else{
        ans += town[num];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define deb(x) cout<<#x<<" " <<x<<"\n";
#define pi 3.1415926535897932384626433832795
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define cr7 ios_base::sync_with_stdio(false);cin.tie(NULL);
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (((a)*(b))/gcd((a),(b)))

//POWER FUNCTION

ll power(ll x, ll y)
{
    ll temp;
    if ( y == 0)
        return 1;
    temp = power(x, y / 2);
    if (y % 2 == 0)
        return ((temp) * (temp));
    else
        return (x * (temp) * (temp));
}
int main()
{
    cr7
#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
#endif
    ll x;
    cin >> x;
    ll a = 1;
    for (ll i = -1000; i <= 1000; ++i) {
        for (ll j = -1000; j <= 1000; ++j) {
            if (power(i, 5) - power(j, 5) == x) {
                cout << i << " " << j << "\n";
                return 0;
            }
        }
    }
    return 0;
}

//OUTPUT

/*

*/

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

using namespace std;

#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)

const int maxn = 1e5 + 5;
int N, A[maxn], B[maxn], Cnt;
map<int, int> mp;

int main() {
  //  freopen("c.in", "r", stdin);
  //  freopen("c.out", "w", stdout);
  scanf("%d", &N);
  foru(i, 1, N) scanf("%d", &A[i]);
  foru(i, 1, N) B[i] = A[i];
  sort(B + 1, B + N + 1);
  foru(i, 1, N) mp[B[i]] = i;
  foru(i, 1, N) A[i] = mp[A[i]];
  foru(i, 1, N) Cnt += (A[i] & 1) ^ (i & 1);
  printf("%d\n", (Cnt + 1) >> 1);
  return 0;
}


Measured memory_bytes: 5760
//By TheOneYouWant
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i=0;i<e;++i)
#define forsn(i,s,e) for(int i=s;i<e;++i)
#define rforn(i,s) for(int i=s;i>=0;--i)
#define rforsn(i,s,e) for(int i=s;i>=e;--i)
#define bitcount(a) __builtin_popcount(a) // set bits (add ll)
#define ln '\n'
#define getcurrtime() cerr<<"Time = "<<((double)clock()/CLOCKS_PER_SEC)<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cerr<<endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t"; err(++it, args...);
}
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
	c<<"("<<v.fi<<","<<v.se<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    forstl(x,c) out<<x<<" ";
    out<<"}"; return out;
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM=2e5+5,MOD=1e9+7;
const ld EPS = 1e-9;

int read(){
    int xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=(xx<<3)+(xx<<1)+ch-'0';ch=getchar();}
    return xx*ff;
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using mint = modint;

int main(){
	fastio;
	mint::set_mod(MOD);

	int n, d; cin>>n>>d;
	ll x[n], y[n];
	forn(i,n){
		cin>>x[i]>>y[i];
	}
	two_sat ts(2*n);
	forn(i,n){
		ts.add_clause(2*i,1,2*i+1,1);
	}
	forn(i,n){
		forn(j,i){
			forn(l,2){
				forn(k,2){
					int pos1 = x[i];
					if(l == 1) pos1 = y[i];
					int pos2 = x[j];
					if(k == 1) pos2 = y[j];
					if(abs(pos1-pos2)<d){
						ts.add_clause(2*i+l,0,2*j+k,0);
					}
				}
			}
		}
	}
	if(ts.satisfiable()){
		cout<<"Yes"<<ln;
		vector<bool> v = ts.answer();
		forn(i,n){
			if(v[2*i]){
				cout<<x[i]<<ln;
			}
			else{
				cout<<y[i]<<ln;
			}
		}
	}
	else cout<<"No"<<ln;

	return 0;
}

Measured memory_bytes: 3764
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i=0; i<n; i++)
#define loop(i, j, n) for(int i=j; i<n; i++)
using namespace std;
int main()
{
	int h, w;
	cin >> h >> w;
	vector<string> a(h);
	rep(i,h){
		cin >> a[i];
	}

	vector<bool> row(h, false);
	vector<bool> col(w, false);
	rep(i,h){
		rep(j,w){
			if(a[i][j] == '#'){
				row[i] = true;
				col[j] = true;
			}
		}
	}

	rep(i,h){
		if(row[i]){
			rep(j,w){
				if(col[j]){
					cout << a[i][j];
				}
			}
			cout << endl;
		}
	}

	return 0;
}


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

#define NL '\n'
#define C char
#define D double
#define F float
#define S string

#define sz(x) x.size()
#define INF LONG_MAX
#define IINF LLONG_MAX
#define PI (2.0*acos(0.0))

#define sfi(x) scanf("%d",&x)
#define sfi2(x,y) scanf("%d %d",&x,&y)
#define sfi3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sfl(x) scanf("%lld",&x)
#define sfl2(x,y) scanf("%lld %lld",&x,&y)
#define sfl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sfd(x) scanf("%lf",&x);

#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d) max(max3(a,b,c),d)
#define min3(a,b,c) min(a,min(b,c))
#define min4(a,b,c,d) min(a,min3(b,c,d))

#define pb push_back
#define mp(x,y) make_pair(x,y)
#define all(x) x.begin(),x.end()
#define asort(x) sort(all(x));
#define dsort(x) sort(all(x), greater<int>())
#define unq(x) x.erase(unique(x.begin(),x.end()),x.end())

#define mem(ara,val) memset(ara,val,sizeof(ara))
#define READ freopen("input.txt","r",stdin)
#define WRITE freopen("output.txt","w",stdout)
#define IOS ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0)

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;

LL gcd(LL a,LL b)
{
    if(b==0) return a;
    else return gcd(b,a%b);
}
LL lcm(LL a,LL b)
{
    return a/gcd(a,b)*b;
}

LL bigmod(LL base, LL power, LL mod)
{
    if(power==0) return 1;
    else if(power%2==1)
    {
        LL value1 = base % mod; LL value2 = (bigmod(base,power-1,mod))%mod;
        return (value1*value2)%mod;
    }
    else
    {
        LL value1 = (bigmod(base,power/2,mod))%mod;
        return (value1*value1)%mod;
    }
}



int main()
{
    //IOS;

    /*int a,b;
    sfi2(a,b);
    int c,d;
    sfi2(c,d);

    int i = 2;
    while(true)
    {
        if(a<=0)
        {
            cout<<"No";
            break;
        }
        if(c<=0)
        {
            cout<<"Yes";
            break;
        }

        else if(i%2==0)
        {
             c -= abs(d-b);
             i++;
        }
        else if(i%2)
        {
            a-= abs(b-d);
            i++;
        }
    }*/

    int n;
    sfi(n);

    map <S,int> maap;

    while(n--)
    {
        S s;
        cin>>s;
        maap[s]++;
    }

    cout<<sz(maap);

}


Measured memory_bytes: 19116
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>

using namespace std;

int main()
{
	int a, b, c, k,max=0, ans;
	cin >> a >> b >> c>>k;
	ans = a + b + c;
	if (max < a) max = a;
	if (max < b) max = b;
	if (max < c) max = c;
	ans -= max;
	for (int i = 0; i < k; i++) {
		max = max * 2;
	}
	ans += max;
	cout <<ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <sstream>
#include <algorithm>
using namespace std;
#define pb push_back
#define mp make_pair
#define ms(a, b)  memset((a), (b), sizeof(a))
#define eps 0.0000001
typedef long long LL;
typedef unsigned long long ULL;
const int inf = 0x3f3f3f3f;
const LL INF = 0x7fffffff;
const int maxn = 1e6+10;
const int mod = 1e9+7;

void init() {

}
void solve() {
    LL H, W;
    cin >> H >> W;
    if(H%3==0|| W%3==0) {
        cout << "0" << endl;
        return;
    } else {
        LL ans = INF;
        LL s1, s2, s3, s4;
        for(LL i = 1; i<=H; i++) {
            s1 = i*W;
            s2 = (H-i)*W;
            if(s2%2==0) {
                s4 = s3 = s2/2;
            } else {
                s3 = (H-i)*(W/2);
                s4 = s2 - s3;
            }
            LL Min = min(min(s1, s3), s4);
            LL Max = max(max(s1, s3), s4);
            ans = min(ans, Max-Min);
        }
        for(LL i = 1; i<=W; i++) {
            s1 = i*H;
            s2 = (W-i)*H;
            if(s2%2==0) {
                s4 = s3 = s2/2;
            } else {
                s3 = (W-i)*(H/2);
                s4 = s2 - s3;
            }
            LL Min = min(min(s1, s3), s4);
            LL Max = max(max(s1, s3), s4);
            ans = min(ans, Max-Min);
        }
        cout << ans << endl;
    }

}
int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
//      freopen("output.txt", "w", stdout);
#endif // LOCAL
    init();
    solve();
    return 0;
}


Measured memory_bytes: 256
x, y = map(int, input().split())

def answer():
    if y % 2 == 1:
        return False

    a = 2 * x - y // 2
    b = - x + y // 2

    return (0 <= a and 0 <= b)


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




Measured memory_bytes: 9168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }

int main(){
    char c; cin >> c;
    if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') cout << "vowel" << endl;
    else cout << "consonant" << endl;
}

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

int main() {
	int N, M, a, b;
	size_t i;
	vector<int> first, last;
	cin >> N >> M;
	for (int i = 0; i < M; ++i) {
		cin >> a >> b;
		if (a == 1) first.push_back(b);
		else if (b == N) last.push_back(a);
	}
	sort(last.begin(), last.end());
	for (i = 0; i < first.size(); ++i) {
		if (binary_search(last.begin(), last.end(), first[i])) break;
	}
	if (i == first.size()) cout << "IMPOSSIBLE";
	else cout << "POSSIBLE";
}

Measured memory_bytes: 1276
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int main()
{
	int n;
	int i, j;
	int x, y;
	int temp;
	scanf("%d", &n);
	x = 800 * n;
	y = n / 15 * 200;
	printf("%d\n", x - y);

}

Measured memory_bytes: 256
n,k=map(int, input().split())
l=sorted(list(map(int, input().split())))
ll=[]

cont=1
for i in range(n-1):
  if l[i]==l[i+1]:
    cont+=1
  else:
    ll.append(cont)
    cont=1
ll.append(l.count(l[-1]))
ll.sort()
ll.reverse()

print(sum(ll[k:]))

Measured memory_bytes: 26004
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2000000 + 10;
const int mod = 1e9 + 7;
ll qpow(ll n,ll k){
    ll res = 1;
    while(k){
        if(k&1) res = res * n % mod;
        n = n * n % mod;
        k >>= 1;
    }
    return res;
}
ll fac[N],inv[N];
ll C(int n,int k){
    return fac[n] * inv[k] % mod * inv[n-k] % mod;
}
ll f(int x,int y){
    int n = 0, k = 0;
    ll S = 1, ans = S;
    for(int i=1;i<=x;i++){
        S = (S * 2 - C(n,k) + mod) % mod, n++;
        S = (S + C(n,k+1)) % mod, k++;
//        cout<<n<<' '<<k<<' '<<S<<endl;
        ans += S;
    }
    for(int i=1;i<=y;i++){
        S = (S * 2 - C(n,k) + mod) % mod, n++;
//        cout<<n<<' '<<k<<' '<<S<<endl;
        ans += S;
    }
    n = 0, k = 0, S = 1, ans -= S;
    for(int i=1;i<=y;i++){
        S = (S * 2 - C(n,k) + mod) % mod, n++;
//        cout<<n<<' '<<k<<' '<<S<<endl;
        ans -= S;
    }
    for(int i=1;i<=x;i++){
        S = (S * 2 - C(n,k) + mod) % mod, n++;
        S = (S + C(n,k+1)) % mod, k++;
//        cout<<n<<' '<<k<<' '<<S<<endl;
        ans -= S;
    }
    for(int i=0;i<=y;i++) ans += C(i,0);
    for(int i=1;i<=x;i++) ans += C(i+y,i);
//    cout<<x<<' '<<y<<' '<<ans<<endl;
    return (ans % mod + mod) % mod;
}
int main(){
    fac[0] = 1; for(int i=1;i<N;i++) fac[i] = fac[i-1] * i % mod;
    inv[N-1] = qpow(fac[N-1],mod-2);
    for(int i=N-2;i>=0;i--) inv[i] = inv[i+1] * (i+1) % mod;
    int x1,x2,y1,y2;
    cin>>x1>>y1>>x2>>y2;
    ll ans = f(x2,y2)-f(x2,y1-1)-f(x1-1,y2)+f(x1-1,y1-1);
    ans = (ans % mod + mod) % mod;
    cout<<ans<<endl;
}


Measured memory_bytes: 31488
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (int i = (int)(start); i < (int)(n); ++i)
static const int INFTY = (1 << 30);
int N, M;
void msearch(vector<vector<bool>> &g, bool *isv, int v, int &ans)
{
    bool visited = true;
    rep(i, 1, N + 1)
    {
        if (!isv[i])
        {
            visited = false;
            break;
        }
    }
    if (visited)
    {
        ++ans;
        return;
    }
    rep(i, 1, N + 1)
    {
        if (g[v][i] && !isv[i])
        {
            isv[i] = true;
            msearch(g, isv, i, ans);
            isv[i] = false;
        }
    }
}
void func()
{
    cin >> N >> M;
    vector<vector<bool>> g(N + 1, vector<bool>(N + 1, false));
    bool isv[N + 1] = {};
    isv[1] = true;
    int ai, bi;
    rep(i, 0, M)
    {
        cin >> ai >> bi;
        g[ai][bi] = true;
        g[bi][ai] = true;
    }
    int ans = 0;
    msearch(g, isv, 1, ans);
    cout << ans << endl;
}
int main()
{
    func();
}

Measured memory_bytes: 3616
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
    for (T& x: vec) { is >> x; }
    return is;
}

ll tr[3001][3001] = {};
ll dp[3001][3001][4] = {};

int main() {
	ll ans = 0;
	ll tmp;
	int r, c, k; cin >> r >> c >> k;
	int X, Y;
	ll V;
	REP(no, k){
		cin >> X >> Y >> V;
		tr[X][Y] = V;
		//tr[no / c][no%c] = 1000000000;
	}
	REP1(x, r){
		REP1(y, c){
			REP(st, 4) dp[x][y][0] = max(dp[x][y][0], dp[x-1][y][st]);
			REP(st, 4) dp[x][y][1] = max(dp[x][y][1], dp[x-1][y][st]+tr[x][y]);
			REP(st, 4) dp[x][y][st] = max(dp[x][y][st], dp[x][y-1][st]);
			REP1(st, 3) dp[x][y][st] = max(dp[x][y][st], dp[x][y-1][st-1]+tr[x][y]);
			//REP(i, 4) cout << dp[x][y][i] << " ";
		}
		//cout << endl;
	}
	REP(i, 4) ans = max(ans, dp[r][c][i]);
	cout << ans << endl;
}

Measured memory_bytes: 355236
A=0;G=1;C=2;T=3
N=int(input())
dp=[[[[0 for i in range(4)]for i in range(4)]for i in range(4)]for i in range(N+1)]
mod=10**9+7
dp[0][T][T][T]=1
for i in range(N):
    for j in range(4):
        for k in range(4):
            for l in range(4):
                for m in range(4):
                    if (k==A and l==G and m==C):
                        continue
                    if (k==G and l==A and m==C):
                        continue
                    if (k==A and l==C and m==G):
                        continue
                    if (j==A and l==G and m==C):
                        continue
                    if (j==A and k==G and m==C):
                        continue
                    dp[i+1][k][l][m]+=dp[i][j][k][l]
                    dp[i+1][k][l][m]%=mod
ans=0
for i in range(4):
    for j in range(4):
        for k in range(4):
            ans+=dp[N][i][j][k]
            ans%=mod
print(ans)

Measured memory_bytes: 3316
#include <stdio.h>

int main(){
	int W, H, x, y, r,xr,xr2,yr,yr2;
	scanf("%d%d%d%d%d", &W, &H, &x, &y, &r);
	xr = x + r;
	xr2 = x - r;
	yr = y + r;
	yr2 = y - r;
	if ((xr2 >= 0 && xr <= W) && (yr2 >= 0 && yr <= H) )
	{
		printf("Yes\n");
		
	}
	else
	{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 584
st = gets.chomp!.split(" ")
n = st[0].to_i
m = st[1].to_i
a = Array.new(m+1,0)
count = 0

for i in 1..n
    st = gets.chomp!.split(" ")
    
    for j in 1..st[0].to_i
        a[st[j].to_i] += 1
    end
end

for i in 1..m
    if a[i] == n
        count += 1
    end
end

puts count

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
#define PI 3.14159265358979323846264338327950L
const int mod=1000000007,MAX=200005,INF=1<<30;

int main() {
	int x;
  	cin>>x;
  
  if(x==1){
  	cout<<0<<endl;
  }

  else{
  	cout<<1<<endl;
  }

}

Measured memory_bytes: 3632