akhauriyash/Code-Regression huggingface dataset:
//om nama sivaya
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define maxn 100001
#define pb push_back
using namespace std;
void solve(){
    ll n,w;
    cin>>n>>w;
    ll a[n],b[n];
    for(int i=0;i<n;i++)
    cin>>a[i]>>b[i];
    ll dp[n+1][w+1];
    for(int i=0;i<=n;i++)
    dp[i][0]=0;
    for(int i=0;i<=w;i++)
    dp[0][i]=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=w;j++){
            if(j<a[i-1])
            dp[i][j]=dp[i-1][j];
            else
            dp[i][j]=max(dp[i-1][j-a[i-1]]+b[i-1],dp[i-1][j]);
        }
    }
    cout<<dp[n][w];
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tt=1;
    //cin>>tt;
    while(tt--){
        solve();
    }
}


Measured memory_bytes: 82432
#include<stdio.h>
int main(void){

int a,b;
	
scanf("%d %d",&a,&b);

if(a<b){
	printf("a < b\n");
	}
else if(a>b){
	printf("a > b\n");
	}
else{
	printf("a == b\n");
	}
	
return 0 ;
}



Measured memory_bytes: 2072
import sys
hyperScan = sys.stdin.readline
n = int(hyperScan())
tSum = 0
tLi = {}
for i in range(n):
    s, t = map(str, hyperScan().strip('\n').split())
    tSum += int(t)
    tLi[s] = tSum

x = hyperScan().strip('\n')
print(tSum - tLi[x])

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	int T;
	cin >> T;
	while(T--){
		//char s[100] = "abc";
		string a,b;
		
		cin >> a >> b;
		if(a==b){
			if(a=="0"){
			cout<<"0"<<endl;
				continue;
			}
		}
		reverse(a.begin(),a.end());
		reverse(b.begin(),b.end());
		while( a.size() < 100 ) a += "0";
		while( b.size() < 100 ) b += "0";
		string ans = "";
		int carry = 0;
		for(int i = 0 ; i < 100 ; i++){
			int d = (a[i]-'0') + (b[i]-'0') + carry;
			ans += d % 10 + '0';
			carry = d / 10;
		}
		reverse(ans.begin(),ans.end());
		if(ans.find_first_not_of('0')<20){
			cout << "overflow" << endl;
			continue;
		}
		ans = ans.substr(ans.find_first_not_of('0') );
		
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1220
#include<iostream>
using namespace std;
#include<vector>
long long invmod(long long a,long long m)
{
	long long s=a%m,t=m,sx=1,sy=0,tx=0,ty=1;
	while(s%t!=0)
	{
		long long f=s/t;
		long long u=s-t*f,ux=sx-tx*f,uy=sy-ty*f;
		s=t,sx=tx,sy=ty;
		t=u,tx=ux,ty=uy;
	}
	if(tx<0)tx+=m;
	return tx;
}
long long garner(const vector<long long>&x,const vector<long long>&m,const int mod=0)//*=x mod m
{
	if(x.empty())return 0LL;
	vector<long long>v(x.size());
	v[0]=x[0];
	for(int i=1;i<x.size();i++)
	{
		long long X=(x[i]-x[0])%m[i];
		long long M=1;
		for(int j=0;j<i-1;j++)
		{
			(M*=m[j])%=m[i];
			(X-=v[j+1]*M)%=m[i];
		}
		(M*=m[i-1])%=m[i];
		if(X<0)X+=m[i];
		v[i]=X*invmod(M,m[i])%m[i];
	}
	long long ret=v[0],p=1;
	if(mod==0)
	{
		for(int i=1;i<x.size();i++)
		{
			p*=m[i-1];
			ret+=p*v[i];
		}
	}
	else
	{
		ret%=mod;
		for(int i=1;i<x.size();i++)
		{
			(p*=m[i-1])%=mod;
			(ret+=p*v[i])%=mod;
		}
	}
	return ret;
}
#include<algorithm>
long long garner_helper(vector<int>A,vector<int>B,const int mod=0,bool zero=true)//allow zero?
//make B disjoint. NA => -1
{
	vector<int>primes;
	for(int i=0;i<A.size();i++)
	{
		int b=B[i];
		for(int j=2;j*j<=b;j++)
		{
			if(b%j==0)
			{
				primes.push_back(j);
				while(b%j==0)b/=j;
			}
		}
		if(b>1)primes.push_back(b);
	}
	sort(primes.begin(),primes.end());
	primes.erase(unique(primes.begin(),primes.end()),primes.end());
	vector<long long>a,b;
	bool flag=!zero;
	long long ret=1;
	for(int p:primes)
	{
		int ma=1,res;
		vector<pair<int,int> >x;
		for(int i=0;i<A.size();i++)
		{
			if(B[i]%p==0)
			{
				int t=1;
				while(B[i]%p==0)
				{
					B[i]/=p;
					t*=p;
				}
				x.push_back(make_pair(t,A[i]%t));
				if(ma<t)ma=t,res=x.back().second;
				A[i]%=B[i];
			}
		}
		for(pair<int,int>q:x)
		{
			if(res%q.first!=q.second)return-1;
		}
		a.push_back(res);
		b.push_back(ma);
		flag&=res==0;
		if(flag)
		{
			ret*=ma;
			if(mod!=0)ret%=mod;
		}
	}
	if(!flag)ret=garner(a,b,mod);
	return ret;
}
int ap[200][200];
main()
{
	int N;
	cin>>N;
	vector<int>P(N),Q(N);
	for(int i=0;i<N;i++)cin>>P[i],P[i]--;
	for(int i=0;i<N;i++)cin>>Q[i],Q[i]--;
	vector<int>A(N),B(N),tmp(N,1);
	for(int i=1;i<=N+1;i++)
	{
		for(int j=0;j<N;j++)
		{
			if(ap[j][P[j]]==0)
			{
				ap[j][P[j]]=i;
			}
			else
			{
				if(B[j]==0)B[j]=i-ap[j][P[j]];
			}
			P[j]=Q[P[j]];
		}
	}
	for(int i=0;i<N;i++)
	{
		A[i]=ap[i][i]-1;
		if(A[i]<0)
		{
			cout<<-1<<endl;
			return 0;
		}
	}
	cout<<garner_helper(A,B)<<endl;
}




Measured memory_bytes: 3312
#include <iostream>
using namespace std;
//3????????°??¨3???????????°??????????????????????????°??????

int main(){

	int n, num, *array;
	cin >> n;
	

	array = new int[n];
	for (int i = 0; i < n; i++){
		cin >> num;
		array[i] = num;
	}

	for (int i = n-1; i > 0; i--){
		cout << array[i] << " ";
	}
	cout << array[0] << endl;

	delete[] array;


	return 0;
}

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

int main(){
  int n;
  cin >>n;
  long long ans=1;
  for(int i=1;i<=n;i++){
    ans=ans*i;
    if(ans>1000000007){ans=ans%1000000007;}
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
"""
A - Subscribers
"""


def solve():
    N, A, B = map(int, input().split())
    max_both = B if A > B else A
    min_both = (A + B) - N if (A + B) > N else 0
    print(max_both, min_both)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define Keep_calmYou_are_still_learning ios_base::sync_with_stdio(false);cin.tie(NULL);//freopen("out.txt","w",stdout);
typedef long long ll;
typedef long double ld;
using namespace std;

string a, b;

vector<vector<ll> > dp(3000,vector<ll>(3001,-1));
pair<ll,ll> nxt[3001][3001]={};

ll solve(ll i ,ll j)
{
    if (i==a.size() || j==b.size())
        return 0;
    if (dp[i][j]!=-1)
        return dp[i][j];

    ll choice1= solve(i+1,j),choice2=solve(i,j+1),choice3=0;
    if (a[i]==b[j])
        choice3=solve(i+1,j+1)+1;
    dp[i][j]=max(choice1,max(choice2,choice3));
    if(dp[i][j]==choice1)
        nxt[i][j]={i+1,j};
    else if(dp[i][j]==choice2)
        nxt[i][j]={i,j+1};
    else
        nxt[i][j]={i+1,j+1};

    return dp[i][j];
}
int main()
{
    Keep_calmYou_are_still_learning;

    cin>>a>>b;
    solve(0,0);
    pair<ll,ll> cur={};
    while(cur.first<a.size() && cur.second<b.size())
    {
        pair<ll,ll> nxtone=nxt[cur.first][cur.second];
        if (nxtone==make_pair(cur.first+1,cur.second+1) )
            cout<<a[cur.first];
        cur=nxtone;
    }
    cout<<'\n';
    return 0;
}


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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    int n; cin >> n;

    deque<int> deq;

    for (int i = 0; i < n; ++i) {
        int a; cin >> a;

        if (i % 2 == 0) {
            deq.push_back(a);
        } else {
            deq.push_front(a);
        }
    }

    for (int i = 0; i < n; ++i) {
        if (n % 2 == 0) {
            cout << deq[i];
        } else {
            cout << deq[n-1-i];
        }

        if (i != n-1) {
            cout << ' ';
        }
    }

    cout << endl;
}

Measured memory_bytes: 2944
#include<iostream>
#include<cmath>
#include<limits.h>
#define ll long long
using namespace std;
ll int function(ll int arr[],ll int initial,ll int final,ll int memo[])
{
	if(initial>final)
	{
		return INT_MAX;
	}
	if(memo[initial]!=-1)
	  return memo[initial];
	if(initial==final)
	  return 0;
	if(initial==final-1)
	{
		return abs(arr[initial]-arr[initial+1]);
	}
	else
	{
		ll int x=abs(arr[initial+2]-arr[initial])+function(arr,initial+2,final,memo);
		ll int y=abs(arr[initial+1]-arr[initial])+function(arr,initial+1,final,memo);
		memo[initial]=x<y?x:y;
		return memo[initial];
	}
}
int main()
{
	ll int n;
	cin>>n;
	ll int arr[n];
	ll int j;
	ll int answer;
	for(j=0;j<n;j++)
	  cin>>arr[j];
	ll int memo[n];
	for(j=0;j<n;j++)
	  memo[j]=-1;
	answer=function(arr,0,n-1,memo);
	cout<<answer<<endl;
}

Measured memory_bytes: 6528
N, M = map(int, input().split())
preferances = [list(map(int, input().split()))[1:] for _ in range(N)]
all_kind_of_food = [i for i in range(1, M + 1)]
check_for_foods = [i for i in range(1, M + 1)]
for i in range(N):
  for j in range(M):
    if all_kind_of_food[j] in check_for_foods and (not all_kind_of_food[j] in preferances[i]):
      check_for_foods.remove(all_kind_of_food[j])
print(len(check_for_foods))


Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<bitset>
#include<set>
#define N (1010)
#define P ()
#define M ()
#define inf (0x7f7f7f7f)
#define rg register int
#define Label puts("NAIVE")
#define spa print(' ')
#define ent print('\n')
#define rand() (((rand())<<(15))^(rand()))
#define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
typedef long double ld;
typedef long long LL;
typedef unsigned long long ull;
using namespace std;
namespace fastIO1{
	inline char read(){
		static const int IN_LEN=1000000;
		static char buf[IN_LEN],*s,*t;
		return (s==t?t=(s=buf)+fread(buf,1,IN_LEN,stdin),(s==t?-1:*s++):*s++);
	}
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=read();!isdigit(c);c=read()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=read())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
	inline char readc(char &c){
		for(c=read();!isalpha(c)&&!isdigit(c);c=read())
		if(c==-1)return 0;
	}
	const int OUT_LEN = 10000000;
	char obuf[OUT_LEN],*ooh=obuf;
	inline void print(char c){
		if(ooh==obuf+OUT_LEN)fwrite(obuf,1,OUT_LEN,stdout),ooh=obuf;
		*ooh++=c;
	}
	template<class T>
	inline void print(T x){
		static int buf[30],cnt;
		if(x==0)print('0');
		else{
			if(x<0)print('-'),x=-x;
			for(cnt=0;x;x/=10)buf[++cnt]=x%10+48;
			while(cnt)print((char)buf[cnt--]);
		}
	}
	inline void flush(){fwrite(obuf,1,ooh-obuf,stdout);}
}
namespace fastIO2{
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=getchar();!isdigit(c);c=getchar()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=getchar())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
}
using namespace fastIO1;
int K,n,a[N][N];
int main(){
	read(K),n=2*((K-1)/4+1); 
	if(K==1)puts("1\n1"),exit(0);else printf("%d\n",n);
	for(int i=0;i<n;i++)
	for(int j=0;j<n;j++){
		int w=(i+j)%n+(i&1)*n;
		printf("%d ",(w+1<=K)?w+1:w+1-n); if(j+1==n)puts("");
	}
}

Measured memory_bytes: 5248
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

int gcd(int n, int m) {
    if (n < m) swap(n, m);
    while (m != 0) {
        int r = n % m;
        n = m;
        m = r;
    }
    return n;
}

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

    int c = gcd(a, b);

    cout << (ll)a * b / c << endl;

    return 0;
}

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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if ((a + b) > (c + d))
      cout << "Left" << endl;
    else if ((a + b) < (c + d))
      cout << "Right" << endl;
    else
      cout << "Balanced" << endl;
}

Measured memory_bytes: 256
import numpy as np

def input_numbers():
    temp = list(map(int, input().split()))
    return temp

def GCD(a, b):
    if(a < b):
        temp = a
        a = b
        b = temp
    a = a % b
    if(a == 0):
        return b
    else:
        return GCD(a, b)

a = input_numbers()

m = 10000000000000000000

for i in range(3):
    for j in range(3):
        for k in range(3):
            if(i != j and j != k and k != i):
                cost = abs(a[i] - a[j]) + abs(a[j] - a[k])
                m = min(m, cost)

print(m)

Measured memory_bytes: 12500
#include<iostream>
using namespace std;
long long n,k,a,b,bb[100005];
main(){
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>a>>b;
        bb[a]+=b;
    }
    int ans=0;
    for(int i=1;k>0;i++)k-=bb[i],ans=i;
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <vector>
using namespace std;
int n, m, k, a, b;
int ans[100000];
int e[100000];
int h[100000];
vector<int>g[100000];
void dfs(int ba, int p, int co) {
	h[p] = co;
	for (int i = 0; i < g[p].size(); i++) {
		if (g[p][i] != ba && h[g[p][i]] > co)dfs(p, g[p][i], co);
	}
}
int main() {
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 0; i < m; i++) {
		scanf("%d%d", &a, &b);
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
		ans[a]--;
		ans[b]--;
	}
	for (int i = 0; i < n; i++) {
		h[i] = i;
	}
	for (int i = 0; i < n; i++) {
		if (h[i] == i)dfs(-1, i, i);
	}
	for (int i = 0; i < n; i++) {
		e[h[i]]++;
	}
	for (int i = 0; i < n; i++) {
		ans[i] += e[h[i]] - 1;
	}
	for (int i = 0; i < k; i++) {
		scanf("%d%d", &a, &b);
		a--; b--;
		if (h[a] == h[b]) {
			ans[a]--;
			ans[b]--;
		}
	}
	for (int i = 0; i < n; i++) {
		printf("%d\n", ans[i]);
	}
}

Measured memory_bytes: 8704
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


 fn main(){
 	let s: String = read();
    let sv: Vec<char> = s.chars().collect();
    let mut ans = 0;
    if sv[0]=='1' { ans += 1;}
    if sv[1]=='1' { ans += 1;}
    if sv[2]=='1' { ans += 1;}
    println!("{}",ans);
    
 }
 

Measured memory_bytes: 4352
from pprint import pprint
import sys
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

H = ri()

def dfs(i):
	if i == 0: return 0
	return 1 + 2 * dfs(i//2)
print(dfs(H))


Measured memory_bytes: 39764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(void)
{
    int a,b;
    cin >> a >> b;
    FOR(i,1,1001){
        if(floor(i * 0.08) == a && floor(i * 0.1) == b){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>
int main(int argc, const char * argv[]) {
    // insert code here...
    int i;
    char array[1201], c, c2;
    scanf("%[^\n]", array);
    for (i=0; i!='\0'; i++) {
        printf("%c", array[i]);
    }
    for (i=0; array[i]!='\0'; i++) {
        c=array[i];
        if (tolower(c)!=array[i]) {
            c2=tolower(c);
        }else if(toupper(c)!=array[i]){
            c2=toupper(c);
        }else{
            c2=c;
        }
        printf("%c", c2);
    }
    printf("\n");
    return 0;
}



Measured memory_bytes: 2064
from scipy.sparse import coo_matrix, csgraph
N, M = map(int, input().split())
points = tuple(tuple(map(lambda n: int(n) - 1, input().split())) for _ in range(M))
matrix = coo_matrix(([1] * M, tuple(zip(*points))), shape=(N, N)).toarray()
total = 0
for point in points:
    matrix[point] = 0
    total += csgraph.connected_components(matrix, directed=False, return_labels=False) != 1
    matrix[point] = 1
print(total)

Measured memory_bytes: 17160
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;
  int r = n % 10;
  if (r == 2 || r == 4 || r == 5 || r == 7 || r == 9)
    cout << "hon" << endl;
  else if (r == 0 || r == 1 || r == 6 || r == 8)
    cout << "pon" << endl;
  else if (r == 3)
    cout << "bon" << endl;
}


Measured memory_bytes: 3636
/*==============================================*\
Codeforces ID:    mdshihab
                                                  |
Name:     Md. Shihabul Minhaz                     |
Study:      CSE, JKKNIU                           |
Address:  Trishal, Mymensingh, Bangladesh         |
                                                  |
 mail:   mdshihabul20171@gmail.com                |
 FB  :   fb.com/mdshihabul.minhaz.7               |
 github: Shihabulminhaz                           |
stopstalk :  mdshihab                             |
                                                  |
@uthor   Md. Shihabul Minhaz (shihab)             |
\*===============================================*/


#include<bits/stdc++.h>
using namespace std;
#define fi(a) scanf("%d",&a);
#define fli(a) scanf("%ld",&a);
#define fll(a) scanf("%lld",&a);
#define pi(a) printf("%d\n",a);
#define ppi(i,a) printf("Case %d: %d\n",i,a);
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
void FI()
{
#ifndef ONLINE_JUDGE
    freopen("C:\\Users\\SHIHAB\\Desktop\\input.in","r",stdin);
#endif // ONLINE_JUDGE
}

int main()
{
    fast
   // FI(); /// skip this line for compile
    ll n,k,cnt=1,x=1;
    cin >> n >> k;
    x = k;
    while(n>=x){
        cnt++;
        x*=k;
    }
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 3604
def main():
    n,k = map(int,input().split())
    d = ''.join(input().split())
    ans=str(n)
    while True:
        key=0
        for c in d:
            if c in ans:
                key=1
                ans=str(int(ans)+1)
        if key==0:
            print(ans)
            return   

if __name__ == "__main__":
    main()


Measured memory_bytes: 40684
H, N= map(int,input().split())
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())
ma = max(A)
dp = [float("inf")] * (H + ma)
dp[0] = 0
for i in range(N):
    a = A[i]
    b = B[i]
    for j in range(1, H + ma):
        dp[j] = min(dp[j - a] + b, dp[j])
print(min(dp[H:]))



Measured memory_bytes: 53212
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def init_dp1(init, N): return [init for _ in range(N)]
def init_dp2(init, N, M): return [[init for _ in range(M)] for _ in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def print_ans(B):
    for b in B:
        b.sort(key=lambda l: int(l))
        print(" ".join(b))



def main():
    N, M, X = read_values()
    A = read_lists(N)

    res = V(min)
    for i in range(2 ** N):
        K = [0] * (M + 1)
        for n in range(N):
            if i & (1 << n):
                for k in range(M + 1):
                    K[k] += A[n][k]
                
                for k in range(1, M + 1):
                    if K[k] < X:
                        break
                else:
                    res.ud(K[0])

    if res.v is None:
        print(-1)
    else:
        print(res)


if __name__ == "__main__":
    main()



Measured memory_bytes: 9880
# coding: utf-8
# Your code here!

n = int(input())
al = []
for _ in range(n):
    a = int(input())
    al.append(-a)

def LIS(L):
  from bisect import bisect
  seq=[]
  for i in L:
    pos=bisect(seq,i)
    if len(seq)<=pos:
      seq.append(i)
    else:
      seq[pos]=i
  return len(seq)
  
print(LIS(al))


Measured memory_bytes: 54360
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

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; }
const long long INF = 10010010010010;
const long long MOD = 1000000007;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

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

int main() {
    int N;cin >> N;
    vector<long long> retu(N);
    long long S = 0,A = 0;
    for(int i = 0;i<N;i++) {
        cin >> retu.at(i);
        A += retu.at(i);
    }
    long long ans = INF;
    for(int i = 0;i<N;i++){
        if(i == N-1) break;
        S += retu.at(i);
        A -= retu.at(i);
        ans = min(ans,abs(S-A));
    }
    cout << ans << endl;
}


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

const int MAXn = 200005, MAX = 2147483647;
int n, q, t1, t2, t3, t4, h, t[MAXn], d[MAXn];
bool tag[MAXn];

int msb(int val) {
	int i = 0;
	while (val) val >>= 1, i++;
	return i;
}

void apply(int p, int val) {
	t[p] += val;
	if (p < n) d[p] += val, tag[p] = 1;
}

void push(int p) {
	for (int s = h; s > 0; s--) {
		int i = p >> s;
		if (tag[i]) {
			apply(i << 1, d[i]);
			apply(i << 1 | 1, d[i]);
			tag[i] = 0, d[i] = 0;
		}
	}
}

void build(int p) {
	while (p > 1) p >>= 1, t[p] = min(t[p << 1], t[p << 1 | 1]) + d[p];
}

void update(int l, int r, int val) {
	l += n, r += n;
	int l0 = l, r0 = r;
	for (; l < r; l >>= 1, r >>= 1) {
		if (l & 1) apply(l++, val);
		if (r & 1) apply(--r, val);
	}
	build(l0);
	build(r0 - 1);
}

int query(int l, int r) {
	l += n, r += n;
	push(l);
	push(r - 1);
	int ans = MAX;
	for (; l < r; l >>= 1, r >>= 1) {
		if (l & 1) ans = min(ans, t[l++]);
		if (r & 1) ans = min(ans, t[--r]);
	}
	return ans;
}

int main() {
	cin >> n >> q;
	h = msb(n);
	for (int i = 0; i < q; i++) {
		cin >> t1;
		if (t1 == 0) {
			cin >> t2 >> t3 >> t4;
			update(t2, t3 + 1, t4);
//			for (int j = 1; j < 2 * n; j++) cout << t[j] << ' ';
//			cout << endl;
//			for (int j = 1; j < 2 * n; j++) cout << d[j] << ' ';
//			cout << endl;
		}
		else {
			cin >> t2 >> t3;
			cout << query(t2, t3 + 1) << endl;
//			for (int j = 1; j < 2 * n; j++) cout << t[j] << ' ';
//			cout << endl;
//			for (int j = 1; j < 2 * n; j++) cout << d[j] << ' ';
//			cout << endl;
		}
	}
}


Measured memory_bytes: 4372
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
const double eps = 1e-8;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T> ostream& operator << (ostream& os, const set<T>& s) { for (auto si : s) os << si << " "; return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b % mod; if (a >= mod) a -= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12); // debuged
    int T;
    T = 1;
    while (T--) solve();
}

ll dp[3005][3005][4];
int v[3005][3005];
void solve() {
    int r, c, k;
    cin >> r >> c >> k;
    rep(i, k) {
        int r_, c_, v_;
        cin >> r_ >> c_ >> v_;
        --r_; --c_;
        v[r_][c_] = v_;
    }
    
    auto dp_ = [&](int i, int j, int l) { return (i >= 0 && j >= 0 ? dp[i][j][l] : 0LL); };
    rep(i, r) rep(j, c) rep(l, 4) {
        // 拾わない
        chmax(dp[i][j][0], dp_(i - 1, j, l));
        chmax(dp[i][j][l], dp_(i, j - 1, l));
        // 拾う
        chmax(dp[i][j][1], dp_(i - 1, j, l) + v[i][j]);
        if (l != 3) chmax(dp[i][j][l + 1], dp_(i, j - 1, l) + v[i][j]);
    }
    
    ll ans = 0;
    rep(l, 4) chmax(ans, dp[r - 1][c - 1][l]);
    cout << ans << endl;
    
    /*
    rep(l, 4) {
        cerr << l << endl;
        rep(i, r) { rep(j, c) cerr << dp[i][j][l] << " "; cerr << endl; }
    } */
}


Measured memory_bytes: 320444
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using P = pair<int, int>;
const ll q = 1e9 + 7;
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;
}
int main()
{
    ll n;
    cin >> n;
    ll ans = modpow(10,n,q) - modpow(9,n,q)  - modpow(9,n,q) + modpow(8,n,q);
    ans %= q;
    if(ans < 0) ans += q;
    cout << ans <<  endl;
return 0;
}

Measured memory_bytes: 3552
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <complex>

int main(){
  long long int N, tmp;
  std::vector<long long int> A, A_cum;
  A_cum.push_back(0);

  scanf("%lld", &N);
  for(long long int i = 0; i < N; i++){
    scanf("%lld", &tmp);
    A.push_back(tmp);
    A_cum.push_back(A_cum[i]+tmp);
  }

  long long int ans = 1e18;
  for(long long int i = 0; i < N; i++){
    ans = std::min(ans, std::abs(A_cum[N]- 2*A_cum[i]));
  }

  std::cerr << "A_cum: " << std::endl;
  for(long long int i = 0; i <= N; i++){
    std::cerr << A_cum[i] << std::endl;
  }

  std::cerr << "Answer: " << std::endl;
  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 3684
s = list(input())
a = [False, False, False]
count = 0
count1 = 0
if s[0] == "A":
  a[0] = True
for i in s[2:-1]:
  #print(i)
  if i == "C":
    count += 1
#print(count)
if count == 1:
  a[1] = True
for j in range(len(s)):
  if s[j].islower():
    count1 += 1
#print(count1)
if count1 == len(s)-2:
  a[2] = True
#print(a)
if all(a):
  print("AC")
else:
  print("WA")

Measured memory_bytes: 3064
def main():
    n , k = map(int, input().split())
    p = list(map(int, input().split()))
    size = max(p)
    sheet = [0]*size
    for i in range(size):
        if (i == 0):
            sheet[i]=1
        else:
            sheet[i] = (sheet[i-1]*i + (i+1))/(i+1)
    ans = 0
    total = 0
    for i in range(n-k+1):
        if (i == 0):
            for j in range(k):
                total += sheet[p[i+j]-1]
            if (total > ans):
                ans = total
        else:
            total -= sheet[p[i-1]-1]
            total += sheet[p[i+k-1]-1]
            if (total > ans):
                ans = total
    print (ans)
main()

Measured memory_bytes: 24804
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var buff []byte

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextFloat64() float64 {
	sc.Scan()
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextInts(n int) (r []int) {
	r = make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt64

func maxInt(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func minInt(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buff, bufio.MaxScanTokenSize*1024)
	log.SetFlags(log.Lshortfile)
}

func main() {
	x := nextInt()
	n := nextInt()
	var p [200]bool
	for i := 0; i < n; i++ {
		m := nextInt() + 10
		p[m] = true
	}
	ans := -1000000
	abs := 10000000
	for i := -10; i <= 110; i++ {
		if p[i+10] {
			continue
		}
		if absInt(x-i) < abs {
			abs = absInt(x - i)
			ans = i
		} else if absInt(x-i) == abs {
			ans = minInt(ans, i)
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1760
#include <algorithm>
#include <iostream>
#include <cstdio>
using namespace std;

int L[210];

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= 2 * n; ++ i) scanf("%d", L + i);
	sort(L + 1, L + 2 * n + 1);
	long long ans = 0;
	for (int i = 1; i <= 2 * n; i += 2) ans += L[i];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
use proconio::*;
use proconio::marker::*;

#[fastout]
#[allow(non_snake_case)]
fn main() {
    input! {
        K: usize,
    }
    let mut ans = 0;
    for i in 1..K + 1 {
        for j in 1..K + 1 {
            for k in 1..K + 1 {
                ans += gcd3(i, j, k);
            }
        }
    }
    println!("{}", ans);
}

fn gcd(a: usize, b: usize) -> usize {
    if a < b {
        return gcd(b, a);
    }
    let (mut a, mut b) = (a, b);
    let mut r: usize;
    while a % b != 0 {
        r = a % b;
        a = b;
        b = r;
    }
    b
}

fn gcd3(a: usize, b: usize, c: usize) -> usize {
    gcd(gcd(a, b), c)
}


Measured memory_bytes: 2196
#include <stdio.h>
 int main(void) {
 int k, a, b,s;

 scanf("%d", &k);
 scanf("%d%d", &a, &b);

 s=(b / k) * k;
 if (a <= s) {
 puts("OK");
 } 
 else {
 puts("NG");
 }

 return 0;
}


Measured memory_bytes: 1660
#include <iostream>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

long getGCD(long x, long y){
  if (y == 0) {
    return x;     
  }
  return getGCD(y, x % y);
}

int main(int argc, char const *argv[])
{
  int N;
  bool NegCount = 0;
  long tmp = 0, min = 10000000000;
  unsigned long long sum = 0;
  cin >> N;
  vector<long> A(N);
  for(int i=0;i<N;i++){
    cin >> A[i];
    if(A[i] < 0){
      NegCount = !NegCount;
    }
    if(labs(A[i]) < min){
      min = labs(A[i]);
    }
  }
  for(int i=0;i < N;i++){
    sum += labs(A[i]);
  }
  if(NegCount != 0){
    sum = sum - min * 2;
  }
  // cout << NegCount << endl;
  // cout << min << endl;
  cout << sum << endl;
  return 0;
}


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


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll a;
    cin>>a;
    ll ans=0;
    ans=a;
    ans+=a*1LL*a;
    ans+=a*1LL*a*1LL*a;
    cout<<ans;
}

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

using namespace std;

int n, a, b, c, l[8];

int f(int i, int j, int k, int idx, int mp) {
	if (idx == n) {
		return mp + abs(l[i] - a) + abs(l[j] - b) + abs(l[k] - c);
	}
	if (idx == i || idx == j || idx == k)
		return f(i, j, k, idx + 1, mp);

	int mn = 1e9;
	mn = min(mn, f(i, j, k, idx + 1, mp));
	l[i] += l[idx];
	mn = min(mn, f(i, j, k, idx + 1, mp + 10));
	l[i] -= l[idx];
	l[j] += l[idx];
	mn = min(mn, f(i, j, k, idx + 1, mp + 10));
	l[j] -= l[idx];
	l[k] += l[idx];
	mn = min(mn, f(i, j, k, idx + 1, mp + 10));
	l[k] -= l[idx];

	return mn;
}

int main() {
	scanf("%d %d %d %d", &n, &a, &b, &c);

	for (int i = 0;i < n;++i)
		scanf("%d", &l[i]);

	int mn = 1e9;
	for (int i = 0;i < n;++i)
		for (int j = 0;j < n;++j)
			for (int k = 0;k < n;++k) {
				if (i == j || j == k || k == i)
					continue;

				mn = min(mn, f(i, j, k, 0, 0));
			}

	printf("%d", mn);

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();
    String t = sc.next();
    String sum = "";
    for (int i=0;i<n;i++){
      sum = sum + s.charAt(i) + t.charAt(i);
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <deque>
#include <numeric>
#include <utility>
#define sign(a) ((a>0)-(a<0))
#define LL long long
#define INF (LL)(1LL<<60)

using namespace std;

void solve(long long N, long long A, long long B, std::vector<long long> X){
    LL ans=0;
    for(LL i=1; i<N; i++){
        LL tmp = A*(X[i]-X[i-1]);
        if(tmp < B)ans+=tmp;
        else ans+=B;
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    std::vector<long long> X(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&X[i]);
    }
    solve(N, A, B, std::move(X));
    return 0;
}


Measured memory_bytes: 1024
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, m) revi(i, m, 0)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define allr(n) (n.rbegin(), n.rend())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  rep(i, 3){
    st a;
    ci(a);
    cout << a.at(0);
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long lint;

#define MOD (1000000007)

typedef vector<lint> vec;
typedef vector<vec> matrix;

matrix mul(matrix &A, matrix &B)
{
    matrix C(A.size(), vec(B[0].size()));
    
    for (int i = 0; i < A.size(); i++){
        for (int j = 0; j < B[0].size(); j++){
            for (int k = 0; k < A[0].size(); k++){
                C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
            }
        }
    }
    
    return (C);
}

lint f(lint n)
{
	matrix A(2, vec(2));
	A[0][0] = 1, A[0][1] = 1;
    A[1][0] = 1, A[1][1] = 0;
	
    matrix B(A.size(), vec(A.size()));
    
    for (int i = 0; i < A.size(); i++){
        B[i][i] = 1;
    }
    
    while (n > 0){
        if (n & 1){
            B = mul(B, A);
        }
        A = mul(A, A);
        n >>= 1;
    }
    
    return (B[1][0]);
}

int main()
{
	lint n;
	
	scanf("%lld", &n);
	
	lint lo = 1, hi = 2000000000;
	
	while (lo != hi){
		lint mid = (lo + hi) / 2;
		lint no = (mid / 2) * (mid / 2 + 1);
		
		if (mid & 1) no += (mid + 1) / 2;
		if (no < n) lo = mid + 1;
		else hi = mid;
	}
	
	lint s = ((lo - 1) / 2) * ((lo - 1) / 2 + 1);
	if ((lo - 1) & 1) s += lo / 2;
	lint pos = n - s - 1, rev = (lo - 1) / 2 - pos + 1;
	
	if (lo - pos * 2 + 1 >= (pos + 1) * 2) printf("%lld\n", f(lo - pos * 2 + 1) * f((pos + 1) * 2) % 1000000007);
	else printf("%lld\n", f(rev * 2 + 1) * f(lo - rev * 2 + 2) % 1000000007);
	
	return (0);
}

Measured memory_bytes: 1056
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    ll n,m;
    cin>>n>>m;
    vector<ll> a(m),d(m-1);
    rep(i,m) cin>>a[i];
    if(n>=m) cout<<0;
    else{
        sort(all(a));
        int dis=0;
        rep(i,m-1){
            d[i]=abs(a[i+1]-a[i]);
            dis+=d[i];
        }
        sort(all(d));
        reverse(all(d));
        rep(i,n-1) dis-=d[i];
        cout<<dis;
    }
}

Measured memory_bytes: 4692
def ints():
  return [int(x) for x in input().split()]
def readi():
  return int(input())

def permutation(a, aa=[]):
  if len(a)<=1:
    return [aa+a]

  res = []
  for x in a:
    b = a.copy()
    b.remove(x)
    res.extend(permutation(b, aa+[x]))

  return res

N = readi()
P = [ints() for i in range(N)]

s = 0.0
ps = permutation(list(range(N)))
pn = len(ps)

for p in ps:
  for i in range(N-1):
    q = p[i]
    r = p[i+1]
    s += ((P[q][0]-P[r][0])**2+(P[q][1]-P[r][1])**2)**(0.5)/pn
print(s)


Measured memory_bytes: 9204
// rust input macro: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
 
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
 
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
 
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
 
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
 
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
 
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
  input!{
    n: i64
  };
  let mut ans: i64 = 0;
  for i in 1..=n {
    if i % 3 > 0 && i % 5 > 0 {ans += i;}
  }
  println!("{}", ans);
}


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

int a[100001], b[100001], c[100001];

int main() {
  int n; cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  for (int i = 0; i < n; i++) cin >> c[i];
  sort(a, a+n); sort(c, c+n);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    long long ia = lower_bound(a, a+n, b[i]) - a;
    long long ic = c+n - upper_bound(c, c+n, b[i]);
    ans += ia*ic;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1408
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
// dfmt on

void main()
{
    long H, W;
    scan(H, W);
    long[2][] black;
    auto A = new bool[][](H, W);
    foreach (i; 0 .. H)
    {
        auto s = sread();
        foreach (j, c; s)
            if (c == '#')
            {
                black ~= [i, j];
                A[i][j] = true;
            }
    }

    long cnt;
    while (true)
    {
        long[2][] tmp;
        foreach (b; black)
        {
            long y = b[0];
            long x = b[1];
            if (0 < y && !A[y - 1][x])
            {
                A[y - 1][x] = true;
                tmp ~= [y - 1, x];
            }
            if (0 < x && !A[y][x - 1])
            {
                A[y][x - 1] = true;
                tmp ~= [y, x - 1];
            }
            if (y + 1 < H && !A[y + 1][x])
            {
                A[y + 1][x] = true;
                tmp ~= [y + 1, x];
            }
            if (x + 1 < W && !A[y][x + 1])
            {
                A[y][x + 1] = true;
                tmp ~= [y, x + 1];
            }
        }
        if (tmp.empty)
        {
            writeln(cnt);
            return;
        }
        else
        {
            cnt++;
            black = tmp;
        }
    }
}


Measured memory_bytes: 33020
N = int(input())
A = list(map(int, input().split()))

DP = [[0, 0] for _ in range(N+1)]
DP[0][1] = -10**15 

for i in range(N):
    for j in range(2):
        DP[i+1][0] = max(DP[i][0]+A[i], DP[i][1]-A[i])
        DP[i+1][1] = max(DP[i][0]-A[i], DP[i][1]+A[i])

print(DP[N][0])

Measured memory_bytes: 25644
/**
 * Combinatorial - Knapsack Problem
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.lang.Integer.parseInt;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int n = parseInt(line.substring(0, line.indexOf(' ')));
			int w = parseInt(line.substring(line.indexOf(' ') + 1));

			int[] dp = new int[w + 1];
			int[] vs = new int[n];
			int[] ws = new int[n];

			for (int i = 0; i < n; i++) {
				line = br.readLine();
				vs[i] = parseInt(line.substring(0, line.indexOf(' ')));
				ws[i] = parseInt(line.substring(line.indexOf(' ') + 1));
			}

			//
			for (int i = 0; i < n; i++) {
				for (int j = ws[i]; j < w + 1; j++) {
					dp[j] = Math.max(dp[j], dp[j - ws[i]] + vs[i]);
				}
			}
			System.out.println(dp[w]);
		}//end while
	}//end main
}

Measured memory_bytes: 19620
def prime(x):
    if  x == 2:
        return True
    elif x < 2 or  x %2 == 0:
        return False
    i = 3
    while i <= x**(1/2):
        if x % i == 0:
            return False
        i = i + 2

    return True

L = []
while True:
    try:
        i = int(input())
        L.append(i)
    except EOFError:
        break
K = 0
for i in range(len(L)):
    if prime(L[i]):
        K += 1

print(K)


Measured memory_bytes: 5984
using System;

class MainClass
{
    public static void Main()
    {
        int input = int.Parse(Console.ReadLine());
        for (int i = 1; i <= input; i++)
        {
            int x = i;
            bool isInThree = false;

            while (x > 10)
            {
                x /= 10;
                if (x % 10 == 3)
                    isInThree = true;
            }

            if (i % 10 == 3 || i % 3 == 0 || isInThree)
                Console.Write(" " + i);
        }
        Console.WriteLine();
    }
}

Measured memory_bytes: 9376
n,m = map(int,input().split())
ks = [[int(i) for i in input().split()] for _ in range(m)]
p = list(map(int,input().split()))

ans=0
for i in range(2**n):
    sw=[]
    on=0
    for j in range(n):
        sw.append(i>>j & 1)
    for k in range(m):
        if (sum( [sw[ks[k][j+1]-1] for j in range(ks[k][0])] ))%2 == p[k]:
            on +=1
    if on==m:
        ans +=1
print(ans)


Measured memory_bytes: 8736
N,M=map(int,input().split())
students,checks=[],[]
for _ in range(N):
  students.append(list(map(int,input().split())))
  pass
for _ in range(M):
  checks.append(list(map(int,input().split())))
  pass

for i in range(N):
  closed_manhattan=10**16
  closed_j=0
  for j in range(M):
    x=abs(students[i][0]-checks[j][0])
    y=abs(students[i][1]-checks[j][1])
    manhattan=x+y
    if closed_manhattan > manhattan:
      closed_manhattan=manhattan
      closed_j=j+1
  print(closed_j)



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

int main(){
    int A, B, H, M;
    cin >> A >> B >> H >> M;
    double thA = ((double) H * 60.0 + (double) M)/ 720.0;// (rad / 2pi)
    double thB = ((double) M) / 60.0; //(rad / 2pi)
    double C2 = pow((double) A, 2) + pow((double) B, 2) - 2 * ((double) A) * ((double) B) * cos((thA - thB) * 2 * M_PI );

    cout << fixed;
    cout << setprecision(20);
    cout << sqrt(C2) << "\n";
    
}

Measured memory_bytes: 4168