akhauriyash/Code-Regression huggingface dataset:
H,W,K=map(int,input().split())
L=[]
for i in range(H):
    s=list(input())
    for j in range(W):
        if s[j]=="#":
            s[j]=1
        else:
            s[j]=0
    L.append(s)
#print(L)

import copy
ans=0
l=[0 for i in range(W)]
for h in range(2**H):
    A=copy.deepcopy(L)
    Y=h+0
    for y in range(H):
        if Y&1==0:
            A[y]=l
        Y=Y>>1
    #print(A)
    
    for w in range(2**W):
        X=w+0
        cnt=0
        for x in range(W):
            if X&1==1:
                for z in range(H):
                    cnt+=A[z][x]
            X=X>>1
        #print(cnt)
        if cnt==K:
            ans+=1
print(ans)
        

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int main()
{
    int n;
    cin >> n;

    string ans = "No";
    rep(i, n / 4 + 1)
    {
        rep(j, n / 7 + 1)
        {
            if (4 * i + 7 * j == n)
            {
                ans = "Yes";
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)

using namespace std;

typedef long long int lli;
typedef unsigned long long int ulli;

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<int>> C(10, vector<int>(10, 0));
    REP (i, 0, 10) REP (j, 0, 10) cin >> C[i][j];
    vector<vector<int>> A(H, vector<int>(W, 0));
    REP (i, 0, H) REP (j, 0, W) cin >> A[i][j];
    lli res = 0;
    REP (k, 0, 10) REP (i, 0, 10) REP (j, 0, 10) {
        C[i][j] = min(C[i][k] + C[k][j], C[i][j]);
    }
    REP (i, 0, H) REP (j, 0, W) {
        if (A[i][j] == -1) continue;
        res += C[A[i][j]][1];
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int l[105];
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    
    int n,x; cin >> n >> x;
    rep(i,n) cin >> l[i]; 
    int d = 0;
    int cnt=0;
    
    rep(i,n+1){
        d += l[i];
        cnt++;
        if(d > x) break;
    }
    
    cout << cnt << ln;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>

using namespace std;

int main(){
	string hi [5];
	string input;
	hi[0] ="hi";
	for(int i=1;i<5;i++){
		hi[i]=hi[i-1]+hi[0];
	}
	cin>>input;
	for(int i=0;i<5;i++){
		if(input==hi[i]){
			cout<<"Yes"<<endl;
			break;
		}
		if(i==4){
			cout<<"No"<<endl;
		}
	}
	return 0;
}
		
	

Measured memory_bytes: 256
// atcoder/abc118/B/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, m;
  while (cin >> n >> m) {
    map<int, int> cnt;
    int x = 0;
    for (int i = 0; i < n; ++i) {
      int k;
      cin >> k;
      for (int j = 0; j < k; ++j) {
        int y;
        cin >> y;
        x += (++cnt[y] == n);
      }
    }
    cout << x << endl;
  }

  return 0;
}


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

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define EACH(begin, end) for(auto itr = (begin); itr != (end); itr++)

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;



ll N = 0;
ll K = 0;
ll ret = 0;
string str;

void input() {
  IN(N);
  IN(K);
  IN(str);
}

void solve() {
  char c = str[K-1];
  if (c == 'A') {
    c = 'a';
  } else if (c == 'B'){
    c = 'b';
  } else {
    c = 'c';
  }
  str[K-1] = c;
}

int main(void){
  input();
  solve();
  cout << str << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N,M=[int(x) for x in input().strip().split()]
AN=[]
BN=[]
val={}
for i in range(N):
    Ai,Bi=[int(x) for x in input().strip().split()]
    val[Ai]=Bi+val.get(Ai,0)
    AN.append(Ai)

AN=sorted(set(AN))
m=0
ans=0
for Ai in AN:
    ans+=Ai*min(M-m,val[Ai])
    m+=min(M-m,val[Ai])
    if m==M:
        break
print(ans)


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

int main(){
    int n;
    cin >> n;
    ll ans = 0, i = 1;
    for (i=1; i<=n; ++i) {
        ll k = n / i;
        ans += k*(k+1)/2 * i;
    }
    //ans += (i+n)*(n-i+1)/2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3600
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
A.sort()
C = Counter(A)
ma = max(2, A[-1])
L = [0]*(ma+1)
for i in range(ma+1):
    l = C.get(i)
    if l == None:
        l = 0
    L[i] = l
# print(L)
ans = [0]*(ma-1)
ans[0] = L[0]+L[1]+L[2]
for i in range(1, ma-1):
    ans[i] = ans[i-1]-L[i-1]+L[i+2]
# print(ans)
print(max(ans))


Measured memory_bytes: 96160
n,k=map(int,input().split())
arr=list(map(int,input().split()))
arr=sorted(arr)
nc=0
zc=0
pc=0
for i in range(n):
  if arr[i]<0:
    nc+=1
  elif arr[i]==0:
    zc+=1
  else:
    pc+=1
ncc=nc*pc
zcc=zc*(nc+pc)+(zc*(zc-1))//2
pcc=(nc*(nc-1))//2+(pc*(pc-1))//2
if k<=ncc:
  arr1=[]
  arr2=[]
  for i in range(n):
    if arr[i]<0:
      arr1.append(-arr[i])
    elif arr[i]>0:
      arr2.append(arr[i])
  arr1=arr1[::-1]
  c1=len(arr1)
  c2=len(arr2)
  l=0
  r=10**18+1
  k=ncc-k
  while r-l!=1:
    mid=(l+r)//2
    cnt=0
    pos=c2-1
    for i in range(c1):
      while pos!=-1:
        if arr2[pos]>mid//arr1[i]:
          pos-=1
        else:
          break        
      cnt+=pos+1
    if cnt>k:
      r=mid
    else:
      l=mid
  print(-r)
elif k<=(ncc+zcc):
  print(0)
else:
  arr1=[]
  arr2=[]
  for i in range(n):
    if arr[i]<0:
      arr1.append(-arr[i])
    elif arr[i]>0:
      arr2.append(arr[i])
  arr1=arr1[::-1]
  c1=len(arr1)
  c2=len(arr2)
  l=0
  r=10**18+1
  k-=(ncc+zcc)
  while r-l!=1:
    mid=(l+r)//2
    cnt1=0
    pos1=c1-1
    for i in range(c1):
      tmp=0
      while pos1!=-1:
        if arr1[pos1]>mid//arr1[i]:
          pos1-=1
        else:
          break
      tmp+=pos1+1
      if arr1[i]**2<mid:
        tmp-=1
      cnt1+=tmp
    cnt1=cnt1//2
    cnt2=0
    pos2=c2-1
    for i in range(c2):
      tmp=0
      while pos2!=-1:
        if arr2[pos2]>mid//arr2[i]:
          pos2-=1
        else:
          break
      tmp+=pos2+1
      if arr2[i]**2<mid:
        tmp-=1
      cnt2+=tmp
    cnt2=cnt2//2
    cnt=cnt1+cnt2
    if cnt>=k:
      r=mid
    else:
      l=mid
  print(r)

Measured memory_bytes: 101588
#include <iostream>
using namespace std;
int n, A[50];
int solve(int i, int m) {
  if(m == 0) return 1;
  if(i >= n) return 0;
  int res = solve(i+1, m) || solve(i+1, m-A[i]);
  return res;
}

int main() {
  int q, M;
  cin >> n;
  for(int i = 0; i < n; i++) cin >> A[i];
  cin >> q;
  for(int i = 0; i < q; i++) {
    cin >> M;
    if(solve(0, M)) cout << "yes" << endl;
    else cout << "no" << endl;
  }
  return 0;
}



Measured memory_bytes: 3116
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {
		
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int K = sc.nextInt();
			final int N = sc.nextInt();
			
			final long[] arr = new long[N];
			for(int i = 0; i < N; i++) {
				arr[i] = sc.nextLong();
			}
			
			long answer = Long.MAX_VALUE;
			for(int curr = 0; curr < N; curr++) {
				final int prev = (curr + N - 1) % N;
				
				if(arr[prev] < arr[curr]) {
					answer = Math.min(answer, K - Math.abs(arr[curr] - arr[prev]));
				}else {
					answer = Math.min(answer, K - (K - arr[prev]) - arr[curr]);
				}
			}
			
			System.out.println(answer);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}


Measured memory_bytes: 50132
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  maxn = 1e6 + 5;
const int N = 1e5 + 5;

long long n,k,f[N];

ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>k;
	ll ans=0;
	for(int i=k;i>=1;i--){
		f[i]=power(k/i,n);
		for(int j=2*i;j<=k;j+=i) f[i]-=f[j];
		ans=(ans+i*f[i]%mod)%mod;
	}
	cout<<(ans+mod)%mod<<'\n';
	return 0;
}

Measured memory_bytes: 4372
#include<bits/stdc++.h>
using namespace std;
string s,t;
int main(void)
{
	cin>>t;
	s=t;
	reverse(s.begin(),s.end());
	for(int i=0;i<s.size();i++)
	{
		(s[i]=='b'?s[i]='d':(s[i]=='d'?s[i]='b':(s[i]=='q'?s[i]='p':s[i]='q')));
	}
	if(s==t)
	{
		puts("Yes");
	}
	else
	{
		puts("No");
	}
	return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
template<class T>bool chmin(T&a,const T&b){return a>b?(a=b,true):false;}
template<class T>bool chmax(T&a,const T&b){return a<b?(a=b,true):false;}

int nextInt() {
  int x; scanf("%d", &x); return x;
}

const int MAX_N = 100000;
ll h[MAX_N];

bool possible(ll K, ll N, ll A, ll B) {
  vector<ll> r;
  REP(i, N) {
    if (h[i] > K * B) {
      r.push_back(h[i] - (K * B));
    }
  }
  ll need = 0;
  REP(i, r.size()) {
    ll P = (A - B);
    need += (r[i] + P - 1) / P;
  }
  return need <= K;
}

int main2() {
  int N = nextInt();
  int A = nextInt();
  int B = nextInt();
  REP(i, N) h[i] = nextInt();


  ll hi = (ll)1e9 + 10;
  ll lo = 0;
  while(hi - lo > 1) {
    ll mid = (hi + lo) / 2;
    if (possible(mid, N, A, B)) {
      hi = mid;
    } else {
      lo = mid;
    }
  }
  cout << hi << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}


Measured memory_bytes: 2892
#include <iostream>

using namespace std;

int main()
{
	int N, K, X, Y, money = 0;
	cin >> N >> K >> X >> Y;

	for (int i = 0; i < N; i++) {
		if (i < K)
			money += X;
		else money += Y;
	}
	cout << money << endl;
	return 0;
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int n;cin >> n;
    vector<pair<pair<string, int>, int>> v;
    inc(i, 0, n){
        string s;cin >> s;
        int p;cin >> p;
        v.pb({{s, -p}, i+1});
    }
    sort(v.begin(), v.end());
    inc(i, 0, n){
        cout << v[i].se << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
using namespace std;
int p[10000];
void init(int N){
	for(int i=0 ; i<N ; i++ ) p[i]=i ;
}

int root(int a){
		if(p[a]==a) return a;
		return(p[a]=root(p[a]));
}

bool same(int x,int y){
		return root(x)==root(y);
}

void unite(int x,int y){
		p[root(x)]=root(y);
}

int main(){
	int n,q;
	cin >> n >> q ;
	init(n);
	int com,x,y;
	for(int i=0 ; i<q ; i++){
		cin >> com >> x >> y ;
		if(com == 0){
			unite(x,y);
		}
		else if(com == 1){
			cout<<same(x,y)<<endl;	
				}
	}
	return 0;
}

Measured memory_bytes: 1316
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
using namespace std;
using ll = unsigned long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
int main() {
  ll a;
  string b;
  cin >> a >> b;
  // a *= ll(b);
  ll x = 0, y = 0;
  bool o = false;
  for (int i = 0; i < b.length(); i++) {
    if (b[i] == '.')
      o = 1;
    else if (!o)
      x *= 10, x += b[i] - '0';
    else if (o)
      y *= 10, y += b[i] - '0';
  }
  ll temp = a * y / 100;
  a *= x;
  // cout << a << ' ' << temp << endl;
  cout << ll(a + temp) << endl;
}

Measured memory_bytes: 3624
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}

ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 1000000000;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1};
//vector<int> dx = {1,-1,0,0};

int main(){
  string O, E;
  cin >> O >> E;
  if(O.size() == E.size()){
    rep(i, O.size()){
      cout << O[i] << E[i];
    }
    cout << endl;
  }else{
    rep(i, E.size()){
      cout << O[i] << E[i];
    }
    cout << O[O.size()-1] << endl;
  }
}


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

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

	int n,g=-1,x;
	cin>>n;
	while(n--){
		cin>>x;
		if(g==-1) g=x;
		else g=__gcd(g,x);
	}
	cout<<g<<"\n";
	return 0;
}

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

typedef long long ll;
typedef pair<int,int> pii;

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  int N,M;
  cin >> N >> M;
  vector<vector<int>> v(N);

  map<pii,ll> m;

  vector<pii> e; // 枝情報

  int tmp1,tmp2;
  for(int i = 0; i < M; i++){

    ll d;
    cin >> tmp1 >> tmp2 >> d;
    tmp1--;
    tmp2--;
    v.at(tmp1).push_back(tmp2);
    v.at(tmp2).push_back(tmp1);

    m[make_pair(tmp1,tmp2)] = d;
    m[make_pair(tmp2,tmp1)] = -d;
    e.push_back(make_pair(tmp1,tmp2));
    e.push_back(make_pair(tmp2,tmp1));
  }

  queue<int> q;

  ll INF = 1000000000000000000;
  vector<ll> dist(N, INF);
  vector<bool> check(N, false);



  bool flg = true;
  for(int i = 0; i <= N ; i++){

    while(!q.empty()){
      int now = q.front();
      check[now] = true;
      q.pop();

      for(auto next: v.at(now)){
        if(dist[next] == INF){
          dist[next] = dist[now] + m[make_pair(now,next)];
          q.push(next);
        } else{
          if(dist[next] == dist[now] + m[make_pair(now,next)]){
            // ok
            //if(!check[next]) q.push(next);
          } else { 
            flg = false;
            break;
          }
        }
      }
      if(!flg) break;
    }

    if(i < N && check[i] == false){
      q.push(i);
      dist[i] = 0;
    }

  }
  cout << (flg ? "Yes" : "No") << endl;




}


Measured memory_bytes: 35948
#include<cstdio>
int q,c,a,n,cnt;
main(){scanf("%d",&q);for(int i = 0;i <q;i++){cnt= 0;scanf("%d %d %d",&c,&a,&n);while(1){if(c==0){break;}if(c-1>=0&&a-1>=0&&n-1>=0){cnt++;c--;a--;n--;continue;}if(c-2>=0&&a-1>=0){cnt++;c-=2;a--;continue;}if(c-3>=0){cnt++;c-=3;continue;}break;}printf("%d\n",cnt);}return 0;}

Measured memory_bytes: 1028
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.C_Challenge
{
    class ABC_097
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            string s = Console.ReadLine();
            int k = ReadInt();
            var strList = new List<string>();
            var existDict = new Dictionary<string, bool>();
            for(int i = 0; i < s.Length; i++)
            {
                string temp = "";
                for(int j = 0; j < k && i + j < s.Length; j++)
                {
                    temp += s[i + j].ToString();
                    if (!existDict.ContainsKey(temp))
                    {
                        strList.Add(temp);
                        existDict.Add(temp, true);
                    }
                }
            }
            strList.Sort();

            Console.WriteLine(strList[k - 1]);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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


int main() {
  long long int n, ans = 0;
 
  scanf("%lld", &n);
 
  vector<long long int> a(3 * n);
 
  for (int i = 0; i < 3 * n; i++)
  {
    scanf("%lld", &a[i]);
}
    sort(a.begin(), a.end(), greater<int>());
 
  for (int i = 0; i < n; i++)
  {
    ans += a[2 * i + 1];
  }
 
  printf("%lld", ans);
}



Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;
int main(){
	int N;
	cin >> N;
	int L[N];
	for (int i=0;i<N;i++){
		cin >> L[i];
	}
	int check = 1;
	for (int i= 0;i<N;i++){
		int sum = 0;
		for (int j = 0;j<N;j++){
			if(j != i){
				sum = sum + L[j];
			}
		}
		if(sum <= L[i]){
			check = 0;
			break;
		}
	}
	if(check == 1){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<P> ans;
	if(n%2){
		for(int l = 1, r = n-1; l < r; ++l, --r){
			ans.emplace_back(l, r);
		}
	}
	else{
		bool flag = false;
		for(int l = 1, r = n-1; l < r; ++l, --r){
			if(!flag && r-l <= n/2){
				--r;
				flag = true;
			}
			ans.emplace_back(l, r);
		}
	}
	rep(i,m){
		cout << ans[i].first << " " << ans[i].second << endl;
	}
	return 0;
}


Measured memory_bytes: 4236
#include<bits/stdc++.h>
#include<cmath>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#define R register int
#define mm make_pair
using namespace std;
const int manx=300;
#define LL long long
int a[10];
int main()
{
    string s; cin >> s;
    if(s[2] == s[3] && s[4] == s[5]) cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 256
a, b = input().split();
a = int(a);
b = int(b);

for x in range(1,1001):
  tax_8 = int(x * 0.08);
  tax_10= int(x * 0.1);
  if tax_8 == a and tax_10 == b:
    ans = x;
    break;
  elif x == 100:
    ans = -1;
  else:
    pass;
  
print(ans);
  


Measured memory_bytes: 3316
import java.io.*;
import java.util.*;



public class Main{
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;
                    
        str = br.readLine();
        int x = Integer.parseInt(str.trim());
        int[] line = new int[x];

        for(int i=0;i<x;i++){
            line[i] = Integer.parseInt(br.readLine());
        }

        int ans = -1000000000;
        int Ri = line[0];
        for(int i=1;i<x;i++){
            if(line[i] - Ri >ans){
                ans = line[i] - Ri;
            }
            if(Ri > line[i]){
                Ri = line[i];
            }

        }

        System.out.println(ans);

        br.close();
    }

    
}



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

int main(void){
    int A[32] ={
        1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
    };
    int k;
    cin >> k;
    cout << A[k-1] << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int n,y;
int s,g,i;

bool solve(){
  for(s=0;s<=n;s++){
    for(g=0;g<=n-s;g++){
      i=n-s-g;
      if(s*1000+g*5000+i*10000==y) return true;
    }}
  return false;
}

int main(){
  cin >> n >> y;

  if(solve()){
    cout << i << ' '  << g << ' ' << s << endl;}
  else{
    cout << "-1 -1 -1" << endl;}
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <cstring>
#include<cstdio>
#include <cmath>
using namespace std;



int main()
{
	int n;
	int a[300], flag = 1, cnt = 0;

	cin >> n;

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

	while (flag){
		for (int i = 0; i < n; i++)
			if (a[i] % 2)
				flag = 0;
		if (flag){
			for (int i = 0; i < n; i++)
				a[i] = a[i] / 2;
			cnt++;
		}
	}

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

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


int main() {
    int H, W;
    std::cin >> H >> W;

    std::vector<std::vector<int>> tiles_hist(H, std::vector<int>(W, 0));
    for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
            int val;
            std::cin >> val;
            if (val == 1) {
                tiles_hist[y][x] = 0;
            } else {
                if (y > 0) {
                    tiles_hist[y][x] = tiles_hist[y - 1][x] + 1;
                } else {
                    tiles_hist[y][x] = 1;
                }
            }
        }
    }

    int max_area = 0;
    for (int y = 0; y < H; y++) {
        std::stack<std::pair<int, int>> stack;
        for (int x = 0; x < W; x++) {
            int min_x = x;
            while (!stack.empty() && stack.top().second > tiles_hist[y][x]) {
                int area = (x - stack.top().first) * stack.top().second;
                max_area = std::max(area, max_area);
                min_x = stack.top().first;
                stack.pop();
            }
            stack.push(std::make_pair(min_x, tiles_hist[y][x]));
        }
        while (!stack.empty()) {
            int area = (W - stack.top().first) * stack.top().second;
            max_area = std::max(area, max_area);
            stack.pop();
        }
    }

    std::cout << max_area << std::endl;
}



Measured memory_bytes: 10444
# -*- coding: utf-8 -*-
S = input()
result = 0
space_cnt = len(S)-1
for i in range(2 ** space_cnt):
    space = [""] * space_cnt
    for j in range(space_cnt):
        if ((i >> j) & 1):
            space[space_cnt -1 -j] = "+"
    formula = ""
    for i in range(space_cnt):
        formula += S[i]+space[i]
    formula += S[-1]
    result += eval(formula)
print(result)


Measured memory_bytes: 8876
#!/usr/bin/env python3
import sys


def solve(A: int, B: int):
    print(max(A+B,A-B,A*B))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>

int main(int argc, char **argv)
{
    int N;
    std::cin >> N;

    for(int i = 1; i <= 9; i++){
        if((N / i <= 9) && (N % i == 0)){
            std::cout << "Yes" << std::endl;
            return 0;
        }
    }
    std::cout << "No" << std::endl;
}


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


int main() {
  long long  h,w; cin >> h >> w;
  int heven,weven; heven = 0; weven = 0;
  if(h%2 == 0){
    heven =1;
  }
  if(w%2==0){
    weven =1;
  }
  
  if(w==1||h==1){
    cout << 1 << endl;
  }
  else if(weven == 1||heven==1){
    cout << h*w /2 << endl;
  }
  else{
    cout << (h*w + 1)/2 << endl;
  }
}

Measured memory_bytes: 256
<?php

list($n, $q) = explode(' ', trim(fgets(STDIN)));
$s = trim(fgets(STDIN));
$e = strlen($s);
$a = [0];
for ($i = 1; $i < $e; $i++) {
    $a[$i] = $a[$i - 1] + ($s[$i - 1] === 'A' && $s[$i] === 'C' ? 1 : 0);
}
while (false !== $lr = fgets(STDIN)) {
    list($l, $r) = explode(' ', trim($lr));
    printf("%s\n", $a[$r - 1] - $a[$l - 1]);
}


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

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;	
}

int main() {
	ll x; cin >> x;
	ll money = 100LL;
	ll ans = 0;
	while(money<x){
		money = ll (money*1.01);
		ans++;
	}

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

Measured memory_bytes: 3644
program main
      implicit none
      integer :: n, i, cnt
      character(50) :: s

      read *, n
      read *, s

      cnt = 0
      do i = 1, n
        if( s(i:i) == 'A' ) then
          if( s(i+1:i+1) == 'B' ) then
            if ( s(i+2:i+2) == 'C' ) then
              cnt = cnt + 1
            else
            end if
          else
          end if
        end if
      end do
      print *, cnt

end program main


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

#define FORu(i, start, n) for (ll i = start; i < (ll)(n); i++)
#define FORd(i, start, n) for (ll i = start; i > (ll)(n); i--)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

ll gcd(ll a, ll b) { //greatest common divisor
  if(b == 0)  return a;
  return gcd(b, a%b);
}
ll nCr(ll n, ll r) { // combinations
  ll C[r+1]; memset(C, 0, sizeof(C)); C[0] = 1;
  FORu(i,1,n+1){ 
    FORd(j,min(i,r),0){
      C[j] = C[j] + C[j-1];
    }
  }
  return C[r];
}
bool isPrime(ll n) {//check if prime
  if(n<=1) return false;
  if(n==2) return true;
  if(n%2==0) return false;
  ll m = sqrt(n);
  for (ll i=3; i<=m; i+=2) {
    if (n%i==0){
      return false;
    }
  }
  return true;
}

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

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n; cin >> n;
    if( n <= 999 ) cout << "ABC" << endl;
    else cout << "ABD" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int a, b, c;
	int i = 0;
	i = scanf("%d", &a);
	i = scanf("%d", &b);
	i = scanf("%d", &c);
        i = 0;
	if (a == b)i++;
	if (b == c)i++;
	if (c == a)i++;
	if(a == b&& b == c)i=2;
	
	printf("%d", 3-i);
	return 0;

}


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

int main()
{
ll n , m ;
cin >> n >> m ;
vector<vector<ll>> v(100000);
priority_queue<ll> q;
rep(i,n){
  ll a , b ;
  cin >> a >> b ;
  v[a].push_back(b);
}
rep(i,m+1){
  rep(j,v[i].size()){
    q.push(v[i][j]);
  }
  if(q.size()>0){
    ll te=q.top();
    ans+=te;
    q.pop();
  }
}

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


Measured memory_bytes: 5632
import java.util.*;
import java.util.Map.Entry;
 

public class Main{
	
	
	
	
	public static long answer = 0;
	public static long MOD=1000000007;
	
	
	

	

 
	
	//最大公約数・最小公倍数（セットで使う）
	public static long gcm(long a, long b) {
		long result = a;
		long k = 0;
		long n = b;
		do {
			k = result % n;
			result = n;
			n = k;
		} while(k != 0);
		return result;
	}
	
	public static long lcm(long a, long b) {
		long g;
		g = gcm(a, b);
		return a/g*b;
	}
	
	static long gcd(long a, long b) {
		if (b == 0) {
			return a;			
		}
		return gcd(b, a % b);
	}
	
	//等差数列
	static long tousasum(int n) {
		return (long)n*((long)n+1)/2;
	}
 
 
 
	//素数判定
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2) if(n%i==0){return false;}
		return true;
	}
 
 
	//倍数判定（10進数以外のときに有用）
	static boolean isMultiple (String s, int base, int m) {
		int temp = 0;
		for (int i=0; i<s.length(); i++) {
			temp = (temp*base+Character.getNumericValue(s.charAt(i)))%m;
		}
		if (temp==0) {return true;}
		return false;
	}
 
 
	//階乗
	static long factorial (int k) {
		long sum = 1;
		for(int i=1;i<=k;i++) {
			sum = (sum*i)%MOD;
		}
		return sum;
		
	}
 
 
	//進数変換
	static String toNbase (String sm, int m, int n) {
		return Long.toString(Long.parseLong(sm,m),n);
	}
	
	public static final long gcd_n(long[] param) {
	    final int len = param.length;
	    long g = gcd(param[0], param[1]);    //gcd(a, b) は以前作ったもの
	    for (int i = 1; i < len - 1; i++) {
	        g = gcd(g, param[i + 1]);       //gcd(a, b) は以前作ったもの
	    }
	    return g;
	}
	
	public static long lcm_n(long[] numbers) {
		long l;
		l = numbers[0];
		for (int i = 1; i < numbers.length; i++) {
			l = lcm(l, numbers[i]);
		}
		return l;
	}
	
	
    
	
	
 public static void main(String[] args) {
	 
	 Scanner sc=new Scanner(System.in);
	 int N=sc.nextInt();
	 char[] s=sc.next().toCharArray();
	 if(N%2!=0) {
		 System.out.println("No");
	 }else {
		 boolean flag = true;
		 for(int i=0;i<N/2;i++) {
			 if(s[i]!=s[i+N/2]) {
				 flag = false;
			 }
			
		 }
		 
		 if(flag) {
			 System.out.println("Yes");
		 }else {
			 System.out.println("No");
		 }
	 }
	 
	 
	 

	 
	 
	
}
 
 
}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int h,w,n;cin >> h >> w >> n;
  int count = 0;
  if(h>=w){
    for(int i = 1;i<=w;i++){
      if(h*i>=n){
        cout << i << endl;
        break;
      }
      else{
        continue;
      }
    }
  }
    else{
      for(int i = 1;i<=h;i++){
       if(w*i>=n){
         cout << i << endl;
         break;
       }
       else{
         continue;
       }
      }
    }
  }
      
      
  
    

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


ll GCD(ll x, ll y) {
	if(y == 0) return x;
	else return GCD(y, x % y);
}


int main() {
	int n; cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];

	vector<ll> l(n+1, 0), r(n+1, 0);

	rep(i, n) l[i+1] = GCD(l[i], a[i]);
	for(int i=n-1; i>=0; i--) r[i] = GCD(r[i+1], a[i]);

	ll res = -1;
	rep(i, n) {
		ll can;
		can = GCD(l[i], r[i+1]);
		if(can > res) res = can;
	}

	cout << res << endl;
}


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

int main()
{
    int X, Y, A, B, C, a = 0, b = 0, c = 1;
    long long sum = 0;
    bool a_ = true, b_ = true;
    cin >> X >> Y >> A >> B >> C;

    vector<int> p(A), q(B), r(C);

    rep(i, A)
    {
        cin >> p.at(i);
    }
    rep(i, B)
    {
        cin >> q.at(i);
    }
    rep(i, C)
    {
        cin >> r.at(i);
    }

    sort(p.begin(), p.end());
    sort(q.begin(), q.end());
    sort(r.begin(), r.end());

    rep(i, C)
    {
        if (C - c >= 0)
        {
            if (p.at(A - X + a) > q.at(B - Y + b)&& b_ == true)
            {
                if (q.at(B - Y + b) < r.at(C - c))
                {
                    q.at(B - Y + b) = r.at(C - c);
                    b++;
                    c++;
                    if (B - Y + b == B)
                    {
                        b--;
                        b_ = false;
                    }
                }
            }
            else if (p.at(A - X + a) <= q.at(B - Y + b)&&a_ == true)
            {
                if (p.at(A - X + a) < r.at(C - c))
                {
                    p.at(A - X + a) = r.at(C - c);
                    a++;
                    c++;
                    if (A - X + a == A)
                    {
                        a--;
                        a_ = false;
                    }
                }
            }
        }
    }

    rep(i, X)
    {
        sum += p.at(A - i - 1);
    }

    rep(i, Y)
    {
        sum += q.at(B - i - 1);
    }

    cout << sum << endl;
}


Measured memory_bytes: 1408
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<cstring>
using namespace std;
int l;
string a;
int main()
{
    cin>>a;
    l=a.size();
    for(register int i=0;i<l;i++)
    {
        if(a[i]=='C')
        {
            for(register int j=i;j<l;j++) if(a[j]=='F')
            {
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD=1000000007;

int main() {
  ll N,M,X,ans;
  ll A=0,b=0;
  cin>>N>>M>>X;
  ll a[M];
  for(ll i=0;i<M;i++){
    cin>>a[i];
  }
  for(ll i=0;i<M;i++){
    
    if(a[i]>X){
      A++;
    }
    else{
      b++;
    }
    //cout<<min(a,b);
  }
  cout<<min(A,b);
}

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

typedef long long ll;

int main(){
  cout<<fixed<<setprecision(12);
  ll n;
  while(cin>>n && n){
  vector<vector<double>> dp(1000,vector<double>(1000,0));
  double ans=0;
  dp[n/2][0]=1;
  for(ll i=n/2;i>0;i--){
    for(ll t=0;t<=i;t++){
      double k=dp[i][t];
      if(k==0){continue;}
      ll A=i*2-t;
      k*=t;
      k/=A;
      dp[i-1][t-1]+=k;
      k=dp[i][t]-k;
      if(k==0){continue;}
      A--;
      dp[i-1][t]+=k/A;
      k-=k/A;
      if(k==0){continue;}
      double d;
      d=k*(i*2-t*2-2)/(i*2-t-2);
      ans+=d;
      dp[i][t+2]+=d;
      d=k*t/(i*2-t-2);
      ans+=d;
      dp[i-1][t]+=d;
    }
  }
  cout<<ans<<endl;
  }




  return 0;
}



Measured memory_bytes: 10832
fun main(args: Array<String>) {
    val (H, W) = readInputLine().split(" ").map { it.toLong() }

    if (H == 1L || W == 1L) {
        println(1)
        return
    }

    println(((W + 1L) / 2L) * ((H + 1L) / 2L) + (W / 2L) * (H / 2L))
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 37876
/**
*    author:  yuya1234
*    created: 05.07.2020 22:20:09
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define ALL(x) x.begin(),x.end()
#define SORT(x) sort(x.begin(),x.end())
#define SORTD(x) sort(x.rbegin(),x.rend())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define SZ(x) ll(x.size())

#define MEMSET(v, h) memset((v), h, sizeof(v))

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

  int n;
  cin>>n;

  vector<ll> v;
  ll tmp;
  REP(i,n)
  {
    cin>>tmp;
    v.push_back(tmp);
  }

  SORTD(v);
  ll ans=v[0],a=1,cnt=0;
  REP(i,n-2)
  {
    ans+=v[a];
    cnt++;
    if(cnt%2==0)a++;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 5328
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	LL k;
	cin >> k;

	LL n = 50;
	vector<LL> v(n, n - 1 + k / n);
	LL t = k % n;
	for(int i = 0; i < n; ++i){
		v[i] += i < t ? n - (t - 1) : -t;
	}
	cout << n << '\n';
	for(int i = 0; i < n; ++i){
		cout << v[i] << (i + 1 == n ? '\n' : ' ');
	}
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


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

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> w(n);
	int sum=0;
	for(int i=0;i<n;i++)
	{
		cin >> w[i];
		sum+=w[i];
	}
	int s=0;
	int dis=100000000;
	for(int i=0;i<n;i++)
	{
		s+=w[i];
		if(dis>(abs((sum-s)-s)))dis=abs((sum-s)-s);
	}
	cout << dis << endl;


	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxN = 100200;
int mem[maxN];
vector<int> nums(maxN);
int solve(int i,int n,int k){
	if(i == n - 1){
		return 0;
	}
	if(mem[i] != -1){
		return mem[i];
	}
	int res = 2000000000;
	for(int j = i + 1; j <= i + k; j++){
		if(j < n){
			res = min(res,abs(nums[i] - nums[j]) + solve(j,n,k));
		}
	}
	return mem[i] = res;
}
int main(){
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,k;
    cin >> n >> k;
    for(int i = 0;i < n ;i++){
		cin >> nums[i];
	}
	memset(mem,-1,sizeof(mem));
    cout << solve(0,n,k) << "\n";
}


Measured memory_bytes: 11816
#include<iostream>
using namespace std;
 
int main()
{
int R0,W0,C,R;
while(true)
{
cin >> R0 >> W0 >> C >>R ;
if(R0 == 0) break;
double d = static_cast<double>(C*W0-R0)/R;
if(d>0&&(int)d==d)cout << (int)d << endl;
else if (d>0)cout << (int)d+1 << endl;
else cout << 0 << endl;
}
return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define MOD 998244353
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
int solve(int n) {
    int l = 0, r = 1000000001;
    while(r - l > 1) {
        int mid = (r + l) / 2;
        if(mid * mid > n)
            r = mid;
        else
            l = mid;
    }
    return l;
}
signed main(void) {
    int S;
    cin >> S;
    int x1, y1, x2, y2;
    x1 = solve(S);
    //cout << x1 << endl;
    if(S == x1 * x1) {
        y2 = x1;
        x2 = 0;
        y1 = 1;
    } else {
        if(S <= x1 * (x1 + 1)) {
            y2 = x1 + 1;
            x2 = x1 * y2 - S;
            y1 = 1;
        } else {
            x1++;
            y2 = x1;
            x2 = x1 * y2 - S;
            y1 = 1;
        }
    }
    cout << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << ' ' << 0 << ' ' << 0 << endl;
}


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

int main() {
	int N, b, f, r, v;
	int A[4][3][10] = {};
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> b >> f >> r >> v;
		A[b - 1][f - 1][r - 1] += v;
	}
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 10; k++) {
				cout << " " << A[i][j][k];
			}
			cout << endl;
		}
		if (i != 3) {
			for (int l = 0; l < 20; l++) {
				cout << '#';
			}
			cout << endl;
		}
	}
}


Measured memory_bytes: 3104
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
wsv = [None]*n
for i in range(n):
    wsv[i] = tuple(map(int, input().split()))
wsv.sort(key=lambda x: x[0]+x[1])
ms = max(item[1] for item in wsv) + max(item[0] for item in wsv)
dp = [[0]*(ms+1) for _ in range(n+1)]
for i in range(1, n+1):
    w,s,v = wsv[i-1]
    for j in range(1, ms+1):
        dp[i][j] = dp[i-1][j]
        if j>=w and s>=j-w:
            dp[i][j] = max(dp[i][j], dp[i-1][j-w] + v)
ans = max(dp[n][w] for w in range(ms+1))
print(ans)

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
typedef pair<int,int> P;

//-----------------------------------------------------------------------

bool isSquare[50000];
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    while(cin>>n,n)
    {
        int cnt=0;
        for(int a=1;a*a<=n;a++){
            isSquare[a*a]=true;
            if(a*a==n) cnt++;
        }
        for(int a=1;a*a<n;a++){
            if(isSquare[n-a*a] && n-a*a>=a*a) cnt++;
        }
        for(int a=1;a*a<n;a++) for(int b=a;a*a+b*b<n;b++){
            if(isSquare[n-a*a-b*b] && n-a*a-b*b>=b*b) cnt++;
        }
        for(int a=1;a*a<n;a++) for(int b=a;a*a+b*b<n;b++){ 
            for(int c=b;a*a+b*b+c*c<n;c++){
                if(isSquare[n-a*a-b*b-c*c] && n-a*a-b*b-c*c>=c*c) cnt++;
            }
        }
        cout<<cnt<<endl;
    }
}


Measured memory_bytes: 3164
#include<stdio.h>
#include<math.h>
#define pie 3.1415926535897

 void kock(int n,double p1x,double p1y,double p2x,double p2y){
         double sx,sy,tx,ty,ux,uy;
         if(n==0)return 0;
         sx=(p1x*2+p2x)/3;
         tx=(p1x+p2x*2)/3;
         sy=(p1y*2+p2y)/3;
         ty=(p1y+p2y*2)/3;
         ux=(tx-sx)*cos(pie*60/180)-(ty-sy)*sin(pie*60/180)+sx;
         uy=(tx-sx)*sin(pie*60/180)+(ty-sy)*cos(pie*60/180)+sy;

         kock(n-1,p1x,p1y,sx,sy);
         printf("%lf %lf\n",sx,sy);
         kock(n-1,sx,sy,ux,uy);
         printf("%lf %lf\n",ux,uy);
         kock(n-1,ux,uy,tx,ty);
         printf("%lf %lf\n",tx,ty);
         kock(n-1,tx,ty,p2x,p2y);
         }

 int main(){
        int n;
        double p1x=0.0,p2x=100.0,p1y=0.0,p2y=0.0;
        scanf("%d",&n);
        printf("%lf %lf\n",p1x,p1y);
        kock(n,p1x,p1y,p2x,p2y);
        printf("%lf %lf\n",p2x,p2y);
        return 0;
        }



Measured memory_bytes: 2064