akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author vikas.k
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();

            int[] a = new int[n + 1];

            for (int i = 1; i <= n; i++) {
                a[i] = in.nextInt();
            }

            Arrays.sort(a, 1, n + 1);

            int v = 0;
            int prev = a[1];
            for (int i = 2; i <= n; i++) {
                v += (a[i] - prev);
                prev = a[i];
            }

            out.print(v);
        }

    }

    static class FastScanner {
        private BufferedReader bufferedReader;
        private StringTokenizer stringTokenizer;

        public FastScanner(InputStream inputStream) {
            bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        }

        public String next() {
            if (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {
                try {
                    stringTokenizer = new StringTokenizer(bufferedReader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return stringTokenizer.nextToken();
        }

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

    }
}



Measured memory_bytes: 21588
n=int(input())
l=list(map(int,input().split()))
if l[0]:print(0);exit()
mod=998244353
k=[0]*n
for i in l:k[i]+=1
if k[0]!=1:print(0);exit()
ans=1
for i,s in zip(k,k[1:]):ans*=pow(i,s,mod)
print(ans%mod)

Measured memory_bytes: 14020
#include <cstdlib>
#include <iostream>
#include <string>

int toInt(char c) { return std::atoi(&c); }

int main() {
  std::string numStr;
  while (std::cin >> numStr) {
    if (numStr == "0") return 0;
    int sum = 0;
    for (char c : numStr) {
      sum += toInt(c);
    }
    std::cout << sum << std::endl;
  }
}



Measured memory_bytes: 3156
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll n,x,r; cin>>n;
    vector<ll>v,v1;
    cin>>x;
    r = x;
    ll p=0;
    for(ll i = 0; i<n-1; i++)
    {
        cin>>x;
        if(r>x) p += (r-x);
        else r = x;
    }
    cout<<p<<endl;
}



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

#define ll long long
#define ld long double

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define repA(i,A)   for(auto i:A)

#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define mp make_pair
#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)	A.rbegin(),A.rend()
#define ft first
#define sd second

#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V> 
#define Vpll vector<pll>

#define endl "\n"

const ll logN = 20;
const ll N = 100005;
const ll M = 1000000007;
const ll INF = 1e12;
#define PI 3.14159265

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

map<string,ll> m;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n;
    cin>>n;
    rep(i,0,n){
    	string s;
    	cin>>s;
    	sort(all(s));
    	m[s]++;
    }
    ll ans=0;
    for(auto i:m){
    	ans += ((i.sd)*(i.sd-1))/2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 11264
W = input()
T = []
while True:
    a = input().split()
    if a == ["END_OF_TEXT"]:
        break
    else:
        for i in a:
            T.append(i)
cnt = 0
for i in range(len(T)):
    if str.lower(T[i]) == W:
        cnt += 1
print(cnt)


Measured memory_bytes: 5564
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define TOUPPER(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define TOLOWER(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define FILLZERO(s, n)                      \
    do {                                    \
        ostringstream os;                   \
        os << setw(n) << setfill('0') << s; \
        s = os.str();                       \
    } while (0);
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
#define INIT                               \
    std::cin.tie(nullptr);                 \
    std::ios_base::sync_with_stdio(false); \
    cout << std::fixed << std::setprecision(10);

constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
vector<T> make_vec(size_t a) { return vector<T>(a, INF); }
template <typename T, typename... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}
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;
}

signed main() {
    INIT;
    cin >> S;
    A = INF, B = 0;
    REP(i, S.size()) {
        if (S[i] == 'A')
            chmin(A, (ll)i);
        if (S[i] == 'Z')
            chmax(B, (ll)i);
    }
    cout << B - A + 1 << endl;
}

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

int gcd(int x, int y)
{
  return y ? gcd(y,x%y) : x;
}

int lcm(int x, int y)
{
  return x / gcd(x, y) * y;
}

int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  rep(i, n)
  {
    cin >> a[i];
    a[i] /= 2;
  }
  vector<int> b(n, 0);
  rep(i, n)
  {
    while (a[i] % 2 == 0)
    {
      a[i] /= 2;
      b[i]++;
    }
    if (i != 0 && b[i] != b[0])
    {
      cout << 0 << endl;
      return 0;
    }
  }
  m >>= b[0];
  int l = 1;
  rep(i, n)
  {
    l = lcm(l, a[i]);
    if (l > m)
    {
      cout << 0 << endl;
      return 0;
    }
  }
  cout << (m / l + 1) / 2 << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  int R = tx - sx, U = ty - sy;
  REP(i, U) cout << 'U';
  REP(i, R) cout << 'R';
  REP(i, U) cout << 'D';
  REP(i, R) cout << 'L';
  cout << 'L';
  REP(i, U + 1) cout << 'U';
  REP(i, R + 1) cout << 'R';
  cout << 'D' << 'R';
  REP(i, U + 1) cout << 'D';
  REP(i, R + 1) cout << 'L';
  cout << 'U' << endl;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(500005)
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

# n(n+1)(n+2)/6
n = ni()
ans = n*(n+1)*(n+2)//6
for i in range(n-1):
    x, y = na()
    if x > y:
        x, y = y, x
    ans -= x * (n-y+1)
print(ans)


Measured memory_bytes: 68508
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Data{
	int S,H,V_ruiseki,H_ruiseki;
};

struct Info{
	int K;
	Data data[20];
};

double dp[201][201];

int main(){

	int N,M;
	scanf("%d %d",&N,&M);

	Info info[N];
	int V_sum,H_sum,all_V_sum = 0,all_H_sum = 0;

	for(int i = 0; i < N; i++){
		scanf("%d",&info[i].K);
		V_sum = 0;
		H_sum = 0;

		for(int a = 0; a < info[i].K; a++){
			scanf("%d %d",&info[i].data[a].S,&info[i].data[a].H);
			all_V_sum += info[i].data[a].S*info[i].data[a].H;
			all_H_sum += info[i].data[a].H;
			V_sum += info[i].data[a].S*info[i].data[a].H;
			H_sum += info[i].data[a].H;
			info[i].data[a].V_ruiseki = V_sum;
			info[i].data[a].H_ruiseki = H_sum;
		}
	}

	if(all_V_sum <= M){
		printf("%d\n",all_H_sum);
		return 0;
	}

	for(int i = 0; i <= N; i++){
		for(int k = 0; k <= M; k++)dp[i][k] = -1.0;
	}

	dp[0][M] = 0.0;

	double height;
	int next_rest,num;

	for(int pot = 0; pot < N; pot++){
		for(int rest = 0; rest <= M; rest++){
			if(dp[pot][rest] == -1.0)continue;
			for(int water = 0; water <= rest; water++){

				for(num = 0; num < info[pot].K; num++){
					if(info[pot].data[num].V_ruiseki > water){
						break;
					}
				}

				if(num == info[pot].K){
					height = (double)info[pot].data[info[pot].K-1].H_ruiseki;
					next_rest = water-info[pot].data[info[pot].K-1].V_ruiseki;
					dp[pot+1][next_rest] = max(dp[pot+1][next_rest],dp[pot][rest]+height);
				}else{

					if(num == 0){
						height = (double)water/(double)info[pot].data[num].S;
					}else{
						height = (double)info[pot].data[num-1].H_ruiseki+(double)(water-info[pot].data[num-1].V_ruiseki)/(double)info[pot].data[num].S;
					}
					dp[pot+1][rest-water] = max(dp[pot+1][rest-water],dp[pot][rest]+height);
				}
			}
		}
	}

	printf("%.10lf\n",dp[N][0]);

	return 0;
}

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

int msb(int l){
    int m=0;
    while(l>>=1)m++;
    return m;
}

int cnt(int l){
    int c=0;
    while(l){c+=l&1;l>>=1;}
    return c;
}

void p(int u,int v,int w){
    cout<<u<<" "<<v<<" "<<w<<"\n";
}

signed main(){
    int l;
    cin>>l;
    int n=msb(l)+1;
    int m=(n-1)*2+cnt(l)-1;
    cout<<n<<" "<<m<<"\n";
    for(int i=0;i+1<n;i++){
        p(i+1,i+2,0);
        p(i+1,i+2,1<<i);
    }
    int k=l^(1<<(n-1));
    while(k){
        int j=msb(k);
        p(j+1,n,l-k);
        k^=(1<<j);
    }
    return 0;
}


Measured memory_bytes: 256
n=int(input())
res=0
x=[]
for i in range(1,10001):
    x.append(i)
a=list(map(int,input().split()))
a_=list(set(x)-set(a))

c=a[0]
for i in range(1,n):
    b=a[i]
    if b==c:
        res+=1
        b=a_[i]
    c=b
print(res)

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

int main() {
  int N;
  scanf("%d", &N);

  int ans = 0;
  for (int i = 1; i <= N; i++) {
    int digit = 0;
    int tmp = i;
    while (tmp > 0) {
      tmp /= 10;
      digit++;
    }
    if (digit % 2 != 0) ans++;
  }

  printf("%d", ans);
  return 0;
}

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

using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<vector<int> >p(n,vector<int>(3,0));
    for(auto &e:p)
    {
        for(auto &c:e)
        {
            cin>>c;
        }
    }
    vector<vector<int> >dp(n,vector<int>(3,0));
    for(int i=0;i<3;i++)
    {
        dp[0][i]=p[0][i];
    }
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            for(int k=0;k<3;k++)
            {
                if(j==k)
                continue;
                dp[i][j]=max(dp[i][j],dp[i-1][k]+p[i][j]);
            }
        }
    }
    int maxi=INT_MIN;
    for(int i=0;i<3;i++)
    {
        maxi=max(dp[n-1][i],maxi);
    }
    cout<<maxi;
}

Measured memory_bytes: 14076
Imports System

Module Program
    Sub Main(args As String())

        Dim ND() As Integer = Console.ReadLine().Split(" ").Select(Function(x) Integer.Parse(x)).ToArray()
        Dim ans As Integer = 0
        For i As Integer = 0 To ND(0) - 1
            Dim tmp() As Integer = Console.ReadLine().Split(" ").Select(Function(x) Integer.Parse(x)).ToArray()

            If Math.Sqrt(tmp(0) ^ 2 + tmp(1) ^ 2) <= ND(1) Then
                ans += 1
            End If
        Next

        Console.WriteLine(ans)

    End Sub
End Module


Measured memory_bytes: 41512
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n;bool ans=true;
	map<int,int> m;vector<int> v;
	for(int i=0;i<n;i++)
	{
		cin>>k;
		if(m[k]==0) v.push_back(k);
		m[k]++;
		
	}
	for(int i=0;i<v.size();i++)
	{
		if(m[v[i]]%2==0)
		{
			ans=false;break;
		 } 
	}
	if(ans) cout<<"YES\n";
	else cout<<"NO\n";
}

Measured memory_bytes: 10356
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#define fi first
#define se second
#define pb push_back
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,b) for (int i=a; i<=b; i++)
#define per(i,a,b) for (int i=a; i>=b; i--)
#define L(i,u) for (int i=head[u]; i!=0; i=edge[i].nxt)
#define abs(a) ((a)>0 ? (a) : -(a))
#define INF 0x3f3f3f3f
using namespace std;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
typedef long long ll;
typedef long double ld;
const int N = 200200;


inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (c<'0'||c>'9') {if (c=='-') f=-1; c=getchar();}
	while (c>='0'&&c<='9') {x=10*x+c-'0'; c=getchar();} x*=f;
}
int n,m,f[N],g[N];
inline int find(int x) {
	if (f[x]==x) return x;
	int fa=f[x]; f[x]=find(f[x]); g[x]+=g[fa]; return f[x];
}
int main() {
	read(n); read(m);
	rep(i,1,n) f[i]=i,g[i]=0;
	bool ok=1;
	rep(i,1,m) {
		int x,y,v; read(x); read(y); read(v);
		int fx=find(x),fy=find(y);
		if (fx!=fy) {f[fx]=fy; g[fx]=g[y]+v-g[x];}
		else if (g[x]!=g[y]+v) {ok=0;}
	}
	if (ok) puts("Yes"); else puts("No");
	return 0;
}

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

using namespace std;
typedef long long ll;

const int N = 500'010, M = 1e9 + 7;
ll fact[N];

ll qpow(ll x, ll p) {
    ll res = 1;
    while (p) {
        if (p & 1) res = res * x % M;
        x = x * x % M;
        p >>= 1;
    }
    return res;
}

ll divide(ll a, ll b) { return a * qpow(b, M - 2) % M; }

ll subtract(ll a, ll b) { return (a - b) % M + (a >= b ? 0 : M); }

ll add(ll a, ll b) { return (a + b) % M; }

int main() {
    int n, m;
    cin >> n >> m;
    fact[0] = 1;
    for (int i = 1; i <= m; i++) fact[i] = fact[i - 1] * i % M;
    ll na = divide(fact[m], fact[m - n]);
    ll nb = 0;
    for (int i = 0; i <= n; i++) {
        ll cnt = divide(fact[n] * fact[m - i] % M, (fact[n - i] * fact[i] % M) * fact[m - n] % M);
        if (i % 2 == 0) {
            nb = add(nb, cnt);
        } else {
            nb = subtract(nb, cnt);
        }
    }
    ll ans = na * nb % M;
    cout << ans << "\n";
}


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

main()
{
	priority_queue<int> pq;
	char input[20];
	int len,i;
	scanf("%s",&input);
	len=strlen(input);
	for(i=0;i<len;i++)
	{
		if(input[i]==',')
		input[i]=' ';
	}
	printf("%s",input);
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String S1 = sc.next();
		String S2 = sc.next();
		
		long N = Long.parseLong(S1);
		long K = Long.parseLong(S2);
		
		double res = 0;
		for (int i = 1; i < K && i <= N; i++) {
			double t = Math.ceil((Math.log(K)/Math.log(2))-Math.log(i)/Math.log(2));
			res += (double)Math.pow((0.5), t)/N;
		}
		for (int i = (int) K; i <= N; i++) {
			res += (double)1/N;
		}
		System.out.println(res);
		
	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

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

template<typename T>
map<T, T> primeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(long i=s;i<e;i++)
#define repeq(i,s,e) for(long i=s;i<=e;i++)



int main() {
	ll a,b;
	in(a);
	in(b);
	
	if(a>9 || b>9){
		outn(-1);
	}
	else{
		outn(a*b);
	}

	return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
//#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define veccat(v1, v2) std::copy((v2).begin(),(v2).end(),std::back_inserter(v1)/*v1の後ろにv2を入れる*/)
#define intmax (std::numeric_limits<int64_t>::max() / 4)
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);


int H, W, K;

void gravity(vector<vector<int>>&F) {
	rep(x, W) {
		int D = H - 1;
		for (; 1 <= D && F[D][x]; D--);
		if (D == 0)continue;
		int U = D - 1;
		for (; 0 <= U && F[U][x] == 0; U--);
		if (U < 0)continue;
		while (1) {
			swap(F[D][x], F[U][x]);
			for (; 1 <= D && F[D][x]; D--);
			if (D == 0)break;
			for (; 0 <= U && F[U][x] == 0; U--);
			if (U < 0)break;
		}
	}
}
void solve(vector<vector<int>>&F, array<int, 512> &chain, int depth) {
	int erase = 0;
	rep(y, H) {
		for (int x = 0; x < W;) {
			int serial = 1;
			for (; x+serial < W && F[y][x + serial - 1] == F[y][x + serial]; serial++);
			if (K <= serial && F[y][x]) {
				erase += serial * F[y][x];
				rep(i, serial)F[y][x + i] = 0;
			}
			x += serial;
		}
	}
	chain[depth] = erase;
	if (erase == 0)return;
	gravity(F);
	solve(F, chain, depth + 1);

}

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

	cin >> H >> W >> K;
	vector<vector<int>>F(H, vector<int>(W));
	rep(i, H) {
		string S;
		cin >> S;
		rep(j, W)F[i][j] = S[j] - '0';
	}

	int ans = 0;
	rep(h, H)rep(w, W) {
		auto FF = F;
		FF[h][w] = 0;
		gravity(FF);
		array<int, 512>chain;
		rep(i, 512)chain[i] = 0;
		solve(FF, chain, 0);
		int keisuu = 1,score = 0;
		for (int i = 0; chain[i] != 0; i++) {
			score += keisuu * chain[i];
			keisuu *= 2;
		}
		ans = max(ans, score);
	}


	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
h,w = map(int,input().split())
a = [input() for _ in range(h)]

a_set = set()
for i in range(h):
    for j in range(w):
        a_set.add(a[i][j])

odd = 0
mul_2 = 0
for s in a_set:
    tmp = 0
    for i in range(h):
        tmp += a[i].count(s)
    odd += (tmp%2 == 1) * 1
    mul_2 += ((tmp%2 == 0) & (tmp%4 == 2)) * 1


limit_odd = ( h*w % 2 == 1) * 1
limit_mul_2 = (h%2 == 1) * (w//2) + (w%2 == 1) * (h//2)
if((odd <= limit_odd) & (mul_2 <= limit_mul_2)):
    print('Yes')
else:
    print('No')

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

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    struct edge{
        ll from;
        ll to;
        ll cost;
    };

    ll v,e,r;
    cin>>v>>e>>r;
    vector<edge> E(e);
    rep(i,e){
        ll s,t,d;
        cin>>s>>t>>d;
        E[i]={s,t,d};
    }

    vector<ll> dist(v,INF);
    dist[r]=0;
    rep(i,v){
        bool update=false;
        for(auto x:E){
            if(dist[x.from] != INF && dist[x.from]+x.cost < dist[x.to]){
                if(i==v-1){
                    cout<<"NEGATIVE CYCLE"<<endl;
                    return 0;
                }
                dist[x.to] = dist[x.from]+x.cost;
                update=true;
            }
        }
        if(!update) break;
    }
    rep(i,v){
        if(dist[i]==INF) cout<<"INF"<<endl;
        else cout<<dist[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3120
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final int k = scanner.nextInt();

        double result = 0;

        for (int i = 1; i <= n; i++) {
            final double a = Math.log(k) / Math.log(2);
            final double b = Math.log(i) / Math.log(2);
            double ceil = Math.ceil(a - b);
            if(ceil < 0){
                ceil = 0;
            }
            final double pow = Math.pow(0.5, ceil);
            result += pow;
        }

        System.out.println(result / n);
    }
}


Measured memory_bytes: 21844
function Main(input){
	var str = '1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51';
	var arr = str.split(', ');

	console.log(arr[input-1]);
}



Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 11340
#include <bits/stdc++.h>
using namespace std;
char enl = '\n';
#define rep(i, from, to) for (int i = from; i < (to); ++i)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<pair<int, int>> vii;

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

    ll n, a, b;
    cin >> n >> a >> b;

    vector<ll> h(n);
    rep(i,0,n) {
        cin >> h[i];
    }

    ll low = 0;
    ll high = 2 * 1e9;

    while (high - low > 1) {
        ll mid = (high + low) / 2;

        ll abc = 0;
        rep(i,0,n) {
            ll val = h[i] - mid * b;
            if (val > 0)
                abc += (val - 1) / (a-b) + 1;
        }
        if (abc > mid) {
            low = mid;
        } else {
            high = mid;
        }
    }

    cout << high << endl;


    return 0;
}


Measured memory_bytes: 1024
import itertools

S = list(input())
A = [0,1]
Comb = list(itertools.product(A, repeat=len(S)-1))

ans = 0
for i in range(len(Comb)):
  tmp = list(Comb[i])
  num1 = []
  num2 = S[0]
  for j in range(len(tmp)):
    if(tmp[j] == 0): num2 += S[j+1]
    else:
      if(num2 != ''): num1.append(int(num2))
      num2 = S[j+1]
  if(num2 != ''): num1.append(int(num2))
  num = sum(num1)
  ans += num
  
print(ans)     

Measured memory_bytes: 3064
s = input()

howmany = len(s)
judge = "Yes"

for x in range(howmany):
  if x % 2 == 0:
    if s[x] != "R" and s[x] != "U" and s[x] != "D":
      judge = "No"
      break
  else:
    if s[x] != "L" and s[x] != "U" and s[x] != "D":
      judge = "No"
      break
      
print(judge)

Measured memory_bytes: 8920
#include <bits/stdc++.h>
using namespace std;
#define MAXN 2020
#define MOD 1000000007
#define INF 1000000009
#define FOR(x,n) for(int x=0; x<n; x++)
#define FOR1e(x,n) for(int x=1; x<=n; x++)
typedef pair<int, int> ii;
typedef long long ll;

int main() {
	int op = 100000;
	int n, v;
	scanf("%d", &n);
	FOR(x, n) {
		scanf("%d", &v);

		int k = 0;
		while(v%2 == 0 && v != 0) {
			k++;
			v /= 2;
		}
		op = min(op, k);
	}
	printf("%d\n", op); 
	return 0;
}

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




int main(){
    cout<<fixed<<setprecision(10);

    int n,m; cin>>n>>m;
    int b[m], a[n][m];
    rep(i,n)rep(j,m)cin>>a[i][j];
    rep(j,m)cin>>b[j];
    
    int ans[n];
    rep(i,n){
        ans[i] = 0;
        rep(j,m) ans[i] += a[i][j]*b[j];
    }
    
    rep(i,n)cout<<ans[i]<<endl;

    return 0;
}








Measured memory_bytes: 3116
#include<stdio.h>
#include<math.h>

int main() {
	int ta, thp, aa, ahp,tn,an;
	scanf("%d %d %d %d", &thp, &ta, &ahp, &aa);
	tn = ahp / ta;
	an = thp / aa;
	if (ahp%ta != 0) {
		tn = tn + 1;
	}
	if (thp%aa != 0) {
		an = an + 1;
	}
	if (an < tn) {
		printf("No");
	}
	else {
		printf("Yes");
	}
}

Measured memory_bytes: 2116
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse=True)

#必要票数を求める
s = sum(a)
needed = s/4/m if s%(4*m) == 0 else s//(4*m)+1

for i in range(m):
    if a[i] < needed:
        print("No")
        break
else:
    print("Yes")


Measured memory_bytes: 9028
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <cstring>
using namespace std;

#ifdef ENABLE_LL
#define int long long
#endif

#ifdef ENABLE_LL
#define I "%lld"
#define II "%lld%lld"
#define III "%lld%lld%lld"
#define IIII "%lld%lld%lld%lld"
#define IN "%lld\n"
#define IIN "%lld%lld\n"
#define IIIN "%lld%lld%lld\n"
#define IIIIN "%lld%lld%lld%lld\n"
#else
#define I "%d"
#define II "%d%d"
#define III "%d%d%d"
#define IIII "%d%d%d%d"
#define IN "%d\n"
#define IIN "%d%d\n"
#define IIIN "%d%d%d\n"
#define IIIIN "%d%d%d%d\n"
#endif

#ifdef __LOCALE__
#define see(a) std::cout << #a << "=" << a << std::endl
#define ses(a) std::cout << #a << "=" << a << " " 
#else
#define see(a) //std::cout << #a << "=" << a << std::endl
#define ses(a)
#endif
#define repe(a,b) for (int a=0;a<(int)b.size();a++)
#define rep(i,n) for (int i=0;i<n;i++)
#define repa(i,n) for (int i=1;i<=n;i++)
#define repi(i,a,b) for (int i=a;i<=b;i++) 
#define repb(i,a,b) for (int i=a;i>=b;i--)
typedef pair < int , int > pr;
typedef pair < pr  , int > prr;
#define L first
#define R second
template <class T> inline bool checkMin(T& a , T b) { return (a > b ? a=b,1 : 0); }
template <class T> inline bool checkMax(T& a , T b) { return (a < b ? a=b,1 : 0); }
class Scanner{ private: istream& ist;public: Scanner(istream& in):ist(in){} string next(){ string r; ist >> r; return r; } string nextLine(){ string r; getline(ist,r); return r; } int nextInt(){ int r; ist >> r; return r; } double nextDouble(){ double r; ist >> r; return r; }};
Scanner sc(cin);


void init() {
     
}

void solve() {
    int k; string s;
    cin >> k >> s;
    if ((int)s.length() <= k) {
        cout << s << endl;
    } else {
        cout << s.substr(0,k) << "..." << endl;
    }
}


#ifdef ENABLE_LL
#undef int
#endif
int main(){
    init();
    solve();
    return 0;
}

Measured memory_bytes: 3632
def main():
    N, M = (int(_) for _ in input().split())
    H = [int(_) for _ in input().split()]
    good = [1] * N
    for _ in range(M):
        a, b = (int(_) for _ in input().split())
        a -= 1
        b -= 1
        if H[a] > H[b]: good[b] = 0
        elif H[a] < H[b]: good[a] = 0
        else:
            good[a] = 0
            good[b] = 0
    print(sum(good))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 20056
N = int(input())
L = list(map(int, input().split()))
cnt = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            if not (L[i] == L[j] or L[j] == L[k] or L[k] == L[i]):
                if L[i]+L[j]-L[k]>0 and L[i]-L[j]+L[k]>0 and -L[i]+L[j]+L[k]>0:
                    cnt += 1
print(cnt)

Measured memory_bytes: 9208
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<queue>
#include<vector>
#include<tuple>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()
bool comparator(P a, P b) {
	return a.first / a.second < b.first / b.second;
}

struct UnionFind {
	vector<int> par;
	UnionFind(int n) : par(n) {
		rep(i, n) {
			par[i] = i;
		}
	}
	int root(int x) {
		if (par[x] == x)return x;
		return par[x] = root(par[x]);
	}
	void unite(int x, int y) {
		int rx = root(x); int ry = root(y);
		if (rx == ry)return;
		par[rx] = ry;
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}
};

int main() {
	ll n, k, l;
	cin >> n >> k >> l;
	UnionFind road(n);
	UnionFind train(n);

	rep(i, k) {
		ll p, q;
		cin >> p >> q;
		p--; q--;
		road.unite(p,q);
		//cout <<k<<i<< p << q << endl;
	}
	rep(i, l) {
		ll p, q;
		cin >> p >> q;
		p--; q--;
		train.unite(p,q);
		//cout << p << q << endl;
	}
	map<P, ll> ans;
	rep(i, n) {
		ans[make_pair(road.root(i),train.root(i))]++;
	}
	rep(i, n) {
		if (i < n - 1) {
			cout << ans[make_pair(road.root(i),train.root(i))] << " ";
		}
		else {
			cout << ans[make_pair(road.root(i),train.root(i))] << endl;
		}
	}
}


Measured memory_bytes: 15672
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

s = STR()
l = len(s)
for i in reversed(range(1, (l - 1) // 2 + 1)):
    if s[:i] == s[i:2 * i]:
        print(i * 2)
        exit()


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

int main() {
	int x, y;
	cin >> x >> y;

	int ax = abs(x);
	int ay = abs(y);
	ll d = abs(ax - ay);

	ll res = 1e18;
	if (-x == y) { res = min(res, 1LL); }
	ll t = x + d;
	if (t == y) { res = min(res, d); }
	if (-t == y) { res = min(res, d + 1); }
	t = -x + d;
	if (t == y) { res = min(res, 1 + d); }
	if (-t == y) { res = min(res, 1 + d + 1); }

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
	ll N, P;
	string S;
	cin >> S;
  	N = S.length();
  	P = 2019;
	ll ans = 0;
	if (P == 5) {
		rep(i, N) {
			if (S[i] == '0' || S[i] == '5')
				ans += (i + 1);
		}
		cout << ans << endl;
		return 0;
	}
	else if (P == 2) {
		rep(i, N) {
			if ((int)(S[i] - '0') % 2 == 0)
				ans += (i + 1);
		}
		cout << ans << endl;
		return 0;
	}
	vl i_modP(N + 1, 1);
	rep(i, N) {
		i_modP[i + 1] = i_modP[i] * 10LL;
		i_modP[i + 1] %= P;
	}
	vl SmodP(N + 1, 0);
	ll Stmp = 0;
	map<ll, ll> modcount;
	modcount[0]++;
	rep(i, N) {
		ll n = S[N - i - 1] - '0';
		SmodP[i + 1] = SmodP[i];
		SmodP[i + 1] += i_modP[i] * n;
		SmodP[i + 1] %= P;
		modcount[SmodP[i + 1]]++;
	}
	rep(i, P) {
		if (modcount[i] > 0)
			ans += modcount[i] * (modcount[i] - 1LL) / 2LL;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 6676
#include <algorithm>
#include <functional>
#include <iostream>
#include <utility>
#include <vector>
#define ll long long
#define rep(i, s, n) for (ll i = s; i < n; ++i)
#define dump(x) cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define MOD 1000000007
// https://atcoder.jp/contests/abc131/tasks/abc131_d
using namespace std;

string solve(int n, vector<pair<int, int>> v) {
    string ans = "Yes";

    int current = v[0].first;
    int lim;
    int cost;

    rep(i, 0, n) {
        lim = v[i].first;
        cost = v[i].second;

        // cout << lim << " " << current << " " << cost << endl;
        if (lim < current) {
            current -= current - lim;
        }

        current -= cost;

        if (current < 0) {
            ans = "No";
            break;
        }
    }

    return ans;
}

int main() {
    int n, a, b;

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;

    vector<pair<int, int>> v;

    rep(i, 0, n) {
        cin >> a >> b;
        v.push_back(pair<int, int>(b, a));
    }
    sort(begin(v), end(v), greater<pair<int, int>>());
    // cout << "=====================" << endl;
    // rep(i, 0, n) cout << v[i].first << " " << v[i].second << endl;

    string ans = solve(n, v);
    cout << ans << endl;
}


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

using namespace std;
using ll = long long;

inline ll mpow(ll a, ll n) {
  ll ret = 1;
  while (n > 0) {
    if (n % 2 == 1) ret *= a;
    a = a * a;
    n /= 2;
  }
  return ret;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  int max_digits = 40;
  ll ans         = 0;
  for (int i = max_digits; i >= 0; i--) {
    ll num = mpow(2, i);
    ll cnt = 0;
    for (int j = 0; j < N; j++)
      if (A[j] & (1LL << i)) cnt++;
    if (cnt < N / 2.0 && num <= K) {
      cnt = N - cnt;
      K -= num;
    }
    ans += num * cnt;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int a[1111],b[1111],c[1111],d[1111],p[1111],i,j,x,y,z;
main(){
  for(;scanf("%d%d%d",a,b,c)&&(*a+=*b+*c);i=0){
    for(scanf("%d",p);i++<*p;scanf("%d%d%d%d",a+i,b+i,c+i,d+i),p[i]=2);
    for(;--i;)
      for(j=0;j++<*p;d[j]?p[a[j]]=p[b[j]]=p[c[j]]=1:(x=p[a[j]]&1)&(y=p[b[j]]&1)?p[c[j]]=0:x&(z=p[c[j]])?p[b[j]]=0:y&z?p[a[j]]=0:0);
    for(;i<*a;printf("%d\n",p[++i]));
  }exit(0);
}

Measured memory_bytes: 620
#include<stdio.h>
#define N 500000
#define S 1000000000
int L[N],R[N];
int count=0;
void merge(int A[],int left,int mid,int right){
  int n1 = mid - left;
  int n2 = right - mid;
  int i,j,k;
  for(i=0;i<n1;i++) L[i] = A[left + i];
  for(i=0;i<n2;i++) R[i] = A[mid + i];
  L[n1] = 2*S;
  R[n2] = 2*S;
  i = 0;
  j = 0;
    for(k=left;k<right;k++){
      count++;
      if(L[i] <= R[j]){
	A[k] = L[i];
	i++;
      }
      else { 
	A[k] = R[j];
      j++;
      }
    }
}

void mergeSort(int A[],int left,int right){
  if (left+1 < right){
    int mid = (left + right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}
int main(){ 
  int A[N],n,i;
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
    mergeSort(A,0,n);    
    for(i=0;i<n;i++){
      if(i == n-1)
	printf("%d\n",A[i]);
      else printf("%d ",A[i]);
    }
    printf("%d\n",count);
    return 0;
}



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

using namespace std;
int main() {
	int n;
	string s;
	cin >> n >> s;
	int ans = 0;
	int cur = 0;
	for (char c : s) {
		if (cur == 0 && c == 'A') {
			cur++;
		} else if (cur == 1 && c == 'B') {
			cur++;
		} else if (cur == 2 && c == 'C') {
			cur = 0;
			ans++;
		} else if (c == 'A') {
			cur = 1;
		} else {
			cur = 0;
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

typedef long long int64;

int64 FirstMultipleGreaterThan(int64 x, int64 k) {
	return (x / k + 1) * k; 
}

void Solve() {
	int n;
	cin >> n;

	vector<int> a(n+1);

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

	int64 minv = 2, maxv = 2;

	for (int i = n; i >= 1; --i) {
		minv = FirstMultipleGreaterThan(minv - 1, a[i]);
		maxv = FirstMultipleGreaterThan(maxv, a[i]) - 1;
		if (minv > maxv) {
			cout << -1 << "\n";
			return;
		}
	}

	cout << minv << " " << maxv << "\n";
}

int main() {
	int tests = 1;
	for (;tests; --tests) {
		Solve();
	}
}

Measured memory_bytes: 768
class iostream:
    def __init__(self):
        self.s = []
        self.i = 0

    def next(self, T=str):
        if(self.i < len(self.s)):
            ret = self.s[self.i]
            self.i += 1
            return T(ret)
        st = input()
        while(st == ""):
            st = input()
        self.s = st.split(" ")
        self.i = 0
        return T(self.next(T))

def even(n):
    return n % 2 == 0

def main():
    cin = iostream()
    a, b, c = cin.next(int), cin.next(int), cin.next(int)
    if even(a) or even(b) or even(c):
        print(0)
        exit()
    a, b, c = sorted([a, b, c])
    print(a * b)


main()


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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(y==0)return x;
    return gcd(y,x%y);
}
ll LCM(ll a, ll b){
    return a/gcd(a,b)*b;
}

int main(void)
{
    ll a,v,b,w,t;
    cin>>a>>v>>b>>w>>t;
    cout<<(abs(a-b)-(v-w)*t<=0?"YES":"NO")<<endl;
    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <tuple>
#include <bitset>
#include <random>
#define REP(i,n) for(int i=0;i<n;i++)
#define INF 100000000000007
using namespace std;
using pii=pair<int,int>;
using LL=int64_t;





int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    REP(i,n){
        cin>>a.at(i);
    }

    sort(a.begin(), a.end(),greater<int>());

    
    LL ans=0;
    
    ans+=a.at(0);
    
    for(int i=1;i<n/2;i++){
        ans+=2*a.at(i);
    } 

    if(n%2==1){
        ans+=a.at(n/2);
    }  

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

Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ull  unsigned long long
#define vll  vector <long long>
#define pll pair <long long,long long>
#define f first
#define s second
#define up upper_bound
#define lp lower_bound
#define pq priority_queue
#define inf 1e10
#define minf -1e10
#define pi 3.14159265
#define mod 300000000000000000
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);
int main()
{
    ll n;
    cin>>n;
    vll vec;
    ll ara[100001];
    memset(ara,0,sizeof(ara));
    for(ll i=0;i<n;i++)
    {
        ll num;
        cin>>num;
        vec.pb(num);
    }
    ll ans=0;
    ara[n-2]=abs(vec[n-2]-vec[n-1]);
    for(ll i=n-3;i>=0;i--)
    {
        ara[i]=min(abs(vec[i]-vec[i+1])+ara[i+1],abs(vec[i]-vec[i+2])+ara[i+2]);
    }
    cout<<ara[0]<<endl;
}


Measured memory_bytes: 2168
#include <iostream>
#include <algorithm>

/*int main(int argc, char **argv)
{
	int a, b, c, d, e;
	std::cin >> a >> b >> c >> d >> e;
	std::cout << std::min(a, std::min(b, c)) + std::min(d, e) - 50 << std::endl;
	return 0;
}*/
int main()
{
	int l, a, b, c, d;
	std::cin >> l >> a >> b >> c >> d;
	int japa, math;
	japa = a / c;
	if(a % c != 0){
		japa++;
	}
	math = b / d;
	if(b % d != 0){
		math++;
	}
	std::cout << l - std::max(japa, math) << std::endl;
}

Measured memory_bytes: 3112
import java.io.*;
import java.util.*;
import java.math.BigDecimal;
public class Main
{
	
	private void solve()throws Exception
	{
		BigDecimal a=new BigDecimal(nextToken());
		BigDecimal b=new BigDecimal(nextToken());
		a=a.multiply(b);
		out.println(a.toBigInteger());
	}

	 
	///////////////////////////////////////////////////////////

	public void run()throws Exception
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		solve();
		
		br.close();
		out.close();
	}
	public static void main(String args[])throws Exception{
		new Main().run();
	}
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	String nextToken()throws Exception{
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	String nextLine()throws Exception{
		return br.readLine();
	}
	int nextInt()throws Exception{
		return Integer.parseInt(nextToken());
	}
	long nextLong()throws Exception{
		return Long.parseLong(nextToken());
	}
	double nextDouble()throws Exception{
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 33216
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
const int MOD=1000000007;
//BFSキタコレ
int main(){
    int n,m;
    cin>>n>>m;
    vector<int> G[100000];
    vector<bool> visited(n,false);
    vector<int> sign(n);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--,b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    queue <int> q;
    q.push(0);
    while(!q.empty()){
        int p = q.front();
        visited[p]=true;
        q.pop();
        rep(i,G[p].size()){
            int next = G[p][i];
            if(!visited[next]){
                visited[next]=true;
                q.push(next);
                sign[next] = p;
                //cout<<"sign["<<next+1<<"]="<<p+1<<endl;
            }
        }
    }
    bool ans=true;
    rep(i,n){
        if(!visited[i]){
            ans=false;
        }
    }
    if(!ans){
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
    for(int i=1;i<n;i++){
        cout<<sign[i]+1<<endl;
    }
}

Measured memory_bytes: 10180
N = int(input())
S = input()
m = 10**9 + 7
nl = [0 for i in range(26)]
for s in S:
    nl[ord(s)-97] += 1
ans = 1
for i in range(26):
    if nl[i] == 0:
        continue
    else:
        ans *= nl[i] + 1
        ans = ans % m
print(ans-1)



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

int main(){
  //input 入力
  string w;cin >> w;

  //solve 処理
  map<char,int> m;
  rep(i,w.length()){
    m[w[i]] += 1;
  }
  
  //output 出力
  rep(i,w.length()){
    if(m[w[i]] % 2 != 0){cout << "No" << endl;return 0;}
  }
  cout << "Yes" << endl;
  return 0;
  
}

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

int main() {
  vector<vector<char>> c(3, vector<char>(3));
  rep(i, 3) rep(j, 3) cin >> c[i][j];

  rep(i, 3) printf("%c", c[i][i]);
  printf("\n");
}



Measured memory_bytes: 256
#define _[2<<17]
n,i,flag;A _,B _,T _,F _;long M,D _,P _,R _,R2 _;s(u,i,p,I){i?s(u,T[i],p),R[i]=(I=B[i])-p?s(I,F[I],u),D[u]=D[u]*-~D[I]%M:D[u]:++D[u];D[u];}S(u,x,p,i,I){for(i=F[u];I=B[i];I-p?S(I,R[i]*x%M+1,u),x=x*-~D[I]%M:0)i=T[i];P[u]=x%M;}main(u,v){for(;~scanf("%d%d",&u,&v);)i++?A[i-1]=B[i]=u,B[i-1]=A[i++]=v:(n=u,M=v);for(;--i;F[A[i]]=i)T[i]=F[A[i]];s(*R=1,F[1]);for(S(1,1);i++<n;)printf("%d ",P[i]);for(i=0;i<2<<17;i++)flag+=R[i]!=R2[i];return 0*flag;}

Measured memory_bytes: 16640
#include <bits/stdc++.h>
#define int long long 

using namespace std;

const int maxn = 1e5 + 7;

int n, a[maxn], ans[maxn], curval;

vector<pair<int, int>> vt;
set<int> st;

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin);
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
        vt.emplace_back(a[i], i);
    }
    sort(vt.begin(), vt.end(), greater<pair<int, int>>());
    int cur = 1;
    st.insert(vt[0].second);
    for(; cur < vt.size(); cur++)
    {
        if(vt[cur].first == vt[cur - 1].first) st.insert(vt[cur].second);
        else break;
    }
    curval = vt[cur - 1].first;
    while(cur < vt.size())
    {
        ans[*st.begin()] += (curval - vt[cur].first) * st.size();
        curval = vt[cur].first;
        for(; cur < vt.size() && vt[cur].first == curval; cur++)
        {
            st.insert(vt[cur].second);
        }
    }
    ans[*st.begin()] += (curval - 0) * st.size();
    for(int i = 1; i <= n; i++) cout << ans[i] << '\n';
}

Measured memory_bytes: 8944
require "matrix"

while gets
  a, b, c, d, e, f = $_.split.map(&:to_i)
  ans = Matrix[[a, b], [d, e]].lup.solve([c, f]).to_a.map{ |i| i.to_f.round(3) }
  puts "%.3f %.3f" % ans
end

Measured memory_bytes: 6592
#include <bits/stdc++.h>
using namespace std;
#define forn(i,a,b) for(i=a;i<b;i++)
#define for1(i,b) for(int i=1;i<=b;i++);
#define rep(i,n) forn(i,0,n)
#define ford(i,a,b) for(i=a;i>=b;i--)
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)

struct node{
    int x; int y;
    bool blu;

    node(int a, int b, bool c) {
	x = a; y = b; blu = c; 
    }

};

bool operator<(const node&  a,const node& b) {
    return a.y > b.y; 
}

bool cmp(const node& a, const node& b) {
    return a.x < b.x;
}

int main(){
    std::ios::sync_with_stdio(false);

    int N,i;
    cin >> N;
    vector<node> a;
    forn(i, 0, N) {
	int x, y;
	cin >> x >> y;
	node n(x,y,false);
	a.pb(n);
    } 
    forn(i, 0, N) {
	int x, y;
	cin >> x >> y;
	node n(x,y,true);
	a.pb(n);
    }

    sort(all(a),cmp);
    multiset<node> hi;
    int cnt = 0;
   for(node n : a) {
	if(n.blu) {
	    for(node q : hi) {
		if(q.y < n.y) {
		    hi.erase(q); cnt++; 
		    break;
		}
	    }
	} else {
	    hi.insert(n);
	}
   }

    cout << cnt << endl;
    
    return 0;    
}

Measured memory_bytes: 256