akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	_, a := readLengthAndSlice()

	m := make(map[string]int)
	for _, rate := range a {
		switch {
		case rate < 400:
			m["400"]++
		case rate < 800:
			m["800"]++
		case rate < 1200:
			m["1200"]++
		case rate < 1600:
			m["1600"]++
		case rate < 2000:
			m["2000"]++
		case rate < 2400:
			m["2400"]++
		case rate < 2800:
			m["2800"]++
		case rate < 3200:
			m["3200"]++
		default:
			m["free"]++
		}
	}
	x := len(m)
	y := m["free"]
	if y == 0 {
		println(x, x)
		return
	}
	if x == 1 {
		println(1, y)
		return
	}
	println(x-1, x-1+y)
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 640
H, W = map(int, input().split())
field = [list(map(int, input().split())) for _ in range(H)]
direction = []
h_flag = False
for i, line in enumerate(field):
    v_flag = False
    for j, coin in enumerate(line):
        if v_flag:
            coin += 1
        if h_flag and j == W-1:
            coin += 1

        if coin % 2 == 0:
            v_flag = False
            if j == W-1:
                h_flag = False
        else:
            if j == W-1:
                h_flag = True
                if i == H-1:
                    continue
                direction.append("{} {} {} {}".format(i+1,j+1,i+2,j+1))
                continue
            v_flag = True
            direction.append("{} {} {} {}".format(i+1,j+1,i+1,j+2))
print(len(direction))
for line in direction:
    print(line)


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

int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int main() {
  int k;
  cin >> k;
  int sum = 0;
  for ( int i = 0 ; i < k ; i++ ) {
    for ( int j = 0 ; j < k ; j++ ) {
      for ( int m = 0 ; m < k ; m++ ) {
        int a = gcd(i+1,j+1);
        sum+=gcd(a,m+1);
        
      }
    }
  }
  
  cout << sum << endl;
  
}

Measured memory_bytes: 3624
module module1
  sub main()
    dim str as string
    str = console.readline()
    dim a as string()
    a = split(str)
    dim b as string
    if a(0)>=a(1)*2 then
      b = a(0)-a(1)*2
      console.writeline(b)
    else
      console.writeline(0)
    end if
  end sub
end module

Measured memory_bytes: 13536
N, M = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
num = [0,2,5,5,4,5,6,3,7,6]

DP = [-1] * (N+1)
DP[0] = 0

for i in range(N+1):
    for j in range(M):
        n = num[A[j]]
        if i - n >= 0 and DP[i-n] != -1:
            DP[i] = max(DP[i], DP[i-n] * 10 + A[j])

print(DP[N])

Measured memory_bytes: 14516
#include <cstdio>
#include <vector>
const long long MOD = 1000000007;
int N, M, sg[16], c0[15], c1[15], e[16][16];
std::vector < int > V[16];
long long O = 0;
long long DFS(int k)
{
	if (k <= 2)
	{
		static long long H[15];
		static int T[15];
		H[0] = 1;
		for (int i = 1; H[i - 1] && i <= N - 1; i++)
			H[i] = H[i - 1] * ((1 << c0[i - 1]) - 1) * ((1 << c1[i - 1]) - 1) % MOD;
		T[N - 1] = 0;
		for (int i = N - 2; ~i; i--)
			T[i] = T[i + 1] + c0[i + 1] + c1[i + 1];
		long long O = 0;
		for (int i = 0; i <= N - 1 && H[i]; i++)
			O = (O + (H[i] << T[i])) % MOD;
		return O;
	}
	static int cnt[16];
	for (int i = 0; i <= N; i++)
		cnt[i] = 0;
	for (int i : V[k])
		cnt[sg[i]]++;
	static long long H[16], T[16];
	H[0] = 1;
	for (int i = 1; i <= N; i++)
		H[i] = H[i - 1] * ((1 << cnt[i - 1]) - 1) % MOD;
	T[N] = 1;
	for (int i = N - 1; ~i; i--)
		T[i] = (T[i + 1] << cnt[i + 1]) % MOD;
	long long U[16], O = 0;
	for (int i = 0; i <= N; i++)
		U[i] = H[i] * T[i] % MOD;
	for (int i = 0; i <= N; i++)
		if (U[i])
		{
			if (e[1][k])
				c0[i]++;
			if (e[2][k])
				c1[i]++;
			sg[k] = i;
			O = (O + U[i] * DFS(k - 1)) % MOD;
			if (e[1][k])
				c0[i]--;
			if (e[2][k])
				c1[i]--;
		}
	return O;
}
int main()
{
	scanf("%d%d", &N, &M);
	long long BASE = 1;
	for (int i = 1, u, v; i <= M; i++)
	{
		scanf("%d%d", &u, &v);
		BASE = BASE * 2 % MOD;
		if (u != 1 || v != 2)
		{
			V[u].push_back(v);
			e[u][v] = 1;
		}
	}
	printf("%lld\n", (BASE - DFS(N) + MOD) % MOD);
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<vector>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const long long mod = 1e9 + 7;
typedef struct que{string name; int time;}que;
#define l 100005
que Q[l];
int head, tail, n;

void enque(que x){
     Q[tail] = x;
     tail = (tail + 1) % l;
}

que deque(){
     que x = Q[head];
     head = (head + 1) % l;
     return x;     
}

int main(){
     int q, c, t=0;
     que tmp;
     cin >> n >> q;
     for(int i = 1; i<n+1; i++){
          cin >> Q[i].name >> Q[i].time;
     }
     head = 1; tail = n+1;
     while(head != tail){
          tmp = deque();
          c = min(q, tmp.time);
          tmp.time -= c;
          t += c;
          if(tmp.time > 0) enque(tmp);
          else{
               cout << tmp.name << " " << t << endl;
          }
     }
}


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

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

    if(A>=13){
        cout << B << endl;
    }
    else if(A>=6){
        cout << B/2 << endl;
    }
    else{
        cout << 0 << endl;
    }
}

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

using i64 = long long int;

int participants[303]={0}, indexes[303]={0};
bool closed[303]={0};

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> v(n, vector<int>());
    int ans = 0, maxi = 0;
    for(int i=0;i<n;++i){
        for(int j=0;j<m;++j){
            int a;
            cin >> a;
            v[i].push_back(a-1);
        }
        participants[v[i][0]]++;
        if(ans < participants[v[i][0]]){
            ans = participants[v[i][0]];
            maxi = v[i][0];
        }
    }

    closed[maxi] = true;
    for(int k=1;k<m;++k){
        for(int i=0;i<m;++i)participants[i] = 0;
        int tmp = 0;
        for(int i=0;i<n;++i){
            while(closed[v[i][indexes[i]]])
                indexes[i]++;
            participants[v[i][indexes[i]]]++;
            if(tmp < participants[v[i][indexes[i]]]){
                tmp = participants[v[i][indexes[i]]];
                maxi = v[i][indexes[i]];
            }
        }
        ans = min(ans, tmp);
        closed[maxi] = true;
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

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

  int s = 0;
  int n0 = n;
  for (size_t i = 0; i < 10; i++) {
    s += n % 10;
    n = n / 10;
    if (n == 0) {
      break;
    }
  }

  if (n0 % s == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>


int main(void)
{
	//変数の宣言
	int h,w;
	int i,j;
	int map[60][60];
	char temp;
	char dummy;
	int sum;
	int quex[3000];
	int quey[3000];
	int queb[3000];
	
	//データの読み込み
	scanf("%d %d",&h,&w);
	scanf("%c",&dummy);
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			scanf("%c",&temp);
			if(temp=='.'){
				map[i][j]=1;
			}else{
				map[i][j]=0;
			}
		}
		scanf("%c",&dummy);
	}
	
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	sum=0;
	
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			sum=sum+map[i][j];
		}
	}
	
	for(i=0;i<3000;i++){
		queb[i]=0;
	}
	quex[0]=0;
	quey[0]=0;
	queb[0]=1;
	map[0][0]=0;
	
	i=1;//書き込み用
	j=0;//読み込み用
	while(queb[j]!=0){
//		printf("x=%d,y=%d,b=%d\n",quex[j],quey[j],queb[j]);
		if(quex[j]==h-1&&quey[j]==w-1){
			printf("%d",sum-queb[j]);
			return 0;
		}
		if(quex[j]!=0&&map[quex[j]-1][quey[j]]==1){
			quex[i]=quex[j]-1;
			quey[i]=quey[j];
			queb[i]=queb[j]+1;
			map[quex[j]-1][quey[j]]=0;
			i++;
		}
		if(quex[j]!=h-1&&map[quex[j]+1][quey[j]]==1){
			quex[i]=quex[j]+1;
			quey[i]=quey[j];
			queb[i]=queb[j]+1;
			map[quex[j]+1][quey[j]]=0;
			i++;
		}
		if(quey[j]!=0&&map[quex[j]][quey[j]-1]==1){
			quex[i]=quex[j];
			quey[i]=quey[j]-1;
			queb[i]=queb[j]+1;
			map[quex[j]][quey[j]-1]=0;
			i++;
		}
		if(quey[j]!=w-1&&map[quex[j]][quey[j]+1]==1){
			quex[i]=quex[j];
			quey[i]=quey[j]+1;
			queb[i]=queb[j]+1;
			map[quex[j]][quey[j]+1]=0;
			i++;
		}
		j++;
	}
	
//	printf("計算部分終了\n");
	
	//出力
	
	printf("-1");
	
//	printf("結果の出力終了\n");
	
	return 0;
}

Measured memory_bytes: 256
def gcd(a,b):
    if a == 0:
        return b
    if b == 0:
        return a
    r = 1
    while r > 0:
        r = a % b
        a = b
        b = r
    return a


n = int(input())
A = [int(i) for i in input().split()]

L = [0] * n
L[0] = 0
L[1] = A[0]
for i in range(2,n):
    L[i] = gcd(L[i-1], A[i-1])

R = [0] * n
R[-1] = 0
R[-2] = A[-1]
for i in range(3,n+1):
    R[-i] = gcd(R[-i+1], A[-i+1])

M = [gcd(L[i],R[i]) for i in range(n)]

print(max(M))


Measured memory_bytes: 14436
fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val s = readLine()!!
    val cCnt = mutableListOf<Cnt>()

    var prev = Cnt(0, 0, 0)
    s.forEach {
        val newCnt = when(it) {
            'R' -> Cnt(prev.r+1, prev.g, prev.b)
            'G' -> Cnt(prev.r, prev.g+1, prev.b)
            'B' -> Cnt(prev.r, prev.g, prev.b+1)
            else -> return
        }
        cCnt.add(newCnt)
        prev = newCnt
    }

    var ans = 0L

    for (i in 0..n-3) {
        inner@for (j in i+1..n-2) {
            if (s[j] == s[i]) continue@inner

            val last = "RGB".filter { it != s[i] && it != s[j] }
            val diff = j-i
            val sub = if (j+j-i < n && s[j+j-i] == last[0]) 1 else 0

            when(last) {
                "R" -> ans += cCnt[n-1].r - cCnt[j].r - sub
                "G" -> ans += cCnt[n-1].g - cCnt[j].g - sub
                "B" -> ans += cCnt[n-1].b - cCnt[j].b - sub
                else -> return
            }
        }
    }

    println(ans)
}

data class Cnt(val r: Int, val g: Int, val b: Int)

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

long long solve(string S){
    string T = "";
    for(auto c:S)if(c!='x')T+=c;
    string T2 = T;
    reverse(T2.begin(),T2.end());
    if(T!=T2)return -1;
    
    int N = T.size();
    vector<long long> nums(N+1,0);
    int iter = 0;
    for(int i = 0; i < S.size();){
        int j = i;
        while(j < S.size() && S[j] == 'x')j++;
        nums[iter++]=j-i;
        i = j+1;
    }
    
    long long res = 0;
    for(int i = 0; i*2 < nums.size();i++){
        res += max(nums[i],nums[(int)nums.size()-i-1])
            -  min(nums[i],nums[(int)nums.size()-i-1]);
    }
    
    return res;
    
}


int main(){
    string S;
    while(cin >> S)cout << solve(S) <<endl;
    
    
}




Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define inter ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nuintptr)
	
using namespace std;


typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;

 
const ll MAX = 2e5+10;
const ll inf = 1e9+10;



int main(){
	fastio;
	string s;
	cin>>s;
	cout<<s.substr(0,3)<<endl;

}	

Measured memory_bytes: 3612
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

const double PI=acos(-1);
const double EPS=1e-9; //うまくいかなかったらゆるめる

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int n;
    cin >> n;
    vi a(n),b(n);
    rep(i,n)cin >> a[i] >> b[i];
    sort(all(a));
    sort(all(b));
    if(n%2){
        int l = a[n/2];
        int r = b[n/2];
        cout << r-l+1 << endl;
    }else{
        int l = a[n/2-1] + a[n/2];
        int r = b[n/2-1] + b[n/2];
        cout << r-l+1 << endl;
    }
}


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

int main() {
    int n;
    cin >> n;
    if(n%1000==0) {cout << 0 << endl; return 0;}
    int ans  =1000 -  n%1000;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int A, B;
  cin >> A >> B;
  cout << (A - 1) * (B - 1) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>

#include <climits>
#include <cmath>

//#include <show_vec.hh>

#define DEBUG if(false)

using namespace std;

int main(){

  int N;
  cin >> N;
  vector<pair<int, int>> X;
  vector<int> A(N, 0), B(N, 0);

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

  if(N % 2 == 0){
    // even
    int min = (A[N/2] + A[N/2 - 1]);
    int max = (B[N/2] + B[N/2 - 1]);
    cout << max - min + 1 << endl;
  }else{
    // odd
    int min = A[N/2];
    int max = B[N/2];
    cout << max - min + 1 << endl;
  }

  return 0;
}


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

using namespace std;

int main()
{
    int N, a[3];
    cin >> N;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> a[j];
        }
        sort(a, a + 3);
        cout << (a[0]*a[0] + a[1]*a[1] == a[2]*a[2] ? "YES" : "NO") << endl;
    }
    return 0;
}

Measured memory_bytes: 3036
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0;i < (int)(n);i++)
constexpr long long MOD = 1000000007;

signed main(){
	int N,K;
	cin>>N>>K;
	vector<int>p;
	for(int i=1;i*i<=N;i++){
		p.push_back(i);
		if(i != N/i)p.push_back(N/i);
	}
	sort(p.begin(),p.end());
	vector<int>mul;mul.push_back(1);
	REP(i,p.size()-1)mul.push_back(p[i+1]-p[i]);

	vector<int>dp(mul.size(),1);
	REP(i,K-1){
		vector<int>ndp(mul.size());
		int sum = 0;
		REP(j,mul.size()){
			(ndp[mul.size()-j-1] += dp[j] * mul[j] + sum) %= MOD;
			(sum += dp[j] * mul[j]) %= MOD;
		}
		dp = ndp;
	}
	int ans = 0;
	REP(i,mul.size())(ans += dp[i]*mul[i]) %= MOD;
	cout << ans << endl;
}

Measured memory_bytes: 2296
#include <bits/stdc++.h>
using namespace std;
typedef pair<string,string>P;
#define pb(a,b) push_back(P( a , b ))

string Replace(string S,string from,string to){
	int p=S.find(from);
	while(p!=string::npos){
		S.replace(p,from.size(),to);
		p=S.find(from,p+to.size());
	}
	return S;
}

vector<P>V;
void init(){
	for(char c='A';c<'Z';c++){
		string tmp="+",tmp2="";tmp+=c;tmp2+=(c+1);
		V.pb(tmp,tmp2);
	}
	V.pb("+Z","A");
	V.pb("+?","?");
	for(char c='Z';c>'A';c--){
		string tmp="-",tmp2="";tmp+=c;tmp2+=(c-1);
		V.pb(tmp,tmp2);
	}
	V.pb("-A","Z");
	V.pb("-?","?");
}

string Rep(string S){
	for(string tmp;true;){
		tmp=S;
		for(int i=0;i<V.size();i++){
			S=Replace(S,V[i].first,V[i].second);
		}
		if(tmp==S)break;
	}
	return S;
}

string Rev(string s){
	string S="";
	for(int i=0;i<s.size();i++){
		if(s[i]=='['){
			string tmp="";
			int flg=1;
			for(;true;i++){
				tmp+=s[i];
				if(s[i]==']')break;
				if(s[i+1]=='['){
					flg=0;
					break;
				}
			}
			if(flg){
				for(int j=tmp.size()-2;j>0;j--)S+=tmp[j];
			}
			else{
				S+=tmp;
			}
		}
		else{
			S+=s[i];
		}
	}
	return S;
}

int main(){
	init();
	for(string s;cin>>s,s!=".";){
		while(s.find("+")!=string::npos || s.find("-")!=string::npos || s.find("[")!=string::npos){
			s=Rep(s);
			s=Rev(s);
		}
		
		cout<<Replace(s,"?","A")<<endl;
	}
	return 0;
}


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

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  bool flag=false;
  if(abs(a-c)<=d) flag=true;
  else if(a<b && a+d>=b && b+d>=c && c>b) flag=true;
  else if(c<b && c+d>=b && b+d>=a && a>b) flag=true;
  if(flag) cout<<"Yes";
  else cout<<"No";
  cout<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

// p1>p2<p3>p4...
// p1-p2 + p3 - p2 + p3 - p4
// +p1 + 2*p3 -2*p2 -p4

// p1<p2>p3<p4
// p2-p1 + p2-p3 + p4-p3
// -p1 - 2*p3 + 2*p2 + p4

// p1>p2<p3>p4<p5...
// p1-p2 + p3 - p2 + p3 - p4 + p5 - p4
// +p1 + 2*p3 + p5 -2*p2 -2*p4 

// p1<p2>p3<p4>p5
// -p1 - 2*p3 - p5 + 2*p2 + 2*p4


ll solve(){
  ll N; cin>>N;
  ll a[N]; CINA(a,N);
  sort(a,a+N,greater<int>());
  ll ans = 0;
  
  
  if(N%2==0){
    for(int i=0;i<=N/2-2;++i){ ans += a[i]*2;}
    ans += a[N/2-1];
    ans -= a[N/2];
    for(int i=N/2+1;i<N;++i){ ans -= a[i]*2; }
  }else{
    ll m1=0,m2=0;
    for(int i=0;i<=N/2-2;++i){ m1 += a[i]*2;}
    m1 += a[N/2-1];
    m1 += a[N/2];
    for(int i=N/2+1;i<N;++i){ m1 -= a[i]*2; }
    
    for(int i=0;i<N/2;++i){ m2 += a[i]*2;}
    m2 -= a[N/2];
    m2 -= a[N/2+1];
    for(int i=N/2+2;i<N;++i){ m2 -= a[i]*2; }
    
    ans = max(m1,m2);
  }
  return ans;
}

int main(){
  cout << solve()<<"\n";
}

Measured memory_bytes: 1024
n=int(input())
a=[int(i) for i in  input().split()]
sigma=0
for i in a:
    sigma+=i
sigma/=2
sigma=int(sigma)

x=[sigma for i in range(n)]
g=1

for i in range(int((n-1)/2)):
    sigma-=a[g]
    g+=2
    
x[0]=sigma
for i in range(1,n):
    x[i]=a[i-1]-x[i-1]

        
        
x2=[str(i*2) for i in x]
print(" ".join(x2))

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

int main() {

	int n, m; cin >> n >> m;
	vector<vector<char>> a(n, vector<char>(n));
	vector<vector<char>> b(m, vector<char>(m));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < m; j++) {
			cin >> b[i][j];
		}
	}
	
	bool can = false;
	for (int i = 0; i < n - m + 1; i++) {
		for (int j = 0; j < n - m + 1; j++) {
			bool tmpCan =true;
			for (int y = 0; y < m; y++) {
				for (int x = 0; x < m; x++) {
					if (a[i + y][j + x] != b[y][x]) tmpCan = false;				
				}
			}
			if (tmpCan) can = true;
		}
	}
	if (can) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3536
#include<iostream>
using namespace std;
int off(int x)
{
	if(x>=0) return x;
	else return -x;
}
int main()
{
	long long m,n,sum=0;
	cin>>m>>n;
	if(m>n)
	{
		if(m!=0)
		{
			m=-m;
		    sum++;
		}
		if(m==0){
			n=-n;
			sum++;
		}
	}
	if(m*n<0) sum++;
	sum+=max(off(m),off(n))-min(off(m),off(n));
	cout<<sum;
	return 0;
}

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

int main()
{
    int n , x;
    while(1)
    {
        int ans = 0;
        cin >> n >> x;
        if(n == 0 && x == 0)
        {
            break;
        }
        for(int i = 1 ; i <= n;i++)
        {
            for(int j =i+1 ; j <= n;j++)
            {
                for(int m = j +1 ; m <= n; m++)
                {
                    if((i + j + m) == x)
                    {
                        ans++;
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3008
#include <stdio.h>

int main(void){
    char s[1000];
    int i = 0;
    int sum = 0;

    while(1){
        scanf("%s", s);
        if(s[0] - '0' == 0)
            break;

        while(s[i]){
            sum += s[i] - '0';
            i++;
        }
        printf("%d\n", sum);
        sum = 0;
        i = 0;
    }
    return 0;
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	llong N, Q;
	string s;
	vector<char> d, t;

	cin >> N >> Q >> s;
	d.resize(Q), t.resize(Q);
	for(int i = 0; i < Q; i++)
		cin >> d[i] >> t[i];

	int lastLG, lastRG;
	int ng, ok;

	ng = N,ok = -1;
	while(abs(ng-ok) != 1){
		int mid = (ng+ok)/2;
		int check = mid;
		for(int i = 0; i < Q; i++){
			if(s[check] == d[i]){
				if(t[i] == 'L') check--;
				else check++;
			}
			if(check == -1 || check == N)
				break;
		}
		if(check == -1)
			ok = mid;
		else
			ng = mid;
	}
	lastLG = ok;

	ng = -1,ok = N;
	while(abs(ng-ok) != 1){
		int mid = (ng+ok)/2;
		int check = mid;
		for(int i = 0; i < Q; i++){
			if(s[check] == d[i]){
				if(t[i] == 'L') check--;
				else check++;
			}
			if(check == -1 || check == N)
				break;
		}
		if(check == N)
			ok = mid;
		else
			ng = mid;
	}
	lastRG = ok;

	cerr << lastLG << " " << lastRG << endl;
	cout << lastRG - lastLG -1 << endl;

	return 0;
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	int n,x,t;
	cin>>n>>x>>t;
	int z = (n+x-1)/x;
	cout<<(z*t)<<"\n";
	return 0;
}

Measured memory_bytes: 3656
s = list(input())
hani = (ord("a"),ord("z"))

if s[0] != "A":
    print("WA")
    exit()

del s[0]
cc = 0
for i in range(1,len(s)-1):
    if s[i] == "C":
        cc+=1
        d = i
        

if cc != 1:
    print("WA")
    exit()

del s[d]

for i in s:
    if not hani[0] <= ord(i) <= hani[1]:
        print("WA")
        exit()

print("AC")


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

using namespace std;

#define INF 2000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;


int main()
{
	int a, b;
	cin >> a >> b;

	int ans = 0;

	for (int i = a; i <= b; ++i) {
		if ((i/10000==i%10) && ((i/1000%10) ==(i/10%10))) {
//			cout << i << " " << i/10000 << " " << i%10 << " " << i/1000%10 << " " << i/100%10 << "\n";
			ans++;
		}
	}


	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
 
#define rp(i, k, n) for (int i = k; i < n; i++)
using ll = long long;
using ld = double;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;

int main() {
    int n, t;
    cin >> n >> t;
    vector<pair<int, int>> food;
    rp(i, 0, n) {
        int a, b; cin >> a >> b;
        food.emplace_back(a, b);
    }
    sort(food.begin(), food.end());
    vector<vector<int>> dp(n+1, vector<int>(t+2, -INT_MAX));
    dp[0][0] = 0;
    rp(i, 0, n) {
        int a = food[i].second;
        int b = food[i].first;
        rp(j, 0, t) {
            chmax(dp[i+1][j], dp[i][j]);
            if(j + b >= t) chmax(dp[i+1][t], dp[i][j] + a);
            else chmax(dp[i+1][j+b], dp[i][j] + a);
        }
        chmax(dp[i+1][t], dp[i][t]);
    }
    int res = 0;
    rp(i, 0, t+1) chmax(res, dp[n][i]);
    cout << res << endl;
    return 0;
}


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

#include <limits.h>

using namespace std;

typedef long long ll;

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

const ll INF = LONG_LONG_MAX / 2;

int main(void) {
    ll L, R;
    cin >> L >> R;

    if (R - L >= 2019) {
        cout << 0 << endl;
        return 0;
    }

    ll cand = INF;
    for (int i = L; i <= R; i++) {
        for (int j = i + 1; j <= R; j++) {
            ll x = ((i % 2019) * (j % 2019)) % 2019;
            chmin(cand, x);
        }
    }

    cout << cand << endl;
    
    return 0;
}


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

using namespace std;

#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 lrep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define LREP(i, a, b) for (ll i = (ll)a; i < (ll)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

ll f(ll n) {
	ll res = 0;
	while (n > 0) {
		res += n % 10;
		n /= 10;
	}
	return res;
}

double g (ll n) {
	return (double)n/f(n);
}

int main (){
	ll k; cin >> k;
	
	vector<ll> a;
	ll base = 1;
	
	rep(i, 15) {
		REP(j, 1, 150) {
			a.push_back(base * (j + 1) - 1);
		}
		base *= 10;
	}
	
	sort(a.begin(), a.end());
	a.erase(unique(a.begin(), a.end()), a.end());
	
	rep(i, a.size()) {
		REP(j, i + 1, a.size()) {
			if (g(a[i]) > g(a[j])) {
				a.erase(a.begin() + i--);
				break;
			}
		}
	}
	
	rep(i, k) cout << a[i] << endl;
}



Measured memory_bytes: 256
//////////////////////////
//////////////////////////
////Please give me AC!////
////Please give me AC!////
//////////////////////////
//////////////////////////
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const int MOD=1e9+7;
const long double Pi=acos(-1);
using  P=pair<ll,ll>;
ll gcd(ll a,ll b){//aとbの最大公約数を返す
  if(a%b==0){return b;}
  else{return gcd(b,a%b);}
}
ll lcm(ll a,ll b){//aとbの最小公倍数を返す
  return a*b/gcd(a,b);
}
ll pow(ll x,ll y){//x^yを返す
  ll tmp=x,res=1;
  while(y){
    if(y%2){res=res*tmp%MOD;}
    y>>=1;
    tmp=tmp*tmp%MOD;
  }
  return res;
}
ll nature(ll a){//絶対値を返す
  if(a>=0){return(a);}
  else{return(-1*a);}
}
ll prime(ll a){//素数なら1を返す
  if(a==2){return 1;}
  else if(a%2==0 || a==1){return 0;}
  for(ll i=3;i*i<=a;i+=2){if(a%i==0){return 0;}}
  return 1;
}
int main(){
  ll X,Y;
  cin>>X>>Y;
  for(ll i=0;i<=X;i++){
    if(2*i+4*(X-i)==Y){cout<<"Yes"<<endl;return 0;}
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main() {
    string s,t;
    cin>>s>>t;
    bool f=1;
    for(int i=0;i<s.size();i++){
    	if(s[i]!=t[i]){
    		f=0;
    		break;
    	}
    }if(f&&(s.size()+1==t.size())){
    	cout<<"Yes";
    }else cout<<"No";
    return 0;
}


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

int main()
{
  int N, K, ans = 0;
  cin >> N >> K;
  int a[N];
  rep(i,N){
    cin >> a[i];
  }
  sort(a, a + N);
  rep(i,K){
    ans += a[i];
    
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

long long dp[3010][3010];
string s,t;
string print(int i,int j){
    if(i==0||j==0) return "";
    if(s[i-1]==t[j-1]) return print(i-1,j-1)+s[i-1];
    if(dp[i][j-1]>dp[i-1][j]) return print(i, j-1);
    return print(i-1,j);
}
int main(){
    cin>>s>>t;
    int ns=s.size(),nt=t.size();
    for(int i=0;i<=ns;i++){
        for(int j=0;j<=nt;j++){
            if(i==0||j==0) continue;
            if(s[i-1]==t[j-1]) dp[i][j]=dp[i-1][j-1]+1;
            else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    cerr<<dp[ns][nt]<<endl;
    cout<<print(ns,nt)<<endl;
    return 0;
}


Measured memory_bytes: 71168
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a,b;
    if (n & 1) {
        for (int i = 1; i <= n; ++i)
            for  (int j = i + 1; j <= n; ++j)
                if (i + j != n)
                    a.push_back(i), b.push_back(j);
    } else {
        for (int i = 1; i <= n; ++i)
            for  (int j = i + 1; j <= n; ++j)
                if (i + j != n + 1)
                    a.push_back(i), b.push_back(j);
    }
    cout << a.size() << endl;
    for (int i = 0; i < a.size(); ++i)
        cout << a[i] << ' ' << b[i] << '\n';
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;
const ll mod=1000000007;

int main(){
  string s; cin>>s;
  bool f=0;
  vector<ll> d;
  if(s[0]=='<')
  f=1;
  else
  d.pb(0);

  int c=0;
  rep(i,s.size()){
    if(f){
      if(s[i]=='<')
      c++;
      else{
        d.pb(c);
        f=0;c=1;
      }
    }else{
      if(s[i]=='>')
      c++;
      else{
        d.pb(c);
        f=1;c=1;
      }
    }
  }
  d.pb(c);
  if(d.size()%2!=0)
  d.pb(0);
  // rep(i,d.size())
  // cout<<d[i]<<" ";
  ll ans=0;
  for(int i=0;i<d.size();i+=2){
    if(d[i]<d[i+1]){
      ans+=d[i+1]*(d[i+1]+1)/2+d[i]*(d[i]+1)/2-d[i];
    }else{
      ans+=d[i+1]*(d[i+1]+1)/2+d[i]*(d[i]+1)/2-d[i+1];
    }
  }
  cout<<ans<<endl;

  return 0;
}


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


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

    int ans = 0;
    if (n < 500) ans = (n / 5) * 5;
    else ans = (n / 500) * 1000 + ((n % 500) / 5) * 5;
    cout << ans << endl;
}

Measured memory_bytes: 256
use std::io::prelude::*;
use std::io::stdin;
use std::mem::swap;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let m: usize = read();
    let ab: Vec<(usize, usize)> = (0..m)
        .map(|_| (read::<usize>() - 1, read::<usize>() - 1))
        .collect();

    let mut uf = UnionFind::new(n);
    let mut ans = vec![0; m];
    ans[m - 1] = n * (n - 1) / 2;

    for i in (1..m).rev() {
        ans[i - 1] = ans[i];
        if !uf.same(ab[i].0, ab[i].1) {
            ans[i - 1] -= uf.size(ab[i].0) * uf.size(ab[i].1);
            uf.unite(ab[i].0, ab[i].1);
        }
    }
    for ans in ans {
        println!("{}", ans);
    }
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

/// http://sntea.hatenablog.com/entry/2017/06/07/091246
/// https://www.slideshare.net/chokudai/union-find-49066733

#[derive(Debug)]
struct UnionFind {
    par: Vec<usize>,
    sizes: Vec<usize>,
}

impl UnionFind {
    fn new(n: usize) -> UnionFind {
        UnionFind {
            par: (0..n).collect(),
            sizes: vec![1; n],
        }
    }

    fn find(&mut self, x: usize) -> usize {
        if x == self.par[x] {
            x
        } else {
            let x = self.par[x];
            let root = self.find(x);
            self.par[root]
        }
    }

    fn unite(&mut self, x: usize, y: usize) -> bool {
        let mut x = self.find(x);
        let mut y = self.find(y);
        if x != y {
            if self.sizes[x] < self.sizes[y] {
                swap(&mut x, &mut y);
            }

            self.par[y] = x;
            self.sizes[x] += self.sizes[y];
            self.sizes[y] = 0;
            true
        } else {
            false
        }
    }

    fn same(&mut self, x: usize, y: usize) -> bool {
        self.find(x) == self.find(y)
    }

    fn size(&mut self, x: usize) -> usize {
        let root = self.find(x);
        self.sizes[root]
    }
}


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

struct t {
    string data1;
    int data2;
    int data3;

    t(string d1, int d2, int d3) {
        data1 = d1;
        data2 = d2;
        data3 = d3;
    }

    bool operator<(const t& another) const {
        return data2 > another.data2;
    }
};

int main() {
    int n, p, i;
    cin >> n;
    vector<t> data;
    set<string> st;
    string s;

    for (i = 0; i < n; i++) {
        cin >> s >> p;
        st.insert(s);
        data.push_back(t(s, p, i+1));
    }

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

    for (auto next: st) {
        for (i = 0; i < n; i++) {
            if (data.at(i).data1 == next) {
                cout << data.at(i).data3 << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
/*
* @Author: kabbo
* @Date:   2020-05-10 13:35:27
* @Last Modified by:   kabbo
* @Last Modified time: 2020-05-10 14:02:21
*/
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define endl '\n'
#define ull unsigned long long
#define ll long long
const int mod = 1e9 + 7;
using u64 = uint64_t;
using u128 = __uint128_t;
struct day
{
	int a, b, c;

};
void solve() {
	int n;
	cin >> n;
	vector<day>task(n + 1);
	for (int i(1); i <= n; ++i) {
		cin >> task[i].a >> task[i].b >> task[i].c;
	}
	int dp[n + 1][3];
	memset(dp, 0, sizeof(dp));
	dp[1][0] = task[1].a;
	dp[1][1] = task[1].b;
	dp[1][2] = task[1].c;
	auto ans = INT_MIN;
	ans = max({ans, dp[1][0], dp[1][1], dp[1][2]});
	for (int i(2); i <= n; ++i) {
		dp[i][0] = task[i].a + max(dp[i - 1][1], dp[i - 1][2]);
		dp[i][1] = task[i].b + max(dp[i - 1][0], dp[i - 1][2]);
		dp[i][2] = task[i].c + max(dp[i - 1][0], dp[i - 1][1]);
		ans = max({ans, dp[i][0], dp[i][1], dp[i][2]});
	}
	cout << ans << endl;

}
int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	/*int t;
	cin >> t;
	for (int i(1); i <= t; ++i) {
		printf("Case %d: ", i);*/
	solve();
	//}
#ifndef LOCAL_DEFINE
	cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
#endif
	return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=3.14159265359;

int main() {
    int N, M, X;
    cin>>N>>M>>X;
    ll C[N];
    int A[N][M];
    for(int i=0;i<N;++i){
        cin>>C[i];
        for(int j=0;j<M;++j){
            cin>>A[i][j];
        }
    }
    vector<int> S;
    int skill[M];
    ll money = big;
    ll tmpmoney;
    bool ok;
    for(int bit=0;bit<(1<<N);++bit){
        for(int i=0;i<M;++i){
            skill[i] = 0;
        }
        S.clear();
        for(int i=0;i<N;++i){
            if(bit&(1<<i)) S.push_back(i);
        }
        tmpmoney = 0;
        for(int i=0;i<S.size();++i){
            tmpmoney += C[S[i]];
            for(int j=0;j<M;++j){
                skill[j] += A[S[i]][j];
            }
        }
        ok = true;
        for(int i=0;i<M;++i){
            if(skill[i] < X) ok = false;
        }
        if((ok) & (money>tmpmoney)){
            money = tmpmoney;
        }
    }
    if(money==big) cout<<-1<<endl;
    else cout<<money<<endl;
}



Measured memory_bytes: 3632
#![allow(
  non_snake_case,
  unused_variables,
  unused_assignments,
  unused_mut,
  unused_imports,
  unused_macros,
  dead_code
)]
use proconio::{input, marker::*};
use std::cmp::*;

fn main() {
  input! {
    n:usize, A:[String;n]
  }
  let mut cnt = vec![vec![0; 50]; 50];
  let mut p2 = vec![0; n];
  let mut p5 = vec![0; n];
  let A: Vec<String> = A;
  for i in 0..n {
    let s = A[i].clone();
    let mut ip = 0usize;
    let mut dp = 0;
    if let Some(i) = s.find('.') {
      // 小数の場合
      ip = s[0..i].parse().unwrap();
      let ss = s[(i + 1)..].to_string() + "0000000000";
      dp = ss[0..9].parse::<usize>().unwrap()
    } else {
      ip = s.parse::<usize>().unwrap();
    }
    let mut x = ip * 1_000_000_000 + dp;
    while x % 2 == 0 {
      x /= 2;
      p2[i] += 1;
    }
    while x % 5 == 0 {
      x /= 5;
      p5[i] += 1;
    }
    cnt[p2[i]][p5[i]] += 1;
  }

  let mut ans = 0usize;
  for i in 0..n {
    let remain2 = max(18 - p2[i] as i64, 0) as usize;
    let remain5 = max(18 - p5[i] as i64, 0) as usize;
    for j in remain2..50 {
      for k in remain5..50 {
        ans += cnt[j][k];
      }
    }
    if p2[i] >= remain2 && p5[i] >= remain5 {
      ans -= 1;
    }
  }
  println!("{}", ans / 2);
}


Measured memory_bytes: 18644
import java.util.Scanner;;

public class Main {
	
	static int[] s;
	static int max = 1000000001;
	static int count =0;
	
	static void merge(int s[], int left,int mid,int right) {
		int n1 = mid - left;
		int n2 = right - mid;
		int[] L = new int[n1+1];
		int[] R = new int[n2+1];
		for(int i=0;i<n1;i++) {
			L[i] = s[left + i];
		}
		L[n1] = max;
		for(int i=0;i<n2;i++) {
			R[i] = s[mid + i];
		}
		R[n2] = max;
		
		for(int i=0, j=0, k=left;k<right;k++) {
			if(L[i] <= R[j]) {
				s[k] = L[i];
				i++;
				count++;
			}else {
				s[k] = R[j];
				j++;
				count++;
			}
		}
	}
	
	static void mergeSort(int s[],int left,int right) {
		if(left + 1 < right) {
			int mid = (left + right)/2;
			mergeSort(s,left,mid);
			mergeSort(s,mid,right);
			merge(s,left,mid,right);
		}
	}
	
	void main() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		s = new int[n];
		for(int i=0;i<n;i++) {
			s[i] = sc.nextInt();
		}
		
		int left = 0;
		int right = n;
		mergeSort(s,left,right);
		
		System.out.print(s[0]);
		for(int i=1;i<n;i++) {
			System.out.print(" " + s[i]);
		}
		System.out.println();
		System.out.println(count);
	}

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

}



Measured memory_bytes: 173936
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <unordered_set>
#include <queue>
#include <cmath>
#include <bitset>

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

using Graph = vector<vector<int>>;

// 深さ優先探索
vector<bool> seen;
void dfs(const Graph &G, int v) {
    seen[v] = true; // v を訪問済にする

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main() {
  ll X, K, D;
  cin >> X >> K >> D;
  
  X=abs(X);
  
  if(X/K>=D){
    cout << X-D*K << endl;
  }else{
    ll tmp = X/D;
    ll pl = X - tmp*D;
    ll ms = X - (tmp+1)*D;

    if((tmp%2)==(K%2)){
      cout << pl << endl;
    }else{
      cout << -ms << endl;
    }
  }
}

Measured memory_bytes: 3656
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll N;
double arr[3005];
ll vis[3005][3005];
double dp[3005][3005];

double rec(int ind, int heads) {
	if(ind == N) {
		if(2 * heads >= N) {
			return 1;
		}
		return 0;
	}
	ll &temp = vis[ind][heads];
	double &ans = dp[ind][heads];
	if(temp) {
		return ans;
	}
	temp = 1;
	ans = arr[ind] * rec(ind + 1, heads + 1) + (1 - arr[ind]) * rec(ind + 1, heads);
	return ans;
}

int main() {
	scanf("%lld", &N);
	for(int i = 0; i < N; i++) {
		scanf("%lf", &arr[i]);
	}
	// memset(dp, -1, sizeof(dp));
	// for(int i = 0; i < N; i++) {
	// 	for(int j = 0; j < N; j++) {
	// 		cout << dp[i][j] << " ";
	// 	}
	// }
	printf("%0.12lf", rec(0, 0));


	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 139776
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair <ll, ll> cn;
const int NS = 1e5 + 100;

int main() {
	ll sum = 0, argn, m, a[NS];
	scanf("%lld%lld", &argn, &m);
	for (int i = 0; i < argn; ++i) {
		scanf("%lld", a + i);
	}
	sort(a, a + argn);
	cn z[m];
	for (int i = 0; i < m; ++i) {
		scanf("%lld%lld", &z[i].first, &z[i].second);
	}
	sort(z, z + m, [](const cn &p1, const cn &p2) {
			return p1.second < p2.second;
			});
	int i = 0;
	--m;
	for (; i < argn; ++i) {
		if (a[i] >= z[m].second) { break; }
		sum += z[m].second;
		if (z[m].first == 1) {
			if (m-- == 0) {
				++i;
				break;
			}
			continue;
		}
		z[m].first -= 1;
	}
	for (;i < argn; ++i) {
		sum += a[i];
	}
	cout << sum;
	return 0;
}


Measured memory_bytes: 2560
import java.io.*;
import java.util.*;
 
public class Main {
    static ContestScanner in;
    static Writer out;
    public static void main(String[] args) {
        Main main = new Main();
        try {
            in = new ContestScanner();
            out = new Writer();
            main.solve();
            out.close();
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
    void solve() throws IOException {
    	int x = in.nextInt();
    	int t = in.nextInt();
    	System.out.println(Math.max(0, x - t));
    }
 
}

@SuppressWarnings("serial")
class MultiSet<T> extends HashMap<T, Long>{
    @Override public Long get(Object key){return containsKey(key)?super.get(key):0L;}
    public void add(T key,long v){put(key,get(key)+v);}
    public void add(T key){put(key,get(key)+1);}
    public void sub(T key){final long v=get(key);if(v==1)remove(key);else put(key,v-1);}
    public MultiSet<T> merge(MultiSet<T> set)
    {MultiSet<T>s,l;if(this.size()<set.size()){s=this;l=set;}else{s=set;l=this;}
        for(Entry<T,Long>e:s.entrySet())l.add(e.getKey(),e.getValue());return l;}
}
 
class Writer extends PrintWriter{
    public Writer(String filename)throws IOException
    {super(new BufferedWriter(new FileWriter(filename)));}
    public Writer()throws IOException{super(System.out);}
}
class ContestScanner implements Closeable{
    private BufferedReader in;private int c=-2;
    public ContestScanner()throws IOException
    {in=new BufferedReader(new InputStreamReader(System.in));}
    public ContestScanner(String filename)throws IOException
    {in=new BufferedReader(new InputStreamReader(new FileInputStream(filename)));}
    public String nextToken()throws IOException {
        StringBuilder sb=new StringBuilder();
        while((c=in.read())!=-1&&Character.isWhitespace(c));
        while(c!=-1&&!Character.isWhitespace(c)){sb.append((char)c);c=in.read();}
        return sb.toString();
    }
    public String readLine()throws IOException{
        StringBuilder sb=new StringBuilder();if(c==-2)c=in.read();
        while(c!=-1&&c!='\n'&&c!='\r'){sb.append((char)c);c=in.read();}
        return sb.toString();
    }
    public long nextLong()throws IOException,NumberFormatException
    {return Long.parseLong(nextToken());}
    public int nextInt()throws NumberFormatException,IOException
    {return(int)nextLong();}
    public double nextDouble()throws NumberFormatException,IOException
    {return Double.parseDouble(nextToken());}
    public void close() throws IOException {in.close();}
}

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

int main(){
	int m;
	while(cin >> m && m){
		vector< pair<int,int> > OK;
		for(int x = 0 ; x < m ; x++){
			int prev = 0 , ans = 0;
			vector< vector<int> > v;
			int num; cin >> num;
			for(int i = 0 ; i < 10 ; i++){
				int a;
				vector<int> t;
				cin >> a;
				t.push_back(a);
				if(i != 9){
					if(a!=10){
						int b;
						cin >> b;
						t.push_back(b);
					}
				}else{
					if(a==10){
						int b,c;
						cin >> b >> c;
						t.push_back(b);
						t.push_back(c);
					}else{
						int b; cin >> b;
						t.push_back(b);
						if(a+b==10){
							int c;
							cin >> c;
							t.push_back(c);
						}
					}
				}
				v.push_back(t);
			}
			for(int i = 0 ; i < 9 ; i++){
				if(v[i][0]==10){
					ans += v[i][0];
					if(v[i+1].size() < 2){
						ans += v[i+1][0] + v[i+2][0];
					}else{
						ans += v[i+1][0] + v[i+1][1];
					}
				}else if(v[i][0]+v[i][1] == 10){
					ans += 10;
					ans += v[i+1][0];
				}else{
					ans += v[i][0]+v[i][1];
				}
			}
			for(int j = 0 ; j < v[9].size() ; j++)
				ans += v[9][j];
			OK.push_back(make_pair(-ans,num));
		}
		sort(OK.begin(),OK.end());
		for(int i = 0 ; i < OK.size() ; i++)
			cout << OK[i].second << " " << -OK[i].first << endl;
	}
}

Measured memory_bytes: 0