akhauriyash/Code-Regression huggingface dataset:
/*
tarun360
IIT Indore
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ll_s long
#define mod 1000000007
#define forn(i,start,lim) for(ll i=start;i<lim;i++)
#define forn_d(i,start,lim) for(ll i=start;i>=lim;i--)
#define forn_s(i,start,lim) for(ll_s i=start;i<lim;i++)
#define forn_d_s(i,start,lim) for(ll_s i=start;i>=lim;i--)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define debug1(a) cout<<a<<endl
#define debug2(a,b) cout<<a<<" "<<b<<endl
#define debug3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define debug4(a) cout<<"chu "<<a<<endl

double p[3005];
double dp[3005][3005];

int main()
{
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  ll n;
  cin>>n;
  forn(i,1,n+1) cin>>p[i];
  dp[0][0]=1.0;
  forn(i,1,n+1){
    forn(j,0,i+1){
      if(j==0) dp[i][j]=dp[i-1][j]*(1-p[i]);
      else dp[i][j]=dp[i-1][j]*(1-p[i])+ dp[i-1][j-1]*p[i];
    }
  }
  double ans=0.0;
  forn(i,(n+1)/2,n+1) ans+=dp[n][i];
  cout<<fixed<<setprecision(10)<<ans<<endl;
  return 0;
}


Measured memory_bytes: 69120
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define repr(i, n) for(int i = n;i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define PI 3.141592653589793
#define MOD 1000000007
 
typedef long long ll;
 

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

    ll n,ans=1;
    cin >> n;

    for(int i = 1; i <= n; ++i){
        ans = ans * i % MOD;
    }

    cout << ans << endl;

	return 0;
}

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

flag = 1

for i in a:
    if i%2 == 0:
        if i%3 == 0:
            pass
        elif i%5 == 0:
            pass
        else:
            flag = 0

if flag == 1:
    print("APPROVED")
else:
    print("DENIED")





Measured memory_bytes: 2940
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 d = Integer.parseInt(sc.next());
        int count = 0;
        for (int i = 0; i < n; i++) {
            int x = Integer.parseInt(sc.next());
            int y = Integer.parseInt(sc.next());
            double sum = Math.pow(x, 2) + Math.pow(y, 2);
            if (Math.sqrt(sum) <= d) {
                count++;
            }
        }
        System.out.println(count);
        sc.close();
    }
}


Measured memory_bytes: 58196
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int a[n];
    for (int i1 = 0; i1 < 2; i1++){
        for (int i2 = 0; i2 < 2; i2++){
            a[0] = i1;
            a[1] = i2;
            for (int i = 1; i < n - 1; i++){
                if((s[i] == 'o' && a[i] == 0) || (s[i] == 'x' && a[i] == 1)) a[i+1] = a[i-1];
                else a[i+1] = a[i-1] ^ 1;
            }
            // 結果に矛盾がないことのフラグ
            bool flag = false;
            if((s[n-1] == 'o' && a[n-1] == 0 && a[n-2] == a[0]) || (s[n-1] == 'x' && a[n-1] == 1 && a[n-2] == a[0])){
                if((s[0] == 'o' && a[0] == 0 && a[n-1] == a[1]) || (s[0] == 'x' && a[0] == 1 && a[n-1] == a[1])){
                    flag = true;
                }else if((s[0] == 'x' && a[0] == 0 && a[n-1] != a[1]) || (s[0] == 'o' && a[0] == 1 && a[n-1] != a[1])){
                    flag = true;
                }
            }else if((s[n-1] == 'x' && a[n-1] == 0 && a[n-2] != a[0]) || (s[n-1] == 'o' && a[n-1] == 1 && a[n-2] != a[0])){
                if((s[0] == 'o' && a[0] == 0 && a[n-1] == a[1]) || (s[0] == 'x' && a[0] == 1 && a[n-1] == a[1])){
                    flag = true;
                }else if((s[0] == 'x' && a[0] == 0 && a[n-1] != a[1]) || (s[0] == 'o' && a[0] == 1 && a[n-1] != a[1])){
                    flag = true;
                }
            }

            if(flag){
                rep(i, n){
                    if (a[i] == 0) cout << 'S';
                    else cout << 'W';
                }cout << endl;
                return 0;
            }

            // rep(i, n) cout << a[i] << " ";
            // cout << endl;
        }
    }
    cout << -1 << endl;
}


Measured memory_bytes: 896
from sys import stdin
rs = lambda : stdin.readline().strip()
ri = lambda : int(rs())
ril = lambda : list(map(int, rs().split()))

def main():
    a, b, k = ril()
    t = True
    for i in range(k):
        if t:
            if a % 2 == 1:
                a -= 1
            b += a // 2
            a //= 2
        else:
            if b % 2 == 1:
                b -= 1
            a += b // 2
            b //= 2
        t = not t
    print(a, b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9132
import java.util.Scanner;

fun main (args : Array<String>) {
  val input = Scanner(System.`in`)
  
  while (input.hasNext()) {
    val S = input.next()
    val T = input.next()
    var A = input.nextInt()
    var B = input.nextInt()
    val U = input.next()
    
    if (U.equals(S)) {
      --A
    } else if (U.equals(T)) {
      --B
    }
    
    println("$A $B")
  }
}

Measured memory_bytes: 36236
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N, a, b = map(int, input().split())
    if (b-a)%2==0:
        print("Alice")
    else:
        print("Borys")


if __name__ == '__main__':
    main()


Measured memory_bytes: 62120
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  map<int, int> mp;
  rep(i, N) {
    cin >> A[i];
    if(!mp.count(A[i])) mp[A[i]] = 0;
    mp[A[i]]++;
  }
  ll sum = 0;
  for(auto m: mp) {
    ll cnt = m.second;
    if(cnt > 1) sum += cnt * (cnt-1) / 2;
  }
  rep(i, N) {
    ll cnt = mp[A[i]];
    if(cnt <= 1) cout << sum << endl;
    else cout << sum - cnt * (cnt-1) / 2 + (cnt-1) * (cnt-2) / 2 << endl;
  }
  return 0;
}


Measured memory_bytes: 8320
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <vector>

using namespace std;

int h,w ;

int y_can[8] = {0, 0, -1, +1, +1, +1, -1, -1};  // 進む方向の簡便化，テクニックとして覚えておく．
int x_can[8] = {-1, +1, 0, 0, +1, -1, +1, -1};  // ループで回すことで上下左右に移動できるようになっている


void change(vector<vector<char>> maze,vector<vector<char>> &out){

    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if(maze[i][j]=='#') continue ;
            int cnt = 0 ;
            for (int k = 0; k < 8; k++)
            {
                int next_x = i+x_can[k] ;
                int next_y = j+y_can[k] ;
                if(next_x>=0 && next_x<h && next_y>=0 && next_y<w){
                    char next = maze[next_x][next_y] ;
                   cnt = (next=='#') ? cnt+1 : cnt+0 ;  
                } 
            }
            out[i][j] = '0'+cnt ;
        }
    }
}

int main() {
  
  cin>>h>>w ;
  vector<vector<char>> s(h,vector<char>(w)) ;
  vector<vector<char>> ans(h,vector<char>(w)) ;

  for (int i = 0; i < h; i++)
  {
      for (int j = 0; j<w ; j++)
      {
          cin >> s[i][j] ;
          ans[i][j] = s[i][j] ;
      }
  }
  
change(s,ans) ;

  for (int i = 0; i < h; i++)
  {
      for (int j = 0; j<w ; j++)
      {
        cout << ans[i][j] ;
      }
        cout << endl ;
  }

 return 0 ;

}

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

int main() {
	long long n;
	cin >> n;
	long long b;
	long long num;
	long long m = sqrt(n)+1;
	for (long long a = 1; a <= m; a++) {
		if (n % a == 0) {
			b = n / a;
			if (a > b) {
				break;
			}
			num = b;
		}
		else {
			continue;
		}
	}
	string s = to_string(num);
	cout << s.length() << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int x,k;
int ans[100000],cnt=0;
int main()
{
    cin>>k>>x;
    for(int i=x-k+1;i<=x+k-1;i++)ans[++cnt]=i;
    for(int i=1;i<=cnt;i++){
        cout<<ans[i];
        if(i!=cnt)cout<<" ";
        else cout<<endl;
    }
}


Measured memory_bytes: 256
#include<cstdio>
int read(){
	int x=0,ch=getchar(),f=1;
	while(ch<'0'||ch>'9'){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
	return x*f;
}
int main(){
	printf("%d\n",read()+read());
	return 0;
}

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

int main(){
  int n; cin>>n;
  int h[n][3];
  rep (i,n) rep(j,3) cin>>h[i][j];
  for (int i=1; i<n; i++){
    h[i][0] = max(h[i-1][1] + h[i][0], h[i-1][2] + h[i][0]);
    h[i][1] = max(h[i-1][0] + h[i][1], h[i-1][2] + h[i][1]);
    h[i][2] = max(h[i-1][0] + h[i][2], h[i-1][1] + h[i][2]);
  }
  cout << max( h[n-1][0], max(h[n-1][1], h[n-1][2] ));

}

Measured memory_bytes: 4768
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner inp = new Scanner(System.in);
        do_(inp);
        inp.close();
    }
    public static void do_(Scanner inp) {
        int a = inp.nextInt();
        int b = inp.nextInt();
        int ans = 0;
        for (int i = 1; i <= 3; i++) {
            if (i != a && i != b) ans = i;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21460
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

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

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

//container util

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

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define MOD 1000000007

int count(LL a) {
	int ret = 0;
	while (a) {
		ret++;
		a /= 10;
	}
	return ret;
}

int main() {
	LL n;
	cin >> n;
	int ret = 10000000;
	for (LL i = 1; i*i <= n; i++) {
		if (n%i == 0) {
			ret = min(ret, max(count(i) , count(n / i)));
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main() {
  int a, b, c, d;
  scanf("%d %d %d %d", &a, &b, &c, &d);
  if((a + b + c + d) == 21 && (a * b * c * d) == 252) {
    printf("YES\n");
  }else{
    printf("NO\n");
  }
  return 0;
}

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

int main() {
  string str;
  cin >> str;
  int N = str.size();
  int bool1=0, bool2=0, bool3=0;
  if (str.at(0) == 'A') {
    bool1 = 1;
  }
  for (int i=1; i<N; ++i) {
    if (!(str.at(i) >= 'a' && str.at(i) <='z')) {
      ++bool2;
    }
  }
  for (int i=2; i<N-1; ++i) {
    if (str.at(i) == 'C') {
      ++bool3;
    }
  }
  string ans = "WA";
  if (bool1 == 1 && bool2 == 1 && bool3 ==1) {
    ans ="AC";
  }
  //cout << bool1 << bool2 << bool3 << ans << endl;
  cout << ans << endl;
}




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

int main() {
  int N, x;
  cin >> N;
  x = N%10 + (N%100)/10 + (N%1000)/100 + (N%10000)/1000 + (N%100000)/10000 + (N%1000000)/100000 + (N%10000000)/1000000 + (N%100000000)/10000000 + (N%1000000000)/100000000;

  if (N / x * x == N)
  cout << "Yes" << endl;
  
  else cout << "No" << endl;
}

Measured memory_bytes: 3580
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int  a[3];
    for(int i=0;i<3;i++) cin>>a[i];
	sort(a,a+3);
	int ans=0;
	ans+=(a[2]-a[0])/2;
	//cout<<ans<<endl;
	a[0]+=(a[2]-a[0])/2*2;
	ans+=(a[2]-a[1])/2;
	//cout<<ans<<endl;
	a[1]+=(a[2]-a[1])/2*2;
	sort(a,a+3);
	if(a[0]==a[1]&&a[1]==a[2])
	{
		cout<<ans<<endl;
	}
	else if(a[0]==a[1]&&a[1]!=a[2])
	{
		cout<<ans+1<<endl;
	}
	else cout<<ans+2<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
	int h,m,s,S;
	scanf("%d",&S);
	h=S/3600;
	S=S%3600;
	m=S/60;
	s=S%60;
	printf("%d:%d:%d\n",h,m,s);

	return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; k < n; i++)

#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define PI 3.1415926535897932384626
#define endl "\n"
#define F first
#define S second
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
//=======================
const int MOD = 1'000'000'007;
const int N = 2e6 + 13;
//=======================
vi g[N];
int a[N];
//=======================

void solve()
{
  int n;
  double d;
  ll val1, val2;
  cin >> n >> d;
  int count = 0;
  for (int i = 0; i < n; i++)
  {
    cin >> val1 >> val2;
    ll sum = pow(val1, 2) + pow(val2, 2);
    double res = sqrt(sum);
    if (res <= d)
      count++;
  }
  cout << count << endl;
}

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

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int t = 1;

  // cin >> t;

  while (t--)
  {
    solve();
  }

  return 0;
}

Measured memory_bytes: 50636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,n,k,i;
  cin>>n;
  k=0;
  for(i=1; i<n+1; i++){
    cin>>a;
    if(a==i){
    }
    else{
      k=k+1;
    }
  }

  if(k==2||k==0){
    cout<<"YES";
  }
  else{
    cout<<"NO";
  }
}

Measured memory_bytes: 256
S =input()
T = input()

s = list(S)
ans = 0

if S.lower() == T.lower():
        ans +=1

for _ in  range(len(s)-1):
    A=s[-1]
    s.pop(-1)
    s.insert(0,A)
    #print(s)
    B=''.join(s)
    if B.lower() == T.lower():
        ans +=1
if ans != 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
using namespace std;
int main()
{
	int N, T;
	cin >> N >> T;
	vector<int> A;
	for (int i = 0; i < N; ++i)
	{
		int ai;
		cin >> ai;
		A.push_back(ai);
	}
	int sum = 0;
	int prev = 0;
	if (N == 1)
	{
		sum = T;
	}
	else
	{
		for (int i = 0; i < N - 1; ++i)
		{
			if (A[i + 1] <= A[i] + T)
			{
				if (i == N - 2)
				{
					sum += A[i + 1] + T - prev;
				}
			}
			else
			{
				sum += A[i] + T - prev;
				prev = A[i + 1];
				if (i == N - 2)
				{
					sum += A[i + 1] + T - prev;
				}
			}
		}
	}
	

	cout << sum << endl;
	
}

Measured memory_bytes: 1400
from itertools import accumulate,chain
from itertools import combinations

from random import randrange


def solve(A):
    N = len(A)
    oddacc = tuple(chain((0,),accumulate(A[1::2])))
    evenacc = tuple(chain((0,),accumulate(A[::2])))
    if N%2==0:
        return max(evenacc[i]+oddacc[-1]-oddacc[i] for i in range(N//2+1))

    # one 3 space
    res = max(evenacc[-1]-A[i*2] for i in range(N//2+1))
    # two 2 space
    def it():
        m = 0

        for i in reversed(range(N//2)):
            m = max(m+A[i*2+1], A[i*2+1]+evenacc[-1]-evenacc[i+2])
            yield m+evenacc[i]
    res = max(max(it()), res)
    return res

def naive(A):
    def it():
        for indices in combinations(range(len(A)), r=len(A)//2):
            if all(i+1!=j for i,j in zip(indices,indices[1:])):
                yield (sum(A[i] for i in indices), indices)

    return max(it())

if __name__ == '__main__':
    N = map(int,input().split())
    A = tuple(map(int,input().split()))
    print(solve(A))


    # for _ in range(10000):
    #     A = [randrange(1000)-500 for _ in range(6)]

    #     a = solve(A)
    #     b,ind = naive(A)
    #     if a!=b:
    #         print(ind)
    #         print(A)
    #         print(a,b)
    #         break

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

int main() {
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    bool ans = false;
    for (int i = 0; i < a; i++) {
        if (s[i] == '-') {
            ans = true;
        }
    }
    if (s[a] != '-') {
        ans = true;
    }
    for (int i = a + 1; i < a + b + 1; i++) {
        if (s[i] == '-') {
            ans = true;
        }
    }
    if (ans == true) {
        cout << "No" << endl;
    } else if (ans == false) {
        cout << "Yes" << endl;
    }
    return 0;
}


Measured memory_bytes: 764
#include <stdio.h>
#include <string.h>

int main(void)
{
	int A = 0, B = 0, O = 0, AB = 0;
	int num;
	char blood[10];
	
	while (scanf("%d,%s", &num, blood) != EOF){
		if (strcmp(blood, "A") == 0) A++;
		if (strcmp(blood, "B") == 0) B++;
		if (strcmp(blood, "O") == 0) O++;
		if (strcmp(blood, "AB") == 0) AB++;
	}
	
	printf("%d\n%d\n%d\n%d\n", A, B, AB, O);
	
	return (0);
}

Measured memory_bytes: 0
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

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

int main()
{
    int x, a, b;
    cin >> x >> a >> b;
    if (b - a <= 0)
    {
        cout << "delicious" << endl;
    }
    else if (b - a <= x)
    {
        cout << "safe" << endl;
    }
    else
    {
        cout << "dangerous" << endl;
    }
    return 0;
}

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

using namespace std;

int abs(int x) {
    return x >= 0 ? x : -x;
}

int main() {

    int x;
    cin >> x;

    int near_sq = 1;
    for (int i = 2; i <= 31; i++) {
        for (int j = 2; j < 31; j++) {
            if (pow(i, j) <= x && pow(i,j) > near_sq) {
                near_sq = (int)pow(i, j);
            }
        }
    }

    cout << near_sq << endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef vector<int>   vi;
typedef vector<long long> vll;
typedef vector<pair<int,int> > vii;
#define ll long long
#define pb push_back
#define mp  make_pair
#define ff first
#define ss second
#define pq priority_queue
#define sf(x) scanf("%d",&x)
int inf = (1e9) + 7;
	

int main()
{
	ll c[4];
	ll n;
	cin >> c[0] >> c[1] >> c[2] >> c[3];

	cin >> n;

	n *= 4;
	double ca,cb,cc,cd;
	ca = c[0] / 1.0;
	cb = c[1] / 2.0;
	cc = c[2] / 4.0;
	cd = c[3] / 8.0;


	vector<pair<double,int>> qs;
	map<ll,ll> mapa;
	mapa[1] = 1;
	mapa[2] = 2;
	mapa[3] = 4;
	mapa[4] = 8;
	qs.pb(mp(ca,1));
	qs.pb(mp(cb,2));
	qs.pb(mp(cc,3));
	qs.pb(mp(cd,4));

	sort(qs.begin(),qs.end());


	ll ans = 0;
	for (int i = 0; i < 4; ++i)
	{
		ll aux = n / mapa[qs[i].ss];
		ans += aux * c[qs[i].ss-1];
		n -= aux * mapa[qs[i].ss];
	}
	printf("%lld\n",ans );


}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func ri() int {
	sc.Scan()
	b := sc.Bytes()
	if b[0] == 45 {
		return -b2i(b[1:])
	} else {
		return b2i(b)
	}
}

func b2i(a []byte) (n int) {
	for _, v := range a {
		n = n*10 + int(v-48)
	}
	return
}

func main() {
	sc.Split(bufio.ScanWords)
	n := ri()

	cs := make([]int, n+1)
	cs[0] = 0
	sum := 0
	for i := 1; i < len(cs); i++ {
		sum += ri()
		cs[i] = sum
	}

	occurs := make(map[int]int)
	for _, v := range cs {
		occurs[v]++
	}

	ans := 0
	for _, v := range occurs {
		if v >= 2 {
			ans += v * (v - 1) / 2
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 12288
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>
#include <random>
//#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using pil = std::pair<int, long long>;
using pli = std::pair<long long, int>;
using plpii = std::pair<long long, std::pair<int, int>>;
using pdd = std::pair<double, double>;
using pis = std::pair<int, std::string>;

const long long INF = 1000000000000000001;
const long long _MOD_ = 1000000000000000009;
const long long _MOD = 1000000007;
const long long MOD = 998244353;
const int ALPHABET = 27;
const double pi = 3.14159265358979;

using namespace std;
//namespace mp = boost::multiprecision;

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

	int n;
	cin >> n;
	int* p = new int[n];
	rep(i, n) cin >> p[i];
	sort(p, p + n);
	
	int ans = 0;
	rep(i, n - 1) {
		ans += p[i];
	}

	ans += p[n - 1] / 2;
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 3612
#include <iostream>

#include <cstdlib>

int main() {
  int D, T, S;
  std::cin >> D >> T >> S;

  auto div_v = std::div(D, S);

  auto d_s = div_v.quot;

  if (div_v.rem != 0) {
    d_s += 1;
  }

  std::cout << (d_s <= T ? "Yes" : "No") << '\n';
}


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

int main(){
  int n, a;
  cin >> n >> a;
  if (n < 1 || 10000 < n) {
    cout << "No" << endl;
  }
  else if (a < 0 || 1000 < a) {
    cout << "No" << endl;
  }
  else if ((n % 500) <= a){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
 
//Write From this Line

//const ll mod = 1e9+7;
//const ll mod = 998244353;

const int dy[] = {0,0,1,-1};
const int dx[] = {1,-1,0,0};
int main()
{
	int h, w, m;
	cin >> h >> w >> m;

	vector<P> gyou(h);
	vector<P> retu(w);
	rep(i,h) gyou[i] = {0,i};
	rep(i,w) retu[i] = {0,i};
	map<P,bool> bomb;

	rep(i,m){
		int a, b;
		cin >> a >> b;
		a--, b--;
		bomb[{a,b}] = true;

		gyou[a].first++;
		retu[b].first++;
	}
	SORT(gyou), SORT(retu);
	REV(gyou), REV(retu);
	int M = gyou[0].first;
	int sime_h = h;
	int sime_w = w;
	rep(i,h){
		if(gyou[i].first != M){
			sime_h = i;
			break;
		}
	}
	M = retu[0].first;
	rep(j,w){
		if(retu[j].first != M){
			sime_w = j;
			break;
		}
	}
	// sime_h と sime_w番目まで見ればいい。

	int ans = gyou[0].first + retu[0].first - 1;
	rep(i,sime_h){
		rep(j,sime_w){
			int y = gyou[i].second;
			int x = retu[j].second;
			if(bomb[{y,x}] != true){
				ans ++;
				cout << ans << endl;
				return 0;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 26756
#include<bits/stdc++.h>
using namespace std;
int main(){


  int N;

  cin>>N;

  int p[11];

  int ans=0;

  int maxx=0;
  for(int i=0;i<N;i++){
    cin>>p[i];
    ans+=p[i];

    maxx=max(maxx,p[i]);
  }

  cout<<ans-maxx+maxx/2<<endl;
  
  return 0;
}


Measured memory_bytes: 256
from collections import Counter
n,k = map(int,input().split())
L = list(map(int,input().split()))
s = len(set(L))
L1 = Counter(L)
L2 = L1.most_common()
L2 = sorted(L2,key = lambda x:x[1])

sum1 =0
if s-k <= 0:
    print(0)
    exit()
else:
    for i in range(s-k):
        sum1 += L2[i][1]
print(sum1)

Measured memory_bytes: 48540
import math

def A():
    a, b = [int(x) for x in input().split()]
    print(math.ceil((a + b)/2))

def B():
    a = ''.join(sorted(list(input()), key=lambda x:ord(x)))
    b = ''.join(sorted(list(input()), key=lambda x:-ord(x)))
    if a < b:
        print('Yes')
    else:
        print('No')

def C():
    N = input()
    A = [x for x in input().split()]
    counter = {}

    for a in A:
        if(a in counter):
            counter[a] += 1
        else:
            counter[a] = 1
    remove_count = 0
    for key in counter:
        if counter[key] - int(key) >= 0:
            remove_count += counter[key] - int(key)
        else:
            remove_count += counter[key]
    print(remove_count)

def E():
    s1 = input()
    s2 = input()
    if s1 == s2[::-1]:
        print('YES')
    else:
        print('NO')
E()


Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
	int n,k,a=1;
	cin>>n>>k;
	for(int I=0;I<n;I++){
		if(a+k<a*2)a=a+k;
		if(a+k>=a*2)a=a*2;
	}
	cout<<a<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define db long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound 
#define pii pair<int , int>
#define pdd pair<double , double>
#define pll pair<long long int,long long int>
#define vpl vector<pll >
#define vll vector<ll >
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.000001
#define stp setprecision(20)
#define endl '\n'
int main()
{  
    fastio;
    //#ifndef ONLINE_JUDGE
    //    freopen("input.txt", "rt", stdin);
    //    freopen("output.txt", "wt", stdout);
    //#endif
    ll n,i;cin>>n>>i;
    cout<<n-i+1;
} 



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

const int MAX_V = 100010;
int V;
vector<int> G[MAX_V];
vector<int> rG[MAX_V];
vector<int> vs;
bool used[MAX_V];
int cmp[MAX_V];

void add_edge(int from, int to){
    G[from]. push_back(to);
    rG[to]. push_back(from);
}

void dfs(int v){
    used[v] = true;
    for(int i = 0; i < G[v].size(); i++){
        if(!used[G[v][i]]) dfs(G[v][i]);
    }
    vs. push_back(v);
}

void rdfs(int v, int k){
    used[v] = true;
    cmp[v] = k;
    for(int i = 0; i < rG[v].size(); i++){
        if(!used[rG[v][i]]) rdfs(rG[v][i], k);
    }
}

int scc(){
    memset(used, 0, sizeof(used));
    vs.clear();
    for(int v = 0; v < V; v++){
        if(!used[v]) dfs(v);
    }
    memset(used, 0, sizeof(used));
    int k = 0;
    for(int i = vs.size() - 1; i >= 0; i--){
        if(!used[vs[i]]) rdfs(vs[i], k++);
    }
    return k;
}

signed main(){
    int E;
    cin >> V >> E;
    rep(i, 0, E){
        int s, t;
        cin >> s >> t;
        add_edge(s, t);
    }
    scc();
    int q;
    cin >> q;
    rep(i, 0, q){
        int s, t;
        cin >> s >> t;
        cout << (cmp[s] == cmp[t] ? 1 : 0) << endl;
    }
}

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

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

  sort(vc.begin(), vc.end());
  double value = vc[0];
  for (int i=1; i<N; ++i) {
    value = (value + vc[i]) / 2;
  }

  cout << fixed << setprecision(5) << value << "\n";
  return 0;
}


Measured memory_bytes: 256
import math

N = int(input().strip())
A = [list(map(int, input().strip().split())) for i in range(N)]
d = [[-1 for i in range(N)] for j in range(N)]
for i in range(N):
    ax = A[i][0]
    ay = A[i][1]
    for j in range(i+1,N):
        bx = A[j][0]
        by = A[j][1]

        tmp = math.sqrt((ax-bx)**2 + (ay-by)**2)
        d[i][j] = tmp
        d[j][i] = tmp
#print(d)
total = 0
for i in range(N):
    for j in range(i+1,N):
        total += d[i][j]


def func(check, k, town, to):
    if k == N:
        return to
    t = 0
    for i in range(N):
        if i == town or check[i] :
            continue
        #print(town , "->", i)
        check[i] = True
        t += func(check, k+1, i, to + d[town][i])
        check[i] = False
    return t
check = [False] * N
total = 0
for i in range(N):
    #print("head")
    check[i] = True
    total += func(check, 1, i, 0)
    check[i] = False
print(total/math.factorial(N))

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int w,h,n; cin >> w >> h >> n;
  vector<int> x(n),y(n),a(n); rep(i,n) cin >> x[i] >> y[i] >> a[i];
  vector<vector<bool>> white(w,vector<bool>(h,true));
  
  rep(i,n){
    switch(a[i]){
    case 1:
      for(int j = 0;j<x[i];++j){
	  rep(k,h) white[j][k] = false;
      }
      break;
    case 2:
      for(int j = x[i];j<w;++j){
	  rep(k,h) white[j][k] = false;
      }
      break;
    case 3:
      rep(j,w){
	for(int k = 0;k<y[i];++k)
	   white[j][k] = false;
      }
      break;
    case 4:
      rep(j,w){
	for(int k = y[i];k<h;++k) white[j][k] = false;
      }
    }
  }
  int ans=0;

  rep(i,w){
    rep(j,h){
      if(white[i][j]){
	ans++;
      }
    }
  }  
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
struct point{double x;double y;};
int i,j,k,count1=0,count2=0;

int main(){
    int n,x,takai=0;
    cin>>n;
    vector<int> rate(8);
    for(i=0;i<n;i++){
        cin>>x;
        if(x>=3200){
            takai++;
            continue;
        }
        for(j=0;j<8;j++){
            if(x>=400*j&&x<400*(j+1)){
                rate[j]++;
                break;
            }
        }
    }
    cerr<<takai<<endl;
    int min=0,max;
    for(i=0;i<8;i++){
        if(rate[i]>=1)min++;
    }
    if(min==0){
        min=1;
        max=takai;
    }else{
        max=min+takai;
    }
    cout<<min<<" "<<max<<endl;
}

Measured memory_bytes: 256
function Main(input) {
  input = input.split("\n");
  S= input[0].split("");
  var ans=999;
  for(i=0;i<S.length-2;i++){
    ans=Math.min(ans,Math.abs(753-parseInt(S[i]+S[i+1]+S[i+2])));
  }

  console.log('%s', ans);
}
  
// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug(){
  var input = document.getElementById("input").value;
  Main(input);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010;
int main(){
    string s;cin>>s;
    int n=s.length();
    if(s[n-1]=='1'||s[0]=='0'){
        cout<<-1<<endl;
        return 0;
    }
    int id=1;
    for(int i=0;i<n-1;i++){
        if(s[i]!=s[n-2-i]){
            cout<<-1<<endl;
            return 0;
        }
    }
    for(int i=0;i<n-1;i++){
        if(s[i]=='1'){
            cout<<id<<" "<<i+2<<endl;
            id=i+2;
        }else{
            cout<<id<<" "<<i+2<<endl;
        }
    }
}


Measured memory_bytes: 1664
import java.util.*;

public class Main {
  public static void main(String... args) {
    Scanner input = new Scanner(System.in);
    
    int n = input.nextInt();
    int m = input.nextInt();
    int x = input.nextInt();
    int[] cost = new int[n];
    int[][] c = new int[n][m];
    for (int i = 0; i < n; i++) {
      cost[i] = input.nextInt();
      for (int j = 0; j < m; j++) {
        c[i][j] = input.nextInt();
      }
    }
    
    int ans = Integer.MAX_VALUE;
    for (int i = 0; i < (1 << n); i++) {
      int local = 0;
      int[] algo = new int[m];
      for (int j = 0; j < n; j++) {
        if ((i & (1 << j)) != 0) {
          local += cost[j];
          for (int k = 0; k < m; k++) {
            algo[k] += c[j][k];
          }
        }
      }
      
      boolean good = true;
      for (int j = 0; j < m && good; j++) {
        good &= (algo[j] >= x);
      }
      
      if (good) {
        ans = Math.min(ans, local);
      }
    }
    
    
    System.out.println(ans == Integer.MAX_VALUE ? -1 : ans);
  }
}

Measured memory_bytes: 37272
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  vector<string> s;
  for (int i = 0; i < min(4, n); i++) {
    for (int j = 0; j < min(4, n); j++) {
      if (i == j) continue;
      s.emplace_back(to_string(a[i]) + to_string(a[j]));
    }
  }
  sort(s.begin(), s.end(), [&](string a, string b) {
    int az = a.size(), bz = b.size();
    return az != bz ? az < bz : a < b;
  });
  cout << s[2] << endl;

  return 0;
}


Measured memory_bytes: 3268
#include <iostream>
#include <vector>
using namespace std;
int main() {
	int N, M;
	cin >> N >> M;
	vector<int> Num(N + 1, 1);
	vector<int> Red(N + 1);
	Red[1] = 1;
	for (int i = 0; i < M; i++) {
		int x, y;
		cin >> x >> y;
		Num[x]--;
		Num[y]++;
		if (Red[x] == 1) Red[y] = 1;
		if (Num[x] == 0) Red[x] = 0;
	}
	int ans = 0;
	for (int r : Red) ans += r;
	cout << ans << endl;

}


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

using namespace std;

const int INF = 1 << 30;

int g[100][100];
int deg[100];
bool v[100];


int main() {
  int N, M;
  cin >> N >> M;
  for(int i = 0; i < M; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    --x, --y;
    g[x][y] = z;
    g[y][x] = z;
    deg[x]++;
    deg[y]++;
  }
  int ret = 0;
  if(N <= 20) {
    for(int i = 0; i < (1 << N); i++) {
      if(__builtin_popcount(i) <= 1) continue;
      int cost = 0;
      for(int j = 0; j < N; j++) {
        if((i >> j) & 1) {
          int add = INF;
          for(int k = 0; k < N; k++) {
            if(j == k) continue;
            if((i >> k) & 1) add = min(add, g[j][k]);
          }
          cost += add;
        }
      }
      ret = max(ret, cost);
    }
  } else {
    for(int i = 0; i < N; i++) {
      int chal = -1;
      for(int j = 0; j < N; j++) {
        if(v[j]) continue;
        if(chal == -1 || deg[j] < deg[chal]) chal = j;
      }
      vector< int > rots;
      for(int j = 0; j < N; j++) {
        if(g[chal][j] > 0) rots.emplace_back(j);
      }
      for(int j = 1; j < (1 << rots.size()); j++) {
        int cost = 0, st = INF;
        for(int k = 0; k < rots.size(); k++) {
          if((j >> k) & 1) {
            int add = g[chal][rots[k]];
            for(int l = 0; l < rots.size(); l++) {
              if(k == l) continue;
              if((j >> l) & 1) add = min(add, g[rots[k]][rots[l]]);
            }
            cost += add;
            st = min(st, g[chal][rots[k]]);
          }
        }
        ret = max(ret, cost + st);
      }
      v[chal] = true;
      for(int j = 0; j < N; j++) {
        if(g[j][chal] > 0) --deg[j];
        g[chal][j] = g[j][chal] = 0;
      }
    }
  }
  cout << ret << endl;
}



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

#define int				long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define FORE( i, m, n ) FOR( i, m , n + 1 )
#define REP( i, n )     FOR( i, 0, n )
#define REPE( i, n )	FOR( i, 0, n + 1 )
#define FORR( i, m )	for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )	FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()             
#define MP( a, b )		make_pair( (a), (b) )
#define fi				first
#define se				second

template<class T>bool chmax( T& a, const T& b ) { if( a < b ) { a = b; return 1; } return 0; }
template<class T>bool chmin( T& a, const T& b ) { if( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main() {
	int N, M; cin >> N >> M;
	vector<int> card( N );
	REP( i, N ) cin >> card[i];
	sort( ALL( card ) );

	vector<pair<int, int> > CB( M );
	REP( i, M ) cin >> CB[i].se >> CB[i].fi;
	sort( ALL( CB ), greater<pair<int, int> >() );


	int cnt = 0;
	REP( i, M ) {
		int ccnt = 0;
		while( cnt < N && card[cnt] < CB[i].fi ) {
			card[cnt] = CB[i].fi;
			cnt++;
			ccnt++;
			if( ccnt == CB[i].se ) break;
		}
	}

	int sum = 0;
	REP( i, N ) sum += card[i];
	cout << sum << endl;

}

Measured memory_bytes: 2560
N,K = map(int,input().split())


sum = 0
for k in range(K,N+2):
    # sum(arr[0:0+k]), sum([l-,l])
    s1 = ((0 + k-1) * k) // 2
    s2 = (((N - k + 1) + N) * k) // 2
    sum = sum + (s2 - s1 + 1)

print(sum % (1000000000 + 7))

Measured memory_bytes: 9188
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(lint)(n);i++)
#define REP(i,n) for(int i=1;i<=(lint)(n);i++)
#define all(V) V.begin(),V.end()
#define stackReplaceBegin(size)\
	void* p=malloc(size);\
	esp_new=(lint)p+size-1;\
	void * stack_extend_memory_ = malloc(size);\
	void * stack_extend_origin_memory_;\
	char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);\
	*stack_extend_dummy_memory_ = 0;\
	asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
typedef long long lint;
typedef unsigned long long ulint;
typedef std::pair<int, int> P;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = DBL_EPSILON;
constexpr double PI = 3.141592653589793238462643383279;
lint esp_new;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
template<typename T>
T mypow(T a, unsigned int b) {
	T res(1),now(a);
	while(b){
		if(b&1)res*=now;
		b>>=1;
		now*=now;
	}
	return res;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, (int)vec.size() - 1)std::cout << vec[i] << " ";
	if(!vec.empty())std::cout << vec.back() << std::endl;
}
template<typename T>
void printArray(T l, T r) {
	T rprev = r;
	rprev--;
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
int n,a[200010];
int main() {
	std::cin>>n;
	rep(i,n)std::cin>>a[i];
	std::sort(a,a+n,std::greater<int>());
	lint ans=0;
	rep(i,n/2)ans+=a[i]*2;
	if(n%2)ans+=a[n/2];
	std::cout<<ans-a[0]<<std::endl;
	return 0;
}

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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define pb push_back

using namespace std;
using ll=long long;
using pii= pair<int, int>;
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
template<typename... T> void rd(T&... args) {((cin>>args), ...);}
template<typename... T> void wr(T... args) {((cout<<args<<" "), ...);cout<<endl;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s,t;
    cin>>s>>t;
    int ans=0;
    forn(i,sz(s)){
        ans+=s[i]!=t[i];
        }
    cout<<ans;
    return 0;
}



Measured memory_bytes: 3856
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll i,o,t,j,l,s,z;
  cin >> i >> o >> t >> j >> l >> s >> z;
  ll ans=0;
  ans+=o;
  ans+=i/2*2;
  ans+=j/2*2;
  ans+=l/2*2;
  if(i%2&&j%2&&l%2) ans+=3;
  if((i%2+j%2+l%2==2)&&i&&j&&l) ans++;
  cout << ans << endl;
}

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

int main() {
 	    long n,w,a,b;
        cin>>n>>w;
        vector<pair<long,long>>p; long val=0;
        for(long i=0;i<n;i++){cin>>a>>b; p.push_back({b,a}); val=val+b;}
       
        long dp[n+1][val+1];
        for(int i=0;i<=n;i++)dp[i][0]=0;       //dp[i][j] is min weight for value atleast i considering frst i elements
                                               //see it can be solved in one array only as in dp realtion there is i-1 for both terms
        for(int i=1;i<=val;i++)dp[0][i]=1000000000;
         //here it measn impossible and as we used min so we need LONG_MAX in base case
             for(long i=1;i<=n;i++){
             for(long j=1;j<=val;j++){
                 
                 if(j-p[i-1].first<0)dp[i][j]=dp[i-1][j];
                 else{
                dp[i][j]=min(dp[i-1][j-p[i-1].first]+p[i-1].second,dp[i-1][j]);
               }
             }
        }
        long ans; //find  max value so that is weight req is less or equal w
        for(long i=0;i<=val;i++){
           // cout<<dp[n][i]<<endl;
            if(dp[n][i]<=w)ans=i;
        }
        cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 82484
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define square(x) pow(x,2.0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define max_queue(x) priority_queue<x>
#define min_queue(x) priority_queue<x, vector<x>, greater<x>>
#define big_sort(v) sort(all(v), [](int a, int b) { return a > b; })//大きい順にソート
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;
using vd = vector<long double>;
#define co(x) cout << x << endl;
#define cins(n,v) rep(i,n){cin >> v.at(i);}
#define couts(v) rep(i,v.size()){cout << v.at(i) << endl;}
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
/*
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
*/
int main() {
  int n,num=0;
  cin >> n;
  vector<int> v(n);
  rep(i,n){
    cin >> v[i];
  }
  rep(i, n-2){
    REP(j,i+1, n-1){
      REP(k,j+1,n){
        if(v[i]==v[j]||v[i]==v[k]||v[j]==v[k]){}
        else{
          if(v[i]+v[j]>v[k]&&v[i]+v[k]>v[j]&&v[k]+v[j]>v[i]){
            num++;
          }
        }
      }
    }
  }
  cout << num << endl;
  return 0;
}


Measured memory_bytes: 3528
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

double x, y;

int main()
{
	int len, in_way;
	int way = 90;
	
	while (scanf("%d,%d", &len, &in_way), len || in_way){
		double rad = way * M_PI / 180.0;
		x += cos(rad) * len;
		y += sin(rad) * len;
		
		way = (way - in_way + 360) % 360;
	}
	
	printf("%d\n%d\n", (int)x, (int)y);
	
	return (0);
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> w(n);
  int s1 = 0;/*最初に重さを全部足す変数*/
  for(int i=0;i<n;i++){
    cin>>w.at(i);
    s1+=w.at(i);
  }
  int s2 = 0;/*順番に重さを足す変数*/
  int count = 0;/*何番目の重さなのかを知るための変数*/
  for(int i=0;i<n;i++){
    s2+=w.at(i);/*重さをどんどん足していきます*/
    s1-=w.at(i);/*重さの合計をどんどん減らしていきます*/
    /*s2とs1の値がだんだん近づいていきます*/
    if(s2>=s1){/*s2がs1を超えるもしくは等しくなったらループを抜けます*/
      break;
    }
    else{/*そうではない場合は何番目の重さを足したり引いたりしているのかを調べます*/
      count++;
    }
  }
  /*"絶対値”の最小値なのでs2>=s1の時のs2-s1が最小とは限らない(1個前の段階が最小の可能性アリ)*/
  if(s2-s1>(s1+w.at(count))-(s2-w.at(count))){
    cout<<(s1+w.at(count))-(s2-w.at(count))<<endl;
  }
  else{
    cout<<s2-s1<<endl;
  }
  return 0;
}


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

using namespace std;
using ll = long long;

int main(){
    string s;
    cin>>s;
    bool ok=true;
    if(s.length() % 2 != 0) ok = false;
    else {
        for(int i=0;i<s.length();i+=2){
            if(!(s[i]=='h'&&s[i+1]=='i')) ok=false;
        }
    }

    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

using namespace std;

int main() {
    for (int i = 0; i < 3; ++i) {
        int a, b, c, d, e, f;
        cin >> a >> b >> c >> d >> e >> f;
        int s = 3600 * a + 60 * b + c;
        int g = 3600 * d + 60 * e + f;
        int ans = g - s;
        cout << ans / 3600 << " ";
        ans -= 3600 * (ans / 3600);
        cout << ans / 60 << " ";
        ans -= (ans / 60) * 60;
        cout << ans << '\n';
    }
}


Measured memory_bytes: 3104