akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PA pair<int,int>
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
using namespace std;

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

int main(){
    int r,c,n; cin>>r>>c>>n;
    vector<PA> left,down,right,up;
    int x1,y1,x2,y2;
    FOR(i,0,n){
        cin>>x1>>y1>>x2>>y2;
        if(x1==0){
            left.PB(PA(y1,i));
        }else if(x1==r){
            right.PB(PA(-y1,i));
        }else if(y1==0){
            up.PB(PA(-x1,i));
        }else if(y1==c){
            down.PB(PA(x1,i));
        }
        if(x2==0){
            left.PB(PA(y2,i));
        }else if(x2==r){
            right.PB(PA(-y2,i));
        }else if(y2==0){
            up.PB(PA(-x2,i));
        }else if(y2==c){
            down.PB(PA(x2,i));
        }
    }
    sort(all(left));
    sort(all(right));
    sort(all(up));
    sort(all(down));
    vector<int> edge;
    FOR(i,0,left.size()) edge.PB(left[i].SE);
    FOR(i,0,down.size()) edge.PB(down[i].SE); 
    FOR(i,0,right.size()) edge.PB(right[i].SE);
    FOR(i,0,up.size()) edge.PB(up[i].SE);
    int count[100001]={};
    FOR(i,0,edge.size()) count[edge[i]]++;
    vector<int> edge2;
    FOR(i,0,edge.size()){
        if(count[edge[i]]>=2){
            edge2.PB(edge[i]);
        }
    }
    stack<int> s;
    FOR(i,0,edge2.size()){
        if(s.empty()||s.top()!=edge2[i]) s.push(edge2[i]);
        else s.pop();
    }
    YES(s.empty());

}


Measured memory_bytes: 4948
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

namespace ABC178
{
    class Program
    {
        static void Main(string[] args)
        {
            //var NXT = Console.ReadLine().Split().Select(double.Parse).ToArray();
            var N = long.Parse(Console.ReadLine());
            //var A = Console.ReadLine().Split().Select(long.Parse).ToArray();
            // var CA = Enumerable.Repeat(0, (int)N).Select(_ => Console.ReadLine().Split().Select(long.Parse).ToArray()).ToArray();
            //var L = Console.ReadLine().Split().Select(long.Parse).OrderBy(x => x).ToArray();
            if (N == 0) Console.WriteLine(1);
            else Console.WriteLine(0);

        }
    }
}


Measured memory_bytes: 27508
import qualified Data.Vector as V

main = do
    [n,m,k] <- map read . words <$> getLine
    print $ solve n m k

solve :: Int -> Int -> Int -> Int
solve n m k = foldl (\acc x -> acc +% x) 0 (map f [0..k])
    where f x = m *% (comb (n-1) x) *% ((m-1) ^% (n-1-x))

class (Integral a) => Modint a where
    p :: a
    modp :: a -> a
    (+%) :: a -> a -> a
    (-%) :: a -> a -> a
    (*%) :: a -> a -> a
    (^%) :: a -> a -> a
    inv :: a -> a
    (/%) :: a -> a -> a

instance Modint Int where
    p = 998244353
    modp a = mod a p
    a +% b = modp $ a+b
    a -% b = modp $ a-b
    a *% b = modp $ a*b
    a ^% 0 = 1
    a ^% x = let aa = modp $ (a ^% (div x 2)) ^ 2 in aa *% (a ^ (mod x 2))
    inv a = a ^% (p-2)
    a /% b = a *% (inv b)

facts :: V.Vector Int
facts = V.scanl (\acc x -> acc *% x) 1 $ V.generate 200200 (+1)
fact :: Int -> Int
fact = (facts V.!)

comb :: Int -> Int -> Int
comb n r
    | n < 0 || r < 0 || n < r = 0
    | otherwise = (fact n) /% (fact r) /% (fact $ n-r)

Measured memory_bytes: 22020
using System;
using System.Linq;
public class B{
    public static void Main(){
        int n = int.Parse(Console.ReadLine());
        int[] p = Console.ReadLine().Split(' ').Select(x=>int.Parse(x)).ToArray();
        int ans = 0;
        for (int i =1;i<n-1;i++){
            if ((p[i-1]<p[i] & p[i]<p[i+1]) | (p[i-1]>p[i] & p[i]>p[i+1])){
                ans++;
            } 
        }
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 13396
q,h,s,d = map(int,input().split())
n = int(input())
cheep = min((q*4),(h*2),s)
if cheep * 2 <= d:
  print(cheep*n)
else:
  n1 = n % 2
  print(n // 2 * d + n1 * cheep)


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = 10e15;
const ll MINF = -10e10;
const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;

int main() {
    int n;
    cin >> n;
    map<ll, int> sequences;
    rep(i, n) {
        ll a;
        cin >> a;
        sequences[a]++;
    }
    ll ans = 0;
    for (auto e : sequences) {

        ll a = e.first;
        ll count = e.second;
        if (a > count) {
            ans += count;
        } else {
            ans += (count - a);
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 6272
#include <iostream>
#include <cstdlib>

using namespace std;

bool t (int x, int n) {
	if (x == 0) 
		return true;
	if (n == 0) 
		return false;
	return t(abs(x-n) < x ? abs(x-n) : x, n-1);
}

int main () {

	int x;

	cin >> x;

	for (int i=0; i<=x; i++) {
		if ((i*(i+1))/2 >= x) {
			cout << i << endl;
			break;
		}
	}

	return 0;
}

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

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <int, ii> iii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
#ifdef VC
#define scanf scanf_s
#endif
#define iINF (1<<30)
#define INF (1LL<<59)
#define forn(i) for(int i = 0;i < n; ++i)
#define form(i,n) for(int i = 0 ;i < n; ++i)
#define NIL -1

const ll mod = 998244353;
int n;
int m;
int ans = 0;

int main(){
	ll a[100010];
	int j = 0, l,r;
	cin >> n;
	forn(i) {
		cin >> a[i];
	}
	sort(a, a+n);
	l = 0;
	r = n - 1;
	ll ans = 0;
	while (r-l>2) {
		ans += 2 * a[r];
		ans -= 2 * a[l];
		l++;
		r--;
	}
	ans = abs(ans);
	if (r - l == 2) {
		ans += max(2 * a[r] - a[l] - a[l + 1], a[r]+a[r-1]-2*a[l]);
	}
	else {
		ans += a[r] - a[l];
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  string S;
  cin >> S;
  for(int i = 0;i < 3;i++){
    if(S[i] == S[i + 1]){
      cout << "Bad" << endl;
      break;
    }
    else if(i == 2){
      cout << "Good" << endl;
    }
  }
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)

def dfs(now):
    for to,dis in G[now]:
        if color[to] == -1:
            color[to] = (color[now] + dis) % 2
            dfs(to)

N = int(input())
G = [[] for _ in range(N)]
color = [-1] * N
color[0] = 0 #偶数=0

for i in range(N-1):
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    G[a].append([b,c%2])
    G[b].append([a,c%2])

#print(G)    
dfs(0)
print(*color,sep="\n")

Measured memory_bytes: 82268
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( stdin . lock ( ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        n: usize,
        mut d: [u64;n]
    }

    d.sort();
    println!("{}", d[n/2]-d[n/2-1]);
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
#define all(v) v.begin(),v.end()
using namespace std;
const int mo=998244353;
const int N=3005;
int A,B,C,D,n;
int f[N][N];
int main(){
	cin>>A>>B>>C>>D;
	f[A][B]=1;
	For(i,A,C) For(j,B,D){
		f[i+1][j]=(f[i+1][j]+1ll*f[i][j]*j)%mo;
		f[i][j+1]=(f[i][j+1]+1ll*f[i][j]*i)%mo;
		f[i+1][j+1]=(f[i+1][j+1]+mo-1ll*f[i][j]*i*j%mo)%mo;
	}
	cout<<f[C][D]<<endl;
}

Measured memory_bytes: 38736
H,W = map(int,input().split())
S = [list(input()) for _ in range(H)]
from collections import deque
ans = 0
for i in range(H):
  for j in range(W):
    if S[i][j]=='#':
      continue
    inf = 10**5
    A = [[inf]*W for _ in range(H)]
    A[i][j]=0
    q = deque([[i,j]])
    while q:
      a = q.popleft()
      x=a[0]
      y=a[1]
      b = A[x][y]
      for m in [[x-1,y],[x+1,y],[x,y-1],[x,y+1]]:
        h = m[0]
        w = m[1]
        if (h<0)or(h>H-1)or(w<0)or(w>W-1):
          continue
        if S[h][w]=='#':
          A[h][w]=0
          continue
        c = b+1
        if c>=A[h][w]:
          continue
        A[h][w]=c
        q.append([h,w])
        
    A = [a for b in A for a in b if a!=inf]
    ans = max(ans,max(A))
    
print(ans)

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

using namespace std;
typedef long long ll;

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

    /*Solve*/

int main(){
    int a[3];
    rep(i,3){
        cin >> a[i];
    }
    sort(a,a+3,greater<>());
    cout << a[0]*10+a[1]+a[2];
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<cmath>
#include<deque>
#include<map>

using namespace std;
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define INF 1LL << 60
#define MAX 1000000000
const int MOD = 1000000007;
int gcd(int p, int q) { return p % q ? gcd(q, p % q) : q; }
long long modpow(long long a, long long n) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % MOD;
		a = a * a % MOD;
		n >>= 1;
	}
	return res;
}
ll dp[100001], s;
int main() {
	int N, K;
	scanf("%d%d", &N, &K);
	rep(l, 1, K + 1) {
		dp[l] += l;
		for (int m = l * 2; m <= K; m += l) {
			dp[m] -= dp[l];
		}
		s += modpow(K / l, N) * dp[l];
		s %= MOD;
	}
	printf("%lld\n", s);
	return 0;
}

Measured memory_bytes: 2508
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;
ll N, M, V, P;
//番兵を入れていなかったので添字の操作と二分探査が噛み合わずドチャクソ悩んだ
//要復習

bool check(ll mid){
    //vec[0]は番兵
    //vec[mid]がP番目に選ばれれば目的を満たせる
    //満たすような操作を考える
    //vec[mid]がP番目に入るためにはvec[P]より大きいスコアになる必要がある
    //とりあえず全員がvec[mid]に投票してスコアをMだけ上げる
    vector<ll > tmp = vec;
    //トータルの投票数
    ll tmpVM = V * M;
    //vec[mid+1]~vec[N]に関しては投票者が全員投票してもvec[mid]にスコアより
    //小さくなる. なぜなら vec[mid] >= vec[mid+1] ...降順に並んでいるから
    for(ll i = mid; i <= N; i++){
        if(tmpVM <= 0){
            break;
        }
        tmp[i] += M;
        tmpVM -= M;
    }
    //vec[1]~vec[P-1]はvec[mid]より大きくて構わない
    //なぜなら，vec[mid]がP番目であるとき,この範囲のスコアが高くなってもvec[P]
    //はP番目に選ばれるのは確実だから
    for(ll i = 1; i < P; i++){
        if(tmpVM <= 0){
            break;
        }
        tmp[i] += M;
        tmpVM -= M;        
    }

    //vec[P]~vec[mid-1]に関してはvec[mid]+Mを超えないように投票する必要がある
    //なぜなら，超えてしまうとvec[mid]はP番目に選ばれなくなるから
    for(ll i = P; i < mid; i++){
        if(tmpVM <= 0){
            break;
        }
        ll sabun = tmp[mid] - tmp[i];
        if(sabun < 0){
            //vec[mid]+Mがvec[P]のスコアを超えられないと絶対にP番目に選ばれない
            return false;
        } 
        tmp[i] += sabun;
        tmpVM -= sabun;        
    }    

    if(tmpVM > 0){
        //全員の投票権を使い切れていない
        //つまりvec[P]~vec[mid-1]でまだまで投票できるのでvec[mid]はP番目に選ばれない
        return false;
    }

    if(tmp[P] > tmp[mid]){
        return false;
    }

    return true;
}

int main() {

    cin >> N >> M >> V >> P;
    //配列で言うP-1までは採用対象

    for(ll i = 0; i < N; i++){
        ll t; cin >> t;
        vec.push_back(t);
    }
    //番兵
    vec.push_back(INF);
    sort(vec.rbegin(), vec.rend());

    //条件を満たすような最大値
    //絶対に1問は選べる
    ll left = 1; ll right = N + 1;
    while(left + 1 < right){
        ll mid = (left + right) / 2;
        //cout << "mid" << mid << endl;
        if(check(mid)){
            left = mid;
        }else{
            right = mid;
        }
        
    }
    cout << left << endl;

}

Measured memory_bytes: 1908
#include<iostream>
using namespace std;
int N,ev,od;
main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		int a;cin>>a;
		(a%2?od:ev)++;
	}
	cout<<(od==0||ev==0?0:od%2?N-1:N-2)<<endl;
}


Measured memory_bytes: 3108
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        var input = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        var n = input[0];
        var a = input[1];
        var b = input[2];

        var result = n / (a + b) * a + Math.Min(a, n % (a + b));
        Console.WriteLine(result);
    }
}

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

void findNumberOfDigits(ll n, ll base)
{
    ll dig = (ll)(floor( log(n) / log(base)) + 1);

    cout << dig<<endl;
}

int main()
{
    ll n,b;
    cin>>n>>b;

    findNumberOfDigits(n, b);
    return 0;
}



Measured memory_bytes: 256
module Main where

import Data.Functor
import Data.List

main :: IO ()
main = do
  { xs <- getInts
  ; let result = sort xs
  ; putInts result
  }

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show

Measured memory_bytes: 3604
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
int main()
{
	string a, b, c;
	cin >> a >> b >> c;
	char dif = 'A' - 'a';
	printf("%c%c%c",a[0] + dif,b[0] + dif,c[0] + dif);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)
 
int main(void) {
  int n,k;cin>>n>>k;
  vector<int> sunuke(n,0);
  fr(i,k){
    int d;cin>>d;
    fr(j,d){
      int a;cin>>a;
      sunuke[a-1]++;
    }
  }
  int ans = 0;
  fr(i,n) if(sunuke[i]==0) ans++;

  
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3612
/*http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_B&lang=jp*/
#include<iostream>

using namespace std;

void println(int *a,int n){
    for(int i=0;i<n;i++){
        cout<<a[i];
        if(i<n-1){
            cout<<" ";
        }
    }
    cout<<endl;
}

int main()
{
    int n;
    int a[100];
    int count=0;

    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        int minj=i;
        for(int j=i+1;j<n;j++){
            if(a[j]<a[minj]){
                minj=j;
            }
        }
        if(i!=minj) {
            swap(a[i], a[minj]);
            count++;
        }
    }
    println(a,n);
    cout<<count<<endl;
    return 0;
}

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

using namespace std;

typedef pair<char, int> P;

int idx, N;

int solve(vector<P> &v)
{
    char c = v[idx].first, d = v[idx].second;
    
    idx++;
    if (isdigit(c)) {
        return c - '0';
    } else {
        int res = (c == '*');
        while (idx < N && d < v[idx].second) {
            if (c == '*') {
                res *= solve(v);
            } else {
                res += solve(v);
            }
        }
        return res;
    }
}

int main()
{
    while (cin >> N, N) {
        vector<P> v(N);
        string s;
        for (int i = 0; i < N; i++) {
            cin >> s;
            v[i] = P(s.back(), s.size()-1);
        }
        idx = 0;
        cout << solve(v) << endl;
    }
    return 0;
}

Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
           
#define pb push_back
#define PII pair<int,int>
           
#define VS vector<string>
#define VI vector<int>
#define ll long long int 
#define debug(x) cout << x << " :" <<#x << endl 
int main(void) {   
    int n;cin >> n;
    VI t(n);                                                                                                                               
    REP(i,n) cin >> t[i];
    int sum=0;     
    REP(i,n) {     
        sum += t[i];
    }      
    int m;cin >> m;
    int p,x;       
    REP(i,m) {     
        cin >> p >> x;
        cout << sum - t[p-1] + x << endl;
    }      
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1000000001;
const ll MOD = 1000000007;

int main(){
  int n;
  int table[300];
  fill(table, table+300,0);
  cin>>n;
  for(int i=1;i<300;i++){
    int k=1;
      while(k*i<300){
        table[k*i]++;
        k++;
      }
  }
  int cnt=0;
  for(int i=1; i<=n;i+=2)
    if(table[i]==8) cnt++;
    
  cout<<cnt<<endl;
}

Measured memory_bytes: 3676
from heapq import heapify, heappush, heappop
X, Y, A, B, C = map(int, input().split())
ps = list(map(int, input().split()))
qs = list(map(int, input().split()))
rs = list(map(int, input().split()))


rs.sort(key=lambda x: -x)
hp = []
hq = []
for p in ps:
    heappush(hp, p)
    if len(hp) > X:
        heappop(hp)

for q in qs:
    heappush(hq, q)
    if len(hq) > Y:
        heappop(hq)

for r in rs:
    if len(hq) < Y:
        heappush(hq, r)
    elif len(hp) < X:
        heappush(hp, r)
    elif hp[0] < hq[0]:
        heappush(hp, r)
        heappop(hp)
    else:
        heappush(hq, r)
        heappop(hq)

print(sum(hq) + sum(hp))


Measured memory_bytes: 122792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int X, N; cin >> X >> N;
  if(N==0){
    cout << X << endl;
    return 0;
  }
  int now=10000;
  int ans=1000;
  vector<pair<int,int>> A(103);
  for(int i=0;i<103;i++){
    A[i].first=i-1;
    A[i].second=1;
  }
  for(int i=0;i<N;i++){
    int p; cin >> p;
    A[p+1].second=0;
  }
  for(int i=0;i<103;i++){
    if(A[i].second==1){
      if(now>abs(A[i].first-X)){
        ans=A[i].first;
        now=abs(A[i].first-X);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
  
    

Measured memory_bytes: 3624
def resolve():
    N = int(input()[-1])
    hon = [2, 4, 5, 7, 9]
    pon = [0, 1, 6, 8]

    if N in hon:
        print('hon')
    elif N in pon:
        print('pon')
    elif N == 3:
        print('bon')

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 9176
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

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

int main(){
	string a, b;
	cin >> a >> b;
	if ((a == "H"&&b == "H") || (a == "D"&&b == "D")){
		cout << "H" << endl;
	}
	if ((a == "H"&&b == "D") || (a == "D"&&b == "H")){
		cout << "D" << endl;
	}

}

Measured memory_bytes: 256
N = int(input())
S = input()

wc = 0
rc = N - 1

cnt = 0
while True:
    while wc < N and S[wc] == "R":
        wc += 1

    while rc >= 0 and S[rc] == "W":
        rc -= 1

    if wc == N or rc == -1 or wc > rc:
        break

    cnt += 1
    wc += 1
    rc -= 1

print(cnt)

Measured memory_bytes: 9412
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a, b;
    cin >> a;
    cin >> b;
    if(a+b == 3) cout << 3 << endl; 
    if(a+b == 4) cout << 2 << endl; 
    if(a+b == 5) cout << 1 << endl; 
}

Measured memory_bytes: 256
n,m,x=map(int,input().split())
a=list(map(int,input().split()))
l=[]
r=[]
if x<a[0] or x>a[m-1]:
  print(0)
else:
  for i in range(m):
    if a[i]<x:
      l.append(a[i])
    else:
      r.append(a[i])
  print(min(len(l),len(r)))

Measured memory_bytes: 3060
import java.util.*;

public class Main {
	int INF = 1 << 24;
	
	class State implements Comparable<State>{
		int now,cost, time;

		public State(int now, int cost, int time) {
			this.now = now;
			this.cost = cost;
			this.time = time;
		}

		@Override
		public int compareTo(State o) {
			return this.cost - o.cost;
		}
	}
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			int l = sc.nextInt();
			int k = sc.nextInt();
			int s = sc.nextInt();
			int g = sc.nextInt();
			if((n|m|l|k|s|g) == 0) break;
			
			ArrayList<Integer> hos = new ArrayList<Integer>();
			hos.add(s);hos.add(g);
			for(int i = 0; i < l; i++){
				hos.add(sc.nextInt());
			}
			int [][] pass = new int[n][n];
			for(int i = 0; i < n; i++){
				Arrays.fill(pass[i], INF);
			}
			for(int i = 0; i < k; i++){
				int x = sc.nextInt();
				int y = sc.nextInt();
				int cost = sc.nextInt();
				pass[x][y] = cost;
				pass[y][x] = cost;
			}
			
			for(int j = 0; j < n; j++){
				for(int i = 0; i < n; i++){
					for(int K = 0; K < n; K++){
						pass[i][K] = Math.min(pass[i][K], pass[i][j] + pass[j][K]);
					}
				}
			}
			
			PriorityQueue<State> open = new PriorityQueue<Main.State>();
			open.add(new State(s, 0, m));
			int [][] close = new int[n][m+1];
			for(int i = 0; i < n; i++){
				Arrays.fill(close[i], INF);
			}
			
			for(int i = 0; i < m+1; i++){
				close[s][i] = 0;
			}
			int ans = INF;
			while(! open.isEmpty()){
				State now = open.poll();
				if(now.now == g){
					ans = now.cost;
					break;
				}
				
				for(int to: hos){
					if(pass[now.now][to] == INF) continue;
					if(pass[now.now][to] > m) continue;
					int value = pass[now.now][to] - now.time;
					int nexttime = 0;
					if(value < 0){
						value = 0;
						nexttime = now.time - pass[now.now][to];
					}
					int nextcost = now.cost + pass[now.now][to] + value;
					if(close[to][nexttime] <= nextcost) continue;
					open.add(new State(to, nextcost, nexttime));
					close[to][nexttime] = nextcost;
				}
			}
			System.out.println(ans == INF ? "Help!" : ans);
		}
	}
	
	public static void main(String [] args){
		new Main().doit();
	}
}

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

using namespace std;


string Formulation, StrNum1, StrNum2, StrSum, StrTmp;

void solve() {
	int index, len1, len2, maxLength, num1, num2, sum, a;
	string tmp;
	size_t pos;

	len1 = StrNum1.size();
	len2 = StrNum2.size();
	maxLength = max(len1, len2);
	for (int x = 0; x < 10; x++) {
		pos = StrSum.find('X',0);
		while ( pos != string::npos) {
			//cout << pos << endl;
			StrSum[pos] = x + '0';
			pos = StrSum.find('X', pos);
		}
		tmp = "";
		a = 0;
		for (index = 0; index < maxLength; index++) {
			if (index < len1 && index < len2) {
				num1 = (StrNum1[len1 - 1 - index] == 'X' ? x : StrNum1[len1 - 1 - index] - '0');
				num2 = (StrNum2[len2 - 1 - index] == 'X' ? x : StrNum2[len2 - 1 - index] - '0');
				sum = num1 + num2 + a;
			}
			else if (index < len1) {
				num1 = (StrNum1[len1 - 1 - index] == 'X' ? x : StrNum1[len1 - 1 - index] - '0');
				sum = num1 + a;
			}
			else if (index < len2) {
				num2 = (StrNum2[len2 - 1 - index] == 'X' ? x : StrNum2[len2 - 1 - index] - '0');
				sum = num2 + a;
			}

			a = 0;
			if (sum > 9) {
				a = 1;
				sum %= 10;
			}
			tmp += sum + '0';
		}
		if (a == 1) {
			tmp += '1';
		}
		reverse(tmp.begin(), tmp.end());
		//cout << "X=" << x << endl << "StrSum=" << StrSum << endl << "StrTmp=" << tmp << endl;
		if (tmp == StrSum) {
			cout << x << endl;
			return;
		}
		StrSum = StrTmp;
	}
	cout << "NA" << endl;
	return;
}

int main() {
	int i;

	while ( cin >> Formulation ) {
		//cout << Formulation << endl;
		StrNum1 = StrNum2 = StrSum = "";
		i = 0;
		while (Formulation[i] != '+') {
			StrNum1 += Formulation[i];
			i++;
		}
		i++;
		while (Formulation[i] != '=') {
			StrNum2 += Formulation[i];
			i++;
		}
		i++;
		while (Formulation[i] != '\0') {
			StrSum += Formulation[i];
			i++;
		}
		StrTmp = StrSum;
		solve();
		StrTmp = "";
	}

	return 0;
}


Measured memory_bytes: 3100
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
ab = [LIST() for _ in range(M)]

ab.sort(key=lambda x:x[1])
# print(ab)

tmp = ab[0][1]
count = 1
for i in range(M):
	a, b = ab.pop(0)
	# print(a, b)
	if a < tmp:
		continue
	else:
		tmp = b
		count += 1
print(count)


Measured memory_bytes: 31620
// ARC099E.cpp
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 770;

int n, m, color[MAX_N], cnt[2];
bool G[MAX_N][MAX_N], tmp[MAX_N << 1], pack[MAX_N << 1];

void dfs(int u, int col)
{
    color[u] = col, cnt[col == 1]++;
    for (int i = 1; i <= n; i++)
        if (G[u][i] == false && i != u)
            if (color[i] == col)
                puts("-1"), exit(0);
            else if (color[i] == 0)
                dfs(i, -col);
}

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1, u, v; i <= m; i++)
        scanf("%d%d", &u, &v), G[u][v] = G[v][u] = true;
    pack[0] = true;
    for (int i = 1; i <= n; i++)
        if (!color[i])
        {
            cnt[0] = cnt[1] = 0, dfs(i, 1);
            memset(tmp, false, sizeof(tmp));
            for (int j = 0; j <= n; j++)
                tmp[j + cnt[0]] |= pack[j], tmp[j + cnt[1]] |= pack[j];
            memcpy(pack, tmp, sizeof(pack));
        }
    int ans = 0x7fffffff;
    for (int i = 0; i <= n; i++)
        if (pack[i])
            ans = min(ans, i * (i - 1) / 2 + (n - i) * (n - i - 1) / 2);
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 768
//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector") 
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>


#define ll long long
#define int ll
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define ret(a) {cout << a; exit(0);}

using namespace std;

mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

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

const int N = 2e5 + 1;

int n, m, k;
int a[N];
string s;
bool was[N];
main(){
	ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
	ld a , b , x;
	cin >> a >> b >> x;	
	cout << setprecision(9) << fixed;
	ld y = 2.0 * x / (b * a);
	if(y <= a){
		ld alfa = atan(y / b);
		ld beta = 180.0 * alfa / acos(-1.0);
		cout << 90.0 - beta;
	}
	else{
		ld y = 2 * (a*a*b-x) / (a * a);
		ld alfa = atan(y / a);
		ld beta = 180.0 * alfa / acos(-1.0);
		cout << beta;
	}
}


Measured memory_bytes: 512
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

class UnionFindTree {
public:
    this(size_t n) {
        parent = iota(n).array();
        rank = new size_t[](n);
    }
    size_t find(size_t n) {
        if(n == parent[n]) {
            return n;
        } else {
            parent[n] = find(parent[n]);
            return parent[n];
        }
    }
    void unite(size_t n, size_t m) {
        auto p1 = find(n);
        auto p2 = find(m);
        if(n == m) {
            return;
        }
        if(rank[p1] < rank[p2]) {
            swap(p1, p2);
        }
        if(rank[p1] == rank[p2]) {
            ++rank[p1];
        }
        parent[p2] = p1;
    }
private:
    size_t[] parent;
    size_t[] rank;
}
unittest {
    auto uft = new UnionFindTree(10);
    foreach(i; iota(10)) {
        assert(uft.find(i) == i);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0).drop(1)) {
        uft.unite(i, i-3);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0)) {
        assert(uft.find(0) == uft.find(i));
    }
    foreach(i; iota(10).filter!(a => a%3 != 0)) {
        assert(uft.find(0) != uft.find(i));
    }
}

const real eps = 1e-10;

const long p = 1_000_000_000 + 7;

void main(){
    auto s = readln().chomp();
    writeln(s.canFind("AC")? "Yes": "No");
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include <cmath>
#include <ctype.h>
#include<vector>
using namespace std;
int N, M; 
int a[51], b[51], c[51], d[51];
int main() {
    cin >> N >> M;
    for(int i=0; i<N; ++i){
        cin >> a[i] >> b[i];
    }
    for(int i=0; i<M; ++i){
        cin >> c[i] >> d[i];
    }
    
    for(int i=0; i<N; ++i){
        int min=1000000000, dis=0, ans=0;
        for(int j=0; j<M; ++j){
            dis = abs(a[i]-c[j])+abs(b[i]-d[j]);
            if(min > dis) {
                min=dis;
                ans=j+1;
            }
        }
        cout << ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
var1 = list(map(int, input().split()))
N = var1[0]
M = var1[1]
C = var1[2]
B = list(map(int, input().split()))
A = []
result = 0
for i in range(N):
    A.append(list(map(int, input().split())))
for j in range(N):
    ans = 0
    for i in range(M):
        ans += A[j][i]*B[i]
    ans += C
    if(ans > 0):
        result+=1
print(result)

Measured memory_bytes: 3064
// **** WHEN THE GOING GETS TOUGH, THE TOUGH GETS GOING. ****

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >
//added two more functions to set
//(1)*(set.find_by_order(k))[kth element in the sorted set] 
//(2)set.order_of_key(k)[count of elements strictly less than k]

typedef vector< int > vi;
typedef vector< ll > lvi;
typedef vector< vi > vvi;
typedef vector< lvi > lvvi;
typedef pair< int,int > ii;
typedef pair< ll,ll > lii;
typedef vector<ii> vii;
typedef vector<lii> lvii;

#define min_prq(t) priority_queue<t,vector<t>,greater<t>>
#define max_prq(t) priority_queue<t>
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)//remember i is an iterator
#define present(c,x) ((c).find(x) != (c).end())//for sets,maps,multimaps
#define cpresent(c,x) (find(all(c),x) != (c).end())//for vectors
#define tc(t) int (t); cin>>(t);while((t)--)
#define ff first
#define ss second
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " is " << a << endl;
	err(++it, args...);
}

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
#define mod 1000000007
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------

ll mod_sum() { return 0LL; }
template<typename T, typename... Args>
T mod_sum(T a, Args... args) { return ((a + mod_sum(args...))%mod + mod)%mod; }

ll mod_product() { return 1LL; }
template<typename T, typename... Args>
T mod_product(T a, Args... args) { return (a*mod_product(args...))%mod; }
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------


signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);	
	ll n;
	cin>>n;
	ll ans=0;
	for (int i = 0; i < n; ++i)
	{
		ll x;
		cin>>x;
		ans=__gcd(ans,x);
	}
	cout<<ans<<endl;
	return 0;
}	

Measured memory_bytes: 256
#include <iostream>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;

int main(){
  int N;
  cin >> N;
  int a[N];
  rep(i, N)
    cin >> a[i];
  //ここまで入力

  //2で0,1,2(以上)回割り切れる整数の数を格納する
  int c0 = 0, c1 = 0, c2 = 0;
  rep(i, N){
    int count = 0;
    //2で何回割り切れるか
    while(a[i] != 0){
      if(a[i]%2 == 0){
	a[i] /= 2;
	count++;
      }
      //奇数になったら抜ける
      else
	break;
    }
    //カウント
    if(count == 0)
      c0++;
    else if(count == 1)
      c1++;
    else
      c2++;
  }

  //2で1回割り切れるものは左から並べる
  if(c1 > 0)
    //あとは，0回割り切れるものと2回割り切れるものを交互に並べる
    //0回割り切れるものの方が多ければ題意を満たさない
    if(c0 > c2)
      cout << "No" << endl;
    else 
      cout << "Yes" << endl;
  //2で1回割り切れるものがなければ
  else
    //2で2回以上割り切れるものの両端に0回割り切れるものを配置していけばよい
    if(c0 <= c2+1)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int moder = 1000000007;
int h,w;
int grid[1005][1005];
int dp[1005][1005];
int f(int y,int x){
	int&ret = dp[y][x];
	if(~ret) return ret;
	ret = 0;
	if(y<h && grid[y+1][x]==0) ret+=f(y+1,x);
	ret%=moder;
	if(x<w && grid[y][x+1]==0) ret+=f(y,x+1);
	ret%=moder;
	return ret; 
}
int main(){
	cin>>h>>w;
	for(int i=1; i<=h; i++){
		string s;
		cin>>s;
		for(int j=0; s[j]; j++){
			if(s[j]=='#') grid[i][j+1] = 1;
		}
	}
	memset(dp,-1,sizeof(dp));
	dp[h][w] = 1;
	cout<<f(1,1);
}

Measured memory_bytes: 11556
package main

import (
	"fmt"
)

func main() {
	var (
		d, c, x int
	)

	fmt.Scan(&d, &c, &x)

	if 0 <= (x-d) && (x-d) <= c {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}

}


Measured memory_bytes: 1772
n = int(input())
min = 100000
for i in range(1,n):
  a = i
  b = n-i
  f = []
  while a > 0:
    f.append(a%10)
    a //= 10
  while b > 0:
    f.append(b%10)
    b //= 10
  if min>sum(f):
    min = sum(f)
print(min)
    

Measured memory_bytes: 3060
#include<stdio.h>
int main(void)
{
	int dp[1000]={0};
	int n,i;

	scanf("%d",&n);
	dp[0]=1;
	dp[1]=1;
	for(i=2;i!=n+1;i++){
		dp[i]=dp[i-1]+dp[i-2];
	}
	printf("%d\n",dp[n]);
}

Measured memory_bytes: 1028
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll mod = 1e9 +7;
const ll MAXN = 1e6 + 5;

ll x[1000];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>x[i];
	}
	sort(x+1,x+1+n);
	ll p=x[n];
	ll res=INF,pos=1,ans=0;
	for(int i=1;i<=p;i++){
		ans=0;
		for(int j=1;j<=n;j++){
			ans+=(x[j]-i)*(x[j]-i);
		}
		if(ans<res){
			res=ans;
			pos=i;
		}
	} 
	cout<<res;
	return 0;
}


Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto n = readln.chomp.to!int;
  auto s = readln.chomp;
  if (n % 2 == 0 && s[0..n/2] == s[n/2..n]) {
    writeln("Yes");
  } else {
    writeln("No");
  }
}


Measured memory_bytes: 256
require "pp"

def read(arr)
  m = arr.shift.to_i
  sets = m.times.map do |i| 
    start_money = arr.shift.to_i
    year = arr.shift.to_i
    n = arr.shift.to_i
    ways = []
    n.times do |j| 
      ways << arr.shift.split.map(&:to_f)
    end 
    [start_money, year, ways]
  end 
end

def result(dataset)
  start_money = dataset[0]
  year = dataset[1]
  ways = dataset[2]
  #pp [start_money, year, ways]
  re = ways.map do |mode, rate, cost|
    #pp [mode, rate, cost]
    result = 0
    a = start_money
    b = 0
    if mode == 1.0
      year.times{
        b = (a * rate).floor
        a = a + b - cost
      }
      result = a
    else
      year.times{
        b += (a * rate).floor
        a = a - cost
      }
      result = a + b
    end 
    result
  end 
  #pp re
  re.max.to_i
end

#pp result([1000000, 5, [[0.0, 0.03125, 3000], [1.0, 0.03125, 3000]]])
read(STDIN.readlines).each{|i| pp (result i)}

Measured memory_bytes: 6308
import java.util.*;

public class Main {
    static int MOD = 1000000007;
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        long answer = 0;
        
        if (n == m) {
            answer = fact(n) * fact(m) % MOD * 2 % MOD;
        } else if (Math.abs(n - m) == 1) {
            answer = fact(n) * fact(m) % MOD;
        }
        
        System.out.println(answer);
    }
    
    public static long fact(int n) {
        long answer = 1;
        for (int i = 1; i <= n; i++) {
            answer = answer * i % MOD;
        }
        
        return answer;
    }
}


Measured memory_bytes: 21844
ENV[Z='RUBY_THREAD_VM_STACK_SIZE']||exec({Z=>'10000000'},'ruby',$0)

N, M = gets.split.map(&:to_i)

$g = Array.new(N){ [] }

M.times do |i|
  a, b = gets.split.map(&:to_i)
  a -= 1
  b -= 1
  $g[a] << b
  $g[b] << a
end

$color = Array.new(N, 0)

def is_bipartite_graph v, c
  
  # p [v,c]
  $color[v] = c
  
  $g[v].each do |w|
    
    return false if $color[w] == c
    return false if $color[w] == 0 && !is_bipartite_graph(w, -c)
  end
  return true
end

# p $g
# p $color
    
if is_bipartite_graph(0, 1)
  b = $color.count(1)
  w = N - b
  puts b * w - M
else
  puts N * ( N - 1 ) / 2 - M
end

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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;


signed main() {
  int64_t n,k,p;
  cin >> n >> k;
  list<int64_t> valueList;
  int64_t totalCurrent = 0;
  int64_t totalMax = 0;
  for(int64_t i=0;i<n;i++){
    cin >> p;
    valueList.push_back(p);
    totalCurrent += p;
    int size = valueList.size();
    if(size>k){
      totalCurrent -= valueList.front();
      valueList.pop_front();
    }
    if(totalCurrent>totalMax){
      totalMax = totalCurrent;
    }
  }
  cout << fixed << setprecision(10) << ((double)(totalMax+k))/2.0 << endl;
  return 0;
}


Measured memory_bytes: 9832
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}



int main(){
   string s;cin>>s;
   s[3] = '8';
   cout<<s;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<double> VD;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 18;
const int MAGIC = 150;
int n;
LL a[N];

LL f(int l, int r, LL zliva, LL sprava)
{
	if (l + 1 == r)
		return 0;

	LL res = LINF;
	FOR(m, l + 1, r)
		res = min(res, a[m] * (zliva + sprava)
			+ f(l, m, zliva, zliva + sprava)
			+ f(m, r, zliva + sprava, sprava));
	
	return res;
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	//freopen("In.txt", "w", stdout);
	
	cin >> n;
	n -= 2;
	LL ans = 0, x;
	cin >> x;
	ans += x;
	FOR(i, 1, n + 1)
		cin >> a[i];
	cin >> x;
	ans += x;
	ans += f(0, n + 1, 1, 1);
	cout << ans << endl;
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}


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

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

using namespace std;

int main(){
	int n;
	cin >> n;
	
	int red[102][2];
	int blue[102][2];
	REP(i,n) cin >> red[i][0] >> red[i][1];
	REP(i,n) cin >> blue[i][0] >> blue[i][1];
	
	REP(k,n-1){
		REP(i,n-1){
			if (max(red[i][0],red[i][1]) < max(red[i+1][0],red[i+1][1])){
				int tmp[2];
				tmp[0] = red[i][0]; tmp[1] = red[i][1];
				red[i][0] = red[i+1][0]; red[i][1] = red[i+1][1];
				red[i+1][0] = tmp[0]; red[i+1][1] = tmp[1];
			}
		}
	}
	
	REP(k,n-1){
		REP(i,n-1){
			if (min(blue[i][0],blue[i][1]) > min(blue[i+1][0],blue[i+1][1])){
				int tmp[2];
				tmp[0] = blue[i][0]; tmp[1] = blue[i][1];
				blue[i][0] = blue[i+1][0]; blue[i][1] = blue[i+1][1];
				blue[i+1][0] = tmp[0]; blue[i+1][1] = tmp[1];
			}
		}
	}
	
	/*REP(i,n) printf("(%d, %d) ",red[i][0],red[i][1]);
	cout << endl;
	REP(i,n) printf("(%d, %d) ",blue[i][0],blue[i][1]);
	cout << endl;*/
	
	int ans;
	
	REP(i,n){
		REP(k,n){
			if (red[i][0]<blue[k][0] && red[i][1]<blue[k][1]){
				ans++;
				//printf("(%d, %d) : (%d, %d)\n",red[i][0],red[i][1],blue[k][0],blue[k][1]);
				blue[k][0] = -1;
				blue[k][1] = -1;
				break;
			}
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <tuple>
#include <vector>

#define rep(i, n) for (int i = 0; (i) < (n); (i)++)
using namespace std;
using ll = long long;

int main(void) {
    int N, M;
    int ret = 1;
    cin >> N >> M;
    for(int i=1; i*i <= M; ++i) {
        if( M % i == 0) {
            if (i <= M/N && i > ret)
                ret = i;
            if (M/i <= M/N && M/i > ret)
                ret = M/i;
        }
    }
    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cassert>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n, k;
int st[100000];
int mid[100000];
int ed[100000];

int main() {
	int i;
	
	cin >> n >> k;
	if (k > (n + 1) / 2) { cout << -1 << endl; return 0; }
	
	int num = k;
	
	rep(i, n) { st[i] = num; num++; }
	
	rep(i, n - (2 * k - 1)) { mid[i] = num; num++; }
	for (i = n - (2 * k - 1) + k; i < n; i++) {
		mid[i] = num; num++;
	}
	for (i = n - (2 * k - 1); i < n - (2 * k - 1) + k; i++) {
		mid[i] = num; num++;
	}
	
	typedef pair<int, int> P;	//(val, pos)
	vector<P> vec;
	
	rep(i, n) {
		int lower = st[i] + mid[i];
		vec.push_back(P(lower, i));
	}
	sort(vec.begin(), vec.end(), greater<P>());
	
	num = k + 3 * n - 1;
	rep(i, vec.size()) {
		int pos = vec[i].second;
		if (st[pos] + mid[pos] > num) { assert(0); return 0; }
		ed[pos] = num; num--;
	}
	
	rep(i, n) {
		cout << st[i] << " " << mid[i] << " " << ed[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 4340