akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<set>

using namespace std;

typedef unsigned long long ull;

void input(bool *p,int n){
  int m=(n+5)/6;
  while(m--){
    char c;
    cin>>c;
    int v=
      ('A'<=c&&c<='Z')?c-'A':
      ('a'<=c&&c<='z')?c-'a'+26:
      ('0'<=c&&c<='9')?c-'0'+52:
      (c=='+')?62:63;
    for(int i=5;i>=0;i--){
      *p++=v>>i&1;
    }
  }
}

int main(){
  const ull B1=9973;
  const ull B2=100000007;
  for(int w,h,p;cin>>w>>h>>p,w;){
    static bool image[1000][1000];
    for(int i=0;i<h;i++){
      input(image[i],w);
    }
    bool pattern[100][100];
    for(int i=0;i<p;i++){
      input(pattern[i],p);
    }
    if(w<p||h<p){
      cout<<0<<endl;
    }else{
      set<ull> ph;
      for(int i=0;i<2;i++){
	for(int j=0;j<p;j++){
	  reverse(pattern[j],pattern[j]+p);
	}
	for(int k=0;k<4;k++){
	  bool tmp[100][100];
	  for(int l=0;l<p;l++){
	    for(int m=0;m<p;m++){
	      tmp[l][m]=pattern[m][p-1-l];
	    }
	  }
	  copy(tmp[0],tmp[p],pattern[0]);
	  ull hh[100]={};
	  for(int l=0;l<p;l++){
	    for(int m=0;m<p;m++){
	      hh[l]=hh[l]*B1+pattern[l][m];
	    }
	  }
	  ull e=0;
	  for(int l=0;l<p;l++){
	    e=e*B2+hh[l];
	  }
	  ph.insert(e);
	}
      }
      ull pob1=1,pob2=1;
      for(int i=0;i<p;i++){
	pob1*=B1;
	pob2*=B2;
      }
      static ull ihh[1000][1000];
      for(int i=0;i<h;i++){
	ull e=0;
	for(int j=0;j<w;j++){
	  e=e*B1+image[i][j]-((j-p>=0)?image[i][j-p]*pob1:0);
	  ihh[i][j]=e;
	}
      }
      int ans=0;
      for(int i=p-1;i<w;i++){
	ull e=0;
	for(int j=0;j<h;j++){
	  e=e*B2+ihh[j][i]-((j<p)?0:ihh[j-p][i]*pob2);
	  if(j>=p-1){
	    ans+=ph.count(e);
	  }
	}
      }
      cout<<ans<<endl;
    }
  }
}

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

using namespace std;

constexpr int64_t modulo = UINT64_C(1000000007);

struct sq_facts_t {
  constexpr sq_facts_t() : facts() {
    int64_t fact = 1;
    facts[1] = fact;
    for (int i = 2; i < 100001; i++) {
      fact *= i;
      fact %= modulo;
      fact *= i;
      fact %= modulo;
      facts[i] = fact;
    }
  }
  int64_t facts[100001];
};
static constexpr sq_facts_t sqFacts{};

int64_t solve(int n, int m) {
  if (n < m) {
    std::swap(n, m);
  }
  if (n - m >= 2) {
    return 0;
  }
  int64_t ret = sqFacts.facts[m];
  if (n == m) {
    ret *= 2;
  } else {
    ret *= n;
  }
  ret %= modulo;
  return ret;
}

int main() {
  int n, m;
  std::cin >> n >> m;
  std::cout << solve(n, m) << std::endl;
  return 0;
}


Measured memory_bytes: 256
from math import sqrt
from typing import Tuple


def dist(p: Tuple[float, float], q: Tuple[float, float]) -> float:
    return sqrt((p[0] - q[0]) ** 2 + (p[1] - q[1]) ** 2)


if __name__ == "__main__":
    c1x, c1y, c1r = map(lambda x: float(x), input().split())
    c2x, c2y, c2r = map(lambda x: float(x), input().split())
    if c2r < c1r:
        c1x, c1y, c1r, c2x, c2y, c2r = c2x, c2y, c2r, c1x, c1y, c1r

    center_dist = dist((c1x, c1y), (c2x, c2y))
    if (c1r + c2r) < center_dist:
        print(4)
    elif (c1r + c2r) == center_dist:
        print(3)
    elif center_dist < (c1r + c2r) and (c2r - c1r) < center_dist:
        print(2)
    elif center_dist == (c2r - c1r):
        print(1)
    else:
        print(0)



Measured memory_bytes: 7248
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
double a,b,x;
int main()
{
    // freopen("in.txt","r",stdin);
    cin>>a>>b>>x;
    double ans;
    // DEBUG(atan(1)/acos(-1)*180);
    if(2*x<=a*a*b){
        ans=atan(2*x/a/b/b)/(acos(-1))*180;
        ans=90-ans;
    }
    else {
        ans=atan((2*a*a*b-2*x)/(a*a*a))/acos(-1)*180;
    }
    cout<<fixed<<setprecision(10)<<ans;
}

Measured memory_bytes: 512
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <regex>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
using ll = long long;
using VL=vector<ll>;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
const long long INF =  999999999;

ll N,M,c[100010];

ll gcm(ll a, ll b) {
	ll result = a;
	ll k = 0;
	ll n = b;
	do {
		k = result % n;
		result = n;
		n = k;
	} while(k != 0);
	return result;
}

ll lcm(ll a, ll b) {
	ll g;
	g = gcm(a, b);
	return a*b/g;
}

int main(){
  cin>>N>>M;
  REP(i,N)cin>>c[i],c[i]=c[i]/2;
  bool flag=false;
  ll g=c[0];
  FOR(i,1,N){
    g=lcm(g,c[i]);
  }
  REP(i,N){
    if((g/c[i])%2==0){
      flag=true;break;
    }
  }

  if(flag)cout<<0<<endl;
  else cout<<(M/g+1)/2<<endl;

}


Measured memory_bytes: 1024
# include <bits/stdc++.h>
using namespace std;
# define lli long long int
# define MOD 1000000007
# define INF 10000000000009


void solve(){
    lli n;
    cin >> n;

    lli arr[n];
    lli pref[n];
    for(lli i = 0; i < n; i++){
        cin >> arr[i];
        pref[i] = (i == 0 ? arr[i] : pref[i - 1] + arr[i]);
    }

    lli dp[n][n];
    memset(dp, 0, sizeof(dp));

    for(lli i = 1; i < n; i++){
        lli r = 0, c = i;
        while(c < n){
            lli minVal = INF;
            for(lli k = r; k < c; k++){
                minVal = min(minVal, dp[r][k] + dp[k + 1][c] + (r == 0 ? pref[c] : pref[c] - pref[r - 1]));
            }
            dp[r][c] = minVal;
            r++, c++;
        }
    }

    cout << dp[0][n - 1];


}


int main(){
    int t;
    t = 1;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 4824
#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod = 1e9 + 7;
int INF = 2e18;
 
signed main() {
    string S, T;
    cin >> S >> T;
    int ans = 0;
    for (int i = 0; i < 3; i++) {
        if (T[i] == S[i]) ++ans;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
N = input()
L = N.split()
a = int(L[0])
b = int(L[1])

if a < b:
    c = a
    a = b
    b = c

r = a % b
    
while r != 0:
    a = b
    b = r
    r = a % b

# この時のbが最大公約数

print(int(int(L[0])*int(L[1])/b))

Measured memory_bytes: 3064
from sys import stdin
from itertools import accumulate
q = int(stdin.readline().rstrip())
l_r = [list(map(int,stdin.readline().rstrip().split())) for _ in range(q)]
max_n = 0
for s in l_r:
    max_n = max(s[1], max_n)
# print(max_n)
# print(l_r)
# b : isPrime
b = [1] * (max_n+1)
b[0] = 0
b[1] = 0
# エラトステネスのふるい
for i in range(2,max_n+1):
    if b[i]:
        j = i*2
        while j <= max_n:
            b[j] = 0
            j += i
# print(b)
c = [1 if x == 1 and b[int((i+1)/2)] == 1 else 0 for i,x in enumerate(b)] 
# print(c)
s = list(accumulate(c))
# print(len(s))

for i in range(q):
    print(s[l_r[i][1]]-s[l_r[i][0]-1])

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

int main(){
	int n,x,m;
	int small=1001;

	cin >>n >>x;
	for(int i=0;i<n;i++){
		cin >>m;
		x-=m;
		if(small>m)small=m;
	}
	cout<<n+x/small<<endl;
	return 0;

}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

    int N = 0;
    int M = 0;
    int count = 0;
    int check = 0;
    double sikii = 0;
    scanf("%d %d", &N, &M);
    int A[N]; 

    check = N;

    for (int i = 0; i < N; i++){
        scanf("%d", &A[i]);
        count = count + A[i];
    }
    sikii = (double)count / (double)(4 * M);

    for (int j = 0; j < N; j++){
        if ((double)A[j] < sikii){
            check--;
        }
    }

    if (M > check){
        printf("No\n");
    } else {
        printf("Yes\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(){
	string s;
	cin >> s;
	for(int i=0 ; i<s.size() ; ++i){
		if(s[i]=='B'){
			if(i==0){
				s.erase(0,1);
				--i;
			} else {
			s.erase(i-1,2);
			i-=2;
			}
		}
	}
	cout << s << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
#define int long long
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF (long long)(1e18)
#define MOD (int)(1e9+7)
#define yn(f) (f?"Yes":"No")
#define YN(f) (f?"YES":"NO")
#define MAX_N 1
#define MAX_V 1

signed main(){
	int N, M, ans = 1;
	
	cin>>N>>M;
	
	for(int i = 2; i * i <= M; i++){
		if(M%i == 0){
			if(i*N <= M) ans = max(ans,i);
			if((M/i)*N <= M) ans = max(ans,M/i);
		}
	}
	
	if(N != 1)cout<<ans<<endl;
	else cout<<M<<endl;
	
	
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> L(N);
  for (int i = 0; i < N; ++i)
    cin >> L[i];
  sort(L.begin(), L.end());
  long long ans = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      int k = lower_bound(L.begin(), L.end(), L[i] + L[j]) - L.begin();
      ans += max(k - j - 1, 0);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long int
#define M 1000000007
#define pb push_back
#define pf push_front
#define ulli unsigned long long int
#define what_is(x) cerr << #x << " is " << x << endl;
#define pi 2*acos(0.0)
#define F  first
#define S  second
#define endl '\n'
using namespace std;
using namespace __gnu_pbds;
const int INF = 1e18L+5;
const int LG = 20;
const int N = 1e5+9;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int power(int x,int y){int res=1;while(y>0){if(y%2==1)res=(res*x)%M;x=(x*x)%M;y=y/2;}return res;}
bool isvowel(char c){if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u' || c=='A' || c=='E' || c=='I' || c=='O' || c=='U')return true;return false;}
int32_t main()
{
	//cout.precision(15);
	//cout.setf(ios::fixed,ios::floatfield);
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int T=1;
	//cin>>T;
	while(T--)
	{
		int a,b,c,d,x,y;
		cin>>a>>b>>c>>d;
		x=ceil((float)a/d);
		y=ceil((float)c/b);
		if(x>=y)
		cout<<"Yes"<<endl;
		else
		cout<<"No"<<endl;
	}
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const ull B=1e9+7;
ull Hash(vector<int> v){
  ull h=0;
  for(int i=0;i<26;i++)h=h*B+v[i];
  return h;
}

int main(){
  string a,b;
  cin>>a>>b;
  int ans=0,n=a.size(),m=b.size();
  
  for(int i=1;i<=n;i++){
    unordered_set<ull> S;
    vector<int> v(26,0);
    for(int j=0;j<n;j++){
      if(i==j)S.insert(Hash(v));
      v[a[j]-'a']++;
      if(j>=i) {
	v[a[j-i]-'a']--;
	S.insert(Hash(v));
      }
    }
    S.insert(Hash(v));
    v=vector<int>(26,0);
    for(int j=0;j<m;j++){
      if(i==j&&S.count(Hash(v)))ans=i;
      v[b[j]-'a']++;
      if(j>=i){
	v[b[j-i]-'a']--;
	if(S.count(Hash(v)))ans=i;
      }    
    }
    if(S.count(Hash(v)))ans=i;
  }
  cout <<ans<<endl;
  return 0;
}

Measured memory_bytes: 3272
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_set>
#include <bitset>
#include <time.h>
#include <limits.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) (int)x.size()
#define sz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
typedef tuple<int, int, int> t3;

const ll mod = 998244353;
char X[2020];
ll dp[4020][4020];
int sa[4040], sb[4040];

int main() {
	scanf("%s", X + 1);
	int N = (int)strlen(X + 1);
	for(int i=1;i<=N;i++) sa[i] = sa[i-1] + (X[i] - '0');
	for(int i=1;i<=N;i++) sb[i] = sb[i-1] + 2 - (X[i] - '0');
	dp[0][0] = 1;
	for(int a=0;a<=sa[N];a++) for(int b=0;b<=sb[N];b++) {
		if(a < sa[N] && (a+b >= N || sa[a+b+1] >= a+1)) dp[a+1][b] = (dp[a+1][b] + dp[a][b]) % mod;
		if(b < sb[N] && (a+b >= N || sb[a+b+1] >= b+1)) dp[a][b+1] = (dp[a][b+1] + dp[a][b]) % mod;
	}
	printf("%lld\n", dp[sa[N]][sb[N]]);
	
	return 0;
}


Measured memory_bytes: 123520
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)
#define FOR(i, m, n) for(int i = (m); i < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;
typedef long long ll;
template <class T>
inline bool chmin(T& a, T b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  int h, w;
  char input;
  cin >> h >> w;

  int mat[h][w];
  int dp[h][w];

  // 初期状態入力(白:0, 黒:1)
  REP(i, h) {
    REP(j, w) {
      cin >> input;
      if(input == '.')
        mat[i][j] = 0;
      else
        mat[i][j] = 1;
    }
  }

  int sum = 0;
  REP(i, h) { REP(j, w) sum += mat[i + 1][j + 1]; }

  // 全部白の場合は0
  if(sum == h * w) {
    cout << 0 << endl;
    return 0;
  }
  // 全部黒の場合は1
  if(sum == 0) {
    cout << 1 << endl;
    return 0;
  }

  // DPテーブルの1行目を初期化
  if(mat[0][0] == 1) {
    dp[0][0] = 1;
  } else {
    dp[0][0] = 0;
  }
  REP(i, w - 1) {
    if(mat[0][i + 1] == 0) {
      // 白の場合
      dp[0][i + 1] = dp[0][i];
    } else {
      // 黒の場合
      if(mat[0][i] == 1) {
        // 左も黒なら同じ
        dp[0][i + 1] = dp[0][i];
      } else {
        // 左が白なら左隣+1
        dp[0][i + 1] = dp[0][i] + 1;
      }
    }
  }

  // DPテーブルの1列目を初期化
  REP(i, h - 1) {
    if(mat[i + 1][0] == 0) {
      // 白の場合
      dp[i + 1][0] = dp[i][0];
    } else {
      // 黒の場合
      if(mat[i][0] == 1) {
        // 上も黒なら同じ
        dp[i + 1][0] = dp[i][0];
      } else {
        // 上が白なら上+1
        dp[i + 1][0] = dp[i][0] + 1;
      }
    }
  }
  // DPテーブル更新
  REP(i, h - 1) {
    REP(j, w - 1) {
      int left, up;
      // 上から来るパターン
      if(mat[i][j + 1] == 1) {
        // 上が黒の場合は上と同じ
        up = dp[i][j + 1];
      } else {
        // 上が白の場合
        if(mat[i + 1][j + 1] == 1) {
          // 現在地が黒の場合
          up = dp[i][j + 1] + 1;
        } else {
          // 現在地が白の場合
          up = dp[i][j + 1];
        }
      }

      // 左から来るパターン
      if(mat[i + 1][j] == 1) {
        // 左が黒の場合は左と同じ
        left = dp[i + 1][j];
      } else {
        // 左が白の場合
        if(mat[i + 1][j + 1] == 1) {
          // 現在地が黒の場合
          left = dp[i + 1][j] + 1;
        } else {
          // 現在地が白の場合
          left = dp[i + 1][j];
        }
      }

      dp[i + 1][j + 1] = min(left, up);
    }
  }

  cout << dp[h - 1][w - 1] << endl;

  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60

int A[8][8]; // A[i][j] : 1回の操作でi番目からj番目に移れるようなあみだくじの個数

void decA(int w) {
	int n = 1; for (int i = 0; i < w - 1; i++) n *= 2;
	for (int i = 0; i < n; i++) {
		int tmp = i;
		vector<bool> V; // V[i] : i番目のひもと(i+1)番目のひもの間に橋があるかどうか
		for (int j = 0; j < w - 1; j++) {
			V.push_back((tmp & 1));
			tmp = tmp >> 1;
		}

		// 橋が連続してないかチェック
		bool flag = true;
		for (int i = 0; i < V.size()-1 && flag; i++) {
			if (V[i] && V[i + 1]) flag = false;
		}

		if (flag) {
			if (V[0]) A[0][1]++;
			else A[0][0]++;
			for (int j = 1; j < w-1; j++) {
				if (V[j - 1]) A[j][j - 1]++;
				else if (V[j]) A[j][j + 1]++;
				else A[j][j]++;
			}
			if (V[w - 2]) A[w - 1][w - 2]++;
			else A[w - 1][w - 1]++;
		}
	}

	// 確認
	/*
	for (int i = 0; i < w; i++) {
		cout << i << "からの移動  : ";
		for (int j = 0; j < w; j++) cout << A[i][j] << " ";
		cout << endl;
	}
	*/
}

ll before[8];
ll after[8];

void onestep(int w){
	for (int i = 0; i < w; i++) after[i] = 0LL;
	for (int i = 0; i < w; i++) {
		for (int j = 0; j < w; j++) {
			after[i] += before[j] * A[j][i];
			after[i] %= MOD;
		}
	}
	for (int i = 0; i < w; i++) before[i] = after[i];
}

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

	int H, W, K; cin >> H >> W >> K;
	
	if (W == 1) cout << 1 << endl;
	else {
		decA(W);

		before[0] = 1;
		for (int i = 1; i < W; i++) before[i] = 0;

		for (int i = 0; i < H; i++) onestep(W);
		cout << before[K - 1] << endl;
	}

	return 0;
}

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

int main(){
    int n; cin >> n;
    int act[n+1][3];
    for(int i=1;i<=n;i++) 
        for(int j=0;j<3;j++)
            cin >> act[i][j];

    int dp[n+1][3];
    for(int i=0;i<=n;i++)fill(dp[i], dp[i]+3, 0);

    for(int i=1;i<=n;i++){
        dp[i][0] = act[i][0] + max(dp[i-1][1], dp[i-1][2]);
        dp[i][1] = act[i][1] + max(dp[i-1][0], dp[i-1][2]);
        dp[i][2] = act[i][2] + max(dp[i-1][0], dp[i-1][1]);
    }
    
    cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl;
}

Measured memory_bytes: 5524
#include <stdio.h>
#include<math.h>
using namespace std;



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

	while(true){
		scanf("%d",&n);
		if(n == 0)break;
		A = B = 0;
		for(int i=0;i < n; i++){
			scanf("%d %d",&a,&b);
			if(a > b){
				A += (a+b);
			}else if(a < b){
				B += (a+b);
			}else{
				A += a;
				B += b;
			}
		}

		printf("%d %d\n",A,B);
	}

    return 0;
}

Measured memory_bytes: 2708
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

MOD = 10 ** 9 + 7

N = int(input())
A,B = [[int(input()) for _ in range(N)] for _ in [0,1]]

AB = [(x,0) for x in A] + [(x,1) for x in B]
AB.sort()

a = 0
b = 0
answer = 1
for x,i in AB:
    if i == 0:
        if b == 0:
            a += 1
            continue
        answer *= b
        b -= 1
    else:
        if a == 0:
            b += 1
            continue
        answer *= a
        a -= 1
    answer %= MOD

print(answer)

Measured memory_bytes: 26796
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n,i,sum=0;
    cin>>n;
    ll arr[n+5],b[n];
    for(i=0;i<=n;i++)
        cin>>arr[i];
    for(i=0;i<n;i++)
        cin>>b[i];
    for(i=0;i<n;i++){
        if(b[i]>arr[i]){
            b[i]-=arr[i];
            sum+=arr[i];
            arr[i]=0;
            if(b[i]>arr[i+1]){
                b[i]-=arr[i+1];
                sum+=arr[i+1];
                arr[i+1]=0;
            }
            else{
                arr[i+1]-=b[i];
                sum+=b[i];
            }
        }
        else{
            arr[i]-=b[i];
            sum+=b[i];
        }
    }
    cout<<sum<<endl;
    return 0;
}


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

using namespace std;

int N;
vector<double> Coordinate, Radius;

bool judge(double y) {
	double minX, maxX, d;

	y *= y;
	minX = 0;
	maxX = 1e12;
	for (int i = 0; i < N; ++i) {
		d = sqrt(Radius[i] * Radius[i] - y);
		minX = max(minX, Coordinate[i] - d);
		maxX = min(maxX, Coordinate[i] + d);
	}

	return minX <= maxX;
}

void solve() {
	double left, right, mid;

	left = 0;
	right = *min_element(Radius.begin(), Radius.end());
	while (true) {	//while (left < right) {
		if (abs(left - right) < 0.00001) {
			break;
		}
		mid = (left + right) / 2;
		(judge(mid) ? left : right) = mid;
	}
	cout << fixed << setprecision(3) << left << endl;
}

int main() {
	double x, r;

	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> x >> r;
		Coordinate.push_back(x);
		Radius.push_back(r);
	}
	solve();
	
	return 0;
}


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

using namespace std;
typedef long long int l;
#define mod 1000000007
#define t1 l t; cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define vl vector<l>
#define pb push_back
#define ub upper_bound
#define lb lower_bound

int main() {
fast;
l n,m,k;
cin>>n>>m>>k;
l a=n/m;
a=a*k;
if(n%m!=0)
a=a+k;
cout<<a<<"\n";


	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main(void){
    double a, b;
    std::cin >> a >> b;
    double result = (a + b) / 2;
    
    std::cout << std::setprecision(10);
    if (std::ceil(result) == result) {
        std::cout << result << std::endl;
    } else {
        std::cout << "IMPOSSIBLE" << std::endl;
    }
}


Measured memory_bytes: 3788
/* 	* In the name of GOD 
	* Thanks God */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second
#define int long long

int32_t main(){
	int l, r;
	cin >> l >> r;
	if (r - l <= 10000){
		int mn = 100000000;
		for (int i = l; i <= r; i++){
			for (int j = i + 1; j <= r; j++){
				mn = min(mn, (i * j) % 2019);
			}
		}
		cout << mn;
	}else{
		cout << 0;
	}
}


Measured memory_bytes: 3596
N = STDIN.gets.to_i
aa = STDIN.gets.strip.split.map(&:to_i)

multiples = {
  0 => 0,
  2 => 0,
  4 => 0,
}

aa.each do |a|
  if a % 4 == 0
    multiples[4] += 1
  elsif a % 2 == 0
    multiples[2] += 1
  else
    multiples[0] += 1
  end
end

if multiples[2] == 0
  puts multiples[0]-1 <= multiples[4] ? "Yes" : "No"
else
  puts multiples[0] <= multiples[4] ? "Yes" : "No"
end

Measured memory_bytes: 9476
#include<bits/stdc++.h>
using namespace std;
#define intt long long int
#define intu unsigned long long int
#define vi vector<intt>
#define ii pair<int,int>
#define pb push_back
//#define mp make_pair
#define ff first
#define ss second
#define fast_io ios::sync_with_stdio(0);cin.tie(NULL);std::cout.tie(NULL);
# define PI           3.14159265358979323846 
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
int mod = 1000000007;
int gcd(int a, int b) {return b ? gcd(b, a % b) : a;}
int lcm(int a, int b) {return a * b / gcd(a, b); }
intt bpow(intt a,intt b) 
{
  intt res = 1;
  while (b > 0) {
    if (b & 1)res = res * a;
      a = a * a;
      b >>= 1;
  }
  return res;
}
intt fact(intt n) { 
   if ((n==0)||(n==1))
      return 1; 
   else
      return n*fact(n-1);
}

void go()
{
#ifndef ONLINE_JUDGE
  freopen("IN.txt","r",stdin);
  freopen("OUT.txt","w",stdout);
  #endif
}


int main(){
	go();
	fast_io

	intt d,t,s;cin>>d>>t>>s;
	if(s*t>=d){
		cout << "Yes" <<"\n";
	}
	else
		cout << "No" <<"\n";
}




















Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

int main(){
	string s;
	cin>>s;
	string t = "CODEFESTIVAL2016";
	int ans = 0;
	rep(i, t.size()){
		if(t[i] != s[i]) ans++;
	}
	cout<<ans<<endl;
}

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

int main(){
    ll n, m;
    cin >> n >> m;
    vector<ll> h(n);
    vector<int> a(m);
    vector<int> b(m);
    vector<bool> good(n, true);

    rep(i, n){
        cin >> h.at(i);
    }
    rep(i, m){
        cin >> a.at(i) >> b.at(i);
        a.at(i)--;
        b.at(i)--;
        if(h.at(a.at(i))>=h.at(b.at(i))){
            good[b[i]]=false;
        }
        if(h.at(a.at(i))<=h.at(b.at(i))){
            good[a[i]]=false;
        }
    }
    // rep(i, m){
    //     cout << min_high.at(i) << endl;
    // }
    int ans = 0;
    rep(i, n){
        if(good[i]){
            ans++;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 4780
#include <bits/stdc++.h>
#define maxn 100086

using namespace std;

int a, b, c, d;

int main(){
	scanf("%d%d%d%d", &a, &b, &c, &d);
	printf("%lld", max(1ll * a * c, max(1ll * a * d, max(1ll * b * c, 1ll * b * d))));
}

Measured memory_bytes: 3820
#include <iostream>
#include <algorithm>
#include <limits>
#include <vector>
#include <map>
#include <cmath>
#include <limits>
#define ll long long int
#define rep(i,n) for(int i = 0;i < n;i++)
#define pb push_back
#define mp make_pair

using namespace std;

int main(){

    int n;
    string s;
    cin >> n >> s;
    vector<int> vec(n);
    rep(i,n) vec[i] = s[i] - '0';
    bool i1 = true,j1 = false,k1 = false;
    ll ans = 0;

    for(int i = 0;i < 10;i++){
        for(int j = 0;j < 10;j++){
            for(int k =0;k<10;k++){
                i1 = true;
                j1 = false;
                k1 = false;
                for(int l = 0;l < n;l++){
                    if(i1 && vec[l] == i){
                        i1 = false;
                        j1 = true;
                    }
                    else if(j1 && vec[l] == j){
                        j1 = false;
                        k1 = true;
                    }
                    else if(k1 && vec[l] == k){
                        k1 = false;
                        ans++;
                        break;
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cctype>
#include<cstdio>
using namespace std;
int main(){
    char ch;
    int count[26] = {};
    while(cin >> ch){
        if(isalpha(ch)){
            count[tolower(ch) - 'a'] ++;
        }
    }
    for(int i = 0; i <= 25; i++){
        printf("%c : %d\n",i + 'a',count[i]);
    }
    return 0;
}


Measured memory_bytes: 3192
h, w = map(int, input().split())
a = [input() for _ in range(h)]
flag = True
def check(x, y):
    candidates = []
    if x > 0:
        candidates.append(a[x - 1][y])
    if x < h - 1:
        candidates.append(a[x + 1][y])
    if y > 0:
        candidates.append(a[x][y - 1])
    if y < w - 1:
        candidates.append(a[x][y + 1])
    if '#' in candidates:
        return True
    else:
        return False

for i in range(w):
    for j in range(h):
        if a[j][i] == '#':
            if check(j, i):
                pass
            else:
                flag = False
                break
print('Yes') if flag else print('No')

Measured memory_bytes: 3064
//B Power Socket

//

#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
using ll = long long;
#define range(a) (a).begin(),(a).end()


int main (){
    int A, B, Ans, i;cin >> A >> B;
    for(i=0;;){
        Ans = 1 + (A-1) * i;
        if(Ans>=B)break;
        i++;
    }
    cout << i << endl;
    return 0;
}

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

using namespace std;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    char c;
    int a = 0;
    int b = 0;
    vector <int> q(n);
    for (int i = 0; i<n; i++){
        cin >> c;
        if (c=='E') {
            a++;
            q[i] = 1;
        }
        else {
            b++;
            q[i] = 0;
        }
    }
    int x = 0;
    int y = 0;
    int xp = 0;
    int yp = 0;
    int ans = 1000000;
    for (int i=0; i<n; i++){
        if (q[i] == 1){
            x = a-xp-1;
            y = b-yp;
        }
        else{
            x=a-xp;
            y=b-yp-1;
        }
        if (ans>yp+x){
            ans = yp+x;
        }
        if (q[i] == 1){
            xp++;
        }
        else{
            yp++;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1408
(declaim (optimize (speed 3) (debug 0) (safety 0)))
(let ((k (read))
      (s (read)))

  (declare (type fixnum k))
  (declare (type fixnum s))

  (format t "~A~%"
          (loop for i from 0 to k
                sum (loop for j from 0 to k
                          count (and (>= (the fixnum (- s i j)) 0) (<= (the fixnum (- s i j)) k))))))


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

public class Main {

    public static void main(String[] args) throws IOException {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }
        String arr01[] = mylist.get(0).split(" ");
        String arr02[] = mylist.get(1).split(" ");
        String arr03[] = mylist.get(2).split(" ");
        String arr04[] = mylist.get(3).split(" ");

        String s = arr01[0];
        Integer n = Integer.valueOf(s);

        int mysum = 0;
        for (String v : arr03) {
            mysum += Integer.valueOf(v);

        }

        for (int i = 0; i < n - 1; i++) {

            int temp = Integer.valueOf(arr02[i]);

            if (temp + 1 == Integer.valueOf(arr02[i + 1])) {
                mysum += Integer.valueOf(arr04[temp - 1]);
            }

        }

        System.out.println(mysum);
    }

}

Measured memory_bytes: 22996
import java.util.Scanner;


public class Main {

	public static void main(String[] args)  {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int x = Integer.parseInt(sc.next());
		int t = Integer.parseInt(sc.next());
		
		int cnt = n / x;
		if(n%x != 0) {
			cnt++;
		}
		
		
		System.out.println(cnt*t);
	}

}




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

struct UnionFind
{
    vector<int> par;
    UnionFind(int n) : par(n, -1){ }
    int root(int x){
        if(par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    bool issame(int x, int y){
        return root(x) == root(y);
    }
    bool merge(int x, int y){
        x = root(x); y = root(y);
        if(x == y) return false;
        if(par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    int size(int x){
        return -par[root(x)];
    }
};

int main() {
    int N, M; cin >> N >> M;
    vector<pair<int, int>> bri(M);
    for (int i = 0; i < M; i++)
    {
        int a, b; cin >> a >> b;
        a--,b--;
        bri[i] = make_pair(a,b);
    }
    reverse(bri.begin(), bri.end());

    UnionFind uf(N);
    vector<long long> ans(M, 0);
    for (int i = 0; i < M; i++)
    {
        long long sa = uf.size(bri[i].first), sb = uf.size(bri[i].second);
        if(uf.merge(bri[i].first, bri[i].second)){
            ans[M-i-1] = sa * sb;
        }
    }

    for (int i = 0; i < M; i++)
    {
        if(i > 0) ans[i] += ans[i-1];
    }

    for(int i = 0; i < M; i++) cout << ans[i] << endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    string s;
    char ansOp[3];
    int num[4];
    bool op[3];
    cin >> s;
    rep(i, 4) num[i] = s[i] - '0';
    rep(bit, 1 << 3) {
        int tmp = num[0];
        rep(i, 3) {
            if (bit & 1 << i) {
                tmp += num[i + 1];
                ansOp[i] = '+';
            } else {
                tmp -= num[i + 1];
                ansOp[i] = '-';
            }
        }
        if (tmp == 7)
            break;
    }
    rep(i, 3) cout << s[i] << ansOp[i];
    cout << s[3] << "=7" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

void yn(bool b){
  if(b) cout << "Yes" << endl;
  else cout << "No" << endl;
  return;
}

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> v(h);
  rep(i, h) cin >> v[i];
  bool b = 1;
  rep(i, h){
    rep(j, w){
      if(v[i][j] == '.') continue;
      bool c = 0, d = 0;
      if(i == 0){
        if(v[1][j] == '.') c = 1;
      }
      else if(i == h-1){
        if(v[h-2][j] == '.') c = 1;
      }
      else{
        if(v[i-1][j] == '.' && v[i+1][j] == '.') c = 1;
      }
      if(j == 0){
        if(v[i][1] == '.') d = 1;
      }
      else if(j == w-1){
        if(v[i][w-2] == '.') d = 1;
      }
      else{
        if(v[i][j-1] == '.' && v[i][j+1] == '.') d = 1;
      }
      if(c && d){
        b = 0;
        break;
      }
    }
  }
  yn(b);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    int h,r;
    cin >> h >> r;
    if(h+r == 0)cout << 0 << endl;
    else if(h+r > 0)cout << 1 << endl;
    else cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 3092
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
int dp[5000][5000] = {};
int tx[5000]; int ty[5000];
int s[500000][4];
int main() {
	int n, m; cin >> n >> m;
	vector<int> xs; vector<int>ys;
	rep(i, n) {
		cin >> tx[i] >> ty[i];
		xs.push_back(tx[i]);
		ys.push_back(ty[i]);
	}
	sort(xs.begin(), xs.end());
	sort(ys.begin(), ys.end());
	rep(i, m) {
		rep(j, 4) {
			cin >> s[i][j];
		}
		s[i][0] = lower_bound(xs.begin(), xs.end(), s[i][0]) - xs.begin();
		s[i][1] = lower_bound(ys.begin(), ys.end(), s[i][1]) - ys.begin();
		s[i][2] = upper_bound(xs.begin(), xs.end(), s[i][2]) - xs.begin(); s[i][2]--;
		s[i][3] = upper_bound(ys.begin(), ys.end(), s[i][3]) - ys.begin(); s[i][3]--;
	}
	rep(i, n) {
		tx[i] = find(xs.begin(), xs.end(), tx[i]) - xs.begin();
		ty[i] = find(ys.begin(), ys.end(), ty[i]) - ys.begin();
	}
	rep(i, n) {
		dp[tx[i]][ty[i]]++;
	}
	rep(i, n) {
		rep(j, n) {
			if (i == 0 && j == 0) {
				dp[0][0] = dp[0][0];
			}
			else if (i == 0) {
				dp[0][j] += dp[0][j - 1];
			}
			else if (j == 0) {
				dp[i][0] += dp[i - 1][0];
			}
			else {
				dp[i][j] += dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
			}
		}
	}
	rep(i, m) {
		int sx = s[i][0]; int sy = s[i][1]; int gx = s[i][2]; int gy = s[i][3];
		int cnt;
		if (sx >= n || sy >= n || gx < 0 || gy < 0) {
			cnt = 0;
		}
		else if (sx > 0 && sy > 0) {
			cnt = dp[gx][gy] - dp[sx - 1][gy] - dp[gx][sy - 1] + dp[sx - 1][sy - 1];
		}
		else if (sx > 0) {
			cnt = dp[gx][gy] - dp[sx - 1][gy];
		}
		else if (sy > 0) {
			cnt = dp[gx][gy] - dp[gx][sy - 1];
		}
		else {
			cnt = dp[gx][gy];
		}
		cout << cnt << endl;
	}
	return 0;
}


Measured memory_bytes: 108720
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        String[] v = sc.nextLine().split(" ");
        String[] c = sc.nextLine().split(" ");

        int ret = 0;
        for (int i = 0; i < n; i++) {
            int tmp = Integer.parseInt(v[i]) - Integer.parseInt(c[i]);
            if (tmp > 0) {
                ret += tmp;
            }
        }

        System.out.println(ret);
    }
}

Measured memory_bytes: 22480
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
   return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
   os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}



signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n;cin>>n;
  V<ll> v(n);
  rep(i,0,n)cin>>v[i];
  sort(all(v));
  reverse(all(v));


  ll ans=0,now=0;
  rep(i,0,n-1){
    ans+=v[now];
    if(i%2==0)now++;
  }

  cout<<ans<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 4764
n,*a=map(int,open(0).read().split())
d=[j-i for i,j in zip(a,a[1:]+[a[0]])]
M=max(d)
dd=[M-x for x in d]
if n==1:
	print("YES")
elif (n==2 and sum(a)%3) or any(x%n for x in dd) or sum(x//n for x in dd)!=M or sum(a)//M!=n*(n+1)//2:
	print("NO")
else:
	print("YES")

Measured memory_bytes: 14956
from math import *

n,k = map(int,input().split())
a = list(map(int,input().split()))

b = list()

for i in range(n):
    if(i==0):
        b.append(0)
    elif(i==1):
        b.append(abs(a[i]-a[i-1]))
    else:
        mn = 100000000000
        if(i-k>=0):
            for j in range(i-k,i):
                if(mn>b[j]+abs(a[j]-a[i])):
                    mn = b[j]+abs(a[j]-a[i])
        else:
            for j in range(0,i):
                if(mn>b[j]+abs(a[j]-a[i])):
                    mn = b[j]+abs(a[j]-a[i])
        b.append(mn)
    
print(b[n-1])

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

void solve() {
    string s;
    cin >> s;
    int n = s.size();
    string first = s.substr(0, (n - 1) / 2);
    string re_first = first;
    reverse(re_first.begin(), re_first.end());
    if (re_first != first) {
        cout << "No" << endl;
        return;
    }

    string last = s.substr((n + 3)/2 - 1);
    string re_last = first;
    reverse(re_last.begin(), re_last.end());
    if (re_last != last) {
        cout << "No" << endl;
        return;
    }

    cout << (first == last ? "Yes" : "No") << endl;
}

int main() {
    solve();
    return 0;
}


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

using namespace std;

int gcd(int a,int b){
  if(a<b) return gcd(b,a);
  int r;
  while((r=a%b)){
    a=b;
    b=r;
  }
  return b;
}

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

  int num = gcd(A,B);
  
  int a = A/num;
  int b = B/num;
  
  long long result = (long long)a*(long long)b*(long long)num;

  cout<<result<<endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        d = sc.nextInt();
        int[][] x = new int[n][d];
        for(int i=0; i<n; i++){
            for(int j=0; j<d; j++){
                x[i][j] = sc.nextInt();
            }
        }
        
        for(int i=0; i*i<16000; i++){
            square[i] = i*i;
        }
        
        int c = 0;
        
        
        for(int i=0; i<n-1; i++){
            for(int j=i+1; j<n; j++){
                if(check(x[i],x[j])) c++;
            }
        }
        
        System.out.println(c);
        
    }
    
    public static int n, d;
    public static int[] square = new int[160];
    
    static boolean check(int[] x1, int[] x2){
        int s = 0;
        for(int i=0; i<d; i++){
           s += (x1[i] - x2[i]) * (x1[i] - x2[i]);
        }
        for(int i=0; i<160; i++){
            if(square[i] == s) return true;
        }
        return false;
    }
}


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

int main() {
  int N;
  cin >> N;
  vector<int> X(N);
  int a, b = 0; 
  int P, Q = 0;
  int count = 0;
  int count2 = 0;
  for(int i = 0; i < N; i++) {
    cin >> X.at(i);  
  }
  for(int i = 0; i < N; i++) {  
    a = a + X.at(i);
    b = b + X.at(i)*X.at(i);
  }
  if(a%N == 0) {
    P = a/N;
    count = b - 2*P*a + N*P*P;
    cout << count << endl;
  }
  else {
    P = a/N;
    count = b - 2*P*a + N*P*P;
    Q = a/N + 1;
    count2 = b - 2*Q*a + N*Q*Q;
    cout << min(count,count2) << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

const int MAXN = 1e5+5;
int N, dp[3][MAXN]{0}, arr[3][MAXN];

int main()
{
    cin >> N;
    for(int i = 0; i < N; i++)
        cin >> arr[0][i] >> arr[1][i] >> arr[2][i];
    dp[0][0] = arr[0][0];
    dp[1][0] = arr[1][0];
    dp[2][0] = arr[2][0];
    for(int i = 1; i < N; i++) {
        for(int j = 0; j < 3; j++) {
            dp[j][i] = max(dp[(j+1)%3][i-1], dp[(j+2)%3][i-1]) + arr[j][i];
        }
    }
    cout << max(dp[0][N-1], max(dp[1][N-1], dp[2][N-1])) << '\n';
    return 0;
}


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

int main() {
    int A,B;
    cin >> A >> B;
    if(A%3 ==0 || B%3 == 0 || (A + B)%3 == 0) {
        cout << "Possible" << endl;
    }
    else {
        cout << "Impossible" << endl;
    }
}


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

#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define SZ(x) ((int) (x).size())
#define ALL(x) x.begin(), x.end()
#define debug(x) cerr << #x" = " << x << endl

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef unsigned long long u64;
typedef vector<int> VI;

template <typename T> inline bool cmin(T & a, const T & b) { return a > b ? a = b, 1 : 0;}
template <typename T> inline bool cmax(T & a, const T & b) { return a < b ? a = b, 1 : 0;}
template <typename T> void read(T & x) {
	int f = 1; char ch; x = 0;
	while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
	while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); x *= f;
}

// a, b, c
// b + c, a + c, a + b
// b - a
// 2a + b + c, 2b + a + c, 2c + a + b
// a - b
// 3b + 2a + 3c, 3b + 3a + 2c, 2b + 3a + 3c
// b - a
int main() {
	LL a, b, c; read(a); read(b); read(c);
	LL k; read(k); 
	LL d = (k & 1) ? b - a : a - b;
	if(abs(d) > 1000000000000000000LL)
		puts("Unfair");
	else
		cout << d << endl;
	return 0;
}





Measured memory_bytes: 256
#include<iostream>
#include<queue>
using namespace std;
typedef pair<pair<int,int>,int> pa;
#define ff first.first
#define fs first.second
#define f(a,b) for(int a=0;a<b;a++)

int h,w,sx,sy,gx,gy,i,j,go,m = 999999;
int dx[4]={1,0,-1,0};
int dy[4]={0,-1,0,1};
int co[21][21];
char ma[21][21];
bool visited[21][21];
string pat;

int main(){
    while(cin>>h>>w,h){
        f(i,h){
            f(j,w){
                co[i][j]=m;
                cin>>ma[i][j];
                if(ma[i][j]=='A')
                    sx=j,sy=i;
                else if(ma[i][j]=='B')
                    gx=j,gy=i;
            }
        }
        queue<pa>q;
        q.push(make_pair(make_pair(sx, sy), 0));
        while(q.size()){
            pa p = q.front();
            q.pop();
            if(co[p.fs][p.ff]!=m)
                continue;
            co[p.fs][p.ff]=p.second;
            f(i,4){
                int nx=p.ff+dx[i];
                int ny=p.fs+dy[i];
                if(nx>=0&&nx<w&&ny>=0&ny<h&&ma[ny][nx]!='#'&&co[ny][nx]==m)
                    q.push(make_pair(make_pair(nx, ny), p.second+1));
            }
        }
        cin>>pat;
        for(j=0,go=0;;j++,go++){
            i=j%pat.length();
            if(co[gy][gx]<=go){
                cout<<go<<" "<<gy<<" "<<gx<<endl;
                break;
            }
            if(go>700){
                cout<<"impossible"<<endl;
                break;
            }
            if(pat[i]=='8')
                gy--;
            else if(pat[i]=='6')
                gx++;
            else if(pat[i]=='4')
                gx--;
            else if(pat[i]=='2')
                gy++;
            gy=max(0,min(h-1,gy));
            gx=max(0,min(w-1,gx));
        }
    }
}

Measured memory_bytes: 1228