akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,T,A,H;
  cin >> N >> T >> A;
  double h = (T - A) / 0.006;
  int c = 1;
  cin >> H;
  int Hc = H;
  for (int i = 2; i <= N; i++){
    cin >> H;
    if (abs(H - h) < abs(Hc - h)){
      Hc = H;
      c = i;
    }
  }
  cout << c;
}


Measured memory_bytes: 256
n=int(input())
a=[list(map(int, input().split())) for i in range(n)]
a=a[::-1]
count=0
for i in range(n):
    b=a[i][0]+count
    if b%a[i][1]!=0:
        count+=a[i][1]-b%a[i][1]
print(count)

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

int main() {
	int N;
	std::cin >> N;

	int result = 0;
	int count = 0;
	int before;
	int current;
	std::cin >> current;

	for(int i = 1; i < N; i++) {
		int H;
		std::cin >> H;

		before = current;
		current = H;

		if(before >= current) {
			count++;
			result = std::max(result, count);
		} else {
			count = 0;
		}
	}

	std::cout << result << std::endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <array>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <cctype>
#include <map>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>


#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define FOR(i,l,r) for(size_t i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)



using namespace std;

bool is_integer( float x ){
    return floor(x)==x;
}


int main() {
    char ch[101][101];

    int h,w;
    cin >> h >> w;

    for(int i = 0; i < h; i ++){
        for(int j = 0; j < w; j ++){
            cin >> ch[i][j];
        }
    }

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


    return 0;
}











Measured memory_bytes: 3600
I=N=9**9
P,M,L,R,U,*D='x+y,','x-y,',[],[],[]
for t in[*open(0)][1:]:*z,u=t.split();exec('%s+=[*map(int,z)],'%u)
for*A,S in(D,U,'x,y,'),(L,R,'y,x,'),(U,R,P+M),(L,D,P+M),(L,U,M+P),(D,R,M+P):
 n=p=-I
 for x,y,r in eval('sorted((%sQ)for Q,P in enumerate(A)for x,y in P)'%S):
  if r:n,p=x,y
  elif x==n:N=min(N,y-p)
print(N%I*5or'SAFE')

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
    string s;cin>>s;
    ll n=s.size();
    map<char,ll>a;
    rep(i,s.size()){
        a[s[i]]++;
    }
    sort(all(s));
    s.erase(unique(all(s)),s.end());
    ll ans=n*(n-1)/2+1;
    rep(i,s.size()){
        ans-=a[s[i]]*(a[s[i]]-1)/2;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<math.h>

using namespace std;
typedef long long ll;

int main(){
    ll a;
    double b;
    cin >> a >> b;
    ll c = b * 100 + 0.5;
    ll ans = (a * c) / 100;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3680
N,M=map(int,input().split())
a,b=[],[]
for i in range(N):
    s,t=map(int,input().split())
    a.append(s)
    b.append(t)
c,d=[],[]
for i in range(M):
    s,t=map(int,input().split())
    c.append(s)
    d.append(t)
for i in range(N):
    x,y=a[i],b[i]
    dist = []
    for j in range(M):
        z,w=c[j],d[j]
        dist.append(abs(x-z)+abs(y-w))
    print(dist.index(min(dist))+1)

Measured memory_bytes: 3064
import java.util.*;
import static java.lang.Integer.*;
//import static java.lang.Long.*;
//import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {

	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		int m = parseInt(sc.next());
		int a;
		int b;
		HashMap<Integer, ArrayList<Integer>> ab = new HashMap<>();
		for(i=0;i<n;i++) {
			a = parseInt(sc.next());
			b = parseInt(sc.next());
			if(!ab.containsKey(a)) {
				ab.put(a, new ArrayList<Integer>());
			}
			ab.get(a).add(b);
		}
		sc.close();
		PriorityQueue<Integer> pq = new PriorityQueue<>(new Comparator<Integer>() {
			@Override
			public int compare(Integer s1, Integer s2) {
				return s2.intValue() - s1.intValue();
			}
		});
		int ans=0;
		Integer po;
		j=0;
		for(i=1;i<=m;i++) {
			if(ab.get(i) != null) {
				pq.addAll(ab.get(i));
			}
			po = pq.poll();
			if(po != null) {
				ans += po;
			}
		}
		out.println(ans);
	}
}


Measured memory_bytes: 73736
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();// <10^5
        int m = sc.nextInt();// <10^9
        
        int gcd = IntStream.iterate(m / n, i -> i - 1)
                        .filter(i -> m % i == 0)
                        .findFirst()
                        .orElse(1);
        System.out.println(gcd);
    }
}


Measured memory_bytes: 28752
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define mp make_pair
#define pb push_back
#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)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {
	int x, a, b;
	cin >> x >> a >> b;
	if (abs(x - a) < abs(x - b))
		cout << "A" << endl;
	else
		cout << "B" << endl;

	return 0;
}

Measured memory_bytes: 256
import Control.Applicative
import Data.List
main = do
    n <- readLn
    putStrLn $ " " ++ intercalate " " [show x | x <- [1..(n :: Int)], mod x 3 == 0 || hasThreeIn x]

hasThreeIn :: Int -> Bool
hasThreeIn x = any (== '3') $ show x

Measured memory_bytes: 4060
#include <iostream>

using namespace std;

int main()
{
    int x=0,m=x,n;
    char s[100];
    cin>>n;
    cin>>s;
    for(int i=0;i<n;i++){
        if(s[i]=='I'){
            x++;
        }else{x--;}
        if(x>m){m=x;}
    }
    cout<<m;

}


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

using namespace std;

multiset<int> edges[523];

void erase(int v){
  while(edges[v].size()==1){
    int nv=*edges[v].begin();
    edges[nv].erase(edges[nv].find(v));
    edges[v].clear();
    v=nv;
  }
}    

int main(){
  int N,M;
  cin>>N>>M;
  for(int i=0;i<M;i++){
    int s,t;
    cin>>s>>t;
    edges[s].insert(t);
    edges[t].insert(s);
  }
  int ans=0;
  for(;;){
    int m=1e9;
    int x;
    for(int i=1;i<=N;i++){
      if(!edges[i].empty()&&edges[i].size()<m){
	m=edges[i].size();
	x=i;
      }
    }
    if(m>1e8)break;
    while(!edges[x].empty()){
      ans++;
      auto it=edges[x].begin();
      int t=*it;
      edges[x].erase(it);
      edges[t].erase(edges[t].find(x));
      erase(t);
      erase(x);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1496
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>

#define MOD 1000000007
#define ll long long

using namespace std;

ll N;
vector <ll> a;

int main(){
  ll inp;
  ll two=0,four=0;
  ll a;
  
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> N;
  for(ll i =0;i<N;i++){
    cin >> inp;
    inp%=4;
    if(inp == 2) two++;
    else if(inp== 0) four++;
  }

  if(two != 0){
    a = four*2+two;
    if(a >= N) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  else {
    a = four*2+1;
    if(a>=N) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  
  
  
  
  return 0;
}


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


int main() {
  int n, T;
  cin >> n >> T;
  int minv = 10000;
  rep(i,n){
    int c, t;
    cin >> c >> t;
    if(t<=T){
      minv = min(c,minv);
    }
  }
  if(minv==10000) cout << "TLE" << endl;
  else cout << minv << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 500006
using namespace std;
char s[N];long long f[1006],g[1006][26],a[26],l,r,x;
long long n,p,t,v[26],height[N],sa[N],fuckyouatcoder[N],tsa[N],cntA[N],cntB[N],A[N],B[N];
void SA()
{
	for(long long i=1;i<=n;i++)cntA[(long long)s[i]]++;
	for(long long i=1;i<N;i++)cntA[i]+=cntA[i-1];
	for(long long i=n;i;i--)sa[cntA[(long long)s[i]]--]=i;
	fuckyouatcoder[sa[1]]=1;
	for(long long i=2;i<=n;i++){
		fuckyouatcoder[sa[i]]=fuckyouatcoder[sa[i-1]];
		if(s[sa[i]]!=s[sa[i-1]])fuckyouatcoder[sa[i]]++;
	}
	for(long long l=1;fuckyouatcoder[sa[n]]!=n;l<<=1){
		for(long long i=0;i<N;i++)cntA[i]=cntB[i]=0;
		for(long long i=1;i<=n;i++){
			cntA[A[i]=fuckyouatcoder[i]]++;
			cntB[B[i]=(i+l<=n?fuckyouatcoder[i+l]:0)]++;
		}
		for(long long i=1;i<N;i++)cntA[i]+=cntA[i-1],cntB[i]+=cntB[i-1];
		for(long long i=n;i;i--)tsa[cntB[B[i]]--]=i;
		for(long long i=n;i;i--)sa[cntA[A[tsa[i]]]--]=tsa[i];
		fuckyouatcoder[sa[1]]=1;
		for(long long i=2;i<=n;i++){
			fuckyouatcoder[sa[i]]=fuckyouatcoder[sa[i-1]];
			if(A[sa[i]]!=A[sa[i-1]]||B[sa[i]]!=B[sa[i-1]])fuckyouatcoder[sa[i]]++;
		}
	}
	long long tot=0;
	for(long long i=1;i<=n;i++){
		if(tot)tot--;
		while(s[i+tot]==s[sa[fuckyouatcoder[i]-1]+tot])tot++;
		height[fuckyouatcoder[i]]=tot;
	}
	p=n;long long mi=N;
	for(long long i=fuckyouatcoder[1];i>=2;i--){
		mi=min(mi,height[i]);
		if(mi==n-sa[i-1]+1)p=min(p,sa[i-1]-1);
	}mi=N;
	for(long long i=fuckyouatcoder[1]+1;i<=n;i++){
		mi=min(mi,height[i]);
		if(mi==n-sa[i]+1)p=min(p,sa[i]-1);
	}
}
void wk(long long w,long long F)
{
	if(x==0)return;
	if(f[w]>x)
		if(w>2){wk(w-1,F);if(x)wk(w-2,F);}
		else{for(long long i=1;i<=x;i++)a[s[i]-97]+=F;x=0;}
	else{for(long long i=0;i<26;i++)a[i]+=F*g[w][i];x-=f[w];}
}
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1)/2;scanf("%lld%lld",&l,&r);s[n+1]='#';SA();s[n+1]=s[1];
	for(long long i=1;i<=p;i++)v[s[i]-97]++;
	if(n%p==0){
		if(r<=n)for(long long i=l;i<=r;i++)a[s[i]-97]++;
		else{
			if(l<=n)for(long long i=l;i<=n;i++)a[s[i]-97]++;
			else for(long long i=(l-n-1)%p+1;i<=p;i++)a[s[i]-97]++;
			r-=n;for(long long i=1;i<=(r-1)%p+1;i++)a[s[i]-97]++;
			for(long long i=0;i<26;i++)a[i]+=1LL*v[i]*((r-1)/p-(l<=n?0:(l-n-1)/p+1));
		}
	}else{
		f[1]=n;f[2]=n+p;
		for(long long i=1;i<=n;i++)g[1][s[i]-97]=++g[2][s[i]-97];
		for(long long i=0;i<26;i++)g[2][i]+=v[i];
		for(t=3;f[t-1]<r;t++){
			f[t]=f[t-1]+f[t-2];
			for(long long i=0;i<26;i++)g[t][i]=g[t-1][i]+g[t-2][i];
		}t--;
		x=r;wk(t,1);if(l>1)x=l-1,wk(t,-1);
	}
	for(long long i=0;i<25;i++)printf("%lld ",a[i]);printf("%lld\n",a[25]);
}

Measured memory_bytes: 23680
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

typedef pair<string,int> P;
typedef long long ll;

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
#define MOD 1000000007
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")



/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main() { 
  int n;cin>>n;
  vector<P> a(n);
  long long sm = 0;
  for(int i = 0; n > i; i++){
    cin>>a[i].first >> a[i].second;
    sm += a[i].second;
  }
  string x;cin>>x;
  for(int i = 0; n > i; i++){
    sm -= a[i].second;
    if (a[i].first == x){
      break;
    }
  }
  cout << sm <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define s second
#define f first
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define reset(a,b) memset(a,b,sizeof a)
#define ll long long
#define MOD 30013
#define MID (l+r)/2
#define ALL(x) x.begin(),x.end()
#define dalam fl<=l && r<=fr
#define kiwo 2*(idx),l,MID
#define tengen 2*idx+1,MID+1,r
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define mx 100000
#define pc(x) putchar_unlocked(x);

int cnt[40];

int main(){
	string ss;
	int n;
	cin>>ss;
	string sem=ss;
	if(ss.length()==26){
		int cnt=0;
		do{
			if(cnt==0){
				cnt++;
				continue;
			}
			int las=-1;
			for(int i=0;i<26;i++){
				las=i;
				if(ss[i]!=sem[i])break;
			}
			for(int i=0;i<=las;i++)
				cout<<ss[i];
			if(las!=-1){
				cout<<endl;
				return 0;
			}
			cout<<-1<<endl;
			return 0;
		}while(next_permutation(ALL(ss)));
			
		cout<<-1<<endl;	
		return 0;
	}
	for(char a:ss){
		cnt[a-'a']++;
	}
	cout<<ss;
	for(int i=0;i<26;i++){
		char a='a'+i;
		if(!cnt[i]){
			cout<<a<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
import collections
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("Yes")
    elif q == 0:print("No")
    exit(0)


"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


n = ip()                                     #入力整数1つ
#a,b,t= (int(i) for i in input().split())       #入力整数横2つ以上
a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#k = ip()                      #入力セット(整数改行あり)(1/2)
#v=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
if n==2:
    print(max(a))
else:
    ans = []
    s = [a[0]]
    for i in range(1,n):
        s.append(fractions.gcd(s[i-1],a[i]))
    r = [a[n-1]]
    for i in range(n-2,-1,-1):
        r.append(fractions.gcd(r[len(r)-1],a[i]))
    r = r[::-1]
 #   print(s,"from left")
 #   print(r,"from right")
    ans.append(r[1])
    for i in range(1,n-1):
        ans.append(fractions.gcd(s[i-1],r[i+1]))
    ans.append(s[n-2])
    print(max(ans))

Measured memory_bytes: 24140
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif
template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static void tp_swap(_T& right, _T& left) {
	//	usage:  tp_swap<type name>(a, b);
	_T tmp = right;
	right = left;
	left = tmp;
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}

static void ABC085C_Otoshidama();

#if 1
int main()
{
	ABC085C_Otoshidama();
	fflush(stdout);
	return 0;
}
#endif

static void ABC085C_Otoshidama()
{
	int N, Y;
	get2int(N, Y);

	int big = Y / 10000;
	int restY = Y % 10000;
	int mid = restY / 5000;
	restY = restY % 5000;
	int sml = restY / 1000;
	
	int nowBills = big + mid + sml;
	if (nowBills > N) {
		printf("-1 -1 -1\n");
		return;
	}
	int diff = N - nowBills;
	for (int b = 0; b <= big; b++) {
		for (int bb = 0; bb <= (big - b); bb++) {
			for (int m = 0; m <= (mid + (bb * 2)); m++) {
				int bills = (big - b - bb) + (b * 10) + (bb * 2) + (mid - m) + (m * 5) + sml;
				if (bills == N) {
					printf("%d %d %d\n", big - b - bb, mid + (bb * 2) - m, sml + b * 10 + m * 5);
					return;
				}
			}
		}
	}
	printf("-1 -1 -1\n");
}


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

if m <= n:
    print(0)
else:
    x.sort()
    diff = []#i番目とi+1番目の距離
    for i in range(m-1):
        diff.append(x[i+1] - x[i])
    diff.sort(reverse=True)
    # print(diff)
    if n > 1:
        for i in range(n-1):
            diff.pop(0)
    # print(diff)
    print(sum(diff))

Measured memory_bytes: 13968
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int[] B = nextIntArray(sc, N - 1);

		sc.close();

		int ans = 0;

		ans += B[0];
		for (int i = 1; i < N - 1; i++) {
			ans += Math.min(B[i - 1], B[i]);
		}
		ans += B[N - 2];

		out.println(ans);
	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
}


Measured memory_bytes: 21716
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
typedef long long ll;

int main(void)
{
    char s[200];
    int k;

    scanf("%d%s", &k, s);

    if (strlen(s) > k)
    {
        rep(i, k)
            printf("%c", s[i]);
        puts("...");
        return 0;
    }

    printf("%s", s);

    return 0;
}

Measured memory_bytes: 1692
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  int n ; 
  string s ;
  cin >> n >> s ;
  int W[n] = {INF} ;
  int E[n] = {INF} ;
  
  int W_now = 0;
  int E_now = 0;
  
  rep(i,n){
    if(s.at(i) == 'W')
       W_now ++;
    W[i] = W_now ;
  }
  
  for(int i=n-1;i>=0;i--){
    if(s.at(i) == 'E')
      E_now ++;
    E[i] = E_now;
  }
  

  int ans = INF ;
  rep(i,n){
    int now = 0;
    now = abs(W[i-1] + E[i+1]);
    ans = min(now,ans);
  }
  
  cout << ans ;
  
  
}


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

int main() {
  int N, D;
  cin >> N >> D;
  vector<int64_t> X(N), Y(N);
  vector<double> dis(N);
  int c = 0;
  for(int i = 0; i < N; i++){
    cin >> X.at(i) >> Y.at(i);
    dis.at(i) = (double)pow((X.at(i)*X.at(i) + Y.at(i)*Y.at(i)) ,0.5);
    
    if(dis.at(i) <= D) c++;
  }
  
  cout << c << endl;
}

Measured memory_bytes: 8008
import sys
A=[a.rstrip() for a in sys.stdin.readlines()]
N=int(A[0])
S="".join(["A",A[1]])

a=0
ans=S.count("R")*S.count("G")*S.count("B")

for i in range(1,N+1):
    for j in range(1,N+1):
        k=2*j-i
        if 1 <= k <= N and i < j < k:
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -= 1
print(ans)



Measured memory_bytes: 73672
#include <stdio.h>
#include <cassert>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>
#include <iomanip>
 
#ifdef LOCAL_CODE
	#define DEBUG(x) cerr << "[" << #x << '=' << x << "]" << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif
 
#define pb push_back
#define mp make_pair
#define ALL(x) (x).begin(), (x).end()
#define PER(i, N) for(int i = (N)-1; i >= 0; i--)
#define REP(i, N) for(int i = 0; i < (int)(N); i++)
using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.first >> p.second; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.first << ' ' << p.second; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
template<typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

ll n,m;//A,B,C,D;
int ans[222222][2];
int from[222222][2];
void solve(istream& cin, ostream& cout) {
	string T;
	cin >> T;
	int n = T.size();
	memset(ans, -1, sizeof(ans));
	ans[0][0] = -1;
	ans[0][1] = 0;
	from[0][0] = from[0][1] = -1;
	REP(i, n) {
		if(T[i] == 'P') {
			ans[i+1][0] = max(ans[i][0], ans[i][1]);
			if(ans[i][0] < ans[i][1]) from[i+1][0] = 1; else from[i+1][0] = 0;
			ans[i+1][1] = -1;
		} else if(T[i] == 'D') {
			ans[i+1][0] = -1;
			int C1 = ans[i][0] == -1 ? -1 : (ans[i][0]+2);
			int C2 = ans[i][1] == -1 ? -1 : (ans[i][1]+1);
			if(C1 < C2) from[i+1][1] = 1; else from[i+1][1] = 0;
			ans[i+1][1] = max(C1, C2);//ans[i][0] == -1 ? -1 : (ans[i][0]+2), ans[i][1] == -1 ? -1 : (ans[i][1]+1));
		} else {
			ans[i+1][0] = max(ans[i][0], ans[i][1]);
			if(ans[i][0] < ans[i][1]) from[i+1][0] = 1; else from[i+1][0] = 0;
			int C1 = ans[i][0] == -1 ? -1 : (ans[i][0]+2);
			int C2 = ans[i][1] == -1 ? -1 : (ans[i][1]+1);
			if(C1 < C2) from[i+1][1] = 1; else from[i+1][1] = 0;
			ans[i+1][1] = max(C1, C2);//ans[i][0] == -1 ? -1 : (ans[i][0]+2), ans[i][1] == -1 ? -1 : (ans[i][1]+1));
		}
	}
	int M = ans[n][0] > ans[n][1] ? 0 : 1;
	int P = n;
	while(P > 0) {
		if(M == 0) T[P-1] = 'P'; else T[P-1] = 'D';

		M = from[P][M];
		P--;
	}
	cout << T << endl;//max(ans[n][0], ans[n][1]);
}


int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	solve(cin, cout);
	/*
	{
		istringstream instr("2\n2\n14");
		solve(instr, cout);
	}
 */
	return 0;
}


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


#define	l_l_int	long long int
#define	SIZE	100000


// 末尾に追加
void Pushback(l_l_int *box, int soeji, int num)
{
	box[soeji] = num;
}


// 指定した場所にあるデータを表示
void Randomaccess(l_l_int *box, int soeji)
{
	printf("%lld\n", box[soeji]);
}


int main(void)
{
	char in_str[20];
	l_l_int *box, *tmp;
	int q;
	int command, num;
	int count, count2;
	int i;

	box = (l_l_int *)malloc(sizeof(l_l_int) * SIZE);

	fgets(in_str, sizeof(in_str), stdin);
	in_str[strlen(in_str) - 1] = '\0';
	sscanf(in_str, "%d", &q);

	count = count2 = 1;
	for(i = 0; i < q; i++){
		fgets(in_str, sizeof(in_str), stdin);
		in_str[strlen(in_str) - 1] = '\0';
		sscanf(in_str, "%d %d", &command, &num);

		if(command == 0){
			Pushback(box, count - 1, num);
			count++;
			if(count2 * SIZE < count){
				if( (tmp = (l_l_int *)realloc(box, sizeof(l_l_int) * (++count2 * SIZE))) == NULL){
					printf("realloc error\n");
					exit(1);
				}else
					box = tmp;
//				printf("SIZE「%d」を確保しました。\n", count2 * SIZE);
			}
		}else if(command == 1){

			Randomaccess(box, num);
		}else
			count--;
//		printf("count:%d\n", count);
	}

	return 0;
}


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

typedef unsigned long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

#define INF (int)(1e9)

#define rep(i,n) for(int i=0; i<(n); ++i)
#define REP(i,start,end) for(int i=(start);i<=(end);++i)
#define all(n) begin(n),end(n)

#define DEBUG

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	int x,a,b;
	cin >> x >> a >> b;

	x -= a;
	while(x - b >= 0)
	{
		x -= b;
	}

	cout << x << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	public static void solve() {
		long n=s.nextLong();
		long a=s.nextLong();
		long b=s.nextLong();
		long diff = Math.abs(b-a);
		if((diff&1)==0){
			out.println(diff/2L);
		}else {
			long min = Long.min(a,b);
			long max= Long.max(a, b);
			long left = min + (diff-1)/2L;
			long right = n-max+1 + (diff-1)/2L;
			out.println(Math.min(left, right));
		
		}
	}

	public static void main(String[] args) {
		out = new PrintWriter(new BufferedOutputStream(System.out));
		s = new FastReader();
		solve();
		out.close();
	}

	public static FastReader s;
	public static PrintWriter out;

	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	
}


Measured memory_bytes: 22996
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.container;
import std.datetime;

void main()
{
	auto n = readln.chomp.to!int;
	bool[string] ids;
	foreach (i; 0..n) {
		auto x = readln.chomp;
		ids[x] = 1;
	}
	auto m = readln.chomp.to!int;
	bool s;
	foreach (i; 0..m) {
		auto x = readln.chomp;
		if (ids.get(x, 0)) {
			if (s) writeln("Closed by ", x);
			else  writeln("Opened by ", x);
			s = !s;
		} else {
			writeln("Unknown ", x);
		}
	}
}

Measured memory_bytes: 1208
//#include <string>
//#include <set>
//#include <map>
//#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int inf = 0x7fffffff;
typedef long long ll;
void Faster( ){ ios_base::sync_with_stdio( false ); cin.tie( nullptr ); }
void iv( vector<int>& p ){ for( int& x: p ) cin >> x; }
void sa( vector<int>& p ){ sort( p.begin(), p.end() ); }
void pv( const vector<int>& p ){ for( int x: p ) cout << x << ' '; cout << '\n'; }

int main( ){
	Faster( );
	int x, a;
	cin >> x >> a;
	cout << (  (x < a) ? 0 : 10 );
	return 0;
}

// 08-06-2020
// Master Template 14
// kafiulshabbir@phystech.edu



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

constexpr int max_len = 1024;

int lcs(const string &s,const string &t){
    const int m=s.size(),n=t.size();
    vector<vector<int>> dp(m+1,vector<int>(n+1,0));

    for(int i=0;i<m;i++){
        for(int j=0;j<n;j++){
            if(s[i]==t[j])  dp[i+1][j+1] = dp[i][j] + 1;
            else            dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1]);
        }
    }

    return dp[m][n];
}

int main(){
    int n;cin>>n;
    for(int i=0;i<n;i++){
        string s,t;
        cin >> s >> t;
        cout << lcs(s,t) << endl;
    }
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define BiSearchRangeNum(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y)turn idx;
#define deg_to_rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad_to_deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)

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;
};

static const int mod = 1e9+7;

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

  ll ans = 1;
  vector<int> state(3, 0);
  rep(i, 0, N) {
    int a = A[i];
    int tmp = 0;
    bool flag = true;
    rep(j, 0, state.size()) {
      if (a == state[j]) {
        tmp += 1;
        if (flag) {
          state[j] += 1;
          flag = false;
        }
      }
    }

    ans *= tmp;
    ans %= mod;
  }

  cout << ans << endl;

};


Measured memory_bytes: 640
import math 
a,b,c=map(float,input().split())
d=a*a+b*b-2*a*b*math.cos(math.pi*c/180)
print(0.5*a*b*math.sin(math.pi*c/180))
print(a+b+d**0.5)
print(b*math.sin(math.pi*c/180))


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

#define co(x) cout << x << endl ;

int main ()
{
    int nump , costTR , costTX , cro ;

    cin >> nump >> costTR >> costTX ;

    cro = nump * costTR ;

    if (cro <= costTX) co (cro)
    else co (costTX)

    return 0 ;
}


Measured memory_bytes: 256
#N = int(input())
#a = [int(i) for i in input().split()]
#s = [[int(j) for j in input().split()] for i in range(N)]

N = int(input())
if N==1:
    print("Hello World")
else:
    a = int(input())
    b = int(input())
    print(a+b)


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

using vi = vector<int>; 
using vvi = vector<vi>;

int main() {
  int a, b, c;
  cin >> a >> b >>  c;
  if((c - (a-b)) <=0)
      cout << 0 << endl;
  else
    cout << c - (a-b) << endl;
  return 0;
}


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

using namespace std;

#define int long long

typedef long long int64;

signed main()
{
  int N, K;
  cin >> N >> K;
  vector< pair< int, int > > vs(N);
  for(int i = 0; i < N; i++) {
    int A, B;
    cin >> vs[i].first >> vs[i].second;
  }
  sort(begin(vs), end(vs));

  int64 sum = 0LL;
  for(auto &p : vs) {
    sum += p.second;
    if(sum >= K) {
      cout << p.first << endl;
      return (0);
    }
  }

}

Measured memory_bytes: 1792
N = int(input())
hs = list(map(int,input().strip().split()))

count = 0
flag = True

def split_zero(hs):
    lens = []
    tmp = []

    for i in range(0,N):
        if hs[i] == 0 and len(tmp) > 0:
            lens.append(tmp)
            tmp = []
        elif hs[i] > 0:
            tmp.append(hs[i])

    if len(tmp) > 0:
        lens.append(tmp)

    return len(lens)

def dec_array(hs):
    for i in range(0,N):
        hs[i] -= 1
        hs[i] = max(hs[i],0)
    return hs


count = 0
while any([h > 0 for h in hs]):
    count += split_zero(hs)
    hs = dec_array(hs)

print(count)

#00100111

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

#define MAX 1000001
int A[MAX];
int ans[MAX];

void mark(int x) {
    if (A[x] >= 2) ans[x] = 0;
    for (int i = 2; i <= MAX / x; i++) {
        if (A[x*i]) ans[x*i] = 0;
    }
}

void solve() {
    int n;
    cin >> n;
    rep(i, n) {
        int a;
        cin >> a;
        A[a]++;
        ans[a] = 1;
    }

    vector<int> cand;
    rep(i, MAX) {
        if (ans[i]) {
            cand.push_back(i);
        }
    }

    rep(i, cand.size()) {
        mark(cand[i]);
    }


    int cnt = 0;
    rep(i, MAX) {
        if (ans[i]) cnt++;
    }

    cout << cnt << endl;
}

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


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 1000005;
const int MAX_Q = 75;

int N;
string S;
int Q;
int K[MAX_Q];

int sumM[MAX_N];

class SlideMinDeque {
public:
    SlideMinDeque(int size) : _size(size) {
        deq.clear();
    }

    void add(int index) {
        deq.push_back(index);
    }

    int get(int index) { //何かを排出した
      int ret = -1;
      while(deq.size()) {
          if(deq.front() <= index-_size) {
              ret = deq.front();
              deq.pop_front();
          } else {
              return ret;
          }
      }
      return ret;
    }

    int getSize()
    {
      return deq.size();
    }

private:
    int _size;
    deque<int> deq; 
};

signed main()
{
  cin >> N;
  cin >> S;
  cin >> Q;
  REP(q,Q) {
    cin >> K[q];
  }

  REP(n,N) {
    sumM[n+1] = sumM[n] + (S[n] == 'M');
  }

  REP(q,Q) {
    SlideMinDeque deq(K[q]);
    int ans = 0;
    int tmp = 0;
    REP(n,N) {
      int r = deq.get(n);
      if(r >= 0) {
        tmp -= (sumM[n] - sumM[r]);
      }
      if(S[n] == 'D') {
        deq.add(n);
      }
      if(S[n] == 'M') {
        tmp += deq.getSize();
      }
      if(S[n] == 'C') {
        ans += tmp;
      }
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 17256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int Cin()
{
    int n;
    cin >> n;
    return n;
}

int main()
{
    int N = Cin(), M = Cin(), Q = Cin();
    // 二次元累積和
    vector<vector<int>> p(N + 1, vector<int>(N + 1, 0));
    for (int i = 1; i <= M; ++i)
    {
        int L = Cin(), R = Cin();
        ++p[L][R];
    }
    for (int i = 1; i <= N; ++i)
    {
        for (int j = 1; j <= N; ++j)
        {
            p[i][j] += p[i][j - 1];
        }
    }
    for (int i = 1; i <= N; ++i)
    {
        for (int j = 1; j <= N; ++j)
        {
            p[i][j] += p[i - 1][j];
        }
    }
    for (int i = 0; i < Q; ++i)
    {
        int L = Cin(), R = Cin();
        cout << p[R][R] - p[L - 1][R] - p[R][L - 1] + p[L - 1][L - 1] << endl;
    }
}


Measured memory_bytes: 1920
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#include <time.h>
#include <chrono>
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a,b) for(ll i=a;i>b;i--)
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define repl(i,l,r) for(int i=(1);i<(r);i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = (1LL << 31) - 1;
const ll mod = 1e9 + 7;

ll K, N, ans = 1;
ll sei[200001];
ll hu[200001];
ll pcnt, ncnt, zcnt;

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

	cin >> N >> K;
	FOR(i, 0, N) {
		ll cur; cin >> cur;
		
		if (cur >= 0) {
			sei[pcnt] = cur;
			pcnt++;
		}
		else {
			hu[ncnt] = cur;
			ncnt++;
		}
	}

	ll judge = 1;
	
	for (int i = 0; i <= min(ncnt,K); i += 2) {
		if (K - i <= pcnt)judge = 0;
	}
	//cout << judge << endl;

	ll pnow = 0, nnow = 0;

	if (judge == 0) {//正になる

		sort(sei, sei + pcnt);
		reverse(sei, sei + pcnt);
		sort(hu, hu + ncnt);

		while (K > 0) {

			if (K >= 2) {
				ll pp, nn;
				ll pflag = -1;
				if (pcnt >= 2) {
					pp = (sei[pnow] * sei[pnow + 1]);
					pflag = 1;
				}
				else if (pcnt == 1) {
					pp = sei[pnow];
					pflag = 0;
				}
				else {
					pp = -1e9;
				}

				if (ncnt >= 2) {
					nn = (hu[nnow] * hu[nnow + 1]);
				}
				else nn = -1e9;

				if (pp > nn) {
					if (pflag == 1) {
						
						pcnt -= 2; pnow += 2;
						ans = (((pp%mod)*ans)%mod+mod) % mod;
					}
					else {
						K++;
						pcnt--; pnow++;
						ans = (((pp%mod)*ans)%mod+mod) % mod;
					}
				}
				else {
					ncnt -= 2; nnow += 2;
					ans = (((nn%mod)*ans)%mod+mod) % mod;
				}
				K -= 2;

			}
			else if (K == 1) {
				ans = ((ans*sei[pnow])%mod+mod) % mod;
				K--;
			}
		}
		cout << (ans+mod)%mod << endl;

	}
	else if (judge == 1) {//負になるとき
		sort(sei, sei + pcnt);
		sort(hu, hu + ncnt);
		reverse(hu, hu + ncnt);

		ans = (hu[0] + mod) % mod;
		nnow++; ncnt--; K--;

		while (K > 0) {

			if (K >= 2) {
				ll pp, nn;
				ll pflag = -1;
				if (pcnt >= 2) {
					pp = (sei[pnow] * sei[pnow + 1]);
					pflag = 1;
				}
				else if (pcnt == 1) {
					pp = sei[pnow];
					pflag = 0;
				}
				else {
					pp = 1e18 + 1LL;
				}

				if (ncnt >= 2) {
					nn = (hu[nnow] * hu[nnow + 1]);
				}
				else nn = 1e18 + 1LL;

				if (pp < nn) {
					if (pflag == 1) {
						pcnt -= 2; pnow += 2;
						ans = ((pp%mod)*ans + mod) % mod;
					}
					else {
						K++;
						pcnt--; pnow++;
						ans = ((pp%mod)*ans + mod) % mod;
					}
				}
				else {
					ncnt -= 2; nnow += 2;
					ans = ((nn%mod)*ans + mod) % mod;
				}
				K -= 2;

			}
			else if (K == 1) {
				ans = (ans*sei[pnow] + mod) % mod;
				K -= 1;
			}




		}
		cout << (ans + mod) % mod << endl;
	}




}


Measured memory_bytes: 5164
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << 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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int x;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> x;
    int ans=1;
    for(int i=2;i<=x;i++){
        int temp=i*i;
        while(x>=temp){
            chmax(ans,temp);
            temp*=i;
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(ll i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<llint,llint>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 100000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0)return a;
	return gcd(b, a % b);
}

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b, ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}
int main() {
	llint n, k;
	cin >> n >> k;
	hei(llint) a(n);
	rep(i, 0, n) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	llint ans = (int)INF;
	rep(i, 0, n - k+1) {
		ans = min(ans, a[i + k-1] - a[i]);
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main() {
	int i, l, r, f1, f2, count1 = 0, count2 = 0;
	char S[100000];

	scanf("%s", &S);
	
	f1 = 1;
	for (i = 0; i < strlen(S); i++) {
		if (S[i] == '0')f2 = -1;
		else f2 = 1;
		if (f1 != f2) count1++;
		f1 *= -1;
	}

	f1 = -1;
	for (i = 0; i < strlen(S); i++) {
		if (S[i] == '0')f2 = -1;
		else f2 = 1;
		if (f1 != f2) count2++;
		f1 *= -1;
	}

	printf("%d\n", count1 < count2 ? count1 : count2);

	return 0;
}

Measured memory_bytes: 256
n = int(input())
d = [[] for i in range(n)]
for i in range(n-1):
  u, v, w = map(int, input().split())
  d[u-1].append([v-1, w])
  d[v-1].append([u-1, w])
  
ans = [[] for i in range(n)]
ans[0].append(0)
q = [0]

while q:
  x = q.pop()
  for u, w in d[x]:
    if not ans[u]:
      buf = ans[x][0]
      if w%2==1:
        buf = (buf+1)%2
      ans[u].append(buf)
      q.append(u)
    
for i in ans:
  print(*i)

Measured memory_bytes: 55360
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
int main(){
    int n;
    cin >> n;
    set<int>st;
    rep(i,n){
        int x;
        cin >> x;
        st.insert(x);
    }
    int ans = (int) st.size();
    if(ans%2==0)ans--;
    cout << ans << endl;
}

Measured memory_bytes: 4992
using System;
using System.Collections.Generic;
using System.Linq;

namespace ziyuutyou
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine().Split(' ');
            var a = int.Parse(str[0]);
            var b = int.Parse(str[1]);
            var c = int.Parse(str[2]);

            if(a == b && b== c)
            {
                Console.WriteLine(1);
            }
            else if(a == b || b == c || a == c)
            {
                Console.WriteLine(2);
            }
            else
            {
                Console.WriteLine(3);
            }
        }
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>
#include<utility>
#include<numeric>

#define PB push_back
#define all(a)  (a).begin(),(a).end()
#define ALL(v) begin(v), end(v)
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define V vector<int>
#define VV vector<V>
#define VVV vector<VV>

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int inf = (int)1e9;
const ll INF = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };
const long double EPS = 1e-10;

int main() {
	string s;
	cin >> s;
	cout << s.substr(0, s.length() - 8) << endl;
	return 0;
}

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

using namespace std;

int main(void)
{
  int n;
  cin >> n;
  set<int> a;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    a.emplace(tmp);
  }
  auto s = a.size();
  printf("%ld\n", s % 2 ? s : (s - 1));
}


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

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

	//string s;
	int n;

	//cin >> a >> b;
	cin >> n;
	
	//string ans="Yes";
	
	float ans=0;
	
	vector<int> a(n);
	rep(i,n){
		cin >> a[i];
	}
	
	float sum=0;//逆数の和
	rep(i,n){
		sum+=1.0/(float)a[i];
	}
	//cout << sum << "\n";
	
	ans=1.0/sum;
	
	cout << ans << "\n";
	
	
	return 0;

    }

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric> 
#include <math.h>

#define REP(i, n) for (int i = 0; i < n; i++)
#define INF 999999999
using namespace std;

int main()
{
    int x;
    cin >> x;
    x = abs(x);
    int ans = 0;
    int i = 1;
    while(true) {
        if(x <= 0) {
            break;
        }
        x = x - i;
        ans += 1;
        i++;
    }

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


Measured memory_bytes: 256