akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>
#include <numeric>
#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FILL(a, x) memset(a, x, sizeof(a))

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

int h[100005];
int dp[100005];

int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	memset(dp, 0x7f, sizeof(dp));
	dp[0] = 0;
	REP(i, n)scanf("%d", &h[i]);
	REP(i, n) {
		FOR(j, i + 1, min(n, i + k + 1)) {
			dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
		}
	}
	printf("%d\n", dp[n - 1]);
	return 0;
}

Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.Scanner;

class Main{

	static int N;
	static int M;
	static 		ArrayList<ArrayList<Integer>> map;



	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);			//文字の入力
		N = sc.nextInt();
		long[] a = new long[N];
		long sum = 0;
		
		a[0] = sc.nextLong();
		for(int i = 1;i < N;i++){
			a[i] = sc.nextLong()+a[i-1];
		}
		sum = a[N-1];
		
		long ans = 1000000000000000L;
		for(int i = 0;i < N-1;i++){
			long score = Math.abs(a[i] - (sum - a[i]));
			ans = Math.min(ans, score);
		}
		System.out.println(ans);
		
		
	}

}




Measured memory_bytes: 65544
n = int(input())
ac = 0
wa = 0
tle = 0
re = 0

for i in range(n) :
    s = input().rstrip('\n')
    if s == 'AC' :
        ac += 1
    elif s == 'WA' :
        wa += 1
    elif s == 'TLE' :
        tle += 1
    elif s == 'RE' :
        re += 1

print('AC x',ac)
print('WA x',wa)
print('TLE x',tle)
print('RE x',re)

Measured memory_bytes: 9208
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
   
public class Main {
    public static void main( String args[] ) throws IOException {
		BufferedReader bufRed	= new BufferedReader( new InputStreamReader( System.in ) );
        String[] dat			= bufRed.readLine().split( " " );
        int a, b, C;
		a = Integer.parseInt(dat[0]);
        b = Integer.parseInt(dat[1]);
        C = Integer.parseInt(dat[2]);
		
		double radianC	= Math.toRadians( C );
		double ab		= a * b;
        double sinC		= Math.sin( radianC );
        double cosC		= Math.cos( radianC );
        double S		= ab * sinC / 2;
        double L		= a + b + Math.sqrt( a * a + b * b - 2 * ab * cosC );
        double h		= b * sinC;
          
        System.out.print(S + "\n" + L + "\n" + h + "\n");
          
    }
      
}

Measured memory_bytes: 17060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long ans = 0;
		for(int i = 0; i < n; i++) {
			ans += sc.nextLong() - 1;
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 27492
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll N;
    ll base = 0;
    string S;

    cin >> N >> S;
    ll icnt = 0, jcnt = 0;
    ll ians = 0, jans = 0, oadd = 0;
    for(int i = 0; i < N; i++) if(S[i] == 'I') icnt++;
    for(int i = 0; i < N; i++) {
        if(S[i] == 'J') {
            jcnt++;
        }
        oadd = max(oadd, icnt * jcnt);
        if(S[i] == 'I') {
            icnt--;
        }
        if(S[i] == 'O') {
            base += icnt * jcnt;
            ians += (icnt + 1) * jcnt;
            jans += icnt * (jcnt + 1);
        }
    }
    cout << max(base + oadd, max(ians, jans)) << endl;
    return (0);
}



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

int main()
{
    int N,D,X,c=0,A[100];
    cin>>N;
    cin>>D>>X;
    for(int i=1;i<=N;i++)
    {
        cin>>A[i];
        for(int j=1;j<=D;j=j+A[i])
        {
            c++;

        }
    }
    cout<<(X+c);
}

Measured memory_bytes: 256
using System;

namespace tes
{
    class Program
    {
        static void Main(string[] args)
        {
            var line1 = Console.ReadLine().Split();
            int a = int.Parse(line1[0]);
            int b = int.Parse(line1[1]);
            int c = int.Parse(line1[2]);
            int[] x = new int[10000];
            int y = 0;
            int calc = 0;

            for (int n = 1; n <= c; n++)
            {
                if (c % n == 0)
                {
                    x[y] = n;
                    y++;
                }

            }

            for (int q = 0; q < y; q++)
            {
                if ((x[q] >= a)&&(x[q]<=b))
                {
                    calc += 1;
                }
            }
            Console.WriteLine(calc);
        }
    }
}

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

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {

	string s, t; cin >> s >> t;
	int res = 0;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] != t[i]) res++;
	}

	cout << res;
	
	return 0;
}

Measured memory_bytes: 3892
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

import math

n, d = getList()

zahyo = [getList() for i in range(n)]

ans = 0

for i in range(n):
    for j in range(i+1, n):
        tmp = 0
        va = zahyo[i]
        vb = zahyo[j]
        for dim in range(d):
            tmp += (vb[dim] - va[dim]) ** 2

        base = int(math.sqrt(tmp))
        if base ** 2 == tmp:
            ans += 1
            # print(va, vb)

print(ans)


Measured memory_bytes: 38384
n = int(input())
if(n < 105):
    print(0)
elif(105 <= n < 135):
    print(1)
elif(135 <= n < 165):
    print(2)
elif(165 <= n < 189):
    print(3)
elif(189 <= n < 195):
    print(4)
else:
    print(5)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int n;
  cin>>n;
  VEC<LL>a(n);
  REP(i,0,n)cin>>a[i];
  sort(ALL(a));
  cout<<abs(a[0]-a[n-1]);

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
using static System.Array;

class MainClass : Scanner
{
    
    static void Main()
    {
        int N = RInt();
        var A = RLongs();
        var B = new long[N];
        for (int i = 0; i < N; i++)
        {
            B[i] = A[i] - (i + 1);
        }
        Array.Sort(B);
        long b = B[N / 2];
        long ans = 0;
        for (int i = 0; i < N; i++)
        {
            ans += Abs(B[i]-b);
        }
        WriteLine(ans);
    }
    
}

class Scanner
{
    public static int RInt() => int.Parse(Console.ReadLine());
    public static long RLong() => long.Parse(Console.ReadLine());
    public static string RString() => Console.ReadLine();
    public static double RDouble() => double.Parse(Console.ReadLine());

    public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
    public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
    public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static string[] RStrings() => Console.ReadLine().Split();
    //public static string[] RStrings(Func<string, string> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static T1 ReadStream<T1>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        return r1;
    }
    public static (T1, T2) ReadStream<T1, T2>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        return (r1, r2);
    }
    public static (T1, T2, T3) ReadStream<T1, T2, T3>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        return (r1, r2, r3);
    }
    public static (T1, T2, T3, T4) ReadStream<T1, T2, T3, T4>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        var r4 = (T4)Convert.ChangeType(r[3], typeof(T4));
        return (r1, r2, r3, r4);
    }
}

Measured memory_bytes: 46772
#include<stdio.h>
#include<map>
#include<algorithm>
int main()
{
	int n,i,s;
	std::pair<int,int>b[25];
	while(scanf("%d",&n),n)
	{
		for(i=0;i<n;++i)scanf("%d%d",&b[i].second,&b[i].first);
		std::sort(b,b+n);
		for(i=s=0;i<n;++i)
		{
			s+=b[i].second;
			if(s>b[i].first){puts("No");goto E;}
		}
		puts("Yes");
E:;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
	int n;
	
	while( cin >> n ) {

		if( n == 0 ) break;

		int p, d1, d2;
		int maxd = 0;
		int maxp = 0;
		
		for( int i = 0; i < n; i++ ) {
			cin >> p >> d1 >> d2;
			int d = d1+d2;
			if( maxd <= d ) {
				maxd = d;
				maxp = p;
			}
		}

		cout << maxp << " " << maxd << endl;
	}

    return 0;
}

Measured memory_bytes: 3016
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

map< ll, int > prime_factor(ll n) {
  map< ll, int > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main() {
  ll n,p;
  cin >> n >> p;
  auto mp = prime_factor(p);
  ll ans = 1;
  for(auto key : mp){
    if(key.se >= n){
      int e = key.se/n;
      ans*=pow(key.fi,e);
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long int
#define endl "\n"
const int MOD=1e9+7;
#ifndef HOME
#define cerr if(0)cerr
#endif
double maxvolume(double s) 
{ 
	// finding length 
	double length = s / 3; 

	s -= length; 

	// finding breadth 
	double breadth = s / 2; 

	// finding height 
	double height = s - breadth; 

	return length * breadth * height; 
} 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    double l;
    cin>>l;
    double ans = maxvolume(l);
    cout<<setprecision(12)<<ans<<endl;
    
    return 0;
    
}



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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

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

    ll n;cin >> n;
    REP(i, n){
        ll a;cin >> a;
        if(a % 2)continue;
        if(a % 3 == 0)continue;
        if(a % 5 == 0)continue;
        cout << "DENIED" << endl;
        return 0;
    }

    cout << "APPROVED" << endl;

	return 0;
}


Measured memory_bytes: 256
d = {1:0, 2:0, 3:0, 4:0}
for i in range(3):
  a, b = map(int, input().split())
  d[a] += 1
  d[b] += 1
d = sorted(d.items(), key=lambda x:x[1])
if len(d) == 4 and d[0][1] == 1 and d[1][1] == 1 and d[2][1] == 2 and d[3][1] == 2:
  print('YES')
else:
  print('NO')

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

using namespace std;

int main() {
   long long n,arr[1000000];
   double c;
   cin >> n;
   for(long long i=0;i<n;i++){
       cin >> arr[i];
   }
   sort(arr,arr+n);
   c=(double)arr[0];
   for(long long i=0;i<n-1;i++){
       c=(c+(double)arr[i+1])/2.0;
   }
 cout <<setprecision(16)<< c;   
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

void solve(long long N, long long K){
    long long ans = 1;
    REP(i, N)
        ans = min(ans * 2, ans + K);
    cout << ans << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    solve(N, K);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef long long int lli;
using namespace std;
#define int long long int

inline void swap(int &a, int &b) {
    int tmp = a;
    a = b;
    b = tmp;
}

/**
 * 約数列挙
 * @order: O(N^1/2)
 **/
vector<int> divisor(int n) {
    vector<int> res;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (i != n / i) res.push_back(n / i);
        }
    }
    return res;
}

signed main() {
    int N;
    cin >> N;

    vector<int> divisors = divisor(N);
    int ans = 0;
    for (auto it = divisors.begin(); it != divisors.end(); ++it) {
        int m = *it - 1;
        if (m > 1) {
            int p = N / m;
            if (p < m) ans += m;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
n,m=map(int,input().split())
ks=[]
for i in range(m):
    ks.append([int(j) for j in input().split()])
p=[int(i) for i in input().split()]

def base(X, a):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%a)+out
        X_dumy = int(X_dumy/a)
    return str(out).rjust(n,'0')
ans=0
for x in range(2**n):
    s=[0 for _ in range(m)]
    b=base(x,2)
    for i in range(m):
        for j in range(ks[i][0]):
            if b[ks[i][j+1]-1]=="0":
                if s[i]==0:
                    s[i]=1
                else:
                    s[i]=0
    if s==p:
        ans+=1

print(ans)
    
        
    









Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define eb emplace_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vl> vvl;
#define deb(x) cout << #x": " << (x) << endl;

const int N = 1e3+5;
const lli INF = 1e18;
const lli MOD = 1e9+7;

bool mm[N];
vi primes(1,2);
ld nk[N][N];
void sieve(){
	for(int i = 4; i<N; i+=2)mm[i]=1;
	for(int i = 3; i*i<=N; i+=2)if(!mm[i])for(int j = i*i; j<N; j+=i)mm[j]=1;
	for(int i = 3; i<N; i+=2)if(!mm[i])primes.pb(i);
}

void pascal(){
	fore(i,0,N)nk[i][0]=nk[i][i]=1.0;
	fore(i,1,N)fore(j,1,i)nk[i][j]=nk[i-1][j-1]+nk[i-1][j];
}

lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}

lli lcm(lli a, lli b){
	if(a<b)swap(a,b);
	lli c = gcd(a,b);
	a/=c;
	return a*b;
}

int popcount(lli x) { return __builtin_popcountll(x); }

lli poww(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = res * a;
		a = a*a;
		b/=2;
	}
	return res;
}

lli powm(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = (res * a)%MOD;
		a = (a*a)%MOD;
		b/=2;
	}
	return res;
}

bool isPrime(lli x){
	if(x==1)return 0;
	for(auto i:primes){
		if(i*i>x)return 1;
		if(x%i==0)return 0;
	}
	return 1;
}

// ---- コーディングはここから！ ('-')7

int main(){
	lli a,c; double b; cin>>a>>b;
	c=round(b*100.0);
	lli d = a*c/100;
	cout<<d<<ENDL;
}


Measured memory_bytes: 3740
#include<bits/stdc++.h>
using namespace std;
int64_t g(int64_t a,int64_t b){
  if(a>b)
    return g(b,a);
  if(a==0)
    return b;
  return g(b%a,a);
}
int main(){
  int n;
  cin>>n;
  int64_t c=1;
  for(int i=0;i<n;i++){
    int64_t t;
    cin>>t;
    c*=t/g(t,c);
  }
  cout<<c<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>
 
using namespace std;
 
#define MOD 1000000007
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,l,r) for(ll (i)=(l);(i)<(r);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
 
 
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;
}
 
//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
 
void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}
 
//最短経路(負の辺を含んでいてもOK)
void WarshallFloyd(Graph& G, Matrix& d) {//O(V^3)
	d.resize(G.size());
	REP(i, d.size())d[i].resize(G.size());
	REP(i, d.size()) {
		REP(j, d[i].size()) {
			d[i][j] = INF;
		}
	}
	REP(i, G.size()) {
		REP(j, G[i].size()) {
			d[i][G[i][j].to] = G[i][j].cap;
		}
	}
	REP(i, G.size()) {
		REP(j, G.size()) {
			REP(k, G.size()) {
				chmin(d[j][k], d[j][i] + d[i][k]);
			}
		}
	}
}
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
 
	ll n, m, l;
	cin >> n >> m >> l;
	Graph g(n);
	REP(i, m) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		if(c<=l) add_edge(g, a, b, c, true, c);
	}
 
	Matrix d;
	WarshallFloyd(g, d);
 
	Graph g2(n);
	REP(i, n) {
		REP(j, n) {
			if (d[i][j] <= l) add_edge(g2, i, j, 1, false, 1);
		}
	}
	Matrix ans;
	WarshallFloyd(g2, ans);
 
	ll q;
	cin >> q;
 
	REP(i, q) {
		ll s, t;
		cin >> s >> t;
		s--; t--;
		if (ans[s][t] != INF) {
			cout << ans[s][t]-1 << endl;
		}
		else {
			
          cout << -1 << endl;
		}
	}
 
	return 0;
}

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

int main(){
    int n;
    while(scanf("%d",&n), n != 0){
        int a[1001]={0};
        for(int i=0;i<n;++i)scanf("%d ",&a[i]);
        int mini = INT_MAX;
        for(int i=0;i<n;++i){
            for(int j=i+1;j<n;++j){
                int d = abs(a[i] - a[j]);
                if(d < mini)mini = d;
            }
        }
        printf("%d\n",mini);
    }

    return 0;
}


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

int main() {
  string N;
  cin >> N;
  if(N[0] == N[1] && N[1] == N[2] ||N[1] == N[2] && N[2] == N[3]){
     cout << "Yes" << endl;
  }
  else {
  cout << "No" << endl;
  } 
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int N;cin>>N;
        if(N==0) break;
        vector<int> sum(1000),time(1000,-1);
        
        while(N--){
            string md,hm,type,d;cin>>md>>hm>>type>>d;
            int a=(hm[0]-'0')*600+(hm[1]-'0')*60+(hm[3]-'0')*10+(hm[4]-'0');
            int id=stoi(d);
            
            if(type[0]=='I'){
                time[id]=a;
                if(id==0){
                    for(int i=1;i<1000;i++){
                        if(time[i]!=-1) time[i]=a;
                    }
                }
            }else{
                if(id==0){
                    time[id]=-1;
                    for(int i=1;i<1000;i++){
                        if(time[i]!=-1){
                            sum[i]+=a-time[i];
                            time[i]=a;
                        }
                    }
                }else{
                    if(time[0]!=-1){
                        sum[id]+=a-time[id];
                    }
                    time[id]=-1;
                }
            }
            
            //cout<<a<<" "<<id<<" "<<type[0]<<endl;
        }
        
        int ans=0;
        
        for(int i=1;i<1000;i++) ans=max(ans,sum[i]);
        
        cout<<ans<<endl;
    }
}






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

template <typename T> inline void read (T &x) {bool b = 0; char c; while (!isdigit (c = getchar()) && c != '-');
if (c == '-') c = getchar(), b = 1; x = c - 48; while (isdigit(c = getchar())) x = (x<<3) + (x<<1) + c - 48; if (b)x=-x;}
template <typename T> inline void wrip(T x) {if (x > 9) wrip(x / 10); putchar(x%10 + 48); }

template <typename T> inline void write(T x) {if (x < 0) putchar('-'), x = -x; wrip(x); putchar(' ');}
template <typename T> inline void writeln(T x) {if (x < 0) putchar('-'), x = -x; wrip(x); putchar('\n');}
inline char readch() {char c; do c = getchar(); while (c == '\n' || c == ' '); return c;}
inline void reads(string &s) {char c; while((c=getchar())==' '||c =='\n'); s=c; while((c=getchar())!=' '&&c!='\n'&&c!=EOF) s+=c;}
inline void getlines(string &s) {char c; while((c=getchar())=='\n'); s=c; while((c=getchar())!='\n') s+=c;}
typedef const int csint;

#define fi first
#define se second
#define mp make_pair
typedef unsigned long long ll;
typedef long double ld;
typedef pair <int, ll> ii;
typedef vector <int> vi;

const ld pi = acos(-1);
const int inf = 1e9,
N = 1e5 + 11;

int n;
ll a[N], node[N], s[N], res;
int main() {
    #ifdef makacha
        freopen("m.inp", "r", stdin);
        freopen("m.out", "w", stdout);
    #endif //makacha
    read(n);
    for (int i = 0; i <= n; i++)
        read(a[i]);
    node[0] = 1 - a[0];
    for (int i = n; i > 0; i--)
        s[i] = s[i + 1] + a[i];
    for (int i = 1; i < n; i++) {
        node[i] = min(s[i], node[i - 1] * 2 - a[i]);
        if (node[i] <= 0)
            return cout << -1, 0;
    }
    for (int i = n - 1; i >= 0; i--) {
        node[i] = min(node[i], node[i + 1] + a[i + 1]);
        if (node[i] * 2 < node[i + 1] + a[i + 1])
            return cout << -1, 0;
    }
    if (n == 0 && a[0] > 1)
        return cout << -1, 0;
    for (int i = 0; i <= n; i++)
        res += a[i] + node[i];
    cout << res;
}


Measured memory_bytes: 5980
#include<bits/stdc++.h>
using namespace std;                                                            
#define pb push_back                                                            
#define mp make_pair                                                                                                                                
#define sqr(a) ((a) * (a))                                                      
#define io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);   
#define co() cout.precision(10);                                                
#define F for(li i=0;i<n;i++)
#define fo(i,a,n) for(i=a;i<n;i++)
#define ne cout<<"\n";
#define nec cout<<"\n";continue; 
#define test int t;cin>>t;while(t--)
//#define oj #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif

typedef long long li;
typedef long double ld;

const li mod = 1000000007; 

int main()
{
    io();
	li x;
	cin>>x;
	if(x>=30)cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 3636
object Main extends App {

  import scala.io.StdIn._

  val n = readLine.trim.toInt
  val a = readLine.trim.split(' ').map(_.toInt).zipWithIndex
  val indicesOf2 = a.filter(_._1 == 2).map(_._2 + 1)
  val indicesOfMinus2: Array[Int] = a.filter(_._1 == -2).map(_._2 + 1)
  val indicesOfMinus1 = a.filter(_._1 == -1).map(_._2 + 1)
  val res = if (indicesOfMinus2.length % 2 == 0){
    indicesOf2 ++ indicesOfMinus2
  }else {
    if (indicesOfMinus1.length > 0){
      indicesOf2 ++ indicesOfMinus2 :+ indicesOfMinus1.min
    }
    else {
      indicesOf2 ++ indicesOfMinus2.sorted.dropRight(1)
    }
  }
  println(res.length)
  res.sorted.foreach(println(_))
}


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

using namespace std;

const int N = 2005;

int n, x, y;
int adj[N][N];

map <int, int> mp;

int main() {

	cin >> n >> x >> y;
	for (int i = 1; i <= n; i ++) {
		for (int j = i + 1; j <= n; j ++) {
			adj[i][j] = j - i;
			adj[j][i] = j - i;
		}
	}

	/* for (int i = 1; i <= n; i ++) {
		for (int j = 1; j <= n; j ++) {
			cout << i << ' ' << j << ' ' << adj[i][j] << '\n';
		}
	} */

	adj[x][y] = 1;

	for (int i = 1; i <= n; i ++) {
		for (int j = 1; j <= n; j ++) {
			int k1 = adj[i][j];
			int k2 = adj[i][x] + adj[j][y] + 1;
			int k3 = adj[i][y] + adj[j][x] + 1;
			adj[i][j] = min(k1, min(k2, k3));
		}
	}

	for (int i = 1; i <= n; i ++) {
		for (int j = 1; j <= n; j ++) {
			mp[adj[i][j]] ++;
		}
	}

	for (int i = 1; i < n; i ++) {
		cout << mp[i] / 2 << '\n';
	}
	return 0;
}

Measured memory_bytes: 16000
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"math"
	"os"
	"strconv"
)

const MAX = 10000
const INFTY = math.MaxInt64
const WHITE = 0
const GRAY = 1
const BLACK = 2

var n int
var adj [MAX][]pair

type pair struct {
	v1, v2 int
}

func dijkstra() {
	PQ := &PriorityQueue{}
	heap.Init(PQ)
	color := [MAX]int{}
	d := [MAX]int{}
	for i := 0; i < n; i++ {
		d[i] = INFTY
		color[i] = WHITE
	}

	d[0] = 0
	heap.Push(PQ, pair{0, 0})
	color[0] = GRAY

	for len(*PQ) != 0 {
		f := heap.Pop(PQ).(pair)
		u := f.v2
		color[u] = BLACK

		if d[u] < f.v1 { // TODO
			continue
		}

		for j := 0; j < len(adj[u]); j++ {
			v := adj[u][j].v1
			if color[v] == BLACK {
				continue
			}
			if d[v] > d[u]+adj[u][j].v2 {
				d[v] = d[u] + adj[u][j].v2
				heap.Push(PQ, pair{d[v], v})
				color[v] = GRAY
			}
		}
	}

	for i := 0; i < n; i++ {
		v := -1
		if d[i] != INFTY {
			v = d[i]
		}
		fmt.Printf("%v %v\n", i, v)
	}
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ = strconv.Atoi(sc.Text())

	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())

		for j := 0; j < k; j++ {
			sc.Scan()
			v, _ := strconv.Atoi(sc.Text())
			sc.Scan()
			c, _ := strconv.Atoi(sc.Text())
			adj[u] = append(adj[u], pair{v, c})
		}
	}

	dijkstra()
}

type PriorityQueue []pair

func (h PriorityQueue) Len() int {
	return len(h)
}

func (h PriorityQueue) Less(i, j int) bool {
	return h[i].v1 < h[j].v1
}

func (h PriorityQueue) Swap(i, j int) {
	//fmt.Printf("swap: %v <> %v\n", h[i], h[j])
	h[i], h[j] = h[j], h[i]
}

func (h *PriorityQueue) Push(x interface{}) {
	*h = append(*h, x.(pair))
}

func (h *PriorityQueue) Pop() interface{} {
	// if len(*m) == 0 {
	//     return nil
	// }

	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]

	return x
}



Measured memory_bytes: 15484
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int main(){
 int a,b,c;
 cin >> a>>b>> c;
 if((b-a)==(c-b)){
     cout << "YES" << endl; 
 }else{
     cout << "NO" << endl;
 }
return 0;
}

Measured memory_bytes: 256
def primefactor(x):
    fac=[]
    for i in xrange(2,int(x**0.5)+1):
        while x%i==0:
            fac+=[i]
            x=x/i
    if x!=1:
        fac+=[x]
    return fac

n=input()
ans=primefactor(n)
print(str(n)+":"+" "+" ".join(map(str,ans)))

Measured memory_bytes: 6608
fun main(args: Array<String>) {
    val sc = java.util.Scanner(System.`in`)
    val n = sc.nextInt()
    //val a = sc.asSequence().take(n).map(String::toInt).sortedDescending().toList()
    val a = sc.asSequence().take(n).map(String::toInt).toList()

    var r = 999

    for (i in 1 until a.size) {
        val v = Math.abs(a.take(i).sum() - a.takeLast(a.size - i).sum())
        if (v < r) {
            r = v
        }
    }

    println(r)
}


Measured memory_bytes: 33640
#include <bits/stdc++.h>
using namespace std;
queue< pair<string,int> > Q;
pair<string,int> P;

int main()
{
    int n , q , time;
    string name;
    cin >> n >> q;
    for(int i = 0;i < n;i++){
        cin >> name >> time;
        P = make_pair(name,time);
        Q.push(P);
    }
    int sum = 0;
    while(!Q.empty()){
        P = Q.front();
        time = P.second;
        if(time > q){
                P.second -= q;
                sum += q;
                Q.push(P);
                Q.pop();
        }else{
            sum += time;
            cout << P.first << " " << sum << endl;
            Q.pop();
        }
    }
    return 0;
}



Measured memory_bytes: 6400
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back
#define sz(x) int(x.size())

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    else return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    return -Parent[root(a)];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);
    if(a == b) return false;

    if(size(a) < size(b)) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }
};

class Factrial{
public:
  vl Fac;
  Factrial(int MAX){
    Fac = vl(MAX+1);
    rep(i,MAX) {
      if(i == 0) Fac[i] = 1;
      else Fac[i+1] = ((i+1)*Fac[i])%MOD;
    }
  }
};

int main(){
  int k,x; cin >> k >> x;
  cout << (500*k >= x ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

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

fn main() {
    input!{
        n: usize,
        v: [usize; n]
    }
    let mut map: HashMap<usize, usize> = HashMap::new();
    for &x in &v {
        *map.entry(x).or_insert(0) += 1;
    }
    let mut w: Vec<usize> = map.values().cloned().collect();
    w.sort_by(|x, y| y.cmp(x));
    let mut idx = 0;
    let mut rest = n;
    for k in 1..n + 1 {
        while idx < w.len() && rest < w[idx] * (k - idx) {
            rest -= w[idx];
            idx += 1;
        }
        println!("{}", rest / (k - idx));
    }
}


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

using namespace std;

int main() {
    std::ios::sync_with_stdio(false); 
    cin.tie(nullptr);
    
    int H, W;
    cin >> H >> W;
    vector<string> grid(H);
    for (int i = 0; i < H; ++i) {
        cin >> grid[i];
    }
    constexpr int MOD = 1'000'000'007;
    vector<vector<int>> dp(H, vector<int>(W, 0));
    dp[0][0] = 1;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (i + 1 < H && grid[i + 1][j] != '#') {
                dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % MOD;
            }
            if (j + 1 < W && grid[i][j + 1] != '#') {
                dp[i][j + 1] = (dp[i][j + 1] + dp[i][j]) % MOD;
            }
        }
    }
    cout << dp[H - 1][W - 1] << "\n";

    return 0;
}

Measured memory_bytes: 5248
use v5.18;
use warnings;
use List::Util qw( sum );
sub read_line { chomp(my $s = <>); $s }
sub splited_read_line { split / /, read_line }

my $n = read_line;
my @nums = splited_read_line;
say sum map { $_ - 1 } @nums;


Measured memory_bytes: 1280
/*
author : seryu
title : ABC168C_"Colon"
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define mreps(i,j,n) for(int i = j; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(all(x), val), x.end())
typedef long long ll;
typedef pair<int, int> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;
int INF = 1001001001;
double PI = acos(-1);

void solve()
{
	double a, b, h, m;
	cin >> a >> b >> h >> m;
	double t_a = (h+m/60.)*30.*PI/180.;
	double t_b = m*6.*PI/180.;
	double ans = pow(pow(a*cos(t_a)-b*cos(t_b),2)+pow(a*sin(t_a)-b*sin(t_b),2),0.5);
	cout << ans << endl;
	return;	
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 4328
using System;
using System.IO;
using System.Text;

namespace MinPro2019D
{
    public class Program
    {
        void Solve(SimpleScanner ss, StreamWriter sw)
        {
            //---------------------------------
            var L = int.Parse(ss.Next());
            var dp = new long[5];

            for (var i = 0; i < L; i++)
            {
                var A = long.Parse(ss.Next());
                var x = A == 0 ? 2 : A & 1;

                dp[0] += A;
                dp[1] += x;
                dp[2] += (x & 1) ^ 1;
                dp[3] += x;
                dp[4] += A;

                for (var t = 1; t < 5; t++)
                {
                    dp[t] = Math.Min(dp[t], dp[t - 1]);
                }
            }

            sw.WriteLine(dp[4]);
            //---------------------------------
        }

        static void Main()
        {
            var ss = new SimpleScanner(Console.OpenStandardInput());
            var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            new Program().Solve(ss, sw);
            sw.Flush();
        }
    }

    //ref: https://qiita.com/Camypaper/items/de6d576fe5513743a50e#%E5%85%A5%E5%8A%9B%E3%81%AE%E9%AB%98%E9%80%9F%E5%8C%96
    //by Camypaperさん 
    public class SimpleScanner
    {
        const int DefaultCapacity = 1024;

        readonly Stream stream;
        readonly int capacity;
        readonly byte[] buffer;

        int index = 0;
        int length = 0;
        bool isEof = false;

        public SimpleScanner(Stream stream, int capacity = DefaultCapacity)
        {
            this.stream = stream;
            this.capacity = capacity;
            this.buffer = new byte[capacity];
        }

        void Reload()
        {
            if (isEof) throw new EndOfStreamException();
            index = 0;
            length = stream.Read(buffer, 0, capacity);
            isEof = length <= 0;
        }

        int Peek()
        {
            if (index < length) return buffer[index];
            Reload();
            return Peek();
        }

        int Read()
        {
            var ret = Peek();
            index++;
            return ret;
        }

        bool IsInputable(int b)
        {
            return 33 <= b && b <= 126;
        }

        public string Next()
        {
            var sb = new StringBuilder();
            while (!IsInputable(Peek())) Read();
            while (IsInputable(Peek())) sb.Append((char)Read());
            return sb.ToString();
        }
    }
}


Measured memory_bytes: 17212
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <iostream>

using namespace std;

int main() {
  int64_t N;
  cin >> N;
  vector<int64_t> nums(N);
  for (int n = 0; n < N; ++n) {
    cin >> nums[n];
  }
  sort(nums.begin(), nums.end(), greater<int64_t>());
  int64_t result = 0;
  for (int64_t n = 1; n < N; ++n) {
    result += nums[n / 2];
  }
  cout << result << endl;
  
  return 0;
}


Measured memory_bytes: 4848
from collections import Counter
n = int(input())
c = Counter(map(int, input().split()))
dp = [[[0]*(n+1) for _ in range(n+1)] for _ in range(n+1)]

for i in range(n+1):
    for j in range(n+1-i):
        for k in range(n+1-i-j):
            non_zero = i+j+k
            if non_zero == 0:
                continue
            dp[i][j][k] = n
            if 0 <= i-1 and j+1 <= n:
                dp[i][j][k] += dp[i-1][j+1][k]*i
            if 0 <= j-1 and k+1 <= n:
                dp[i][j][k] += dp[i][j-1][k+1]*j
            if 0 <= k-1:
                dp[i][j][k] += dp[i][j][k-1]*k
            dp[i][j][k] /= non_zero

print(dp[c[3]][c[2]][c[1]])


Measured memory_bytes: 497416
def check(p, k, arr):
  subtotal = 0
  num_of_tracks = 1
  for a in arr:
    subtotal += a
    if subtotal > p:
      num_of_tracks += 1
      if num_of_tracks > k: return False
      subtotal = a
  return True

n, k = map(int, input().split())
arr = [int(input()) for i in range(n)]

min_p = max(arr)
max_p = sum(arr)
while min_p < max_p:
  mid_p = (min_p + max_p) // 2
  if check(mid_p, k, arr):
    max_p = mid_p
  else:
    min_p = mid_p + 1

print(min_p)

Measured memory_bytes: 11568
n0,m0,v0,p0,*a0=$<.read.split.map &:to_i
as=a0.sort_by{|e|-e}
th=as[p0-1]
a1=as.drop(p0).map{|e| th-e }
v1=[v0-p0,0].max
n1=n0-p0
ans=p0
tsum=0
#p [a1,v1,n1,ans]
a1.each_with_index{|e,i|
  break if e>m0
  ans+=1 if i<n1-v1 || (m0-e)*(i+1)+tsum >= (v1-(n1-i-1))*m0
  tsum+=e
}
p ans

Measured memory_bytes: 14456
package main

import (
	"fmt"
	"strings"
)

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func main() {
	var s string
	fmt.Scan(&s)

	fmt.Println(strings.LastIndex(s, "Z") - strings.Index(s, "A") + 1)
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
const int INT_INF = 1001001001;
//stoi(s) : string→int stoll(s) :string→longlong  int→string to_string(i)
const double PI = acos(-1.0);
//小数点の表し方 cout << fixed << setprecision(5);

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

}

Measured memory_bytes: 3636
N, K = map(int, input().split())
MOD = 10**9 + 7
MAX_N = 10**6 + 5
fact = [0]*(MAX_N)
fact_inv = [0]*(MAX_N)
fact[0] = 1
for i in range(MAX_N-1):
    fact[i+1] = fact[i]*(i+1) % MOD
fact_inv[-1] = pow(fact[-1], MOD-2, MOD)
for i in range(MAX_N-2, -1, -1):
    fact_inv[i] = fact_inv[i+1]*(i+1) % MOD


def comb(n, k):
    return fact[n]*fact_inv[k] % MOD * fact_inv[n-k] % MOD


if K >= N:
    print(comb(2*N-1, N-1))
    exit()

ans = 1
for i in range(1, K+1):
    ans += comb(N, i)*comb(N-1, i) % MOD
    ans %= MOD
print(ans)


Measured memory_bytes: 87768
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner stdn = new Scanner(System.in);

		int a = stdn.nextInt();
		int b = stdn.nextInt();
		int c = stdn.nextInt();
		int flg = 0;
		
		for( ; a <= b; a++){
			if(c % a == 0){
				flg++;
			}
		}
		System.out.println(flg);
	}
}

Measured memory_bytes: 26324
#include <iostream>
using namespace std;
int N, D, X;
int main() {
	cin >> N >> D >> X;
	int s = 0;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		s += (D + a - 1) / a;
	}
	cout << s + X << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define MOD 1000000007
#define pb push_back
#define cy cout<<"Yes\n"
#define cn cout<<"No\n"
typedef unsigned long long int ll;
int main()
{
   ll n;
   cin>>n;
   vector<ll>a(n);
   ll sum=0;
   ll cnt[100005]={};
   for(int i=0;i<n;i++)
   {
       cin>>a[i];
       sum+=a[i];
       cnt[a[i]]++;
   }
   ll q;
   cin>>q;
   ll sum1=sum;
   while(q--)
   {
       ll b,c;
       cin>>b>>c;
       ll va=cnt[b];
       //cout<<va<<endl;
       if(va==0)
       {
           cout<<sum1<<endl;
       }
       else
       {
           sum1-=(va*b);
           sum1+=(va*c);
           cnt[c]+=va;
           cnt[b]=0;
           cout<<sum1<<endl;
       }
   }
}


Measured memory_bytes: 4836
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
a.sort()
b = list(itertools.accumulate(a))
for i in range(n-1)[::-1]:
    if b[i]*2 < a[i+1]:
        res = n-i-1
        break
else:
    res = n
print(res)

Measured memory_bytes: 90420