akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
inline ll read() {
    ll x=0,f=1; char ch=getchar();
    for(;ch<'0'||ch>'9';ch=getchar())
        if(ch=='-')f=-f;
    for(;ch>='0'&&ch<='9';ch=getchar())
        x=x*10+ch-'0';
    return x*f;
}
inline void chkmin( int &a,int b ) { if(a>b) a=b; }
inline void chkmax( int &a,int b ) { if(a<b) a=b; }
#define _ read()
#define ln endl
const int N=505;
int n,k,a[N],b[N];
ll sum,p[N],tmp,ans;
inline ll check( int x ) {
	tmp=0;
	for( int i=1;i<=n;i++ ) b[i]=a[i]%x;
	sort(b+1,b+n+1);
	// for( int i=1;i<=n;i++ ) cout<<b[i]<<" ";
	for( int i=1;i<=n;i++ ) p[i]=p[i-1]+b[i];
	for( int i=n;i;i-- ) {
		if(tmp==p[i]&&tmp<=k) return 1;
		tmp=tmp+(x-b[i]);
	}
	return 0;
}
int main() {
	n=_; k=_;
	for( int i=1;i<=n;i++ ) a[i]=_,sum+=a[i];
	 for( ll i=1;i<=sqrt(sum);i++ ) 
		if(sum%i==0) {
			if(check(sum/i)) ans=max(ans,sum/i);
			if(check(i)) ans=max(ans,i);
		}
	// cout<<check(7)<<ln2 10;
	cout<<ans<<ln;
}

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

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    sort(a.begin(),a.end());
    
    cout << a[n-1]-a[0] << endl;
}


Measured memory_bytes: 256
a,b,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = [tuple(map(int,input().split())) for i in range(m)]
p = [min(a)+min(b)]
for t in c:
    p.append(a[t[0]-1]+b[t[1]-1]-t[2])
print(min(p))

Measured memory_bytes: 32872
#include <algorithm>
#include <iostream>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(a) (a).begin(), (a).end()

#define INF 1000000000

using namespace std;

typedef long long ll;
ll mod = 1000000007;

long long power(int base, int n) {
    long long res = 1;
    long long cur = base;

    for (int i = 0; i < 31; ++i) {
        int mask = 1 << i;

        if (n & mask) {
            res *= cur;
            res %= mod;
        }

        cur *= cur;
        cur %= mod;
    }

    return res;
}


ll C(int n, int k) {
    long long x = 1;
    long long y = 1;

    REP(i, k) {
        x *= (n - i);
        x %= mod;

        y *= (k - i);
        y %= mod;
    }

    return (x * power(y, mod - 2)) % mod;
}

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

    long long sum = power(2, N) - 1;

    sum = ((sum - C(N, A)) + mod) % mod;
    sum = ((sum - C(N, B)) + mod) % mod;

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 384
from fractions import gcd
from functools import reduce

def gcd_list(nums):
    return reduce(gcd, nums)

def lcm(a,b):
    return a*b//gcd(a,b)

def lcm_list(nums):
    return reduce(lcm, nums)

def solve():
    N = int(input())
    T = [int(input()) for _ in range(N)]
    print(lcm_list(T))
    
solve()

Measured memory_bytes: 5204
package main

import (
	"fmt"
)

func main() {
	var n, a, b int
	fmt.Scan(&n,&a,&b)
	var ans int
	for i := 1; i <= n; i++ {
		s := sum(i)
		if a <= s && s <= b {
			ans += i
		} 
	}
	fmt.Println(ans)
} 

func sum(num int) int {
	var sum int
	for num != 0 {
		sum += num % 10
		num /= 10
	}
	return sum
}


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

const double INF = 1e9;
const double EPS = 1e-11;

// ????¬????
struct P3{
  double x,y,z;
  double vx,vy,vz;
  double r,vr;
  P3(double x=0, double y=0, double z=0):x(x),y(y),z(z){}
  P3 operator + (const P3 &a) const{ return P3(x+a.x, y+a.y, z+a.z); }
  P3 operator - (const P3 &a) const{ return P3(x-a.x, y-a.y, z-a.z); }
  P3 operator * (const double &c) const{ return P3(x*c, y*c, z*c); }
  void input(){cin>>x>>y>>z>>vx>>vy>>vz>>r>>vr;}
  P3 v ()const{return P3(vx,vy,vz);}
};
P3 operator * (double c, const P3 &a){ return P3(c * a.x, c * a.y, c * a.z); }


double norm(P3 a){ return a.x*a.x + a.y*a.y + a.z*a.z; }
double abs(P3 a){ return sqrt(norm(a)); }

typedef pair<int,int> P;
typedef pair<double,P> PP;

double calc(P3 A,P3 B,double t){
  if((A.r-t*A.vr)<0|| (B.r-t*B.vr)<0) return -1;
  return abs((A+t*A.v())-(B+t*B.v())) - ((A.r-t*A.vr) + (B.r-t*B.vr));
}

double calc(P3 A,P3 B){
  double L=0,R=INF,cnt = 200;
  while(cnt--){
    double M = (L+R)/2;
    double y1 = calc(A,B,M);
    double y2 = calc(A,B,M+EPS);
    if(y1<0||y1-y2<0) R = M;
    else L = M+EPS;
  }
  return L;
}

int main(){
  int n;
  while(cin>>n,n){
    vector<P3>A(n);
    for(int i=0;i<n;i++) A[i].input();

    priority_queue<PP,vector<PP>,greater<PP> >Q;
    for(int i=0;i<n;i++)
      for(int j=i+1;j<n;j++){
	double t = calc(A[i],A[j]);
	if(abs(calc(A[i],A[j],t))<2e-8)Q.push(PP(t,P(i,j)));
      }

    vector<double> ans(n,-1);
    while(!Q.empty()){
      PP t = Q.top();Q.pop();
      double c = t.first;
      int a = t.second.first;
      int b = t.second.second;
      if(ans[a]>=0||ans[b]>=0)continue;
      ans[a] = ans[b] = c;
    }

    for(int i=0;i<n;i++){
      if(ans[i]<0) ans[i] = A[i].r / A[i].vr;
      ans[i] = min(ans[i],A[i].r / A[i].vr);
      printf("%.10Lf\n",ans[i]);
    }    
    
  }
  return 0;    
}

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

int main(void) {
    int N, ans=0;

    cin >> N;
    int X[N];
    for(int i=0; i<N; i++) cin >> X[i];
    long long int min_val = 1001001001;

    for(int i=1; i<=100; i++){
      long long int total = 0;
      for(int j=0; j<N; j++){
          total += (X[j]-i)*(X[j]-i);
      }
      if(total < min_val)
      min_val =total;
    }


    cout << min_val << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		String text = scanner.nextLine();
		String[] all = text.split(" ");
		String ans = "";
		for(int i = 1; i >= 0; i--){
			ans += all[i];
		}
		System.out.println(ans);
	}

}


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

int main() {
    string S;
    cin >> S;
    stack<char> s;
    int len = S.length(), ans = 0;
    for(int i = 0; i < len; ++i) {
        if(!s.empty() && (s.top() != S[i])) {
            ans += 2;
            s.pop();
            continue;
        }
        s.push(S[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

void YesNo(bool x) {
    cout << (x ? "Yes" : "No") << endl;
}

int main() {
    int n, a;
    cin >> n >> a;
    YesNo((n % 500) <= a);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD=1e9+7;
using Graph = vector<vector<int>>;
int main(){
  ll N,M;
  cin>>N>>M;
  Graph G(N);
  for (ll i=0;i<M;++i) {
    ll a,b;
    cin>>a>>b;
    G[a-1].push_back(b-1);
    G[b-1].push_back(a-1);
  }
  vector<int> dist(N, -1); // 全頂点を「未訪問」に初期化
  queue<int> que;
  unordered_map<ll,ll> map;
  dist[0] = 0;
  que.push(0);
  while (!que.empty()) {
    int v = que.front(); // キューから先頭頂点を取り出す
    que.pop();

        // v から辿れる頂点をすべて調べる
    for (int nv : G[v]) {
      if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
      dist[nv] = dist[v] + 1;
      map[nv] = v;
      que.push(nv);
    }
  }
  //for(ll i=1;i<N;i++){
  //  cout<<i<<":"<<dist.at(i)<<","<<map[i]+1<<endl;
  //}
  cout<<"Yes"<<endl;
  for(ll i=1;i<N;i++){
    cout<<map[i]+1<<endl;
  }
}

Measured memory_bytes: 14256
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
static const long double GRATIO=(long double)(1+sqrt(5))/2;
ll GCD(ll a, ll b){
    return b ? GCD(b, a%b) : a;
}
ll LCM(ll a, ll b){
    return a/GCD(a,b)*b;
}
int main(){
    int N,W;
    cin>>N>>W;
    vector<int> w(N),v(N);
    rep(i,N) cin>>w[i]>>v[i];
    vector<vector<ll>> dp(N+1,vector<ll>(W+1,0));
    for(int i=1; i<N+1; i++){
        rep(j,W+1){
            dp[i][j] = max(dp[i][j],dp[i-1][j]);
            if(j-w[i-1]>=0) dp[i][j] = max(dp[i-1][j-w[i-1]]+v[i-1],dp[i][j]);
        }
    }
    ll m=0;
    rep(i,W+1) m = max(dp[N][i],m);
    cout<<m<<endl;
}

Measured memory_bytes: 80256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

alphala=[chr(i) for i in range(65, 65+26)]

#print(alphala)
s=input().rstrip()
count=0

if s[0]=="A":
    count+=1
x=0
for i in range(2,len(s)-1):
    u=s[i]
    if u=="C":
        x+=1
if x==1:
    count+=1
#print(count)
y=0
for i in range(len(s)):
    k=s[i]
    if k in alphala:
        y+=1
    #print(y)
if y==2:
    count+=1
#print(count)
if count==3:
    print("AC")
else:
    print("WA")

Measured memory_bytes: 3316
n = int(input())
# the num of monster in the cith A[i]
a = list(map(int, input().split()))
# the num of monster the hero can defeat
b = list(map(int, input().split()))


b_rest = [max(b[0]-a[0],0)]
a_rest = [max(a[0]-b[0],0)]


for i in range(n-1):
  b_rest.append( min( b[i+1], max( ((b[i+1]+b_rest[i])-a[i+1]), 0 ) ) )
  a_rest.append( max( a[i+1]-(b[i+1]+b_rest[i]), 0 ) ) 

a_rest.append(max(0, (a[n]-b_rest[-1]) ) )
ans = sum(a) - sum(a_rest)
                                
print(ans)


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

int main() {
  string S;
  cin >> S;
  
  if (S == "Sunny") {
    cout << "Cloudy" << endl;
  }
  else if (S == "Cloudy") {
    cout << "Rainy" << endl;
  }
  else {
    cout << "Sunny" << endl;
  }
}


Measured memory_bytes: 3520
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

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

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return ('0' <= c && c <= '9')?(c - '0'):-1;}

// TODO: write
int main() {
  int n;cin>>n;
  bool isOk = true;
  set<int> s;
  rep(i,n){
    int tmp;cin>>tmp;
    if(s.find(tmp) != s.end())isOk = false;
    s.insert(tmp);
  }
  print((isOk?"YES":"NO"));
  return 0;
}



Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using P = pair<int,int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;

ll gcd(ll a, ll b){return b!=0 ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

ll pow(ll a, ll b){
	ll ret = 1;
	while(0 < b){
		if(b % 2 == 1){
			ret = ret * a % MOD;
		}
		a = a * a % MOD;
		b >>= 1;
	}
	return ret;
}

int main(){
	ll n, k;
	cin >> n >> k;
	vector<ll> a(k+1, 0);
	for(ll i = k; 1 <= i; --i){
		a[i] = pow(k / i, n);
		int ii = 2;
		while(ii * i <= k){
			a[i] = (a[i] - a[ii * i]) % MOD;
			if(a[i] < 0) a[i] += MOD;
			ii++;
		}
	}
	
	ll ans = 0;
	for(ll i = 1; i <= k; ++i){
		ans += a[i] * i % MOD;
        ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 4052
#include <iostream>
#include <string>
using namespace std;
int main ()
{
	long long n,temp;
	cin>>n;
	long long three=(n/3);
	long long five=(n/5);
	long long fifteen=(n/15);
	long long a=(1+n)*n/2;
	long long b=(3+three*3)*three/2;
	long long c=(5+five*5)*five/2;
	long long d=(15+fifteen*15)*fifteen/2;
	cout<<a-b-c+d<<endl;
	
	
}

Measured memory_bytes: 3596
#include<stdio.h>
#define MAX 100005
#define NIL -1
struct Node_struct{int p, l, r;}; /*p: 親(parent), l: 一番左の子(left child), r:右の兄弟(right sibling)*/
typedef struct Node_struct Node;
Node T[MAX];
int D[MAX];

void print(int u){
  int i, c;
  printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]);

  if(T[u].p==NIL) printf("root, ");
  else if(T[u].l==NIL) printf("leaf, ");
  else printf("internal node, ");
  
  printf("[");
  for (i=0, c = T[u].l; c != NIL; i++, c = T[c].r){
    if(i) printf(", ");
    printf("%d", c);
  }
  printf("]\n");
  
}

void calcDepth(int u, int p){
  D[u] = p;
  if(T[u].r!=NIL) calcDepth(T[u].r,p);
  if(T[u].l!=NIL) calcDepth(T[u].l,p+1);
}

int main(){
  int i, j, k;
  int n;
  int id, sib, child;
  int root = NIL;
  scanf("%d", &n);
  for(i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL;
  
  for(i=0; i<n; i++){
    scanf("%d %d", &id, &k);
    for(j = 0, sib = NIL; j<k; j++){ //子を入力する (input children)
      scanf("%d", &child);
      T[child].p = id;
      if(j == 0) T[id].l = child; //idの一番左の子 (the most left child of id)
      else T[sib].r = child; //左の兄弟に繋げる (connect to left sibling)
      sib = child;//次の子供の左の兄弟 (the left sibling of the next child)
    }
  }

  //根を求める (find the root)
  for(i=0; i<n; i++){
    if(T[i].p == -1) root = i;
  }
  
  //それぞれのノードの深さを求める (find depth of each node)
  calcDepth(root, 0);

  //出力 (output)
  for(i=0; i<n; i++) print(i);
  
  return 0;
}



Measured memory_bytes: 6464
from sys import stdin

arr = list(map(int, stdin.readline().split('/')))
if arr[0] > 2019:
  print('TBD')
else:
  if arr[1] > 4:
    print('TBD')
  else:
    if arr[2] > 30:
      print('TBD')
    else:
      print('Heisei')


Measured memory_bytes: 2940
N, M = map(int, input().split())
ans = 1
for i in range(1, int(M ** 0.5) + 2):
    j = M // i
    if M % i == 0:
        if j >= N:
            ans = max(ans, i)
        if i >= N:
            ans = max(ans, j)
print(ans)


Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
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;
    return 0;
}

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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//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();}


int main(){
  string s;
  cin >> s;
  string ans = "AKIHABARA";
  if(s.size() > ans.size()){
    cout << "NO" << endl;
    return 0;
  }
  int index = 0;
  rep(i,ans.size()){
    if(index == s.size() && i == ans.size()-1){
      cout << "YES" << endl;
      return 0;
    }else if(index == s.size()){
      cout << "NO" << endl;
      return 0;
    }
    if(ans[i] == s[index]) {
      index++;
      continue;
    }else{
      if(ans[i] == 'A') continue;
      else{
        cout << "NO" << endl;
        return 0;
      }
    }
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 256
//
#include <vector>
#include <set>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <string>
//
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
constexpr double BIGP = 1000000007L;
constexpr double INF_I = std::numeric_limits<double>::max();
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll N;
    string S;
    cin >> N >> S;
    if (N % 2 == 1)
    {
        yes(false);
        return 0;
    }
    bool ok = true;
    rep(i, N / 2)
    {
        if (S[i] != S[i + N / 2]) ok = false;
    }
    yes(ok);
    return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>  // ver1.9.5
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define Pii pair<int,int>
#define pb push_back
#define mp make_pair
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define Vout(a) rep(i,0,a.size()-1)cout<<a[i]<<' ';cout<<a[a.size()-1]<<endl
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
using namespace std;

int XOR(int a,int b){bitset<64>z(a),x(b),c;c=z^x;return c.to_ullong();}  //  XOR

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  cout << fixed << setprecision(8);
  int n;
  cin >> n;
  int ans = 0,pre=0,now;
  rep(i,0,n){
    cin >> now;
    ans += min(pre,now);
    now -= min(pre,now);
    ans += now/2;
    now = now%2;
    pre = now;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long int x, bao=100, i;
	int nian=0;
	scanf("%lld", &x);
	do{
		bao=bao*1.01;
		nian++;
	}while(bao<x);
	printf("%d", nian);
	return 0;
}

Measured memory_bytes: 3832
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    int D,N; cin >> D >> N;
    int ans=0;
    int f=0;
    if(N==100){
        f=1;
    }
    if(D==0){
        ans = N+f;
    }else if(D==1){
        ans = (N+f)*100;
    }else{
        ans = (N+f)*100*100;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import deque

N,M =map(int,input().split())
A=[0]*M
B=[0]*M
C=[[] for _ in range(N)] #隣接リスト
d=[-1 for _ in range(N)]
for i in range(M):
  A[i],B[i] = map(int,input().split())
  C[A[i]-1].append(B[i]-1)
  C[B[i]-1].append(A[i]-1)
m=[-1]*N #道しるべの番号

def BFS(x):
  v=deque([x])
  d[x]=0

  while len(v)>0:
    s=v.popleft()
    for t in C[s]:
      #print(s,t,d)
      if d[t]==-1:
        d[t]=0
        m[t]=s
        v.append(t)
        #print(v)
  else:
    pass
    #print(m)
  
BFS(0)

if -1 in m[1:]:
  print("No")
else:
  print("Yes")
  for i in range(1,N):
    print(m[i]+1)

Measured memory_bytes: 50780
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

ll cost[4010];
signed main(void)
{
  while(true) {
    int n;
    cin >> n;
    if(!n) break;
    REP(i, 4010) cost[i] = 0;
    VI v;
    REP(i, n) {
      ll e, p, q;
      cin >> e >> p >> q;
      if(cost[e] < 1000000 && cost[e]+p*q>=1000000) {
        v.PB(e);
        cost[e] = 1000000;
      } else if(cost[e] < 1000000) {
        cost[e] += p*q;
      }
    }
    if(v.size() == 0) cout << "NA" << endl;
    REP(i, v.size()) cout << v[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 3092
class Dice

  def initialize
    @bottom,@top,@east,@west,@south,@north = 6,1,3,4,2,5
    @tmp_bottom,@tmp_top,@tmp_e,@tmp_w,@tmp_s,@tmp_n = @bottom,@top,@east,@west,@south,@north
  end
        #??¢??????????????????
  def west
    @tmp_bottom,@tmp_top,@tmp_e,@tmp_w,@tmp_s,@tmp_n = @bottom,@top,@east,@west,@south,@north
    @bottom,@top,@east,@west = @tmp_w,@tmp_e,@tmp_bottom,@tmp_top
  end

  def east
    @tmp_bottom,@tmp_top,@tmp_e,@tmp_w,@tmp_s,@tmp_n = @bottom,@top,@east,@west,@south,@north
    @bottom,@top,@east,@west = @tmp_e,@tmp_w,@tmp_top,@tmp_bottom
  end

  def south
    @tmp_bottom,@tmp_top,@tmp_e,@tmp_w,@tmp_s,@tmp_n = @bottom,@top,@east,@west,@south,@north
    @bottom,@top,@south,@north = @tmp_s,@tmp_n,@tmp_top,@tmp_bottom
  end

  def north
    @tmp_bottom,@tmp_top,@tmp_e,@tmp_w,@tmp_s,@tmp_n = @bottom,@top,@east,@west,@south,@north
    @bottom,@top,@south,@north = @tmp_n,@tmp_s,@tmp_bottom,@tmp_top
  end

  def position_top
    @top
  end
end

surface = gets.split
state = gets.chomp
dice = Dice.new
for i in 0..state.length-1 do
  case state[i]
    when 'E'
      dice.east
    when 'W'
      dice.west
    when 'S'
      dice.south
    when 'N'
      dice.north
  end
end
puts surface[dice.position_top-1]

Measured memory_bytes: 8636
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>

using namespace std;
typedef long long ll;
ll N;

int main(){

    ll N;

    cin >> N;
    ll ans = 0;
    for(ll i = 1; i <= N; i++){
        string s = to_string(i);
        if(s.length() % 2 == 1){
            ans++;
        }
    }

    cout << ans << endl;




} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

const int mod = 1000000007;

struct mint{
  ll x;
  mint(ll x = 0):x((x % mod + mod) % mod){};
  mint pow(ll y) const {
    mint res(1);
    mint a(x);
    while(y>0){
      if(y&1) res *= a;
      a *= a;
      y >>= 1;
    }
    return res;
  }
  mint inv() const{ return pow(mod-2); }
  mint& operator+= (const mint a) noexcept {
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-= (const mint a) noexcept {
    if((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*= (const mint a) noexcept {
    (x *= a.x) %= mod;
    return *this;
  }
  mint& operator/= (const mint a) noexcept {
    return (*this) *= a.inv();
  }
  mint operator+ (const mint a) const noexcept {
    mint res(*this);
    return res += a;
  }
  mint operator- (const mint a) const noexcept {
    mint res(*this);
    return res -= a;
  }
  mint operator* (const mint a) const noexcept {
    mint res(*this);
    return res *= a;
  }
  mint operator/ (const mint a) const noexcept{
    mint res(*this);
    return res /= a;
  }
};

ostream& operator<<(ostream& stream, const mint& n){
  stream << n.x;
  return stream;
};

struct comb{
  vector<mint> fact, ifact;
  comb(int n): fact(n+1), ifact(n+1){
    fact[0] = 1;
    for(int i = 1; i <= n; i++) fact[i] = fact[i-1] * i;
    ifact[n] = fact[n].inv();
    for(int i = n; i >= 1; i--) ifact[i-1] = ifact[i] * i;
  }
  mint operator()(int n, int k) const noexcept{
    if(k < 0 || n < k) return 0;
    return fact[n] * ifact[k] * ifact[n-k];
  }
};

mint dp[2005];

int main(void){
  ll n;
  cin >> n;
  dp[0] = 1;
  REP(i, n){
    FORe(j, 3, n){
      if(i+j > n) break;
      dp[i+j] += dp[i];
    }
  }
  cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 3604
N=int(input())
xs = [int(x) for x in input().split()]

def variance(xs,mean):
    return sum([(x-mean)**2 for x in xs])

mean = sum(xs)/N
variance1 = variance(xs,int(mean))
variance2 = variance(xs,int(mean)+1)
print(min(variance1,variance2))

Measured memory_bytes: 38256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <climits>
#include <fstream>
#include <bitset>
#include <time.h>
#include <assert.h>

#define LL long long
#define VI vector<int>
#define VL vector<long long>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS 1e-14
#define INF 1e7

using namespace std;


int longest_increasing_subsequence(const vector<int> &a) {
	vector<int> dp(a.size() + 1, INT_MAX);
	for (int i = 0; i < a.size(); ++i) {
		*lower_bound(ALL(dp), a[i]) = a[i];
	}
	return lower_bound(ALL(dp), INT_MAX) - dp.begin();
}

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

	int N;
	cin >> N;
	vector<int> a(N, 0);
	FOR(i, 0, N) {
		cin >> a[i];
	}

	cout << longest_increasing_subsequence(a) << endl;

	return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
#define MAX 1000

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

int main(){
	int h,w;
	cin >> h >> w;
	char a[h][w];
	REP(i,h) REP(j,w) cin >> a[i][j];
	int dist[h][w];
	REP(i,h) REP(j,w) dist[i][j] = INF;
	queue<P> que;
	REP(i,h){
		REP(j,w){
			if(a[i][j] == '#'){
				dist[i][j] = 0;
				que.push(P(i, j));
			}
		}
	}
	while(que.size()){
		P p = que.front();
		que.pop();
		REP(i,4){
			int nx = p.first + dx[i], ny = p.second + dy[i];
			if(0 <= nx && nx < h && 0 <= ny && ny < w && dist[nx][ny] == INF){
				que.push(P(nx, ny));
				dist[nx][ny] = dist[p.first][p.second] + 1;
			}
		}
	}
	int ans = 0;
	REP(i,h) REP(j,w) ans = max(ans, dist[i][j]);
	cout << ans << endl;
}

Measured memory_bytes: 13328
#include <iostream>
#include <string>

using namespace std;

void solve()
{
	string D;
	cin >> D;
	if (D.size() < 8)
	{
		cout << D << endl;
		return;
	}
	for (int i = 0; i < D.size() - 7; ++i)
	{
		int count[6] = { 0 };
		for (int j = i; j < i + 8; ++j)
		{
			if (D[j] == 'A')
			{
				++count[0];
			}
			else if (D[j] == 'I')
			{
				++count[1];
			}
			else if (D[j] == 'D')
			{
				++count[2];
			}
			else if (D[j] == 'U')
			{
				++count[3];
			}
			else if (D[j] == 'N')
			{
				++count[4];
			}
			else if (D[j] == 'Y')
			{
				++count[5];
			}
		}
		if (count[0] == 2 && count[1] == 1 && count[2] == 1 && count[3] == 1 && count[4] == 2 && count[5] == 1)
		{
			D[i] = 'A';
			D[i + 1] = 'I';
			D[i + 2] = 'Z';
			D[i + 3] = 'U';
			D[i + 4] = 'N';
			D[i + 5] = 'Y';
			D[i + 6] = 'A';
			D[i + 7] = 'N';
			i += 7;
		}
	}
	cout << D << endl;
}

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

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=b-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 1000000007
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 100;

int main(){
	fast_io();
	int n,k;
	cin >> n >> k;
	vector<int> moves(n);
	cu(i,0,n)cin >> moves[i];
	vector<vector<int>> dp(k + 1, vector<int>(2)); // 0 = taro
	cu(i,0,moves[0]){
		dp[i][0] = 1;
		dp[i][1] = 0;
	}
	fu(i,moves[0],k){
		fu(j,0,1){
			bool win = false;
			for(int move: moves){
				if(i - move >= 0 && dp[i-move][j^1] == j){
					win = true;
					break;
				}
			}
			dp[i][j] = (win?j:j^1);
		}
	}
	cout << (dp[k][0] ? "Second":"First") << endl;
}


Measured memory_bytes: 5760
#include<iostream>
int main()
{
int n;
std::cin >> n;
int a[100];
int i;
	for ( i = 0; i < n; i++ )
	{
		std::cin >> a[i];
	}
	for(i = n - 1;i > 0;i--)
	{
		std::cout << a[i] << " ";
	}
	std::cout << a[0] << std::endl;
	return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N,H,W;
  cin>>N>>H>>W;
  cout<<(N+1-H)*(N+1-W)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007LL;
vector<int> adj[100005];
int n, k, cur[100005], ans[100005];

void helper(int node, int p=-1){
    for(int i:adj[node]){
        if(cur[i]){
            ans[node] += cur[i] + (i==p&&p>1);
            continue;
        }
        ++cur[node]; helper(i, node);
    }
}

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);
  
    cin >> n >> k;

    for(int a, b, i = 1; i < n; ++i){
        cin >> a >> b;
        adj[a].push_back(b); adj[b].push_back(a);
    }

    helper(1);
    long long prod = 1;

    for(int i = 1; i <= n; ++i)
        prod = prod * max(0, k - ans[i]) % MOD;

    cout << prod;
    return 0;
}

Measured memory_bytes: 9984
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for(int i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VII;   // VII a(n,vector<int>(m)) n * m 
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T>  // chmax(max, a);
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> //chmin(min,a)
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}

ll Max=-1,Min=1e9+1;
       
int main(){
    ll a,b,c,x=0,y=0,n,m,k,w,sum=0,ans=0;
    string s,t;
    bool f=true;
    cin >> a >> b >> c >> x >> y;
    if(x>y){
        m=y;w=x;k=x-y;
    }
    else{
        m=x;w=y;k=y-x;
    }

    if(2*c>a+b){
        ans += a*x + b*y;
    }
    else{
        ans += m*c*2;
        if(x>y){
            if(2*c>a){ 
                ans += a*k;
            }   
            else{
                ans += k*2*c;
            }
        }
        else{
            if(2*c>b){ 
                ans += b*k;
            }   
            else{
                ans += k*2*c;
            }
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		StringBuilder str = new StringBuilder();
		
		while(true){
			String number = scan.next();
			if(number.equals("0")) break;
			int sum = 0;
			for(int i = 0 ; i < number.length() ; i++){
				sum += Integer.parseInt("" + number.charAt(i));
			}
			str.append(sum + "\n");
		}
		
		System.out.print(str);
	}
}

Measured memory_bytes: 18760
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(a,b) memset(a,b,sizeof(a))
#define msn(a,n,b) for(int i=0;i<=n;i++)a[i]=b
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define fi first
#define se second
using namespace std;
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef double db;
const int mod=1e9+7;
const int seed=233;
const double PI=acos(-1.0);
const double eps=1e-7;
const int inf=0x3f3f3f3f;
const int max_n=100005;
ll ceil(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?(x+y-1)/y:-x/y;}
ll floor(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?x/y:-(x+y-1)/y;}
namespace {
    inline int Add(int x,int y){return (x+=y)>=mod?x-mod:x;}
    inline int Sub(int x,int y){return (x-=y)<0?x+mod:x;}
    inline int Mul(int x,int y) {return 1ll*x*y%mod;}
    inline int Pow(int x,int y=mod-2){if(y==0)return 1;int res=1;while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}return res;}
}
/**********************head************************/
int n,m;
int main(){
    scanf("%d%d",&n,&m);
    int ans=n*(n-1)/2+m*(m-1)/2;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
require 'pp'
n, m, X, Y = gets.split.map(&:to_i)
x = gets.split.map(&:to_i).sort
y = gets.split.map(&:to_i).sort
if x[-1] >= y[0]
  puts 'War'
  exit
end
# p [x[-1], y[0]]
# p ((x[-1]+1)..y[0]).to_a
puts ((x[-1]+1)..y[0]).to_a.any?{|z| X < z && z <= Y} ? 'No War' : 'War'
# n w w


Measured memory_bytes: 4092
//
// Created on 2020/05/17.
//

#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
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;


int main() {
    string s;
    cin>>s;
    if(s[s.size()-1] == '3'){
        cout<<"bon"<<endl;
        return 0;
    }

    vector<char>pon;
    pon = {'0', '1','6','8'};
    vector<char>hon;
    hon = {'2','4','5','7','9'};

    for (int i = 0; i < pon.size(); ++i) {
        if(s[s.size()-1] == pon[i]){
            cout<<"pon"<<endl;
            return 0;
        }
    }
    for (int i = 0; i < hon.size(); ++i) {
        if(s[s.size()-1] == hon[i]){
            cout<<"hon"<<endl;
            return 0;
        }
    }
    return 0;
    
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
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(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    vector<ll> a(n);rep(i,n)cin>>a[i];
    sort(begin(a), end(a));
    function<bool(ll)> func = [&] (ll value) {
        ll cnt = 0;
        rep(i,n) {
            auto ptr = lower_bound(begin(a), end(a), value-a[i]);
            cnt += ll(end(a)-ptr);
        }
        return cnt >= m;
    };
    ll from = 0,to = 1e+5*2;
    while(to>from) {
        ll mid = (from + to) / 2;
        if (func(mid)) {
            from = mid;
        }
        else {
            to = mid;
        }
        if (to==from+1) {
            if (func(to)) {
                from = to;
            }
            else { 
                to = from;
            }
        }
    }
    vector<ll> csum(n+1,0);
    rep(i,n) {
        csum[i+1] = csum[i] + a[i];
    }  
    ll res = 0;
    ll cnt = 0;
    rep(i,n) {
        auto ptr = lower_bound(begin(a), end(a), from+1-a[i]);
        int idx = int(ptr-a.begin());
        res += csum[n] - csum[idx] + a[i] * (n-idx);
        cnt += n-idx;
    }
    res += from * (m-cnt);
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1792
//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
#include <stdio.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;
ll MODP = 998244353;

ll kai(ll x,ll y){
  if(y == 0)return 1;
  if(y == 1)return x;
  if(y&1){
    return (x*kai(x,y-1))%MOD;
  }else{
    ll t = kai(x,y/2);
    return (t*t)%MOD;
  }
}

ll comb(ll a,ll b,vector<ll> &p){
  if(a == 0)return 1;
  if(b == 0)return 1;
  ll ans = p[a+b];
  ans = (ans*kai(p[a],MOD-2))%MOD;
  ans = (ans*kai(p[b],MOD-2))%MOD;
  return ans;
}

int main(){
  ll N;
  cin >> N;
  ll ans = INFL;
  for(int i = 1;i <= 1000000;i++){
    if(N%i == 0){
      ll t = i + N/i;
      if(ans > t-2)ans = t-2;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3624
// vim:ts=4:sts=4:sw=4:et
// MOSCOW IPT JINOTEGA
// Table #14
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for (int i = 0; i < int(n); ++i)
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;
typedef long long i64;

int main() {
#ifdef LOCAL
    assert(freopen("a.in", "r", stdin));
#endif
    //ios_base::sync_with_stdio(false);
    
    int a, b, n;

    cin >> n >> a >> b;
    if (a % 2 == b % 2)
        cout << "Alice\n";
    else
        cout << "Borys\n";

    return 0;
}



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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 2e3+34;

int s[N];

void solve() {
  int n, x, y; scanf("%d%d%d", &n, &x, &y);
  --x; --y;
  for (int i = 0; i < n-1; ++i) {
    for (int j = i+1; j < n; ++j) {
      int d = j-i; // 3
      if (j >= y && i <= x) {
	d -= y-x-1;
      } else if (i <= x && j <= y && j > x) {
	d = min(d, x-i+y-j+1); // 3, 1-0+3-3+1
      } else if (i >= x && i < y && j >= y) {
	d = min(d, i-x+j-y+1); // 2, 2-1+4-3+1
      } else if (i >= x && j <= y) {
	d = min(d, i-x+y-j+1);
      }
      ++s[d];
      //printf("(%d, %d) -> %d\n", i+1, j+1, d);
    }
  }
  for (int i = 1; i < n; ++i) {
    printf("%d\n", s[i]);
  }
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <limits>
#include <sstream>
#include <typeinfo>

using namespace std;

int main() {
	int N;
	cin >> N;
	N *= 2;
	vector<int> L(N);
	for (int i = 0; i < N; i++) {
		cin >> L[i];
	}
	sort(L.begin(), L.end());
	int ans = 0;
	for (int i = 0; i < N; i+=2) {
		ans += L[i];
	}
	cout << ans << endl;
	return 0;
}


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

#define int             long long int
#define ld              long double
#define ff              first
#define ss              second
#define mp              make_pair
#define pb              push_back
#define endl            "\n"

#define si              set <int>
#define vi              vector <int>
#define pii             pair <int, int>
#define vpii            vector <pii>
#define mii             map <int, int>
#define que_max         priority_queue <int>
#define que_min         priority_queue <int, vi, greater<int>>

#define loop(i,s,e)     for(int i=s;i<e;i++)
#define rloop(i,e,s)    for(int i=e;i>=s;i--)
#define mset(a,f)       memset(a,f,sizeof(a))


#define M               1000000007
#define sz(x)           ((int) x.size())
#define all(p)          p.begin(), p.end()

#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define Print(a,x,y)    for (int i=x; i<y; i++) cout<< a[i]<< " "; cout << endl

const int inf = INT_MAX;
const long long INF = LLONG_MAX;

inline int power(int a, int b)
{
	int x = 1;
	while (b)
	{
		if (b & 1) x *= a;
		a *= a;
		b >>= 1;
	}
	return x;
}

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 3e5 + 7;
vector <vi > adj(N);

bool vis[N];

int dp[100005][2];
int n;


void solve()
{
	int n;
	cin >> n;
	int a[n];
	set<int>s;
	loop(i, 0, n)
	{
		cin >> a[i];
		s.insert(a[i]);
	}
	if (sz(s) == n) cout << "YES" << endl;
	else cout << "NO" << endl;
	return;
}

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


	cout << setprecision(9) << fixed;

	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}


	return 0;
}


Measured memory_bytes: 18304
#include<bits/stdc++.h>
using namespace std;
int main(){
        int n; cin >> n;
        int cnt = 0;
        int mn = 0;
        for (int x = 0; x < n; ++x){
            int q; cin >> q;
            if (q >= mn){
                cnt += q - mn;
            }
            mn = q;
        }
        cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		int limit = 5;
		int [] list = new int [limit];

		for(int i = 0 ; i < limit ; ++i) {

			list[i] = Integer.parseInt(sc.next());

		};

		int k = Integer.parseInt(sc.next());

		if(list[list.length-1] - list[0] <= k) {
			System.out.println("Yay!");
		}else {
			System.out.println(":(");

		}

	}

}


Measured memory_bytes: 21844
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>


int cmp(const int *a,const int *b){

return *a > *b ? -1 : *a < *b ? 1 : 0 ;
}
//qsort(pa,n,sizeof(int),(int(*)(const void* ,const void*))cmp);

long long int memo[100];
long long int fib(int n){
  if(n<=1){
    return n;
  }
  else{
    return fib(n-1)+fib(n-2);
  }
}

long long int fib2(int n){
  if(n<=1){
    return n;
  }
  if(memo[n]!=0){
    return memo[n];
  }
    return memo[n]=fib(n-1)+fib(n-2);

}


int main(void){
  int h,w,n;
  scanf("%d%d%d",&h,&w,&n);
  int max;
  if(h>w){
    max=h;
  }
  else{
    max=w;

  }
  int ans;
  if(n%max==0){
    ans=n/max;
  }
  else{
    ans=n/max+1;
  }

  printf("%d",ans);





  return 0;
}


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

using namespace std;

int main(int argc, char *argv[]) {
    int N;
    cin >> N;
    
    vector<int> arr(N + 1);
    for (int i = 0; i < N + 1; i++) {
        cin >> arr[i];
    }

    vector<int> barr(N);
    for (int j = 0; j < N; j++) {
        cin >> barr[j];
    }

    int64_t ans = 0;
    for (int k = 0; k < N; k++) {
        int curb = barr[k];

        int first = min(barr[k], arr[k]);
        curb -= first;
        arr[k] -= first;
        ans += first;

        int second = min(curb, arr[k + 1]);
        arr[k + 1] -= second;
        ans += second;
    }

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


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

int main(void) {
	double k, n, a, buf, a_first;
  	double max_a = 0;
  
  	cin >> k >> n;
    for (int i = 0; i < n; i++){
      	cin >> a;
        if (i == 0) a_first = a;
      	if (max_a < (a - buf)) max_a = (a - buf);
      	buf = a;
    }
    if (max_a < (k - buf + a_first)) max_a = (k - buf + a_first);
  
    cout << (k - max_a) << endl;
  	
      
	return 0;
}

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

#define pb push_back
#define mp make_pair

typedef long long ll;

const int inf = 1e9;
const ll linf = 1e18;
const ll mod = 1e9 + 7;

vector<int> e[100000];
bool used[100000];
vector<int> g;
int dp[100000];

void dfs(int x)
{
  if(used[x]) return;

  used[x] = true;

  for(auto u : e[x]){
    dfs(u);
  }
  g.pb(x);
}

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

  for(int i = 0; i < m; i++){
    int x, y;
    cin >> x >> y;
    x--; y--;
    e[x].pb(y);
  }

  for(int i = 0; i < n; i++){
    dfs(i);
  }

  reverse(g.begin(), g.end());

  int ans = 0;
  for(auto u : g){
    for(auto x : e[u]){
      dp[x] = max(dp[x], dp[u] + 1);
      ans = max(ans, dp[x]);
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 8824