akhauriyash/Code-Regression huggingface dataset:
/******************************************************************************
 
                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
 
*******************************************************************************/
 
#include <iostream>
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    string s,x,subs,subx,subs2,subx2;
    int N,Pal1,Pal2;
    cin >> s;
    N = s.size();
    Pal1 = (N-1)/2; 
    Pal2 = (N + 3)/2;
    
    x = s;
    
    
    reverse(s.begin(), s.end());
    subs = s.substr(0, Pal1 ); 
     
    subx = subs;
    subs2 = s.substr(Pal2 - 1, N); 
    
    subx2 = subs2; 
    
    reverse(subs.begin(), subs.end());
    reverse(subs2.begin(), subs2.end());
    
    
    if(subx == subs && subs2 == subx2 && s == x){
        cout << "Yes";
    }else{
        cout << "No";
    }
}

Measured memory_bytes: 256
H, W = map(int, input().split())
C = [list(map(int, input().split())) for _ in range(10)]
wall = [list(map(int, input().split())) for _ in range(H)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            C[i][j] = min(C[i][j], C[i][k] + C[k][j])
ans = 0
for i in range(H):
    for j in range(W):
        if wall[i][j] != -1:
            ans += C[wall[i][j]][1]
print(ans)


Measured memory_bytes: 40284
#include <iostream>
#include <map>
#include <algorithm>
 
using namespace std;
 
const int MAX = 500;
const int INF = 1e9;
 
int main(){
    int n,m;
 
    while(cin >> n >> m, n | m){
	map<string,int> mp;
	int dist[MAX+1][MAX+1];
	string a,b,start,goal,via;
	int c,d;
 
	for(int i = 0 ; i <= n ; i++){
	    for(int j = 0 ; j <= n ; j++){
		dist[i][j] = INF;
	    }
	}
 
	cin >> start >> via >> goal;
 
	int s = 1;
	for(int i = 0 ; i < m ; i++){
	    cin >> a >> b >> c >> d;
 
	    if(!mp[a]){
		mp[a] = s++;
	    }
	    if(!mp[b]){ 
		mp[b] = s++;
	    }
 
	    dist[mp[a]][mp[b]] = dist[mp[b]][mp[a]] = c / 40 + d;
	}
   
	for(int k = 1 ; k <= n ; k++){
	    for(int i = 1 ; i <= n ; i++){
		for(int j = 1 ; j <= n ; j++){
		    dist[i][j] = min(dist[i][j] ,dist[i][k] + dist[k][j]);
		}
	    }
	}
	cout << dist[mp[start]][mp[via]] + dist[mp[via]][mp[goal]] << endl;
    }
    return 0;
}

Measured memory_bytes: 4148
//https://github.com/mostafa-saad/MyCompetitiveProgramming/blob/master/UVA/UVA_10740.txt
#include<queue>
#include<map>
#include <string>
#include<bits/stdc++.h>
#define pi 3.141592654
#define forr(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define input ios_base::sync_with_stdio(0);cin.tie(0);
//#define x real()
//#define y imag()
using namespace std;
typedef pair<double,double>pdd;
typedef long long  ll;
typedef pair<ll, ll>pii;
//typedef complex<double> point;
//template<typename T>T gcd(T x, T y) { if(y == 0)return x; else return gcd(y, x%y); }
//typedef bitset<30> mask;
//int x[8]={1,0,0,-1,-1,-1,1,1};
//int y[8]={0,1,-1,0,-1,1,-1,1};
//#define var(x) ((x)<<1)
//#define nvar(x) ((x)^1)

ll n,k;
double ans;
 main()
{

//cout<<Pow((ll)1000000,(ll)110);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//    char input[15];
//    scanf("%s", &input);  array of char
//  gets(c+1);  array of char
//printf("%s, ",name[k[i]].c_str());  printf of string
input;
cin>>n>>k;

forr(i,1,n)
{
    ll x=i,a=0;
    while(x<k)a++,x*=2;
    ans+=1.0/n*pow(0.5,a);
}
cout<<fixed<<setprecision(12)<<ans;
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <utility>
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;

int main() {
	vector<double> tem;
    int n; cin >> n;
    double t, a;
    cin >> t >> a;
    for(int i = 0; i < n; ++i){
    	double y; cin >> y;
    	double f = t - y * 0.006;
    	tem.pb(f);
    }
    int index = 0;
    double ch = abs(tem[0] - a);
    for(int i = 1; i < n; ++i){
    	double nn = abs(tem[i] - a);
    	if(nn < ch){
    		index = i;
    		ch = nn;
    	}
    }
    cout << index + 1 << endl;
	return 0;
} 

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <list>
#include <cstring>
#include <stack>

using namespace std;

#define mod 1000000007

class UF
{
private:
	vector<int> root;

public:
	UF(int n)
	{
		root = vector<int>(n + 1, -1);
	}

	int getroot(int n)
	{
		if(root[n] == -1) return n;
		else return root[n] = getroot(root[n]);
	}

	void add(int x, int y)
	{
		x = getroot(x);
		y = getroot(y);
		if(x == y) return;
		if(x > y) swap(x, y);
		root[y] = x;
		return;
	}
};

int main()
{
	int n;
	cin >> n;
	priority_queue<pair<int, pair<int, int> > > qu;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			int w;
			cin >> w;
			if(w >= 0){
				qu.push(make_pair(-w, make_pair(i, j)));
			}
		}
	}
	UF uf(n);
	int ans = 0;
	while(!qu.empty()){
		int cost = -(qu.top()).first;
		int x = ((qu.top()).second).first;
		int y = ((qu.top()).second).second;
		qu.pop();
		if(uf.getroot(x) == uf.getroot(y)) continue;
		ans += cost;
		uf.add(x, y);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3224
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main() {
  string s;
  cin>>s;
  int flag =1;
  for(int i = 0;i<s.size()/2;i++){
    if(s[i] != s[s.size()-i-1]){
      flag =0;
    }
  }
  if(flag == 1){
    for(int i = 0;i<s.size()/4;i++){
      if(s[i] != s[s.size()/2-i-1]){
	flag =0;
      }
    }
  }

  if(flag == 1){
    int tem = 0;
    for(int i = s.size()/2+1;i<s.size();i++){
      if(s[i] != s[s.size()-tem-1]){
	flag =0;
      }
      tem++;
    }
  }
  if(flag==1)
  cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
bool dist(vector<ll> vec[], ll x, ll y, ll d){
	if(x>=y)	return false;
	ll sum = 0;
	for(int i=0;i<d;i++){
		sum+= pow(abs(vec[x][i]-vec[y][i]),2);
	}
	if(ceil(sqrt(sum))==floor(sqrt(sum)))	return true;
	return false;
}
int main()
{
	ll n,d;
	cin>>n>>d;
	vector<ll> vec[n];
	for(int i=0;i<n;i++){
		for(int j=0;j<d;j++){
			ll x;
			cin>>x;
			vec[i].push_back(x);
		}
	}
	ll count =0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(dist(vec,i,j,d)==true)	count++;
		}
	}
	cout<<count<<"\n";
	return 0;
}

Measured memory_bytes: 256
<?php
define("MOD", 10**9+7);
$n = intval(fgets(STDIN));
for($i = 1; $i <= $n; $i++){
    $G[$i] = [];
    $dp1[$i] = 0;
    $dp2[$i] = 0;
}
for($i = 0; $i < $n-1; $i++){
    list($a, $b) = array_map("intval", explode(" ", trim(fgets(STDIN))));
    $G[$a][] = $b;
    $G[$b][] = $a;
}
dfs(0,1);
echo ($dp1[1] + $dp2[1]) % MOD;

function dfs($from, $current){
    global $G, $dp1, $dp2;
    $dp1[$current] = 1;
    $dp2[$current] = 1;
    foreach($G[$current] as $next){
        if($next != $from){
            dfs($current, $next);
            $dp1[$current] *= $dp1[$next] + $dp2[$next];
            $dp2[$current] *= $dp1[$next];
            $dp1[$current] %= MOD;
            $dp2[$current] %= MOD;
        }
    }
}



Measured memory_bytes: 94836
#[allow(unused_imports)]
use std::cmp;

// Input macro from 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)*) => {
    #[allow(unused_mut)]
    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")
  };
}

const MODULO: i64 = 1_000_000_007;

fn main() {
  input! {
    n: usize,
    k: usize,
    aa: [usize; n]
  }
  let mut dp = vec![vec![0i64; k+1]; n+1];
  dp[0][0] = 1;
  for (i, &a) in aa.iter().enumerate() {
    dp[i+1][0] = 1;
    for c in 0 .. k {
      dp[i+1][c+1] = (dp[i+1][c] + dp[i][c+1]) % MODULO;
      if let Some(d) = c.checked_sub(a) {
        dp[i+1][c+1] = (dp[i+1][c+1] - dp[i][d] + MODULO) % MODULO;
      }
    }
  }
  println!("{}", dp[n][k]);
}


Measured memory_bytes: 106748
import java.util.Scanner;

public class Main {
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        int a=sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int k =sc.nextInt();
        int ans =0;

        if(k<=(a))
        {
            ans = k;
        }
        else
        if(k<=(a+b))
        {
            ans =a;
        }else
        {
            int g = k-a-b;
            if(g>c)
            {
                ans = a-c;
            }
            else
            {
                ans = a-g;
            }
        }
        System.out.println(ans);

    }
}

Measured memory_bytes: 35584
#include<bits/stdc++.h>
using namespace std;
int main(){
    int l,r,d,s,ans=0;
    cin>>l>>r>>d;
    s = l/d;
    s *=d;
    if(s!=l)
        s+=d;
    for(int i=s;i<=r;i+=d)
        ans++;
    cout<<ans<<endl;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  for(int i=0;i<h;i++)
    cin >> s.at(i);
  
  //--output--
  for(int i=0;i<w+2;i++)
    cout << "#";
  cout << endl;

  for(int i=0;i<h;i++)
    cout << "#" << s.at(i) << "#" << endl;

  for(int i=0;i<w+2;i++)
    cout << "#";
  cout << endl;
}


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

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

    bool flagY = false;
    rep(i, N){
        string s;
        cin >> s;
        if(s == "G" || s == "W" || s == "P"){
        }
        else{
            flagY = true;
            break;
        }
    }

    if(flagY){
        cout << "Four" << endl;
    }
    else{
        cout << "Three" << endl;
    }
}

Measured memory_bytes: 3568
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;
    
    int X, A, B;
    io.read(X, A, B);
    X -= A;
    X %= B;
    cout << X;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P, ll> T;
 
long long int INF = 2e18;
const ll fact_table = 1200008;
double Pi = 3.1415926535897932384626;

priority_queue <ll> pql;
priority_queue <P> pqp;
priority_queue <P> bag;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
ll dx[8]={1,0,-1,0,1,1,-1,-1};
ll dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//↓,→,↑,←

#define endl "\n"
#ifdef ENJAPMA
    #undef endl
#endif
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
#define pc(x) cout << x << ",";
 
// const ll mod = 998244353ll;
const ll mod = 1000000007ll;
  
ll mypow(ll number1,ll number2, ll mod){
    if(number2 == 0){
        return 1ll;
    }else{
        ll number3 = mypow(number1,number2 / 2, mod);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
void YES(bool condition){
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
 
/*
ll fact[fact_table + 5],rfact[fact_table + 5]; 
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = mypow(fact[fact_table],mod - 2, mod);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}
*/

bool multicase = false;

ll n,m,num,a,b,c,d,e,h,q;
ll w, k;
ll x[500005], y[500005], z[500005];
string s;

void solve(){
    long double r;
    cin >> r;
    ps(2 * r * Pi);

    return;
}

int main(){
    // init();
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll q, testcase = 1;
 
    if(multicase){
        cin >> q;
    }else{
        q = 1;
    }
    while(q--){
        // pu("Case ");pu("#");pu(testcase);pu(": ");
        solve();
        testcase++;
    }
    
    // solve();
    return 0;
 
}
















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

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main(){
  int N;
  cin >> N;
  vector<pair<int , int>> v(N);
  for(int i = 0; i < N; i++){
    int tmp1,tmp2;
    cin >> tmp1 >> tmp2;
    v[i] = make_pair(tmp1,tmp2);
  }
  
  sort(v.begin(),v.end(), compare_by_b);
  /*
  for(int i = 0; i < N; i++){
    cout << v[i].first << " " << v[i].second << endl;
  }
  */
  int sum_time = 0;
  bool ans =true;
  for(int i = 0; i < v.size(); i++){
    sum_time += v[i].first;
    if(sum_time > v[i].second){
      ans = false;
      break;
    }
  }
  
  if(ans)cout << "Yes" << endl;
  else cout << "No" << endl;

}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    ios();
    int n;
    cin >> n;
    vector<int> v(n);
    for(int& i : v){
        cin >> i;
    }
    vector<int> color(200010, 0);
    vector<ll> dp(n+1);
    dp[0] = 1;

    REP(i, n){
        if(color[v[i]] > 0 && v[max(i-1,0)] != v[i]){
            dp[i+1] = dp[i] + dp[color[v[i]]];
            dp[i+1] %= MOD;
        }else{
            dp[i+1] = dp[i];
        }
        color[v[i]] = i+1;
    }

    cout << dp.back() << endl;

    return 0;
}

Measured memory_bytes: 3456
sel='D'
#A
if sel=='A':
    N,M=map(int,input().split())
    ans=0
    ans+=M*(M-1)//2
    ans+=N*(N-1)//2
    print(ans)

#B
if sel=='B':
    def ispal(s):
        for i in range(len(s)//2+1):
            if s[i]!=s[-(i+1)]:
                return False
        return True

    S=input()
    if ispal(S) and ispal(S[:(N-1)//2]) and ispal(S[(N+3)//2-1:]):
        print('Yes')
    else:
        print('No')

#C
if sel=='C':
    L=int(input())
    print((L**3)/27)

#D
if sel=='D':    
    N=int(input())
    A=[int(i) for i in input().split()]
    kin=list(set(A))
    cnt={}
    for k in kin:
        cnt[k]=0
    for a in A:
        cnt[a]+=1
    SUM=0
    for k in kin:
        SUM+=cnt[k]*(cnt[k]-1)//2
    for a in A:
        if cnt[a]>=2:
            print(SUM-cnt[a]+1)
        else:
            print(SUM)
        
#E
if sel=='E':
    a=0

#F
if sel=='F':
    N,S=map(int,input().split())
    A=[int(i) for i in input().split()]
    
    for l in range(N):
        for r in range(l,N):
            print(tab[l][r])



Measured memory_bytes: 26780
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int k,count=0,temp;
	cin>>k;
	if(k<10){
		cout<<k<<endl;
		return 0;
	}
	set<long long int> s;
	s.emplace(1);s.emplace(2);s.emplace(3);s.emplace(4);s.emplace(5);s.emplace(6);s.emplace(7);s.emplace(8);s.emplace(9);
	count=+9;
	auto it=s.begin();
	while(1){
		temp=(*it)%10;
		if(temp!=0){
			s.emplace((*it)*10+temp-1);
			count++;
		}
		if(count>=k)
		break;
		s.emplace((*it)*10+temp);
		count++;
		if(count>=k)
		break;
		if(temp!=9){
			s.emplace((*it)*10+temp+1);
			count++;
		}
		if(count>=k)
		break;
		it++;
	}
	cout<<*(--s.end())<<endl;
}

Measured memory_bytes: 4992
#include <queue>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <functional>
#include <stack>
#include <iterator>
#include <set>
#include <cmath>
#include <list>
#include <map>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cstring>
using namespace std;
int n, m, x;
int c[12];
int a[12][12];
int chk(int buy)
{
    int num[12] = {0};
    int money = 0;
    for (int i = 0; i < n; ++i)
    {
        if (buy & (1 << i))
        {
            money += c[i];
            for (int j = 0; j < m; ++j)
                num[j] += a[i][j];
        }
    }
    for (int i = 0; i < m; ++i)
        if (num[i] < x)
            return -1;
    return money;
}
int main()
{
    // freopen("in", "r", stdin);
    // freopen("out", "w", stdout);
    cin >> n >> m >> x;
    for (int i = 0; i < n; ++i)
    {
        cin >> c[i];
        for (int j = 0; j < m; ++j)
            cin >> a[i][j];
    }
    int minn = 100000000;
    for (int i = 0; i < (1 << n); ++i)
    {
        int mm = chk(i);
        if (mm >= 0)
            minn = min(minn, mm);
    }
    if (minn == 100000000)
        minn = -1;
    cout << minn;
    return 0;
}

Measured memory_bytes: 3636
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)
#define endl '\n'

using ll = long long;
using db = long double;
using ii = pair<int, int>;

const int N = 1e5 + 5, LG = 19, MOD = 998244353;
const int SQ =320;
const long double EPS = 1e-7;
ll sum[N+N];
int n;
ll getSum(int l, int r){
  return sum[r] - sum[l-1];
}
int getPartition(int l, int r){

  int lo = l, hi = r - 1;
  while(lo < hi){

    int md = lo + (hi - lo + 1) / 2;

    if(getSum(l,md) <= getSum(md+1,r))
      lo = md;
    else
      hi = md - 1;

  }

  return lo;
}
int32_t main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif

  cin >> n;

  f(i,1,n+1)cin >> sum[i], sum[i] += sum[i-1];
  ll ans = LLONG_MAX;
  f(i,2,n-1){

    int x = getPartition(1,i);
    int y = getPartition(i+1,n);

    for(int j = -5; j <= 5; j++){
      for(int k = -5; k <= 5; k++){
        if(x + j < 1 || x + j >= i)continue;
        if(y + k <= i || y + k >= n)continue;
        vector<ll> v = {getSum(1,x+j),getSum(x+j+1,i),getSum(i+1,y+k),getSum(y+k+1,n)};
        sort(v.begin(),v.end());
        ans = min(ans, v.back()-v[0]);
      }
    }

  }

  cout << ans << '\n';


  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll m = 1000000007;

ll geom(ll n, ll r, ll mod = m) {
    ll T = 1, x = r%mod;
    ll total = 0;
    while(n) {
        if(n&1) {
            total = (x*total + T)%mod;
        }
        T = ((x+1)*T)%mod;
        x = (x*x)%mod;
        n = n/2;
    }
    return total;
}

ll mul(ll a, ll b, ll mod = m) {
    ll r = 0;
    a %= mod;
    while (b) {
        if (b & 1) {
            r = (r + a) % mod;
        }
        a = (a + a) % mod;
        b /= 2;
    }
    return r;
}

ll power(ll x, ll n, ll mod = m) {
    ll res = 1;
    x %= mod;
    while (n)  
    {  
        if (n & 1)  res = (res*x)%mod;  
        n = n/2; 
        x = (x*x)%mod;  
    }  
    return res;
}

ll power2(ll x, ll n) {
    ll res = 1;
    while (n > 0)  
    {  
        if (n & 1)  res = (res*x);  
        n = n/2; 
        x = (x*x);  
    }  
    return res;
}

bool is_prime(long long x) {
    if(x == 1 || x == 0) return false;
    for(int i=2; i*i <= x; i++) {
        if(x%i == 0) return false;
    }
    return true;
}

ll totient(ll n, vector<ll> primes) 
{ 
    ll res = n; 
    for (ll i=0; primes[i]*primes[i] <= n; i++) {
        if (n % primes[i]== 0) { 
            res -= (res / primes[i]); 
            while (n%primes[i]== 0) {
               n/=primes[i]; 
            }
        } 
    } 
    if (n > 1) {
       res -= (res / n); 
    }
    return res; 
} 

void sieve(vector<ll> &primes, vector<bool> &prime, ll lim) {
    for(int i = 2; i*i <= lim; i++) {
        if(prime[i]) {
            for(int j = 2; j*i <= lim; j++) {
                prime[j*i] = false;
            }
        }
    }
    for(int i = 2; i <= lim; i++) {
        if(prime[i]) {
            primes.push_back(i);
        }
    }
}

int main() 
{ 
    ios_base::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll count = (n >= 3 ? 2 : (n>=2 ? 1 : 0));
    for(ll i=2; i*i <= n; i++) {
        if(n%i == 1) {
            count++;
            if(i*i != (n-1)) {
                count++;
            }
        } else if(n%i == 0){
            ll x = n;
            while(x%i == 0) {
                x /= i;
            }
            if(x%i == 1) {
                count++;
            }
            if(n/(n/i) > n/i) {
                x = n;
                while(x % (n/i) == 0) {
                    x /= (n/i);
                }
                if(x%(n/i)==1) {
                    count++;
                }
            }
        }
    }
    cout << count << "\n";
    return 0;
} 

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll W, H;
  cin >> W >> H;
  // vl P(W), Q(H);
  vector<pll> C(W + H);
  REP(i, W) {
    ll p = 0;
    cin >> p;
    C[i] = make_pair(p, 0);
  }
  REP(i, H) {
    ll q = 0;
    cin >> q;
    C[i + W] = make_pair(q, 1);
  }
  sort(ALL(C));

  ll a = W + 1;
  ll b = H + 1;
  ll ans = 0;
  REP(i, W + H) {
    if (C[i].second == 0) {
      ans += (b * C[i].first);
      a--;
    } else {
      ans += (a * C[i].first);
      b--;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3456
// When you are hungry for something and you're determined and you're focused 
// and you're committed to something it's hard to surrender, isn't it?

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define ll long long 
#define int ll
#define mod 1000000007
#define mod1 1000000006
#define modi 998244353
#define setbit(x) __builtin_popcount(x)
#define fff(i,n) for(int i=0;i<n;i++)
#define ff first
#define ss second
#define pb push_back
vector<ll> vi[300005];
int color[100005];
ll pa[500005];
ll si[500005];
#define pb push_back
bool visi[1000005]={false};
bool is[100005];
ll fac[10000001];
ll prime[400005];
ll bit[100005];
const long double eps = 1.0e-14;      // allowable error
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
 
 
void fact(){
    fac[0]=1;
    for(int i=1;i<=10000000;i++){
        fac[i]=(fac[i-1]*i)%mod;
    }
    return ;
}
void sieve(){
    prime[0]=0;
    prime[1]=0;
    for(int i=2;i<400005;i++){
        prime[i]=1;
    }
    for(int i=2;i*i<400005;i++){
        if(prime[i]==1){
            for(int j=i*i;j<400005;j+=i){
                prime[j]=0;
            }
        }
    }
    
}
 
ll power(ll n , ll p ){
    if(p==0)
        return 1;
    
    ll res = power((n*n)%mod,p/2);
    if(p%2==1)
        res = (n*res)%mod;
    
    return res;
}
 
 
void upd(ll i,ll val,ll n) {
    for(;i<=n;i+=i&(-i))
        bit[i]+=val;
}
 
ll qry(ll i) {
    ll sum=0;
    for(;i>0;i-=i&(-i))
        sum+=bit[i];
    return sum;
}
 
 
ll fin(ll u) {
    if(pa[u]==u)
        return u;
    return fin(pa[u]);
}
 
void uni(ll u,ll v) {
    ll p1=fin(u);
    ll p2=fin(v);
    if(p1==p2)
        return;
    if(si[p1]<si[p2])
        swap(p1,p2);
    si[p1]+=si[p2];
    pa[p2]=p1;
    return;
}

int log(int x) {
    int i;
    for(i=0;(1ll<<i)<=x;i++);
    return i;
}
 
int32_t main() {
    fio
    
    cout << fixed << setprecision(15);
    int n,m,x;
    cin >> n >> m >> x;
    
    map<int,int> ma;
    fff(i,m) {
        int x;cin>>x;
        ma[x]=1;
    }
    
    int c=0;
    fff(i,x) {
        if(ma[i]==1)
        c++;
    }
    int d=0;
    for(int i=x+1;i<n;i++){
        if(ma[i]==1)
        d++;
    }
    
    cout << min(c,d);
    
    
	return 0;
    
}

Measured memory_bytes: 8960
import itertools
n, m = map(int, input().split())
ab = set()

for _ in range(m):
    a, b = map(int, input().split())
    ab.add((a, b))
    ab.add((b, a))

cnt = 0
for x in itertools.permutations(range(1, n + 1)):
    if x[0] != 1:
        break
    flag = True
    for i in range(len(x)-1):
        if (x[i], x[i + 1]) not in ab:
            flag = False
            break
    if flag:
        cnt += 1
print(cnt)


Measured memory_bytes: 3064
// All Heil Fire Lord Zuko

#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define PB push_back
#define debug(x) cerr << #x << " = " << x << endl

#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef long double ld;

const int N = 2 * 100 * 1000 + 19;

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n * a, b);
    return 0;
}


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

int main() {
  vector<int> a(3);
  cin >>a.at(0) >>a.at(1) >>a.at(2);
  sort(a.begin(), a.end());
  if(a.at(0)==a.at(1)&&a.at(1)==5&&a.at(2)==7){
    cout <<"YES" <<endl;
  }
  else{
    cout <<"NO" <<endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();

        long[] AList = new long[N];
        long[] BList = new long[N];

        for (int i=0; i < N; i++) {
            AList[i] = scanner.nextInt();
            BList[i] = scanner.nextInt();
        }

        Map<Long, Long> simekiriMap = new HashMap<>();
        for (int i=0; i < N; i++) {
            if (simekiriMap.containsKey(BList[i])) {
                simekiriMap.put(BList[i], simekiriMap.get(BList[i]) + AList[i]);
            } else {
                simekiriMap.put(BList[i], AList[i]);
            }
        }

        List<Map.Entry<Long, Long>> entryList = new ArrayList<>(simekiriMap.entrySet());
        entryList.sort((o1, o2) -> {
            long result = o1.getKey() - o2.getKey();
            if (result > 0) {
                return 1;
            } else if (result < 0) {
                return -1;
            }
            return 0;
        });

        long sum = 0;
        for (Map.Entry<Long, Long> entry : entryList) {
            if (entry.getKey() < entry.getValue() + sum) {
                System.out.println("No");
                return;
            }
            sum += entry.getValue();
        }

        System.out.println("Yes");
    }
}

Measured memory_bytes: 127960
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

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

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

template<class T>
bool umax(T &a, const T &b){
    if (a<b) {
        a=b; return 1;
    }
    return 0;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b<a) {
        a=b; return 1;
    }
    return 0;
}

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
// v.front() = -BOUND;
// v.back() = BOUND;

int main(){
    ll N;
    cin >> N;
    vector<ll>A(N);
    ll ans=0;

    rep(i,N){
        cin >> A[i];
    }

    ll r=0;
    ll l=0;
    ll result=0;
    while(r<N){
        if((result & A[r])==0){
            result+=A[r];
            r++;
            ans+=(r-l);
        }else if(l==r){
            l++;
            r++;
        }else{
            result-=A[l];
            l++;
        }
    }
    cout << ans <<endl;
    return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define printV(v) for(int i=0;i<v.size();i++){cout << v[i] << " ";} cout << endl
#define printRev(v) for(int i=v.size()-1;i >= 0;i--){cout << v[i] << " ";} cout << endl
#define sortV(v) sort(v.begin(),v.end())
ll a,b,c,d,e,f,g,n,m,k,t,p;

ll mod = 1000000007;


struct LCA {
    vector<int> height, euler, first, segtree;
    vector<bool> visited;
    int n;
 
    LCA(vector<vector<int>> &adj, int root = 0) {
        n = adj.size();
        height.resize(n);
        first.resize(n);
        euler.reserve(n * 2);
        visited.assign(n, false);
        dfs(adj, root);
        int m = euler.size();
        segtree.resize(m * 4);
        build(1, 0, m - 1);
    }
 
    void dfs(vector<vector<int>> &adj, int node, int h = 0) {
        visited[node] = true;
        height[node] = h;
        first[node] = euler.size();
        euler.push_back(node);
        for (auto to : adj[node]) {
            if (!visited[to]) {
                dfs(adj, to, h + 1);
                euler.push_back(node);
            }
        }
    }
 
    void build(int node, int b, int e) {
        if (b == e) {
            segtree[node] = euler[b];
        } else {
            int mid = (b + e) / 2;
            build(node << 1, b, mid);
            build(node << 1 | 1, mid + 1, e);
            int l = segtree[node << 1], r = segtree[node << 1 | 1];
            segtree[node] = (height[l] < height[r]) ? l : r;
        }
    }
 
    int query(int node, int b, int e, int L, int R) {
        if (b > R || e < L)
            return -1;
        if (b >= L && e <= R)
            return segtree[node];
        int mid = (b + e) >> 1;
 
        int left = query(node << 1, b, mid, L, R);
        int right = query(node << 1 | 1, mid + 1, e, L, R);
        if (left == -1) return right;
        if (right == -1) return left;
        return height[left] < height[right] ? left : right;
    }
 
    int lca(int u, int v) {
        int left = first[u], right = first[v];
        if (left > right)
            swap(left, right);
        return query(1, 0, euler.size() - 1, left, right);
    }
};
 
 






void solve(){
   string str; cin >> str;
   sort(str.begin(),str.end());
   if(str[0] == str[str.size()-1]){
       cout << "No"; 

   }else cout <<"Yes";
}

int main(){
    ios_base::sync_with_stdio(false);
    
    int cases = 1; 
    //cin >> cases;

    while(cases--){
        solve();
    }
    return 0;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <limits.h>
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define ll long long

ll max(ll a, ll b){
    if(a > b) return a;
    else return b;
}

ll min(ll a, ll b){
    if(a < b) return a;
    else return b;
}

int main(){
    int n;
    scanf("%d", &n);
    ll A[n];
    rep(i, 0, n) scanf("%lld", &A[i]);
    ll mn = INT_MAX, mx = INT_MIN, sum = 0;
    rep(i, 0, n){
        mn = min(mn, A[i]);
        mx = max(mx, A[i]);
        sum += A[i];
    }

    printf("%lld %lld %lld\n", mn, mx, sum);

    return 0;
}



Measured memory_bytes: 2100
#include <iostream>

using namespace std;

struct  Node { int p, l, r; };

Node T[100005];
int n, d[100005];

void print(int u) {
	cout << "node " << u << ": ";
	cout << "parent = " << T[u].p << ", ";
	cout << "depth = " << d[u] << ", ";

	if (T[u].p == -1) cout << "root, ";
	else if (T[u].l == -1)cout << "leaf, ";
	else cout << "internal node, ";

	cout << "[";
	for (int i = 0, c = T[u].l; c != -1; ++i, c = T[c].r) {
		if (i) cout << ", ";
		cout << c;
	}
	cout << "]" << endl;
}

void rec(int u, int p) {
	d[u] = p;
	if (T[u].r != -1) rec(T[u].r, p);
	if (T[u].l != -1) rec(T[u].l, p + 1);
}

int main() {
	int d, v, c, l, r; cin >> n;
	for (int i = 0; i < n; ++i) T[i].p = T[i].l = T[i].r = -1;

	for (int i = 0; i < n; ++i) {
		cin >> v >> d;
		for (int j = 0; j < d; ++j) {
			cin >> c;
			if (j == 0) T[v].l = c;
			else T[l].r = c;
			l = c;
			T[c].p = v;
		}
	}
	for (int i = 0; i < n; ++i)
		if (T[i].p == -1) r = i;

	rec(r, 0);
	for (int i = 0; i < n; ++i) print(i);

	return 0;
}


Measured memory_bytes: 7688
import java.util.Scanner;
class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
        int h=sc.nextInt();
        int n=sc.nextInt();
        int a[]=new int[n];
		for(int i=0; i<n; i++){
            a[i]=sc.nextInt();
        }
        int sum=0;
        for(int j=0; j<n; j++){
            sum+=a[j];
        }
        if(h-sum<=0){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
        sc.close();
    }
}

Measured memory_bytes: 50480
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
 
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
 
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;
    }
}

void main()
{
    long a,b,c;
    scan(a,b,c);
    long max = max(a,b,c);
    long min = min(a,b,c);
    (max - min).writeln();
}

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

long long N, M, K, dp[4009][4009][2], mod = 1000000007;

int main() {
	cin >> N >> M >> K;
	dp[0][0][0] = 1;
	for (int i = 1; i <= N + M; i++) {
		long long sum = 0;
		for (int j = 0; j <= N + M; j++) {
			// 合計が K - 1 なので, [j - K + 1, j) が OK
			sum += dp[i - 1][j][0];
			dp[i][j][0] = sum%mod;
			if (j - K + 1 >= 0) sum -= dp[i - 1][j - K + 1][0];
		}
		sum = 0;
		for (int j = 0; j <= N + M; j++) {
			// 合計が K なので, [j - K + 1, j - 1) が OK
			if (j >= 1) sum += dp[i - 1][j - 1][0];
			dp[i][j][1] = sum%mod;
			if (j - K + 1 >= 0) sum -= dp[i - 1][j - K + 1][0];
		}
	}
	long long ans = 0;
	for (int i = 1; i <= N + M; i++) {
		for (int j = 0; j <= N + M; j++) {
			int X = j, Y = i*(K - 1) + 1 - X;
			if (!((N - X) % (K - 1) == 0 && N - X >= 0)) continue;
			if (!((M - Y) % (K - 1) == 0 && M - Y >= 0)) continue;
			ans += dp[i][j][1];
		}
	}
	cout << ans%mod << endl;
	return 0;
}

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

int main(){
	int mus,sum,w,a,b;
	cin >> w >> a >> b;
	sum=a+w;
	mus=b+w;
	if (b>sum){
		cout << b-sum;
	}
	else if (mus<a){
		cout << a-mus;
	}
	else {
	
		cout << "0";
	}
	}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - 48;}
char myitoc(int N) {return '0' + N;}

signed main()
{
  int N, X;
  cin >> N >> X;
  
  int a = X, b = N - X;
  if (a > b) swap(a, b);
  int ans = N;
  cerr << a << " " << b << " " << ans << endl;
  while (a != 0 && b != 0)
  {
    if (b % a == 0) ans += -a + 2 * b;
    else ans += b / a * a * 2;
    b %= a;
    swap(a, b);
    cerr << a << " " << b << " " << ans << endl;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int h,r;
	scanf("%d %d",&h,&r);
	if(h>=0){
		printf("1\n");
	}
	else if(h<=-1&&h*-1==r){
		printf("0\n");
	}
	else{
		printf("-1\n");
	}
	return 0;
}


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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> pll;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define MOD 1000000007
#define ARRAY_MAX 100005

const int INF = 1e9+7;


int main(){

    ll t,n,k;
    cin >> t;
    for(int tm = 0;tm < t;tm++){
        cin >> n >> k;
        vector<ll> x(n);
        for(int i = 0;i < n;i++){
            cin >> x[i];
        }
        vector<ll> dist;
        for(int i = 0;i < n-1;i++){
            dist.push_back(x[i+1] - x[i]);
        }
        sort(dist.begin(),dist.end());
        
        ll ans = 0;
        for(int i = 0;i < (n-k);i++){
            ans += dist[i];
        }
        cout << ans << endl;
        x.shrink_to_fit();
        dist.shrink_to_fit();
    }

    return 0;
}


Measured memory_bytes: 5524
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <math.h>
using namespace std;

const int MAX_N=10000;
int h,w,n,a[MAX_N];

int main(){
	cin >> h >> w >> n;
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	
	int c=0;
	for(int i=0;i<h;i++){
		if(i%2==0){
			int s[w];
			for(int j=0;j<w;j++){
				s[j] = c+1;
				a[c]--;
				if(a[c]==0) c++;
			}
			for(int j=0;j<w;j++){
				cout << s[(w-1)-j] << " ";
			}
		}else{
			for(int j=0;j<w;j++){
				cout << c+1 << " ";
				a[c]--;
				if(a[c]==0) c++;
			}
		}
	cout << endl;
	}
	return 0;
}


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

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

		int max = a;
		if( max < b ){
			max = b;
		}
		if( max < c ){
			max = c;
		}
		printf("%d",a + b + c - max);

		return 0;
	}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  if(a <= 5)
    cout << 0 << endl;
  else if(5 < a && a < 13)
    cout << b/2 << endl;
  else
    cout << b << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  long long int k, i, j, min = 2, max = 3;
  scanf("%lld", &k);
  int a[k];
  for(i = 0; i < k; ++i) scanf("%d", &a[i]);
  if(a[k - 1] != 2) {
    printf("-1");
    return 0;
  }
  for(i = k - 2; i >= 0; --i) {
    long long int d1, d2;
    d1 = min / a[i];
    d2 = max / a[i];
    if(d1 == d2 && min % a[i]) {
      printf("-1");
      return 0;
    }
    d1 = (min + a[i] - 1) / a[i];
    min = d1 * a[i];
    max = d2 * a[i] + a[i] - 1;
    //printf("%d %d\n", min, max);
  }
  printf("%lld %lld", min, max);
  return 0;
}

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

int m[2][100];
int ans[2][100];
int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < 2; i++)
		for (int j = 0; j < n; j++)
		{
			cin >> m[i][j];
		}
	for (int i = 0; i < 2; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (i > 0) ans[i][j] = max(ans[i][j], ans[i - 1][j]);
			if (j > 0) ans[i][j] = max(ans[i][j], ans[i][j - 1]);
			ans[i][j] += m[i][j];
		}
	}
	cout << ans[1][n - 1];
	//system("pause");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long N;
  cin>>N;
  bool K=false;
  vector<long long>v(N);
  for(int X=0;X<N;X++){
    cin>>v[X];
    if(v[X]%2==1){
      K=true;
      cout<<"first"<<endl;
      break;
    }
  }
  if(K==false){
    cout<<"second"<<endl;
  }
}


Measured memory_bytes: 3964
#include<iostream>
#include<vector>
#include<queue>
#include<utility>

using namespace std;

int n,m,a,b;
vector<int> g[200005];
queue<pair<int,int>> q;
bool vis[200005];

int main() {
	cin >> n >> m;
	for(int i = 0; i < m; i++) {
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	vis[1] = 1;
	q.push(make_pair(1,0));
	while((int)q.size()) {
		auto f = q.front();
		q.pop();
		for(auto p : g[f.first]) {
			if(!vis[p]) {
				vis[p] = 1;
				q.push(make_pair(p,f.second+1));
				if(f.second+1 > 2) {
					cout << "IMPOSSIBLE" << "\n";
					return 0;
				} else if (p == n) {
					cout << "POSSIBLE" << "\n";
					return 0;
				}
			}
		}
	}
	cout << "IMPOSSIBLE" << "\n";
}

Measured memory_bytes: 13040
let scan_int () = Scanf.scanf " %d" (fun x -> x)
let print_int n = Printf.printf "%d\n" n

module PriorityQueue :
  sig
    type 'a t
    type 'a heap
    type 'a pq
    exception Is_empty
    val init : ('a -> 'a -> int) -> int -> 'a pq
    val size : 'a pq -> int
    val push : 'a pq -> 'a -> unit
    val top  : 'a pq -> 'a
    val pop  : 'a pq -> unit
    val empty: 'a pq -> bool
  end = 
  struct
    type 'a t = Nil | Val of 'a
    type 'a heap = ('a t) array
    type 'a pq = {heap: 'a heap; compare: 'a -> 'a -> int; mutable size: int}
    exception Is_empty
    let swap a i j = let tmp = a.(i) in begin a.(i) <- a.(j); a.(j) <- tmp end
    let init comp max_size = {heap = Array.make (max_size+1) Nil; compare = comp; size = 0}
    let size pq = pq.size
    let t_compare pq i j =
      match pq.heap.(i), pq.heap.(j) with
        Nil, Nil -> 0 | Nil, _ -> -1 | _, Nil -> 1 | Val(a), Val(b) -> pq.compare a b 
    let push pq a =
      let _ = pq.size <- (pq.size + 1) in
      let _ = pq.heap.(pq.size) <- Val(a) in
      let rec upheap h i =
        if i > 1 && t_compare pq i (i/2) > 0 then
          let _ = swap h (i/2) i in upheap h (i/2) in
      upheap pq.heap pq.size
    let top pq =
      match pq.heap.(1) with Nil -> raise Is_empty | Val(a) -> a
    let pop pq =
      if pq.size = 0 then raise Is_empty
      else
        let _ = pq.heap.(1) <- Nil in
        let _ = swap pq.heap 1 pq.size in
        let _ = pq.size <- pq.size - 1 in
        let rec downheap h i = 
          let l = 2*i and r = 2*i+1 in
          let j = if l <= pq.size && t_compare pq l i > 0 then l else i in
          let j = if r <= pq.size && t_compare pq r j > 0 then r else j in
          if j <> i then let _ = swap h i j in downheap h j in
      downheap pq.heap 1
    let empty pq = pq.size = 0
  end

let () =
  let n = scan_int() and m = scan_int() in
  let arr = Array.make n (0, 0) in
  let rec read_loop i =
    if i < n then
      let a = scan_int() and b = scan_int() in 
      let _ = arr.(i) <- (a, b) in read_loop (i+1) in
  let _ = read_loop 0 in
  let f (la, lb) (ra, rb) = if la <> ra then la - ra else lb - rb in
  let _ = Array.fast_sort f arr in
  let pq = PriorityQueue.init compare n in
  let rec calc day index ret =
    if day > m then ret
    else 
      if index < n then
        let a, b = arr.(index) in
        if a = day then
          let _ = PriorityQueue.push pq b in calc day (index+1) ret
        else
          if not (PriorityQueue.empty pq) then
            let ret = ret + (PriorityQueue.top pq) in
            let _ = PriorityQueue.pop pq in calc (day+1) index ret
          else calc (day+1) index ret
      else
        if not (PriorityQueue.empty pq) then
          let ret = ret + (PriorityQueue.top pq) in
          let _ = PriorityQueue.pop pq in calc (day+1) index ret
        else calc (day+1) index ret in
  print_int (calc 1 0 0)

Measured memory_bytes: 9344
import math
import sys


def lcm(a, b):
  return a * b // math.gcd(a, b)


input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
LCM = 1
ans = 0
MOD = 1000000007
for x in A:
  LCM = lcm(LCM, x)
for x in A:
  ans += LCM // x

print(ans%MOD)

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  int n ; 
  cin >> n ; 
  cout << (n-2) *180 <<endl ;
}


Measured memory_bytes: 3568