akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define range(i, l, r) for (int i = l; i < r; i += 1)

pair< int, int > dp[33][33][33][33];

void solver(int h, int w, int s) {
    vector< vector< int > > u(h + 1, vector< int >(w + 1, 0));
    for (int i = 1; i <= h; ++i) for (int j = 1; j <= w; ++j) {
        cin >> u[i][j];
        u[i][j] += u[i - 1][j] + u[i][j - 1] - u[i - 1][j - 1];
    }

    range(a, 0, h + 1) range(b, 0, h + 1) {
        range(c, 0, w + 1) range(d, 0, w + 1) {
            dp[a][b][c][d] = make_pair(0, 0);
        }
    }

    pair< int, int > none(0, 0);
    range(dh, 1, h + 1) range(dw, 1, w + 1) {
        range(i, dh, h + 1) range(j, dw, w + 1) {
            int a = i - dh, c = j - dw;
            int b = i,      d = j;

            range(mi, a + 1, b) {
                pair< int, int > l = dp[a][mi][c][d], r = dp[mi][b][c][d];
                if (l == none || r == none) continue;
                pair< int, int > nxt(l.first + r.first, min(l.second, r.second));
                dp[a][b][c][d] = max(dp[a][b][c][d], nxt);
            }

            range(mj, c + 1, d) {
                pair< int, int > l = dp[a][b][c][mj], r = dp[a][b][mj][d];
                if (l == none || r == none) continue;
                pair< int, int > nxt(l.first + r.first, min(l.second, r.second));
                dp[a][b][c][d] = max(dp[a][b][c][d], nxt);
            }

            if (dp[a][b][c][d] == none) {
                int now = u[a][c] + u[b][d] - u[b][c] - u[a][d];

                if (now >= u[h][w] - s) {
                    dp[a][b][c][d] = make_pair(1, now);
                }
            }
        }
    }

    auto ans = dp[0][h][0][w];

    cout << ans.first << " " << s + ans.second - u[h][w] << endl;
}

int main() {
    int h, w, s;

    while (cin >> h >> w >> s, h && w && s) {
        solver(h, w, s);
    }
}



Measured memory_bytes: 12416
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      s: chars,
    }
    let mut cnt = 1;
    for i in 1..s.len() {
        if s[i] != s[i-1] {
            cnt += 1;
        }
    }
    println!("{}", cnt-1);
}


Measured memory_bytes: 4352
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,k = inpl()
g = [[] for _ in range(n)]
for i in range(n-1):
    a,b = inpl()
    a -= 1; b -= 1
    g[a].append(b)
    g[b].append(a)
res = k
q = deque()
q.append(0)
fin = set()
fin.add(0)
while q:
    v = q.popleft()
    cnt = 1 if v == 0 else 2
    for nv in g[v]:
        if nv in fin:
            continue
        res *= k-cnt
        res %= mod
        cnt += 1
        fin.add(nv)
        q.append(nv)
print(res)

Measured memory_bytes: 93468
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
static const int INF (1<<30);

int main() {
  int A, B; cin >> A >> B;
  
  if ((A+B)%2 == 0) cout << (A+B)/2 << endl;
  else cout << "IMPOSSIBLE" << endl;

  return 0;
}

Measured memory_bytes: 256
n, a, b = map(int, input().split())
monsters = [int(input()) for _ in range(n)]

right = max(monsters) // b + 1
left = 0

while left+1 < right:
    bomb_count = (left+right) // 2
    base_damage = bomb_count * b

    center_count = 0
    for hp in monsters:
        if hp <= base_damage:
            continue

        remaining_hp = hp - base_damage
        need_center = (remaining_hp + a-b-1) // (a-b)
        center_count += need_center

    if center_count <= bomb_count:
        right = bomb_count
    else:
        left = bomb_count

print(right)


Measured memory_bytes: 7072
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int taro = 0;
        int hanako = 0;
        int scint = sc.nextInt();
        for (int i = 0; i < scint; ++i) {
            int c = sc.next().compareTo(sc.next());
            if (c > 0) {
                taro += 3;
            } else if (c == 0) {
                taro++;
                hanako++;
            } else {
                hanako += 3;
            }
        }
        System.out.println(taro + " " + hanako);
    }
}


Measured memory_bytes: 29172
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define INF (2e9)
const int maxv=100+10;
const int maxe=9900+10;
int V,E;
int d[maxv][maxv];

void floyd()
{

    for(int k=0; k<V; k++)
    {
        for(int i=0; i<V; i++)
        {
            if(d[i][k]==INF) continue;
            for(int j=0; j<V; j++)
            {
                if(d[k][j]==INF) continue;
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);

            }
        }
    }
}
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d%d",&V,&E);
    int u,v,cost;
    for(int i=0; i<V; i++)
    {
        for(int j=0; j<V; j++)
        {
            if(i==j) d[i][j]=0;
            else d[i][j]=INF;

        }
    }
    for(int i=0; i<E; i++)
    {
        scanf("%d%d%d",&u,&v,&cost);
        d[u][v]=cost;

    }
    floyd();
    bool negative=false;
    for(int i=0; i<V; i++)
    {
        if(d[i][i]<0) negative=true;
    }
    if(negative)
    {
        printf("NEGATIVE CYCLE\n");
    }
    else
    {
        for(int i=0; i<V; i++)
        {
            for(int j=0; j<V; j++)
            {
                if(j) printf(" ");
                if(d[i][j]!=INF) printf("%d",d[i][j]);
                else printf("INF");
            }
            printf("\n");
        }
    }
    return 0;
}

Measured memory_bytes: 3264
n = int(input())
b = list(map(int, input().split()))

last = 10 ** 6
sum = 0
for i in range(0, n - 1):
    if b[i] < last:
        sum += b[i]
    else:
        sum += last
    last = b[i]

sum += b[n-2]

print(sum)


Measured memory_bytes: 38256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <math.h>
#include <string.h>
#define mp make_pair
#define pb push_back
#define pm %1000000007
#define llc (long long)
#define ldc (long double)
#define poc __builtin_popcount
using namespace std;

int modex(int b, int e){
	int h = 1;
	while(e){
		if(e&1)h=llc h*b pm;
		b=llc b*b pm;
		e>>=1;
	}
	return h;
}
int main(){
	int n;
	cin>>n;
	int inp;
	for(int i = 0;i < n;i ++){
		cin>>inp;
		if(inp&1){
			printf("first\n");
			return 0;
		}
	}
	printf("second\n");
	return 0;
}
/*
0 0123456789

0 212121
1 111111
2 212121
3 111111
4 212121
5 111111
6 
7 
8 
9 
*/

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include <vector>
using namespace std;
#define vi vector<int>
#define pb push_back
#define p push
#define sll stack<long long>
#define qll queue<long long>
#define vll vector<long long>
#define fori(n) for(int i=0;i<n;i++)
#define forj(n) for(int j=0;j<n;j++)
#define fork(n) for(int k=0;k<n;k++)
#define fori1(n) for(int i=1;i<n;i++)
#define f(i,a,b) for(int i=a;i<=b;i++)
#define ll long long
#define pi 3.14159265358979323
#include <math.h>
#define yn(n) if(n)cout<<"yes\n";else cout<<"no\n";
#define Yn(n) if(n)cout<<"Yes\n";else cout<<"No\n";
#define YN(n) if(n)cout<<"YES\n";else cout<<"NO\n";
#define mp   make_pair 
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll lcm(ll a, ll b){return a*b/gcd(a, b);}


ll sum = 0;
int md(int n){
	if(n>0)return n;
	else return -n;
}
string str1,str2;
void solve(){
	ll n,d;cin>>n>>d;
	ll ans=0;
	fori(n){
		ll a,b;cin>>a>>b;
		if(d*d>=a*a+b*b)ans++;
	}
	cout<<ans;
}


int main(){
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
 
     cin.tie(0);
    ios::sync_with_stdio(false);
   
	
	int t;
	t=1;
	//cin >> t;
	while(t--){
		solve();
	}	
	//cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";

}

Measured memory_bytes: 3608
n, m = map(int, input().split())
if m == 1:
    print(1, 2)
    exit()
l1 = 1
l2 = m + 2
f = True
for length in range(m, 0, -1):
    if f:
        print(l1, l1 + length)
        l1 += 1
        f = False
    else:
        print(l2, l2 + length)
        l2 += 1
        f = True


Measured memory_bytes: 9256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        String s = sc.next();
        int cnt = 1;
        int fcnt = 1;
        for (int i = 0; i < n; i++) {
            char c = s.charAt(i);
            if (c == 'a' && cnt <= a + b) {
                System.out.println("Yes");
                cnt++;
                continue;
            }
            if (c == 'b' && cnt <= a + b && fcnt <= b) {
                System.out.println("Yes");
                cnt++;
                fcnt++;
                continue;
            }
            System.out.println("No");
        }
    }

}


Measured memory_bytes: 34620
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    bitset<61> bs(n);

    constexpr auto M = 1000000007L;
    vector dp(61, vector(3, 0L));
    dp[60][0] = 1;
    for (auto i : irange(0L, 60L) | reversed) {
        dp[i][0] = dp[i + 1][0] + (1 - bs[i]) * dp[i + 1][1];
        dp[i][0] %= M;
        dp[i][1] = bs[i] * dp[i + 1][0] + dp[i + 1][1];
        dp[i][1] %= M;
        dp[i][2] += 3 * dp[i + 1][2] + (1 + bs[i]) * dp[i + 1][1];
        dp[i][2] %= M;
    }

    cout << (dp[0][0] + dp[0][1] + dp[0][2]) % M << endl;

    return 0;
}

Measured memory_bytes: 3592
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

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

func main() {
	sc.Split(bufio.ScanWords)
	H, W := nextInt(), nextInt()
	C := make([]rune, H*W)

	for i := 0; i < H; i++ {
		for j, c := range nextStr() {
			C[i*W+j] = c
		}
	}

	for i := 0; i < H*2; i++ {
		for j := 0; j < W; j++ {
			fmt.Print(string(C[(i/2)*W+j]))
		}
		fmt.Println()
	}
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;

int main(){
  
  int n,k; cin>>n>>k;
  vector<int> a(n);
  for(auto &i:a) cin>>i;
  deque<int> d;
  for(int i=0; i<k; i++){
    d.push_back(a.at(i));
  }
  for(int i=k; i<n; i++){
    auto b = d.front();
    if(b<a.at(i)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    d.pop_front();
    d.push_back(a.at(i));
  }
  
  
}


Measured memory_bytes: 4796
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;

int main(void) {
    string S; cin>>S;
    int S_length = S.length();
    ll ans = 0;
    for (int i = 0; i < (1<<(S_length-1)); ++i) {
        ll now = 0;
        for (int j = 0; j < S_length; ++j) {
            now = now*10 + S[j]-'0';
            if(i & (1<<(S_length-j-2))){
                ans += now;
                now = 0;
            }
        }
        ans += now;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);

    int N, K;
    cin >> N >> K;
    vector<int> p(N);
    vector<long double> e(N);
    REP (i, N) {
        cin >> p[i];
        e[i] = (p[i] + 1) / 2.0;
    }
    long double ans = 0, sum = 0;
    REP (i, K) sum += e[i];
    REP (i, N - K + 1) {
        ans = max(ans, sum);
        sum -= e[i];
        if (i + K < N) sum += e[i + K];
    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
#include <stdio.h>
#include <math.h>

void main(void){
    int x,y,z;
    int N;
    if(scanf("%d",&N) == 0){}
    
    int sum [N];
    for (int  i = 0; i < N; i++){
        sum[i] = 0;
    }
    
    for( x = 1;x <= (int)sqrt(N - 5);x++){
        for(y = 1; y <= (int)sqrt(N - x*x - 2*x - 2 );y++){
            for(z = 1;z <= (int)sqrt(N - x*x - y*y - x*y - x - y );z++){
                int e = x*x + y*y + z*z + x*y + y*z + z*x;
                if(e <= N){
                    sum[e-1]++;
                }
            }
        }
    }
    for(int i = 0;i < N;i++){
        printf("%d\n",sum[i]);
    }
    
}

Measured memory_bytes: 2140
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <iomanip>
#include <string.h>
#include <sstream>
//#define N 200

using namespace std;
long long cmd(long long a , long long  b){
    return a > b;
}

int main()
{
    string s;
    while(cin>>s)
    {
        stringstream ss,sss,ssss;
        string hi , ha;
        long long num;
        ss<<s;
        ss>>num;
        int sq = (int )sqrt(num);
        int flag=0;
        for(int i=1;i<=sq;i++)
        {
            if(num%i==0)
            {
                //cout<<i<<" "<<endl;
                for(int j=sq;j>0;j--)
                {
                    if(num%j==0)
                    {
                        long long hah = num/j;
                        //cout<<hah<<" "<<endl;
                        ssss<<hah;
                        ssss>>hi;
                        sss<<j;
                        sss>>ha;
                        long long ma = max(hi.length(),ha.length());
                        cout<<ma<<endl;
                        break;
                    }
                }
                flag=1;
                break;
            }
        }
        if(flag==0)
            cout<<s.length()<<endl;
    }
    return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){

    int aa, bb, m;
    int a[100010], b[100010];
    int x[100010], y[100100], c[100010];
    cin >> aa>>bb>>m;
    int min_a = 200000, min_b = 200000;
    for(int i=0; i < aa; i++){
        cin >> a[i];
        min_a = min(min_a, a[i]);
    }
    for(int i=0; i < bb; i++){
        cin >> b[i];
        min_b = min(min_b, b[i]);
    }
    int min_ans = min_a+min_b;
    for(int i = 0; i < m; i++){
        cin >> x[i] >>y[i]>>c[i];
        min_ans = min(min_ans, a[x[i]-1]+b[y[i]-1]-c[i]);
    }
    cout << min_ans << endl;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
#define int long long int  //comment for large arrays
#define pll pair<int,int>
#define dbl long double
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000007
#define eps 0.00000001
#define INF 10000000000000001
#define all(x) (x).begin(),(x).end()
#define LB(v,x) (lower_bound(all(v),x) - v.begin()) 
#define UB(v,x) (upper_bound(all(v),x) - v.begin())
#define size(x) (int)(x).size()
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define popb() pop_back()
#define popf() pop_front()
#define mp(x,y) make_pair((x),(y))
#define vec(dt) vector<dt>
#define vv(dt) vector<vector<dt>>
#define fastio(x) ios_base::sync_with_stdio(x); cin.tie(NULL)
#define init(v,s) memset(v,s,sizeof(v)) 
#define bug(x) cerr<<"LINE: "<<__LINE__<<" || click to see test details "<<#x<<" = "<<x<<endl
#define loop(i,s,n) for(int i=s;i<n;i++)
#define bugprint(v) for(auto it:v) cout<<it<<" "; cout<<endl 
using namespace std;


signed main()
{
	fastio(0);
	string s,t;
	cin>>s;
	cin>>t;
	int n = size(s), m = size(t);
	s = '#' + s;
	t = '#' + t;
	int dp[m+1][n+1];
	loop(i,0,n+1) dp[0][i] = 0;
	loop(i,0,m+1) dp[i][0] = 0;
	loop(i,1,m+1)
	{
		loop(j,1,n+1)
		{
			if(s[j]==t[i]) dp[i][j] = dp[i-1][j-1] + 1;
			else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
		}
	}
	set<int> ss;
	int j=n,i=m;
 	while(i>0 && j>0)
	{
		if(s[j]==t[i]) 
		{
			ss.insert(j);
			j--;
			i--;
		}
		else if(dp[i][j]==dp[i-1][j]) i--;
		else j--;
	}
	string ans = "";
	for(auto it:ss) ans += s[it];
	cout<<ans<<endl;
	return 0;		
}

Measured memory_bytes: 70784
package main
 
import (
	"fmt"
	"strconv"
)
 
 
func main(){
	var s string
	fmt.Scan(&s)
	var dp []int
	n := len(s)
	dp = append(dp,0)
	var sum int
	ten := 1
	for i:=n-1 ; i>=0 ; i-- {
		x,_ := strconv.Atoi(s[i:i+1])
		x = ((x*ten)%2019 + sum%2019)%2019
		ten *= 10
		ten = ten%2019
		sum = x
		dp = append(dp,x)
	}
//fmt.Println(dp)
	ans := make([]int,2019)
	for i:=0 ; i<len(dp) ; i++ {
		ans[dp[i]]++
	}
	var a int
	for i:=0 ; i<2019; i++ {
		a += ans[i]*(ans[i]-1)/2
	}
	fmt.Println(a)
}

Measured memory_bytes: 8996
// AtCoder150 C

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include <string.h>
#include <memory.h>
#include <malloc.h>
#include <stdlib.h>
#include <ctype.h>

// qsortで用いる比較用関数．*a<*bならaが先になる．
int compare(const void* a, const void* b) {
    return *(int*)a - *(int*)b;
}

int revcompare(const void* a, const void* b) {
    return *(int*)b- *(int*)a;
}

int main(void)
{
    int i,j,n;

    int a,b,c,d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    int x = c-a;
    int y = d - b;
    printf("%d %d %d %d", c-y, d+x, a-y, b+x);
    return 0;

}


Measured memory_bytes: 128
/*我是萌新*/
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include <iomanip> 
typedef long long ll;
const int mod = 1e9 + 7;
using namespace std;
ll gcd(ll a, ll b) {
    return b ? gcd(b, a % b) : a;
}
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    string s;
    while (cin >> s)
    {
        if (s[2] == s[3] && s[4] == s[5])
            cout << "Yes\n";
        else cout << "No\n";
    }
}



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

#define fa(x,v) for(auto x:v)
#define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define spc " "
#define endl '\n'
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(s) (ll)int(s.length())
#define sz(v) (ll)int(v.size())
#define MOD 1000000007

void Fast_IO() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    freopen("debug.out","w",stderr);
    #endif
} 

// Code Here

int main()
{
    // Fast_IO();
    ll a; string b; cin >> a >> b;
    ll ans = a * (b[0] - '0');
    ll add1 = a * (10 * (b[2] - '0') + (b[3] - '0'));
    add1 /= 100;
    ans += add1;
    cout << ans;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;

int main(){
	cin>>n;
	if(n==3){
		cout<<2<<' '<<5<<' '<<63<<endl;
		return 0;
	}
	vi a,b;
	for(int i=1;i<=30000;i++){
		if(i%2==0) a.push_back(i);
		else if(i%3==0) b.push_back(i);
	}
	int B=min(5000,n/2*2),A=n-B;
	if(!A) A+=2,B-=2;
	if(A%3==1) A+=2,B-=2;
	vi c;
	for(int i=0;i<A;i++) c.push_back(a[i]);
	for(int i=0;i<B;i++) c.push_back(b[i]);
	for(int i=0;i<n;i++) cout<<c[i]<<" \n"[i==n-1];
}

Measured memory_bytes: 640
rep = input()
while rep:
	rep -= 1
	[a, b, c] = map(int, raw_input().split())
	if b < a and c < a:
		a **= 2
		b = b ** 2 + c ** 2
	elif a < b and c < b:
		a = a ** 2 + c ** 2	
		b **= 2
	else:
		a = a ** 2 + b ** 2
		b = c ** 2
	if a == b:
		print 'YES'
	else:
		print 'NO'

Measured memory_bytes: 4212
//#typedef int ll
// include
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <tuple>
// namespace
using namespace std;
// typedef
typedef long long ll;
typedef long double ld;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pint;
// const
const int inf = 1e9;
const ll mod = ((ll)1e9 + 7);
// loop
#define rep(i, n) for(int i = 0, i##_mx = n; i < i##_mx; i++)
#define brep(i, b, e) for(int i = b; i < e; i++)
#define erep(i, b, e) for(int i = b; i <= e; i++)
#define rrep(i, b, e) for(int i = b; i >= e; i--)
// STL
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) (v).begin(), (v).end()
// sort
#define vsort(v, b) sort(all(v), [](auto l, auto r){return (b);})
// access
#define gt(i, n) get<n>(i)
// function
ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
void prime(vint& v, int n){brep(i, 2, n){bool fg = false; for(auto e : v){if(i % e == 0){fg = true;}} if(fg){continue;} v.pb(i);}}
void in(vint& v){for(auto& i : v){cin >> i;}}
void in(vll& v){for(auto& i : v){cin >> i;}}

signed main(){
    int n;
    cin >> n;
    
    vint p;
    p.resize(n);
    in(p);
    
    int ans = 0;
    rep(i, n - 2){
        if(p[i] + p[i + 1] + p[i + 2] - max({p[i], p[i + 1], p[i + 2]}) - min({p[i], p[i + 1], p[i + 2]}) == p[i + 1]){
            ans++;
        }
    }
    
    cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define swap(type, x, y)  do{ type t = x; x = y; y = t; }while(0)

void quick(int array[], int left, int right, int mode, int id[]){
  int pl = left, pr = right;
  int x = array[(left + right) / 2];
  do{
    while(array[pl] < x)  pl++;
    while(array[pr] > x)  pr--;
    if(pl <= pr){
      swap(int, array[pl], array[pr]);
      if(mode)  swap(int, id[pl], id[pr]);
      pl++, pr--;
    }
  }while(pl <= pr);
  if(pl < right)  quick(array, pl, right, mode, id);
  if(pr > left)  quick(array, left, pr, mode, id);
}

int main(){
  int n, m;  scanf("%d %d", &n, &m);
  int x[100005], id[100005];
  for(int i=0; i<m; i++)  scanf("%d", x+i);
  if(n >= m){
    printf("0\n"); return 0;
  }
  quick(x, 0, m-1, 0, id);
  int sa[100005];
  for(int i=0; i<m-1; i++){
    sa[i] = x[i+1] - x[i];
    id[i] = i;
  }
  quick(sa, 0, m-2, 1, id);
  quick(id, m-n, m-2, 0, id);
  long ans = 0;
  int start = 0;
  for(int i=m-n; i<=m-2; i++){
    ans = ans + (long)(x[id[i]] - x[start]);
    start = id[i] + 1;
  }
  ans = ans + (long)(x[m-1] - x[start]);

  printf("%ld\n", ans);
  return 0;
}


Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int D = sc.nextInt();
		int N = sc.nextInt();
		sc.close();
		
		int ans = 1;
		if(D == 1)
			ans = 100;
		else if(D == 2)
			ans = 10000;
		ans *= N + N/100;
		System.out.println(ans);
	}
}


Measured memory_bytes: 23124
#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector<vector<int>> mat;
//typedef unsigned int uint;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N, i;
	cin >> N >> i;
	cout << N - i + 1 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pi>
#define vpl vector<pl>
#define pb push_back
#define INF 1000000005
#define LINF 1000000000000000005

int n,q,ans;

string s;

pair<char,char> a[200005];

bool reml(int x){
    x--;
    for(int i=1;i<=q;i++){
        if(a[i].x==s[x]){
            if(a[i].y=='L') x--;
            else x++;
        }
        if(x<0) return 1;
        if(x>=n) return 0;
    }
    return 0;
}

bool remr(int x){
    x--;
    for(int i=1;i<=q;i++){
        if(a[i].x==s[x]){
            if(a[i].y=='L') x--;
            else x++;
        }
        if(x<0) return 0;
        if(x>=n) return 1;
    }
    return 0;
}

int32_t main(){
    /*seed_seq seq{
        (uint64_t) chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count(),
        (uint64_t) __builtin_ia32_rdtsc(),
        (uint64_t) (uintptr_t) make_unique<char>().get()
    };
    mt19937 rng(seq);*/
#ifdef LOCAL_DEFINE
    ifstream cin("input.in");
#endif
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();

    cin >> n >> q >> s;
    for(int i=1;i<=q;i++){
        cin >> a[i].x >> a[i].y;
    }
    int l=0,r=n;
    while(l!=r){
        int mid=(l+r+1)/2;
        if(reml(mid)) l=mid;
        else r=mid-1;
    }
    ans+=l;
    //cout << ans << '\n';
    l=1,r=n+1;
    while(l!=r){
        int mid=(l+r)/2;
        if(remr(mid)) r=mid;
        else l=mid+1;
    }
    ans+=n-r+1;
    cout << n-ans;
}


Measured memory_bytes: 976
from collections import deque
S = deque(input())
Q = int(input())
q = [input().split() for _ in range(Q)]
flag = True
for x in q:
    if x[0] == "1":
        if flag: flag = False
        else: flag = True
    else:
        if x[1] == "1":
            if flag: S.appendleft(x[2])
            else: S.append(x[2])
        else:
            if flag: S.append(x[2])
            else: S.appendleft(x[2])
s = list(S)
if not flag: s = s[::-1]
print("".join(s))

Measured memory_bytes: 49060
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}



int n,a[5555],b[5555];
ll d[2525],c[5555];
bool visited[2525],pos[2525];
vector<int> g[2525];

bool dfs(int v){
	int i;
	visited[v] = true;
	if(v==n){
		return pos[v] = true;
	}
	for(i=0; i<g[v].l_ength(); ++i){
		if(visited[g[v][i]]){
			continue;
		}
		if(dfs(g[v][i])){
			return pos[v] = true;
		}
	}
	return pos[v] = false;
}

int main(void){
	int m,i,cnt=0,j;
	bool update,loop = false;
	ll p;
	fill(d,d+2525,INFLL);
	d[1] = 0ll;
	cin >> n >> m >> p;
	for(i=0; i<m; ++i){
		cin >> a[i] >> b[i] >> c[i];
		c[i] = p - c[i];
		g[a[i]].push_back(b[i]);
	}
	dfs(1);
	while(true){
		update = false;
		for(i=0; i<m; ++i){
			if(d[b[i]]>d[a[i]]+c[i]){
				update = true;
				d[b[i]] = d[a[i]]+c[i];
			}
		}
		if(!update){
			break;
		}
		if(cnt > n){
			break;
		}
		++cnt;
	}
	for(j=0; j<n; ++j){
		for(i=0; i<m; ++i){
			if(d[b[i]]>d[a[i]]+c[i]){
				d[b[i]] = d[a[i]]+c[i];
				if(pos[b[i]]){
					loop = true;
				}
			}
		}
	}
	if(loop){
		cout << -1 << endl;
		return 0;
	}
	cout << max(-d[n],0ll) << endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0;i--)
#define _GLIBCXX_DEBUG
using namespace std;

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  fspcnt = 0;
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
int64_t univMod = 1000000007;
int64_t factnum = 200000; //変更すること
vector<int64_t> modfact(factnum);
vector<int64_t> modinvfact(factnum);

void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t modpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t modinverse(int64_t n){
	return modpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = modpower(modfact.at(i),univMod-2);
    }
  }
}

int64_t modcomb(int64_t n,int64_t r){
  return (((modfact.at(n)*modinvfact.at(n-r))%univMod)*modinvfact.at(r))%univMod;
}

int64_t modperm(int64_t n,int64_t r){
  return (modfact.at(n)*modinvfact.at(n-r))%univMod;
}

int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}


int main(){
  int64_t n,k;
  cin >> n >> k;
  setmodfact();
  setmodinvfact();
  for(int64_t i = 1;i <= k; i++){
    if(n-k-i+1 < 0){
      cout << 0 << endl;
    }else{
      int64_t hoge = (modcomb(n-k+1,i)*modcomb(k-1,i-1))%univMod;
      cout << hoge << endl;
    }
  }
    
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int n;
    cin >> n;
    vi a(n);
    cin >> a;
    vi bc(21, 0);
    int l = 0, ans = 0;
    REP(i, n) {
        bool over = false;
        REP(j, 21) {
            if ((a[i] >> j) & 1) bc[j]++;
            if (bc[j] > 1) over = 1;
        }
        if (over) {
            while (1) {
                bool over = false;
                REP(j, 21) {
                    if ((a[l] >> j) & 1) bc[j]--;
                    if (bc[j] > 1) over = true;
                }
                l++;
                if (!over) {
                    break;
                }
            }
        }
        ans += i - l + 1;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int a,b,c,k;
vi ans;
int main(){
	ios::sync_with_stdio(0);
	cin>>a>>b>>k;
	c=__gcd(a,b);
	for(int i=c;i>0;i--){
		if(c%i)
		continue;
		k--;
		if(!k){
			cout<<i;
			re 0;
		}
	}
	re 0;
}


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

int main(void)
{
  int A,B,K,Ans,Bns;
  scanf("%d",&A);scanf("%d",&B);
  for(K=0;K<=1000000000;K++){
    Ans=abs(A-K);
    Bns=abs(B-K);
    if(Ans==Bns){
      printf("%d",K);
      break;
    }else if(K==1000000000){
      printf("IMPOSSIBLE");
      }
    }
    return 0;
  }



Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

namespace ARC96_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = ReadLine().Split();
            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);
            int c = int.Parse(s[2]);
            int x = int.Parse(s[3]);
            int y = int.Parse(s[4]);

            long m = (long)5000 * 1000000;
            for (int i = 0; i <= Math.Max(x,y); i++)
            {
                m = Math.Min(m, c * 2 * i + a * Math.Max(x - i, 0) + b * Math.Max(y - i, 0));
            }
            WriteLine(m);
        }
    }
}


Measured memory_bytes: 11220
#include <stdio.h>
#include <string.h>
int queue[1000000];
int head, tail;

void enq(int i);

int deq();

int emp();


int main() {
  int n;
  int A[101][101] = {{}};
  int i, j;
  scanf("%d", &n);
  for(i = 0; i < n; i++) {
    int u, k;
    scanf("%d %d", &u, &k); --u;
    for(j = 0; j < k; j++) {
      int v;
      scanf("%d", &v); --v;
      A[u][v] = 1;
    }
  }
  int dist[101];
  memset(dist, -1, sizeof(dist));
  enq(0);
  dist[0] = 0;
  while(!emp()) {
    int u = deq();
    for(i = 0; i < n; i++) {
      if(A[u][i] == 1 && dist[i] == -1) {
    enq(i);
    dist[i] = dist[u]+1;
      }
    }
  }
  for(i = 0; i < n; i++) printf("%d %d\n", i+1, dist[i]);
 
  return 0;
}

void enq(int i) {
  if((tail+1)%1000000 == head) return;
  queue[tail] = i;
  tail++;
  tail %= 1000000;
}

int deq() {
  int res;
  if(head == tail) return -1;
  res = queue[head];
  head++;
  head %= 1000000;
  return res;
}

int emp() {
  return head == tail;
}



Measured memory_bytes: 2096
type Scanner() = class
    let mutable hold = [||]
    let mutable index = 0
    member public this.Next() =
        if hold.Length > index
        then 
            index <- index + 1
            hold.[index - 1]
        else
            let mutable st = stdin.ReadLine()
            while st = "" do st <- stdin.ReadLine()
            hold <- st.Split(' ')
            if hold.Length = 0
            then
                this.Next()
            else
                index <- 1
                hold.[index - 1]
            
    member public this.NextI32() =
        this.Next() |> int

    member public this.ArrayI32(n: int) =
        [for _ in 0 .. n - 1 -> this.NextI32()]

    member public this.NextI64() =
        this.Next() |> int64
    
    member public this.ArrayI64(n: int) =
        [for _ in 0 .. n - 1 -> this.NextI64()]

    member public this.NextF32() =
        this.Next() |> float32
    
    member public this.ArrayF32(n: int) =
        [for _ in 0 .. n - 1 -> this.NextF32()]

    member public this.NextF64() =
        this.Next() |> double
    
    member public this.ArrayF64(n: int) =
        [for _ in 0 .. n - 1 -> this.NextF64()]

    member public __.Tuple2List n (f : int -> 'a list) =
        [for _ in 0 .. n - 1 -> f 2 |> fun x -> x.[0], x.[1]]
    
    member public __.Tuple3List n (f : int -> 'a list) =
        [for _ in 0 .. n - 1 -> f 3 |> fun x -> x.[0], x.[1], x.[2]]

end

[<EntryPoint>]
let main _ =
    let sc = Scanner()
    let n = sc.NextI32()
    let a = sc.ArrayI32 n |> List.sort
    let sum = List.sum a
    if sum % 10 = 0 then
        match List.tryFind (fun x -> x % 10 <> 0) a with
        | Some(x) -> sum - x
        | None -> 0
    else
        sum
    |> printfn "%i"

    0


Measured memory_bytes: 14940
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<map>
using namespace std;

typedef long long ll;
typedef short int sh;

const ll inf=0x3f3f3f3f;
const int MAX=1<<6;
const int mod=1e9+7;

ll dp[51][51][2501];
int num[50],n,a;

ll Dp(int st,int cnt,int sum)
{
    if(dp[st][cnt][sum]!=-1)
        return dp[st][cnt][sum];
    dp[st][cnt][sum]=0;
    if(cnt&&(double)sum/cnt==a)
    {
        dp[st][cnt][sum]++;
    }
    for(int i=st;i<n&&(double)(sum+num[i])/(cnt+1)<=a;i++)
    {
        dp[st][cnt][sum]+=Dp(i+1,cnt+1,sum+num[i]);
    }
    return dp[st][cnt][sum];
}

int main()
{
    while(scanf("%d%d",&n,&a)!=EOF)
    {
        for(int i=0;i<n;i++)
        {
            scanf("%d",&num[i]);
        }
        sort(num,num+n);
        memset(dp,-1,sizeof(dp));
        printf("%lld\n",Dp(0,0,0));
    }
    return 0;
}


Measured memory_bytes: 54008
line = input()
words = line.split()

num_list = []
for elm in words:
    num_list.append(int(elm))

num_list.sort()
score = 0
for i, num in enumerate(num_list):
    if i < (len(num_list) - 1):
        score += (abs(num_list[i] - num_list[i+1]))
    else:
        break

print(score)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,sum = 0,tmp,cnt = 0,i;
    vector<int>v;
    cin>>a;
    for(i = 0;i < a;i++)
    {
        cin>>b;
        v.push_back(b);
    }
    sort(v.begin(),v.end());
    for(i = 0;i < a;i++)
    {
        if(i%2==0)
            sum+=v[i];
        else
            cnt+=v[i];
    }
    cout<<abs(sum-cnt)<<endl;

    return 0;
}


Measured memory_bytes: 256
// Knapsack on W ~ 1e9 and smaller v

// DP[i][j] = min weight   herer max possible value = N * 1000 = 1e5

#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define input freopen("1.txt","r",stdin);
#define output freopen("output.txt","w",stdout);
#define ll long long int
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define vi vector<int>
#define vii vector<vi>
#define vl vector<ll>
#define vll vector<vl>
#define pii pair<int, int>
#define pll pair<ll,ll>
#define mp make_pair
#define vpi vector<pii>
#define vpl vector<pll> 
using namespace std;
 
const int p=1e9+7;
const int maxn=1e5+1;
ll DP[100][maxn];

void solve() {
    int N, W; cin>>N>>W;
    int w[N], v[N];  
    for(int i = 0; i < N; i++) {
        cin >> w[i] >> v[i];
    }
    for(int i = 0; i < N; i++) {
        for(int j = 0; j <= maxn; j++) DP[i][j] = p;
    } 
    DP[0][0] = 0;
    DP[0][v[0]] = w[0]; 
    for(int i = 1; i < N; i++) {
        DP[i][0] = 0;
        for(int j = 0; j <=100000; j++) {
            // discard the weight
            
            DP[i][j] = DP[i-1][j];
            
            // pick the weight
            if(j >= v[i]) DP[i][j] = min(DP[i][j], w[i] + DP[i-1][j - v[i]]);
        }    
    }
    int ans = 0;
    for(int i = 100000; i >= 0; i--) {
        if(DP[N-1][i] <= W) {
            ans = i; break;
        }
    }
    cout << ans << "\n";
}

int main() {
    fast 
    // input output
    int t = 1; 
    // cin>>t; 
    while(t--) solve();
    return 0;
}

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

int main() {
    int n, k, q, temp;
    cin >> n >> k >> q;
    vector<int> cnt(n, 0);
    rep(i, q) {
        cin >> temp;
        cnt.at(temp - 1)++;
    }
    rep(i, n) {
        if(q - cnt.at(i) < k) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;

typedef long long ll;

const int MOD = (int) 1e9 + 7;

int rev[100005], point[100005];

int binpow(int x, int step)
{
	if (step == 0) return 1;
	if (step % 2 == 0)
	{
	 	int t = binpow(x, step / 2);
	 	return (ll) t * (ll) t % (ll) MOD;
	}
	else return (ll) x * (ll) binpow(x, step - 1) % (ll) MOD;	
}

int revers(int x)
{
 	return binpow(x, MOD - 2);
}

int main()
{
 	//freopen("input.txt", "r", stdin);
 	//freopen("output.txt", "w", stdout);
 	ios_base::sync_with_stdio(0); cin.tie(0);
 	int n;
 	cin >> n;
 	for (int i = 1; i <= n; i++) cin >> point[i];
 	for (int i = 1; i <= n; i++) rev[i] = revers(i);

 	int ans = 0;
 	for (int i = 1; i <= n - 1; i++) ans = ((ll) ans + (ll) rev[n - i] * (ll) (point[n] - point[i]) % (ll) MOD) % (ll) MOD;
 	for (int i = 1; i <= n - 1; i++) ans = ((ll) ans + (ll) point[i] * (ll) (1 - rev[i] + MOD) % (ll) MOD) % (ll) MOD;
 	for (int i = 1; i <= n - 1; i++) ans = ((ll) ans + (ll) MOD - (ll) point[i] * (ll) (1 + MOD - rev[n - i]) % (ll) MOD) % (ll) MOD;
 	for (int i = 1; i <= n - 1; i++) ans = (ll) ans * (ll) i % (ll) MOD;
 	cout << ans << '\n';
 	return 0;
}

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

template <typename T>
struct trie_t {
    T data;
    array<shared_ptr<trie_t>, 2> children;
};
template <typename T>
shared_ptr<trie_t<T> > trie_insert(shared_ptr<trie_t<T> > original_t, string const & s, T data) {
    if (not original_t) original_t = make_shared<trie_t<T> >();
    auto t = original_t;
    for (char c : s) {
        assert (c == '0' or c == '1');
        int i = c - '0';
        if (not t->children[i]) t->children[i] = make_shared<trie_t<T> >();
        t = t->children[i];
    }
    t->data = data;
    return original_t;
}

int grundy(ll l) {
    return (not l ? 0 : __builtin_ctzll(l) + 1);
}

int go(ll l, shared_ptr<trie_t<bool> > const & a) {
    if (not a) {
        return grundy(l);
    } else if (a->data) {
        return 0;
    } else {
        return go(l - 1, a->children[0]) ^ go(l - 1, a->children[1]);
    }
}

bool solve(int n, ll l, vector<string> const & s) {
    shared_ptr<trie_t<bool> > root = nullptr;
    for (auto const & s_i : s) {
        root = trie_insert(root, s_i, true);
    }
    return go(l + 1, root);
}

int main() {
    int n; ll l; cin >> n >> l;
    vector<string> s(n);
    REP (i, n) cin >> s[i];
    cout << (solve(n, l, s) ? "Alice" : "Bob") << endl;
    return 0;
}


Measured memory_bytes: 11264
N, K = list(map(int, input().split()))
S = input()

D = []
count = 0
mode = 1
if S[0] == "0":
    D.append(0)
    mode = 0

for i in range(N):
    if int(S[i]) == mode:
        count += 1
    else:
        D.append(count)
        count = 1
        mode = 1 - mode
    if i == N-1:
        D.append(count)

if S[-1] == "0":
    D.append(0)
lk = int((len(D)-1)/2)
if K > lk:
    K = lk
ans = sum(D[:(2*K+1)])
sumd = ans
for i in range(int((len(D)-2*K-1)/2)):
    sumd += D[2*K+2*i+1]+D[2*K+2*i+2]-D[2*i]-D[2*i+1]
    if sumd > ans:
        ans = sumd

print(ans)


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




int a[1005][1005];
int b[1005];
bool v[1005] ;
int main(){
	int n ;
	// cin >> n ;
	scanf("%d",&n);
	for( int i = 0 ; i < n ; i++ ){
		for( int j = 0 ; j < n-1 ; j++ ){
			scanf("%d",&a[i][j]);
			a[i][j]-- ;
		}
	}
	int c = 0 , d = 0 ;
	queue < pair< int , int > > q ;
	for( int  i = 0 ; i < n ; i++ ){
			if( v[i] ) continue ;
			int j = a[i][b[i]] ;
			if( !v[j] && a[j][b[j]] == i ){
				v[j] = 1 ;
				q.push(make_pair(i,j));
			}
	}
	while( !q.empty()  && c != n ){
		d++ ;	
		int l = q.size() , i , j  ;
		while(l--){
			pair < int , int > x = q.front() ;
			q.pop() ;
			b[x.first]++ ;
			b[x.second]++ ;
			if( b[x.first]  == n-1 ) c++ ;
			if( b[x.second] == n-1  ) c++ ;
			i = x.first ;
			j = a[i][b[i]] ;
			if( b[i] != n-1 && a[j][b[j]] == i ){
				q.push(make_pair( i , j ));
			}
			i = x.second ;
			j = a[i][b[i]] ;
			if( b[i] != n-1 && a[j][b[j]] == i ){
				q.push(make_pair( i , j ));
			}

		}

	}
	if( c < n ) puts("-1");
	else cout << d << endl ;


	return 0 ;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define fs first
#define sc second
#define mx 100005
#define mod 1000000007
#define pii pair<int, int>
#define ll long long
#define mkp make_pair
#define all(a) a.begin(),a.end()
using namespace std;

int main()
{
	int n;
	scanf("%d", &n);
	ll ara[n];
	for(int i = 0; i<n; i++){
		scanf("%lld", &ara[i]);
	}
	int lim = 61;
	ll ans = 0;
	for(int i = 0; i<lim; i++){
		int c = 0;
		for(int j = 0; j<n; j++){
			if(ara[j]&(1ll<<i)) c++;
		}
		if(c & 1){
			for(int j = 0; j<n; j++){
				ara[j] = ara[j]&(~(1ll<<i));
			}
			ans |= (1ll << i);
		}
	}
	ll basis[62];
	memset(basis, 0, sizeof basis);
	for(int j = 0; j<n; j++){
		for(int i = lim-1; i>=0; i--)
		{
			if(ara[j]&(1ll<<i)){
				if(!basis[i]){
					basis[i] ^= ara[j];
					break;
				}
				ara[j] ^= basis[i];
			}
		}
	}
	
	ll nw = 0;
	for(int i = lim-1; i>=0; i--)
		if(nw < (nw^basis[i])) nw ^= basis[i];
	printf("%lld\n", 2ll*nw+ans);
	return 0;
}

Measured memory_bytes: 1024