akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
#include<regex>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define PI 3.14159265359
typedef long long LL;

template<class T> inline void chmax(T & a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

int main(void) {
	int N, M, X;
	cin >> N >> M >> X;

	vector<int> A(110);
	rep(i, M) {
		int tmp;
		cin >> tmp;
		A[tmp]++;
	}

	int ans_1 = 0;
	for (int i = X; i <= N; i++) {
		ans_1 += A[i];
	}
	
	int ans_2 = 0;
	for (int i = X; i >= 0; i--) {
		ans_2 += A[i];
	}

	cout << min(ans_1, ans_2) << endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
import sys
from collections import Counter
from itertools import permutations, combinations
from fractions import gcd
#from math import gcd
from math import ceil, floor
import bisect
sys.setrecursionlimit(10 ** 6)
inf = float("inf")

def input():
    return sys.stdin.readline()[:-1]

def main():
    N, K = map(int, input().split())
    tmp = N % K
    print(min(tmp, abs(tmp-K)))

if __name__ == '__main__':
    main()



Measured memory_bytes: 63980
n = int(input())
s = input()
red = []
white = []
for i in range(n):
  if s[i] == 'W':
    white.append(i)
for i in range(n - 1, -1, -1):
  if s[i] == 'R':
    red.append(i)
#print(white, red)
if min(len(red), len(white)) == 0:
  print(0)
  exit()

for i in range(min(len(red), len(white))):
  if white[i] >= red[i]:
    print(i)
    exit()
print(min(len(red), len(white)))

Measured memory_bytes: 17232
N=int(input())

mod = 10**9+7

if N<=1:
    print(0)
    exit()
    
OK=0

Eight=1
Seven=1

for i in range(2,N+1):
    Eight*=9
    Seven*=8
    ok=(Eight- Seven)%mod
    OK=OK*10+ok*2
    OK%=mod
    Eight%=mod
    Seven%=mod
print(OK)


Measured memory_bytes: 63924
n,m = list(map(int,input().split()))
st = []
for i in range(m):
    a,*b = list(map(int,input().split()))
    st.append(b)
p = list(map(int,input().split()))

k = 0
count = 0
for i in range(2**n):
    ans = 1
    for j in range(m):
        ons = sum([int(format(i,'b').zfill(n)[-k]) for k in st[j]])
        # print(j," gg ", ons,"#",ons%2==p[j])
        if not ons%2==p[j]:
            ans=0
    if ans:
        count +=1

print(count)


Measured memory_bytes: 3064
str = gets.split
N,M = str[0].to_i, str[1].to_i

a = Array.new(M){Array.new(2)}
for i in 0...M do
    str = gets.split
    a[i][0],a[i][1] = str[0].to_i, str[1].to_i
end

if N == 1
    b = 10
    for i in 0...M do
        c = a[i][1]
        if b == 10
            b = c
        elsif b != c
            b = -1
        end
    end
    answer = b
    if answer == 10
        answer = 0
    end
    puts answer
else
    b = Array.new(N,10)
    answer = 0
    for i in 0...M do
        c = a[i][1]
        d = a[i][0]
        if b[d-1] == 10
            b[d-1] = c
        elsif b[d-1] != c
            answer = -1
        end
    end
    if b[0] == 0
        answer = -1
    end
    if answer == -1
        puts answer
    else
        for i in 0...N do
            if b[-i-1] == 10 && i == N-1
                answer += 10**i
            elsif b[-i-1] == 10
                answer += 0
            else
                answer += b[-i-1] * (10**i)
            end
        end
        puts answer
    end
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "
int main(){
    int n,q;ll k;cin>>n>>k>>q;
    int w;
    vector<ll> v(n);
    rep(i, q){
        cin>>w;w-=1;v[w]++;
    }
    for(auto i=v.begin();i!=v.end();++i){
        (k-q+(*i))>0?co("Yes"):co("No");
    }
}

Measured memory_bytes: 1408
#include <iostream>
#include <cmath>
#include <iomanip>
 
using namespace std;
 
int main()
{
  int D, N, n;
  cin >> D >> N;
  
  if (N == 100) {
    n = N+1;
  } else {
    n = N;
  }
  cout  << n * static_cast<int>(pow(100, D)) << endl;
  
  return 0;
}

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

using namespace std;
using pii = pair<int, int>;

void dfs(vector<vector<pii>> &g, vector<int> &e, int v, int avoid_edge) {
  int i = 1;
  for (pii w : g[v]) {
    if (avoid_edge == w.second) {
      continue;
    }
    if (avoid_edge != -1 && i == e[avoid_edge]) {
      i++;
    }
    e[w.second] = i++;
    dfs(g, e, w.first, w.second);
  }
};

int main(int argc, char const *argv[]) {
  int n, a, b;
  cin >> n;
  vector<vector<pii>> g(n);
  vector<int> e(n-1, 0);

  for (int i = 0; i < n - 1; i++) {
    cin >> a >> b;
    g[a - 1].push_back(make_pair(b - 1, i));
    g[b - 1].push_back(make_pair(a - 1, i));
  }
  int k = 0;
  for (int i = 0; i < (int)g.size(); i++) {
    k = max(k, (int)g[i].size());
  }

  dfs(g, e, 0, -1);
  cout << k << endl;
  for (int tmp : e)
    cout << tmp << endl;

  return 0;
}


Measured memory_bytes: 8320
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;

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

    long long ans = 0;
    for (int i = 0; i < N; ++i)
    {
        ans += A[i] - 1;
    }
    cout << ans << endl;
    return 0;
}

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

const int N = 2e5 + 5;

int l[N], r[N];

int main() { 
    ios_base::sync_with_stdio(0); 
    cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    s = '.' + s;
    for (int i = 1; i <= n; i++) {
        l[i] = l[i - 1] + (s[i] == '#');
    } 
    for (int i = n; i >= 1; i--) {
        r[i] = r[i + 1] + (s[i] == '.');
    }
    int mn = INT_MAX;
    for (int i = 1; i <= n; i++) {
        mn = min(mn, l[i] + r[i] - 1);
    }
    cout << mn << '\n';
}

Measured memory_bytes: 2128
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
#include<cmath>
#include<math.h>
#include <cmath>
#include <limits>
#define ll long long
#define M 1000000
#define pi 3.1415926535
using namespace std;
int main() {
    double a,b,x;
    cin >> a >> b >> x;

    double ans1 = (180 / pi) * (atan(2 * (a * b- x/a) / (a * a)));

    if(ans1 <= (180 / pi) * atan(b / a)){
        printf("%f",ans1);
    }
    else{
        double ans2 = (180 / pi) * atan((a * b * b / ( 2 * x)));
        printf("%f",ans2);
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
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; }

int beki(int a, int n)
{
    if(n == 0){
        return 1;
    }
    int ans = beki(a, n / 2);
    ans = ans * ans;
    if(n % 2 == 1){
        ans = ans * a;
    }
    return ans;
}

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

    int N; cin >> N;
    vel dp(1000005);//dp[i] = x はi円引き出す操作の最小値がx回であること


    dp[0] = 0;
    rep1(i, N+1) {
        dp[i] = dp[i - 1] + 1;//一円が最小の時
        rep1(j,8) {
            if(i - pow(6, j) >= 0) {
                dp[i] = min(dp[i], dp[i - beki(6,j)] + 1);//6のべき乗円が最小の時
            }
            if(i - pow(9, j) >= 0) {
                dp[i] = min(dp[i], dp[i - beki(9, j)] + 1);//9のべき乗円が最小の時
            }
        }
    }
    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 8320
def search(ps, id):
    if ps[id] == -1:
        return 0
    else:
        return 1 + search(ps, ps[id])


def search_h(tree, id):
    if tree[id][0] == -1:
        left = -1
    else:
        left = search_h(tree, tree[id][0])

    if tree[id][1] == -1:
        right = -1
    else:
        right = search_h(tree, tree[id][1])

    return 1 + max(left, right)


n = int(input())
tree = [[] for _ in range(n)]
ps = [-1 for _ in range(n)]
ss = [-1 for _ in range(n)]
for _ in range(n):
    s = input().split()
    id = int(s[0])
    left = int(s[1])
    right = int(s[2])
    tree[id] = [left, right]
    if left >= 0:
        ps[left] = id
        ss[left] = right
    if right >= 0:
        ps[right] = id
        ss[right] = left

for id in range(n):
    p = ps[id]
    s = ss[id]
    deg = int(tree[id][0] >= 0) + int(tree[id][1] >= 0)
    d = search(ps, id)
    h = search_h(tree, id)
    if p == -1:
        type = "root"
    elif tree[id][0] == -1 and tree[id][1] == -1:
        type = "leaf"
    else:
        type = "internal node"

    print("node " + str(id) + ": parent = " + str(p) + ", sibling = " + str(s) + ", degree = " + str(
        deg) + ", depth = " + str(d) + ", height = " + str(h) + ", " + type)


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

using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll fexp (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = fexp (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return fexp (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/gcd(num1,num2))*num2;}


// end of Template

int n,p[200000],ans;
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n;
    for(int i=1;i<=n;i++)cin>>p[i];
    for(int i=1;i<n;i++){
        if(p[i]==i){ans++;swap(p[i],p[i+1]);}
    }
    if(p[n]==n){ans++;}
    cout<<ans<<newl;

}


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

struct Vec2d{
  double x,y;
};

double cross(Vec2d &A, Vec2d &B){
  return A.x*B.y - A.y*B.x;
}

int main(void){
	int n;cin>>n;
  while(n--){
  	double x1,y1,x2,y2,x3,y3,xk,yk,xs,ys;
  	cin>>x1>>y1>>x2>>y2>>x3>>y3>>xk>>yk>>xs>>ys;
    Vec2d AB,BC,CA,AK,BK,CK,AS,BS,CS;
    AB.x = x2-x1; AB.y = y2-y1;
    BC.x = x3-x2; BC.y = y3-y2;
    CA.x = x1-x3; CA.y = y1-y3;
    AK.x = xk-x1; AK.y = yk-y1;
    BK.x = xk-x2; BK.y = yk-y2;
    CK.x = xk-x3; CK.y = yk-y3;
    AS.x = xs-x1; AS.y = ys-y1;
    BS.x = xs-x2; BS.y = ys-y2;
    CS.x = xs-x3; CS.y = ys-y3;
    bool k=true,s=true;
    if(cross(AB,AK)>0.0 && cross(BC,BK)>0.0 && cross(CA,CK)>0.0)
    k=false;
    else if(cross(AB,AK)<0.0 && cross(BC,BK)<0.0 && cross(CA,CK)<0.0)
    k=false;
    else ;
    if(cross(AB,AS)>0.0 && cross(BC,BS)>0.0 && cross(CA,CS)>0.0)
    s=false;
    else if(cross(AB,AS)<0.0 && cross(BC,BS)<0.0 && cross(CA,CS)<0.0)
    s=false;
    else ;
    
    if(s!=k) cout<<"OK"<<endl;
    else cout<<"NG"<<endl;
    
  }
  return 0;
}

Measured memory_bytes: 1224
from itertools import accumulate


N, Q = list(map(int, input().split()))
S = input()
A = [list(map(int, input().split())) for i in range(Q)]

flg = []
for i in range(N-1):
    tmp_S = S[i:i+2]
    if tmp_S == 'AC':
        flg.append(1)
    else:
        flg.append(0)

flg2 = [0] + flg
flg2 = list(accumulate(flg2))

for a in A:
    print(flg2[a[1]-1] - flg2[a[0]-1])

Measured memory_bytes: 33140
#include<bits/stdc++.h>
using namespace std;
int main()
{
    double n,d;
    int y;
    cin>>n;
    y=n;
    if(y%2==0)
    {
        d=(y/2)/n;
        printf("%.8lf\n",d);
    }
    else{
            d=((y/2)+1)/n;
        printf("%.8lf\n",d);
    }
    return 0;
}


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

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;
template<typename T>
struct Edge {
    int u, v;
    T cost;
    Edge(int u, int v, T c) : u(u), v(v), cost(c) {}
    bool operator< (const Edge &e) const {return cost < e.cost;}
};

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

ll ans;

int main(void) {
    string s;
    cin >> s;
    int n = sz(s);
    if (s[n-1]=='s') s += "es";
    else s += "s";

    
    cout << s << endl;
    return 0;
}





Measured memory_bytes: 3640
#include<iostream>
using namespace std; 
 
 
int main(){
  int a, b ,c;
  cin >> a >> b >> c;
  
  if(a >= b && b >= c && a >= c){
    cout << (a*10 + b) + c << endl;
  } else if (a >= b && c >= b && a >= c){
    cout << (a*10 + c) + b << endl;
  } else if (b >= a && b >= c && a >= c){
    cout << (b*10 + a) + c << endl;
  } else if (b >= a && b >= c && c >= a){
    cout << (b*10 + c) + a << endl;
  } else if (c >= a && c >= b && b >= a){
    cout << (c*10 + b) + a << endl;
  } else {
    cout << (c*10 + a) + b << endl;
  }
}

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

double dices[200005];
double ans[200005];
int main(){
    int k,n;
    cin>>n>>k;
    rep(i,n){
        double tmp; cin>>tmp;
        dices[i]=(tmp+1)/2.0;
    }
    double ans = 0;
    rep(i,k) ans+=dices[i];
    double t = ans;
    for(int i=0;i<n-k+1;i++){
        t = t+dices[i+k]-dices[i];
        ans = max(ans,t);
    }
    cout<<fixed <<setprecision(8)<< ans << endl;
}

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

const int MAX_N = 1e5;
int N, a[MAX_N+5];

int main(){
  cin >> N;
  
  int total = 0;
  for(int i=1;i<=N;i++){
    cin >> a[i];
    total += abs(a[i]-a[i-1]);
  }
  
  total += abs(0-a[N]);
  for(int i=1;i<=N;i++)
    cout << total - abs(a[i]-a[i-1]) - abs(a[i+1]-a[i]) + abs(a[i+1]-a[i-1]) << endl;
  
  return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N);
    for(int i = 0; i < N; ++i)
        cin >> A[i];
    for(int i = 0; i < N; ++i)
        cin >> B[i];
    for(int i = 0; i < N; ++i)
        cin >> C[i];
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    ll ans = 0;
    for(int i = 0; i < N; ++i) {
        auto aitr = lower_bound(A.begin(), A.end(), B[i]),
             citr = upper_bound(C.begin(), C.end(), B[i]);
        int tmp1 = aitr - A.begin(), tmp2 = C.end() - citr;
        ans += (ll)tmp1 * tmp2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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 (b<a) { a=b; return 1; } return 0; }

int N,color[9]={},sum=0;

int main(){
    cin>>N;
    int a[N];
    rep(i,N){
        cin>>a[i];
        if(a[i]>=3200){
            color[8]+=1;
        }
        else{
            for(int j=400;j<=3200;j+=400){
                // out(j);
                if(a[i]<j){
                    j=j/400-1;
                    color[j]+=1;
                    break;
                }
            }
        }
    }
    rep(i,8){
        if(color[i])sum+=1;
        // out(color[i]);
    }
    if(sum==0){
        cout<<1<<" "<<sum+color[8]<<endl;
    }else{
        cout<<sum<<" "<<sum+color[8]<<endl;
    }
    return 0;
}

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

typedef long long ll;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<ll>;
using vll = vector<vector<ll>>;

#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define MOD 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  ll n,m;
  cin >> n >> m;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sorti(a); // 降順
  vl sum(n+1, 0);
  rep(i, a.size()) {
    sum[i+1] = sum[i] + a[i];
  }

  ll ans = sum[n] * 3 + 10;

  ll left = -1, right = ans;
  ll cnt = 0;
  ll acc = 0;
  while (left + 1 < right) {
    ll mid = (left + right) / 2;
    cnt = 0;
    acc = 0;
    for (auto itr : a) {
      auto it = lower_bound(a.begin(), a.end(), mid - itr);
      int i = it - a.begin(); // 累積和のインデックス
      cnt += a.end() - it;
      acc += sum[n] - sum[i] + (a.end() - it) * itr;
    }

    if (cnt >= m) {
      left = mid;
    } else {
      right = mid;
    }
  }

  cout << acc - (cnt - m) * left << endl;
}


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

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}

int64_t calcmodcomb(int64_t n,int64_t r){
  return (((modfact.at(n)*modinvfact.at(r))%univMod)*modinvfact.at(n-r))%univMod;
}

int64_t calcmodpositive(int64_t n){
  return (n + ((abs(n)+univMod-1)/univMod)*univMod)%univMod;
}
  
    */


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  int64_t n;
  cin >> n;
  int64_t e;
  int64_t cnt = 0;
  rep(i,n){
    cin >> e;
    if(e % 2 == 1){
      cnt++;
    }
  }
  if(cnt % 2 == 1){
    cout << "NO" << endl;
  }else{
    cout << "YES" << endl;
  }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

struct UnionFind {
  vector<int> c, s;
  UnionFind(size_t n) : c(n), s(n, 1) { iota(begin(c), end(c), 0); }
  int root(int i) { return c[i] == i ? i : (c[i] = root(c[i])); }
  bool same(int i, int j) { return root(i) == root(j); }
  void unite(int i, int j) {
    i = root(i); j = root(j);
    if (i != j) {
      if (s[i] > s[j]) { c[j] = i; s[i] += s[j]; }
      else { c[i] = j; s[j] += s[i]; }
    }
  }
  int size(int i) { return s[root(i)]; }
};

i64 n, m;
using P = pair<i64, i64>;
vector<vector<P>> g;
vector<vector<i64>> mw;

void dfs(i64 r, i64 u, i64 b) {
  for (auto p : g[u]) {
    i64 v, c;
    tie(v, c) = p;
    if (v == b) continue;
    mw[r][v] = max(mw[r][u], c);
    dfs(r, v, u);
  }
}

int main() {
  cin >> n >> m;
  vector<tuple<i64, i64, i64>> es, tes;
  for (i64 i = 0; i < m; ++i) {
    i64 a, b, c;
    cin >> a >> b >> c;
    es.emplace_back(c, a, b);
  }
  sort(begin(es), end(es));
  UnionFind uf(n + 1);
  i64 csum = 0;
  for (i64 i = 0; tes.size() < n - 1; ++i) {
    auto t = es[i];
    i64 a, b, c;
    tie(c, a, b) = t;
    if (!uf.same(a, b)) {
      tes.emplace_back(c, a, b);
      csum += c;
      uf.unite(a, b);
    }
  }
  
  init_n(g, n + 1);
  for (auto e : tes) {
    i64 a, b, c;
    tie(c, a, b) = e;
    g[a].emplace_back(b, c);
    g[b].emplace_back(a, c);
  }

  init_n(mw, n + 1, vector<i64>(n + 1));
  for (i64 r = 1; r <= n; ++r) {
    dfs(r, r, 0);
  }

  i64 q;
  cin >> q;
  while (q--) {
    i64 s, t;
    cin >> s >> t;
    cout << csum - mw[s][t] << '\n';
  }
  return 0;
}


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

int main() {
	int a1,a2,a3,a4,b1,b2,b3,b4,asum = 0,bsum = 0;
	cin >> a1 >> a2 >> a3 >> a4;
	cin >> b1 >> b2 >> b3 >> b4;

	asum = a1 + a2 + a3 + a4;
	bsum = b1 + b2 + b3 + b4;
	if(asum > bsum){
		cout << asum << endl;
	}
	else{
		cout << bsum << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<sstream>
#include<algorithm>
#include<stack>
#include<bitset>
#include<map>
#include<set>
#define rep(i,n) for(int i=0;(i)<(n);i++)
#define rep1(i,n) for(int i=1;(i)<=(n);i++)
#define mst(a,b) memset(a,b,sizeof(a))
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define dbg(a) cout<<"* "<< #a <<" : "<<a<<endl
#define fr first
#define se second
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ls x<<1
#define rs x<<1|1
#define lowbit(x) x&(-x)
#define ac cout<<ans<<endl
//#define DEBUG 0
using namespace std;
const double pi=acos(-1.0);
const double eps=1e-6;
const ull hashp=1e7+19;
const ll INF=0x3f3f3f3f3f3f3f3fll;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const int maxn=2e5+100;
int a[maxn],b[maxn],c[maxn];
int vis[maxn],cnt,ans;
int check(int n,int *x){
	rep1(i,n)if(x[i]!=c[i])return 0;return 1;
}
void dfs(int now,int n,int *x){
	if(now==n){
		cnt++;
		if(check(n,x))ans=cnt;
	}
	rep1(i,n)if(!vis[i]){
		vis[i]=1;
		c[now+1]=i;
		dfs(now+1,n,x);
		vis[i]=0;
	}
}
void solve()
{
	int n;scd(n);
	rep1(i,n)scd(a[i]);
	rep1(i,n)scd(b[i]);
	dfs(0,n,a);
	int mark=ans;
	cnt=0;
	dfs(0,n,b);
	printf("%d",abs(ans-mark));
}
int main(){
    //IOS;
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using vs = vector<string>;
using vb = vector<bool>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); if (n == 0) cout << endl; REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

map<ll, ll> prime_factorization(ll n) {
    map<ll, ll> m;
    ll x = n;
    ll d = 2;
    while (x > 1 && d * d <= n) {
        if (x % d == 0) {
            m[d]++;
            x /= d;
        } else {
            d++;
        }
    }
    if (x != 1) m[x]++;
    return m;
}

void solve() {
    ll a, b;
    cin >> a >> b;
    auto g = gcd(a, b);
    auto p = prime_factorization(g);
    cout << sz(p) + 1 << endl;
}


Measured memory_bytes: 3596
// Copyright 2020 yaito3014
#include <bits/stdc++.h>

int main() {
  using namespace std;
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  constexpr double PI = 3.14159265358979;
  int A, B, H, M;
  cin >> A >> B >> H >> M;
  int time = H * 60 + M;
  double hour = 360 * time / (12 * 60.);
  double minute = 360 * M / 60.;
  double angle = hour + 360 - minute;
  angle = min(angle, abs(360 - angle));
  double ans = sqrt(A * A + B * B - 2 * A * B * cos(angle * PI / 180));
  cout << fixed << setprecision(10) << ans << endl;
}


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

int main(void){
    long int N;
    cin >> N;
    char sinsu[10000];
    long int i=0;
    while(true){
        int digit = N % 26;
        
        if(N == 0){ 
            break;
            }
        else{
            if(digit == 0){
                digit = 26;
                N = N / 26 -1;
            }
            else{
                N = N /26;
            }
            sinsu[i] = (96 + digit) + '\0';
        }
        i++;
    }
    //sinsu[i] = (96 + N) + '\0'; 
    string name;
    name = sinsu;
    reverse(name.begin(),name.end());
   
    cout << name << endl;
    return 0;
}


Measured memory_bytes: 3600
#include <iostream>

int main( void ) {
    int x, y;
    std::cin >> x >> y;

    const int normalizer[] = { 0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0 };

    if( normalizer[ x - 1 ] == normalizer[ y - 1 ] ) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int l[100005];
int w[100005];
long long q[100005][15];
int a;
int main() {
	cin>>s;
	int k=s.length();
	for(int i=0;i<k;i++) 
		if(int(s[i])==63) l[k-i]=-1;
		else l[k-i]=int(s[i])-48;
	w[1]=1;
	for(int i=2;i<=k;i++) w[i]=w[i-1]*10%13;
	if(l[1]!=-1) q[1][l[1]]++;
	else for(int i=0;i<10;i++) q[1][i]++;
	for(int i=2;i<=k;i++) {
		if(l[i]!=-1) {
			a=l[i]*w[i]%13;
			for(int j=0;j<13;j++) q[i][j]=q[i-1][(13+j-a)%13],q[i][j]%=1000000007;
		} 
		else {
			for(int j=0;j<10;j++) {
				a=j*w[i]%13;
				for(int m=0;m<13;m++) q[i][m]+=q[i-1][(13+m-a)%13],q[i][m]%=1000000007;
			}
		}
	}
	cout<<q[k][5];
	return 0;
}

Measured memory_bytes: 12928
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAXN 300010
#define LL long long
using namespace std;

int n,m;
LL a[MAXN],s1[MAXN],s2[MAXN];
int pre[MAXN];
LL f1[MAXN],f2[MAXN];
LL ans[MAXN],temp[MAXN];

namespace Convex{
	LL xp[MAXN],yp[MAXN];
	int q[MAXN],head,tail;

	void init(){
		head=0;
		tail=-1;
	}

	void addPoint(int id,LL x,LL y){
		xp[id]=x;
		yp[id]=y;
		while(head<tail && (yp[q[tail]]-yp[q[tail-1]])*(xp[id]-xp[q[tail]]) 
													<=
						   (yp[id]-yp[q[tail]])*(xp[q[tail]]-xp[q[tail-1]])) tail--;
		q[++tail]=id;
	}

	int query(int i){
		while(head<tail && (yp[q[tail]]-yp[q[tail-1]])<=(xp[q[tail]]-xp[q[tail-1]])*i) tail--;
		return q[tail];
	}
}

void init(){
	for(int i=1;i<=n;i++) s1[i]=a[i]+s1[i-1];
	for(int i=1;i<=n;i++) s2[i]=a[n-i+1]+s2[i-1];
	Convex::init();
	Convex::addPoint(0,0,0);
	for(int i=1;i<=n;i++){
		int j=Convex::query(i);
		f1[i]=max(f1[i-1],f1[j]+(LL)(i-j)*(i-j+1)/2-(s1[i]-s1[j]));
		pre[i]=j;
		if(f1[i]==f1[i-1]) pre[i]=i;
		Convex::addPoint(i,i,f1[i]+((LL)i*i-i)/2+s1[i]);
	}
	Convex::init();
	Convex::addPoint(0,0,0);
	for(int i=1;i<=n;i++){
		int j=Convex::query(i);
		f2[i]=max(f2[i-1],f2[j]+(LL)(i-j)*(i-j+1)/2-(s2[i]-s2[j]));
		Convex::addPoint(i,i,f2[i]+((LL)i*i-i)/2+s2[i]);
	}
	for(int i=1;i<=n;i++) if(i<n-i+1) swap(f2[i],f2[n-i+1]);
	for(int i=1;i<=n;i++) ans[i]=-(1LL<<60);
}

void gao(int l,int r){
	if(l==r){
		ans[l]=max(ans[l],f1[l-1]+f2[l+1]+1-a[l]);
		return;
	}
	int mid=(l+r)>>1;
	Convex::init();
	for(int i=l-1;i<mid;i++)
		Convex::addPoint(i,i,f1[i]+((LL)i*i-i)/2+s1[i]);
	for(int i=mid+1;i<=r;i++){
		int j=Convex::query(i);
		temp[i]=f2[i+1]+f1[j]+(LL)(i-j)*(i-j+1)/2-(s1[i]-s1[j]);
	}
	LL tmax=-(1LL<<60);
	for(int i=r;i>mid;i--){
		if(temp[i]>tmax) tmax=temp[i];
		if(tmax>ans[i]) ans[i]=tmax;
	}
	Convex::init();
	for(int i=r+1;i>mid+1;i--){
		int i2=r+1-i;
		Convex::addPoint(i,i2,f2[i]+((LL)i2*i2-i2)/2+s2[n-i+1]);
	}
	for(int i=mid;i>=l;i--){
		int j=Convex::query(r+1-i);
		temp[i]=f1[i-1]+f2[j]+(LL)(j-i)*(j-i+1)/2-(s1[j-1]-s1[i-1]);
	}
	tmax=-(1LL<<60);
	for(int i=l;i<=mid;i++){
		if(temp[i]>tmax) tmax=temp[i];
		if(tmax>ans[i]) ans[i]=tmax;
	}
	gao(l,mid);
	gao(mid+1,r);
}

int main(){
#ifdef DEBUG
	freopen("F.in","r",stdin);
#endif
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%lld",a+i);
	init();
	gao(1,n);
	scanf("%d",&m);
	while(m--){
		int x,y;
		scanf("%d%d",&x,&y);
		LL ans1=f1[x-1]+f2[x+1];
		LL ans2=ans[x]-y+a[x];
		printf("%lld\n",max(ans1,ans2));
	}
}


Measured memory_bytes: 24832
use std::collections::HashMap;

fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: usize = read(&mut stdin_lock, &mut buf, b'\n');
    let mut sv: Vec<Vec<char>> = Vec::new();
    for _ in 0..n {
        sv.push(
            read::<String>(&mut stdin_lock, &mut buf, b'\n')
                .chars()
                .collect(),
        );
    }

    for i in 0..n {
        sv[i].sort();
    }

    sv.reverse();

    let mut cv = vec![0i64; n];
    let mut map = HashMap::new();
    for i in 0..n {
        let s = sv[i].iter().map(|&c| c).collect::<String>();
        let count = match map.get(&s) {
            None => 0,
            Some(&c) => c,
        };
        cv[i] = count;
        map.insert(s, count + 1);
    }

    let ans: i64 = cv.iter().sum();
    println!("{}", ans);
}


Measured memory_bytes: 27964
#include <iostream>
#include <vector>
using namespace std;
#define ll long long

int main(){
  
  int n;
  cin >> n;
  
  vector<string> vec;
  for (int i=0;i<n;i++){
    string str;
    cin >> str;
    vec.emplace_back(str);
  }
  
  for (int i=1;i<n;i++){
    string str1 = vec[i-1];
    string str2 = vec[i];
    if (str1.back()!=str2.front()){
      cout << "No";
      return 0;
    }
    
    for (int j=0;j<i;j++){
      if (vec[i]==vec[j]){
        cout << "No";
      return 0;
      }
    }
    
  }
  
  cout << "Yes";
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef pair<int,pii> state;

const int MAX_N = 100;
const int MAX_H = 24;
const int MAX_K = 8;

struct edge{
  int to,cost,hour,col;
  edge(int a=0,int b=0, int c=0, int d=0):
    to(a),cost(b),hour(c),col(d){}
};

int N,M,K,C,S,T,H;
vector<edge> g[MAX_N+1];
int a,b,c,m,h;
int s,d,k;
int comb[1<<MAX_K];
int dis[MAX_H+1][MAX_N+1];

int main(){
  while(scanf("%d%d%d%d",&N,&M,&H,&K)>=0){
    if(N==0 && M==0 && H==0 && K==0)break;

    rep(i,N)g[i+1].clear();

    rep(i,M){
      scanf("%d%d%d%d%d",&a,&b,&c,&h,&m);
      g[a].pb(edge(b,c,h,m-1));
      g[b].pb(edge(a,c,h,m-1));
    }
    scanf("%d%d",&S,&T);

    scanf("%d",&C);

    memset(comb,-1,sizeof(comb));
    comb[0] = 0;
    rep(i,C){
      scanf("%d%d",&s,&d);
      int bit = 0;
      rep(i,s){
	scanf("%d",&k); k--;
	bit |= 1<<k;
      }
      comb[bit] = (comb[bit]<0?d:min(comb[bit],d));
    }

    rep(i,1<<K){
      if(comb[i]<0)continue;
      rep(j,1<<K){
	if(comb[j]<0)continue;

	int nxt = i|j;
	if(comb[nxt]<0 || comb[nxt] > comb[i] + comb[j]){
	  comb[nxt] = comb[i] + comb[j];
	}
      }
    }

    int ans = -1;
    rep(bit,1<<K){
      if(comb[bit]<0)continue;
      if(ans>=0 && ans<=comb[bit])continue;

      priority_queue<state> q;
      q.push(state(0,pii(0,S)));
      memset(dis,-1,sizeof(dis));
      dis[0][S] = 0;
      
      while(q.size()){
	state p = q.top(); q.pop();
	int cost = -p.first;
	int t = p.second.first, v = p.second.second;
	
	if(dis[t][v]<cost)continue;
	if(v==T)break;

	rep(i,g[v].size()){
	  int nxtv = g[v][i].to, nxtt = t+g[v][i].hour;
	  if(nxtt>H)continue;

	  int nxtcost = cost;
	  if( !((bit >> g[v][i].col) & 1) )nxtcost += g[v][i].cost;
	  
	  if(dis[nxtt][nxtv]<0 || dis[nxtt][nxtv] > nxtcost){
	    dis[nxtt][nxtv] = nxtcost;
	    q.push(state(-nxtcost, pii(nxtt,nxtv)));
	  }
	}
      }

      int val = -1;
      rep(i,H+1){
	if(val<0 || (dis[i][T]>=0 && val>dis[i][T]))val = dis[i][T];
      }
      if(val<0)continue;
      val += comb[bit];
      if(ans<0 || ans>val)ans = val;
    }
    
    cout << ans << endl;
  }
}

Measured memory_bytes: 1360
import scala.io.StdIn.readInt
import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args:Array[String]) = {
    val b = new ArrayBuffer[Int]
    var n = 0
    while({n=readInt;n} != 0) {
      val m = { for(i<-1 to n) yield readInt }.sorted.dropRight(1).drop(1)
      b += m.sum/m.length
    }
    println(b.mkString("\n"))
  }

}

Measured memory_bytes: 43768
while True:
    n,k = map(int,input().split())
    if n==0 and k==0:
        break
    a = []
    for i in range(1,n+1):
        a.append(int(input()))
        i += 1
    max = sum(a[0:k])
    b = sum(a[0:k])
    for j in range(0,n-k):
        c = b-a[j]+a[j+k]
        b = c
        if c > max:
            max = c
    print(max)


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

int main(){
	int n, m;
	cin >> n >> m;
	vector<int> h(n);
	vector<bool> isgood(n, true);
	for(int i=0; i<n; i++){
		cin >> h[i];
	}
	while(m--){
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		if(h[a] > h[b]){
			isgood[b] = false;
		}
		if(h[b] > h[a]){
			isgood[a] = false;
		}
		if(h[a] == h[b]){
			isgood[a] = false;
			isgood[b] = false;
		}
	}
	int res = 0;
	for(int i=0; i<n; i++){
		if(isgood[i]){
			res++;
		}
	}
	cout << res << "\n";
}

Measured memory_bytes: 3732
from functools import*
@lru_cache(None)
def solve(n,m):
  if not n:return 1
  n%=m
  return-~solve(n,bin(n).count('1'))
n=int(input())
s=input()
a=int(s,2)
*x,=map(int,s)
h=sum(x)
try:a,b=a%(h-1),a%(h+1)
except:b=a%(h+1)
for i in range(n):
  if x[i]:
    if not h-1:
      print(0)
      continue
    x[i]=0
    t=(a-pow(2,~i+n,h-1))%(h-1)
  else:
    x[i]=1
    t=(b+pow(2,~i+n,h+1))%(h+1)
  r=solve(t,bin(t).count('1'))
  x[i]^=1
  print(r)

Measured memory_bytes: 97948
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		if (N ==1) {
			System.out.println(M);
			return ;
		}
		for (int i=M/N;i>=0;i--) {
			if (M%i==0) {
				System.out.println(i);
				return ;
			}
		}
	}
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n; cin>>n;
	vector<int> a(n);
	map<int, int> mp;
	ll ans = 0;
	for(auto &x : a){
		cin>>x;
		ans += mp[x];
		mp[x]++;
	}
	for(int i = 0; i < n; i++){
		cout<<ans - mp[a[i]] + 1<<'\n';
	}

	return 0;
}

Measured memory_bytes: 8320
#include<bits/stdc++.h>
using namespace std;
struct str{
	int a[2];
	char c;
} s[300010];
int head,tail,tot,q,t,f;
bool r;
char ss[300010],cc[1];
void bck(char c){
	s[tot].c=c;
	s[tail].a[r]=tot;
	s[tot].a[!r]=tail;
	s[tot].a[r]=0;
	tail=tot;
	++tot;
}
void beg(char c){
	s[tot].c=c;
	s[head].a[!r]=tot;
	s[tot].a[r]=head;
	s[tot].a[!r]=0;
	head=tot;
	++tot;
}
void rev(){
	r=!r;
	swap(head,tail);
}
int main()
{
	scanf("%s",ss);
	head=tail=tot=1;
	r=false;
	for(int i=0;i<strlen(ss);++i) bck(ss[i]);
	scanf("%d",&q);
	while(q--){
		scanf("%d",&t);
		if(t==1) rev();
		else{
			scanf("%d%s",&f,cc);
			if(f==1) beg(cc[0]);
			else bck(cc[0]);
		}
	}
	int p=head;
	while(p){
		printf("%c",s[p].c);
		p=s[p].a[r];
	}
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define out return 0
#define pii pair<ll,ll>
#define ll long long int
using namespace std;
ll mn=1e18,mx=-1e18;
const ll mv=1000005;
ll n,l,a[mv],sum,ch,f,b;
vector<ll> ans;
int main(){
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);
	cin>>n>>l;
	b=n-1;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n-1;i++){
		if(a[i]+a[i+1]>=l){
			f=i;
			ch=1;
			break;
		}
	}
	if(!ch){
		cout<<"Impossible";
		out;
	}
	cout<<"Possible\n";
	for(int i=1;i<=f;i++){
		cout<<i<<"\n";
	}
	for(int i=n-1;i>=f+1;i--){
		cout<<i<<"\n";
	}
}

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

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

constexpr ll mod = 998244353;
constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());


unordered_map<ll, ll> minvmap;
ll minv(ll a, ll m) {
  auto k = a; auto p = minvmap[a]; if (p != 0) return p;
  ll b = m, u = 1, v = 0;
  while (b) { ll t = a/b; swap(a -= t*b, b); swap(u -= t*v, v); }
  p = (u%m+m)%m; minvmap[k] = p; return p;
}
struct mint {
    ll x;
    mint():x(0){}
    mint(ll x):x((x%mod+mod)%mod){}
    mint& fix() { x = (x%mod+mod)%mod; return *this;}
    mint operator-() const { return mint(0) - *this;}
    mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
    mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
    mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
    mint& operator/=(const mint& a){ (x*=minv(a.x, mod))%=mod; return *this; }
    mint operator+(const mint& a)const{ return mint(*this) += a;}
    mint operator-(const mint& a)const{ return mint(*this) -= a;}
    mint operator*(const mint& a)const{ return mint(*this) *= a;}
    mint operator/(const mint& a)const{ return mint(*this) /= a;}
    bool operator<(const mint& a)const{ return x < a.x;}
    bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}

int MAXN = 3000000;
// factorial
vector<mint> fact(MAXN+1);
void init() {
  fact[0] = 1;
  for(int i=1; i<=MAXN; i++) fact[i] = fact[i-1]*i;
}

// nCr
mint comb(int n, int r) {
  if (n < r || n < 0 || r < 0) return 0;
  return fact[n]/(fact[r]*fact[n-r]);
}

signed main() {
  SPEED;
  int n, m; cin >> n >> m;
  init();

  mint all = comb(3*m+n-1, n-1);

  mint ng1 = 0;
  for(int i=m-1; i>=0; i--) {
    mint tmp = comb(i+n-2, n-2);
    ng1 += tmp*n;
  }

  mint ng2 = 0;
  for(int i=m+1; i<=n; i++) {
    if ((3*m-i)%2!=0) continue;
    int r = (3*m-i)/2;
    if (r<0) continue;
    mint tmp = comb(r+n-1, n-1);
    tmp *= comb(n, i);
    ng2 += tmp;
  }
  debug(ng2.x);
  cout << all-ng1-ng2 << endl;

}

Measured memory_bytes: 63248
#include<iostream>

using namespace std;

#define ll long long 

int main () {
  ll n, m, q;
  cin >> n >> m >> q;
  ll s[n], t[m];
  for (ll i = 0; i < n; i++) {
    cin >> s[i];  
  }  
  for (ll i = 0; i < m; i++) {
    cin >> t[i];      
  }
  ll x[q];
  for (ll i = 0; i < q; i++) {
    cin >> x[i];  
  }
  for (ll i = 0; i < q; i++) {
    ll sub = x[i];
    // どこより大きいかを示す．
    ll left = -1;
    ll right = n;
    ll middle;
    while (left < right - 1) {
      middle = (right + left) / 2;
      if (s[middle] < sub) {
        left = middle;  
      }    
      else {
        right = middle;  
      }
    }  
    ll sss = left;
    left = -1;
    right = m;
    while (left < right - 1) {
      middle = (right + left) / 2;
      if (t[middle] < sub) {
        left = middle;  
      }  
      else {
        right = middle;  
      }
    }
    ll ss = left;
    ll min = - 1;
    for (ll j = 0; j < 2; j++) {
      for (ll l = 0; l < 2; l++) {
        if (sss + j >= 0 && sss + j <= n - 1 && ss + l >= 0 && ss + l <= m - 1) {
          ll a = s[sss + j];
          ll b = t[ss + l];
          if (a < b) {
            swap(a, b);  
          }
          if (sub <= b) {
            ll max = a - sub;
            if (max <= min || min == -1) {
              min = max;  
            }  
          }

          else if (sub <= a && sub >= b) {
            ll max;
            if (a - sub >= sub - b) {
              max = (sub - b) * 2 + (a - sub);  
            }  
            else {
              max = (a - sub) * 2 + (sub - b);  
            }
            if (min == -1 || max <= min ) {
              min = max;  
            }
          }

          else if (sub >= a) {
            ll max = sub - b;
            if (min == -1 || max <= min) {
              min = max;  
            }    
          }   
        }  
      }
    } 
      cout << min << endl;
  }

}

Measured memory_bytes: 3712
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
using namespace std;

#define INF 1e9
#define rep(i,j,n) for(int (i)=(j);(i)<(n);(i)++)
#define rep2(i,j,n) for(int (i)=(j);(i)<=(n);(i)++)
#define all(i) (i).begin(),(i).end()
#define rall(i) (i).rbegin(),(i).rend()

typedef long long i64;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<vs> vvs;

int main(){
  int n,k;
  cin>>n>>k;
  int ans=0;
  rep(i,0,n){
    int a;
    cin>>a;
    ans+=min(2*a,2*(k-a));
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
 
int A, B;


int main(void){
	
	scanf("%d %d", &A, &B);
	if(A % 2 == 1 && B % 2 == 1) printf("Yes\n");
	else printf("No\n");
	
    return 0;
}


Measured memory_bytes: 256
from fractions import gcd

A,B,C,D = map(int,input().split())

al = B-A+1

dic = B//C - (A-1)//C
did = B//D - (A-1)//D

g = gcd(C,D)
lcs = g * (C//g) * (D//g)

dicd = B//(lcs) - (A-1)//(lcs)

ans = al - (dic + did - dicd)

print(ans)

Measured memory_bytes: 5048
import sys
input = sys.stdin.readline

def binary_search_int(ok, ng):
    """
    :param ok: solve(x) = True を必ず満たす点
    :param ng: solve(x) = False を必ず満たす点
    """
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if solve(mid):
            ok = mid
        else:
            ng = mid
    return ok, ng

##############################################################

def solve(x):
    """ ある点 x を境にして True と False が二分されるような関数"""
    return N - K*x >= 0

N, K = map(int, input().split())

a, b = binary_search_int(0, 10**18)
print(min(abs(N-a*K), abs(N-b*K)))

Measured memory_bytes: 61900