akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] a = new long[n];
    long[] b = new long[n];
    long[] c = new long[n];
    for(int i = 0; i < n; i++) {
      a[i] = sc.nextLong();
    }
    for(int i = 0; i < n; i++) {
      b[i] = sc.nextLong();
    }
    for(int i = 0; i < n; i++) {
      c[i] = sc.nextLong();
    }
    Arrays.sort(a);
    Arrays.sort(b);
    Arrays.sort(c);
    //a[i]より大きい最小のb[j]のj
    long[] bigb = new long[n];
    //b[i]より大きい最小のc[j]のj
    long[] bigc = new long[n];
    long ind = 0;
    for(int i = 0; i < n; i++) {
      for(int j = (int)ind; j < n; j++) {
        if(a[i] < b[j]) {
          bigb[i] = j;
          ind = j;
          break;
        } else {
          if(j == n - 1) {
            bigb[i] = n;
            ind = n - 1;
          }
        }
      }
    }
    long ind2 = 0;
    for(int i = 0; i < n; i++) {
      for(int j = (int)ind2; j < n; j++) {
        if(b[i] < c[j]) {
          bigc[i] = j;
          ind2 = j;
          break;
        } else {
          if(j == n - 1) {
            bigc[i] = n;
            ind2 = n - 1;
          }
        }
      }
    }
    long[] sum = new long[n];
    sum[n - 1] = n - bigc[n - 1];
    for(int i = n - 2; i >= 0; i--) {
      sum[i] = sum[i + 1] + (n - bigc[i]);
    }
    long ans = 0;
    for(int i = 0; i < n; i++) {
      if(bigb[i] < n) ans += sum[(int)bigb[i]];
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 100360
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define f first
#define s second
#define int long long
int a[114514];
int ans[114514];
bool p(int x){
	if(x==1)return false;
	rep(2,i,x){
		if(x%i==0)return false;
	}
	return true;
}		
signed main(){
	ic(a) ic(b) ic(k)
	if(k<=a)cout<<a-k<<" "<<b<<endl;
	else if(k<=a+b) cout<<0<<" "<<a+b-k<<endl;
	else cout<<0<<" "<<0<<endl;
}	

Measured memory_bytes: 256
n, m, k = gets.split.map(&:to_i)
M = 998244353

def pow(x, n)
    return 1 if n == 0
    (n.odd? ? x : 1) * pow(x ** 2 % M, n / 2) % M
end

fac = Array.new(n, 1)
1.upto(n-1) {|i| fac[i] = fac[i-1] * i % M}

rfac = Array.new(n)
rfac[-1] = pow(fac[-1], M - 2)
(n-2).downto(0) {|i| rfac[i] = rfac[i+1] * (i+1) % M}

ans = 0
(k+1).times do |i|
    ans += m * pow(m-1, n-i-1) * fac[n-1] * rfac[i] * rfac[n-i-1] % M
end
p ans % M

Measured memory_bytes: 17424
l = []
while True:
  h,w = map(int,input().split())
  if (h,w) == (0,0):
    break
  else:
    l.append([h,w])
for i in l:
  r1 = ''
  r2 = ''
  for j in range(i[1]//2):
    r1 += '#.'
    r2 += '.#'
  if i[1]%2 == 1:
    r1 += '#'
    r2 += '.'
  for m in range(i[0]//2):
    print(r1)
    print(r2)
  if i[0]%2 == 1:
    print(r1)
  print()

Measured memory_bytes: 7704
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define MOD 1000000007
ll power(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)

//your code here!

int main(void){
    double a, b, x;
    scanf("%lf %lf %lf", &a, &b, &x);
    if(x==a*a*b) {
        printf("0\n");
        return 0;
    }
    double ans;
    if(x<=a*a*b/2) ans = atan(2*x / (a*b*b));
    else           ans = atan(a*a*a / (2*(a*a*b-x)));
    printf("%.7f\n", 90 - ans*180/M_PI);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
#define maxm 
#define mod 
#define maxn 

int main()
{
	int n;
	
	scanf("%d", &n);
	puts(n % 10 == n / 100 ? "Yes" : "No");
}

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

#define ll long long
#define endl '\n'
#ifndef _WINDOWS
// no getchar_unlocked on Windows so just call getchar
#define getchar getchar_unlocked
#endif

template <typename Func>
inline void loop(int e, Func&& f) {
    for (int i = 0; i < e; i++) {
        std::forward<Func>(f)(i);
    }
}
template <typename Func>
inline void loop(int s, int e, Func&& f) {
    for (int i = s; i < e; i++) {
        std::forward<Func>(f)(i);
    }
}
template <typename T>
inline void scanpn(T& num) {
    int c;
    num = 0;
    c = getchar();
    // bool negative = false;
    // if (c == '-') {
    // 	negative = true;
    // 	c = getchar();
    // }
    for (; (c > 47 && c < 58); c = getchar()) num = num * 10 + c - 48;
    // if (negative)
    //     number = -number;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while (1) {
        c -= b;
        if (c <= 0) {
            cout << "Yes" << endl;
            break;
        }
        a -= d;
        if (a <= 0) {
            cout << "No" << endl;
            break;
        }
    }
    return 0;
}


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

int main()
{
  while(true)
  {
    int candy;
    cin >> candy;
    if ( cin.eof() ) break;
    int student_num = ( candy%39 == 0 )? 39 : candy%39;
    printf("3C%02d\n", student_num);
  }
}

Measured memory_bytes: 1160
import itertools as it
n=int(input())
tr=list(map(int,input().split()))
tr=it.combinations(tr, 3)
ans=[]
c=0
for i in tr:
    if (i[0]+i[1]>i[2] and i[2]+i[1]>i[0] and i[0]+i[2]>i[1]) and (i[0]!=i[1] and i[0]!=i[2]) and (i[1]!=i[2] and i[1]!=i[0]) :
        c+=1
print(c)

Measured memory_bytes: 9196
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  
  int n,m,a[20000],b,max;
  
  
  while(1){
    
    cin >>n>>m;
  
  if( n == 0 && m == 0)break;
  
  for(int i=0 ; i < n  ; i++){
    cin >>a[i];
  }
  for(int i=n; i < n+m ; i++){
    cin >>a[i];  
  }
  
  sort(a,a+n+m);

  max=a[0];
  
  for(int i=0 ; i < n+m-1 ; i++){
      if(a[i+1]-a[i] > max){
	max=a[i+1]-a[i];
      }
    }
    
    cout <<max<<endl;
    
  }
  
  return 0;
}

Measured memory_bytes: 1252
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		scan.close();
		if(r<1200)System.out.println("ABC");
		else if(r<2800)System.out.println("ARC");
		else System.out.println("AGC");
	}
}

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

using namespace std;

#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
#define endl "\n"
#define dump(x) cerr << "~ " << #x << " = " << x << endl


int main() {

	fast_cin;
	

	int n; cin >> n;

	cout <<  (1000 - (n % 1000)) % 1000 << endl;
	
	
	
	return 0;
}

Measured memory_bytes: 3632
def get_order(numbers, originals):
    
    from math import factorial
    from copy import copy
    numbers = copy(numbers)
    originals = copy(originals)
    
    total = 0
    while numbers:
        number = numbers.pop(0)
        number_index = originals.index(number)
        originals.pop(number_index)
        count = (number_index ) * factorial(len(originals))
        total += count
    return total
        
def get_next_int():
    return int(float(input()))
def get_next_ints(delim=" "):
    return tuple([int(float(x)) for x in input().split(delim)])

def main(print=__builtins__.print):
    n = get_next_int()
    
    a = list(get_next_ints())
    b = list(get_next_ints())
    originals = list(map(int, range(1, n+1)))
    print(abs(get_order(a, originals) - get_order(b, originals)))

if __name__ == '__main__':
    main()
    

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a,b,c,x;
	while(cin>>n>>a>>b>>c>>x,n){
		int t = 0;
		int y[120];
		for(int i = 0;i < n;i++){
			cin>>y[i];
		}
		int now = 0;
		while(true){
			if(t > 10001){
				cout<<-1<<endl;
				goto next;
			}
			if(now == n)break;
			//cout<<t<<" "<<x<<" "<<y<<endl;
			if(x == y[now]){
				now++;
			}
			x = (a * x + b) % c;
			t++;
		}
		
		cout<<t-1<<endl;
		next:;
	}
}

Measured memory_bytes: 1160
#include<stdio.h>

int main(){
  int S = 0;
  int h = 0;
  int m = 0;
  int s = 0;

  scanf("%d",&S);
  h = S/3600;
  m = (S-h*3600)/60;
  s = S-h*3600-m*60;
  printf("%d:%d:%d\n",h,m,s);
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;
const ll INF=-10000000000;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}

//a,b x
int main(){
	ll A,B,C,D; cin>>A>>B>>C>>D;
	cout<<(A+B>C+D?"Left":A+B==C+D?"Balanced":"Right");
}

Measured memory_bytes: 256
N = int(input())
A = [list(map(int, input().split())) for _ in range(2)]
ans = 0

for i in range(N):
    ans_cand = 0
    
    for j in range(i+1):
        ans_cand += A[0][j]
    
    for j in range(i, N):
        ans_cand += A[1][j]
    
    ans = max(ans, ans_cand)

print(ans)

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

int main() {
	int k=0;
	char S[5];
	cin>>S;
	for(int i=0;i<4;i++)
	{
		if(S[i]=='+')k++;
		else k--;
	}
	cout<<k;
	}

Measured memory_bytes: 256
#include <cstdio>
#define max(a,b) ((a) > (b) ? (a) : (b))

int N,a,b,t,r[21][21]={0},dp[21]={0};
int l=0;

int rec(int loc, int bef){
	int tmp = -1;
	dp[loc] = -1;
	for(int i = 1; i <= N; i++){
		if(r[loc][i] > 0 && dp[i] == 0){
			int t2 = rec(i,loc);
			tmp = max(tmp,t2);
		}
	}
	if(tmp == -1)
		return 0;
	dp[loc] = tmp;
	l += r[loc][bef]*2;
	return tmp + r[loc][bef];
}

int main(){
	while(scanf("%d",&N), N != 0){
		l = 0;
		for(int i = 1; i <= N; i++){
			for(int j = 1; j <= N; j++){
				r[i][j] = 0;
			}
			dp[i] = 0;
		}
		for(int i = 1; i < N; i++){
			scanf("%d%d%d",&a,&b,&t);
			r[a][b] = r[b][a] = t;
		}
		rec(1,1);
		printf("%d\n", l - dp[1]);
	}

	return 0;
}

Measured memory_bytes: 2576
L,R=map(int,input().split())
if R-L+1>=2019:
    print(0)
else:
    m=2019
    for i in range(L,R):
        for j in range(i+1,R+1):
            x=(i*j)%2019
            if x<m:
                m=x
    print(m)

Measured memory_bytes: 3060
A, B = map(int, input().split())


def f(A, B):
    if A == 0:

        if B % 2 == 0:
            return B ^ (B // 2) % 2
        else:
            return 1 ^ (B // 2) % 2

    else:
        return f(0, B) ^ f(0, A - 1)


print(f(A, B))


Measured memory_bytes: 2940
#include "bits/stdc++.h"
using namespace std;
#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'
const int N = 1e6;

int main() {
	ios_base::sync_with_stdio(0);
	int a,b,n,T,cas=0;
	cin>>a>>b;
	cout<<(int)ceil(a*1.0/b);
	return 0;
}

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

def selectionSort(a, n):
    count = 0
    for i in range(n):
        mini = i
        for j in range(i, n):
            if a[j] < a[mini]:
                mini = j
        if i != mini:
            a[i],a[mini] = a[mini],a[i]
            count += 1
    print(*a)
    print(count)

selectionSort(a,n)

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

#define pb(n) push_back(n)
#define maxn 200010

using namespace std;

vector<int> v;
int t[maxn],f[maxn],p[maxn],q[maxn];

int next(int x)
{
	return v[(x+1)%3];
}

int main()
{
	int n;
	scanf("%d", &n);
	
	for(int i=1; i<=n; ++i)
	{
		scanf("%d", &p[i]);
		q[p[i]]=i;
	}
	
	for(int i=n-1; i>0; --i)
	{
		if(t[i+1]==0)
		{
			if(q[i]>q[i+1])
			{
				t[i]=1;
				f[i]=i+1;
			}
		}
		else
			{
				bool czy=true;
				v.pb(q[f[i+1]]);
				v.pb(q[i]);
				v.pb(q[i+1]);

				sort(v.begin(),v.end());
				for(int j=0; j<3; ++j)
				{
					//cout << v[j] << endl;
					if(v[j]==q[f[i+1]])
					{
						if(next(j)!=q[i])
							czy=false;
					}
					if(v[j]==q[i])
					{
						if(next(j)!=q[i+1])
							czy=false;
					}
					if(v[j]==q[i+1])
					{
						if(next(j)!=q[f[i+1]])
							czy=false;
					}
				}
				v.clear();
				if(czy)
				{
					t[i]=t[i+1];
					f[i]=f[i+1];
				}
				else
				{
					t[i]=t[i+1]+1;
					f[i]=i+1;
				}
			}
		//	cout << t[i] << " " << f[i] << endl;
	}
	printf("%d\n", t[1]);
	return 0;
}



Measured memory_bytes: 3328
#include "bits/stdc++.h"
 
using namespace ::std;
 
#define all(x)  x.begin(),x.end()
#define Unique(x) x.erase(unique(x.begin(), x.end()), x.end())

template< class T > T SQR(T N) {return (T) N * N;}
template< class T > double DIST(T a, T b) {return 1.0 * sqrt(SQR(double(a)) + SQR(double(b)));}
template< class T > bool CROSS(pair< T,T > a, pair< T,T > b, pair< T,T > c) {return (b.first - a.first) * (c.second - b.second) >= (b.second - a.second) * (c.first - b.first);}
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair< int,int > pi;
 
int px[] = {0, 1, -1, 0, -1, -1, 1};
int py[] = {1, 0, 0, -1, -1, 0, -1, -1};

const double eps = 1e-9;
 
inline ll power(ll a, ll p, ll mod)
{
    ll x = a, res = 1;
 
    while(p)
    {
        if(p&1) res = (res * x)%mod;
        p /= 2, x = (x * x)%mod;
    }
    return res;
}

int main()
{
    int n, m, c, d, a, b, k;
 
    int test;
 
    // scanf("%d", &test);
    // while(test--)
    // {
        scanf("%d", &n);
        vector< string >x;

        x.push_back("AC"),
        x.push_back("WA"),
        x.push_back("TLE"),
        x.push_back("RE");

        map< string, int >mp;
        string str;

        for(int i = 0; i<n; ++i)
            cin >> str,
            mp[str] += 1;

        for(string it : x)
            cout << it << " x " << mp[it] << "\n";
    //}
}

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

template <typename T>
void floyd_warshall(vector<vector<T>> &dist) {
    const T INF = numeric_limits<T>::max();
    size_t V = dist.size();
    for(size_t k = 0; k < V; ++k) {
        for(size_t i = 0; i < V; ++i) {
            for(size_t j = 0; j < V; ++j) {
                if(dist[i][k] == INF || dist[k][j] == INF) continue;
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
}

template <typename T>
void floyd_warshall_f(vector<vector<T>> &dist) {
    const T INF = numeric_limits<T>::max();
    size_t V = dist.size();
    for(size_t k = 0; k < V; ++k) {
        for(size_t i = 0; i < V; ++i) {
            for(size_t j = 0; j < V; ++j) {
                if(dist[i][k] == INF || dist[k][j] == INF) continue;
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j] + 1);
            }
        }
    }
}

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

    vector<vector<long long>> dist(N, vector<long long>(N, numeric_limits<long long>::max()));
    for(int i=0; i<M; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        if(c <= L) {
            dist[a - 1][b - 1] = c;
            dist[b - 1][a - 1] = c;
        }
    }
    floyd_warshall<long long>(dist);

    vector<vector<long long>> F(N, vector<long long>(N, numeric_limits<long long>::max()));
    for(int i=0; i<N; ++i) {
        for(int j=0; j<N; ++j) {
            if(dist[i][j] <= L) F[i][j] = 0;
        }
    }
    floyd_warshall_f<long long>(F);

    int Q; cin >> Q;
    while(Q--) {
        int s, t; cin >> s >> t;
        --s; --t;
        if(dist[s][t] <= L) cout << 0 << endl;
        else if(dist[s][t] == numeric_limits<long long>::max()) cout << -1 << endl;
        else cout << F[s][t] << endl;
    }
}

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

int vis[H][H];
char a[H][H];
int h,w,k;
int u,d,l,r;

bool check(int x,int y,int k){
	if(x>=0 && x<h && y>=0 && k>=1 && y<w && a[x][y]!='#' && !vis[x][y])return true;
	return false;
}

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

void dfs(int x,int y,int k){
	queue<pair<int,int>> que;
	queue<int> kque;
	que.push({x,y});
	vis[x][y]=1;
	kque.push(k);
	while(que.size()){
		x=que.front().first;
		y=que.front().second;
		k=kque.front();
		que.pop();
		kque.pop();
		u=min(x,u);
		d=max(x,d);
		l=min(l,y);
		r=max(r,y);
		for (int i = 0; i < 4; i++) {
			if(check(x+dx[i],y+dy[i],k)){
				que.push({x+dx[i],y+dy[i]});
				vis[x+dx[i]][y+dy[i]]=1;
				kque.push(k-1);
			}
		}
	}
}

int main(void)
{
	cin>>h>>w>>k;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin>>a[i][j];
			if(a[i][j]=='S'){
				u=d=i;
				l=r=j;
			}
		}
	}
	dfs(u,l,k);
	int dmin=min(u-0,min(h-1-d,min(l-0,w-1-r)));
	cout<<ceil(float(dmin)/k)+1<<endl;
	return 0;
}


Measured memory_bytes: 3328
ans=[]
a=list(input().split())
for i in range(len(a)):
    if a[i] == '+':
        tmp=ans.pop()
        ans[-1]+=tmp
        #print('+',ans[-1]+tmp)
    elif a[i] == '-':
        tmp=ans.pop()
        ans[-1]-=tmp
        #print('-',ans[-1]-tmp)
    elif a[i] == '*':
        tmp=ans.pop()
        ans[-1]*=tmp
    else:
        ans.append(int(a[i]))
print(ans[0])


Measured memory_bytes: 5604
#include<stdio.h>
#define N 100
#define INF 100000000

int main()
{
  int i,j,k,l;
  int n,p[N+1],m[N+1][N+1];

  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d%d",&p[i-1],&p[i]);
  }
  for(i=1;i<=n;i++) m[i][i]=0;
  
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j = i+l -1;
      m[i][j] = INF;
      for(k=i;k<j;k++){
	if(m[i][j] > m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j])
	  m[i][j] = m[i][k] +m[k+1][j] + p[i-1]*p[k]*p[j];	
      }
    }
  }
  printf("%d\n",m[1][n]);

  return 0;
}
    



Measured memory_bytes: 2108
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    if N <= 599:
        print(8)
    elif N <= 799:
        print(7)
    elif N <= 999:
        print(6)
    elif N <= 1199:
        print(5)
    elif N <= 1399:
        print(4)
    elif N <= 1599:
        print(3)
    elif N <= 1799:
        print(2)
    elif N <= 1999:
        print(1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9888
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
#define ff first
#define ss second

signed main() {

    string s;
    cin >> s;
    int n = s.size();
    int a[n] = {};
    for(int i = 1; i < n; i++) {
        if(s[i - 1] == 'R' && s[i] == 'L') {
            int r = 0, l = 0;
            for(int j = i - 1; j >= 0 && s[j] == 'R'; j--, r++);
            for(int j = i; j < n && s[j] == 'L'; j++, l++);
            l--; r--;
            int rr = r / 2;
            int ll = l / 2;
            a[i - 1] = rr + 1;
            a[i] = ll + 1;
            int remr = r - rr;
            int reml = l - ll;
            a[i - 1] += reml;
            a[i] += remr;
        }
    }
    for(int it : a) cout << it  << " ";

    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define P pair<ll, ll>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

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

ll v = 1000000000000000000;

int main() {
    ll n; cin >> n;
    Vl a(n);
    rep(i, 0, n){ 
        cin >> a[i];
    }
    rep(i, 0, n){
        if(a[i]==0){
            co(0);
            return 0;
        }
    }
    ll cnt = 0;
    rep(i, 0, n){
        if(a[i]>1000000000) cnt++;
    }
    if(cnt >= 2){
        co(-1);
        return 0;
    }
    ll seki = a[0];
    rep(i, 1, n){
        seki *= a[i];
        if(seki > v){
            co(-1);
            return 0;
        }
    }
    co(seki);

    return 0;
}


Measured memory_bytes: 4032
#include<bits/stdc++.h>
#include<vector>
using namespace std;
#define llong long long;
#define MAX 100000
int main(){
  int n; cin >> n;
  vector<int> a(n);
  vector<int> b(0);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }

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

  for(int i = 0; i < n-1; i++){
    if(a[i] == a[i+1]) {
      p.push_back(a[i]);
      i++;
    }


    if(p.size() == 2){
      cout << p[0]*p[1] << endl;
      return 0;
    }
  }


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

Measured memory_bytes: 640
n,m,=map(int,input().split())
*x,=map(int,input().split())
*y,=map(int,input().split())
mod=10**9+7
print(sum((2*i-n-1)*x[i-1]for i in range(1,n+1))*sum((2*i-m-1)*y[i-1]for i in range(1,m+1))%mod)

Measured memory_bytes: 18624
#include<bits/stdc++.h>
#define rep(i, x, n) for(int i = x; i < n; i++)
#define repr(i, x, n) for(int i = x; i > n; i--)
#define pii pair<int,int>
#define ll long long
const long long iinf = 1e18;
const int inf = 1e9;
const int MOD = (1e6+3);
int dir4[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};
int knight[8][2] = {{2,1},{2,-1},{-2,1},{-2,-1},{1,2},{-1,2},{1,-2},{-1,-2}};

using namespace std;

void solve()
{
    string s,t; cin >> s >> t;
    int ans = 0;for(int i = 0; s[i]; i++) if(s[i] != t[i]) ans++;
    cout << ans;
}
//new line is printed in the main

int main()
{
    int t = 1;
        // cin >> t; // comment out if no test case is required
    // int i = 1;
    while(t--){
        //cout << "Case " << i++ << ": ";
        solve();
        // printf("\n");
    }
    return 0;
}


Measured memory_bytes: 3836
# -*- coding: utf-8 -*-
"""
Created on Wed Mar  6 22:11:30 2019

@author: Yamazaki Kenichi
"""

H = int(input())
A = list(map(int,input().split()))
A = [''] + A

class MaxHeap(object):
    def __init__(self,size):
        self.table = [-1 for i in range(size+1)]
    
    def p(self,u):
        return u//2
    def left(self,u):
        return u*2
    def right(self,u):
        return u*2+1
    def swap(self,A,i,size):
        l = self.left(i)
        r = self.right(i)
#        print(r,l,i)
        if l <= size and A[l] > A[i]:
            largest = l
        else:
            largest = i
        if r <= size and A[r] > A[largest]:
            largest = r
        if largest != i:
            A[i],A[largest] = A[largest],A[i]
#            print(i,r,l,largest)            
            self.swap(A,largest,size)
#        print(i,r,l,largest)
mh = MaxHeap(H)
for i in range(H):
    mh.swap(A,H-i,H)
A = map(str,A)
print(' '.join(A))



Measured memory_bytes: 65364
#include <bits/stdc++.h>
#define re return
#define ll long long
#define ull unsigned ll
#define ld long double
#define f first
#define s second
#define pi acos(-1)
#define oo (ll)1e9
#define OO 1e18
#define EPS 1e-6
#define Endl '\n'
#define FX(n) fixed<<setprecision(n)
#define mm(o,k) memset(o,k,sizeof o)
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int maxn=100005;

int main()
{
    IO;
    int n,m;
    cin >> m >> n;--m;
    vector<int> a(n);
    for(int i=0;i<n;++i)cin >> a[i];
    sort(a.begin(),a.end());
    vector<ll> v;
    for(int i=1;i<n;++i)v.push_back(a[i]-a[i-1]);
    sort(v.rbegin(),v.rend());
    ll ans=0;
    for(auto i:v){
        if(m){--m;continue;}
        ans+=i;
    }
    cout<<ans<<endl;
    re 0;
}

Measured memory_bytes: 1784
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
#define p(s) std::cout << s ;
#define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

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;
}
int main() {
    int N, A, B;
    cin >> N >> A >> B;
    int res = 0;
    rep(i, 1, N+1) {
        int sum = findSumOfDigits(i);
        if (sum >= A && sum <= B) res += i;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;

void solve() {
	
	/*int n, m, q;
	cin >> n >> m >> q;
	VI a(100), b(100), c(100), d(100);
	map<int, set<int> > r;
	rep(i, 1, q + 1) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		r[a[i]].insert(b[i]);
	}*/
	ll a, b, n;
	cin >> a >> b >> n;
	if (b == 1||a==1) {
		cout << 0;
		return;
	}
	ll ans = (min(n, b - 1)*a / b);
	cout << ans << endl;
	
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T_ = 1;
	//cin >> T_;
	for (int i = 0; i < T_; i++)solve();
	return 0;
}







Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include<algorithm>
#include<math.h>
#include<iomanip>
#include <set>
#define ff(i,m,n) for(int i=m;i<n;i++)
#define i64 int64_t
using namespace std;


int main() {
	set<int> a;
	ff(i, 0, 3) {
		int b;
		cin >> b;
		a.insert(b);
	}
	cout << a.size();
	return 0;
}

Measured memory_bytes: 256
def main():
  N, M, K = map(int, input().split())
  A = list(map(int, input().split()))
  B = list(map(int, input().split()))
  time = 0
  num = 0
  while True:
    if num < N and time + A[num] <= K:
      time += A[num]
      num += 1
    else:
      break
  ans = num
  ans_temp = num
  for i in range(M):
    time += B[i]
    ans_temp += 1
    while time > K:
      if num > 0:
        time -= A[num-1]
        num -= 1
        ans_temp -=1
      else:
        break
    if num == 0 and time > K:
      break
    ans = max(ans, ans_temp)
  print(ans)
  
if __name__ == "__main__":
  main()
  

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

int main() {
  string s,t;
  cin>>s>>t;
  int n=s.size();
  s=s+s;
  string ans="No";
  for(int i=0;i<n;i++){
    for(int j=i;j<i+n;j++){
      if(s[j]!=t[j-i]) break;
      else if(j==i+n-1) ans="Yes";
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;

int main() {
	string A;
	long long C[26] = {}, ans;
	cin >> A;
	ans = A.size() * (A.size() - 1) / 2;
	for (int i = 0; i < A.size(); i++) {
		C[A[i] - 'a']++;
	}
	for (int i = 0; i < 26; i++) {
		ans -= C[i] * (C[i] - 1) / 2;
	}
	cout << ans + 1;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cmath>

#include <iostream>

#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>

#include <algorithm>

using namespace std;

int g(int a, int b) {
	// cout << a << " " << b << " ";
	while (a % b != 0 && b % a != 0) {
		if (b > a)
			b = b % a;
		else
			a = a % b;
	}
	// cout << min(a, b) << endl;
	return min(a, b);
}

int main() {
	int n;
	cin >> n;
	vector<int> v;
	int flag = 0;
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		if (t < 0)
			flag = 1 - flag;
		if (t < 0)
			t = -t;
		v.push_back(t);
	}

	sort(v.begin(), v.end());
	long long int res = 0;
	for (int i = 0; i < n; i++) {
		if (i == 0 && flag == 1)
			res -=v[i];
		else
			res += v[i];
	}	
	cout << res << endl;
}


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

#define X first
#define Y second
#define N 100010
typedef long long ll;
typedef pair<int,int> pii;
const int Mod=1000000007;

const double INF=1e18;

char s[N];

int main()
{
	//freopen("in.in","r",stdin);
	//freopen("out.out","w",stdout);
	
	int n,x=0,ans=0; scanf("%d",&n);
	scanf("%s",s);
	for (int i=0;i<n;i++)
	{
		if (s[i]=='I') x++;
		else x--;
		ans=max(ans,x);
	}
	cout<<ans<<endl;
	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
// const ll INF = 1000000000000000000LL;

int main() {
    int n;
    string s;
    cin >> n >> s;
    //重複を調べる
    vector<int> table(26);
    rep(i,n){
        table[s[i]-'a']++;
    }
    ll ans = 1;
    rep(i,26){
        ans *= table[i]+1;
        ans %= MOD;
    }
    ans--;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3696
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
int main()
{
    int R, G, t;
	scanf("%d%d", &R, &G);
	t = 2*G-R;
    printf("%d", t);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define long long long
using namespace std;
const int N=2e5;
int arr[N+2],n;
long ans;
int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  cin>>n;
  for(int i=1;i<=n;i++)
    cin>>arr[i];

  if(arr[1]!=0)cout<<-1<<endl,exit(0);
  for(int i=2;i<=n;i++)
  {
    if(arr[i]==0)continue;
    if(arr[i]==arr[i-1]+1)ans++;
    else
    {
      if(arr[i]<=arr[i-1])ans+=(arr[i]*1LL);
      else cout<<-1<<endl,exit(0);
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1152
cost = [1]
i = 1
while 6**i <= 100000:
	cost.append(6**i)
	i += 1
i = 1
while 9**i <= 100000:
	cost.append(9**i)
	i += 1
cost.sort()
cost.reverse()

n = int(input())
ans = [0 for i in range(100001)]
for i in range(len(cost)):
	ans[cost[i]] = 1
for i in range(1,100001):
	if ans[i] == 0:
		tempans = []
		for k in range(len(cost)):
			if i-cost[k] >= 0:
				tempans.append(ans[i-cost[k]])
		ans[i] = min(tempans)+1
print(ans[n])

Measured memory_bytes: 3992
#include <cstdio>

typedef struct{
	bool isVisited;
	int degree;
	int start;
	int end;
	int *neighbors;
} node;

int count = 0;

void dfs(node* nodes, int id){
	nodes[id].isVisited = true;
	if (nodes[id].start == 0) nodes[id].start=count;
	for (int i=0; i<nodes[id].degree; i++){
		if (!nodes[nodes[id].neighbors[i]].isVisited){
			count ++;
			dfs(nodes, nodes[id].neighbors[i]);
		}
	}
	count++;
	nodes[id].end = count;
}

int main(){
	int n, d, r, id;
	node *nodes;

	scanf("%d", &n);
	nodes = new node[n+1];
	nodes[0].start=0;
	nodes[0].degree=n;
	nodes[0].neighbors = new int[n];
	for (int i=0;i<n;i++){
		nodes[0].neighbors[i]=i;
	}
	for (int i=1; i<n+1;i++){
		nodes[i].isVisited=false;
		scanf("%d %d", &r, &d);
		nodes[i].degree=d;
		nodes[i].neighbors = new int[d];
		nodes[i].start = 0;
		
		for (int j=0;j<d;j++){
			scanf("%d", &id);
			nodes[i].neighbors[j] = id;
		}
	}

	dfs(nodes, 0);
	for (int i=1; i<n+1;i++){
		printf("%d %d %d\n", i, nodes[i].start, nodes[i].end);
		delete []nodes[i].neighbors;
	}
	delete []nodes;
	return 0;
}

Measured memory_bytes: 2716
#include<iostream>
using namespace std;
int w, h, c[50][50], ans = 0;
void solve(int p, int q) {
	c[p][q] = 0;
	for (int i = -1; i < 2; i++) {
		for (int j = -1; j < 2; j++) {
			if (p + i >= 0 && p + i < h && q + j >= 0 && q + j < w) {
				if (c[p + i][q + j]) {
					solve(p + i, q + j);
				}
			}
		}
	}
}
int main() {
	while (cin >> w >> h && w + h) {
		ans = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cin >> c[i][j];
			}
		}
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (c[i][j]) {
					//cout << i << " " << j << endl;
					ans++;
					solve(i, j);
				}
			}
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3260
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define INF (1e9)
#define EPS (1e-9)
#define MOD (1000000007)
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}
template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};


int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	cout.precision(10);
	int n,m,p,a,b;
	while(cin>>n>>m>>p>>a>>b,n){
		a--; b--;
		vector<double> h(n); for(auto&i:h)cin>>i;
		vector<vector<pii>> adjlist(m);
		rep(i,p){
			int x,y,z; cin>>x>>y>>z;
			x--, y--;
			adjlist[x].emplace_back(y,z);
			adjlist[y].emplace_back(x,z);
		}
		sort(all(h));
		double ans=INF;
		using data=tuple<double,int,int>;
		auto cmp=[](data a,data b){return get<0>(a)>get<0>(b);};
		do{
			//puti(h);
			vector<double> dist(m,INF);
			priority_queue<data,vector<data>,decltype(cmp)> q(cmp);
			q.emplace(0.0,a,0);
			while(!q.empty()){
				double cost; int pos,depth;
				tie(cost,pos,depth)=q.top(); q.pop();
				if(depth>n) continue;
				if(dist[pos]!=INF) continue;
				//cout<<pos<<","<<cost<<endl;
				dist[pos]=cost;
				if(pos==b) break;
				for(auto edge:adjlist[pos]){
					if(dist[edge.first]==INF){
						q.emplace(cost+edge.second/h[depth], edge.first, depth+1);
					}
				}
			}
			ans=min(ans,dist[b]);
			//puti(dist);
			//cout<<"============="<<endl;
		}while(next_permutation(all(h)));
		if(ans==INF){
			cout<<"Impossible"<<endl;
		}else{
			cout<<fixed<<ans<<endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3248
function Main(input){
	var max = 0;
	var ans = 0;
	input = input.split("\n");
	for(var i=1;i<input.length;i++){
		var mem = input[i].split(" ").map(Number);
		if(max<mem[0]){
			max = mem[0];
			ans = mem[0]+mem[1];
		}
	}
	console.log(ans)
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Measured memory_bytes: 31120
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 3e18;
long long int mod = 4294967296;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(15)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl


ll rui(ll abc,ll bed){
    //abcのbed乗を計算する
    if(bed==0){return 1;}
    else{
        ll ced = rui(abc,bed/2);
        ced *= ced;
        ced %= mod;
        if(bed%2==1){ced*=abc; ced%=mod;}
        return ced;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}

ll n,m,num,sum,ans,a,b,c,d,e,f,g,h,i,j,k,w,ok,ng;
ll t[500005],l[500005],r[500005];
ll dp[5005][5005][3];
char s[500005];
bool flag,dame;

int main(){
    cin >> s;
	if((s[5] - '0' ) * 10 + (s[6] - '0') <= 4){
		p("Heisei");
	}else{
		p("TBD");
	}
	
	return 0;
}

Measured memory_bytes: 24960
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

func scanInts(n int) []int {
	res := make([]int, n); for i := 0; i < n; i++ { res[i] = scanInt() }; return res
}

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1000000)

	n := scanInt()
	k := scanInt()

	p := make([]float64, n)
	for i := 0; i < n; i++ {
		p[i] = scanFloat64()
	}
	vals := make([]float64, n)

	for i := 0; i < n; i++ {
		vals[i] = (p[i]+1)/2
	}

	sums := make([]float64, n+1)
	sums[0] = 0

	for i := 0; i < n; i++ {
		sums[i+1] = sums[i]+vals[i]
	}

	ans := float64(0)

	for i := 0; i < n-k+1; i++ {
		if ans < sums[i+k]-sums[i] {
			ans = sums[i+k]-sums[i]
		}
		// fmt.Println(sums[i+k]-sums[i])
	}
	// fmt.Println(sums)

	fmt.Println(ans)
}

Measured memory_bytes: 6272
n = input()
a = list(map(int, input().split()))

a.sort(reverse=True)

ans = a[0]

mid = int(len(a) / 2)
for i in range(1, mid):
    ans = ans + a[i] * 2
if len(a) % 2 == 1:
    ans = ans + a[mid]

print(ans)


Measured memory_bytes: 31548
#include "bits/stdc++.h"

using namespace std;

#define LOCAL // sumbit source code
#define print_vec(v)          \
    for (auto row : v)        \
    {                         \
        for (auto d : v)      \
        {                     \
            cout << d << " "; \
        }                     \
        cout << endl;         \
    }
#define all(a) begin(a), end(a)
#define MOD 1000000007
#define fi first
#define se second
#define PII pair<int, int>
typedef vector<int> VI;
typedef long long ll;


ll quick_pow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) {
            res = a * res;
        }
        a = a * a;
        b >>= 1;
    }
    return res;
}

ll gcd(ll a, ll b) {
    a = abs(a), b = abs(b);
    while (b != 0) {
        a %= b;
        swap(a, b);
    }
    return a;
}

// TO-DO
// contest required
#ifdef LOCAL


void solve() {
    int n;
    cin >> n;
    if (n % 1000 == 0) {
        cout << 0;
    } else
        cout << 1000 - (n % 1000) << endl;
}

int main() {
    // 加速输入和输出
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solve();
    return 0;
}

#endif


Measured memory_bytes: 3544
//CHANDIGARH UNIVERSITY
//author:- shivamkr21
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
int main()
{
  string s;
  cin>>s;
  if(s=="SUN")
    cout<<7<<endl;
  else if(s=="MON")
    cout<<6<<endl;
  else if(s=="TUE")
    cout<<5<<endl;
  else if(s=="WED")
    cout<<4<<endl;
  else if(s=="THU")
    cout<<3<<endl;
  else if(s=="FRI")
    cout<<2<<endl;
  else if(s=="SAT")
    cout<<1<<endl;

  return 0;
}
  

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

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

	int m; cin >> m;
	vector<int> b(m);
	for(int i=0; i<m; i++) cin >> b[i];

	int N=min(a.size(),b.size());
	bool f=false,F=false;
	for (int i = 0; i < N; i++) {
		if (a[i] < b[i]) {
			F=true;
			f=true;
			break;
		}
		else if (a[i] > b[i]) {
			F=false;
			f=true;
			break;
		}
	}

	if (f) cout << F << endl;
	else {
		if (a.size() < b.size())
			cout << 1 << endl;
		else
			cout << 0 << endl;
	}

}
	



Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
char a[5]={'a','e','i','o','u'},k;
int main()
{
    cin>>k;
    for(int i=0;i<=4;i++)
    {
    	if(k==a[i])
    	{
    		cout<<"vowel"<<endl;
    		return 0;
		}
	}
	cout<<"consonant"<<endl;
    return 0;
}

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

 
int main(){
    
    string s;
    cin>>s;
  //  cout<<s.size();
    for(int i=0;i<s.size();i++)cout<<"x";
    cout<<endl;
    
}

Measured memory_bytes: 256
import sys

# import bisect
# from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter

# import math

# from numba import jit

# from scipy import
# import numpy as np
# import networkx as nx

# import matplotlib.pyplot as plt

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, p = list(map(int, readline().split()))
    s = input()

    ans = 0

    if p == 2 or p == 5:
        for i in range(n):
            if int(s[i]) % p == 0:
                ans += (i + 1)
    else:
        c = [0] * p
        prev = 0
        c[0] = 1
        for i in range(n):
            num = int(s[n - i - 1])
            m = (num * pow(10, i, p) + prev) % p
            c[m] += 1
            prev = m

        for i in range(p):
            cnt = c[i]
            ans += cnt * (cnt - 1) // 2

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 41436
#include <stdio.h>

int main(void)
{
    int m, i;
    scanf("%d", &m);

    for(i = 0; i < m; i++){
        int init, year, n, max = 0, j;

        scanf("%d", &init);
        scanf("%d", &year);
        scanf("%d", &n);
        for(j = 0; j < n; j++){
            int int_t, fee;
            int money = init;
            double interest;
            scanf("%d %lf %d", &int_t, &interest, &fee);

            if(int_t == 0){
                int k, pool = 0;
                for(k = 0; k < year; k++){
                    pool += (int)(money * interest);
                    money -= fee;
                }
                money += pool;
            }else if(int_t == 1){
                int k;
                for(k = 0; k < year; k++){
                    money += (int)(money * interest);
                    money -= fee;
                }
            }
            if(money > max)
                max = money;
        }
        printf("%d\n", max);
    }

    return 0;
}

Measured memory_bytes: 632
#include<bits/stdc++.h>
using namespace std;
int n,f[1000005];
const int p = 1000000007;
int main()
{
    scanf("%d",&n);
    int ans=0;
    f[0]=f[1]=1;int sm=2;
    for(int i=2;i<=n;i++)
    {
        f[i]=(sm-f[i-2]+p)%p;
        (sm+=f[i])%=p;
    }
    for(int i=0;i<n-1;i++)
    {
        ans+=1LL*f[i]*(n-1)%p*(n-1)%p;
        ans%=p;
        ans+=1LL*f[i]*(i+1)%p;
        ans%=p;
    }
    ans+=1LL*f[n-1]*(n-1)%p;
    ans%=p;
    ans+=f[n];
    ans%=p;
    cout<<ans<<endl;
    return 0;
}


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

int main() {
  int a,b; cin >>a >>b;
  int temp=a*b;
  if (temp%2) cout <<"Odd" <<endl;
  else cout <<"Even" <<endl;
  return 0;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
A = LIST()

def dijkstra(E, start):
    N_d = len(E)
    dist = [INF] * N_d
    dist[start] = 0
    q = [(0, start)]
    while q:
        dist_v, v = heappop(q)
        if dist[v] != dist_v:
            continue
        for u, dist_vu in E[v]:
            dist_u = dist_v + dist_vu
            if dist_u < dist[u]:
                dist[u] = dist_u
                heappush(q, (dist_u, u))
    return dist

graph = defaultdict(list)
g = defaultdict(list)
E = [[] for i in range(N)]
visited = [False] * N
for i, a in enumerate(A):
    graph[i].append((a-1, 1))
    g[i].append(a-1)
q = deque([0])
# ma = 0
order = []
while q:
    a = q.popleft()
    if visited[a] == True:
        last_idx = a
        break
    visited[a] = True
    order.append(a)

    for node in g[a]:
        q.append(node)

for i, a in enumerate(order):
    if a == last_idx:
        order_idx = i
# print(order_idx)
if K < order_idx:
    print(order[K]+1)
else:
    order_syuki = order[order_idx:]
    len_syuki = len(order_syuki)
    saigo_num = K - order_idx
    i_in_here = saigo_num % len_syuki
    ans = order_syuki[i_in_here]
    print(ans+1)


# if K <= 

# ma_d = ma - d[last_idx]
# mi_d = d[last_idx]
# print(ma_d, mi_d)





Measured memory_bytes: 127072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxi = 1e6 + 1, mod = 998244353;
int fac[maxi];
ll modex(ll a, ll b, ll m)
{
    ll ans = 1;
    for(; b > 0; b >>= 1, a = (a * a) % m)
        if(b & 1)
            ans = (ans * a) % m;
    return ans;
}
int main()
{
    ll n, x, m, i;
    cin >> n >> x >> m;
    if(x == 0)
        cout << 0 << endl;
    else if(x == 1)
        cout << n << endl;
    else
    {
        ll p = 0, ele = -1;
        vector <int> a;
        set <int> s;
        while(1)
        {
            if(s.find(x) != s.end())
            {
                ele = x;
                p = s.size();
                break;
            }
            else
            {
                a.push_back(x);
                s.insert(x);
                x = (x * x) % m;
            }
        }
        for(i = 0; i < a.size(); i++)
        {
            if(a[i] == ele)
            {
                ele = i;
                break;
            }
        }
        ll ans = 0;
        if(a.size() >= n)
        {
            for(i = 0; i < n; i++)
                ans += a[i];
        }
        else
        {
            for(i = 0; i < ele; i++)
                ans += a[i];
            n -= max(0ll, ele);
            if(ele != -1)
            {
                p = a.size() - ele;
                for(i = ele; i < a.size(); i++)
                    ans += n / p * a[i];
                for(i = ele; i - ele < n % p; i++)
                    ans += a[i];
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 5932