akhauriyash/Code-Regression huggingface dataset:
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextFloat() float64 {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return float64(i)
}

func main() {
	sc.Split(bufio.ScanWords)
	a, b, c := nextInt(), nextInt(), nextInt()

	d := c - a - b
	if d > 0 && 4*a*b < d*d {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 640
#include<stdio.h>

const int mod = 1e9 + 7;
long long fact[302020], rfact[302020];

long long modPow(int x, int n)
{
  if(n == 0) return (1);
  long long ret = modPow(x, n / 2);
  ret *= ret;
  ret %= mod;
  if(n % 2 == 1) {
    ret *= x;
    ret %= mod;
  }
  return (ret);
}

long long modInv(int p)
{
  return (modPow(p, mod - 2));
}

long long modCombination(int p, int q)
{
  if(q < 0 || p < q) return (0);
  return (fact[p] * rfact[q] % mod * rfact[p - q] % mod);
}

void init()
{
  fact[0] = rfact[0] = 1;
  for(int i = 1; i < 302020; i++) {
    fact[i] = fact[i - 1] * i % mod;
    rfact[i] = modInv(fact[i]);
  }
}

int main()
{
  int N, A[100000];
  int appear[100000] = {};
  int i, left, right;
  long long curr = 0;

  init();

  scanf("%d", &N);
  ++N;
  for(i = 0; i < N; i++) {
    scanf("%d", &A[i]);
    --A[i];
    ++appear[A[i]];
  }


  for(i = 0; i < N; i++) {
    if(appear[A[i]] == 2) {
      left = i;
      break;
    }
  }
  for(i = N - 1; i >= 0; i--) {
    if(appear[A[i]] == 2) {
      right = N - i - 1;
      break;
    }
  }

  for(i = 1; i <= N; i++) {
    printf("%lld\n", (modCombination(N, i) + mod - modCombination(right + left, i - 1)) % mod);
  }

  return(0);
}

Measured memory_bytes: 6656
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string.h>
using namespace std;

int main(void) {
	int N, K, mother = 1, child = 1, answer = 0;
	cin >> N >> K;
	for (int i = 0; i < K; i++) {
		answer = (N - i) / (K - i);
	}
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    abc093a()
}

fun abc093a() {
    val s = readLine()!!.toCharArray().sorted()

    val answer = if (s[0] == 'a' && s[1] == 'b' && s[2] == 'c') "Yes" else "No"

    println(answer)
}


Measured memory_bytes: 34032
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define fir first
#define sec second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=2e5+5;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}int n,fa[MAXN],MMx[MAXN],Mx[MAXN],son[MAXN],ans[MAXN],rt[MAXN];vector<int>G[MAXN];
void dfs1(int x,int f){
	fa[x]=f,Mx[x]=Mx[f],MMx[x]=MMx[f];
	if(x>Mx[x])MMx[x]=Mx[x],Mx[x]=x;else MMx[x]=max(MMx[x],x);
	if(Mx[x]==Mx[f]){if(Mx[f]==f)son[x]=x;else son[x]=son[f];}
	for(int i=0,len=G[x].size(),y;i<len;i++)if((y=G[x][i])!=f)dfs1(y,x);
}
int ls[MAXN*60],rs[MAXN*60],cnt[2][MAXN*60],tot;
void upd(int&x,int l,int r,int p,int c){
	if(!x)x=++tot;if(l==r){cnt[c][x]++;return;}int mid=l+r>>1;
	if(p<=mid)upd(ls[x],l,mid,p,c);else upd(rs[x],mid+1,r,p,c);
}int Merge(int x,int y,int l,int r){
	if(!x||!y)return x+y;if(l==r){cnt[0][x]+=cnt[0][y],cnt[1][x]+=cnt[1][y];return x;}
	int mid=l+r>>1;ls[x]=Merge(ls[x],ls[y],l,mid),rs[x]=Merge(rs[x],rs[y],mid+1,r);return x;
}int Ask(int x,int l,int r,int p,int c){
	if(!x)return 0;if(l==r)return cnt[c][x];int mid=l+r>>1;
	return p<=mid?Ask(ls[x],l,mid,p,c):Ask(rs[x],mid+1,r,p,c);
}void dfs2(int x){
	upd(rt[x],1,n,MMx[x],0),upd(rt[x],1,n,Mx[x],1);
	for(int i=0,len=G[x].size(),y;i<len;i++)
		if((y=G[x][i])!=fa[x])dfs2(y),rt[x]=Merge(rt[x],rt[y],1,n);
}void Solve(int x){
	if(x!=1){
		if(Mx[x]!=x)ans[x]=Ask(rt[son[x]],1,n,Mx[x],1)+Ask(rt[Mx[x]],1,n,MMx[Mx[x]],0)-Ask(rt[son[x]],1,n,MMx[Mx[x]],0)+ans[fa[Mx[x]]];
		else ans[x]=Ask(rt[x],1,n,MMx[x],0)+ans[fa[x]];
	}for(int i=0,len=G[x].size(),y;i<len;i++)if((y=G[x][i])!=fa[x])Solve(y);
}
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read();Rep(i,1,n-1){int x=read(),y=read();G[x].push_back(y),G[y].push_back(x);}
	dfs1(1,0),dfs2(1),Solve(1);Rep(i,2,n)cout<<ans[i]<<" ";cout<<'\n';
	return 0;
}




Measured memory_bytes: 130272
package main

import (
	"fmt"
)

func main() {
	var N int
	var S string
	fmt.Scan(&N)
	fmt.Scan(&S)
	max := 0
	for i := 0; i < len(S)-1; i++ {
		f := map[int32]int{}
		l := map[int32]int{}
		for _, v := range S[:i+1] {
			f[v]++
		}
		for _, v := range S[i+1:] {
			l[v]++
		}
		cnt := 0
		for k, _ := range f {
			if _, ok := l[k]; ok {
				cnt++
			}
		}
		if cnt > max {
			max = cnt
		}
	}
	fmt.Println(max)
}

Measured memory_bytes: 640
#include"stdio.h"
int main(){
    char s[100001],a[100001];
    scanf("%s",s);
    int cnt=0;
    while(s[cnt]!='\0'){
        if(cnt%2==0)
            a[cnt/2]=s[cnt];
        cnt++;
    }
    printf("%s\n",a);
}


Measured memory_bytes: 1760
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        int[] cum1 = new int[n+1];
        int[] cum2 = new int[n+1];
        for(int i = 1; i <= n; i++){
            cum1[i] = cum1[i-1]+sc.nextInt();
        }
        for(int i = 1; i <= n; i++){
            cum2[i] = cum2[i-1]+sc.nextInt();
        }
        long ans = 0;
        for(int i = 1; i <= n; i++){
            ans = Math.max(ans,cum1[i] + (cum2[n]-cum2[i-1]));
        }
        System.out.println(ans);
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
    
    public double[] nextDoubleArray(int n) {
        double[] a = new double[n];
        for (int i = 0; i < n; i++)
            a[i] = nextDouble();
        return a;
    } 
}


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


int main() {

    int n;
    cin >> n;
    vector<int> a(n);
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        int s; cin >> s;
        sum += s;
        a[i] = s;
    }
    sort(a.begin(), a.end());
    if (sum % 10 == 0) {
        for (int i = 0; i < n; ++i) {
            if (a[i] % 10 != 0) {
                sum -= a[i];
                break;
            }
        }
    }
    if (sum % 10 == 0) {
        cout << 0 << endl;
        return 0;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int , int> P;
typedef pair<ll, ll> PL;
const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}
 
ll n;
const int SIZE = 100+10;
ll x[SIZE],y[SIZE],h[SIZE];
ll p[SIZE][SIZE],pc[SIZE][SIZE];
int main(){
    cin >> n;
    for(int i = 0; i < n ; i++ )    cin >> x[i] >> y[i] >> h[i];

    for(int i = 0; i < n; i++){
        if(h[i] == 0)   continue;
        for(int j = 0; j <= 100; j++){
            for(int k = 0; k <= 100; k++){
                p[j][k] = h[i]+abs(x[i]-j)+abs(y[i]-k);
            }
        }
    }

    for(int k = 0; k <= 100; k++){
        for(int l = 0; l <= 100; l++){
            bool flag = true;
            for(int i = 0; i < n; i++){
                if(max(p[k][l]-abs(k-x[i])-abs(l-y[i]),0*1LL) != h[i])  flag = false;    
            }

            if(flag){
                cout << k << ' ' << l << ' ' << p[k][l] << ' ' << endl;
                return 0;
            }
        }
    }

}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main (){
	int N,L;
	string T,U;
	cin >> N >> L;
	vector<string> s;
	cin.ignore();	
	for(int i = 0; i < N; ++i)
	{
		cin >> T;
		s.push_back(T);
	}
	sort(s.begin(),s.end());
	for(int i = 0; i < N; ++i)
	{
		U = U + s[i];
	}
	cout << U << "\n";
	return 0;
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    int n,C; cin >> n >> C;
    vl s(n),t(n),c(n);
    vpii p;
    vector<pair<pair<int,int>,int> > pp;
    rep(i,n){
        cin>>s[i]>>t[i]>>c[i];
        p.push_back({s[i],t[i]});
        pp.push_back({p[i],c[i]});
    }
    sort(all(pp));
    vpii res;
    rep(i,n){
        int ss = pp[i].first.first;
        int tt = pp[i].first.second;
        int cc = pp[i].second;
        bool check = false;
        rep(j,res.size()){
            int tt1 = res[j].first;
            int cc1 = res[j].second;
            if(cc1 == cc){ //同じチャネル
                if(tt1 <= ss){
                    res[j] = {tt,cc};
                    check = true;
                    break;
                }
            }
            else{
                if(tt1 + 0.5 <= ss){
                    res[j] = {tt,cc};
                    check = true;
                    break;
                }
            }
        }
        if(check == false)res.push_back({tt,cc});
        //cout << ss << " " << tt << " " << cc << endl;
    }
    out(res.size());
}


Measured memory_bytes: 4752
#include<iostream>
using namespace std;
int main()
{
	long long n,sum=0,i,temp;
	string s;
	cin>>s;
	int k = s.length();
	for(i=0;i<k;i++)
	{
		n=s[i]-'0';
		temp=n%10;
		sum=sum+temp;
	}
	if(sum%9==0)
		cout<<"Yes\n";
	else
		cout<<"No\n";
	return 0;
}

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

char buf[100];
int cnt;
int N;
string calc_p(string c){
  if( c[0] == '?' ) return c;
  c[0]-='A';
  c[0]++;
  c[0]%=26;
  c[0]+='A';
  return c;
}
string calc_m(string c){
  if( c[0] == '?' ) return c;
  c[0]-='A';
  c[0]+=25;
  c[0]%=26;
  c[0]+='A';
  return c;
}


string Letter();
string String();
string Cipher();

string Letter(){
  if( buf[cnt] == '+' ) {
    cnt++;
    return calc_p(Letter());
  } else if (buf[cnt] == '-' ){
    cnt++;
    return calc_m(Letter());
  } else {
    string ret = ""; ret += buf[cnt];
    cnt++;
    return ret;
  }
}

string String(){
  if( buf[cnt] == '[' ){
    cnt++;
    string ret = Cipher();
    reverse(ret.begin(),ret.end());
    cnt++;
    return ret;
  } else {
    return Letter();
  }
}

string Cipher(){
  string s = String();
  while( cnt < N ){
    if( buf[cnt] == ']' ) break;
    s+=String();
  }
  return s;
}

int main(){
  while( cin >> buf ){
    if( buf[0] == '.' ) break;
    cnt = 0;
    N = strlen(buf);
    string res = Cipher();
    for(int i=0;i<(int)res.size();i++){
      if( res[i] == '?' ) cout << 'A';
      else cout << res[i];
    }
    cout << endl;
  }
}

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

int main() {
  int n,k,ans=0;
  cin >> n >> k;
  vector<int> h(n);
  rep(i,n){
    cin >> h[i];
  }
  rep(i,n){
    if(h[i]>=k){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
  ll n, m; cin >> n >> m;
  ll res = 0;
  if(n > 1) res += n*(n-1)*0.5;
  if(m > 1) res += m*(m-1)*0.5;
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<vector>
#include<list>
using namespace std;
const int MAX = 10000;
const int INF = 100000;
int n;
vector<int> G[MAX];
bool book[MAX];
int indeg[MAX];
list<int> L;
void breathFSearch(int s)
{
	queue<int> Q;
	Q.push(s);
	book[s] = true;
	while (!Q.empty())
	{
		int u = Q.front();
		Q.pop();
		L.push_back(u);
		for (int i = 0; i < G[u].size(); i++)
		{
			int v = G[u][i];
			indeg[v]--;
			if (!indeg[v] && !book[v])
			{
				book[v] = true;
				Q.push(v);
			}
		}
	}
}
void topologicalSort()
{
	for (int i = 0; i < n; i++)
		if (!book[i] && !indeg[i])
			breathFSearch(i);
}
int main()
{
	int m;
	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		int u, v;
		cin >> u >> v;
		G[u].push_back(v);
		indeg[v]++;
	}
	topologicalSort();
	for (list<int>::iterator it = L.begin(); it != L.end(); it++)
		cout << *it << endl;
}


Measured memory_bytes: 3984
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {

    static BufferedReader br;
    static StringTokenizer st;

    public static void main(final String[] args) {
        br = new BufferedReader(new InputStreamReader(System.in));

        try {
            final int N = readInt();
            final int M = readInt();

            // final List<Integer> lights = new ArrayList<>();
            final Integer[] lights = new Integer[N];

            final List<List<Integer>> s = new ArrayList<>();
            for (int i = 0; i < M; i++) {
                s.add(new ArrayList<>());

                final int k = readInt();
                for (int j = 0; j < k; j++) {
                    s.get(i).add(readInt() - 1);
                }
            }

            final List<Integer> p = new ArrayList<>();
            for (int i = 0; i < M; i++) {
                p.add(readInt());
            }

            final Solver solver = new Solver();

            System.out.println(solver.solve(N, M, s, p));

        } catch (final IOException e) {
            e.printStackTrace();
        }
    }

    static String next() throws IOException {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine().trim());
        return st.nextToken();
    }

    static long readLong() throws IOException {
        return Long.parseLong(next());
    }

    static int readInt() throws IOException {
        return Integer.parseInt(next());
    }

    static double readDouble() throws IOException {
        return Double.parseDouble(next());
    }

    static char readCharacter() throws IOException {
        return next().charAt(0);
    }

    static String readLine() throws IOException {
        return br.readLine().trim();
    }
}

class Solver {
    public int solve(
            final int N,
            final int M,
            final List<List<Integer>> s,
            final List<Integer> p
    ) {
        int ans = 0;

        for (int i = 0; i < (1 << N); i++) {
            boolean ok = true;

            for (int j = 0; j < M; j++) {
                int c = 0;

                for (final Integer light : s.get(j)) {
                    if (((i >> light) & 1) == 1) {
                        c++;
                    }
                }

                if (c % 2 != p.get(j)) {
                    ok = false;
                    break;
                }
            }

            if (ok) {
                ans++;
            }
        }
        return ans;
    }
}


Measured memory_bytes: 23252
# = int(input())
# = map(int, input().split())
# = list(map(int, input().split()))
# = list(input())
# = [tuple(map(int, input().split())) for _ in range(n)]

n, d, a = map(int, input().split())
xh = [list(map(int, input().split())) for _ in range(n)]

xh.sort()

R = [0] * n
H = 0
for L in range(n):
    while H < n:
        if xh[H][0] > xh[L][0] + d * 2:
            H -= 1
            break
        H += 1
    if H == n:
        H -= 1
    R[L] = H + 1

cs = [0] * (n+1)
H = n - 1
ans = 0
for i in range(n-1, -1, -1):
    x = xh[i][1] // a
    if xh[i][1] % a > 0:
        x += 1
    y = cs[i+1] - cs[R[i]]
    if y >= x:
        cs[i] = cs[i+1]
    else:
#        ans += x - y
        cs[i] = cs[i+1] + x - y

print(cs[0])

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

int main() {
	ll n;
	string s;
	cin >> n;
	cin >> s;
	vector<bool> r(n,false), g(n,false), b(n,false);
	ll cnt_r = 0;
	ll cnt_g = 0;
	ll cnt_b = 0;
	ll ans = 0;
	rep(i,n) {
		if (s[i] == 'R') {
			r[i] = true;
			cnt_r++;
		}
		if (s[i] == 'G') {
			g[i] = true;
			cnt_g++;
		}
		if (s[i] == 'B') {
			b[i] = true;
			cnt_b++;	
		}
	} 
	ans = cnt_r * cnt_g * cnt_b;
	for (ll i=0;i<n;i++) {
		for (ll d=1;i+2*d<n;d++) {
			if(r[i] && g[i+d] && b[i+2*d]) ans--;
			if(r[i] && g[i+2*d] && b[i+d]) ans--;
			if(r[i+d] && g[i+2*d] && b[i]) ans--;
			if(r[i+d] && g[i] && b[i+2*d]) ans--;
			if(r[i+2*d] && g[i+d] && b[i]) ans--;
			if(r[i+2*d] && g[i] && b[i+d]) ans--;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3636
/*input
4
2 2 1 3
*/
#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define rd() abs((int)rng())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int maxn = 2e5 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0);
	int n;
	cin >> n;
	vector<int>v(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	sort(all(v), greater<int>());
	ll ans = v[0];
	int togo = n - 2;
	for (int i = 1; i < n; i++) {
		if (!togo) {
			break;
		}
		if (togo >= 2) {
			ans += v[i] * 2;
		} else {
			ans += v[i];
		}
		togo -= min(2, togo);
		if (togo == 0) {
			break;
		}
	}

	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3988
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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; }

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  string s;
  cin >> s;
  ll n = s.size();
  ll ans = n;
  rep(i, n-1) {
    // here, check the boundary of s[i] and s[i+1]
    if (s[i] != s[i+1]) {
      ll now = max(i+1, n-i-1);
      chmin(ans, now);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define vi vector <int>
#define endl "\n"
#define vvi vector <vector<int> >
#define vii vector <pair<int,int> >
#define rep(i,a,b) for (int i=a;i<b;i++)
#define repD(i,a,b) for (int i=a;i>=b;i--)
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define gcd __gcd
#define init(i,k) memset(i,k,sizeof i)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define setBits(x) __builtin_popcountll(x)
#define pii pair <int,int>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
int lcs[3001][3001];
string s,t;
int fun(int i,int j,int n,int m)
{
	if(i>=n || j>=m)
	{
		return 0;
	}
	if(lcs[i][j]!=-1)
	{
		return lcs[i][j];
	}
	if(s[i]==t[j])
	{
		lcs[i][j]=1+fun(i+1,j+1,n,m);
	}
	else
	{
		lcs[i][j]=max(fun(i+1,j,n,m),fun(i,j+1,n,m));
	}
	return lcs[i][j];
}
string solve()
{
	cin>>s>>t;
	int n=s.size();
	int m=t.size();
	int x=fun(0,0,n,m);
	//cout<<x<<endl;
	string ans="";
	int i=0,j=0;
	while(x>0)
	{
		if(s[i]==t[j])
		{
			ans+=s[i];
			x--;
			i++;
			j++;
		}
		else
		{
			if(lcs[i+1][j]>lcs[i][j+1])
			{
				i++;
			}
			else
			{
				j++;
			}
		}
	}
	return ans;
}
signed main()
{
    int t=1;
    //cin>>t;
    for(int i=0;i<=3000;i++)
    {
    	for(int j=0;j<=3000;j++)
    	{
    		lcs[i][j]=-1;
    	}
    }
    while(t--)
    {
    	cout<<solve()<<endl;
    }
    return 0;
}

Measured memory_bytes: 74348
#include <stdio.h>

#define Mod 1000000007

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

void merge_sort(int x[], int n)
{
	static int y[100001] = {};
	if (n == 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p] < x[q])? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

int prime[11000];

int enum_primes(int n)
{
	int i, k, p;
	for (p = 2, k = 0; p < n; p++) {
		for (i = 2; i * i <= p; i++) if (p % i == 0) break;
		if (i * i > p) prime[k++] = p;
	}
	return k;
}

int factorize(int n, int p[], int m[])
{
	int i, k;
	for (i = 0, k = 0; n > 1 && prime[i] < 1000; i++) {
		if (n % prime[i] != 0) continue;
		p[k] = i;
		for (m[k] = 0; n % prime[i] == 0; m[k]++, n /= prime[i]);
		k++;
	}
	if (n > 1) {
		p[k] = n;
		m[k++] = 1;
	}
	return k;
}

int main()
{
	int i, N, A[100001];
	scanf("%d", &N);
	for (i = 0; i < N; i++) scanf("%d", &(A[i]));
	merge_sort(A, N);
	
	int j, k[2] = {enum_primes(1000)}, l, p[11000], m[11000], lcm[11000] = {};
	prime[k[0]] = 10000;
	k[1] = k[0];
	for (i = 0; i < N; i++) {
		l = factorize(A[i], p, m);
		for (j = 0; j < l && p[j] < k[0]; j++) if (lcm[p[j]] < m[j]) lcm[p[j]] = m[j];
		if (j < l) {
			for (j = k[0]; j < k[1]; j++) if (prime[j] == p[l-1]) break;
			if (j < k[1]) {
				if (lcm[j] < m[l-1]) lcm[j] = m[l-1];
			} else {
				prime[k[1]] = p[l-1];
				lcm[k[1]++] = 1;
			}
		}
	}
	
	long long L = 1, ans = 0;
	for (i = 0; i < k[1]; i++) {
		for (j = 0; j < lcm[i]; j++) L = L * prime[i] % Mod;
	}
	for (i = 0; i < N; i++) ans += div_mod(L, (long long)A[i], Mod);
	
	printf("%lld\n", ans % Mod);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1868
r,g,b,n = map(int,input().split())

ans = 0
for i in range(n//r +1):
    for j in range(n//g +1):
        if 0 <= n-r*i-g*j and (n-r*i-g*j)%b == 0:
            ans += 1

print(ans)

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int a,b;
    cin>>a>>b;
    if(max(a,b)>8)cout<<":("<<endl;
    else cout<<"Yay!"<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
class Main{
	   public static void main(String[] args){
	  Scanner scan =  new Scanner(System.in);
	   String a = scan.next();
       String b = scan.next();
       
        StringBuilder and = new StringBuilder();
      if (a.length()>b.length ()){
for (int i = 0 ;i<b.length();i++){
        and.append(a.charAt(i));
         and.append(b.charAt(i)); 
}System.out.print(and);
System.out.print(a.charAt(a.length()-1));
}else if(a.length()<b.length()){
for (int i = 0 ;i<a.length();i++){
         and.append(a.charAt(i));
         and.append(b.charAt(i));
}System.out.print(and);
System.out.print(b.charAt(b.length()-1));
}else{
for (int i = 0 ;i<b.length();i++){
         and.append(a.charAt(i));
         and.append(b.charAt(i));
}System.out.println(and);
}
}
}

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

#define pb push_back

using namespace std;

typedef long long ll;

int main(){
	int x, y, a, b, c;
	vector<ll> p, q, r;
	cin>>x>>y>>a>>b>>c;
	p.assign(a, 0);
	for(int i=0;i<a;i++){
		int tmp;
		cin>>tmp;
		p.pb(tmp);
	}
	q.assign(b, 0);
	for(int i=0;i<b;i++){
		int tmp;
		cin>>tmp;
		q.pb(tmp);
	}
	r.assign(c, 0);
	for(int i=0;i<c;i++){
		int tmp;
		cin>>tmp;
		r.pb(tmp);
	}
	sort(p.rbegin(), p.rend());
	sort(q.rbegin(), q.rend());
	sort(r.rbegin(), r.rend());
	/*r.pb(-1);
	int curr_p = 0, curr_r = 0, curr_q = 0;
	ll sum = 0;
	while(x>0 && y>0){
		if(p[curr_p] < q[curr_q]){
			if(p[curr_p] < r[curr_r])
				sum += r[curr_r++];
			else
				sum += p[curr_p++];
			x--;
		}
		else{
			if(q[curr_q] < r[curr_r])
				sum += r[curr_r++];
			else
				sum += q[curr_q++];
			y--;
		}
	}
	while(x>0){
		if(p[curr_p] < r[curr_r])
			sum += r[curr_r++];
		else
			sum += p[curr_p++];
		x--;
	}
	while(y>0){
		if(q[curr_q] < r[curr_r])
			sum += r[curr_r++];
		else
			sum += q[curr_q++];
		y--;
	}
	cout<<sum<<"\n";*/
	vector<ll> final;
	final.insert(final.end(), p.begin(), p.begin()+x);
	final.insert(final.end(), q.begin(), q.begin()+y);
	final.insert(final.end(), r.begin(), r.end());
	sort(final.rbegin(), final.rend());
	/*for(int i=0;i<final.size();i++){
		cout<<final[i]<<" "; 
	}
	cout<<"\n";*/
	ll sum = 0;
	for(int i=0;i<x+y;i++){
		sum += final[i];
	}
	cout<<sum<<"\n";
	return 0;
}

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

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

  for(int i=0;i<K;i++){
    if(i%2==0){
      A/=2;
      B+=A;
    }
    else{
      B/=2;
      A+=B;
    }
  }
  cout << A << " " << B << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int y, x;

	int we[100 + 10][100 + 10];

	char c;
	int i, j;

	cin >> y >> x;

	for (i = 0; i <= y ; i++)
	{
		for (j = 0; j < x + 2; j++)
		{
			we[i][j] = -1;
		}
	}

	scanf("%c", &c);
	for (i = 1; i <= y; i++)
	{
		for (j = 1; j <= x+1; j++)
		{
			scanf("%c", &c);

			if (c == 'c')
			{
				we[i][j] = 0;
			}
			else if(we[i][j - 1] > -1)
			{
				we[i][j] = we[i][j - 1] + 1;
			}
		}
	}
	for (i = 1; i <= y; i++)
	{
		for (j = 1; j <= x-1; j++)
		{
			cout << we[i][j] << ' ';
		}
		cout << we[i][x] << endl;
	}

	return 0;
}

Measured memory_bytes: 3180
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

 
//FUNCTION
 
//SOLVE
void solve(void)
{
  int N,M;
  cin>>N>>M;
  cout<<(N-1)*(M-1)<<endl;
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


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

int main() {
  int N;
  int A;
  string s;
  cin >> N >> A;
  if (N % 500 - A <= 0) {
    s = "Yes";
  }
  else {
    s = "No";
  }
  cout << s << endl;
}


Measured memory_bytes: 256
from collections import deque

n = int(input())
g = [list(map(int, input().split()))[2:] for _ in range(n)]
que = deque([0])
dist = [-1] * n
dist[0] = 0  # 初期条件
while que:  # queが空なるまで
    u = que.popleft()  # queの左から順に取り出す
    for v in g[u]:
        v -= 1  # 0-indexedに変更
        if dist[v] == -1:  # 未探索の時
            dist[v] = dist[u] + 1  # 最短距離を記録
            que.append(v)  # queに追加
for i in range(n):
    print(i + 1, dist[i])


Measured memory_bytes: 6028
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
input = sys.stdin.readline
 
# bisect_left(lists, 3)
# bisect_right(lists, 3)
 
def main():
	N, K = map(int, input().split(" "))
	S = input()
	S = S[:-1]
	S = list(S)

	K = K-1

	if S[K] == "A":
		S[K] = "a"
	elif S[K] == "B":
		S[K] = "b"
	elif S[K] == "C":
		S[K] = "c"

	ans = ""
	for i in S:
		ans += i
	print(ans)
		

if __name__ == "__main__":
	main()

Measured memory_bytes: 3700
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class ABuyingSweets {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    int x, a, b;
	    in >> x >> a >> b;
	    out << x - (a + (x-a) / b * b) << endl;
	}
};


int main() {
	ABuyingSweets solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>//最大公約数
using namespace std;

long long gcd(long long a,long long b);

int main(){
    long long a,b;
    cin>>a>>b;
    cout<<gcd(a,b)<<"\n";
    return(0);
}
long long gcd(long long a,long long b){
    while(b!=0){
        long long r=a%b;
        a=b;
        b=r; 
    }
    return(a);
}


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

static const int MAX = 1000;
static const int VMAX = 10000;
int n, s, A[MAX], B[MAX], T[VMAX+1];

int solve() {
    int i, ans = 0;
    bool V[MAX];
    for(i=0; i<n; ++i) {B[i] = A[i]; V[i] = false;}
    sort(B, B+n);
    for(i=0; i<n; ++i) T[B[i]] = i;
    for(i=0; i<n; ++i) {
        if(V[i]) continue;
        int S = 0, an = 0, cur = i, m = VMAX;
        while(1) {
            V[cur] = true; ++an;
            int v = A[cur]; m = min(m, v);
            S += v; cur = T[v];
            if(V[cur]) break;
        }
        ans += min(S+(an-2)*m, m+S+(an+1)*s);
    }
    return ans;
}

int main()
{
    cin >> n;
    s = VMAX;
    for(int i=0; i<n; ++i) {
        cin >> A[i];
        s = min(s, A[i]);
    }
    int ans = solve();
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3180
import copy
n = int(input())
all_list = [int(input()) for _ in range(n)]
max_value = max(all_list)
max_value_count = all_list.count(max_value)
for i in range(n):
    if all_list[i] == max_value:
        if max_value_count > 2:
            print(max_value)
        else:
            tmp = copy.copy(all_list)
            tmp.pop(i)
            print(max(tmp))
    else:
        print(max_value)

Measured memory_bytes: 14556
void main() {
	auto ip = readAs!(int[]);
	ip.sort();
	if(ip == [1,4,7,9]) writeln("YES");
	else writeln("NO");
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


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

//const ll mod =  1000000007;
//const ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvll = vector<vll>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------
//vector<bool> seen;
vll ans(200001,0);
 vll g[200001];
 vector<bool> seen;
void dfs(ll p,ll x) {
   seen[p] = true;
    if(p!=0)ans.at(p)+=x;
    
    for (auto next_v : g[p]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(next_v,ans.at(p)); // 再帰的に探索
    }
}

int main() {
  ll n,q;
  cin>>n>>q;
  
 
  vll a(n-1),b(n-1);
  rep(i,n-1){
      cin>>a.at(i)>>b.at(i);
      g[a.at(i)-1].push_back(b.at(i)-1);
       g[b.at(i)-1].push_back(a.at(i)-1);
  }
  
  vll p(q),x(q);
  rep(i,q){
      cin>>p.at(i)>>x.at(i);
      p.at(i)--;
      ans.at(p.at(i))+=x.at(i);
  }
  seen.assign(n, false); 
  dfs(0,ans.at(0));
  rep(i,n-1){
      cout<<ans.at(i)<<" ";
  }
  cout<<ans.at(n-1)<<endl;
}



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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

template<class T>inline bool chmax(T &a, const T &b) { if (b > a) { a = b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i=0; i<N; ++i) cin >> a[i];

    sort(a.rbegin(), a.rend());
    ll res = 0;
    int cur = 0;
    while (N > 1) {
        if (N == 2 || cur == 0) {
            res += a[cur++];
            --N;
        } else  {
            res += 2 * a[cur++];
            N -= 2;
        }
    }
    cout << res << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 3972
#include <bits/stdc++.h>
#define int long long
using namespace std;

template<class T>
struct Edge{
	int from,to;
	T cost;
	Edge(int to,T cost) : to(to),cost(cost){}
	Edge(int from,int to,T cost) : from(from),to(to),cost(cost){}
	operator int() const noexcept { return to; }
};

template<class T>
using WeightedGraph = vector<vector<Edge<T>>>;
using Graph = vector<vector<int>>;
template<class T>
using Matrix = vector<vector<T>>;

template<class T>
void warshallFloyd(Matrix<T> &G){
	for(int k = 0;k < G.size();k++){
		for(int i = 0;i < G.size();i++){
			for(int j = 0;j < G.size();j++){
				G[i][j] = min(G[i][j],G[i][k] + G[k][j]);
			}
		}
	}
}

int w,h;

inline int ind(int x,int y){
	return x * w + y;
}

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

void solve(){
	const int INF = 1e9;
	string field[25];
	for(int i = 0;i < h;i++) cin >> field[i];
	int pos[20],cnt = 1;
	for(int i = 0;i < h;i++){
		for(int j = 0;j < w;j++){
			if(field[i][j] == 'o') pos[0] = ind(i,j);
			else if(field[i][j] == '*') pos[cnt++] = ind(i,j);
		}
	}
	Matrix<int> G(h * w,vector<int>(h * w,INF));
	for(int i = 0;i < h * w;i++) G[i][i] = 0;
	for(int i = 0;i < h;i++){
		for(int j = 0;j < w;j++){
			for(int k = 0;k < 4;k++){
				int nx = i + dx[k],ny = j + dy[k];
				if(nx >= 0 && nx < h && ny >= 0 && ny < w && field[nx][ny] != 'x'){
					G[ind(i,j)][ind(nx,ny)] = 1;
				}
			}
		}
	}
	warshallFloyd(G);
	vector<int> vec(cnt);
	iota(vec.begin(),vec.end(),0);
	int ans = INF;
	do{
		int sum = 0;
		for(int i = 1;i < cnt;i++) sum += G[pos[vec[i - 1]]][pos[vec[i]]];
		ans = min(ans,sum);
	}while(next_permutation(vec.begin() + 1,vec.end()));
	if(ans == INF) cout << -1 << endl;
	else cout << ans << endl;
}

signed main(){
	while(cin >> w >> h,w) solve();
}


Measured memory_bytes: 3980
#![allow(non_snake_case)]

#[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 ( 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 , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ 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 , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[allow(unused_macros)]
macro_rules! chmin {
    ( $ x : expr , $ y : expr ) => {
        if $x > $y {
            $x = $y;
            true
        } else {
            false
        }
    };
}

fn main() {
    input! {
        n: usize, A: i64, B: i64, C: i64,
        l: [i64; n]
    }

    println!("{}", rec(&l,0,0,0,0,A,B,C));
}

fn rec(l: &Vec<i64>, i: usize, a: i64, b: i64, c: i64, A: i64, B: i64, C: i64) -> i64 {
    if i == l.len() {
        if a==0 || b==0 || c==0 {
            return 1i64 << 60;
        }
        return (a-A).abs()+(b-B).abs()+(c-C).abs();
    }

    let mut ret = rec(l,i+1,a,b,c,A,B,C);
    chmin!(ret, rec(l,i+1,a+l[i],b,c,A,B,C) + if a==0 {0} else {10});
    chmin!(ret, rec(l,i+1,a,b+l[i],c,A,B,C) + if b==0 {0} else {10});
    chmin!(ret, rec(l,i+1,a,b,c+l[i],A,B,C) + if c==0 {0} else {10});
    ret    
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(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;}
using ll = long long;

ll n,m,k,d,a,ans;
//string s,t;
int s[100005];

int main() {
  cin >> n >> k;
  rep(i,k){
    cin >> d;
    rep(j,d){
      cin >> a; a--;
      s[a]++;
    }
  }
  rep(i,n)if(!s[i]) ans++;
  cout << ans << endl;
}

Measured memory_bytes: 3636
import java.io.*;
import java.util.*;
import java.lang.*;

class Main {

	public static void main(String[] args) {
		final FastScanner sc = new FastScanner(System.in);
		int n = sc.nextInt();
		char[] s = sc.next().toCharArray();

		int[][] a = new int[n][3];
		for (int i = n - 1; i > 0; i--) {
			for (int j = 0; j < 3; j++) {
				a[i - 1][j] += a[i][j];
			}

			switch (s[i]) {
				case 'R':
					a[i - 1][0]++;
					break;
				case 'G':
					a[i - 1][1]++;
					break;
				case 'B':
					a[i - 1][2]++;
					break;
			}
		}

		long count = 0;
		for (int i = 0; i < s.length; i++) {
			for (int j = i + 1; j < s.length; j++) {
				if (s[i] == s[j]) continue;
				switch (s[i]) {
					case 'R':
						if (s[j] == 'G') {
							count += a[j][2];
						} else { // B
							count += a[j][1];
						}
						break;
					case 'G':
						if (s[j] == 'R') {
							count += a[j][2];
						} else { // B
							count += a[j][0];
						}
						break;
					case 'B':
						if (s[j] == 'R') {
							count += a[j][1];
						} else { // G
							count += a[j][0];
						}
						break;
				}

				int d = j - i;
				if (j + d < n && s[i] != s[j] && s[j] != s[j + d] && s[i] != s[j + d]) {
					count--;
				}
			}
		}

		System.out.println(count);
	}

	static class FastScanner {
		private final InputStream in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;

		public FastScanner(InputStream source) {
			in = source;
		}

		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte()) return buffer[ptr++];
			else return -1;
		}

		private static boolean isPrintableChar(int c) {
			return 33 <= c && c <= 126;
		}

		public boolean hasNext() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
			return hasNextByte();
		}

		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while (true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if (b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}

		public int nextInt() {
			long nl = nextLong();
			if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
				throw new NumberFormatException();
			return (int) nl;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}


Measured memory_bytes: 34152
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        
        System.out.println(a==b ? b==c ? "Yes" : "No" : "No");
    }
}


Measured memory_bytes: 22740